Skip to content

Commit

Permalink
remove dupe
Browse files Browse the repository at this point in the history
  • Loading branch information
mzywang committed May 30, 2024
1 parent a902eb5 commit 7a190d6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/utils/pricing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const WHITELIST_TOKENS: string[] = [WETH_ADDRESS, USDC_ADDRESS, DAI_ADDRE

export const STABLE_COINS: string[] = [USDC_ADDRESS, DAI_ADDRESS, USDT_ADDRESS]

export const MINIMUM_ETH_LOCKED = BigDecimal.fromString('60')
export const MINIMUM_ETH_LOCKED = BigDecimal.fromString('20')

const Q192 = BigInt.fromI32(2).pow(192 as u8)
export function sqrtPriceX96ToTokenPrices(sqrtPriceX96: BigInt, token0: Token, token1: Token): BigDecimal[] {
Expand Down
36 changes: 18 additions & 18 deletions src/utils/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ export function fetchTokenSymbol(
const contract = ERC20.bind(tokenAddress)
const contractSymbolBytes = ERC20SymbolBytes.bind(tokenAddress)

// try with the static definition
const staticTokenDefinition = getStaticDefinition(tokenAddress, staticTokenDefinitions)
if (staticTokenDefinition != null) {
return staticTokenDefinition.symbol
}

// try types string and bytes32 for symbol
let symbolValue = 'unknown'
const symbolResult = contract.try_symbol()
Expand All @@ -22,12 +28,6 @@ export function fetchTokenSymbol(
// for broken pairs that have no symbol function exposed
if (!isNullEthValue(symbolResultBytes.value.toHexString())) {
symbolValue = symbolResultBytes.value.toString()
} else {
// try with the static definition
const staticTokenDefinition = getStaticDefinition(tokenAddress, staticTokenDefinitions)
if (staticTokenDefinition != null) {
symbolValue = staticTokenDefinition.symbol
}
}
}
} else {
Expand All @@ -44,6 +44,12 @@ export function fetchTokenName(
const contract = ERC20.bind(tokenAddress)
const contractNameBytes = ERC20NameBytes.bind(tokenAddress)

// try with the static definition
const staticTokenDefinition = getStaticDefinition(tokenAddress, staticTokenDefinitions)
if (staticTokenDefinition != null) {
return staticTokenDefinition.name
}

// try types string and bytes32 for name
let nameValue = 'unknown'
const nameResult = contract.try_name()
Expand All @@ -53,12 +59,6 @@ export function fetchTokenName(
// for broken exchanges that have no name function exposed
if (!isNullEthValue(nameResultBytes.value.toHexString())) {
nameValue = nameResultBytes.value.toString()
} else {
// try with the static definition
const staticTokenDefinition = getStaticDefinition(tokenAddress, staticTokenDefinitions)
if (staticTokenDefinition != null) {
nameValue = staticTokenDefinition.name
}
}
}
} else {
Expand All @@ -82,6 +82,12 @@ export function fetchTokenDecimals(
tokenAddress: Address,
staticTokenDefinitions: StaticTokenDefinition[] = STATIC_TOKEN_DEFINITIONS,
): BigInt | null {
// try with the static definition
const staticTokenDefinition = getStaticDefinition(tokenAddress, staticTokenDefinitions)
if (staticTokenDefinition) {
return staticTokenDefinition.decimals
}

const contract = ERC20.bind(tokenAddress)
// try types uint8 for decimals
const decimalResult = contract.try_decimals()
Expand All @@ -90,12 +96,6 @@ export function fetchTokenDecimals(
if (decimalResult.value.lt(BigInt.fromI32(255))) {
return decimalResult.value
}
} else {
// try with the static definition
const staticTokenDefinition = getStaticDefinition(tokenAddress, staticTokenDefinitions)
if (staticTokenDefinition) {
return staticTokenDefinition.decimals
}
}

return null
Expand Down

0 comments on commit 7a190d6

Please sign in to comment.