From 18cf3cda5d6175d97797e39773853f8bac413ac2 Mon Sep 17 00:00:00 2001 From: Soil King <157099073+soilking@users.noreply.github.com> Date: Thu, 26 Sep 2024 11:52:55 -0700 Subject: [PATCH] Fix inconsistent rate order --- projects/subgraph-basin/schema.graphql | 12 ++++++------ projects/subgraph-basin/src/utils/Well.ts | 1 + projects/subgraph-basin/src/utils/legacy/CP2.ts | 6 +++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/projects/subgraph-basin/schema.graphql b/projects/subgraph-basin/schema.graphql index ab45e2df9..3b16b57b8 100644 --- a/projects/subgraph-basin/schema.graphql +++ b/projects/subgraph-basin/schema.graphql @@ -118,7 +118,7 @@ type Well @entity { " The sum of all active and non-active liquidity in USD for this well. " totalLiquidityUSD: BigDecimal! - " The current price of each token in terms of the other token. " + " The current amount of each token needed to exchange for one of the other token. " tokenPrice: [BigInt!]! " Amount of each token in the well. The ordering should be the same as the well's `tokens` field. " @@ -249,7 +249,7 @@ type WellDailySnapshot @entity { " The sum of all active and non-active liquidity in USD for this well. " totalLiquidityUSD: BigDecimal! - " The current price of each token in terms of the other token. " + " The current amount of each token needed to exchange for one of the other token. " tokenPrice: [BigInt!]! " All trade volume occurred for a specific token, in native amount. Volume for an individual token is defined as a purchase of that token. This includes any net trading activity as a result of add/remove liquidity. The ordering should be the same as the well's `tokens` field. " @@ -345,7 +345,7 @@ type WellHourlySnapshot @entity { " The sum of all active and non-active liquidity in USD for this well. " totalLiquidityUSD: BigDecimal! - " The current price of each token in terms of the other token. " + " The current amount of each token needed to exchange for one of the other token. " tokenPrice: [BigInt!]! " All trade volume occurred for a specific token, in native amount. Volume for an individual token is defined as a purchase of that token. This includes any net trading activity as a result of add/remove liquidity. The ordering should be the same as the well's `tokens` field. " @@ -476,7 +476,7 @@ type Deposit @entity(immutable: true) { " USD-normalized value of the transaction of the underlying (e.g. sum of tokens deposited into a well) " amountUSD: BigDecimal! - " The price of each token in terms of the other token, after this event. " + " The current amount of each token needed to exchange for one of the other token, after this event. " tokenPrice: [BigInt!]! " Block number of this event " @@ -530,7 +530,7 @@ type Withdraw @entity(immutable: true) { " USD-normalized value of the transaction of the underlying (e.g. sum of tokens withdrawn from a well) " amountUSD: BigDecimal! - " The price of each token in terms of the other token, after this event. " + " The current amount of each token needed to exchange for one of the other token, after this event. " tokenPrice: [BigInt!]! " Block number of this event " @@ -583,7 +583,7 @@ type Swap @entity(immutable: true) { " Amount of the token withdrawn from the well in native units " amountOut: BigInt! - " The price of each token in terms of the other token, after this event. " + " The current amount of each token needed to exchange for one of the other token, after this event. " tokenPrice: [BigInt!]! " Block number of this event " diff --git a/projects/subgraph-basin/src/utils/Well.ts b/projects/subgraph-basin/src/utils/Well.ts index 9c8347189..0b785a3f9 100644 --- a/projects/subgraph-basin/src/utils/Well.ts +++ b/projects/subgraph-basin/src/utils/Well.ts @@ -48,6 +48,7 @@ export function updateWellTokenUSDPrices(wellAddress: Address, blockNumber: BigI well.save(); } +// Value at index i is how much of token i is received in exchange for one of token 1 - i. export function getTokenPrices(well: Well): BigInt[] { const wellFn = well.wellFunction.load()[0]; const wellFnAddress = toAddress(wellFn.target); diff --git a/projects/subgraph-basin/src/utils/legacy/CP2.ts b/projects/subgraph-basin/src/utils/legacy/CP2.ts index e365dade6..185029bb5 100644 --- a/projects/subgraph-basin/src/utils/legacy/CP2.ts +++ b/projects/subgraph-basin/src/utils/legacy/CP2.ts @@ -8,8 +8,8 @@ export function calcRates(reserves: BigInt[], tokenDecimals: u32[]): BigInt[] { } return [ - reserves[1].times(BI_10.pow(tokenDecimals[0])).div(reserves[0]), - reserves[0].times(BI_10.pow(tokenDecimals[1])).div(reserves[1]) + reserves[0].times(BI_10.pow(tokenDecimals[1])).div(reserves[1]), + reserves[1].times(BI_10.pow(tokenDecimals[0])).div(reserves[0]) ]; } @@ -35,7 +35,7 @@ export function calcRates(reserves: BigInt[], tokenDecimals: u32[]): BigInt[] { * @param addedReserves - the net change in reserves after the liquidity event * @returns a list of tokens and the amount bought of each. the purchased token is positive, the sold token negative. */ -export function calcLiquidityVolume_deprecated(currentReserves: BigInt[], addedReserves: BigInt[]): BigInt[] { +export function deprecated_calcLiquidityVolume(currentReserves: BigInt[], addedReserves: BigInt[]): BigInt[] { // Reserves prior to adding liquidity const initialReserves = deltaBigIntArray(currentReserves, addedReserves); const initialCp = initialReserves[0].times(initialReserves[1]);