diff --git a/schema.graphql b/schema.graphql index b859e12..e794d10 100644 --- a/schema.graphql +++ b/schema.graphql @@ -253,14 +253,14 @@ type BeefyCLVault @entity { """ currentPriceOfToken0InToken1: BigDecimal! - "Price range start this vault is currently configured to operate in" + "Price range start this vault is currently configured to operate in, in token 1" priceRangeMin1: BigDecimal! - "Price range end this vault is currently configured to operate in" + "Price range end this vault is currently configured to operate in, in token 1" priceRangeMax1: BigDecimal! - "Price range start this vault is currently configured to operate in in USD" - priceRangeMin1USD: BigDecimal! - "Price range end this vault is currently configured to operate in in USD" - priceRangeMax1USD: BigDecimal! + "Price range start this vault is currently configured to operate in, in USD" + priceRangeMinUSD: BigDecimal! + "Price range end this vault is currently configured to operate in, in USD" + priceRangeMaxUSD: BigDecimal! "Amount of underlying tokens in the vault. This is the first token." underlyingAmount0: BigDecimal! @@ -352,14 +352,14 @@ type BeefyCLVaultSnapshot implements Snapshot @entity { """ currentPriceOfToken0InToken1: BigDecimal! - "Price range start this vault is currently configured to operate in" + "Price range start this vault is currently configured to operate in, in token 1" priceRangeMin1: BigDecimal! - "Price range end this vault is currently configured to operate in" + "Price range end this vault is currently configured to operate in, in token 1" priceRangeMax1: BigDecimal! - "Price range start this vault is currently configured to operate in in USD" - priceRangeMin1USD: BigDecimal! - "Price range end this vault is currently configured to operate in in USD" - priceRangeMax1USD: BigDecimal! + "Price range start this vault is currently configured to operate in, in USD" + priceRangeMinUSD: BigDecimal! + "Price range end this vault is currently configured to operate in, in USD" + priceRangeMaxUSD: BigDecimal! "Amount of underlying tokens in the vault. This is the first token." underlyingAmount0: BigDecimal! diff --git a/src/entity/vault.ts b/src/entity/vault.ts index 7d72e23..6d95e80 100644 --- a/src/entity/vault.ts +++ b/src/entity/vault.ts @@ -30,8 +30,8 @@ export function getBeefyCLVault(vaultAddress: Bytes): BeefyCLVault { vault.currentPriceOfToken0InToken1 = ZERO_BD vault.priceRangeMin1 = ZERO_BD vault.priceRangeMax1 = ZERO_BD - vault.priceRangeMin1USD = ZERO_BD - vault.priceRangeMax1USD = ZERO_BD + vault.priceRangeMinUSD = ZERO_BD + vault.priceRangeMaxUSD = ZERO_BD vault.underlyingAmount0 = ZERO_BD vault.underlyingAmount1 = ZERO_BD vault.underlyingAmount0USD = ZERO_BD @@ -80,8 +80,8 @@ export function getBeefyCLVaultSnapshot(vault: BeefyCLVault, timestamp: BigInt, snapshot.currentPriceOfToken0InToken1 = ZERO_BD snapshot.priceRangeMin1 = ZERO_BD snapshot.priceRangeMax1 = ZERO_BD - snapshot.priceRangeMin1USD = ZERO_BD - snapshot.priceRangeMax1USD = ZERO_BD + snapshot.priceRangeMinUSD = ZERO_BD + snapshot.priceRangeMaxUSD = ZERO_BD snapshot.underlyingAmount0 = ZERO_BD snapshot.underlyingAmount1 = ZERO_BD snapshot.underlyingAmount0USD = ZERO_BD @@ -111,8 +111,8 @@ export function getBeefyCLVaultSnapshot(vault: BeefyCLVault, timestamp: BigInt, snapshot.currentPriceOfToken0InToken1 = previousSnapshot.currentPriceOfToken0InToken1 snapshot.priceRangeMin1 = previousSnapshot.priceRangeMin1 snapshot.priceRangeMax1 = previousSnapshot.priceRangeMax1 - snapshot.priceRangeMin1USD = previousSnapshot.priceRangeMin1USD - snapshot.priceRangeMax1USD = previousSnapshot.priceRangeMax1USD + snapshot.priceRangeMinUSD = previousSnapshot.priceRangeMinUSD + snapshot.priceRangeMaxUSD = previousSnapshot.priceRangeMaxUSD snapshot.underlyingAmount0 = previousSnapshot.underlyingAmount0 snapshot.underlyingAmount1 = previousSnapshot.underlyingAmount1 snapshot.underlyingAmount0USD = previousSnapshot.underlyingAmount0USD diff --git a/src/harvest.ts b/src/harvest.ts index 2f5affb..06ee7c8 100644 --- a/src/harvest.ts +++ b/src/harvest.ts @@ -60,8 +60,9 @@ export function handleStrategyHarvest(event: HarvestEvent): void { log.error("handleStrategyHarvest: range() reverted for strategy {}", [vault.strategy.toHexString()]) throw Error("handleStrategyHarvest: range() reverted") } - const rangeMinToken1Price = tickToPrice(BigInt.fromI32(rangeRes.value.value0), token0, token1) - const rangeMaxToken1Price = tickToPrice(BigInt.fromI32(rangeRes.value.value1), token0, token1) + // this is purposely inverted as we want prices in token1 + const rangeMinToken1Price = tickToPrice(BigInt.fromI32(rangeRes.value.value1), token0, token1) + const rangeMaxToken1Price = tickToPrice(BigInt.fromI32(rangeRes.value.value0), token0, token1) // balances of the vault const vaultBalancesRes = vaultContract.try_balances() @@ -117,8 +118,8 @@ export function handleStrategyHarvest(event: HarvestEvent): void { vault.currentPriceOfToken0InToken1 = currentPriceInToken1 vault.priceRangeMin1 = rangeMinToken1Price vault.priceRangeMax1 = rangeMaxToken1Price - vault.priceRangeMin1USD = vault.priceRangeMin1.times(token1PriceInUSD) - vault.priceRangeMax1USD = vault.priceRangeMax1.times(token1PriceInUSD) + vault.priceRangeMinUSD = vault.priceRangeMin1.times(token1PriceInUSD) + vault.priceRangeMaxUSD = vault.priceRangeMax1.times(token1PriceInUSD) vault.underlyingAmount0 = vaultBalanceUnderlying0 vault.underlyingAmount1 = vaultBalanceUnderlying1 vault.underlyingAmount0USD = vault.underlyingAmount0.times(token0PriceInUSD) @@ -140,8 +141,8 @@ export function handleStrategyHarvest(event: HarvestEvent): void { vaultSnapshot.currentPriceOfToken0InToken1 = vault.currentPriceOfToken0InToken1 vaultSnapshot.priceRangeMin1 = vault.priceRangeMax1 vaultSnapshot.priceRangeMax1 = vault.priceRangeMax1 - vaultSnapshot.priceRangeMin1USD = vault.priceRangeMax1USD - vaultSnapshot.priceRangeMax1USD = vault.priceRangeMax1USD + vaultSnapshot.priceRangeMinUSD = vault.priceRangeMaxUSD + vaultSnapshot.priceRangeMaxUSD = vault.priceRangeMaxUSD vaultSnapshot.underlyingAmount0 = vault.underlyingAmount0 vaultSnapshot.underlyingAmount1 = vault.underlyingAmount1 vaultSnapshot.underlyingAmount0USD = vault.underlyingAmount0USD diff --git a/src/mapping/clock.ts b/src/mapping/clock.ts index 4169b43..1c2bd74 100644 --- a/src/mapping/clock.ts +++ b/src/mapping/clock.ts @@ -112,8 +112,8 @@ export function handleNew15Minutes(tick: ClockTick): void { // update latest vault usd values log.debug("handleNew15Minutes: updating vault usd values for vault {}", [vault.id.toHexString()]) vault.currentPriceOfToken0InToken1 = currentPriceInToken1 - vault.priceRangeMin1USD = vault.priceRangeMin1.times(token1PriceInUSD) - vault.priceRangeMax1USD = vault.priceRangeMax1.times(token1PriceInUSD) + vault.priceRangeMinUSD = vault.priceRangeMin1.times(token1PriceInUSD) + vault.priceRangeMaxUSD = vault.priceRangeMax1.times(token1PriceInUSD) vault.underlyingAmount0 = vaultBalanceUnderlying0 vault.underlyingAmount1 = vaultBalanceUnderlying1 vault.underlyingAmount0USD = vault.underlyingAmount0.times(token0PriceInUSD) @@ -247,8 +247,8 @@ export function handleNewDay(tick: ClockTick): void { // update vault usd values log.debug("handleNewDay: updating vault usd values for vault {}", [vault.id.toHexString()]) vault.currentPriceOfToken0InToken1 = currentPriceInToken1 - vault.priceRangeMin1USD = vault.priceRangeMin1.times(token1PriceInUSD) - vault.priceRangeMax1USD = vault.priceRangeMax1.times(token1PriceInUSD) + vault.priceRangeMinUSD = vault.priceRangeMin1.times(token1PriceInUSD) + vault.priceRangeMaxUSD = vault.priceRangeMax1.times(token1PriceInUSD) vault.underlyingAmount0 = vaultBalanceUnderlying0 vault.underlyingAmount1 = vaultBalanceUnderlying1 vault.underlyingAmount0USD = vault.underlyingAmount0.times(token0PriceInUSD) @@ -263,8 +263,8 @@ export function handleNewDay(tick: ClockTick): void { ]) const vaultSnapshot = getBeefyCLVaultSnapshot(vault, tick.timestamp, period) vaultSnapshot.currentPriceOfToken0InToken1 = vault.currentPriceOfToken0InToken1 - vaultSnapshot.priceRangeMin1USD = vault.priceRangeMax1USD - vaultSnapshot.priceRangeMax1USD = vault.priceRangeMax1USD + vaultSnapshot.priceRangeMinUSD = vault.priceRangeMinUSD + vaultSnapshot.priceRangeMaxUSD = vault.priceRangeMaxUSD vaultSnapshot.underlyingAmount0 = vault.underlyingAmount0 vaultSnapshot.underlyingAmount1 = vault.underlyingAmount1 vaultSnapshot.underlyingAmount0USD = vault.underlyingAmount0USD diff --git a/src/vault-transfer.ts b/src/vault-transfer.ts index 4003d19..8a9dbad 100644 --- a/src/vault-transfer.ts +++ b/src/vault-transfer.ts @@ -84,8 +84,9 @@ function updateUserPosition(event: ethereum.Event, investorAddress: Address, isD log.error("updateUserPosition: range() reverted for strategy {}", [vault.strategy.toHexString()]) throw Error("updateUserPosition: range() reverted") } - const rangeMinToken1Price = tickToPrice(BigInt.fromI32(rangeRes.value.value0), token0, token1) - const rangeMaxToken1Price = tickToPrice(BigInt.fromI32(rangeRes.value.value1), token0, token1) + // this is purposely inverted as we want prices in token1 + const rangeMinToken1Price = tickToPrice(BigInt.fromI32(rangeRes.value.value1), token0, token1) + const rangeMaxToken1Price = tickToPrice(BigInt.fromI32(rangeRes.value.value0), token0, token1) // balances of the vault const vaultBalancesRes = vaultContract.try_balances() @@ -214,8 +215,8 @@ function updateUserPosition(event: ethereum.Event, investorAddress: Address, isD vault.currentPriceOfToken0InToken1 = currentPriceInToken1 vault.priceRangeMin1 = rangeMinToken1Price vault.priceRangeMax1 = rangeMaxToken1Price - vault.priceRangeMin1USD = vault.priceRangeMin1.times(token1PriceInUSD) - vault.priceRangeMax1USD = vault.priceRangeMax1.times(token1PriceInUSD) + vault.priceRangeMinUSD = vault.priceRangeMin1.times(token1PriceInUSD) + vault.priceRangeMaxUSD = vault.priceRangeMax1.times(token1PriceInUSD) vault.underlyingAmount0 = vaultBalanceUnderlying0 vault.underlyingAmount1 = vaultBalanceUnderlying1 vault.underlyingAmount0USD = vault.underlyingAmount0.times(token0PriceInUSD) @@ -236,8 +237,8 @@ function updateUserPosition(event: ethereum.Event, investorAddress: Address, isD vaultSnapshot.currentPriceOfToken0InToken1 = vault.currentPriceOfToken0InToken1 vaultSnapshot.priceRangeMin1 = vault.priceRangeMax1 vaultSnapshot.priceRangeMax1 = vault.priceRangeMax1 - vaultSnapshot.priceRangeMin1USD = vault.priceRangeMax1USD - vaultSnapshot.priceRangeMax1USD = vault.priceRangeMax1USD + vaultSnapshot.priceRangeMinUSD = vault.priceRangeMaxUSD + vaultSnapshot.priceRangeMaxUSD = vault.priceRangeMaxUSD vaultSnapshot.underlyingAmount0 = vault.underlyingAmount0 vaultSnapshot.underlyingAmount1 = vault.underlyingAmount1 vaultSnapshot.underlyingAmount0USD = vault.underlyingAmount0USD