Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix(#patch); pricelib; fix UniswapForksRouter.getLpTokenLiquidityUsdc decimals; add DPR override #2348

Merged
merged 5 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions deployment/deployment.json
Original file line number Diff line number Diff line change
Expand Up @@ -1352,7 +1352,7 @@
"status": "prod",
"versions": {
"schema": "1.2.0",
"subgraph": "1.1.1",
"subgraph": "1.1.2",
"methodology": "1.0.0"
},
"files": {
Expand All @@ -1374,7 +1374,7 @@
"status": "prod",
"versions": {
"schema": "1.2.0",
"subgraph": "1.1.1",
"subgraph": "1.1.2",
"methodology": "1.0.0"
},
"files": {
Expand Down Expand Up @@ -2618,7 +2618,7 @@
"status": "prod",
"versions": {
"schema": "1.4.0",
"subgraph": "1.0.6",
"subgraph": "1.0.7",
"methodology": "1.0.0"
},
"files": {
Expand Down Expand Up @@ -8164,7 +8164,7 @@
"status": "prod",
"versions": {
"schema": "1.2.0",
"subgraph": "1.1.1",
"subgraph": "1.1.2",
"methodology": "1.0.0"
},
"services": {
Expand All @@ -8185,7 +8185,7 @@
"status": "prod",
"versions": {
"schema": "1.2.0",
"subgraph": "1.1.1",
"subgraph": "1.1.2",
"methodology": "1.0.0"
},
"services": {
Expand Down
2 changes: 1 addition & 1 deletion subgraphs/_reference_/src/prices/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const CHAIN_LINK_USD_ADDRESS = Address.fromString(
"0x0000000000000000000000000000000000000348"
);

export const PRICE_LIB_VERSION = "1.3.1";
export const PRICE_LIB_VERSION = "1.3.2";

export const INT_ZERO = 0 as i32;
export const INT_ONE = 1 as i32;
Expand Down
9 changes: 9 additions & 0 deletions subgraphs/_reference_/src/prices/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ export function isNullAddress(tokenAddr: Address): boolean {
return tokenAddr.equals(constants.NULL.TYPE_ADDRESS);
}

export function bigIntToBigDecimal(
quantity: BigInt,
decimals: i32 = constants.DEFAULT_DECIMALS.toI32()
): BigDecimal {
return quantity.divDecimal(
constants.BIGINT_TEN.pow(decimals as u8).toBigDecimal()
);
}

export function readValue<T>(
callResult: ethereum.CallResult<T>,
defaultValue: T
Expand Down
25 changes: 25 additions & 0 deletions subgraphs/_reference_/src/prices/config/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,23 @@ class baxaOverride implements OracleConfig {
}
}

// https://github.com/messari/subgraphs/issues/2329
class delperOverride implements OracleConfig {
dhruv-chauhan marked this conversation as resolved.
Show resolved Hide resolved
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 /////////////////////////////////
///////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -261,6 +278,14 @@ export class config implements Configurations {
) {
return new baxaOverride();
}
if (
tokenAddr &&
[
Address.fromString("0x077416cc6242b3a7d8e42652b8a6a2599fda4a92"), // DPR
].includes(tokenAddr)
) {
return new delperOverride();
}
}

return null;
Expand Down
6 changes: 3 additions & 3 deletions subgraphs/_reference_/src/prices/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ export function getLiquidityBoundPrice(
.div(amount);

log.warning(
"[getLiquidityBoundPrice] reported (token price * amount): ({} * {}) bound to: {} for token: {} due to insufficient liquidity: {}",
"[getLiquidityBoundPrice] token: {} (reported price * amount): ({} * {}) bound to available liquidity: {}; new price: {}",
[
tokenAddress.toHexString(),
tokenPrice.usdPrice.toString(),
amount.toString(),
liquidityBoundPriceUSD.toString(),
tokenAddress.toHexString(),
liquidity.toString(),
liquidityBoundPriceUSD.toString(),
]
);
}
Expand Down
20 changes: 8 additions & 12 deletions subgraphs/_reference_/src/prices/routers/UniswapForksRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,6 @@ function getLpTokenLiquidityUsdc(
): 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;
Expand All @@ -267,10 +263,8 @@ function getLpTokenLiquidityUsdc(
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) {
let wethReserves = reserves.value0;
if (token1Address == wethAddress) {
wethReserves = reserves.value1;
}

Expand All @@ -282,13 +276,15 @@ function getLpTokenLiquidityUsdc(
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())
const liquidityUSDC = utils
.bigIntToBigDecimal(
wethReserves,
wethDecimals.toI32() - constants.DEFAULT_USDC_DECIMALS
)
.times(wethPrice.usdPrice);

return CustomPriceType.initialize(
liquidity,
liquidityUSDC,
constants.DEFAULT_USDC_DECIMALS,
constants.OracleType.UNISWAP_FORKS_ROUTER
);
Expand Down
6 changes: 3 additions & 3 deletions subgraphs/arbitrum-one-bridge/src/common/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Token } from "../../generated/schema";
import { bigIntToBigDecimal } from "../sdk/util/numbers";
import { TokenPricer } from "../sdk/protocols/config";
import { getUsdPrice, getUsdPricePerToken } from "../prices";
import { getUsdPrice } from "../prices";
import { TokenInitializer, TokenParams } from "../sdk/protocols/bridge/tokens";
import {
Address,
Expand All @@ -18,6 +18,7 @@ import {
import { BridgeConfig } from "../sdk/protocols/bridge/config";
import { Versions } from "../versions";
import {
BIGDECIMAL_ONE,
ETH_ADDRESS,
ETH_NAME,
ETH_SYMBOL,
Expand All @@ -37,8 +38,7 @@ export class Pricer implements TokenPricer {
return BIGDECIMAL_ZERO;
}

const price = getUsdPricePerToken(Address.fromBytes(token.id), this.block);
return price.usdPrice;
return getUsdPrice(Address.fromBytes(token.id), BIGDECIMAL_ONE, this.block);
}

getAmountValueUSD(token: Token, amount: BigInt): BigDecimal {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const CHAIN_LINK_USD_ADDRESS = Address.fromString(
"0x0000000000000000000000000000000000000348"
);

export const PRICE_LIB_VERSION = "1.3.1";
export const PRICE_LIB_VERSION = "1.3.2";

export const INT_ZERO = 0 as i32;
export const INT_ONE = 1 as i32;
Expand Down
9 changes: 9 additions & 0 deletions subgraphs/arbitrum-one-bridge/src/prices/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ export function isNullAddress(tokenAddr: Address): boolean {
return tokenAddr.equals(constants.NULL.TYPE_ADDRESS);
}

export function bigIntToBigDecimal(
quantity: BigInt,
decimals: i32 = constants.DEFAULT_DECIMALS.toI32()
): BigDecimal {
return quantity.divDecimal(
constants.BIGINT_TEN.pow(decimals as u8).toBigDecimal()
);
}

export function readValue<T>(
callResult: ethereum.CallResult<T>,
defaultValue: T
Expand Down
25 changes: 25 additions & 0 deletions subgraphs/arbitrum-one-bridge/src/prices/config/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,23 @@ class baxaOverride implements OracleConfig {
}
}

// https://github.com/messari/subgraphs/issues/2329
class delperOverride 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 /////////////////////////////////
///////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -261,6 +278,14 @@ export class config implements Configurations {
) {
return new baxaOverride();
}
if (
tokenAddr &&
[
Address.fromString("0x077416cc6242b3a7d8e42652b8a6a2599fda4a92"), // DPR
].includes(tokenAddr)
) {
return new delperOverride();
}
}

return null;
Expand Down
6 changes: 3 additions & 3 deletions subgraphs/arbitrum-one-bridge/src/prices/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ export function getLiquidityBoundPrice(
.div(amount);

log.warning(
"[getLiquidityBoundPrice] reported (token price * amount): ({} * {}) bound to: {} for token: {} due to insufficient liquidity: {}",
"[getLiquidityBoundPrice] token: {} (reported price * amount): ({} * {}) bound to available liquidity: {}; new price: {}",
[
tokenAddress.toHexString(),
tokenPrice.usdPrice.toString(),
amount.toString(),
liquidityBoundPriceUSD.toString(),
tokenAddress.toHexString(),
liquidity.toString(),
liquidityBoundPriceUSD.toString(),
]
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,6 @@ function getLpTokenLiquidityUsdc(
): 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;
Expand All @@ -267,10 +263,8 @@ function getLpTokenLiquidityUsdc(
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) {
let wethReserves = reserves.value0;
if (token1Address == wethAddress) {
wethReserves = reserves.value1;
}

Expand All @@ -282,13 +276,15 @@ function getLpTokenLiquidityUsdc(
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())
const liquidityUSDC = utils
.bigIntToBigDecimal(
wethReserves,
wethDecimals.toI32() - constants.DEFAULT_USDC_DECIMALS
)
.times(wethPrice.usdPrice);

return CustomPriceType.initialize(
liquidity,
liquidityUSDC,
constants.DEFAULT_USDC_DECIMALS,
constants.OracleType.UNISWAP_FORKS_ROUTER
);
Expand Down
Loading
Loading