From 2fe2b1cc2f904a76418ca816e355dabf7e4e8d78 Mon Sep 17 00:00:00 2001 From: Robert Seitz Date: Mon, 15 Sep 2025 16:44:47 -0400 Subject: [PATCH 1/5] merge 04-12-add_price_tracking_token_field --- src/mappings/pricing.ts | 203 +++++++++++++++++++++++++++++++++++++ src/v2/mappings/core.ts | 4 +- src/v2/mappings/factory.ts | 47 ++++++--- src/v2/schema.graphql | 3 + 4 files changed, 243 insertions(+), 14 deletions(-) create mode 100644 src/mappings/pricing.ts diff --git a/src/mappings/pricing.ts b/src/mappings/pricing.ts new file mode 100644 index 00000000..f2210540 --- /dev/null +++ b/src/mappings/pricing.ts @@ -0,0 +1,203 @@ +/* eslint-disable prefer-const */ +import { BigDecimal, BigInt } from '@graphprotocol/graph-ts/index' + +import { Bundle, Pair, Token } from '../types/schema' +import { ONE_BD, UNTRACKED_PAIRS, ZERO_BD } from './helpers' + +const WETH_ADDRESS = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' +const USDC_WETH_PAIR = '0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc' // created 10008355 +const DAI_WETH_PAIR = '0xa478c2975ab1ea89e8196811f51a7b7ade33eb11' // created block 10042267 +const USDT_WETH_PAIR = '0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852' // created block 10093341 + +export function getEthPriceInUSD(): BigDecimal { + // fetch eth prices for each stablecoin + let daiPair = Pair.load(DAI_WETH_PAIR) // dai is token0 + let usdcPair = Pair.load(USDC_WETH_PAIR) // usdc is token0 + let usdtPair = Pair.load(USDT_WETH_PAIR) // usdt is token1 + + // all 3 have been created + if (daiPair !== null && usdcPair !== null && usdtPair !== null) { + let totalLiquidityETH = daiPair.reserve1.plus(usdcPair.reserve1).plus(usdtPair.reserve0) + let daiWeight = daiPair.reserve1.div(totalLiquidityETH) + let usdcWeight = usdcPair.reserve1.div(totalLiquidityETH) + let usdtWeight = usdtPair.reserve0.div(totalLiquidityETH) + return daiPair.token0Price + .times(daiWeight) + .plus(usdcPair.token0Price.times(usdcWeight)) + .plus(usdtPair.token1Price.times(usdtWeight)) + // dai and USDC have been created + } else if (daiPair !== null && usdcPair !== null) { + let totalLiquidityETH = daiPair.reserve1.plus(usdcPair.reserve1) + let daiWeight = daiPair.reserve1.div(totalLiquidityETH) + let usdcWeight = usdcPair.reserve1.div(totalLiquidityETH) + return daiPair.token0Price.times(daiWeight).plus(usdcPair.token0Price.times(usdcWeight)) + // USDC is the only pair so far + } else if (usdcPair !== null) { + return usdcPair.token0Price + } else { + return ZERO_BD + } +} + +// token where amounts should contribute to tracked volume and liquidity +export const PRICE_TRACKING_TOKENS: string[] = [ + '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', // WETH + '0x6b175474e89094c44da98b954eedeac495271d0f', // DAI + '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', // USDC + '0xdac17f958d2ee523a2206206994597c13d831ec7', // USDT + '0x0000000000085d4780b73119b644ae5ecd22b376', // TUSD + '0x5d3a536e4d6dbd6114cc1ead35777bab948e3643', // cDAI + '0x39aa39c021dfbae8fac545936693ac917d5e7563', // cUSDC + '0x86fadb80d8d2cff3c3680819e4da99c10232ba0f', // EBASE + '0x57ab1ec28d129707052df4df418d58a2d46d5f51', // sUSD + '0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2', // MKR + '0xc00e94cb662c3520282e6f5717214004a7f26888', // COMP + '0x514910771af9ca656af840dff83e8264ecf986ca', //LINK + '0x960b236a07cf122663c4303350609a66a7b288c0', //ANT + '0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f', //SNX + '0x0bc529c00c6401aef6d220be8c6ea1667f6ad93e', //YFI + '0xdf5e0e81dff6faf3a7e52ba697820c5e32d806a8', // yCurv + '0x853d955acef822db058eb8505911ed77f175b99e', // FRAX + '0xa47c8bf37f92abed4a126bda807a7b7498661acd', // WUST + '0x1f9840a85d5af5bf1d1762f925bdaddc4201f984', // UNI + '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599', // WBTC + '0x956f47f50a910163d8bf957cf5846d573e7f87ca', // FEI +] + +// minimum liquidity required to count towards tracked volume for pairs with small # of Lps +let MINIMUM_USD_THRESHOLD_NEW_PAIRS = BigDecimal.fromString('400000') + +// minimum liquidity for price to get tracked +let MINIMUM_LIQUIDITY_THRESHOLD_ETH = BigDecimal.fromString('2') + +/** + * Search through graph to find derived Eth per token. + * @todo update to be derived ETH (add stablecoin estimates) + **/ +export function findEthPerToken(token: Token): BigDecimal { + if (token.id == WETH_ADDRESS) { + return ONE_BD + } + const priceTrackingPairs = token.priceTrackingPairs + for (let i = 0; i < priceTrackingPairs.length; i++) { + const pairAddress = priceTrackingPairs[i] + const pair = Pair.load(pairAddress) + + if (pair === null) { + continue + } + if (pair.token0 == token.id && pair.reserveETH.gt(MINIMUM_LIQUIDITY_THRESHOLD_ETH)) { + let token1 = Token.load(pair.token1) + if (token1 === null) { + continue + } + return pair.token1Price.times(token1.derivedETH as BigDecimal) // return token1 per our token * Eth per token 1 + } + if (pair.token1 == token.id && pair.reserveETH.gt(MINIMUM_LIQUIDITY_THRESHOLD_ETH)) { + let token0 = Token.load(pair.token0) + if (token0 === null) { + continue + } + return pair.token0Price.times(token0.derivedETH as BigDecimal) // return token0 per our token * ETH per token 0 + } + } + + return ZERO_BD // nothing was found return 0 +} + +/** + * Accepts tokens and amounts, return tracked amount based on price tracking tokens + * If one token is a price tracking token, return amount in that token converted to USD. + * If both are, return average of two amounts + * If neither is, return 0 + */ +export function getTrackedVolumeUSD( + tokenAmount0: BigDecimal, + token0: Token, + tokenAmount1: BigDecimal, + token1: Token, + pair: Pair, +): BigDecimal { + let bundle = Bundle.load('1')! + let price0 = token0.derivedETH.times(bundle.ethPrice) + let price1 = token1.derivedETH.times(bundle.ethPrice) + + // dont count tracked volume on these pairs - usually rebass tokens + if (UNTRACKED_PAIRS.includes(pair.id)) { + return ZERO_BD + } + + // if less than 5 LPs, require high minimum reserve amount amount or return 0 + if (pair.liquidityProviderCount.lt(BigInt.fromI32(5))) { + let reserve0USD = pair.reserve0.times(price0) + let reserve1USD = pair.reserve1.times(price1) + if (PRICE_TRACKING_TOKENS.includes(token0.id) && PRICE_TRACKING_TOKENS.includes(token1.id)) { + if (reserve0USD.plus(reserve1USD).lt(MINIMUM_USD_THRESHOLD_NEW_PAIRS)) { + return ZERO_BD + } + } + if (PRICE_TRACKING_TOKENS.includes(token0.id) && !PRICE_TRACKING_TOKENS.includes(token1.id)) { + if (reserve0USD.times(BigDecimal.fromString('2')).lt(MINIMUM_USD_THRESHOLD_NEW_PAIRS)) { + return ZERO_BD + } + } + if (!PRICE_TRACKING_TOKENS.includes(token0.id) && PRICE_TRACKING_TOKENS.includes(token1.id)) { + if (reserve1USD.times(BigDecimal.fromString('2')).lt(MINIMUM_USD_THRESHOLD_NEW_PAIRS)) { + return ZERO_BD + } + } + } + + // both are price tracking tokens, take average of both amounts + if (PRICE_TRACKING_TOKENS.includes(token0.id) && PRICE_TRACKING_TOKENS.includes(token1.id)) { + return tokenAmount0.times(price0).plus(tokenAmount1.times(price1)).div(BigDecimal.fromString('2')) + } + + // take full value of the price tracking token amount + if (PRICE_TRACKING_TOKENS.includes(token0.id) && !PRICE_TRACKING_TOKENS.includes(token1.id)) { + return tokenAmount0.times(price0) + } + + // take full value of the price tracking token amount + if (!PRICE_TRACKING_TOKENS.includes(token0.id) && PRICE_TRACKING_TOKENS.includes(token1.id)) { + return tokenAmount1.times(price1) + } + + // neither token is a price tracking token, tracked volume is 0 + return ZERO_BD +} + +/** + * Accepts tokens and amounts, return tracked amount based on price tracking token list + * If one token is a price tracking token, return amount in that token converted to USD * 2. + * If both are, return sum of two amounts + * If neither is, return 0 + */ +export function getTrackedLiquidityUSD( + tokenAmount0: BigDecimal, + token0: Token, + tokenAmount1: BigDecimal, + token1: Token, +): BigDecimal { + let bundle = Bundle.load('1')! + let price0 = token0.derivedETH.times(bundle.ethPrice) + let price1 = token1.derivedETH.times(bundle.ethPrice) + + // both are price tracking tokens, take average of both amounts + if (PRICE_TRACKING_TOKENS.includes(token0.id) && PRICE_TRACKING_TOKENS.includes(token1.id)) { + return tokenAmount0.times(price0).plus(tokenAmount1.times(price1)) + } + + // take double value of the price tracking token amount + if (PRICE_TRACKING_TOKENS.includes(token0.id) && !PRICE_TRACKING_TOKENS.includes(token1.id)) { + return tokenAmount0.times(price0).times(BigDecimal.fromString('2')) + } + + // take double value of the price tracking token amount + if (!PRICE_TRACKING_TOKENS.includes(token0.id) && PRICE_TRACKING_TOKENS.includes(token1.id)) { + return tokenAmount1.times(price1).times(BigDecimal.fromString('2')) + } + + // neither token is a price tracking token, tracked volume is 0 + return ZERO_BD +} diff --git a/src/v2/mappings/core.ts b/src/v2/mappings/core.ts index ff8a3f3f..69e567b0 100644 --- a/src/v2/mappings/core.ts +++ b/src/v2/mappings/core.ts @@ -233,7 +233,7 @@ export function handleSync(event: Sync): void { token0.save() token1.save() - // get tracked liquidity - will be 0 if neither is in whitelist + // get tracked liquidity - will be 0 if neither is a price tracking token let trackedLiquidityETH: BigDecimal if (bundle.ethPrice.notEqual(ZERO_BD)) { trackedLiquidityETH = getTrackedLiquidityUSD(pair.reserve0, token0 as Token, pair.reserve1, token1 as Token).div( @@ -428,7 +428,7 @@ export function handleSwap(event: Swap): void { let derivedAmountUSD = derivedAmountETH.times(bundle.ethPrice) - // only accounts for volume through white listed tokens + // only accounts for volume through price tracking tokens let trackedAmountUSD = getTrackedVolumeUSD(amount0Total, token0 as Token, amount1Total, token1 as Token, pair as Pair) let trackedAmountETH: BigDecimal diff --git a/src/v2/mappings/factory.ts b/src/v2/mappings/factory.ts index 17489700..af35b14c 100644 --- a/src/v2/mappings/factory.ts +++ b/src/v2/mappings/factory.ts @@ -1,12 +1,19 @@ /* eslint-disable prefer-const */ import { log } from '@graphprotocol/graph-ts' -import { PairCreated } from '../../../generated/Factory/Factory' -import { Bundle, Pair, PairTokenLookup, Token, UniswapFactory } from '../../../generated/schema' -import { Pair as PairTemplate } from '../../../generated/templates' -import { FACTORY_ADDRESS } from '../../common/chain' -import { ZERO_BD, ZERO_BI } from '../../common/constants' -import { fetchTokenDecimals, fetchTokenName, fetchTokenSymbol, fetchTokenTotalSupply } from '../../common/helpers' +import { PairCreated } from '../types/Factory/Factory' +import { Bundle, Pair, PairTokenLookup, Token, UniswapFactory } from '../types/schema' +import { Pair as PairTemplate } from '../types/templates' +import { + FACTORY_ADDRESS, + fetchTokenDecimals, + fetchTokenName, + fetchTokenSymbol, + fetchTokenTotalSupply, + ZERO_BD, + ZERO_BI +} from './helpers' +import { PRICE_TRACKING_TOKENS } from './pricing' export function handleNewPair(event: PairCreated): void { // load factory (create if first exchange) @@ -29,7 +36,7 @@ export function handleNewPair(event: PairCreated): void { factory.pairCount = factory.pairCount + 1 factory.save() - // create the tokens + let pair = new Pair(event.params.pair.toHexString()) as Pair let token0 = Token.load(event.params.token0.toHexString()) let token1 = Token.load(event.params.token1.toHexString()) @@ -53,8 +60,8 @@ export function handleNewPair(event: PairCreated): void { token0.tradeVolumeUSD = ZERO_BD token0.untrackedVolumeUSD = ZERO_BD token0.totalLiquidity = ZERO_BD - // token0.allPairs = [] token0.txCount = ZERO_BI + token0.priceTrackingPairs = [] } // fetch info if null @@ -75,11 +82,21 @@ export function handleNewPair(event: PairCreated): void { token1.tradeVolumeUSD = ZERO_BD token1.untrackedVolumeUSD = ZERO_BD token1.totalLiquidity = ZERO_BD - // token1.allPairs = [] token1.txCount = ZERO_BI + token1.priceTrackingPairs = [] + } + + if (PRICE_TRACKING_TOKENS.includes(token0.id)) { + const priceTrackingPairs = token1.priceTrackingPairs + priceTrackingPairs.push(pair.id) + token1.priceTrackingPairs = priceTrackingPairs + } + if (PRICE_TRACKING_TOKENS.includes(token1.id)) { + const priceTrackingPairs = token0.priceTrackingPairs + priceTrackingPairs.push(pair.id) + token0.priceTrackingPairs = priceTrackingPairs } - let pair = new Pair(event.params.pair.toHexString()) as Pair pair.token0 = token0.id pair.token1 = token1.id pair.liquidityProviderCount = ZERO_BI @@ -109,13 +126,19 @@ export function handleNewPair(event: PairCreated): void { factory.save() let pairLookup0 = new PairTokenLookup( - event.params.token0.toHexString().concat('-').concat(event.params.token1.toHexString()) + event.params.token0 + .toHexString() + .concat('-') + .concat(event.params.token1.toHexString()) ) pairLookup0.pair = pair.id pairLookup0.save() let pairLookup1 = new PairTokenLookup( - event.params.token1.toHexString().concat('-').concat(event.params.token0.toHexString()) + event.params.token1 + .toHexString() + .concat('-') + .concat(event.params.token0.toHexString()) ) pairLookup1.pair = pair.id pairLookup1.save() diff --git a/src/v2/schema.graphql b/src/v2/schema.graphql index 69355925..6257a065 100644 --- a/src/v2/schema.graphql +++ b/src/v2/schema.graphql @@ -52,6 +52,9 @@ type Token @entity { pairDayDataQuote: [PairDayData!]! @derivedFrom(field: "token1") pairBase: [Pair!]! @derivedFrom(field: "token0") pairQuote: [Pair!]! @derivedFrom(field: "token1") + + # pairs used for USD pricing + priceTrackingPairs: [Pair!]! } type Pair @entity { From 604a06d1512ac609b5bfa3864c664d8235b6d4f8 Mon Sep 17 00:00:00 2001 From: Robert Seitz Date: Mon, 15 Sep 2025 16:54:07 -0400 Subject: [PATCH 2/5] add virtual to base and mainnet --- config/base/chain.ts | 1 + config/ethereum/chain.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/config/base/chain.ts b/config/base/chain.ts index 923cff67..164652d9 100644 --- a/config/base/chain.ts +++ b/config/base/chain.ts @@ -10,6 +10,7 @@ export const WHITELIST: string[] = [ '0x4200000000000000000000000000000000000006', // WETH '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913', // USDC '0xd9aaec86b65d86f6a7b5b1b0c42ffa531710b6ca', // USDbCC + '0x0b3e328455c4059eeb9e3f84b5543f74e24e7e1b', // VIRTUAL ] export const STABLECOINS = [ diff --git a/config/ethereum/chain.ts b/config/ethereum/chain.ts index a1362ee9..2bb2d12c 100644 --- a/config/ethereum/chain.ts +++ b/config/ethereum/chain.ts @@ -32,6 +32,7 @@ export const WHITELIST: string[] = [ '0x1f9840a85d5af5bf1d1762f925bdaddc4201f984', // UNI '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599', // WBTC '0x956f47f50a910163d8bf957cf5846d573e7f87ca', // FEI + '0x44ff8620b8ca30902395a7bd3f2407e1a091bf73', // VIRTUAL ] export const STABLECOINS = [] From 86a5a6c7eb4601de54a4b5fa7c141f7c23717c86 Mon Sep 17 00:00:00 2001 From: robert-seitz-uniswap Date: Tue, 16 Sep 2025 14:47:09 +0000 Subject: [PATCH 3/5] fix(lint): auto-fix [ci] --- src/mappings/pricing.ts | 4 ++-- src/v2/mappings/factory.ts | 12 +++--------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/mappings/pricing.ts b/src/mappings/pricing.ts index f2210540..e715e76b 100644 --- a/src/mappings/pricing.ts +++ b/src/mappings/pricing.ts @@ -116,7 +116,7 @@ export function getTrackedVolumeUSD( token0: Token, tokenAmount1: BigDecimal, token1: Token, - pair: Pair, + pair: Pair ): BigDecimal { let bundle = Bundle.load('1')! let price0 = token0.derivedETH.times(bundle.ethPrice) @@ -177,7 +177,7 @@ export function getTrackedLiquidityUSD( tokenAmount0: BigDecimal, token0: Token, tokenAmount1: BigDecimal, - token1: Token, + token1: Token ): BigDecimal { let bundle = Bundle.load('1')! let price0 = token0.derivedETH.times(bundle.ethPrice) diff --git a/src/v2/mappings/factory.ts b/src/v2/mappings/factory.ts index af35b14c..5c88a03f 100644 --- a/src/v2/mappings/factory.ts +++ b/src/v2/mappings/factory.ts @@ -11,7 +11,7 @@ import { fetchTokenSymbol, fetchTokenTotalSupply, ZERO_BD, - ZERO_BI + ZERO_BI, } from './helpers' import { PRICE_TRACKING_TOKENS } from './pricing' @@ -126,19 +126,13 @@ export function handleNewPair(event: PairCreated): void { factory.save() let pairLookup0 = new PairTokenLookup( - event.params.token0 - .toHexString() - .concat('-') - .concat(event.params.token1.toHexString()) + event.params.token0.toHexString().concat('-').concat(event.params.token1.toHexString()) ) pairLookup0.pair = pair.id pairLookup0.save() let pairLookup1 = new PairTokenLookup( - event.params.token1 - .toHexString() - .concat('-') - .concat(event.params.token0.toHexString()) + event.params.token1.toHexString().concat('-').concat(event.params.token0.toHexString()) ) pairLookup1.pair = pair.id pairLookup1.save() From c8662bd40bea5dabe6efc9814a4c6b73a44c624f Mon Sep 17 00:00:00 2001 From: Robert Seitz Date: Thu, 18 Sep 2025 10:23:14 -0400 Subject: [PATCH 4/5] add untracked_pairs --- config/arbitrum-one/chain.ts | 2 ++ config/avalanche/chain.ts | 2 ++ config/base/chain.ts | 2 ++ config/blast-mainnet/chain.ts | 2 ++ config/bsc/chain.ts | 2 ++ config/ethereum/chain.ts | 2 ++ config/matic/chain.ts | 2 ++ config/optimism/chain.ts | 2 ++ config/soneium-mainnet/chain.ts | 2 ++ config/unichain-mainnet/chain.ts | 2 ++ config/worldchain-mainnet/chain.ts | 2 ++ src/mappings/pricing.ts | 51 +++++++++--------------------- 12 files changed, 37 insertions(+), 36 deletions(-) diff --git a/config/arbitrum-one/chain.ts b/config/arbitrum-one/chain.ts index 22025bc3..1ee05f6b 100644 --- a/config/arbitrum-one/chain.ts +++ b/config/arbitrum-one/chain.ts @@ -31,3 +31,5 @@ export class TokenDefinition { export const STATIC_TOKEN_DEFINITIONS: TokenDefinition[] = [] export const SKIP_TOTAL_SUPPLY: string[] = [] + +export const UNTRACKED_PAIRS: string[] = [] diff --git a/config/avalanche/chain.ts b/config/avalanche/chain.ts index e1897eae..49d55bb1 100644 --- a/config/avalanche/chain.ts +++ b/config/avalanche/chain.ts @@ -31,3 +31,5 @@ export class TokenDefinition { export const STATIC_TOKEN_DEFINITIONS: TokenDefinition[] = [] export const SKIP_TOTAL_SUPPLY: string[] = [] + +export const UNTRACKED_PAIRS: string[] = [] diff --git a/config/base/chain.ts b/config/base/chain.ts index 164652d9..029ece2e 100644 --- a/config/base/chain.ts +++ b/config/base/chain.ts @@ -34,3 +34,5 @@ export class TokenDefinition { export const STATIC_TOKEN_DEFINITIONS: TokenDefinition[] = [] export const SKIP_TOTAL_SUPPLY: string[] = [] + +export const UNTRACKED_PAIRS: string[] = [] diff --git a/config/blast-mainnet/chain.ts b/config/blast-mainnet/chain.ts index 768129a0..641ce3d7 100644 --- a/config/blast-mainnet/chain.ts +++ b/config/blast-mainnet/chain.ts @@ -31,3 +31,5 @@ export class TokenDefinition { export const STATIC_TOKEN_DEFINITIONS: TokenDefinition[] = [] export const SKIP_TOTAL_SUPPLY: string[] = [] + +export const UNTRACKED_PAIRS: string[] = [] diff --git a/config/bsc/chain.ts b/config/bsc/chain.ts index 2e8d1cba..829b5b66 100644 --- a/config/bsc/chain.ts +++ b/config/bsc/chain.ts @@ -32,3 +32,5 @@ export class TokenDefinition { export const STATIC_TOKEN_DEFINITIONS: TokenDefinition[] = [] export const SKIP_TOTAL_SUPPLY: string[] = [] + +export const UNTRACKED_PAIRS: string[] = [] diff --git a/config/ethereum/chain.ts b/config/ethereum/chain.ts index 2bb2d12c..696d3a99 100644 --- a/config/ethereum/chain.ts +++ b/config/ethereum/chain.ts @@ -90,3 +90,5 @@ export const STATIC_TOKEN_DEFINITIONS: TokenDefinition[] = [ ] export const SKIP_TOTAL_SUPPLY: string[] = ['0x0000000000bf2686748e1c0255036e7617e7e8a5'] + +export const UNTRACKED_PAIRS: string[] = ['0x9ea3b5b4ec044b70375236a281986106457b20ef'] diff --git a/config/matic/chain.ts b/config/matic/chain.ts index 655682bd..de2766a0 100644 --- a/config/matic/chain.ts +++ b/config/matic/chain.ts @@ -31,3 +31,5 @@ export class TokenDefinition { export const STATIC_TOKEN_DEFINITIONS: TokenDefinition[] = [] export const SKIP_TOTAL_SUPPLY: string[] = [] + +export const UNTRACKED_PAIRS: string[] = [] diff --git a/config/optimism/chain.ts b/config/optimism/chain.ts index f586ef39..172ed42b 100644 --- a/config/optimism/chain.ts +++ b/config/optimism/chain.ts @@ -31,3 +31,5 @@ export class TokenDefinition { export const STATIC_TOKEN_DEFINITIONS: TokenDefinition[] = [] export const SKIP_TOTAL_SUPPLY: string[] = [] + +export const UNTRACKED_PAIRS: string[] = [] diff --git a/config/soneium-mainnet/chain.ts b/config/soneium-mainnet/chain.ts index a73bb92d..3d8da71a 100644 --- a/config/soneium-mainnet/chain.ts +++ b/config/soneium-mainnet/chain.ts @@ -31,3 +31,5 @@ export class TokenDefinition { export const STATIC_TOKEN_DEFINITIONS: TokenDefinition[] = [] export const SKIP_TOTAL_SUPPLY: string[] = [] + +export const UNTRACKED_PAIRS: string[] = [] diff --git a/config/unichain-mainnet/chain.ts b/config/unichain-mainnet/chain.ts index f0c95064..b4ab5285 100644 --- a/config/unichain-mainnet/chain.ts +++ b/config/unichain-mainnet/chain.ts @@ -33,3 +33,5 @@ export class TokenDefinition { export const STATIC_TOKEN_DEFINITIONS: TokenDefinition[] = [] export const SKIP_TOTAL_SUPPLY: string[] = [] + +export const UNTRACKED_PAIRS: string[] = [] diff --git a/config/worldchain-mainnet/chain.ts b/config/worldchain-mainnet/chain.ts index d1e93f3a..42934dce 100644 --- a/config/worldchain-mainnet/chain.ts +++ b/config/worldchain-mainnet/chain.ts @@ -34,3 +34,5 @@ export class TokenDefinition { export const STATIC_TOKEN_DEFINITIONS: TokenDefinition[] = [] export const SKIP_TOTAL_SUPPLY: string[] = [] + +export const UNTRACKED_PAIRS: string[] = [] diff --git a/src/mappings/pricing.ts b/src/mappings/pricing.ts index e715e76b..4afa2219 100644 --- a/src/mappings/pricing.ts +++ b/src/mappings/pricing.ts @@ -1,8 +1,9 @@ /* eslint-disable prefer-const */ import { BigDecimal, BigInt } from '@graphprotocol/graph-ts/index' +import { UNTRACKED_PAIRS, WHITELIST } from '../common/chain' +import { ONE_BD, ZERO_BD } from '../common/constants' import { Bundle, Pair, Token } from '../types/schema' -import { ONE_BD, UNTRACKED_PAIRS, ZERO_BD } from './helpers' const WETH_ADDRESS = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' const USDC_WETH_PAIR = '0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc' // created 10008355 @@ -39,31 +40,6 @@ export function getEthPriceInUSD(): BigDecimal { } } -// token where amounts should contribute to tracked volume and liquidity -export const PRICE_TRACKING_TOKENS: string[] = [ - '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', // WETH - '0x6b175474e89094c44da98b954eedeac495271d0f', // DAI - '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', // USDC - '0xdac17f958d2ee523a2206206994597c13d831ec7', // USDT - '0x0000000000085d4780b73119b644ae5ecd22b376', // TUSD - '0x5d3a536e4d6dbd6114cc1ead35777bab948e3643', // cDAI - '0x39aa39c021dfbae8fac545936693ac917d5e7563', // cUSDC - '0x86fadb80d8d2cff3c3680819e4da99c10232ba0f', // EBASE - '0x57ab1ec28d129707052df4df418d58a2d46d5f51', // sUSD - '0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2', // MKR - '0xc00e94cb662c3520282e6f5717214004a7f26888', // COMP - '0x514910771af9ca656af840dff83e8264ecf986ca', //LINK - '0x960b236a07cf122663c4303350609a66a7b288c0', //ANT - '0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f', //SNX - '0x0bc529c00c6401aef6d220be8c6ea1667f6ad93e', //YFI - '0xdf5e0e81dff6faf3a7e52ba697820c5e32d806a8', // yCurv - '0x853d955acef822db058eb8505911ed77f175b99e', // FRAX - '0xa47c8bf37f92abed4a126bda807a7b7498661acd', // WUST - '0x1f9840a85d5af5bf1d1762f925bdaddc4201f984', // UNI - '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599', // WBTC - '0x956f47f50a910163d8bf957cf5846d573e7f87ca', // FEI -] - // minimum liquidity required to count towards tracked volume for pairs with small # of Lps let MINIMUM_USD_THRESHOLD_NEW_PAIRS = BigDecimal.fromString('400000') @@ -131,17 +107,17 @@ export function getTrackedVolumeUSD( if (pair.liquidityProviderCount.lt(BigInt.fromI32(5))) { let reserve0USD = pair.reserve0.times(price0) let reserve1USD = pair.reserve1.times(price1) - if (PRICE_TRACKING_TOKENS.includes(token0.id) && PRICE_TRACKING_TOKENS.includes(token1.id)) { + if (WHITELIST.includes(token0.id) && WHITELIST.includes(token1.id)) { if (reserve0USD.plus(reserve1USD).lt(MINIMUM_USD_THRESHOLD_NEW_PAIRS)) { return ZERO_BD } } - if (PRICE_TRACKING_TOKENS.includes(token0.id) && !PRICE_TRACKING_TOKENS.includes(token1.id)) { + if (WHITELIST.includes(token0.id) && !WHITELIST.includes(token1.id)) { if (reserve0USD.times(BigDecimal.fromString('2')).lt(MINIMUM_USD_THRESHOLD_NEW_PAIRS)) { return ZERO_BD } } - if (!PRICE_TRACKING_TOKENS.includes(token0.id) && PRICE_TRACKING_TOKENS.includes(token1.id)) { + if (!WHITELIST.includes(token0.id) && WHITELIST.includes(token1.id)) { if (reserve1USD.times(BigDecimal.fromString('2')).lt(MINIMUM_USD_THRESHOLD_NEW_PAIRS)) { return ZERO_BD } @@ -149,17 +125,20 @@ export function getTrackedVolumeUSD( } // both are price tracking tokens, take average of both amounts - if (PRICE_TRACKING_TOKENS.includes(token0.id) && PRICE_TRACKING_TOKENS.includes(token1.id)) { - return tokenAmount0.times(price0).plus(tokenAmount1.times(price1)).div(BigDecimal.fromString('2')) + if (WHITELIST.includes(token0.id) && WHITELIST.includes(token1.id)) { + return tokenAmount0 + .times(price0) + .plus(tokenAmount1.times(price1)) + .div(BigDecimal.fromString('2')) } // take full value of the price tracking token amount - if (PRICE_TRACKING_TOKENS.includes(token0.id) && !PRICE_TRACKING_TOKENS.includes(token1.id)) { + if (WHITELIST.includes(token0.id) && !WHITELIST.includes(token1.id)) { return tokenAmount0.times(price0) } // take full value of the price tracking token amount - if (!PRICE_TRACKING_TOKENS.includes(token0.id) && PRICE_TRACKING_TOKENS.includes(token1.id)) { + if (!WHITELIST.includes(token0.id) && WHITELIST.includes(token1.id)) { return tokenAmount1.times(price1) } @@ -184,17 +163,17 @@ export function getTrackedLiquidityUSD( let price1 = token1.derivedETH.times(bundle.ethPrice) // both are price tracking tokens, take average of both amounts - if (PRICE_TRACKING_TOKENS.includes(token0.id) && PRICE_TRACKING_TOKENS.includes(token1.id)) { + if (WHITELIST.includes(token0.id) && WHITELIST.includes(token1.id)) { return tokenAmount0.times(price0).plus(tokenAmount1.times(price1)) } // take double value of the price tracking token amount - if (PRICE_TRACKING_TOKENS.includes(token0.id) && !PRICE_TRACKING_TOKENS.includes(token1.id)) { + if (WHITELIST.includes(token0.id) && !WHITELIST.includes(token1.id)) { return tokenAmount0.times(price0).times(BigDecimal.fromString('2')) } // take double value of the price tracking token amount - if (!PRICE_TRACKING_TOKENS.includes(token0.id) && PRICE_TRACKING_TOKENS.includes(token1.id)) { + if (!WHITELIST.includes(token0.id) && WHITELIST.includes(token1.id)) { return tokenAmount1.times(price1).times(BigDecimal.fromString('2')) } From 2d3833728d5d979e13604287bfac5a4fce4d01c4 Mon Sep 17 00:00:00 2001 From: robert-seitz-uniswap Date: Thu, 18 Sep 2025 14:24:17 +0000 Subject: [PATCH 5/5] fix(lint): auto-fix [ci] --- src/mappings/pricing.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/mappings/pricing.ts b/src/mappings/pricing.ts index 4afa2219..29e24e07 100644 --- a/src/mappings/pricing.ts +++ b/src/mappings/pricing.ts @@ -126,10 +126,7 @@ export function getTrackedVolumeUSD( // both are price tracking tokens, take average of both amounts if (WHITELIST.includes(token0.id) && WHITELIST.includes(token1.id)) { - return tokenAmount0 - .times(price0) - .plus(tokenAmount1.times(price1)) - .div(BigDecimal.fromString('2')) + return tokenAmount0.times(price0).plus(tokenAmount1.times(price1)).div(BigDecimal.fromString('2')) } // take full value of the price tracking token amount