Skip to content

Commit

Permalink
Fix inconsistent rate order
Browse files Browse the repository at this point in the history
  • Loading branch information
soilking committed Sep 26, 2024
1 parent 234d46c commit 18cf3cd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
12 changes: 6 additions & 6 deletions projects/subgraph-basin/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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. "
Expand Down Expand Up @@ -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. "
Expand Down Expand Up @@ -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. "
Expand Down Expand Up @@ -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 "
Expand Down Expand Up @@ -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 "
Expand Down Expand Up @@ -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 "
Expand Down
1 change: 1 addition & 0 deletions projects/subgraph-basin/src/utils/Well.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions projects/subgraph-basin/src/utils/legacy/CP2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export function calcRates(reserves: BigInt[], tokenDecimals: u32[]): BigInt[] {
}

return [
reserves[1].times(BI_10.pow(<u8>tokenDecimals[0])).div(reserves[0]),
reserves[0].times(BI_10.pow(<u8>tokenDecimals[1])).div(reserves[1])
reserves[0].times(BI_10.pow(<u8>tokenDecimals[1])).div(reserves[1]),
reserves[1].times(BI_10.pow(<u8>tokenDecimals[0])).div(reserves[0])
];
}

Expand All @@ -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]);
Expand Down

0 comments on commit 18cf3cd

Please sign in to comment.