From f9c33801c2b119cfc31e81a62a9194aa741135dd Mon Sep 17 00:00:00 2001 From: Michael Wang <44713145+mzywang@users.noreply.github.com> Date: Mon, 8 Apr 2024 12:05:16 -0400 Subject: [PATCH 1/8] remove double count --- src/mappings/pool/collect.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mappings/pool/collect.ts b/src/mappings/pool/collect.ts index 6cbf87a4..98243452 100644 --- a/src/mappings/pool/collect.ts +++ b/src/mappings/pool/collect.ts @@ -1,9 +1,9 @@ -import { BigInt } from '@graphprotocol/graph-ts' +import { BigDecimal, BigInt } from '@graphprotocol/graph-ts' -import { Bundle, Collect, Factory, Pool, Token } from '../../types/schema' +import { Bundle, Burn, BurnLoader, Collect, Factory, Pool, Token } from '../../types/schema' import { Collect as CollectEvent } from '../../types/templates/Pool/Pool' import { convertTokenToDecimal, loadTransaction } from '../../utils' -import { FACTORY_ADDRESS, ONE_BI } from '../../utils/constants' +import { FACTORY_ADDRESS, ONE_BI, ZERO_BD } from '../../utils/constants' import { updatePoolDayData, updatePoolHourData, From b8a7ac6f03bfffa1abb65e998a070a5776b8c86a Mon Sep 17 00:00:00 2001 From: Michael Wang <44713145+mzywang@users.noreply.github.com> Date: Mon, 8 Apr 2024 14:51:05 -0400 Subject: [PATCH 2/8] lint --- src/mappings/pool/collect.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mappings/pool/collect.ts b/src/mappings/pool/collect.ts index 98243452..6cbf87a4 100644 --- a/src/mappings/pool/collect.ts +++ b/src/mappings/pool/collect.ts @@ -1,9 +1,9 @@ -import { BigDecimal, BigInt } from '@graphprotocol/graph-ts' +import { BigInt } from '@graphprotocol/graph-ts' -import { Bundle, Burn, BurnLoader, Collect, Factory, Pool, Token } from '../../types/schema' +import { Bundle, Collect, Factory, Pool, Token } from '../../types/schema' import { Collect as CollectEvent } from '../../types/templates/Pool/Pool' import { convertTokenToDecimal, loadTransaction } from '../../utils' -import { FACTORY_ADDRESS, ONE_BI, ZERO_BD } from '../../utils/constants' +import { FACTORY_ADDRESS, ONE_BI } from '../../utils/constants' import { updatePoolDayData, updatePoolHourData, From c3f9a3110246457ea575db3102ee382e28399c5b Mon Sep 17 00:00:00 2001 From: Michael Wang <44713145+mzywang@users.noreply.github.com> Date: Mon, 8 Apr 2024 14:55:00 -0400 Subject: [PATCH 3/8] update transaction ids to use log index --- src/mappings/pool/burn.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mappings/pool/burn.ts b/src/mappings/pool/burn.ts index 3f924c6c..a5eb6e68 100644 --- a/src/mappings/pool/burn.ts +++ b/src/mappings/pool/burn.ts @@ -9,7 +9,7 @@ import { updatePoolHourData, updateTokenDayData, updateTokenHourData, - updateUniswapDayData, + updateUniswapDayData } from '../../utils/intervalUpdates' export function handleBurn(event: BurnEvent): void { From 2f3ad5bbbaa271e0d2bc901c556bd73aa26dbc2b Mon Sep 17 00:00:00 2001 From: Michael Wang <44713145+mzywang@users.noreply.github.com> Date: Mon, 8 Apr 2024 16:52:19 -0400 Subject: [PATCH 4/8] change subgraph to base --- src/utils/constants.ts | 2 +- src/utils/pricing.ts | 45 ++++++++---------------------- src/utils/staticTokenDefinition.ts | 41 ++------------------------- subgraph.yaml | 8 +++--- 4 files changed, 19 insertions(+), 77 deletions(-) diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 6c578871..d148102d 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 = '0x1F98431c8aD98523631AE4a59f267346ea31F984' +export const FACTORY_ADDRESS = '0x33128a8fC17869897dcE68Ed026d694621f6FDfD' 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 6b834ff2..4582fd7a 100644 --- a/src/utils/pricing.ts +++ b/src/utils/pricing.ts @@ -4,60 +4,39 @@ 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 = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' -export const USDC_WETH_03_POOL = '0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8' -export const STABLECOIN_IS_TOKEN0 = true +export const WETH_ADDRESS = '0x4200000000000000000000000000000000000006' +export const USDC_WETH_05_POOL = '0x4c36388be6f416a29c8d8eee81c771ce6be14b18' +export const STABLECOIN_IS_TOKEN0 = false // 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, // WETH - '0x6b175474e89094c44da98b954eedeac495271d0f', // DAI - '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', // USDC - '0xdac17f958d2ee523a2206206994597c13d831ec7', // USDT - '0x0000000000085d4780b73119b644ae5ecd22b376', // TUSD - '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599', // WBTC - '0x5d3a536e4d6dbd6114cc1ead35777bab948e3643', // cDAI - '0x39aa39c021dfbae8fac545936693ac917d5e7563', // cUSDC - '0x86fadb80d8d2cff3c3680819e4da99c10232ba0f', // EBASE - '0x57ab1ec28d129707052df4df418d58a2d46d5f51', // sUSD - '0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2', // MKR - '0xc00e94cb662c3520282e6f5717214004a7f26888', // COMP - '0x514910771af9ca656af840dff83e8264ecf986ca', // LINK - '0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f', // SNX - '0x0bc529c00c6401aef6d220be8c6ea1667f6ad93e', // YFI - '0x111111111117dc0aa78b770fa6a738034120c302', // 1INCH - '0xdf5e0e81dff6faf3a7e52ba697820c5e32d806a8', // yCurv - '0x956f47f50a910163d8bf957cf5846d573e7f87ca', // FEI - '0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0', // MATIC - '0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9', // AAVE - '0xfe2e637202056d30016725477c5da089ab0a043a', // sETH2 + '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913', // USDC ] export const STABLE_COINS: string[] = [ - '0x6b175474e89094c44da98b954eedeac495271d0f', - '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', - '0xdac17f958d2ee523a2206206994597c13d831ec7', - '0x0000000000085d4780b73119b644ae5ecd22b376', - '0x956f47f50a910163d8bf957cf5846d573e7f87ca', - '0x4dd28568d05f09b02220b09c2cb307bfd837cb95', + '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913', // USDC ] -export const MINIMUM_ETH_LOCKED = BigDecimal.fromString('60') +export const MINIMUM_ETH_LOCKED = BigDecimal.fromString('1') 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_03_POOL, - stablecoinIsToken0: boolean = STABLECOIN_IS_TOKEN0, // true is stablecoin is token0, false if stablecoin is token1 + stablecoinWrappedNativePoolAddress: string = USDC_WETH_05_POOL, + stablecoinIsToken0: boolean = false, // true is stablecoin is token0, false if stablecoin is token1 ): BigDecimal { const stablecoinWrappedNativePool = Pool.load(stablecoinWrappedNativePoolAddress) if (stablecoinWrappedNativePool !== null) { diff --git a/src/utils/staticTokenDefinition.ts b/src/utils/staticTokenDefinition.ts index 2c0b8720..f64e08d7 100644 --- a/src/utils/staticTokenDefinition.ts +++ b/src/utils/staticTokenDefinition.ts @@ -10,7 +10,7 @@ export class StaticTokenDefinition { export const getStaticDefinition = ( tokenAddress: Address, - staticDefinitions: Array, + staticDefinitions: Array ): StaticTokenDefinition | null => { const tokenAddressHex = tokenAddress.toHexString() @@ -26,41 +26,4 @@ export const getStaticDefinition = ( return null } -export const STATIC_TOKEN_DEFINITIONS: Array = [ - { - address: Address.fromString('0xe0b7927c4af23765cb51314a0e0521a9645f0e2a'), - symbol: 'DGD', - name: 'DGD', - decimals: BigInt.fromI32(9), - }, - { - address: Address.fromString('0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9'), - symbol: 'AAVE', - name: 'Aave Token', - decimals: BigInt.fromI32(18), - }, - { - address: Address.fromString('0xeb9951021698b42e4399f9cbb6267aa35f82d59d'), - symbol: 'LIF', - name: 'Lif', - decimals: BigInt.fromI32(18), - }, - { - address: Address.fromString('0xbdeb4b83251fb146687fa19d1c660f99411eefe3'), - symbol: 'SVD', - name: 'savedroid', - decimals: BigInt.fromI32(18), - }, - { - address: Address.fromString('0xbb9bc244d798123fde783fcc1c72d3bb8c189413'), - symbol: 'TheDAO', - name: 'TheDAO', - decimals: BigInt.fromI32(16), - }, - { - address: Address.fromString('0x38c6a68304cdefb9bec48bbfaaba5c5b47818bb2'), - symbol: 'HPB', - name: 'HPBCoin', - decimals: BigInt.fromI32(18), - }, -] +export const STATIC_TOKEN_DEFINITIONS: Array = [] diff --git a/subgraph.yaml b/subgraph.yaml index 10e7cb55..f2d8bacd 100644 --- a/subgraph.yaml +++ b/subgraph.yaml @@ -9,11 +9,11 @@ features: dataSources: - kind: ethereum/contract name: Factory - network: mainnet + network: base source: - address: '0x1F98431c8aD98523631AE4a59f267346ea31F984' + address: '0x33128a8fC17869897dcE68Ed026d694621f6FDfD' abi: Factory - startBlock: 12369621 + startBlock: 2009445 mapping: kind: ethereum/events apiVersion: 0.0.7 @@ -39,7 +39,7 @@ dataSources: templates: - kind: ethereum/contract name: Pool - network: mainnet + network: base source: abi: Pool mapping: From 310007d94c112f601e55bf299673ae2116bec907 Mon Sep 17 00:00:00 2001 From: mzywang Date: Tue, 23 Apr 2024 18:14:20 +0000 Subject: [PATCH 5/8] fix(lint): auto-fix [ci] --- src/mappings/pool/burn.ts | 2 +- src/utils/pricing.ts | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/mappings/pool/burn.ts b/src/mappings/pool/burn.ts index a5eb6e68..3f924c6c 100644 --- a/src/mappings/pool/burn.ts +++ b/src/mappings/pool/burn.ts @@ -9,7 +9,7 @@ import { updatePoolHourData, updateTokenDayData, updateTokenHourData, - updateUniswapDayData + updateUniswapDayData, } from '../../utils/intervalUpdates' export function handleBurn(event: BurnEvent): void { diff --git a/src/utils/pricing.ts b/src/utils/pricing.ts index 4582fd7a..d288cf7f 100644 --- a/src/utils/pricing.ts +++ b/src/utils/pricing.ts @@ -25,10 +25,7 @@ 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] From 2b136c8ee6ebdeaab7c39d85145193955d705b67 Mon Sep 17 00:00:00 2001 From: Michael Wang <44713145+mzywang@users.noreply.github.com> Date: Wed, 24 Apr 2024 13:26:36 -0400 Subject: [PATCH 6/8] fix typo --- src/utils/pricing.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/utils/pricing.ts b/src/utils/pricing.ts index d288cf7f..f10d50d9 100644 --- a/src/utils/pricing.ts +++ b/src/utils/pricing.ts @@ -8,16 +8,13 @@ export const WETH_ADDRESS = '0x4200000000000000000000000000000000000006' export const USDC_WETH_05_POOL = '0x4c36388be6f416a29c8d8eee81c771ce6be14b18' export const STABLECOIN_IS_TOKEN0 = false +const USDC_ADDRESS = '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913' + // 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, // WETH - '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913', // USDC -] +export const WHITELIST_TOKENS: string[] = [WETH_ADDRESS, USDC_ADDRESS] -export const STABLE_COINS: string[] = [ - '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913', // USDC -] +export const STABLE_COINS: string[] = [USDC_ADDRESS] export const MINIMUM_ETH_LOCKED = BigDecimal.fromString('1') @@ -25,7 +22,10 @@ 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] From 331dc179f6a56b24347224110a0b30bfafd32b21 Mon Sep 17 00:00:00 2001 From: mzywang Date: Wed, 24 Apr 2024 17:31:28 +0000 Subject: [PATCH 7/8] fix(lint): auto-fix [ci] --- src/utils/pricing.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/utils/pricing.ts b/src/utils/pricing.ts index f10d50d9..2808d315 100644 --- a/src/utils/pricing.ts +++ b/src/utils/pricing.ts @@ -22,10 +22,7 @@ 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] From 8c3ff647db2af32740764c36bc8cadea502c3a3d Mon Sep 17 00:00:00 2001 From: mzywang Date: Thu, 30 May 2024 15:16:24 +0000 Subject: [PATCH 8/8] fix(lint): auto-fix [ci] --- src/mappings/pool/initialize.ts | 4 ++-- src/utils/pricing.ts | 2 +- src/utils/staticTokenDefinition.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mappings/pool/initialize.ts b/src/mappings/pool/initialize.ts index 3e7c56a0..86a14cf2 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_03_POOL, + USDC_WETH_05_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_03_POOL, + stablecoinWrappedNativePoolAddress: string = USDC_WETH_05_POOL, stablecoinIsToken0: boolean = STABLECOIN_IS_TOKEN0, wrappedNativeAddress: string = WETH_ADDRESS, stablecoinAddresses: string[] = STABLE_COINS, diff --git a/src/utils/pricing.ts b/src/utils/pricing.ts index 2808d315..a0c40d30 100644 --- a/src/utils/pricing.ts +++ b/src/utils/pricing.ts @@ -30,7 +30,7 @@ export function sqrtPriceX96ToTokenPrices(sqrtPriceX96: BigInt, token0: Token, t export function getEthPriceInUSD( stablecoinWrappedNativePoolAddress: string = USDC_WETH_05_POOL, - stablecoinIsToken0: boolean = false, // true is stablecoin is token0, false if stablecoin is token1 + stablecoinIsToken0: boolean = STABLECOIN_IS_TOKEN0, // true is stablecoin is token0, false if stablecoin is token1 ): BigDecimal { const stablecoinWrappedNativePool = Pool.load(stablecoinWrappedNativePoolAddress) if (stablecoinWrappedNativePool !== null) { diff --git a/src/utils/staticTokenDefinition.ts b/src/utils/staticTokenDefinition.ts index f64e08d7..9113c65c 100644 --- a/src/utils/staticTokenDefinition.ts +++ b/src/utils/staticTokenDefinition.ts @@ -10,7 +10,7 @@ export class StaticTokenDefinition { export const getStaticDefinition = ( tokenAddress: Address, - staticDefinitions: Array + staticDefinitions: Array, ): StaticTokenDefinition | null => { const tokenAddressHex = tokenAddress.toHexString()