From d145a90c61949ceb0fe654ea51c27e771dd7f43b Mon Sep 17 00:00:00 2001 From: ChefJoJo <94336009+chef-jojo@users.noreply.github.com> Date: Mon, 18 Dec 2023 10:24:34 +0800 Subject: [PATCH 1/4] fix: Fix for bad pricing on wbtc-eth --- config/mainnet.js | 1 + subgraphs/exchange-v3/template/mappings/core.ts | 16 ++++++++++++++-- .../exchange-v3/template/subgraph.template.yaml | 4 ++++ subgraphs/exchange-v3/template/subgraph.yaml | 4 ++++ subgraphs/exchange-v3/template/utils/pricing.ts | 4 ++-- 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/config/mainnet.js b/config/mainnet.js index 724e14f7..7fc37527 100644 --- a/config/mainnet.js +++ b/config/mainnet.js @@ -43,6 +43,7 @@ module.exports = { "0xfe2e637202056d30016725477c5da089ab0a043a", // sETH2 "0x152649ea73beab28c5b49b26eb48f7ead6d4c898", // CAKE "0x5e8422345238f34275888049021821e8e08caa1f", // fraxETH + "0xae78736cd615f374d3085123a210448e74fc6393", // rETH ], nonfungiblePositionManagerAddress: "0x46a15b0b27311cedf172ab29e4f4766fbe7f4364", nonfungiblePositionManagerStartBlock: 16944786, diff --git a/subgraphs/exchange-v3/template/mappings/core.ts b/subgraphs/exchange-v3/template/mappings/core.ts index 62b3a262..bb76f40e 100644 --- a/subgraphs/exchange-v3/template/mappings/core.ts +++ b/subgraphs/exchange-v3/template/mappings/core.ts @@ -1,7 +1,7 @@ /* eslint-disable prefer-const */ import { Bundle, Burn, Factory, Mint, Pool, Swap, Tick, Token, Collect } from "../generated/schema"; import { Pool as PoolABI } from "../generated/Factory/Pool"; -import { BigDecimal, BigInt, ethereum } from "@graphprotocol/graph-ts"; +import { BigDecimal, BigInt, ethereum, log } from "@graphprotocol/graph-ts"; import { Burn as BurnEvent, Flash as FlashEvent, @@ -349,11 +349,24 @@ export function handleSwap(event: SwapEvent): void { pool.token1Price = prices[1]; pool.save(); + let token0DerivedETH = token0.derivedETH; + // update USD pricing bundle.ethPriceUSD = getEthPriceInUSD(); bundle.save(); token0.derivedETH = findEthPerToken(token0 as Token); token1.derivedETH = findEthPerToken(token1 as Token); + + let transaction = loadTransaction(event); + + // fix for bad pricing on wbtc-weth + if ( + transaction.id + "#" + pool.txCount.toString() == + "0x5d56353b390e7ffff6df015f20224bdd4ae8487781bbc1d4544de8836b66daa4#2487" + ) { + token0.derivedETH = token0DerivedETH; + } + token0.derivedUSD = token0.derivedETH.times(bundle.ethPriceUSD); token1.derivedUSD = token1.derivedETH.times(bundle.ethPriceUSD); @@ -374,7 +387,6 @@ export function handleSwap(event: SwapEvent): void { ); // create Swap event - let transaction = loadTransaction(event); let swap = new Swap(transaction.id + "#" + pool.txCount.toString()); swap.transaction = transaction.id; swap.timestamp = transaction.timestamp; diff --git a/subgraphs/exchange-v3/template/subgraph.template.yaml b/subgraphs/exchange-v3/template/subgraph.template.yaml index 31d542c8..92c2de14 100644 --- a/subgraphs/exchange-v3/template/subgraph.template.yaml +++ b/subgraphs/exchange-v3/template/subgraph.template.yaml @@ -5,6 +5,10 @@ schema: file: ./schema.graphql features: - nonFatalErrors + - grafting +graft: + base: QmXT8Dy3SWmutmEfseN9B6jbMcXJqCRL8vgaXsy79YyuBq + block: 18450861 dataSources: - kind: ethereum/contract name: Factory diff --git a/subgraphs/exchange-v3/template/subgraph.yaml b/subgraphs/exchange-v3/template/subgraph.yaml index 2633629a..f3bda9bf 100644 --- a/subgraphs/exchange-v3/template/subgraph.yaml +++ b/subgraphs/exchange-v3/template/subgraph.yaml @@ -5,6 +5,10 @@ schema: file: ./schema.graphql features: - nonFatalErrors + - grafting +graft: + base: QmXT8Dy3SWmutmEfseN9B6jbMcXJqCRL8vgaXsy79YyuBq + block: 18450861 dataSources: - kind: ethereum/contract name: Factory diff --git a/subgraphs/exchange-v3/template/utils/pricing.ts b/subgraphs/exchange-v3/template/utils/pricing.ts index 075b6052..9bd625b4 100644 --- a/subgraphs/exchange-v3/template/utils/pricing.ts +++ b/subgraphs/exchange-v3/template/utils/pricing.ts @@ -9,7 +9,7 @@ const WETH_ADDRESS = "0x5aea5775959fbc2557cc8789bc1bf90a239d9a91"; // prettier-ignore const USDC_WETH_03_POOL = "0x291d9f9764c72c9ba6ff47b451a9f7885ebf9977"; -const STABLE_IS_TOKEN0 = "true" as string; +const STABLE_IS_TOKEN0 = "false" as string; // token where amounts should contribute to tracked volume and liquidity // usually tokens that many tokens are paired with s @@ -19,7 +19,7 @@ export let WHITELIST_TOKENS: string[] = "0x5aea5775959fbc2557cc8789bc1bf90a239d9 // prettier-ignore let STABLE_COINS: string[] = "0x493257fd37edb34451f62edf8d2a0c418852ba4c,0x3355df6d4c9c3035724fd0e3914de96a5a83aaf4,0x2039bb4116b4efc145ec4f0e2ea75012d6c0f181,0x4b9eb6c0b6ea15176bbf62841c6b2a8a398cb656,0x8e86e46278518efc1c5ced245cba2c7e3ef11557".split(","); -let MINIMUM_ETH_LOCKED = BigDecimal.fromString("0"); +let MINIMUM_ETH_LOCKED = BigDecimal.fromString("5"); let Q192 = 2 ** 192; export function sqrtPriceX96ToTokenPrices(sqrtPriceX96: BigInt, token0: Token, token1: Token): BigDecimal[] { From ec8a093331357b423a08570f9cf2637c668cce1a Mon Sep 17 00:00:00 2001 From: ChefJoJo <94336009+chef-jojo@users.noreply.github.com> Date: Fri, 22 Dec 2023 14:19:53 +0800 Subject: [PATCH 2/4] fix on block in eth --- subgraphs/exchange-v3/template/mappings/core.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/subgraphs/exchange-v3/template/mappings/core.ts b/subgraphs/exchange-v3/template/mappings/core.ts index bb76f40e..56acb1be 100644 --- a/subgraphs/exchange-v3/template/mappings/core.ts +++ b/subgraphs/exchange-v3/template/mappings/core.ts @@ -359,11 +359,9 @@ export function handleSwap(event: SwapEvent): void { let transaction = loadTransaction(event); - // fix for bad pricing on wbtc-weth - if ( - transaction.id + "#" + pool.txCount.toString() == - "0x5d56353b390e7ffff6df015f20224bdd4ae8487781bbc1d4544de8836b66daa4#2487" - ) { + // fix for bad pricing on wbtc-weth 18450862 + if (transaction.blockNumber.equals(BigInt.fromI32(18450862))) { + log.warning("bad pricing id: {}, token0: {}", [transaction.id, token0.derivedETH.toString()]); token0.derivedETH = token0DerivedETH; } From 276d779c15fea0982221564b53b9d0f59d63c819 Mon Sep 17 00:00:00 2001 From: ChefJoJo <94336009+chef-jojo@users.noreply.github.com> Date: Fri, 22 Dec 2023 14:21:10 +0800 Subject: [PATCH 3/4] remove grafting --- subgraphs/exchange-v3/template/subgraph.template.yaml | 4 ---- subgraphs/exchange-v3/template/subgraph.yaml | 4 ---- 2 files changed, 8 deletions(-) diff --git a/subgraphs/exchange-v3/template/subgraph.template.yaml b/subgraphs/exchange-v3/template/subgraph.template.yaml index 92c2de14..31d542c8 100644 --- a/subgraphs/exchange-v3/template/subgraph.template.yaml +++ b/subgraphs/exchange-v3/template/subgraph.template.yaml @@ -5,10 +5,6 @@ schema: file: ./schema.graphql features: - nonFatalErrors - - grafting -graft: - base: QmXT8Dy3SWmutmEfseN9B6jbMcXJqCRL8vgaXsy79YyuBq - block: 18450861 dataSources: - kind: ethereum/contract name: Factory diff --git a/subgraphs/exchange-v3/template/subgraph.yaml b/subgraphs/exchange-v3/template/subgraph.yaml index f3bda9bf..2633629a 100644 --- a/subgraphs/exchange-v3/template/subgraph.yaml +++ b/subgraphs/exchange-v3/template/subgraph.yaml @@ -5,10 +5,6 @@ schema: file: ./schema.graphql features: - nonFatalErrors - - grafting -graft: - base: QmXT8Dy3SWmutmEfseN9B6jbMcXJqCRL8vgaXsy79YyuBq - block: 18450861 dataSources: - kind: ethereum/contract name: Factory From 751a0fff805e08b0cb1b20f7747df7725ca44701 Mon Sep 17 00:00:00 2001 From: ChefJoJo <94336009+chef-jojo@users.noreply.github.com> Date: Wed, 27 Mar 2024 14:24:18 +0800 Subject: [PATCH 4/4] push fix for eth only --- subgraphs/exchange-v3/template/mappings/core.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/subgraphs/exchange-v3/template/mappings/core.ts b/subgraphs/exchange-v3/template/mappings/core.ts index 56acb1be..8a78782b 100644 --- a/subgraphs/exchange-v3/template/mappings/core.ts +++ b/subgraphs/exchange-v3/template/mappings/core.ts @@ -361,8 +361,10 @@ export function handleSwap(event: SwapEvent): void { // fix for bad pricing on wbtc-weth 18450862 if (transaction.blockNumber.equals(BigInt.fromI32(18450862))) { - log.warning("bad pricing id: {}, token0: {}", [transaction.id, token0.derivedETH.toString()]); - token0.derivedETH = token0DerivedETH; + if (token0.id == "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599") { + log.warning("bad pricing id: {}, token0: {}", [transaction.id, token0.derivedETH.toString()]); + token0.derivedETH = token0DerivedETH; + } } token0.derivedUSD = token0.derivedETH.times(bundle.ethPriceUSD);