diff --git a/subgraphs/polygon-bridge/src/prices/README.md b/subgraphs/polygon-bridge/src/prices/README.md index 51fc9fb576..a21d78286a 100644 --- a/subgraphs/polygon-bridge/src/prices/README.md +++ b/subgraphs/polygon-bridge/src/prices/README.md @@ -3,6 +3,7 @@ ## Configuration In `subgraph.yaml`, add the following code snippet inside the `abis` section of the `datasources` which is going to fetch prices of token using the `Price Oracle`. +
**NOTE**: Include the following code snippet in each of the datasources, that is dependent on the `Price Oracle` and update imports in each file inside oracle folder. ``` @@ -46,9 +47,21 @@ Following are some ways through which you can get the prices of tokens: ``` import { BigDecimal } from "@graphprotocol/graph-ts"; -import { getUsdPricePerToken, getUsdPrice } from "../Oracle"; +import { getUsdPrice, getUsdPricePerToken, getLiquidityBoundPrice } from "../Oracle"; // Method 1 +// Using function getUsdPrice(tokenAddr: Address, amount: BigDecimal): BigDecimal + +let tokenPrice = getUsdPrice(tokenAddr, amount); +``` + +> Note: Preferred as it internally calls `getLiquidityBoundPrice(...)` and returns token price bounded by it's pool's liquidity. +>
+> To get the price per token, you can still use `getUsdPrice(...)` as: +>

> `let tokenPrice = getUsdPrice(tokenAddr, BIGDECIMAL_ONE);` + +``` +// Method 2 // Using function getUsdPricePerToken(tokenAddr: Address): CustomPriceType let tokenPrice: BigDecimal; @@ -57,18 +70,33 @@ let fetchPrice = getUsdPricePerToken(tokenAddr); // fetchPrice.reverted: Bool // fetchPrice.usdPrice: BigDecimal // fetchPrice.decimals: number - -tokenPrice = fetchPrice.usdPrice * amount - -// Method 2 -// Using function getUsdPrice(tokenAddr: Address, amount: BigDecimal): BigDecimal - -let tokenPrice = getUsdPrice(tokenAddr, amount); +// fetchPrice.oracleType: string +// fetchPrice.liquidity: BigDecimal + +if (!fetchPrice.reverted) { + if ( + fetchPrice.oracleType == constants.OracleType.UNISWAP_FORKS_ROUTER || + fetchPrice.oracleType == constants.OracleType.CURVE_ROUTER + ) { + fetchPrice = getLiquidityBoundPrice(tokenAddr, fetchPrice, amount) + } + tokenPrice = fetchPrice.usdPrice * amount +} ``` ## Optimizations -- Reorder the methods present in `index.ts`, depending on which method works best for you. +- Configure default `number of oracles` to fetch price from and their `order of preference` in OracleType's constructor, depending on which oracles _generally_ works best for you. +- Although querying multiple oracles for the same token's price mean more contract calls, this overhead can be beared for smaller subgraphs, and for specific tokens/block ranges for larger ones in favour of spotting and ignoring outlier values by avoiding complete reliance on a single source of truth and trusting the closer majority values, especially for low/distributed liquidity tokens, or during volatile markets. +

+ The result is an average price on the k-closest reported values. +
+ where, `k = ceil(reportedPrices.length/2)` +- For any observed pricing discrepancies, you may define an override on the default oracle configuration in network's config file which works better for the mispriced token(s). +
+ An example override is defined under `ORACLE CONFIG OVERRIDES` section in `config/template.ts` +

+ Any new overrides shall be maintained in both the subgraph as well as the reference pricelib directory, so the same inconsistencies do not have to be handled separately. ## Folder Structure @@ -86,13 +114,17 @@ Prices │ ├── aurora.ts │ ├── avalanche.ts │ ├── bsc.ts +│ ├── celo.ts +│ ├── cronos.ts │ ├── fantom.ts +│ ├── fuse.ts │ ├── gnosis.ts │ ├── harmony.ts │ ├── mainnet.ts │ ├── moonbeam.ts │ ├── optimism.ts -│ └── polygon.ts +│ ├── polygon.ts +│ └── template.ts ├── oracles │ ├── AaveOracle.ts │ ├── ChainLinkFeed.ts @@ -154,6 +186,21 @@ Prices | | `0x10ED43C718714eb63d5aA57B78B54704E256024E` | `6810080` | ✅ | | | `0x05fF2B0DB69458A0750badebc4f9e13aDd608C7F` | `586899` | ✅ | +### Celo + +| **Method** | **Address** | **StartBlock** | **MultiCall** | +| ------------ | :------------------------------------------: | :------------: | :-----------: | +| UniswapForks | | | | +| | `0xe3d8bd6aed4f159bc8000a9cd47cffdb95f96121` | `5272598` | ✅ | +| | `0x1b02da8cb0d097eb8d57a175b88c7d8b47997506` | `7254057` | ✅ | + +### Cronos + +| **Method** | **Address** | **StartBlock** | **MultiCall** | +| ------------ | :------------------------------------------: | :------------: | :-----------: | +| UniswapForks | | | | +| | `0x145863eb42cf62847a6ca784e6416c1682b1b2ae` | `5247` | ✅ | + ### Fantom | **Method** | **Address** | **StartBlock** | **MultiCall** | @@ -169,6 +216,14 @@ Prices | | `0x16327E3FbDaCA3bcF7E38F5Af2599D2DDc33aE52` | `4250168` | ✅ | | | `0x1b02da8cb0d097eb8d57a175b88c7d8b47997506` | `2457904` | ✅ | +### Fuse + +| **Method** | **Address** | **StartBlock** | **MultiCall** | +| ------------ | :------------------------------------------: | :------------: | :-----------: | +| UniswapForks | | | | +| | `0xe3f85aad0c8dd7337427b9df5d0fb741d65eeeb5` | `15645719` | ✅ | +| | `0x1b02da8cb0d097eb8d57a175b88c7d8b47997506` | `12936314` | ✅ | + ### Gnosis | **Method** | **Address** | **StartBlock** | **MultiCall** | diff --git a/subgraphs/polygon-bridge/src/prices/calculations/CalculationsCurve.ts b/subgraphs/polygon-bridge/src/prices/calculations/CalculationsCurve.ts index 06a9487014..c665371c42 100644 --- a/subgraphs/polygon-bridge/src/prices/calculations/CalculationsCurve.ts +++ b/subgraphs/polygon-bridge/src/prices/calculations/CalculationsCurve.ts @@ -1,25 +1,34 @@ import * as utils from "../common/utils"; import * as constants from "../common/constants"; -import { CustomPriceType } from "../common/types"; -import { Address, BigDecimal, BigInt } from "@graphprotocol/graph-ts"; +import { CustomPriceType, OracleContract } from "../common/types"; +import { Address, BigDecimal, BigInt, ethereum } from "@graphprotocol/graph-ts"; import { CalculationsCurve as CalculationsCurveContract } from "../../../generated/FxERC20Events/CalculationsCurve"; export function getCalculationsCurveContract( - contractAddress: Address + contract: OracleContract, + block: ethereum.Block | null = null ): CalculationsCurveContract | null { - if (utils.isNullAddress(contractAddress)) return null; + if ( + (block && contract.startBlock.gt(block.number)) || + utils.isNullAddress(contract.address) + ) + return null; - return CalculationsCurveContract.bind(contractAddress); + return CalculationsCurveContract.bind(contract.address); } -export function getTokenPriceUSDC(tokenAddr: Address): CustomPriceType { +export function getTokenPriceUSDC( + tokenAddr: Address, + block: ethereum.Block | null = null +): CustomPriceType { const config = utils.getConfig(); if (!config || config.curveCalculationsBlacklist().includes(tokenAddr)) return new CustomPriceType(); const calculationCurveContract = getCalculationsCurveContract( - config.curveCalculations() + config.curveCalculations(), + block ); if (!calculationCurveContract) return new CustomPriceType(); @@ -32,6 +41,7 @@ export function getTokenPriceUSDC(tokenAddr: Address): CustomPriceType { return CustomPriceType.initialize( tokenPrice, - constants.DEFAULT_USDC_DECIMALS + constants.DEFAULT_USDC_DECIMALS, + constants.OracleType.CURVE_CALCULATIONS ); } diff --git a/subgraphs/polygon-bridge/src/prices/calculations/CalculationsSushiswap.ts b/subgraphs/polygon-bridge/src/prices/calculations/CalculationsSushiswap.ts index d69ae96dfd..e20057a595 100644 --- a/subgraphs/polygon-bridge/src/prices/calculations/CalculationsSushiswap.ts +++ b/subgraphs/polygon-bridge/src/prices/calculations/CalculationsSushiswap.ts @@ -1,37 +1,47 @@ import * as utils from "../common/utils"; import * as constants from "../common/constants"; -import { CustomPriceType } from "../common/types"; -import { Address, BigDecimal, BigInt } from "@graphprotocol/graph-ts"; +import { CustomPriceType, OracleContract } from "../common/types"; +import { Address, BigDecimal, BigInt, ethereum } from "@graphprotocol/graph-ts"; import { CalculationsSushiSwap as CalculationsSushiContract } from "../../../generated/FxERC20Events/CalculationsSushiSwap"; export function getSushiSwapContract( - contractAddress: Address + contract: OracleContract, + block: ethereum.Block | null = null ): CalculationsSushiContract | null { - if (utils.isNullAddress(contractAddress)) return null; + if ( + (block && contract.startBlock.gt(block.number)) || + utils.isNullAddress(contract.address) + ) + return null; - return CalculationsSushiContract.bind(contractAddress); + return CalculationsSushiContract.bind(contract.address); } -export function getTokenPriceUSDC(tokenAddr: Address): CustomPriceType { +export function getTokenPriceUSDC( + tokenAddr: Address, + block: ethereum.Block | null = null +): CustomPriceType { const config = utils.getConfig(); if (!config || config.sushiCalculationsBlacklist().includes(tokenAddr)) return new CustomPriceType(); - const sushiContract = getSushiSwapContract(config.sushiCalculations()); - if (!sushiContract) { - return new CustomPriceType(); - } + const calculationSushiContract = getSushiSwapContract( + config.sushiCalculations(), + block + ); + if (!calculationSushiContract) return new CustomPriceType(); const tokenPrice: BigDecimal = utils .readValue( - sushiContract.try_getPriceUsdc(tokenAddr), + calculationSushiContract.try_getPriceUsdc(tokenAddr), constants.BIGINT_ZERO ) .toBigDecimal(); return CustomPriceType.initialize( tokenPrice, - constants.DEFAULT_USDC_DECIMALS + constants.DEFAULT_USDC_DECIMALS, + constants.OracleType.SUSHI_CALCULATIONS ); } diff --git a/subgraphs/polygon-bridge/src/prices/common/constants.ts b/subgraphs/polygon-bridge/src/prices/common/constants.ts index 09801cf65f..334b84bad5 100644 --- a/subgraphs/polygon-bridge/src/prices/common/constants.ts +++ b/subgraphs/polygon-bridge/src/prices/common/constants.ts @@ -9,11 +9,30 @@ export namespace NULL { export const TYPE_ADDRESS = Address.fromString(TYPE_STRING); } +export namespace OracleType { + export const AAVE_ORACLE = "AaveOracle"; + export const CURVE_ROUTER = "CurveRouter"; + export const CHAINLINK_FEED = "ChainlinkFeed"; + export const YEARN_LENS_ORACLE = "YearnLensOracle"; + export const CURVE_CALCULATIONS = "CurveCalculations"; + export const UNISWAP_FORKS_ROUTER = "UniswapForksRouter"; + export const SUSHI_CALCULATIONS = "SushiswapCalculations"; +} + export const CHAIN_LINK_USD_ADDRESS = Address.fromString( "0x0000000000000000000000000000000000000348" ); -export const PRICE_LIB_VERSION = "1.1.0"; +export const PRICE_LIB_VERSION = "1.3.1"; + +export const INT_ZERO = 0 as i32; +export const INT_ONE = 1 as i32; +export const INT_TWO = 2 as i32; +export const INT_THREE = 3 as i32; +export const INT_FOUR = 4 as i32; +export const INT_FIVE = 5 as i32; +export const INT_SIX = 6 as i32; +export const INT_NEGATIVE_ONE = -1 as i32; export const BIGINT_ZERO = BigInt.fromI32(0); export const BIGINT_ONE = BigInt.fromI32(1); diff --git a/subgraphs/polygon-bridge/src/prices/common/types.ts b/subgraphs/polygon-bridge/src/prices/common/types.ts index 00f1439754..e91036e356 100644 --- a/subgraphs/polygon-bridge/src/prices/common/types.ts +++ b/subgraphs/polygon-bridge/src/prices/common/types.ts @@ -1,5 +1,5 @@ import * as constants from "./constants"; -import { Address, BigDecimal, BigInt } from "@graphprotocol/graph-ts"; +import { Address, BigDecimal, BigInt, ethereum } from "@graphprotocol/graph-ts"; export class Wrapped { inner: T; @@ -9,23 +9,52 @@ export class Wrapped { } } +export class OracleContract { + private _contractAddress: string; + private _contractStartBlock: i32; + + constructor( + contractAddress: string = constants.NULL.TYPE_STRING, + startBlock: i32 = -1 + ) { + this._contractAddress = contractAddress; + this._contractStartBlock = startBlock; + } + + get address(): Address { + return Address.fromString(this._contractAddress); + } + + get startBlock(): BigInt { + return BigInt.fromI32(this._contractStartBlock); + } +} + export class CustomPriceType { // `null` indicates a reverted call. private _usdPrice: Wrapped; private _decimals: Wrapped; + private _oracleType: string; + private _liquidity: Wrapped; constructor() { this._usdPrice = new Wrapped(constants.BIGDECIMAL_ZERO); this._decimals = new Wrapped(constants.BIGINT_ZERO.toI32() as u8); + this._oracleType = ""; + this._liquidity = new Wrapped(constants.BIGDECIMAL_ZERO); } static initialize( _usdPrice: BigDecimal, - _decimals: i32 = 0 + _decimals: i32 = 0, + _oracleType: string = "", + _liquidity: BigDecimal | null = null ): CustomPriceType { const result = new CustomPriceType(); result._usdPrice = new Wrapped(_usdPrice); result._decimals = new Wrapped(_decimals as u8); + result._oracleType = _oracleType; + if (_liquidity) result._liquidity = new Wrapped(_liquidity); return result; } @@ -43,32 +72,76 @@ export class CustomPriceType { get decimals(): i32 { return changetype>(this._decimals).inner; } + + get oracleType(): string { + return this._oracleType; + } + + get liquidity(): BigDecimal { + return this._liquidity.inner; + } + + setLiquidity(liquidity: BigDecimal): void { + this._liquidity = new Wrapped(liquidity); + } +} + +export interface OracleConfig { + oracleCount(): number; + oracleOrder(): string[]; +} + +export class OracleType { + oracleCount: number; + oracleOrder: string[]; + + constructor() { + this.oracleCount = constants.INT_THREE; + this.oracleOrder = [ + constants.OracleType.YEARN_LENS_ORACLE, + constants.OracleType.CHAINLINK_FEED, + constants.OracleType.CURVE_CALCULATIONS, + constants.OracleType.SUSHI_CALCULATIONS, + constants.OracleType.CURVE_ROUTER, + constants.OracleType.UNISWAP_FORKS_ROUTER, + ]; + } + + setOracleConfig(override: OracleConfig): void { + this.oracleCount = override.oracleCount(); + this.oracleOrder = override.oracleOrder(); + } } export interface Configurations { network(): string; - yearnLens(): Address; - chainLink(): Address; + yearnLens(): OracleContract; + chainLink(): OracleContract; yearnLensBlacklist(): Address[]; - aaveOracle(): Address; + aaveOracle(): OracleContract; aaveOracleBlacklist(): Address[]; - curveCalculations(): Address; + curveCalculations(): OracleContract; curveCalculationsBlacklist(): Address[]; - sushiCalculations(): Address; + sushiCalculations(): OracleContract; sushiCalculationsBlacklist(): Address[]; - uniswapForks(): Address[]; - curveRegistry(): Address[]; + uniswapForks(): OracleContract[]; + curveRegistry(): OracleContract[]; hardcodedStables(): Address[]; ignoreList(): Address[]; + ethAddress(): Address; wethAddress(): Address; usdcAddress(): Address; usdcTokenDecimals(): BigInt; + getOracleOverride( + tokenAddr: Address | null, + block: ethereum.Block | null + ): OracleConfig | null; } diff --git a/subgraphs/polygon-bridge/src/prices/common/utils.ts b/subgraphs/polygon-bridge/src/prices/common/utils.ts index 3f69784aa2..7a44400ee3 100644 --- a/subgraphs/polygon-bridge/src/prices/common/utils.ts +++ b/subgraphs/polygon-bridge/src/prices/common/utils.ts @@ -1,5 +1,8 @@ import * as BSC from "../config/bsc"; +import * as CELO from "../config/celo"; +import * as FUSE from "../config/fuse"; import * as XDAI from "../config/gnosis"; +import * as CRONOS from "../config/cronos"; import * as AURORA from "../config/aurora"; import * as FANTOM from "../config/fantom"; import * as POLYGON from "../config/polygon"; @@ -10,11 +13,17 @@ import * as OPTIMISM from "../config/optimism"; import * as AVALANCHE from "../config/avalanche"; import * as ARBITRUM_ONE from "../config/arbitrum"; -import { Configurations } from "./types"; +import { Configurations, CustomPriceType } from "./types"; import * as constants from "./constants"; import * as TEMPLATE from "../config/template"; import { _ERC20 } from "../../../generated/FxERC20Events/_ERC20"; -import { Address, BigInt, dataSource, ethereum } from "@graphprotocol/graph-ts"; +import { + Address, + BigInt, + BigDecimal, + dataSource, + ethereum, +} from "@graphprotocol/graph-ts"; export function isNullAddress(tokenAddr: Address): boolean { return tokenAddr.equals(constants.NULL.TYPE_ADDRESS); @@ -81,7 +90,83 @@ export function getConfig(): Configurations { return new AVALANCHE.config(); } else if (network == ARBITRUM_ONE.NETWORK_STRING) { return new ARBITRUM_ONE.config(); + } else if (network == CRONOS.NETWORK_STRING) { + return new CRONOS.config(); + } else if (network == CELO.NETWORK_STRING) { + return new CELO.config(); + } else if (network == FUSE.NETWORK_STRING) { + return new FUSE.config(); } return new TEMPLATE.config(); } + +function sortByPrices(prices: CustomPriceType[]): CustomPriceType[] { + const pricesSorted = prices.sort(function (a, b) { + const x = a.usdPrice; + const y = b.usdPrice; + + if (x < y) return -1; + if (x > y) return 1; + return 0; + }); + + return pricesSorted; +} + +function pairwiseDiffOfPrices(prices: CustomPriceType[]): BigDecimal[] { + const diff: BigDecimal[] = []; + for (let i = 1; i < prices.length; i++) { + const x = prices[i].usdPrice; + const y = prices[i - 1].usdPrice; + + diff.push(x.minus(y)); + } + + return diff; +} + +export function kClosestPrices( + k: i32, + prices: CustomPriceType[] +): CustomPriceType[] { + // sort by USD prices + const pricesSorted = sortByPrices(prices); + + // pairwise difference in USD prices + const pairwiseDiff = pairwiseDiffOfPrices(pricesSorted); + + // k minimum difference values and their original indexes + const pairwiseDiffCopy = pairwiseDiff.map((x: BigDecimal) => x); + const pairwiseDiffSortedSlice = pairwiseDiffCopy.sort().slice(0, k); + const minDiffAtIdx: i32[] = []; + for (let i = 0; i < pairwiseDiffSortedSlice.length; i++) { + const idx = pairwiseDiff.indexOf(pairwiseDiffSortedSlice[i]); + minDiffAtIdx.push(idx as i32); + } + + // k closest USD price values + const kClosestPrices: CustomPriceType[] = []; + for (let i = 0; i < minDiffAtIdx.length; i++) { + if (!kClosestPrices.includes(pricesSorted[minDiffAtIdx[i]])) { + kClosestPrices.push(pricesSorted[minDiffAtIdx[i]]); + } + if (!kClosestPrices.includes(pricesSorted[minDiffAtIdx[i] + 1])) { + kClosestPrices.push(pricesSorted[minDiffAtIdx[i] + 1]); + } + } + + return kClosestPrices; +} + +export function averagePrice(prices: CustomPriceType[]): CustomPriceType { + let summationUSDPrice = constants.BIGDECIMAL_ZERO; + for (let i = 0; i < prices.length; i++) { + summationUSDPrice = summationUSDPrice.plus(prices[i].usdPrice); + } + + return CustomPriceType.initialize( + summationUSDPrice.div(new BigDecimal(BigInt.fromI32(prices.length as i32))), + constants.DEFAULT_USDC_DECIMALS + ); +} diff --git a/subgraphs/polygon-bridge/src/prices/config/arbitrum.ts b/subgraphs/polygon-bridge/src/prices/config/arbitrum.ts index 9c462bdd94..49443ffa72 100644 --- a/subgraphs/polygon-bridge/src/prices/config/arbitrum.ts +++ b/subgraphs/polygon-bridge/src/prices/config/arbitrum.ts @@ -1,6 +1,6 @@ -import * as constants from "../common/constants"; -import { Configurations } from "../common/types"; -import { Address, BigInt } from "@graphprotocol/graph-ts"; +/* eslint-disable @typescript-eslint/no-magic-numbers, @typescript-eslint/no-unused-vars */ +import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts"; +import { Configurations, OracleConfig, OracleContract } from "../common/types"; export const NETWORK_STRING = "arbitrum-one"; @@ -8,36 +8,40 @@ export const NETWORK_STRING = "arbitrum-one"; ///////////////////// CALCULATIONS/ORACLE CONTRACT //////////////////////// /////////////////////////////////////////////////////////////////////////// -export const YEARN_LENS_CONTRACT_ADDRESS = Address.fromString( - "0x043518ab266485dc085a1db095b8d9c2fc78e9b9" +export const YEARN_LENS_CONTRACT_ADDRESS = new OracleContract( + "0x043518ab266485dc085a1db095b8d9c2fc78e9b9", + 2396321 ); -export const CHAIN_LINK_CONTRACT_ADDRESS = constants.NULL.TYPE_ADDRESS; -export const AAVE_ORACLE_CONTRACT_ADDRESS = Address.fromString( - "0xb56c2F0B653B2e0b10C9b928C8580Ac5Df02C7C7" +export const AAVE_ORACLE_CONTRACT_ADDRESS = new OracleContract( + "0xb56c2f0b653b2e0b10c9b928c8580ac5df02c7c7", + 7740843 ); -export const SUSHISWAP_CALCULATIONS_ADDRESS = Address.fromString( - "0x5ea7e501c9a23f4a76dc7d33a11d995b13a1dd25" +export const SUSHISWAP_CALCULATIONS_ADDRESS = new OracleContract( + "0x5ea7e501c9a23f4a76dc7d33a11d995b13a1dd25", + 2396120 ); +export const CHAIN_LINK_CONTRACT_ADDRESS = new OracleContract(); /////////////////////////////////////////////////////////////////////////// ///////////////////////////// CURVE CONTRACT ////////////////////////////// /////////////////////////////////////////////////////////////////////////// -export const CURVE_CALCULATIONS_ADDRESS = Address.fromString( - "0x3268c3bda100ef0ff3c2d044f23eab62c80d78d2" +export const CURVE_CALCULATIONS_ADDRESS = new OracleContract( + "0x3268c3bda100ef0ff3c2d044f23eab62c80d78d2", + 11707234 ); -export const CURVE_REGISTRY_ADDRESSES: Address[] = [ - Address.fromString("0x445FE580eF8d70FF569aB36e80c647af338db351"), - Address.fromString("0x0E9fBb167DF83EdE3240D6a5fa5d40c6C6851e15"), +export const CURVE_REGISTRY_ADDRESSES: OracleContract[] = [ + new OracleContract("0x445fe580ef8d70ff569ab36e80c647af338db351", 1362056), + new OracleContract("0x0e9fbb167df83ede3240d6a5fa5d40c6c6851e15", 4530115), ]; /////////////////////////////////////////////////////////////////////////// /////////////////////////// UNISWAP FORKS CONTRACT //////////////////////// /////////////////////////////////////////////////////////////////////////// -export const UNISWAP_FORKS_ROUTER_ADDRESSES: Address[] = [ - Address.fromString("0x1b02da8cb0d097eb8d57a175b88c7d8b47997506"), // SushiSwap +export const UNISWAP_FORKS_ROUTER_ADDRESSES: OracleContract[] = [ + new OracleContract("0x1b02da8cb0d097eb8d57a175b88c7d8b47997506", 73), // SushiSwap ]; /////////////////////////////////////////////////////////////////////////// @@ -53,9 +57,7 @@ export const SUSHI_CALCULATIONS_BLACKSLIST: Address[] = []; //////////////////////////// HARDCODED STABLES //////////////////////////// /////////////////////////////////////////////////////////////////////////// -export const HARDCODED_STABLES: Address[] = [ - Address.fromString("0x3F56e0c36d275367b8C502090EDF38289b3dEa0d"), // MAI -]; +export const HARDCODED_STABLES: Address[] = []; /////////////////////////////////////////////////////////////////////////// ///////////////////////////////// HELPERS ///////////////////////////////// @@ -64,7 +66,7 @@ export const HARDCODED_STABLES: Address[] = [ export const USDC_TOKEN_DECIMALS = BigInt.fromI32(6); export const ETH_ADDRESS = Address.fromString( - "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE" + "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" ); export const WETH_ADDRESS = Address.fromString( "0x82af49447d8a07e3bd95bd0d56f35241523fbab1" @@ -78,41 +80,41 @@ export class config implements Configurations { return NETWORK_STRING; } - yearnLens(): Address { + yearnLens(): OracleContract { return YEARN_LENS_CONTRACT_ADDRESS; } - chainLink(): Address { + chainLink(): OracleContract { return CHAIN_LINK_CONTRACT_ADDRESS; } yearnLensBlacklist(): Address[] { return YEARN_LENS_BLACKLIST; } - aaveOracle(): Address { + aaveOracle(): OracleContract { return AAVE_ORACLE_CONTRACT_ADDRESS; } aaveOracleBlacklist(): Address[] { return AAVE_ORACLE_BLACKLIST; } - curveCalculations(): Address { + curveCalculations(): OracleContract { return CURVE_CALCULATIONS_ADDRESS; } curveCalculationsBlacklist(): Address[] { return CURVE_CALCULATIONS_BLACKSLIST; } - sushiCalculations(): Address { + sushiCalculations(): OracleContract { return SUSHISWAP_CALCULATIONS_ADDRESS; } sushiCalculationsBlacklist(): Address[] { return SUSHI_CALCULATIONS_BLACKSLIST; } - uniswapForks(): Address[] { + uniswapForks(): OracleContract[] { return UNISWAP_FORKS_ROUTER_ADDRESSES; } - curveRegistry(): Address[] { + curveRegistry(): OracleContract[] { return CURVE_REGISTRY_ADDRESSES; } @@ -137,4 +139,11 @@ export class config implements Configurations { usdcTokenDecimals(): BigInt { return USDC_TOKEN_DECIMALS; } + + getOracleOverride( + tokenAddr: Address | null, + block: ethereum.Block | null + ): OracleConfig | null { + return null; + } } diff --git a/subgraphs/polygon-bridge/src/prices/config/aurora.ts b/subgraphs/polygon-bridge/src/prices/config/aurora.ts index 2c62b20a7f..c293b42efe 100644 --- a/subgraphs/polygon-bridge/src/prices/config/aurora.ts +++ b/subgraphs/polygon-bridge/src/prices/config/aurora.ts @@ -1,6 +1,7 @@ -import { Configurations } from "../common/types"; +/* eslint-disable @typescript-eslint/no-magic-numbers, @typescript-eslint/no-unused-vars */ import * as constants from "../common/constants"; -import { Address, BigInt } from "@graphprotocol/graph-ts"; +import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts"; +import { Configurations, OracleConfig, OracleContract } from "../common/types"; export const NETWORK_STRING = "aurora"; @@ -8,27 +9,27 @@ export const NETWORK_STRING = "aurora"; ///////////////////// CALCULATIONS/ORACLE CONTRACT //////////////////////// /////////////////////////////////////////////////////////////////////////// -export const YEARN_LENS_CONTRACT_ADDRESS = constants.NULL.TYPE_ADDRESS; -export const CHAIN_LINK_CONTRACT_ADDRESS = constants.NULL.TYPE_ADDRESS; -export const AAVE_ORACLE_CONTRACT_ADDRESS = constants.NULL.TYPE_ADDRESS; -export const SUSHISWAP_CALCULATIONS_ADDRESS = constants.NULL.TYPE_ADDRESS; +export const YEARN_LENS_CONTRACT_ADDRESS = new OracleContract(); +export const CHAIN_LINK_CONTRACT_ADDRESS = new OracleContract(); +export const AAVE_ORACLE_CONTRACT_ADDRESS = new OracleContract(); +export const SUSHISWAP_CALCULATIONS_ADDRESS = new OracleContract(); /////////////////////////////////////////////////////////////////////////// ///////////////////////////// CURVE CONTRACT ////////////////////////////// /////////////////////////////////////////////////////////////////////////// -export const CURVE_CALCULATIONS_ADDRESS = constants.NULL.TYPE_ADDRESS; +export const CURVE_CALCULATIONS_ADDRESS = new OracleContract(); -export const CURVE_REGISTRY_ADDRESSES: Address[] = [ - Address.fromString("0x5B5CFE992AdAC0C9D48E05854B2d91C73a003858"), +export const CURVE_REGISTRY_ADDRESSES: OracleContract[] = [ + new OracleContract("0x5b5cfe992adac0c9d48e05854b2d91c73a003858", 62440526), ]; /////////////////////////////////////////////////////////////////////////// /////////////////////////// UNISWAP FORKS CONTRACT //////////////////////// /////////////////////////////////////////////////////////////////////////// -export const UNISWAP_FORKS_ROUTER_ADDRESSES: Address[] = [ - Address.fromString("0x2CB45Edb4517d5947aFdE3BEAbF95A582506858B"), // TriSolaris +export const UNISWAP_FORKS_ROUTER_ADDRESSES: OracleContract[] = [ + new OracleContract("0x2cb45edb4517d5947afde3beabf95a582506858b", 49607893), // TriSolaris ]; /////////////////////////////////////////////////////////////////////////// @@ -67,44 +68,41 @@ export class config implements Configurations { return NETWORK_STRING; } - yearnLens(): Address { + yearnLens(): OracleContract { return YEARN_LENS_CONTRACT_ADDRESS; } - chainLink(): Address { + chainLink(): OracleContract { return CHAIN_LINK_CONTRACT_ADDRESS; } yearnLensBlacklist(): Address[] { return YEARN_LENS_BLACKLIST; } - aaveOracle(): Address { + aaveOracle(): OracleContract { return AAVE_ORACLE_CONTRACT_ADDRESS; } aaveOracleBlacklist(): Address[] { return AAVE_ORACLE_BLACKLIST; } - curveCalculations(): Address { + curveCalculations(): OracleContract { return CURVE_CALCULATIONS_ADDRESS; } curveCalculationsBlacklist(): Address[] { return CURVE_CALCULATIONS_BLACKSLIST; } - ignoreList(): Address[] { - return []; - } - sushiCalculations(): Address { + sushiCalculations(): OracleContract { return SUSHISWAP_CALCULATIONS_ADDRESS; } sushiCalculationsBlacklist(): Address[] { return SUSHI_CALCULATIONS_BLACKSLIST; } - uniswapForks(): Address[] { + uniswapForks(): OracleContract[] { return UNISWAP_FORKS_ROUTER_ADDRESSES; } - curveRegistry(): Address[] { + curveRegistry(): OracleContract[] { return CURVE_REGISTRY_ADDRESSES; } @@ -112,6 +110,9 @@ export class config implements Configurations { return HARDCODED_STABLES; } + ignoreList(): Address[] { + return []; + } ethAddress(): Address { return ETH_ADDRESS; } @@ -125,4 +126,11 @@ export class config implements Configurations { usdcTokenDecimals(): BigInt { return USDC_TOKEN_DECIMALS; } + + getOracleOverride( + tokenAddr: Address | null, + block: ethereum.Block | null + ): OracleConfig | null { + return null; + } } diff --git a/subgraphs/polygon-bridge/src/prices/config/avalanche.ts b/subgraphs/polygon-bridge/src/prices/config/avalanche.ts index b522f104cb..7cc2cbc66b 100644 --- a/subgraphs/polygon-bridge/src/prices/config/avalanche.ts +++ b/subgraphs/polygon-bridge/src/prices/config/avalanche.ts @@ -1,6 +1,7 @@ -import { Configurations } from "../common/types"; +/* eslint-disable @typescript-eslint/no-magic-numbers, @typescript-eslint/no-unused-vars */ import * as constants from "../common/constants"; -import { Address, BigInt } from "@graphprotocol/graph-ts"; +import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts"; +import { Configurations, OracleConfig, OracleContract } from "../common/types"; export const NETWORK_STRING = "avalanche"; @@ -8,33 +9,34 @@ export const NETWORK_STRING = "avalanche"; ///////////////////// CALCULATIONS/ORACLE CONTRACT //////////////////////// /////////////////////////////////////////////////////////////////////////// -export const YEARN_LENS_CONTRACT_ADDRESS = constants.NULL.TYPE_ADDRESS; -export const CHAIN_LINK_CONTRACT_ADDRESS = constants.NULL.TYPE_ADDRESS; -export const SUSHISWAP_CALCULATIONS_ADDRESS = constants.NULL.TYPE_ADDRESS; +export const YEARN_LENS_CONTRACT_ADDRESS = new OracleContract(); +export const CHAIN_LINK_CONTRACT_ADDRESS = new OracleContract(); +export const SUSHISWAP_CALCULATIONS_ADDRESS = new OracleContract(); -export const AAVE_ORACLE_CONTRACT_ADDRESS = Address.fromString( - "0xEBd36016B3eD09D4693Ed4251c67Bd858c3c7C9C" +export const AAVE_ORACLE_CONTRACT_ADDRESS = new OracleContract( + "0xebd36016b3ed09d4693ed4251c67bd858c3c7c9c", + 11970477 ); /////////////////////////////////////////////////////////////////////////// ///////////////////////////// CURVE CONTRACT ////////////////////////////// /////////////////////////////////////////////////////////////////////////// -export const CURVE_CALCULATIONS_ADDRESS = constants.NULL.TYPE_ADDRESS; +export const CURVE_CALCULATIONS_ADDRESS = new OracleContract(); -export const CURVE_REGISTRY_ADDRESSES: Address[] = [ - Address.fromString("0x8474DdbE98F5aA3179B3B3F5942D724aFcdec9f6"), - Address.fromString("0x90f421832199e93d01b64DaF378b183809EB0988"), +export const CURVE_REGISTRY_ADDRESSES: OracleContract[] = [ + new OracleContract("0x8474ddbe98f5aa3179b3b3f5942d724afcdec9f6", 5254206), + new OracleContract("0x90f421832199e93d01b64daf378b183809eb0988", 9384663), ]; /////////////////////////////////////////////////////////////////////////// /////////////////////////// UNISWAP FORKS CONTRACT //////////////////////// /////////////////////////////////////////////////////////////////////////// -export const UNISWAP_FORKS_ROUTER_ADDRESSES: Address[] = [ - Address.fromString("0x60aE616a2155Ee3d9A68541Ba4544862310933d4"), // TraderJOE - Address.fromString("0xE54Ca86531e17Ef3616d22Ca28b0D458b6C89106"), // Pangolin - Address.fromString("0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506"), // Sushiswap +export const UNISWAP_FORKS_ROUTER_ADDRESSES: OracleContract[] = [ + new OracleContract("0x60ae616a2155ee3d9a68541ba4544862310933d4", 2486393), // TraderJOE + new OracleContract("0xe54ca86531e17ef3616d22ca28b0d458b6c89106", 56879), // Pangolin + new OracleContract("0x1b02da8cb0d097eb8d57a175b88c7d8b47997506", 506236), // Sushiswap ]; /////////////////////////////////////////////////////////////////////////// @@ -50,9 +52,7 @@ export const SUSHI_CALCULATIONS_BLACKSLIST: Address[] = []; //////////////////////////// HARDCODED STABLES //////////////////////////// /////////////////////////////////////////////////////////////////////////// -export const HARDCODED_STABLES: Address[] = [ - Address.fromString("0x5c49b268c9841AFF1Cc3B0a418ff5c3442eE3F3b"), // MAI -]; +export const HARDCODED_STABLES: Address[] = []; /////////////////////////////////////////////////////////////////////////// ///////////////////////////////// HELPERS ///////////////////////////////// @@ -75,44 +75,41 @@ export class config implements Configurations { return NETWORK_STRING; } - yearnLens(): Address { + yearnLens(): OracleContract { return YEARN_LENS_CONTRACT_ADDRESS; } - chainLink(): Address { + chainLink(): OracleContract { return CHAIN_LINK_CONTRACT_ADDRESS; } yearnLensBlacklist(): Address[] { return YEARN_LENS_BLACKLIST; } - ignoreList(): Address[] { - return []; - } - aaveOracle(): Address { + aaveOracle(): OracleContract { return AAVE_ORACLE_CONTRACT_ADDRESS; } aaveOracleBlacklist(): Address[] { return AAVE_ORACLE_BLACKLIST; } - curveCalculations(): Address { + curveCalculations(): OracleContract { return CURVE_CALCULATIONS_ADDRESS; } curveCalculationsBlacklist(): Address[] { return CURVE_CALCULATIONS_BLACKSLIST; } - sushiCalculations(): Address { + sushiCalculations(): OracleContract { return SUSHISWAP_CALCULATIONS_ADDRESS; } sushiCalculationsBlacklist(): Address[] { return SUSHI_CALCULATIONS_BLACKSLIST; } - uniswapForks(): Address[] { + uniswapForks(): OracleContract[] { return UNISWAP_FORKS_ROUTER_ADDRESSES; } - curveRegistry(): Address[] { + curveRegistry(): OracleContract[] { return CURVE_REGISTRY_ADDRESSES; } @@ -120,6 +117,9 @@ export class config implements Configurations { return HARDCODED_STABLES; } + ignoreList(): Address[] { + return []; + } ethAddress(): Address { return ETH_ADDRESS; } @@ -133,4 +133,11 @@ export class config implements Configurations { usdcTokenDecimals(): BigInt { return USDC_TOKEN_DECIMALS; } + + getOracleOverride( + tokenAddr: Address | null, + block: ethereum.Block | null + ): OracleConfig | null { + return null; + } } diff --git a/subgraphs/polygon-bridge/src/prices/config/bsc.ts b/subgraphs/polygon-bridge/src/prices/config/bsc.ts index 42b995d0b6..3000b1017b 100644 --- a/subgraphs/polygon-bridge/src/prices/config/bsc.ts +++ b/subgraphs/polygon-bridge/src/prices/config/bsc.ts @@ -1,6 +1,7 @@ -import { Configurations } from "../common/types"; +/* eslint-disable @typescript-eslint/no-magic-numbers, @typescript-eslint/no-unused-vars */ import * as constants from "../common/constants"; -import { Address, BigInt } from "@graphprotocol/graph-ts"; +import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts"; +import { Configurations, OracleConfig, OracleContract } from "../common/types"; export const NETWORK_STRING = "bsc"; @@ -8,26 +9,26 @@ export const NETWORK_STRING = "bsc"; ///////////////////// CALCULATIONS/ORACLE CONTRACT //////////////////////// /////////////////////////////////////////////////////////////////////////// -export const YEARN_LENS_CONTRACT_ADDRESS = constants.NULL.TYPE_ADDRESS; -export const CHAIN_LINK_CONTRACT_ADDRESS = constants.NULL.TYPE_ADDRESS; -export const AAVE_ORACLE_CONTRACT_ADDRESS = constants.NULL.TYPE_ADDRESS; -export const SUSHISWAP_CALCULATIONS_ADDRESS = constants.NULL.TYPE_ADDRESS; +export const YEARN_LENS_CONTRACT_ADDRESS = new OracleContract(); +export const CHAIN_LINK_CONTRACT_ADDRESS = new OracleContract(); +export const AAVE_ORACLE_CONTRACT_ADDRESS = new OracleContract(); +export const SUSHISWAP_CALCULATIONS_ADDRESS = new OracleContract(); /////////////////////////////////////////////////////////////////////////// ///////////////////////////// CURVE CONTRACT ////////////////////////////// /////////////////////////////////////////////////////////////////////////// -export const CURVE_CALCULATIONS_ADDRESS = constants.NULL.TYPE_ADDRESS; +export const CURVE_CALCULATIONS_ADDRESS = new OracleContract(); -export const CURVE_REGISTRY_ADDRESSES: Address[] = []; +export const CURVE_REGISTRY_ADDRESSES: OracleContract[] = []; /////////////////////////////////////////////////////////////////////////// /////////////////////////// UNISWAP FORKS CONTRACT //////////////////////// /////////////////////////////////////////////////////////////////////////// -export const UNISWAP_FORKS_ROUTER_ADDRESSES: Address[] = [ - Address.fromString("0x10ED43C718714eb63d5aA57B78B54704E256024E"), // PancakeSwap v2 - Address.fromString("0x05fF2B0DB69458A0750badebc4f9e13aDd608C7F"), // PancakeSwap v1 +export const UNISWAP_FORKS_ROUTER_ADDRESSES: OracleContract[] = [ + new OracleContract("0x10ed43c718714eb63d5aa57b78b54704e256024e", 6810080), // PancakeSwap v2 + new OracleContract("0x05ff2b0db69458a0750badebc4f9e13add608c7f", 586899), // PancakeSwap v1 ]; /////////////////////////////////////////////////////////////////////////// @@ -43,10 +44,7 @@ export const SUSHI_CALCULATIONS_BLACKSLIST: Address[] = []; //////////////////////////// HARDCODED STABLES //////////////////////////// /////////////////////////////////////////////////////////////////////////// -export const HARDCODED_STABLES: Address[] = [ - Address.fromString("0xd17479997F34dd9156Deef8F95A52D81D265be9c"), // USDD - Address.fromString("0x3F56e0c36d275367b8C502090EDF38289b3dEa0d"), // MAI -]; +export const HARDCODED_STABLES: Address[] = []; /////////////////////////////////////////////////////////////////////////// ///////////////////////////////// HELPERS ///////////////////////////////// @@ -55,7 +53,6 @@ export const HARDCODED_STABLES: Address[] = [ export const USDC_TOKEN_DECIMALS = BigInt.fromI32(18); export const ETH_ADDRESS = constants.NULL.TYPE_ADDRESS; - export const WETH_ADDRESS = Address.fromString( "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c" ); @@ -68,44 +65,41 @@ export class config implements Configurations { return NETWORK_STRING; } - yearnLens(): Address { + yearnLens(): OracleContract { return YEARN_LENS_CONTRACT_ADDRESS; } - chainLink(): Address { + chainLink(): OracleContract { return CHAIN_LINK_CONTRACT_ADDRESS; } yearnLensBlacklist(): Address[] { return YEARN_LENS_BLACKLIST; } - aaveOracle(): Address { + aaveOracle(): OracleContract { return AAVE_ORACLE_CONTRACT_ADDRESS; } aaveOracleBlacklist(): Address[] { return AAVE_ORACLE_BLACKLIST; } - curveCalculations(): Address { + curveCalculations(): OracleContract { return CURVE_CALCULATIONS_ADDRESS; } curveCalculationsBlacklist(): Address[] { return CURVE_CALCULATIONS_BLACKSLIST; } - ignoreList(): Address[] { - return []; - } - sushiCalculations(): Address { + sushiCalculations(): OracleContract { return SUSHISWAP_CALCULATIONS_ADDRESS; } sushiCalculationsBlacklist(): Address[] { return SUSHI_CALCULATIONS_BLACKSLIST; } - uniswapForks(): Address[] { + uniswapForks(): OracleContract[] { return UNISWAP_FORKS_ROUTER_ADDRESSES; } - curveRegistry(): Address[] { + curveRegistry(): OracleContract[] { return CURVE_REGISTRY_ADDRESSES; } @@ -113,6 +107,9 @@ export class config implements Configurations { return HARDCODED_STABLES; } + ignoreList(): Address[] { + return []; + } ethAddress(): Address { return ETH_ADDRESS; } @@ -126,4 +123,11 @@ export class config implements Configurations { usdcTokenDecimals(): BigInt { return USDC_TOKEN_DECIMALS; } + + getOracleOverride( + tokenAddr: Address | null, + block: ethereum.Block | null + ): OracleConfig | null { + return null; + } } diff --git a/subgraphs/polygon-bridge/src/prices/config/celo.ts b/subgraphs/polygon-bridge/src/prices/config/celo.ts new file mode 100644 index 0000000000..cb48654cf8 --- /dev/null +++ b/subgraphs/polygon-bridge/src/prices/config/celo.ts @@ -0,0 +1,134 @@ +/* eslint-disable @typescript-eslint/no-magic-numbers, @typescript-eslint/no-unused-vars */ +import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts"; +import { Configurations, OracleConfig, OracleContract } from "../common/types"; + +export const NETWORK_STRING = "celo"; + +/////////////////////////////////////////////////////////////////////////// +///////////////////// CALCULATIONS/ORACLE CONTRACT //////////////////////// +/////////////////////////////////////////////////////////////////////////// + +export const YEARN_LENS_CONTRACT_ADDRESS = new OracleContract(); +export const CHAIN_LINK_CONTRACT_ADDRESS = new OracleContract(); +export const AAVE_ORACLE_CONTRACT_ADDRESS = new OracleContract(); +export const SUSHISWAP_CALCULATIONS_ADDRESS = new OracleContract(); + +/////////////////////////////////////////////////////////////////////////// +///////////////////////////// CURVE CONTRACT ////////////////////////////// +/////////////////////////////////////////////////////////////////////////// + +export const CURVE_CALCULATIONS_ADDRESS = new OracleContract(); + +export const CURVE_REGISTRY_ADDRESSES: OracleContract[] = []; + +/////////////////////////////////////////////////////////////////////////// +/////////////////////////// UNISWAP FORKS CONTRACT //////////////////////// +/////////////////////////////////////////////////////////////////////////// + +export const UNISWAP_FORKS_ROUTER_ADDRESSES: OracleContract[] = [ + new OracleContract("0xe3d8bd6aed4f159bc8000a9cd47cffdb95f96121", 5272598), // Ubeswap + new OracleContract("0x1b02da8cb0d097eb8d57a175b88c7d8b47997506", 7254057), // Sushiswap +]; + +/////////////////////////////////////////////////////////////////////////// +/////////////////////////// BLACKLISTED TOKENS //////////////////////////// +/////////////////////////////////////////////////////////////////////////// + +export const YEARN_LENS_BLACKLIST: Address[] = []; +export const AAVE_ORACLE_BLACKLIST: Address[] = []; +export const CURVE_CALCULATIONS_BLACKSLIST: Address[] = []; +export const SUSHI_CALCULATIONS_BLACKSLIST: Address[] = []; + +/////////////////////////////////////////////////////////////////////////// +//////////////////////////// HARDCODED STABLES //////////////////////////// +/////////////////////////////////////////////////////////////////////////// + +export const HARDCODED_STABLES: Address[] = []; + +/////////////////////////////////////////////////////////////////////////// +///////////////////////////////// HELPERS ///////////////////////////////// +/////////////////////////////////////////////////////////////////////////// + +export const USDC_TOKEN_DECIMALS = BigInt.fromI32(6); + +export const ETH_ADDRESS = Address.fromString( + "0x122013fd7df1c6f636a5bb8f03108e876548b455" +); +export const WETH_ADDRESS = Address.fromString( + "0x471ece3750da237f93b8e339c536989b8978a438" // Celo native asset (CELO) +); +export const USDC_ADDRESS = Address.fromString( + "0x37f750b7cc259a2f741af45294f6a16572cf5cad" +); + +export class config implements Configurations { + network(): string { + return NETWORK_STRING; + } + + yearnLens(): OracleContract { + return YEARN_LENS_CONTRACT_ADDRESS; + } + chainLink(): OracleContract { + return CHAIN_LINK_CONTRACT_ADDRESS; + } + yearnLensBlacklist(): Address[] { + return YEARN_LENS_BLACKLIST; + } + + aaveOracle(): OracleContract { + return AAVE_ORACLE_CONTRACT_ADDRESS; + } + aaveOracleBlacklist(): Address[] { + return AAVE_ORACLE_BLACKLIST; + } + + curveCalculations(): OracleContract { + return CURVE_CALCULATIONS_ADDRESS; + } + curveCalculationsBlacklist(): Address[] { + return CURVE_CALCULATIONS_BLACKSLIST; + } + + sushiCalculations(): OracleContract { + return SUSHISWAP_CALCULATIONS_ADDRESS; + } + sushiCalculationsBlacklist(): Address[] { + return SUSHI_CALCULATIONS_BLACKSLIST; + } + + uniswapForks(): OracleContract[] { + return UNISWAP_FORKS_ROUTER_ADDRESSES; + } + curveRegistry(): OracleContract[] { + return CURVE_REGISTRY_ADDRESSES; + } + + hardcodedStables(): Address[] { + return HARDCODED_STABLES; + } + + ignoreList(): Address[] { + return []; + } + ethAddress(): Address { + return ETH_ADDRESS; + } + wethAddress(): Address { + return WETH_ADDRESS; + } + usdcAddress(): Address { + return USDC_ADDRESS; + } + + usdcTokenDecimals(): BigInt { + return USDC_TOKEN_DECIMALS; + } + + getOracleOverride( + tokenAddr: Address | null, + block: ethereum.Block | null + ): OracleConfig | null { + return null; + } +} diff --git a/subgraphs/polygon-bridge/src/prices/config/cronos.ts b/subgraphs/polygon-bridge/src/prices/config/cronos.ts new file mode 100644 index 0000000000..522d2f9bbb --- /dev/null +++ b/subgraphs/polygon-bridge/src/prices/config/cronos.ts @@ -0,0 +1,134 @@ +/* eslint-disable @typescript-eslint/no-magic-numbers, @typescript-eslint/no-unused-vars */ +import * as constants from "../common/constants"; +import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts"; +import { Configurations, OracleConfig, OracleContract } from "../common/types"; + +export const NETWORK_STRING = "cronos"; + +/////////////////////////////////////////////////////////////////////////// +///////////////////// CALCULATIONS/ORACLE CONTRACT //////////////////////// +/////////////////////////////////////////////////////////////////////////// + +export const YEARN_LENS_CONTRACT_ADDRESS = new OracleContract(); +export const CHAIN_LINK_CONTRACT_ADDRESS = new OracleContract(); +export const AAVE_ORACLE_CONTRACT_ADDRESS = new OracleContract(); +export const SUSHISWAP_CALCULATIONS_ADDRESS = new OracleContract(); + +/////////////////////////////////////////////////////////////////////////// +///////////////////////////// CURVE CONTRACT ////////////////////////////// +/////////////////////////////////////////////////////////////////////////// + +export const CURVE_CALCULATIONS_ADDRESS = new OracleContract(); + +export const CURVE_REGISTRY_ADDRESSES: OracleContract[] = []; + +/////////////////////////////////////////////////////////////////////////// +/////////////////////////// UNISWAP FORKS CONTRACT //////////////////////// +/////////////////////////////////////////////////////////////////////////// + +export const UNISWAP_FORKS_ROUTER_ADDRESSES: OracleContract[] = [ + new OracleContract("0x145863eb42cf62847a6ca784e6416c1682b1b2ae", 5247), // VVS Finance +]; + +/////////////////////////////////////////////////////////////////////////// +/////////////////////////// BLACKLISTED TOKENS //////////////////////////// +/////////////////////////////////////////////////////////////////////////// + +export const YEARN_LENS_BLACKLIST: Address[] = []; +export const AAVE_ORACLE_BLACKLIST: Address[] = []; +export const CURVE_CALCULATIONS_BLACKSLIST: Address[] = []; +export const SUSHI_CALCULATIONS_BLACKSLIST: Address[] = []; + +/////////////////////////////////////////////////////////////////////////// +//////////////////////////// HARDCODED STABLES //////////////////////////// +/////////////////////////////////////////////////////////////////////////// + +export const HARDCODED_STABLES: Address[] = []; + +/////////////////////////////////////////////////////////////////////////// +///////////////////////////////// HELPERS ///////////////////////////////// +/////////////////////////////////////////////////////////////////////////// + +export const USDC_TOKEN_DECIMALS = BigInt.fromI32(6); + +export const ETH_ADDRESS = Address.fromString( + "0xe44fd7fcb2b1581822d0c862b68222998a0c299a" +); +export const WETH_ADDRESS = Address.fromString( + "0x5c7f8a570d578ed84e63fdfa7b1ee72deae1ae23" // Wrapped CRO (WCRO) +); +export const USDC_ADDRESS = Address.fromString( + "0xc21223249ca28397b4b6541dffaecc539bff0c59" +); + +export class config implements Configurations { + network(): string { + return NETWORK_STRING; + } + + yearnLens(): OracleContract { + return YEARN_LENS_CONTRACT_ADDRESS; + } + chainLink(): OracleContract { + return CHAIN_LINK_CONTRACT_ADDRESS; + } + yearnLensBlacklist(): Address[] { + return YEARN_LENS_BLACKLIST; + } + + aaveOracle(): OracleContract { + return AAVE_ORACLE_CONTRACT_ADDRESS; + } + aaveOracleBlacklist(): Address[] { + return AAVE_ORACLE_BLACKLIST; + } + + curveCalculations(): OracleContract { + return CURVE_CALCULATIONS_ADDRESS; + } + curveCalculationsBlacklist(): Address[] { + return CURVE_CALCULATIONS_BLACKSLIST; + } + + sushiCalculations(): OracleContract { + return SUSHISWAP_CALCULATIONS_ADDRESS; + } + sushiCalculationsBlacklist(): Address[] { + return SUSHI_CALCULATIONS_BLACKSLIST; + } + + uniswapForks(): OracleContract[] { + return UNISWAP_FORKS_ROUTER_ADDRESSES; + } + curveRegistry(): OracleContract[] { + return CURVE_REGISTRY_ADDRESSES; + } + + hardcodedStables(): Address[] { + return HARDCODED_STABLES; + } + + ignoreList(): Address[] { + return []; + } + ethAddress(): Address { + return ETH_ADDRESS; + } + wethAddress(): Address { + return WETH_ADDRESS; + } + usdcAddress(): Address { + return USDC_ADDRESS; + } + + usdcTokenDecimals(): BigInt { + return USDC_TOKEN_DECIMALS; + } + + getOracleOverride( + tokenAddr: Address | null, + block: ethereum.Block | null + ): OracleConfig | null { + return null; + } +} diff --git a/subgraphs/polygon-bridge/src/prices/config/fantom.ts b/subgraphs/polygon-bridge/src/prices/config/fantom.ts index cc064f460d..395c1946e2 100644 --- a/subgraphs/polygon-bridge/src/prices/config/fantom.ts +++ b/subgraphs/polygon-bridge/src/prices/config/fantom.ts @@ -1,6 +1,7 @@ -import { Configurations } from "../common/types"; +/* eslint-disable @typescript-eslint/no-magic-numbers, @typescript-eslint/no-unused-vars */ import * as constants from "../common/constants"; -import { Address, BigInt } from "@graphprotocol/graph-ts"; +import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts"; +import { Configurations, OracleConfig, OracleContract } from "../common/types"; export const NETWORK_STRING = "fantom"; @@ -8,36 +9,39 @@ export const NETWORK_STRING = "fantom"; ///////////////////// CALCULATIONS/ORACLE CONTRACT //////////////////////// /////////////////////////////////////////////////////////////////////////// -export const YEARN_LENS_CONTRACT_ADDRESS = Address.fromString( - "0x57aa88a0810dfe3f9b71a9b179dd8bf5f956c46a" +export const YEARN_LENS_CONTRACT_ADDRESS = new OracleContract( + "0x57aa88a0810dfe3f9b71a9b179dd8bf5f956c46a", + 17091856 ); -export const CHAIN_LINK_CONTRACT_ADDRESS = constants.NULL.TYPE_ADDRESS; -export const AAVE_ORACLE_CONTRACT_ADDRESS = constants.NULL.TYPE_ADDRESS; -export const SUSHISWAP_CALCULATIONS_ADDRESS = Address.fromString( - "0x44536de2220987d098d1d29d3aafc7f7348e9ee4" +export const CHAIN_LINK_CONTRACT_ADDRESS = new OracleContract(); +export const AAVE_ORACLE_CONTRACT_ADDRESS = new OracleContract(); +export const SUSHISWAP_CALCULATIONS_ADDRESS = new OracleContract( + "0x44536de2220987d098d1d29d3aafc7f7348e9ee4", + 3809480 ); /////////////////////////////////////////////////////////////////////////// ///////////////////////////// CURVE CONTRACT ////////////////////////////// /////////////////////////////////////////////////////////////////////////// -export const CURVE_CALCULATIONS_ADDRESS = Address.fromString( - "0x0b53e9df372e72d8fdcdbedfbb56059957a37128" +export const CURVE_CALCULATIONS_ADDRESS = new OracleContract( + "0x0b53e9df372e72d8fdcdbedfbb56059957a37128", + 27067399 ); -export const CURVE_REGISTRY_ADDRESSES: Address[] = [ - Address.fromString("0x0f854EA9F38ceA4B1c2FC79047E9D0134419D5d6"), - Address.fromString("0x4fb93D7d320E8A263F22f62C2059dFC2A8bCbC4c"), +export const CURVE_REGISTRY_ADDRESSES: OracleContract[] = [ + new OracleContract("0x0f854ea9f38cea4b1c2fc79047e9d0134419d5d6", 5655918), + new OracleContract("0x4fb93d7d320e8a263f22f62c2059dfc2a8bcbc4c", 27552509), ]; /////////////////////////////////////////////////////////////////////////// /////////////////////////// UNISWAP FORKS CONTRACT //////////////////////// /////////////////////////////////////////////////////////////////////////// -export const UNISWAP_FORKS_ROUTER_ADDRESSES: Address[] = [ - Address.fromString("0xbe4fc72f8293f9d3512d58b969c98c3f676cb957"), // Uniswap - Address.fromString("0x16327E3FbDaCA3bcF7E38F5Af2599D2DDc33aE52"), // Spiritswap - Address.fromString("0x1b02da8cb0d097eb8d57a175b88c7d8b47997506"), // Sushiswap +export const UNISWAP_FORKS_ROUTER_ADDRESSES: OracleContract[] = [ + new OracleContract("0xbe4fc72f8293f9d3512d58b969c98c3f676cb957", 3796241), // Uniswap v2 + new OracleContract("0x16327e3fbdaca3bcf7e38f5af2599d2ddc33ae52", 4250168), // Spiritswap + new OracleContract("0x1b02da8cb0d097eb8d57a175b88c7d8b47997506", 2457904), // Sushiswap ]; /////////////////////////////////////////////////////////////////////////// @@ -76,44 +80,41 @@ export class config implements Configurations { return NETWORK_STRING; } - yearnLens(): Address { + yearnLens(): OracleContract { return YEARN_LENS_CONTRACT_ADDRESS; } - chainLink(): Address { + chainLink(): OracleContract { return CHAIN_LINK_CONTRACT_ADDRESS; } yearnLensBlacklist(): Address[] { return YEARN_LENS_BLACKLIST; } - aaveOracle(): Address { + aaveOracle(): OracleContract { return AAVE_ORACLE_CONTRACT_ADDRESS; } aaveOracleBlacklist(): Address[] { return AAVE_ORACLE_BLACKLIST; } - curveCalculations(): Address { + curveCalculations(): OracleContract { return CURVE_CALCULATIONS_ADDRESS; } curveCalculationsBlacklist(): Address[] { return CURVE_CALCULATIONS_BLACKSLIST; } - ignoreList(): Address[] { - return []; - } - sushiCalculations(): Address { + sushiCalculations(): OracleContract { return SUSHISWAP_CALCULATIONS_ADDRESS; } sushiCalculationsBlacklist(): Address[] { return SUSHI_CALCULATIONS_BLACKSLIST; } - uniswapForks(): Address[] { + uniswapForks(): OracleContract[] { return UNISWAP_FORKS_ROUTER_ADDRESSES; } - curveRegistry(): Address[] { + curveRegistry(): OracleContract[] { return CURVE_REGISTRY_ADDRESSES; } @@ -121,6 +122,9 @@ export class config implements Configurations { return HARDCODED_STABLES; } + ignoreList(): Address[] { + return []; + } ethAddress(): Address { return ETH_ADDRESS; } @@ -134,4 +138,11 @@ export class config implements Configurations { usdcTokenDecimals(): BigInt { return USDC_TOKEN_DECIMALS; } + + getOracleOverride( + tokenAddr: Address | null, + block: ethereum.Block | null + ): OracleConfig | null { + return null; + } } diff --git a/subgraphs/polygon-bridge/src/prices/config/fuse.ts b/subgraphs/polygon-bridge/src/prices/config/fuse.ts new file mode 100644 index 0000000000..0778996dc0 --- /dev/null +++ b/subgraphs/polygon-bridge/src/prices/config/fuse.ts @@ -0,0 +1,135 @@ +/* eslint-disable @typescript-eslint/no-magic-numbers, @typescript-eslint/no-unused-vars */ +import * as constants from "../common/constants"; +import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts"; +import { Configurations, OracleConfig, OracleContract } from "../common/types"; + +export const NETWORK_STRING = "fuse"; + +/////////////////////////////////////////////////////////////////////////// +///////////////////// CALCULATIONS/ORACLE CONTRACT //////////////////////// +/////////////////////////////////////////////////////////////////////////// + +export const YEARN_LENS_CONTRACT_ADDRESS = new OracleContract(); +export const CHAIN_LINK_CONTRACT_ADDRESS = new OracleContract(); +export const AAVE_ORACLE_CONTRACT_ADDRESS = new OracleContract(); +export const SUSHISWAP_CALCULATIONS_ADDRESS = new OracleContract(); + +/////////////////////////////////////////////////////////////////////////// +///////////////////////////// CURVE CONTRACT ////////////////////////////// +/////////////////////////////////////////////////////////////////////////// + +export const CURVE_CALCULATIONS_ADDRESS = new OracleContract(); + +export const CURVE_REGISTRY_ADDRESSES: OracleContract[] = []; + +/////////////////////////////////////////////////////////////////////////// +/////////////////////////// UNISWAP FORKS CONTRACT //////////////////////// +/////////////////////////////////////////////////////////////////////////// + +export const UNISWAP_FORKS_ROUTER_ADDRESSES: OracleContract[] = [ + new OracleContract("0xe3f85aad0c8dd7337427b9df5d0fb741d65eeeb5", 15645719), // Voltage Finance + new OracleContract("0x1b02da8cb0d097eb8d57a175b88c7d8b47997506", 12936314), // Sushiswap +]; + +/////////////////////////////////////////////////////////////////////////// +/////////////////////////// BLACKLISTED TOKENS //////////////////////////// +/////////////////////////////////////////////////////////////////////////// + +export const YEARN_LENS_BLACKLIST: Address[] = []; +export const AAVE_ORACLE_BLACKLIST: Address[] = []; +export const CURVE_CALCULATIONS_BLACKSLIST: Address[] = []; +export const SUSHI_CALCULATIONS_BLACKSLIST: Address[] = []; + +/////////////////////////////////////////////////////////////////////////// +//////////////////////////// HARDCODED STABLES //////////////////////////// +/////////////////////////////////////////////////////////////////////////// + +export const HARDCODED_STABLES: Address[] = []; + +/////////////////////////////////////////////////////////////////////////// +///////////////////////////////// HELPERS ///////////////////////////////// +/////////////////////////////////////////////////////////////////////////// + +export const USDC_TOKEN_DECIMALS = BigInt.fromI32(6); + +export const ETH_ADDRESS = Address.fromString( + "0xa722c13135930332eb3d749b2f0906559d2c5b99" +); +export const WETH_ADDRESS = Address.fromString( + "0x0be9e53fd7edac9f859882afdda116645287c629" // Wrapped Fuse (WFUSE) +); +export const USDC_ADDRESS = Address.fromString( + "0x620fd5fa44be6af63715ef4e65ddfa0387ad13f5" +); + +export class config implements Configurations { + network(): string { + return NETWORK_STRING; + } + + yearnLens(): OracleContract { + return YEARN_LENS_CONTRACT_ADDRESS; + } + chainLink(): OracleContract { + return CHAIN_LINK_CONTRACT_ADDRESS; + } + yearnLensBlacklist(): Address[] { + return YEARN_LENS_BLACKLIST; + } + + aaveOracle(): OracleContract { + return AAVE_ORACLE_CONTRACT_ADDRESS; + } + aaveOracleBlacklist(): Address[] { + return AAVE_ORACLE_BLACKLIST; + } + + curveCalculations(): OracleContract { + return CURVE_CALCULATIONS_ADDRESS; + } + curveCalculationsBlacklist(): Address[] { + return CURVE_CALCULATIONS_BLACKSLIST; + } + + sushiCalculations(): OracleContract { + return SUSHISWAP_CALCULATIONS_ADDRESS; + } + sushiCalculationsBlacklist(): Address[] { + return SUSHI_CALCULATIONS_BLACKSLIST; + } + + uniswapForks(): OracleContract[] { + return UNISWAP_FORKS_ROUTER_ADDRESSES; + } + curveRegistry(): OracleContract[] { + return CURVE_REGISTRY_ADDRESSES; + } + + hardcodedStables(): Address[] { + return HARDCODED_STABLES; + } + + ignoreList(): Address[] { + return []; + } + ethAddress(): Address { + return ETH_ADDRESS; + } + wethAddress(): Address { + return WETH_ADDRESS; + } + usdcAddress(): Address { + return USDC_ADDRESS; + } + + usdcTokenDecimals(): BigInt { + return USDC_TOKEN_DECIMALS; + } + + getOracleOverride( + tokenAddr: Address | null, + block: ethereum.Block | null + ): OracleConfig | null { + return null; + } +} diff --git a/subgraphs/polygon-bridge/src/prices/config/gnosis.ts b/subgraphs/polygon-bridge/src/prices/config/gnosis.ts index 58dd139855..55cb2479c5 100644 --- a/subgraphs/polygon-bridge/src/prices/config/gnosis.ts +++ b/subgraphs/polygon-bridge/src/prices/config/gnosis.ts @@ -1,6 +1,7 @@ -import { Configurations } from "../common/types"; +/* eslint-disable @typescript-eslint/no-magic-numbers, @typescript-eslint/no-unused-vars */ import * as constants from "../common/constants"; -import { Address, BigInt } from "@graphprotocol/graph-ts"; +import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts"; +import { Configurations, OracleConfig, OracleContract } from "../common/types"; export const NETWORK_STRING: string = "xdai"; @@ -8,28 +9,28 @@ export const NETWORK_STRING: string = "xdai"; ///////////////////// CALCULATIONS/ORACLE CONTRACT //////////////////////// /////////////////////////////////////////////////////////////////////////// -export const YEARN_LENS_CONTRACT_ADDRESS = constants.NULL.TYPE_ADDRESS; -export const CHAIN_LINK_CONTRACT_ADDRESS = constants.NULL.TYPE_ADDRESS; -export const AAVE_ORACLE_CONTRACT_ADDRESS = constants.NULL.TYPE_ADDRESS; -export const SUSHISWAP_CALCULATIONS_ADDRESS = constants.NULL.TYPE_ADDRESS; +export const YEARN_LENS_CONTRACT_ADDRESS = new OracleContract(); +export const CHAIN_LINK_CONTRACT_ADDRESS = new OracleContract(); +export const AAVE_ORACLE_CONTRACT_ADDRESS = new OracleContract(); +export const SUSHISWAP_CALCULATIONS_ADDRESS = new OracleContract(); /////////////////////////////////////////////////////////////////////////// ///////////////////////////// CURVE CONTRACT ////////////////////////////// /////////////////////////////////////////////////////////////////////////// -export const CURVE_CALCULATIONS_ADDRESS = constants.NULL.TYPE_ADDRESS; +export const CURVE_CALCULATIONS_ADDRESS = new OracleContract(); -export const CURVE_REGISTRY_ADDRESSES: Address[] = [ - Address.fromString("0x55E91365697EB8032F98290601847296eC847210"), - Address.fromString("0x8A4694401bE8F8FCCbC542a3219aF1591f87CE17"), +export const CURVE_REGISTRY_ADDRESSES: OracleContract[] = [ + new OracleContract("0x55e91365697eb8032f98290601847296ec847210", 20754886), + new OracleContract("0x8a4694401be8f8fccbc542a3219af1591f87ce17", 23334728), ]; /////////////////////////////////////////////////////////////////////////// /////////////////////////// UNISWAP FORKS CONTRACT //////////////////////// /////////////////////////////////////////////////////////////////////////// -export const UNISWAP_FORKS_ROUTER_ADDRESSES: Address[] = [ - Address.fromString("0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506"), // SushiSwap +export const UNISWAP_FORKS_ROUTER_ADDRESSES: OracleContract[] = [ + new OracleContract("0x1b02da8cb0d097eb8d57a175b88c7d8b47997506", 14735910), // SushiSwap ]; /////////////////////////////////////////////////////////////////////////// @@ -57,7 +58,7 @@ export const ETH_ADDRESS = Address.fromString( "0x6a023ccd1ff6f2045c3309768ead9e68f978f6e1" ); export const WETH_ADDRESS = Address.fromString( - "0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d" + "0xe91d153e0b41518a2ce8dd3d7944fa863463a97d" ); export const USDC_ADDRESS = Address.fromString( "0xddafbb505ad214d7b80b1f830fccc89b60fb7a83" @@ -68,44 +69,41 @@ export class config implements Configurations { return NETWORK_STRING; } - yearnLens(): Address { + yearnLens(): OracleContract { return YEARN_LENS_CONTRACT_ADDRESS; } - chainLink(): Address { + chainLink(): OracleContract { return CHAIN_LINK_CONTRACT_ADDRESS; } yearnLensBlacklist(): Address[] { return YEARN_LENS_BLACKLIST; } - aaveOracle(): Address { + aaveOracle(): OracleContract { return AAVE_ORACLE_CONTRACT_ADDRESS; } aaveOracleBlacklist(): Address[] { return AAVE_ORACLE_BLACKLIST; } - curveCalculations(): Address { + curveCalculations(): OracleContract { return CURVE_CALCULATIONS_ADDRESS; } curveCalculationsBlacklist(): Address[] { return CURVE_CALCULATIONS_BLACKSLIST; } - sushiCalculations(): Address { + sushiCalculations(): OracleContract { return SUSHISWAP_CALCULATIONS_ADDRESS; } sushiCalculationsBlacklist(): Address[] { return SUSHI_CALCULATIONS_BLACKSLIST; } - ignoreList(): Address[] { - return []; - } - uniswapForks(): Address[] { + uniswapForks(): OracleContract[] { return UNISWAP_FORKS_ROUTER_ADDRESSES; } - curveRegistry(): Address[] { + curveRegistry(): OracleContract[] { return CURVE_REGISTRY_ADDRESSES; } @@ -113,6 +111,9 @@ export class config implements Configurations { return HARDCODED_STABLES; } + ignoreList(): Address[] { + return []; + } ethAddress(): Address { return ETH_ADDRESS; } @@ -126,4 +127,11 @@ export class config implements Configurations { usdcTokenDecimals(): BigInt { return USDC_TOKEN_DECIMALS; } + + getOracleOverride( + tokenAddr: Address | null, + block: ethereum.Block | null + ): OracleConfig | null { + return null; + } } diff --git a/subgraphs/polygon-bridge/src/prices/config/harmony.ts b/subgraphs/polygon-bridge/src/prices/config/harmony.ts index e4a2a1c4d9..8bb569c112 100644 --- a/subgraphs/polygon-bridge/src/prices/config/harmony.ts +++ b/subgraphs/polygon-bridge/src/prices/config/harmony.ts @@ -1,6 +1,7 @@ -import { Configurations } from "../common/types"; +/* eslint-disable @typescript-eslint/no-magic-numbers, @typescript-eslint/no-unused-vars */ import * as constants from "../common/constants"; -import { Address, BigInt } from "@graphprotocol/graph-ts"; +import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts"; +import { Configurations, OracleConfig, OracleContract } from "../common/types"; export const NETWORK_STRING = "harmony"; @@ -8,29 +9,30 @@ export const NETWORK_STRING = "harmony"; ///////////////////// CALCULATIONS/ORACLE CONTRACT //////////////////////// /////////////////////////////////////////////////////////////////////////// -export const YEARN_LENS_CONTRACT_ADDRESS = constants.NULL.TYPE_ADDRESS; -export const CHAIN_LINK_CONTRACT_ADDRESS = constants.NULL.TYPE_ADDRESS; -export const SUSHISWAP_CALCULATIONS_ADDRESS = constants.NULL.TYPE_ADDRESS; -export const AAVE_ORACLE_CONTRACT_ADDRESS = Address.fromString( - "0x3c90887ede8d65ccb2777a5d577beab2548280ad" +export const YEARN_LENS_CONTRACT_ADDRESS = new OracleContract(); +export const CHAIN_LINK_CONTRACT_ADDRESS = new OracleContract(); +export const SUSHISWAP_CALCULATIONS_ADDRESS = new OracleContract(); +export const AAVE_ORACLE_CONTRACT_ADDRESS = new OracleContract( + "0xb56c2f0b653b2e0b10c9b928c8580ac5df02c7c7", + 23930344 ); /////////////////////////////////////////////////////////////////////////// ///////////////////////////// CURVE CONTRACT ////////////////////////////// /////////////////////////////////////////////////////////////////////////// -export const CURVE_CALCULATIONS_ADDRESS = constants.NULL.TYPE_ADDRESS; +export const CURVE_CALCULATIONS_ADDRESS = new OracleContract(); -export const CURVE_REGISTRY_ADDRESSES: Address[] = [ - Address.fromString("0x0a53FaDa2d943057C47A301D25a4D9b3B8e01e8E"), +export const CURVE_REGISTRY_ADDRESSES: OracleContract[] = [ + new OracleContract("0x0a53fada2d943057c47a301d25a4d9b3b8e01e8e", 18003250), ]; /////////////////////////////////////////////////////////////////////////// /////////////////////////// UNISWAP FORKS CONTRACT //////////////////////// /////////////////////////////////////////////////////////////////////////// -export const UNISWAP_FORKS_ROUTER_ADDRESSES: Address[] = [ - Address.fromString("0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506"), // SushiSwap +export const UNISWAP_FORKS_ROUTER_ADDRESSES: OracleContract[] = [ + new OracleContract("0x1b02da8cb0d097eb8d57a175b88c7d8b47997506", 11256069), // SushiSwap ]; /////////////////////////////////////////////////////////////////////////// @@ -55,13 +57,13 @@ export const HARDCODED_STABLES: Address[] = []; export const USDC_TOKEN_DECIMALS = BigInt.fromI32(6); export const ETH_ADDRESS = Address.fromString( - "0x6983D1E6DEf3690C4d616b13597A09e6193EA013" + "0x6983d1e6def3690c4d616b13597a09e6193ea013" ); export const WETH_ADDRESS = Address.fromString( - "0xcF664087a5bB0237a0BAd6742852ec6c8d69A27a" + "0xcf664087a5bb0237a0bad6742852ec6c8d69a27a" ); export const USDC_ADDRESS = Address.fromString( - "0x985458E523dB3d53125813eD68c274899e9DfAb4" + "0x985458e523db3d53125813ed68c274899e9dfab4" ); export class config implements Configurations { @@ -69,50 +71,50 @@ export class config implements Configurations { return NETWORK_STRING; } - yearnLens(): Address { + yearnLens(): OracleContract { return YEARN_LENS_CONTRACT_ADDRESS; } - chainLink(): Address { + chainLink(): OracleContract { return CHAIN_LINK_CONTRACT_ADDRESS; } yearnLensBlacklist(): Address[] { return YEARN_LENS_BLACKLIST; } - aaveOracle(): Address { + aaveOracle(): OracleContract { return AAVE_ORACLE_CONTRACT_ADDRESS; } aaveOracleBlacklist(): Address[] { return AAVE_ORACLE_BLACKLIST; } - curveCalculations(): Address { + curveCalculations(): OracleContract { return CURVE_CALCULATIONS_ADDRESS; } curveCalculationsBlacklist(): Address[] { return CURVE_CALCULATIONS_BLACKSLIST; } - ignoreList(): Address[] { - return []; - } - sushiCalculations(): Address { + sushiCalculations(): OracleContract { return SUSHISWAP_CALCULATIONS_ADDRESS; } sushiCalculationsBlacklist(): Address[] { return SUSHI_CALCULATIONS_BLACKSLIST; } - uniswapForks(): Address[] { + uniswapForks(): OracleContract[] { return UNISWAP_FORKS_ROUTER_ADDRESSES; } - curveRegistry(): Address[] { + curveRegistry(): OracleContract[] { return CURVE_REGISTRY_ADDRESSES; } hardcodedStables(): Address[] { return HARDCODED_STABLES; } + ignoreList(): Address[] { + return []; + } ethAddress(): Address { return ETH_ADDRESS; @@ -127,4 +129,11 @@ export class config implements Configurations { usdcTokenDecimals(): BigInt { return USDC_TOKEN_DECIMALS; } + + getOracleOverride( + tokenAddr: Address | null, + block: ethereum.Block | null + ): OracleConfig | null { + return null; + } } diff --git a/subgraphs/polygon-bridge/src/prices/config/mainnet.ts b/subgraphs/polygon-bridge/src/prices/config/mainnet.ts index 935558f9af..39a44980c9 100644 --- a/subgraphs/polygon-bridge/src/prices/config/mainnet.ts +++ b/subgraphs/polygon-bridge/src/prices/config/mainnet.ts @@ -1,6 +1,7 @@ -import { Configurations } from "../common/types"; +/* eslint-disable @typescript-eslint/no-magic-numbers */ import * as constants from "../common/constants"; -import { Address, BigInt } from "@graphprotocol/graph-ts"; +import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts"; +import { Configurations, OracleConfig, OracleContract } from "../common/types"; export const NETWORK_STRING = "mainnet"; @@ -8,37 +9,41 @@ export const NETWORK_STRING = "mainnet"; ///////////////////// CALCULATIONS/ORACLE CONTRACT //////////////////////// /////////////////////////////////////////////////////////////////////////// -export const YEARN_LENS_CONTRACT_ADDRESS = Address.fromString( - "0x83d95e0d5f402511db06817aff3f9ea88224b030" +export const YEARN_LENS_CONTRACT_ADDRESS = new OracleContract( + "0x83d95e0d5f402511db06817aff3f9ea88224b030", + 12242339 ); -export const CHAIN_LINK_CONTRACT_ADDRESS = Address.fromString( - "0x47Fb2585D2C56Fe188D0E6ec628a38b74fCeeeDf" +export const CHAIN_LINK_CONTRACT_ADDRESS = new OracleContract( + "0x47fb2585d2c56fe188d0e6ec628a38b74fceeedf", + 12864088 ); -export const AAVE_ORACLE_CONTRACT_ADDRESS = constants.NULL.TYPE_ADDRESS; -export const SUSHISWAP_CALCULATIONS_ADDRESS = Address.fromString( - "0x8263e161A855B644f582d9C164C66aABEe53f927" +export const AAVE_ORACLE_CONTRACT_ADDRESS = new OracleContract(); +export const SUSHISWAP_CALCULATIONS_ADDRESS = new OracleContract( + "0x8263e161a855b644f582d9c164c66aabee53f927", + 12692284 ); /////////////////////////////////////////////////////////////////////////// ///////////////////////////// CURVE CONTRACT ////////////////////////////// /////////////////////////////////////////////////////////////////////////// -export const CURVE_CALCULATIONS_ADDRESS = Address.fromString( - "0x25BF7b72815476Dd515044F9650Bf79bAd0Df655" +export const CURVE_CALCULATIONS_ADDRESS = new OracleContract( + "0x25bf7b72815476dd515044f9650bf79bad0df655", + 12370088 ); -export const CURVE_REGISTRY_ADDRESSES: Address[] = [ - Address.fromString("0x7D86446dDb609eD0F5f8684AcF30380a356b2B4c"), - Address.fromString("0x8F942C20D02bEfc377D41445793068908E2250D0"), +export const CURVE_REGISTRY_ADDRESSES: OracleContract[] = [ + new OracleContract("0x7d86446ddb609ed0f5f8684acf30380a356b2b4c", 11154794), + new OracleContract("0x8f942c20d02befc377d41445793068908e2250d0", 13986752), ]; /////////////////////////////////////////////////////////////////////////// /////////////////////////// UNISWAP FORKS CONTRACT //////////////////////// /////////////////////////////////////////////////////////////////////////// -export const UNISWAP_FORKS_ROUTER_ADDRESSES: Address[] = [ - Address.fromString("0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F"), // SushiSwap - Address.fromString("0x7a250d5630b4cf539739df2c5dacb4c659f2488d"), // Uniswap +export const UNISWAP_FORKS_ROUTER_ADDRESSES: OracleContract[] = [ + new OracleContract("0xd9e1ce17f2641f24ae83637ab66a2cca9c378b9f", 10794261), // SushiSwap + new OracleContract("0x7a250d5630b4cf539739df2c5dacb4c659f2488d", 10207858), // Uniswap ]; /////////////////////////////////////////////////////////////////////////// @@ -90,8 +95,6 @@ export const HARDCODED_STABLES: Address[] = [ Address.fromString("0xbcca60bb61934080951369a648fb03df4f96263c"), // Aave interest bearing USDC Address.fromString("0x6c5024cd4f8a59110119c56f8933403a539555eb"), // Aave interest bearing SUSD Address.fromString("0xd71ecff9342a5ced620049e616c5035f1db98620"), // Synth sEUR - Address.fromString("0x0C10bF8FcB7Bf5412187A595ab97a3609160b5c6"), // USDD - Address.fromString("0x8D6CeBD76f18E1558D4DB88138e2DeFB3909fAD6"), // MAI ]; export const IGNORELIST: Address[] = [ @@ -121,8 +124,64 @@ export const IGNORELIST: Address[] = [ Address.fromString("0x9783b81438c24848f85848f8df31845097341771"), Address.fromString("0x4e08f03079c5cd3083ea331ec61bcc87538b7665"), Address.fromString("0x09617F6fD6cF8A71278ec86e23bBab29C04353a7"), + Address.fromString("0xFD957F21bd95E723645C07C48a2d8ACB8Ffb3794"), ]; +/////////////////////////////////////////////////////////////////////////// +///////////////////////// ORACLE CONFIG OVERRIDES ///////////////////////// +/////////////////////////////////////////////////////////////////////////// + +// https://github.com/messari/subgraphs/issues/2090 +class spellOverride implements OracleConfig { + oracleCount(): number { + return constants.INT_ONE; + } + oracleOrder(): string[] { + return [ + constants.OracleType.CHAINLINK_FEED, + constants.OracleType.CURVE_CALCULATIONS, + constants.OracleType.SUSHI_CALCULATIONS, + constants.OracleType.CURVE_ROUTER, + constants.OracleType.UNISWAP_FORKS_ROUTER, + constants.OracleType.YEARN_LENS_ORACLE, + ]; + } +} + +// https://github.com/messari/subgraphs/issues/726 +class stETHOverride implements OracleConfig { + oracleCount(): number { + return constants.INT_ONE; + } + oracleOrder(): string[] { + return [ + constants.OracleType.CHAINLINK_FEED, + constants.OracleType.CURVE_CALCULATIONS, + constants.OracleType.SUSHI_CALCULATIONS, + constants.OracleType.CURVE_ROUTER, + constants.OracleType.UNISWAP_FORKS_ROUTER, + constants.OracleType.YEARN_LENS_ORACLE, + ]; + } +} + +// https://github.com/messari/subgraphs/issues/2097 +class baxaOverride implements OracleConfig { + oracleCount(): number { + return constants.INT_ONE; + } + oracleOrder(): string[] { + return [ + constants.OracleType.UNISWAP_FORKS_ROUTER, + constants.OracleType.YEARN_LENS_ORACLE, + constants.OracleType.CHAINLINK_FEED, + constants.OracleType.CURVE_CALCULATIONS, + constants.OracleType.CURVE_ROUTER, + constants.OracleType.SUSHI_CALCULATIONS, + ]; + } +} + /////////////////////////////////////////////////////////////////////////// ///////////////////////////////// HELPERS ///////////////////////////////// /////////////////////////////////////////////////////////////////////////// @@ -130,7 +189,7 @@ export const IGNORELIST: Address[] = [ export const USDC_TOKEN_DECIMALS = BigInt.fromI32(6); export const ETH_ADDRESS = Address.fromString( - "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE" + "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" ); export const WETH_ADDRESS = Address.fromString( "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2" @@ -144,41 +203,41 @@ export class config implements Configurations { return NETWORK_STRING; } - yearnLens(): Address { + yearnLens(): OracleContract { return YEARN_LENS_CONTRACT_ADDRESS; } - chainLink(): Address { + chainLink(): OracleContract { return CHAIN_LINK_CONTRACT_ADDRESS; } yearnLensBlacklist(): Address[] { return YEARN_LENS_BLACKLIST; } - aaveOracle(): Address { + aaveOracle(): OracleContract { return AAVE_ORACLE_CONTRACT_ADDRESS; } aaveOracleBlacklist(): Address[] { return AAVE_ORACLE_BLACKLIST; } - curveCalculations(): Address { + curveCalculations(): OracleContract { return CURVE_CALCULATIONS_ADDRESS; } curveCalculationsBlacklist(): Address[] { return CURVE_CALCULATIONS_BLACKSLIST; } - sushiCalculations(): Address { + sushiCalculations(): OracleContract { return SUSHISWAP_CALCULATIONS_ADDRESS; } sushiCalculationsBlacklist(): Address[] { return SUSHI_CALCULATIONS_BLACKSLIST; } - uniswapForks(): Address[] { + uniswapForks(): OracleContract[] { return UNISWAP_FORKS_ROUTER_ADDRESSES; } - curveRegistry(): Address[] { + curveRegistry(): OracleContract[] { return CURVE_REGISTRY_ADDRESSES; } @@ -203,4 +262,41 @@ export class config implements Configurations { usdcTokenDecimals(): BigInt { return USDC_TOKEN_DECIMALS; } + + getOracleOverride( + tokenAddr: Address | null, + block: ethereum.Block | null + ): OracleConfig | null { + if (tokenAddr || block) { + if ( + tokenAddr && + [ + Address.fromString("0x090185f2135308bad17527004364ebcc2d37e5f6"), // SPELL + ].includes(tokenAddr) + ) { + return new spellOverride(); + } + if ( + tokenAddr && + [ + Address.fromString("0xae7ab96520de3a18e5e111b5eaab095312d7fe84"), // stETH + ].includes(tokenAddr) && + block && + block.number.gt(BigInt.fromString("14019699")) && + block.number.lt(BigInt.fromString("14941265")) + ) { + return new stETHOverride(); + } + if ( + tokenAddr && + [ + Address.fromString("0x91b08f4a7c1251dfccf5440f8894f8daa10c8de5"), // BAXA + ].includes(tokenAddr) + ) { + return new baxaOverride(); + } + } + + return null; + } } diff --git a/subgraphs/polygon-bridge/src/prices/config/moonbeam.ts b/subgraphs/polygon-bridge/src/prices/config/moonbeam.ts index 6580af2c12..1540d6ea23 100644 --- a/subgraphs/polygon-bridge/src/prices/config/moonbeam.ts +++ b/subgraphs/polygon-bridge/src/prices/config/moonbeam.ts @@ -1,6 +1,7 @@ -import { Configurations } from "../common/types"; +/* eslint-disable @typescript-eslint/no-magic-numbers, @typescript-eslint/no-unused-vars */ import * as constants from "../common/constants"; -import { Address, BigInt } from "@graphprotocol/graph-ts"; +import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts"; +import { Configurations, OracleConfig, OracleContract } from "../common/types"; export const NETWORK_STRING = "moonbeam"; @@ -8,27 +9,27 @@ export const NETWORK_STRING = "moonbeam"; ///////////////////// CALCULATIONS/ORACLE CONTRACT //////////////////////// /////////////////////////////////////////////////////////////////////////// -export const YEARN_LENS_CONTRACT_ADDRESS = constants.NULL.TYPE_ADDRESS; -export const CHAIN_LINK_CONTRACT_ADDRESS = constants.NULL.TYPE_ADDRESS; -export const AAVE_ORACLE_CONTRACT_ADDRESS = constants.NULL.TYPE_ADDRESS; -export const SUSHISWAP_CALCULATIONS_ADDRESS = constants.NULL.TYPE_ADDRESS; +export const YEARN_LENS_CONTRACT_ADDRESS = new OracleContract(); +export const CHAIN_LINK_CONTRACT_ADDRESS = new OracleContract(); +export const AAVE_ORACLE_CONTRACT_ADDRESS = new OracleContract(); +export const SUSHISWAP_CALCULATIONS_ADDRESS = new OracleContract(); /////////////////////////////////////////////////////////////////////////// ///////////////////////////// CURVE CONTRACT ////////////////////////////// /////////////////////////////////////////////////////////////////////////// -export const CURVE_CALCULATIONS_ADDRESS = constants.NULL.TYPE_ADDRESS; +export const CURVE_CALCULATIONS_ADDRESS = new OracleContract(); -export const CURVE_REGISTRY_ADDRESSES: Address[] = [ - Address.fromString("0xC2b1DF84112619D190193E48148000e3990Bf627"), +export const CURVE_REGISTRY_ADDRESSES: OracleContract[] = [ + new OracleContract("0xc2b1df84112619d190193e48148000e3990bf627", 1452049), ]; /////////////////////////////////////////////////////////////////////////// /////////////////////////// UNISWAP FORKS CONTRACT //////////////////////// /////////////////////////////////////////////////////////////////////////// -export const UNISWAP_FORKS_ROUTER_ADDRESSES: Address[] = [ - Address.fromString("0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506"), // SushiSwap +export const UNISWAP_FORKS_ROUTER_ADDRESSES: OracleContract[] = [ + new OracleContract("0x445fe580ef8d70ff569ab36e80c647af338db351", 503734), // SushiSwap ]; /////////////////////////////////////////////////////////////////////////// @@ -67,44 +68,41 @@ export class config implements Configurations { return NETWORK_STRING; } - yearnLens(): Address { + yearnLens(): OracleContract { return YEARN_LENS_CONTRACT_ADDRESS; } - chainLink(): Address { + chainLink(): OracleContract { return CHAIN_LINK_CONTRACT_ADDRESS; } yearnLensBlacklist(): Address[] { return YEARN_LENS_BLACKLIST; } - aaveOracle(): Address { + aaveOracle(): OracleContract { return AAVE_ORACLE_CONTRACT_ADDRESS; } aaveOracleBlacklist(): Address[] { return AAVE_ORACLE_BLACKLIST; } - curveCalculations(): Address { + curveCalculations(): OracleContract { return CURVE_CALCULATIONS_ADDRESS; } curveCalculationsBlacklist(): Address[] { return CURVE_CALCULATIONS_BLACKSLIST; } - ignoreList(): Address[] { - return []; - } - sushiCalculations(): Address { + sushiCalculations(): OracleContract { return SUSHISWAP_CALCULATIONS_ADDRESS; } sushiCalculationsBlacklist(): Address[] { return SUSHI_CALCULATIONS_BLACKSLIST; } - uniswapForks(): Address[] { + uniswapForks(): OracleContract[] { return UNISWAP_FORKS_ROUTER_ADDRESSES; } - curveRegistry(): Address[] { + curveRegistry(): OracleContract[] { return CURVE_REGISTRY_ADDRESSES; } @@ -112,6 +110,9 @@ export class config implements Configurations { return HARDCODED_STABLES; } + ignoreList(): Address[] { + return []; + } ethAddress(): Address { return ETH_ADDRESS; } @@ -125,4 +126,11 @@ export class config implements Configurations { usdcTokenDecimals(): BigInt { return USDC_TOKEN_DECIMALS; } + + getOracleOverride( + tokenAddr: Address | null, + block: ethereum.Block | null + ): OracleConfig | null { + return null; + } } diff --git a/subgraphs/polygon-bridge/src/prices/config/optimism.ts b/subgraphs/polygon-bridge/src/prices/config/optimism.ts index 07bf5e0409..3ea31d7fd3 100644 --- a/subgraphs/polygon-bridge/src/prices/config/optimism.ts +++ b/subgraphs/polygon-bridge/src/prices/config/optimism.ts @@ -1,6 +1,7 @@ -import { Configurations } from "../common/types"; +/* eslint-disable @typescript-eslint/no-magic-numbers, @typescript-eslint/no-unused-vars */ import * as constants from "../common/constants"; -import { Address, BigInt } from "@graphprotocol/graph-ts"; +import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts"; +import { Configurations, OracleConfig, OracleContract } from "../common/types"; export const NETWORK_STRING = "optimism"; @@ -8,36 +9,40 @@ export const NETWORK_STRING = "optimism"; ///////////////////// CALCULATIONS/ORACLE CONTRACT //////////////////////// /////////////////////////////////////////////////////////////////////////// -export const YEARN_LENS_CONTRACT_ADDRESS = Address.fromString( - "0xb082d9f4734c535d9d80536f7e87a6f4f471bf65" +export const YEARN_LENS_CONTRACT_ADDRESS = new OracleContract( + "0xb082d9f4734c535d9d80536f7e87a6f4f471bf65", + 18109291 ); -export const CHAIN_LINK_CONTRACT_ADDRESS = constants.NULL.TYPE_ADDRESS; -export const AAVE_ORACLE_CONTRACT_ADDRESS = Address.fromString( - "0xD81eb3728a631871a7eBBaD631b5f424909f0c77" +export const CHAIN_LINK_CONTRACT_ADDRESS = new OracleContract(); +export const AAVE_ORACLE_CONTRACT_ADDRESS = new OracleContract( + "0xd81eb3728a631871a7ebbad631b5f424909f0c77", + 4365625 ); -export const SUSHISWAP_CALCULATIONS_ADDRESS = Address.fromString( - "0x5fd3815dcb668200a662114fbc9af13ac0a55b4d" +export const SUSHISWAP_CALCULATIONS_ADDRESS = new OracleContract( + "0x5fd3815dcb668200a662114fbc9af13ac0a55b4d", + 18216910 ); /////////////////////////////////////////////////////////////////////////// ///////////////////////////// CURVE CONTRACT ////////////////////////////// /////////////////////////////////////////////////////////////////////////// -export const CURVE_CALCULATIONS_ADDRESS = Address.fromString( - "0x0ffe8434eae67c9838b12c3cd11ac4005daa7227" +export const CURVE_CALCULATIONS_ADDRESS = new OracleContract( + "0x0ffe8434eae67c9838b12c3cd11ac4005daa7227", + 18368996 ); -export const CURVE_REGISTRY_ADDRESSES: Address[] = [ - Address.fromString("0xC5cfaDA84E902aD92DD40194f0883ad49639b023"), - Address.fromString("0x7DA64233Fefb352f8F501B357c018158ED8aA455"), +export const CURVE_REGISTRY_ADDRESSES: OracleContract[] = [ + new OracleContract("0xc5cfada84e902ad92dd40194f0883ad49639b023", 2373837), + new OracleContract("0x445fe580ef8d70ff569ab36e80c647af338db351", 3729171), ]; /////////////////////////////////////////////////////////////////////////// /////////////////////////// UNISWAP FORKS CONTRACT //////////////////////// /////////////////////////////////////////////////////////////////////////// -export const UNISWAP_FORKS_ROUTER_ADDRESSES: Address[] = [ - Address.fromString("0x9c12939390052919aF3155f41Bf4160Fd3666A6f"), // Velodrame +export const UNISWAP_FORKS_ROUTER_ADDRESSES: OracleContract[] = [ + new OracleContract("0x9c12939390052919af3155f41bf4160fd3666a6f", 19702709), // Velodrame ]; /////////////////////////////////////////////////////////////////////////// /////////////////////////// BLACKLISTED TOKENS //////////////////////////// @@ -52,9 +57,7 @@ export const SUSHI_CALCULATIONS_BLACKSLIST: Address[] = []; //////////////////////////// HARDCODED STABLES //////////////////////////// /////////////////////////////////////////////////////////////////////////// -export const HARDCODED_STABLES: Address[] = [ - Address.fromString("0xdFA46478F9e5EA86d57387849598dbFB2e964b02"), // MAI -]; +export const HARDCODED_STABLES: Address[] = []; /////////////////////////////////////////////////////////////////////////// ///////////////////////////////// HELPERS ///////////////////////////////// @@ -77,41 +80,41 @@ export class config implements Configurations { return NETWORK_STRING; } - yearnLens(): Address { + yearnLens(): OracleContract { return YEARN_LENS_CONTRACT_ADDRESS; } - chainLink(): Address { + chainLink(): OracleContract { return CHAIN_LINK_CONTRACT_ADDRESS; } yearnLensBlacklist(): Address[] { return YEARN_LENS_BLACKLIST; } - aaveOracle(): Address { + aaveOracle(): OracleContract { return AAVE_ORACLE_CONTRACT_ADDRESS; } aaveOracleBlacklist(): Address[] { return AAVE_ORACLE_BLACKLIST; } - curveCalculations(): Address { + curveCalculations(): OracleContract { return CURVE_CALCULATIONS_ADDRESS; } curveCalculationsBlacklist(): Address[] { return CURVE_CALCULATIONS_BLACKSLIST; } - sushiCalculations(): Address { + sushiCalculations(): OracleContract { return SUSHISWAP_CALCULATIONS_ADDRESS; } sushiCalculationsBlacklist(): Address[] { return SUSHI_CALCULATIONS_BLACKSLIST; } - uniswapForks(): Address[] { + uniswapForks(): OracleContract[] { return UNISWAP_FORKS_ROUTER_ADDRESSES; } - curveRegistry(): Address[] { + curveRegistry(): OracleContract[] { return CURVE_REGISTRY_ADDRESSES; } @@ -135,4 +138,11 @@ export class config implements Configurations { usdcTokenDecimals(): BigInt { return USDC_TOKEN_DECIMALS; } + + getOracleOverride( + tokenAddr: Address | null, + block: ethereum.Block | null + ): OracleConfig | null { + return null; + } } diff --git a/subgraphs/polygon-bridge/src/prices/config/polygon.ts b/subgraphs/polygon-bridge/src/prices/config/polygon.ts index fc63cf8372..8fc378b8b8 100644 --- a/subgraphs/polygon-bridge/src/prices/config/polygon.ts +++ b/subgraphs/polygon-bridge/src/prices/config/polygon.ts @@ -1,6 +1,7 @@ -import { Configurations } from "../common/types"; +/* eslint-disable @typescript-eslint/no-magic-numbers, @typescript-eslint/no-unused-vars */ import * as constants from "../common/constants"; -import { BigInt, Address } from "@graphprotocol/graph-ts"; +import { BigInt, Address, ethereum } from "@graphprotocol/graph-ts"; +import { Configurations, OracleConfig, OracleContract } from "../common/types"; export const NETWORK_STRING = "matic"; @@ -8,32 +9,33 @@ export const NETWORK_STRING = "matic"; ///////////////////// CALCULATIONS/ORACLE CONTRACT //////////////////////// /////////////////////////////////////////////////////////////////////////// -export const YEARN_LENS_CONTRACT_ADDRESS = constants.NULL.TYPE_ADDRESS; -export const CHAIN_LINK_CONTRACT_ADDRESS = constants.NULL.TYPE_ADDRESS; -export const SUSHISWAP_CALCULATIONS_ADDRESS = constants.NULL.TYPE_ADDRESS; +export const YEARN_LENS_CONTRACT_ADDRESS = new OracleContract(); +export const CHAIN_LINK_CONTRACT_ADDRESS = new OracleContract(); +export const SUSHISWAP_CALCULATIONS_ADDRESS = new OracleContract(); -export const AAVE_ORACLE_CONTRACT_ADDRESS = Address.fromString( - "0xb023e699F5a33916Ea823A16485e259257cA8Bd1" +export const AAVE_ORACLE_CONTRACT_ADDRESS = new OracleContract( + "0xb023e699f5a33916ea823a16485e259257ca8bd1", + 25825996 ); /////////////////////////////////////////////////////////////////////////// ///////////////////////////// CURVE CONTRACT ////////////////////////////// /////////////////////////////////////////////////////////////////////////// -export const CURVE_CALCULATIONS_ADDRESS = constants.NULL.TYPE_ADDRESS; +export const CURVE_CALCULATIONS_ADDRESS = new OracleContract(); -export const CURVE_REGISTRY_ADDRESSES: Address[] = [ - Address.fromString("0x094d12e5b541784701FD8d65F11fc0598FBC6332"), - Address.fromString("0x47bB542B9dE58b970bA50c9dae444DDB4c16751a"), +export const CURVE_REGISTRY_ADDRESSES: OracleContract[] = [ + new OracleContract("0x094d12e5b541784701fd8d65f11fc0598fbc6332", 13991825), + new OracleContract("0x47bb542b9de58b970ba50c9dae444ddb4c16751a", 23556360), ]; /////////////////////////////////////////////////////////////////////////// /////////////////////////// UNISWAP FORKS CONTRACT //////////////////////// /////////////////////////////////////////////////////////////////////////// -export const UNISWAP_FORKS_ROUTER_ADDRESSES: Address[] = [ - Address.fromString("0xa5e0829caced8ffdd4de3c43696c57f7d7a678ff"), // QuickSwap - Address.fromString("0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506"), // SushiSwap +export const UNISWAP_FORKS_ROUTER_ADDRESSES: OracleContract[] = [ + new OracleContract("0xa5e0829caced8ffdd4de3c43696c57f7d7a678ff", 4931900), // QuickSwap + new OracleContract("0x1b02da8cb0d097eb8d57a175b88c7d8b47997506", 11333235), // SushiSwap ]; /////////////////////////////////////////////////////////////////////////// @@ -49,9 +51,7 @@ export const SUSHI_CALCULATIONS_BLACKSLIST: Address[] = []; //////////////////////////// HARDCODED STABLES //////////////////////////// /////////////////////////////////////////////////////////////////////////// -export const HARDCODED_STABLES: Address[] = [ - Address.fromString("0xa3Fa99A148fA48D14Ed51d610c367C61876997F1"), // MAI -]; +export const HARDCODED_STABLES: Address[] = []; /////////////////////////////////////////////////////////////////////////// ///////////////////////////////// HELPERS ///////////////////////////////// @@ -74,44 +74,41 @@ export class config implements Configurations { return NETWORK_STRING; } - yearnLens(): Address { + yearnLens(): OracleContract { return YEARN_LENS_CONTRACT_ADDRESS; } - chainLink(): Address { + chainLink(): OracleContract { return CHAIN_LINK_CONTRACT_ADDRESS; } yearnLensBlacklist(): Address[] { return YEARN_LENS_BLACKLIST; } - aaveOracle(): Address { + aaveOracle(): OracleContract { return AAVE_ORACLE_CONTRACT_ADDRESS; } aaveOracleBlacklist(): Address[] { return AAVE_ORACLE_BLACKLIST; } - curveCalculations(): Address { + curveCalculations(): OracleContract { return CURVE_CALCULATIONS_ADDRESS; } curveCalculationsBlacklist(): Address[] { return CURVE_CALCULATIONS_BLACKSLIST; } - sushiCalculations(): Address { + sushiCalculations(): OracleContract { return SUSHISWAP_CALCULATIONS_ADDRESS; } sushiCalculationsBlacklist(): Address[] { return SUSHI_CALCULATIONS_BLACKSLIST; } - ignoreList(): Address[] { - return []; - } - uniswapForks(): Address[] { + uniswapForks(): OracleContract[] { return UNISWAP_FORKS_ROUTER_ADDRESSES; } - curveRegistry(): Address[] { + curveRegistry(): OracleContract[] { return CURVE_REGISTRY_ADDRESSES; } @@ -119,6 +116,9 @@ export class config implements Configurations { return HARDCODED_STABLES; } + ignoreList(): Address[] { + return []; + } ethAddress(): Address { return ETH_ADDRESS; } @@ -132,4 +132,11 @@ export class config implements Configurations { usdcTokenDecimals(): BigInt { return USDC_TOKEN_DECIMALS; } + + getOracleOverride( + tokenAddr: Address | null, + block: ethereum.Block | null + ): OracleConfig | null { + return null; + } } diff --git a/subgraphs/polygon-bridge/src/prices/config/template.ts b/subgraphs/polygon-bridge/src/prices/config/template.ts index cc7df43761..e918f67556 100644 --- a/subgraphs/polygon-bridge/src/prices/config/template.ts +++ b/subgraphs/polygon-bridge/src/prices/config/template.ts @@ -1,6 +1,7 @@ -import { Configurations } from "../common/types"; +/* eslint-disable @typescript-eslint/no-magic-numbers, @typescript-eslint/no-unused-vars */ import * as constants from "../common/constants"; -import { Address, BigInt } from "@graphprotocol/graph-ts"; +import { Address, BigInt, ethereum } from "@graphprotocol/graph-ts"; +import { Configurations, OracleConfig, OracleContract } from "../common/types"; export const NETWORK_STRING = "default"; @@ -8,24 +9,23 @@ export const NETWORK_STRING = "default"; ///////////////////// CALCULATIONS/ORACLE CONTRACT //////////////////////// /////////////////////////////////////////////////////////////////////////// -export const YEARN_LENS_CONTRACT_ADDRESS = constants.NULL.TYPE_ADDRESS; -export const CHAIN_LINK_CONTRACT_ADDRESS = constants.NULL.TYPE_ADDRESS; -export const AAVE_ORACLE_CONTRACT_ADDRESS = constants.NULL.TYPE_ADDRESS; -export const SUSHISWAP_CALCULATIONS_ADDRESS = constants.NULL.TYPE_ADDRESS; +export const YEARN_LENS_CONTRACT_ADDRESS = new OracleContract(); +export const CHAIN_LINK_CONTRACT_ADDRESS = new OracleContract(); +export const AAVE_ORACLE_CONTRACT_ADDRESS = new OracleContract(); +export const SUSHISWAP_CALCULATIONS_ADDRESS = new OracleContract(); /////////////////////////////////////////////////////////////////////////// ///////////////////////////// CURVE CONTRACT ////////////////////////////// /////////////////////////////////////////////////////////////////////////// -export const CURVE_CALCULATIONS_ADDRESS = constants.NULL.TYPE_ADDRESS; - -export const CURVE_REGISTRY_ADDRESSES: Address[] = []; +export const CURVE_CALCULATIONS_ADDRESS = new OracleContract(); +export const CURVE_REGISTRY_ADDRESSES: OracleContract[] = []; /////////////////////////////////////////////////////////////////////////// /////////////////////////// UNISWAP FORKS CONTRACT //////////////////////// /////////////////////////////////////////////////////////////////////////// -export const UNISWAP_FORKS_ROUTER_ADDRESSES: Address[] = []; +export const UNISWAP_FORKS_ROUTER_ADDRESSES: OracleContract[] = []; /////////////////////////////////////////////////////////////////////////// /////////////////////////// BLACKLISTED TOKENS //////////////////////////// @@ -42,6 +42,26 @@ export const SUSHI_CALCULATIONS_BLACKSLIST: Address[] = []; export const HARDCODED_STABLES: Address[] = []; +/////////////////////////////////////////////////////////////////////////// +///////////////////////// ORACLE CONFIG OVERRIDES ///////////////////////// +/////////////////////////////////////////////////////////////////////////// + +class someOverride implements OracleConfig { + oracleCount(): number { + return constants.INT_ONE; + } + oracleOrder(): string[] { + return [ + constants.OracleType.YEARN_LENS_ORACLE, + constants.OracleType.CHAINLINK_FEED, + constants.OracleType.CURVE_CALCULATIONS, + constants.OracleType.SUSHI_CALCULATIONS, + constants.OracleType.CURVE_ROUTER, + constants.OracleType.UNISWAP_FORKS_ROUTER, + ]; + } +} + /////////////////////////////////////////////////////////////////////////// ///////////////////////////////// HELPERS ///////////////////////////////// /////////////////////////////////////////////////////////////////////////// @@ -57,51 +77,51 @@ export class config implements Configurations { return NETWORK_STRING; } - yearnLens(): Address { + yearnLens(): OracleContract { return YEARN_LENS_CONTRACT_ADDRESS; } - chainLink(): Address { + chainLink(): OracleContract { return CHAIN_LINK_CONTRACT_ADDRESS; } yearnLensBlacklist(): Address[] { return YEARN_LENS_BLACKLIST; } - aaveOracle(): Address { + aaveOracle(): OracleContract { return AAVE_ORACLE_CONTRACT_ADDRESS; } aaveOracleBlacklist(): Address[] { return AAVE_ORACLE_BLACKLIST; } - curveCalculations(): Address { + curveCalculations(): OracleContract { return CURVE_CALCULATIONS_ADDRESS; } curveCalculationsBlacklist(): Address[] { return CURVE_CALCULATIONS_BLACKSLIST; } - sushiCalculations(): Address { + sushiCalculations(): OracleContract { return SUSHISWAP_CALCULATIONS_ADDRESS; } sushiCalculationsBlacklist(): Address[] { return SUSHI_CALCULATIONS_BLACKSLIST; } - uniswapForks(): Address[] { + uniswapForks(): OracleContract[] { return UNISWAP_FORKS_ROUTER_ADDRESSES; } - curveRegistry(): Address[] { + curveRegistry(): OracleContract[] { return CURVE_REGISTRY_ADDRESSES; } hardcodedStables(): Address[] { return HARDCODED_STABLES; } + ignoreList(): Address[] { return []; } - ethAddress(): Address { return ETH_ADDRESS; } @@ -115,4 +135,11 @@ export class config implements Configurations { usdcTokenDecimals(): BigInt { return USDC_TOKEN_DECIMALS; } + + getOracleOverride( + tokenAddr: Address | null, + block: ethereum.Block | null + ): OracleConfig | null { + return new someOverride(); + } } diff --git a/subgraphs/polygon-bridge/src/prices/index.ts b/subgraphs/polygon-bridge/src/prices/index.ts index 1fc1382129..af23a6f70d 100644 --- a/subgraphs/polygon-bridge/src/prices/index.ts +++ b/subgraphs/polygon-bridge/src/prices/index.ts @@ -1,3 +1,12 @@ +import { + log, + Address, + ethereum, + BigDecimal, + dataSource, +} from "@graphprotocol/graph-ts"; +import { CustomPriceType, OracleType } from "./common/types"; + import * as utils from "./common/utils"; import * as constants from "./common/constants"; import * as AaveOracle from "./oracles/AaveOracle"; @@ -8,18 +17,16 @@ import * as UniswapForksRouter from "./routers/UniswapForksRouter"; import * as CurveCalculations from "./calculations/CalculationsCurve"; import * as SushiCalculations from "./calculations/CalculationsSushiswap"; -import { CustomPriceType } from "./common/types"; -import { log, Address, BigDecimal, dataSource } from "@graphprotocol/graph-ts"; - -export function getUsdPricePerToken(tokenAddr: Address): CustomPriceType { +export function getUsdPricePerToken( + tokenAddr: Address, + block: ethereum.Block | null = null +): CustomPriceType { if (tokenAddr.equals(constants.NULL.TYPE_ADDRESS)) { return new CustomPriceType(); } const config = utils.getConfig(); - - const network = config.network().toUpperCase(); - if (network == "default") { + if (config.network() == "default") { log.warning("Failed to fetch price: network {} not implemented", [ dataSource.network(), ]); @@ -27,10 +34,6 @@ export function getUsdPricePerToken(tokenAddr: Address): CustomPriceType { return new CustomPriceType(); } - if (config.ignoreList().includes(tokenAddr)) { - return new CustomPriceType(); - } - if (config.hardcodedStables().includes(tokenAddr)) { return CustomPriceType.initialize( constants.BIGDECIMAL_USD_PRICE, @@ -38,102 +41,113 @@ export function getUsdPricePerToken(tokenAddr: Address): CustomPriceType { ); } - if ( - [ - Address.fromString("0x72E2F4830b9E45d52F80aC08CB2bEC0FeF72eD9c"), - Address.fromString("0x82CbeCF39bEe528B5476 FE6d1550af59a9dB6Fc0"), - Address.fromString("0xb69c8CBCD90A39D8D3d3ccf0a3E968511C3856A0"), - ].includes(tokenAddr) // SGETH - ) { - tokenAddr = config.wethAddress(); + if (config.ignoreList().includes(tokenAddr)) { + return new CustomPriceType(); } - // 1. Yearn Lens Oracle - const yearnLensPrice = YearnLensOracle.getTokenPriceUSDC(tokenAddr); - if (!yearnLensPrice.reverted) { - log.info("[YearnLensOracle] tokenAddress: {}, Price: {}", [ - tokenAddr.toHexString(), - yearnLensPrice.usdPrice.toString(), - ]); - return yearnLensPrice; + const oracle = new OracleType(); + const override = config.getOracleOverride(tokenAddr, block); + if (override) { + oracle.setOracleConfig(override); } - - // 2. ChainLink Feed Registry - const chainLinkPrice = ChainLinkFeed.getTokenPriceUSDC(tokenAddr); - if (!chainLinkPrice.reverted) { - log.info("[ChainLinkFeed] tokenAddress: {}, Price: {}", [ - tokenAddr.toHexString(), - chainLinkPrice.usdPrice.toString(), - ]); - return chainLinkPrice; + const oracleCount = oracle.oracleCount; + const oracleOrder = oracle.oracleOrder; + + const prices: CustomPriceType[] = []; + for (let i = 0; i < oracleOrder.length; i++) { + if (prices.length >= oracleCount) { + break; + } + + let oraclePrice = new CustomPriceType(); + + if (oracleOrder[i] == constants.OracleType.YEARN_LENS_ORACLE) { + oraclePrice = YearnLensOracle.getTokenPriceUSDC(tokenAddr, block); + } else if (oracleOrder[i] == constants.OracleType.CHAINLINK_FEED) { + oraclePrice = ChainLinkFeed.getTokenPriceUSDC(tokenAddr, block); + } else if (oracleOrder[i] == constants.OracleType.CURVE_CALCULATIONS) { + oraclePrice = CurveCalculations.getTokenPriceUSDC(tokenAddr, block); + } else if (oracleOrder[i] == constants.OracleType.SUSHI_CALCULATIONS) { + oraclePrice = SushiCalculations.getTokenPriceUSDC(tokenAddr, block); + } else if (oracleOrder[i] == constants.OracleType.AAVE_ORACLE) { + oraclePrice = AaveOracle.getTokenPriceUSDC(tokenAddr, block); + } else if (oracleOrder[i] == constants.OracleType.CURVE_ROUTER) { + oraclePrice = CurveRouter.getCurvePriceUsdc(tokenAddr, block); + } else if (oracleOrder[i] == constants.OracleType.UNISWAP_FORKS_ROUTER) { + oraclePrice = UniswapForksRouter.getTokenPriceUSDC(tokenAddr, block); + } + + if (!oraclePrice.reverted) { + prices.push(oraclePrice); + } } - // 3. CalculationsCurve - const calculationsCurvePrice = CurveCalculations.getTokenPriceUSDC(tokenAddr); - if (!calculationsCurvePrice.reverted) { - log.info("[CalculationsCurve] tokenAddress: {}, Price: {}", [ + if (prices.length == constants.INT_ZERO) { + log.warning("[Oracle] Failed to Fetch Price, tokenAddr: {}", [ tokenAddr.toHexString(), - calculationsCurvePrice.usdPrice.toString(), ]); - return calculationsCurvePrice; - } - // 4. CalculationsSushiSwap - const calculationsSushiSwapPrice = - SushiCalculations.getTokenPriceUSDC(tokenAddr); - if (!calculationsSushiSwapPrice.reverted) { - log.info("[CalculationsSushiSwap] tokenAddress: {}, Price: {}", [ - tokenAddr.toHexString(), - calculationsSushiSwapPrice.usdPrice.toString(), - ]); - return calculationsSushiSwapPrice; + return new CustomPriceType(); + } else if (prices.length == constants.INT_ONE) { + return prices[constants.INT_ZERO]; + } else if (prices.length == constants.INT_TWO) { + return utils.averagePrice(prices); } - // 6. Aave Oracle - const aaveOraclePrice = AaveOracle.getTokenPriceUSDC(tokenAddr); - if (!aaveOraclePrice.reverted) { - log.info("[AaveOracle] tokenAddress: {}, Price: {}", [ - tokenAddr.toHexString(), - aaveOraclePrice.usdPrice.toString(), - ]); - return aaveOraclePrice; - } + const k = Math.ceil(prices.length / constants.INT_TWO) as i32; + const closestPrices = utils.kClosestPrices(k, prices); - // 7. Curve Router - const curvePrice = CurveRouter.getCurvePriceUsdc(tokenAddr); - if (!curvePrice.reverted) { - log.info("[CurveRouter] tokenAddress: {}, Price: {}", [ - tokenAddr.toHexString(), - curvePrice.usdPrice.toString(), - ]); - return curvePrice; - } + return utils.averagePrice(closestPrices); +} - // 8. Uniswap Router - const uniswapPrice = UniswapForksRouter.getTokenPriceUSDC(tokenAddr); - if (!uniswapPrice.reverted) { - log.info("[UniswapRouter] tokenAddress: {}, Price: {}", [ - tokenAddr.toHexString(), - uniswapPrice.usdPrice.toString(), - ]); - return uniswapPrice; +export function getLiquidityBoundPrice( + tokenAddress: Address, + tokenPrice: CustomPriceType, + amount: BigDecimal +): BigDecimal { + const reportedPriceUSD = tokenPrice.usdPrice.times(amount); + const liquidity = tokenPrice.liquidity; + + let liquidityBoundPriceUSD = reportedPriceUSD; + if (liquidity > constants.BIGDECIMAL_ZERO && reportedPriceUSD > liquidity) { + liquidityBoundPriceUSD = liquidity + .div( + constants.BIGINT_TEN.pow( + constants.DEFAULT_USDC_DECIMALS as u8 + ).toBigDecimal() + ) + .times(constants.BIGINT_TEN.pow(tokenPrice.decimals as u8).toBigDecimal()) + .div(amount); + + log.warning( + "[getLiquidityBoundPrice] reported (token price * amount): ({} * {}) bound to: {} for token: {} due to insufficient liquidity: {}", + [ + tokenPrice.usdPrice.toString(), + amount.toString(), + liquidityBoundPriceUSD.toString(), + tokenAddress.toHexString(), + liquidity.toString(), + ] + ); } - log.warning("[Oracle] Failed to Fetch Price, Name: {} Address: {}", [ - utils.getTokenName(tokenAddr), - tokenAddr.toHexString(), - ]); - - return new CustomPriceType(); + return liquidityBoundPriceUSD; } export function getUsdPrice( tokenAddr: Address, - amount: BigDecimal + amount: BigDecimal, + block: ethereum.Block | null = null ): BigDecimal { - const tokenPrice = getUsdPricePerToken(tokenAddr); + const tokenPrice = getUsdPricePerToken(tokenAddr, block); if (!tokenPrice.reverted) { + if ( + tokenPrice.oracleType == constants.OracleType.UNISWAP_FORKS_ROUTER || + tokenPrice.oracleType == constants.OracleType.CURVE_ROUTER + ) { + return getLiquidityBoundPrice(tokenAddr, tokenPrice, amount); + } return tokenPrice.usdPrice.times(amount); } diff --git a/subgraphs/polygon-bridge/src/prices/oracles/AaveOracle.ts b/subgraphs/polygon-bridge/src/prices/oracles/AaveOracle.ts index a6f7db7077..e7eac03631 100644 --- a/subgraphs/polygon-bridge/src/prices/oracles/AaveOracle.ts +++ b/subgraphs/polygon-bridge/src/prices/oracles/AaveOracle.ts @@ -1,24 +1,32 @@ import * as utils from "../common/utils"; import * as constants from "../common/constants"; -import { CustomPriceType } from "../common/types"; -import { Address, BigDecimal, BigInt } from "@graphprotocol/graph-ts"; +import { CustomPriceType, OracleContract } from "../common/types"; +import { Address, BigDecimal, BigInt, ethereum } from "@graphprotocol/graph-ts"; import { AaveOracleContract } from "../../../generated/FxERC20Events/AaveOracleContract"; export function getAaveOracleContract( - contractAddress: Address + contract: OracleContract, + block: ethereum.Block | null = null ): AaveOracleContract | null { - if (utils.isNullAddress(contractAddress)) return null; + if ( + (block && contract.startBlock.gt(block.number)) || + utils.isNullAddress(contract.address) + ) + return null; - return AaveOracleContract.bind(contractAddress); + return AaveOracleContract.bind(contract.address); } -export function getTokenPriceUSDC(tokenAddr: Address): CustomPriceType { +export function getTokenPriceUSDC( + tokenAddr: Address, + block: ethereum.Block | null = null +): CustomPriceType { const config = utils.getConfig(); if (!config || config.aaveOracleBlacklist().includes(tokenAddr)) return new CustomPriceType(); - const aaveOracleContract = getAaveOracleContract(config.aaveOracle()); + const aaveOracleContract = getAaveOracleContract(config.aaveOracle(), block); if (!aaveOracleContract) return new CustomPriceType(); const tokenPrice: BigDecimal = utils @@ -28,5 +36,9 @@ export function getTokenPriceUSDC(tokenAddr: Address): CustomPriceType { ) .toBigDecimal(); - return CustomPriceType.initialize(tokenPrice, constants.AAVE_ORACLE_DECIMALS); + return CustomPriceType.initialize( + tokenPrice, + constants.AAVE_ORACLE_DECIMALS, + constants.OracleType.AAVE_ORACLE + ); } diff --git a/subgraphs/polygon-bridge/src/prices/oracles/ChainLinkFeed.ts b/subgraphs/polygon-bridge/src/prices/oracles/ChainLinkFeed.ts index acc3e35933..69a1980441 100644 --- a/subgraphs/polygon-bridge/src/prices/oracles/ChainLinkFeed.ts +++ b/subgraphs/polygon-bridge/src/prices/oracles/ChainLinkFeed.ts @@ -1,22 +1,31 @@ import * as utils from "../common/utils"; import * as constants from "../common/constants"; -import { Address } from "@graphprotocol/graph-ts"; -import { CustomPriceType } from "../common/types"; +import { Address, ethereum } from "@graphprotocol/graph-ts"; +import { CustomPriceType, OracleContract } from "../common/types"; import { ChainLinkContract } from "../../../generated/FxERC20Events/ChainLinkContract"; -export function getChainLinkContract(): ChainLinkContract | null { - const config = utils.getConfig(); - if (!config || utils.isNullAddress(config.chainLink())) return null; - - return ChainLinkContract.bind(config.chainLink()); +export function getChainLinkContract( + contract: OracleContract, + block: ethereum.Block | null = null +): ChainLinkContract | null { + if ( + (block && contract.startBlock.gt(block.number)) || + utils.isNullAddress(contract.address) + ) + return null; + + return ChainLinkContract.bind(contract.address); } -export function getTokenPriceUSDC(tokenAddr: Address): CustomPriceType { - const chainLinkContract = getChainLinkContract(); +export function getTokenPriceUSDC( + tokenAddr: Address, + block: ethereum.Block | null = null +): CustomPriceType { + const config = utils.getConfig(); + if (!config) return new CustomPriceType(); - if (!chainLinkContract) { - return new CustomPriceType(); - } + const chainLinkContract = getChainLinkContract(config.chainLink(), block); + if (!chainLinkContract) return new CustomPriceType(); const result = chainLinkContract.try_latestRoundData( tokenAddr, @@ -35,7 +44,8 @@ export function getTokenPriceUSDC(tokenAddr: Address): CustomPriceType { return CustomPriceType.initialize( result.value.value1.toBigDecimal(), - decimals.value + decimals.value, + constants.OracleType.CHAINLINK_FEED ); } diff --git a/subgraphs/polygon-bridge/src/prices/oracles/YearnLensOracle.ts b/subgraphs/polygon-bridge/src/prices/oracles/YearnLensOracle.ts index 28ba14fab8..defb89410a 100644 --- a/subgraphs/polygon-bridge/src/prices/oracles/YearnLensOracle.ts +++ b/subgraphs/polygon-bridge/src/prices/oracles/YearnLensOracle.ts @@ -1,24 +1,32 @@ import * as utils from "../common/utils"; import * as constants from "../common/constants"; -import { CustomPriceType } from "../common/types"; -import { Address, BigDecimal, BigInt } from "@graphprotocol/graph-ts"; +import { CustomPriceType, OracleContract } from "../common/types"; +import { Address, BigDecimal, BigInt, ethereum } from "@graphprotocol/graph-ts"; import { YearnLensContract } from "../../../generated/FxERC20Events/YearnLensContract"; export function getYearnLensContract( - contractAddress: Address + contract: OracleContract, + block: ethereum.Block | null = null ): YearnLensContract | null { - if (utils.isNullAddress(contractAddress)) return null; + if ( + (block && contract.startBlock.gt(block.number)) || + utils.isNullAddress(contract.address) + ) + return null; - return YearnLensContract.bind(contractAddress); + return YearnLensContract.bind(contract.address); } -export function getTokenPriceUSDC(tokenAddr: Address): CustomPriceType { +export function getTokenPriceUSDC( + tokenAddr: Address, + block: ethereum.Block | null = null +): CustomPriceType { const config = utils.getConfig(); if (!config || config.yearnLensBlacklist().includes(tokenAddr)) return new CustomPriceType(); - const yearnLensContract = getYearnLensContract(config.yearnLens()); + const yearnLensContract = getYearnLensContract(config.yearnLens(), block); if (!yearnLensContract) return new CustomPriceType(); const tokenPrice: BigDecimal = utils @@ -30,6 +38,7 @@ export function getTokenPriceUSDC(tokenAddr: Address): CustomPriceType { return CustomPriceType.initialize( tokenPrice, - constants.DEFAULT_USDC_DECIMALS + constants.DEFAULT_USDC_DECIMALS, + constants.OracleType.YEARN_LENS_ORACLE ); } diff --git a/subgraphs/polygon-bridge/src/prices/routers/CurveRouter.ts b/subgraphs/polygon-bridge/src/prices/routers/CurveRouter.ts index ded5309467..6a1a59cb40 100644 --- a/subgraphs/polygon-bridge/src/prices/routers/CurveRouter.ts +++ b/subgraphs/polygon-bridge/src/prices/routers/CurveRouter.ts @@ -1,25 +1,35 @@ +/* eslint-disable @typescript-eslint/no-magic-numbers */ import { getUsdPricePerToken } from ".."; import * as utils from "../common/utils"; import * as constants from "../common/constants"; import { CustomPriceType } from "../common/types"; -import { BigInt, Address, BigDecimal } from "@graphprotocol/graph-ts"; +import { BigInt, Address, BigDecimal, ethereum } from "@graphprotocol/graph-ts"; import { CurvePool as CurvePoolContract } from "../../../generated/FxERC20Events/CurvePool"; import { CurveRegistry as CurveRegistryContract } from "../../../generated/FxERC20Events/CurveRegistry"; -export function isCurveLpToken(lpAddress: Address): bool { - const poolAddress = getPoolFromLpToken(lpAddress); +export function isCurveLpToken( + lpAddress: Address, + block: ethereum.Block +): bool { + const poolAddress = getPoolFromLpToken(lpAddress, block); if (poolAddress.notEqual(constants.NULL.TYPE_ADDRESS)) return true; return false; } -export function getPoolFromLpToken(lpAddress: Address): Address { +export function getPoolFromLpToken( + lpAddress: Address, + block: ethereum.Block | null = null +): Address { const config = utils.getConfig(); const curveRegistryAdresses = config.curveRegistry(); for (let idx = 0; idx < curveRegistryAdresses.length; idx++) { + const curveRegistry = curveRegistryAdresses[idx]; + if (block && curveRegistry.startBlock.gt(block.number)) continue; + const curveRegistryContract = CurveRegistryContract.bind( - curveRegistryAdresses[idx] + curveRegistry.address ); const poolAddress = utils.readValue
( @@ -33,8 +43,11 @@ export function getPoolFromLpToken(lpAddress: Address): Address { return constants.NULL.TYPE_ADDRESS; } -export function isLpCryptoPool(lpAddress: Address): bool { - const poolAddress = getPoolFromLpToken(lpAddress); +export function isLpCryptoPool( + lpAddress: Address, + block: ethereum.Block | null = null +): bool { + const poolAddress = getPoolFromLpToken(lpAddress, block); if (poolAddress != constants.NULL.TYPE_ADDRESS) { return isPoolCryptoPool(poolAddress); @@ -57,13 +70,15 @@ export function isPoolCryptoPool(poolAddress: Address): bool { return false; } -export function getCurvePriceUsdc(lpAddress: Address): CustomPriceType { - if (isLpCryptoPool(lpAddress)) { - return cryptoPoolLpPriceUsdc(lpAddress); - } +export function getCurvePriceUsdc( + lpAddress: Address, + block: ethereum.Block | null = null +): CustomPriceType { + if (isLpCryptoPool(lpAddress, block)) + return cryptoPoolLpPriceUsdc(lpAddress, block); - const basePrice = getBasePrice(lpAddress); - const virtualPrice = getVirtualPrice(lpAddress).toBigDecimal(); + const basePrice = getBasePrice(lpAddress, block); + const virtualPrice = getVirtualPrice(lpAddress, block).toBigDecimal(); const config = utils.getConfig(); const usdcTokenDecimals = config.usdcTokenDecimals(); @@ -76,31 +91,44 @@ export function getCurvePriceUsdc(lpAddress: Address): CustomPriceType { constants.BIGINT_TEN.pow(decimalsAdjustment.toI32() as u8).toBigDecimal() ); + const liquidity = getLpTokenLiquidityUsdc(lpAddress, block); + return CustomPriceType.initialize( priceUsdc, - decimalsAdjustment.plus(constants.DEFAULT_DECIMALS).toI32() as u8 + decimalsAdjustment.plus(constants.DEFAULT_DECIMALS).toI32() as u8, + constants.OracleType.CURVE_ROUTER, + liquidity.usdPrice ); } -export function getBasePrice(lpAddress: Address): CustomPriceType { - const poolAddress = getPoolFromLpToken(lpAddress); +export function getBasePrice( + lpAddress: Address, + block: ethereum.Block | null = null +): CustomPriceType { + const poolAddress = getPoolFromLpToken(lpAddress, block); if (poolAddress.equals(constants.NULL.TYPE_ADDRESS)) return new CustomPriceType(); - const underlyingCoinAddress = getUnderlyingCoinFromPool(poolAddress); - const basePrice = getPriceUsdcRecommended(underlyingCoinAddress); + const underlyingCoinAddress = getUnderlyingCoinFromPool(poolAddress, block); + const basePrice = getPriceUsdcRecommended(underlyingCoinAddress, block); return basePrice; } -export function getUnderlyingCoinFromPool(poolAddress: Address): Address { +export function getUnderlyingCoinFromPool( + poolAddress: Address, + block: ethereum.Block | null = null +): Address { const config = utils.getConfig(); const curveRegistryAdresses = config.curveRegistry(); for (let idx = 0; idx < curveRegistryAdresses.length; idx++) { + const curveRegistry = curveRegistryAdresses[idx]; + if (block && curveRegistry.startBlock.gt(block.number)) continue; + const curveRegistryContract = CurveRegistryContract.bind( - curveRegistryAdresses[idx] + curveRegistry.address ); const coins = utils.readValue( @@ -135,13 +163,19 @@ export function getPreferredCoinFromCoins(coins: Address[]): Address { return preferredCoinAddress; } -export function getVirtualPrice(curveLpTokenAddress: Address): BigInt { +export function getVirtualPrice( + curveLpTokenAddress: Address, + block: ethereum.Block | null = null +): BigInt { const config = utils.getConfig(); const curveRegistryAdresses = config.curveRegistry(); for (let idx = 0; idx < curveRegistryAdresses.length; idx++) { + const curveRegistry = curveRegistryAdresses[idx]; + if (block && curveRegistry.startBlock.gt(block.number)) continue; + const curveRegistryContract = CurveRegistryContract.bind( - curveRegistryAdresses[idx] + curveRegistry.address ); const virtualPriceCall = @@ -156,15 +190,19 @@ export function getVirtualPrice(curveLpTokenAddress: Address): BigInt { } export function getPriceUsdcRecommended( - tokenAddress: Address + tokenAddress: Address, + block: ethereum.Block | null = null ): CustomPriceType { - return getUsdPricePerToken(tokenAddress); + return getUsdPricePerToken(tokenAddress, block); } -export function cryptoPoolLpPriceUsdc(lpAddress: Address): CustomPriceType { +export function cryptoPoolLpPriceUsdc( + lpAddress: Address, + block: ethereum.Block | null = null +): CustomPriceType { const totalSupply = utils.getTokenSupply(lpAddress); - const totalValueUsdc = cryptoPoolLpTotalValueUsdc(lpAddress); + const totalValueUsdc = cryptoPoolLpTotalValueUsdc(lpAddress, block); const priceUsdc = totalValueUsdc .times( constants.BIGINT_TEN.pow( @@ -173,11 +211,18 @@ export function cryptoPoolLpPriceUsdc(lpAddress: Address): CustomPriceType { ) .div(totalSupply.toBigDecimal()); - return CustomPriceType.initialize(priceUsdc, 0); + return CustomPriceType.initialize( + priceUsdc, + 0, + constants.OracleType.CURVE_ROUTER + ); } -export function cryptoPoolLpTotalValueUsdc(lpAddress: Address): BigDecimal { - const poolAddress = getPoolFromLpToken(lpAddress); +export function cryptoPoolLpTotalValueUsdc( + lpAddress: Address, + block: ethereum.Block | null = null +): BigDecimal { + const poolAddress = getPoolFromLpToken(lpAddress, block); const underlyingTokensAddresses = cryptoPoolUnderlyingTokensAddressesByPoolAddress(poolAddress); @@ -192,7 +237,8 @@ export function cryptoPoolLpTotalValueUsdc(lpAddress: Address): BigDecimal { const tokenValueUsdc = cryptoPoolTokenAmountUsdc( poolAddress, underlyingTokensAddresses[tokenIdx], - BigInt.fromI32(tokenIdx) + BigInt.fromI32(tokenIdx), + block ); totalValue = totalValue.plus(tokenValueUsdc); } @@ -203,7 +249,8 @@ export function cryptoPoolLpTotalValueUsdc(lpAddress: Address): BigDecimal { export function cryptoPoolTokenAmountUsdc( poolAddress: Address, tokenAddress: Address, - tokenIdx: BigInt + tokenIdx: BigInt, + block: ethereum.Block | null = null ): BigDecimal { const poolContract = CurvePoolContract.bind(poolAddress); @@ -215,7 +262,7 @@ export function cryptoPoolTokenAmountUsdc( .toBigDecimal(); const tokenDecimals = utils.getTokenDecimals(tokenAddress); - const tokenPrice = getPriceUsdcRecommended(tokenAddress); + const tokenPrice = getPriceUsdcRecommended(tokenAddress, block); const tokenValueUsdc = tokenBalance .times(tokenPrice.usdPrice) .div(constants.BIGINT_TEN.pow(tokenDecimals.toI32() as u8).toBigDecimal()); @@ -247,10 +294,12 @@ export function cryptoPoolUnderlyingTokensAddressesByPoolAddress( return coins; } -export function getPriceUsdc(tokenAddress: Address): CustomPriceType { - if (isCurveLpToken(tokenAddress)) { - return getCurvePriceUsdc(tokenAddress); - } +export function getPriceUsdc( + tokenAddress: Address, + block: ethereum.Block +): CustomPriceType { + if (isCurveLpToken(tokenAddress, block)) + return getCurvePriceUsdc(tokenAddress, block); const poolContract = CurvePoolContract.bind(tokenAddress); const virtualPrice = utils @@ -271,10 +320,49 @@ export function getPriceUsdc(tokenAddress: Address): CustomPriceType { } const preferredCoin = getPreferredCoinFromCoins(coins); - const price = getPriceUsdcRecommended(preferredCoin); + const price = getPriceUsdcRecommended(preferredCoin, block); return CustomPriceType.initialize( price.usdPrice.times(virtualPrice), - constants.DEFAULT_DECIMALS.toI32() as u8 + constants.DEFAULT_DECIMALS.toI32() as u8, + constants.OracleType.CURVE_ROUTER + ); +} + +function getLpTokenLiquidityUsdc( + lpAddress: Address, + block: ethereum.Block | null = null +): CustomPriceType { + const poolAddress = getPoolFromLpToken(lpAddress, block); + const poolContract = CurvePoolContract.bind(poolAddress); + + let liquidity = constants.BIGDECIMAL_ZERO; + for (let i = 0; i < 8; i++) { + const coin = utils.readValue
( + poolContract.try_coins(BigInt.fromI32(i)), + constants.NULL.TYPE_ADDRESS + ); + if (coin.equals(constants.NULL.TYPE_ADDRESS) || coin.equals(lpAddress)) + continue; + + const decimals = utils.getTokenDecimals(coin); + const balance = utils.readValue( + poolContract.try_balances(BigInt.fromI32(i as i32)), + constants.BIGINT_ZERO + ); + + const price = getPriceUsdcRecommended(coin, block); + liquidity = liquidity.plus( + balance + .div(constants.BIGINT_TEN.pow(decimals.toI32() as u8)) + .toBigDecimal() + .times(price.usdPrice) + ); + } + + return CustomPriceType.initialize( + liquidity, + constants.DEFAULT_USDC_DECIMALS, + constants.OracleType.CURVE_ROUTER ); } diff --git a/subgraphs/polygon-bridge/src/prices/routers/UniswapForksRouter.ts b/subgraphs/polygon-bridge/src/prices/routers/UniswapForksRouter.ts index 7125513e5a..4bec230f23 100644 --- a/subgraphs/polygon-bridge/src/prices/routers/UniswapForksRouter.ts +++ b/subgraphs/polygon-bridge/src/prices/routers/UniswapForksRouter.ts @@ -1,9 +1,11 @@ +/* eslint-disable @typescript-eslint/no-magic-numbers */ import * as utils from "../common/utils"; import * as constants from "../common/constants"; import { CustomPriceType } from "../common/types"; -import { Address, BigInt, log } from "@graphprotocol/graph-ts"; +import { Address, BigInt, ethereum, log } from "@graphprotocol/graph-ts"; import { UniswapPair as UniswapPairContract } from "../../../generated/FxERC20Events/UniswapPair"; import { UniswapRouter as UniswapRouterContract } from "../../../generated/FxERC20Events/UniswapRouter"; +import { UniswapFactory as UniswapFactoryContract } from "../../../generated/FxERC20Events/UniswapFactory"; export function isLpToken(tokenAddress: Address, ethAddress: Address): bool { if (tokenAddress.equals(ethAddress)) return false; @@ -19,7 +21,10 @@ export function isLpToken(tokenAddress: Address, ethAddress: Address): bool { return true; } -export function getTokenPriceUSDC(tokenAddress: Address): CustomPriceType { +export function getTokenPriceUSDC( + tokenAddress: Address, + block: ethereum.Block | null = null +): CustomPriceType { const config = utils.getConfig(); if (!config) return new CustomPriceType(); @@ -27,21 +32,23 @@ export function getTokenPriceUSDC(tokenAddress: Address): CustomPriceType { const usdcAddress = config.usdcAddress(); if (isLpToken(tokenAddress, ethAddress)) { - return getLpTokenPriceUsdc(tokenAddress); + return getLpTokenPriceUsdc(tokenAddress, block); } - return getPriceFromRouterUSDC(tokenAddress, usdcAddress); + return getPriceFromRouterUSDC(tokenAddress, usdcAddress, block); } export function getPriceFromRouterUSDC( tokenAddress: Address, - usdcAddress: Address + usdcAddress: Address, + block: ethereum.Block | null = null ): CustomPriceType { - return getPriceFromRouter(tokenAddress, usdcAddress); + return getPriceFromRouter(tokenAddress, usdcAddress, block); } export function getPriceFromRouter( token0Address: Address, - token1Address: Address + token1Address: Address, + block: ethereum.Block | null = null ): CustomPriceType { const config = utils.getConfig(); @@ -79,14 +86,17 @@ export function getPriceFromRouter( const routerAddresses = config.uniswapForks(); + let routerAddress = constants.NULL.TYPE_ADDRESS; let amountOut = constants.BIGINT_ZERO; for (let idx = 0; idx < routerAddresses.length; idx++) { - const routerAddress = routerAddresses.at(idx); + const router = routerAddresses[idx]; + if (block && router.startBlock.gt(block.number)) continue; - const uniswapForkRouter = UniswapRouterContract.bind(routerAddress); + const uniswapForkRouter = UniswapRouterContract.bind(router.address); const amountOutArray = uniswapForkRouter.try_getAmountsOut(amountIn, path); if (!amountOutArray.reverted) { + routerAddress = router.address; amountOut = amountOutArray.value[amountOutArray.value.length - 1]; break; } @@ -99,17 +109,43 @@ export function getPriceFromRouter( .div(constants.BIGINT_TEN_THOUSAND.minus(feeBips.times(numberOfJumps))) .toBigDecimal(); - return CustomPriceType.initialize( + const priceFromRouter = CustomPriceType.initialize( amountOutBigDecimal, - config.usdcTokenDecimals().toI32() as u8 + config.usdcTokenDecimals().toI32() as u8, + constants.OracleType.UNISWAP_FORKS_ROUTER + ); + + const routerContract = UniswapRouterContract.bind(routerAddress); + const factoryAddress = utils.readValue( + routerContract.try_factory(), + constants.NULL.TYPE_ADDRESS ); + if (factoryAddress.equals(constants.NULL.TYPE_ADDRESS)) + return priceFromRouter; + + const factoryContract = UniswapFactoryContract.bind(factoryAddress); + const tokenPair = utils.readValue( + factoryContract.try_getPair(token0Address, wethAddress), + constants.NULL.TYPE_ADDRESS + ); + if (tokenPair.equals(constants.NULL.TYPE_ADDRESS)) return priceFromRouter; + + const liquidityUSD = getLpTokenLiquidityUsdc(tokenPair, wethAddress, block); + priceFromRouter.setLiquidity(liquidityUSD.usdPrice); + + return priceFromRouter; } -export function getLpTokenPriceUsdc(tokenAddress: Address): CustomPriceType { +export function getLpTokenPriceUsdc( + tokenAddress: Address, + block: ethereum.Block | null = null +): CustomPriceType { const uniSwapPair = UniswapPairContract.bind(tokenAddress); - const totalLiquidity: CustomPriceType = - getLpTokenTotalLiquidityUsdc(tokenAddress); + const totalLiquidity: CustomPriceType = getLpTokenTotalLiquidityUsdc( + tokenAddress, + block + ); const totalSupply = utils.readValue( uniSwapPair.try_totalSupply(), constants.BIGINT_ZERO @@ -138,12 +174,14 @@ export function getLpTokenPriceUsdc(tokenAddress: Address): CustomPriceType { return CustomPriceType.initialize( pricePerLpTokenUsdc, - constants.DEFAULT_USDC_DECIMALS + constants.DEFAULT_USDC_DECIMALS, + constants.OracleType.UNISWAP_FORKS_ROUTER ); } export function getLpTokenTotalLiquidityUsdc( - tokenAddress: Address + tokenAddress: Address, + block: ethereum.Block | null = null ): CustomPriceType { const uniSwapPair = UniswapPairContract.bind(tokenAddress); @@ -170,8 +208,8 @@ export function getLpTokenTotalLiquidityUsdc( if (reservesCall.reverted) return new CustomPriceType(); - const token0Price = getTokenPriceUSDC(token0Address); - const token1Price = getTokenPriceUSDC(token1Address); + const token0Price = getTokenPriceUSDC(token0Address, block); + const token1Price = getTokenPriceUSDC(token1Address, block); if (token0Price.reverted || token1Price.reverted) { return new CustomPriceType(); @@ -186,20 +224,73 @@ export function getLpTokenTotalLiquidityUsdc( reserve1.notEqual(constants.BIGINT_ZERO) ) { const liquidity0 = reserve0 - .div(constants.BIGINT_TEN.pow(token0Decimals.toI32() as u8)) .toBigDecimal() + .div( + constants.BIGINT_TEN.pow(token0Decimals.toI32() as u8).toBigDecimal() + ) .times(token0Price.usdPrice); const liquidity1 = reserve1 - .div(constants.BIGINT_TEN.pow(token1Decimals.toI32() as u8)) .toBigDecimal() + .div( + constants.BIGINT_TEN.pow(token1Decimals.toI32() as u8).toBigDecimal() + ) .times(token1Price.usdPrice); const totalLiquidity = liquidity0.plus(liquidity1); return CustomPriceType.initialize( totalLiquidity, - constants.DEFAULT_USDC_DECIMALS + constants.DEFAULT_USDC_DECIMALS, + constants.OracleType.UNISWAP_FORKS_ROUTER + ); + } + return new CustomPriceType(); +} + +function getLpTokenLiquidityUsdc( + lpAddress: Address, + wethAddress: Address, + block: ethereum.Block | null = null +): CustomPriceType { + const uniSwapPair = UniswapPairContract.bind(lpAddress); + + const token0Call = uniSwapPair.try_token0(); + if (token0Call.reverted) return new CustomPriceType(); + const token0Address = token0Call.value; + + const token1Call = uniSwapPair.try_token1(); + if (token1Call.reverted) return new CustomPriceType(); + const token1Address = token1Call.value; + + const reservesCall = uniSwapPair.try_getReserves(); + if (reservesCall.reverted) return new CustomPriceType(); + const reserves = reservesCall.value; + + let wethReserves = constants.BIGINT_ZERO; + if (token0Address == wethAddress) { + wethReserves = reserves.value0; + } else if (token1Address == wethAddress) { + wethReserves = reserves.value1; + } + + const wethPrice = getTokenPriceUSDC(wethAddress, block); + if (wethPrice.reverted) { + return new CustomPriceType(); + } + + const wethDecimals = utils.getTokenDecimals(wethAddress); + + if (wethReserves.notEqual(constants.BIGINT_ZERO)) { + const liquidity = wethReserves + .toBigDecimal() + .div(constants.BIGINT_TEN.pow(wethDecimals.toI32() as u8).toBigDecimal()) + .times(wethPrice.usdPrice); + + return CustomPriceType.initialize( + liquidity, + constants.DEFAULT_USDC_DECIMALS, + constants.OracleType.UNISWAP_FORKS_ROUTER ); } return new CustomPriceType();