From a902eb520500d3b785ecd935bd921ee08e8e9393 Mon Sep 17 00:00:00 2001 From: Michael Wang <44713145+mzywang@users.noreply.github.com> Date: Tue, 23 Apr 2024 15:56:41 -0400 Subject: [PATCH 1/2] update network to arbitrum-one --- src/mappings/pool/initialize.ts | 4 ++-- src/utils/constants.ts | 2 +- src/utils/pricing.ts | 21 +++++++++++++-------- src/utils/staticTokenDefinition.ts | 15 ++++++++++++++- subgraph.yaml | 8 ++++---- 5 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/mappings/pool/initialize.ts b/src/mappings/pool/initialize.ts index 86a14cf2..3e7c56a0 100644 --- a/src/mappings/pool/initialize.ts +++ b/src/mappings/pool/initialize.ts @@ -9,7 +9,7 @@ import { MINIMUM_ETH_LOCKED, STABLE_COINS, STABLECOIN_IS_TOKEN0, - USDC_WETH_05_POOL, + USDC_WETH_03_POOL, WETH_ADDRESS, } from '../../utils/pricing' @@ -19,7 +19,7 @@ export function handleInitialize(event: Initialize): void { export function handleInitializeHelper( event: Initialize, - stablecoinWrappedNativePoolAddress: string = USDC_WETH_05_POOL, + stablecoinWrappedNativePoolAddress: string = USDC_WETH_03_POOL, stablecoinIsToken0: boolean = STABLECOIN_IS_TOKEN0, wrappedNativeAddress: string = WETH_ADDRESS, stablecoinAddresses: string[] = STABLE_COINS, diff --git a/src/utils/constants.ts b/src/utils/constants.ts index d148102d..6c578871 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -3,7 +3,7 @@ import { Address, BigDecimal, BigInt } from '@graphprotocol/graph-ts' import { Factory as FactoryContract } from '../types/templates/Pool/Factory' export const ADDRESS_ZERO = '0x0000000000000000000000000000000000000000' -export const FACTORY_ADDRESS = '0x33128a8fC17869897dcE68Ed026d694621f6FDfD' +export const FACTORY_ADDRESS = '0x1F98431c8aD98523631AE4a59f267346ea31F984' export const ZERO_BI = BigInt.fromI32(0) export const ONE_BI = BigInt.fromI32(1) diff --git a/src/utils/pricing.ts b/src/utils/pricing.ts index a0c40d30..e1745587 100644 --- a/src/utils/pricing.ts +++ b/src/utils/pricing.ts @@ -4,32 +4,37 @@ import { exponentToBigDecimal, safeDiv } from '../utils/index' import { Bundle, Pool, Token } from './../types/schema' import { ONE_BD, ZERO_BD, ZERO_BI } from './constants' -export const WETH_ADDRESS = '0x4200000000000000000000000000000000000006' -export const USDC_WETH_05_POOL = '0x4c36388be6f416a29c8d8eee81c771ce6be14b18' +export const WETH_ADDRESS = '0x82af49447d8a07e3bd95bd0d56f35241523fbab1' +export const USDC_WETH_03_POOL = '0x17c14d2c404d167802b16c450d3c99f88f2c4f4d' export const STABLECOIN_IS_TOKEN0 = false -const USDC_ADDRESS = '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913' +const USDC_ADDRESS = '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8' +const DAI_ADDRESS = '0xda10009cbd5d07dd0cecc66161fc93d7c9000da1' +const USDT_ADDRESS = '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9' // token where amounts should contribute to tracked volume and liquidity // usually tokens that many tokens are paired with s -export const WHITELIST_TOKENS: string[] = [WETH_ADDRESS, USDC_ADDRESS] +export const WHITELIST_TOKENS: string[] = [WETH_ADDRESS, USDC_ADDRESS, DAI_ADDRESS, USDT_ADDRESS] -export const STABLE_COINS: string[] = [USDC_ADDRESS] +export const STABLE_COINS: string[] = [USDC_ADDRESS, DAI_ADDRESS, USDT_ADDRESS] -export const MINIMUM_ETH_LOCKED = BigDecimal.fromString('1') +export const MINIMUM_ETH_LOCKED = BigDecimal.fromString('60') const Q192 = BigInt.fromI32(2).pow(192 as u8) export function sqrtPriceX96ToTokenPrices(sqrtPriceX96: BigInt, token0: Token, token1: Token): BigDecimal[] { const num = sqrtPriceX96.times(sqrtPriceX96).toBigDecimal() const denom = BigDecimal.fromString(Q192.toString()) - const price1 = num.div(denom).times(exponentToBigDecimal(token0.decimals)).div(exponentToBigDecimal(token1.decimals)) + const price1 = num + .div(denom) + .times(exponentToBigDecimal(token0.decimals)) + .div(exponentToBigDecimal(token1.decimals)) const price0 = safeDiv(BigDecimal.fromString('1'), price1) return [price0, price1] } export function getEthPriceInUSD( - stablecoinWrappedNativePoolAddress: string = USDC_WETH_05_POOL, + stablecoinWrappedNativePoolAddress: string = USDC_WETH_03_POOL, stablecoinIsToken0: boolean = STABLECOIN_IS_TOKEN0, // true is stablecoin is token0, false if stablecoin is token1 ): BigDecimal { const stablecoinWrappedNativePool = Pool.load(stablecoinWrappedNativePoolAddress) diff --git a/src/utils/staticTokenDefinition.ts b/src/utils/staticTokenDefinition.ts index 9113c65c..283b3c06 100644 --- a/src/utils/staticTokenDefinition.ts +++ b/src/utils/staticTokenDefinition.ts @@ -26,4 +26,17 @@ export const getStaticDefinition = ( return null } -export const STATIC_TOKEN_DEFINITIONS: Array = [] +export const STATIC_TOKEN_DEFINITIONS: Array = [ + { + address: Address.fromString('0x82af49447d8a07e3bd95bd0d56f35241523fbab1'), + symbol: 'WETH', + name: 'Wrapped Ethereum', + decimals: BigInt.fromI32(18) + }, + { + address: Address.fromString('0xff970a61a04b1ca14834a43f5de4533ebddb5cc8'), + symbol: 'USDC', + name: 'USD Coin', + decimals: BigInt.fromI32(6) + } +] diff --git a/subgraph.yaml b/subgraph.yaml index f2d8bacd..85e729e8 100644 --- a/subgraph.yaml +++ b/subgraph.yaml @@ -9,11 +9,11 @@ features: dataSources: - kind: ethereum/contract name: Factory - network: base + network: arbitrum-one source: - address: '0x33128a8fC17869897dcE68Ed026d694621f6FDfD' + address: '0x1F98431c8aD98523631AE4a59f267346ea31F984' abi: Factory - startBlock: 2009445 + startBlock: 165 mapping: kind: ethereum/events apiVersion: 0.0.7 @@ -39,7 +39,7 @@ dataSources: templates: - kind: ethereum/contract name: Pool - network: base + network: arbitrum-one source: abi: Pool mapping: From 7a190d6834a0bb6d9d7317440c258371acfea913 Mon Sep 17 00:00:00 2001 From: Michael Wang <44713145+mzywang@users.noreply.github.com> Date: Wed, 24 Apr 2024 13:31:41 -0400 Subject: [PATCH 2/2] remove dupe --- src/utils/pricing.ts | 2 +- src/utils/token.ts | 36 ++++++++++++++++++------------------ 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/utils/pricing.ts b/src/utils/pricing.ts index e1745587..e5f35083 100644 --- a/src/utils/pricing.ts +++ b/src/utils/pricing.ts @@ -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[] { diff --git a/src/utils/token.ts b/src/utils/token.ts index 1aca8117..e7b7a25f 100644 --- a/src/utils/token.ts +++ b/src/utils/token.ts @@ -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() @@ -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 { @@ -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() @@ -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 { @@ -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() @@ -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