From 039a6b5584f743570cecb5c1b85783e377e9e806 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Pr=C3=A9vost?= <998369+prevostc@users.noreply.github.com> Date: Sat, 23 Mar 2024 01:34:29 +0100 Subject: [PATCH] Add vault current price in usd --- README.md | 3 +++ schema.graphql | 9 +++++++++ src/entity/vault.ts | 3 +++ src/harvest.ts | 2 ++ src/mapping/clock.ts | 3 +++ src/vault-transfer.ts | 2 ++ 6 files changed, 22 insertions(+) diff --git a/README.md b/README.md index 2e7db2e..b6927e8 100644 --- a/README.md +++ b/README.md @@ -108,3 +108,6 @@ yarn test:lint # run prettier linter - feat: add APR - feat: add P&L - feat: handle boosts +- feat: handle zap? +- feat: fetch vault fees %? +- diff --git a/schema.graphql b/schema.graphql index b192c51..9662dd2 100644 --- a/schema.graphql +++ b/schema.graphql @@ -252,6 +252,10 @@ type BeefyCLVault @entity { For example, if the vault is a BTC/ETH vault, this is the price of 1 BTC in ETH """ currentPriceOfToken0InToken1: BigDecimal! + """ + Current price of the token zero in USD + """ + currentPriceOfToken0InUSD: BigDecimal! "Price range start this vault is currently configured to operate in, in token 1" priceRangeMin1: BigDecimal! @@ -352,6 +356,11 @@ type BeefyCLVaultSnapshot implements Snapshot @entity { """ currentPriceOfToken0InToken1: BigDecimal! + """ + Current price of the token zero in USD + """ + currentPriceOfToken0InUSD: BigDecimal! + "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, in token 1" diff --git a/src/entity/vault.ts b/src/entity/vault.ts index 6d95e80..8307a1e 100644 --- a/src/entity/vault.ts +++ b/src/entity/vault.ts @@ -28,6 +28,7 @@ export function getBeefyCLVault(vaultAddress: Bytes): BeefyCLVault { vault.underlyingToken0 = ADDRESS_ZERO vault.underlyingToken1 = ADDRESS_ZERO vault.currentPriceOfToken0InToken1 = ZERO_BD + vault.currentPriceOfToken0InUSD = ZERO_BD vault.priceRangeMin1 = ZERO_BD vault.priceRangeMax1 = ZERO_BD vault.priceRangeMinUSD = ZERO_BD @@ -78,6 +79,7 @@ export function getBeefyCLVaultSnapshot(vault: BeefyCLVault, timestamp: BigInt, snapshot.roundedTimestamp = interval snapshot.period = period snapshot.currentPriceOfToken0InToken1 = ZERO_BD + snapshot.currentPriceOfToken0InUSD = ZERO_BD snapshot.priceRangeMin1 = ZERO_BD snapshot.priceRangeMax1 = ZERO_BD snapshot.priceRangeMinUSD = ZERO_BD @@ -109,6 +111,7 @@ export function getBeefyCLVaultSnapshot(vault: BeefyCLVault, timestamp: BigInt, const previousSnapshot = BeefyCLVaultSnapshot.load(previousSnapshotId) if (previousSnapshot) { snapshot.currentPriceOfToken0InToken1 = previousSnapshot.currentPriceOfToken0InToken1 + snapshot.currentPriceOfToken0InUSD = previousSnapshot.currentPriceOfToken0InUSD snapshot.priceRangeMin1 = previousSnapshot.priceRangeMin1 snapshot.priceRangeMax1 = previousSnapshot.priceRangeMax1 snapshot.priceRangeMinUSD = previousSnapshot.priceRangeMinUSD diff --git a/src/harvest.ts b/src/harvest.ts index bbeaaf5..4a98574 100644 --- a/src/harvest.ts +++ b/src/harvest.ts @@ -107,6 +107,7 @@ export function handleStrategyHarvest(event: HarvestEvent): void { /////// // update vault entities vault.currentPriceOfToken0InToken1 = currentPriceInToken1 + vault.currentPriceOfToken0InUSD = currentPriceInToken1.times(token1PriceInUSD) vault.priceRangeMin1 = rangeToken1Price.min vault.priceRangeMax1 = rangeToken1Price.max vault.priceRangeMinUSD = vault.priceRangeMin1.times(token1PriceInUSD) @@ -130,6 +131,7 @@ export function handleStrategyHarvest(event: HarvestEvent): void { ]) const vaultSnapshot = getBeefyCLVaultSnapshot(vault, event.block.timestamp, periods[i]) vaultSnapshot.currentPriceOfToken0InToken1 = vault.currentPriceOfToken0InToken1 + vaultSnapshot.currentPriceOfToken0InUSD = vault.currentPriceOfToken0InUSD vaultSnapshot.priceRangeMin1 = vault.priceRangeMin1 vaultSnapshot.priceRangeMax1 = vault.priceRangeMax1 vaultSnapshot.priceRangeMinUSD = vault.priceRangeMinUSD diff --git a/src/mapping/clock.ts b/src/mapping/clock.ts index e726ddc..3465bd1 100644 --- a/src/mapping/clock.ts +++ b/src/mapping/clock.ts @@ -110,6 +110,7 @@ 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.currentPriceOfToken0InUSD = token0PriceInUSD vault.priceRangeMinUSD = vault.priceRangeMin1.times(token1PriceInUSD) vault.priceRangeMaxUSD = vault.priceRangeMax1.times(token1PriceInUSD) vault.underlyingAmount0 = vaultBalanceUnderlying0 @@ -245,6 +246,7 @@ 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.currentPriceOfToken0InUSD = token0PriceInUSD vault.priceRangeMinUSD = vault.priceRangeMin1.times(token1PriceInUSD) vault.priceRangeMaxUSD = vault.priceRangeMax1.times(token1PriceInUSD) vault.underlyingAmount0 = vaultBalanceUnderlying0 @@ -261,6 +263,7 @@ export function handleNewDay(tick: ClockTick): void { ]) const vaultSnapshot = getBeefyCLVaultSnapshot(vault, tick.timestamp, period) vaultSnapshot.currentPriceOfToken0InToken1 = vault.currentPriceOfToken0InToken1 + vaultSnapshot.currentPriceOfToken0InUSD = vault.currentPriceOfToken0InUSD vaultSnapshot.priceRangeMinUSD = vault.priceRangeMinUSD vaultSnapshot.priceRangeMaxUSD = vault.priceRangeMaxUSD vaultSnapshot.underlyingAmount0 = vault.underlyingAmount0 diff --git a/src/vault-transfer.ts b/src/vault-transfer.ts index 5987be2..61f3f93 100644 --- a/src/vault-transfer.ts +++ b/src/vault-transfer.ts @@ -197,6 +197,7 @@ function updateUserPosition( // update vault entities log.debug("updateUserPosition: updating vault entities for vault {}", [vault.id.toHexString()]) vault.currentPriceOfToken0InToken1 = currentPriceInToken1 + vault.currentPriceOfToken0InUSD = currentPriceInToken1.times(token1PriceInUSD) vault.priceRangeMin1 = rangeToken1Price.min vault.priceRangeMax1 = rangeToken1Price.max vault.priceRangeMinUSD = vault.priceRangeMin1.times(token1PriceInUSD) @@ -216,6 +217,7 @@ function updateUserPosition( ]) const vaultSnapshot = getBeefyCLVaultSnapshot(vault, event.block.timestamp, periods[i]) vaultSnapshot.currentPriceOfToken0InToken1 = vault.currentPriceOfToken0InToken1 + vaultSnapshot.currentPriceOfToken0InUSD = vault.currentPriceOfToken0InUSD vaultSnapshot.priceRangeMin1 = vault.priceRangeMin1 vaultSnapshot.priceRangeMax1 = vault.priceRangeMax1 vaultSnapshot.priceRangeMinUSD = vault.priceRangeMinUSD