Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix for bad pricing on wbtc-eth #247

Merged
merged 4 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/mainnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module.exports = {
"0xfe2e637202056d30016725477c5da089ab0a043a", // sETH2
"0x152649ea73beab28c5b49b26eb48f7ead6d4c898", // CAKE
"0x5e8422345238f34275888049021821e8e08caa1f", // fraxETH
"0xae78736cd615f374d3085123a210448e74fc6393", // rETH
],
nonfungiblePositionManagerAddress: "0x46a15b0b27311cedf172ab29e4f4766fbe7f4364",
nonfungiblePositionManagerStartBlock: 16944786,
Expand Down
16 changes: 14 additions & 2 deletions subgraphs/exchange-v3/template/mappings/core.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 18450862
if (transaction.blockNumber.equals(BigInt.fromI32(18450862))) {
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);
token1.derivedUSD = token1.derivedETH.times(bundle.ethPriceUSD);

Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions subgraphs/exchange-v3/template/utils/pricing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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[] {
Expand Down
Loading