From d6e9cf53507b4d76f769fe6b651330c4e055bd3e Mon Sep 17 00:00:00 2001 From: aalavandhann <6264334+aalavandhan@users.noreply.github.com> Date: Tue, 5 Nov 2024 21:23:27 -0500 Subject: [PATCH] updated spot subgraph to keep track of vault swap volume --- spot-subgraph/schema.graphql | 6 ++++++ spot-subgraph/src/data/rolloverVault.ts | 8 +++++--- spot-subgraph/src/mappings/rolloverVault.ts | 6 ++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/spot-subgraph/schema.graphql b/spot-subgraph/schema.graphql index 624b640d..c37a2229 100644 --- a/spot-subgraph/schema.graphql +++ b/spot-subgraph/schema.graphql @@ -355,4 +355,10 @@ type RolloverVaultDailyStat @entity { " the total value of swaps on the given day " totalSwapValue: BigDecimal! + + " the total value of underlying to perp swaps on the given day " + totalUnderlyingToPerpSwapValue: BigDecimal! + + " the total value of perp to underlying swaps on the given day " + totalPerpToUnderlyingSwapValue: BigDecimal! } \ No newline at end of file diff --git a/spot-subgraph/src/data/rolloverVault.ts b/spot-subgraph/src/data/rolloverVault.ts index 77f7919c..47575d5e 100644 --- a/spot-subgraph/src/data/rolloverVault.ts +++ b/spot-subgraph/src/data/rolloverVault.ts @@ -4,7 +4,7 @@ import { RolloverVaultAsset, ScaledUnderlyingVaultDepositorBalance, RolloverVaultDailyStat, - Tranche + Tranche, } from '../../generated/schema' import { RolloverVault as RolloverVaultABI } from '../../generated/RolloverVault/RolloverVault' import { ERC20 as ERC20ABI } from '../../generated/BondFactory/ERC20' @@ -144,10 +144,10 @@ export function refreshRolloverVaultRebaseMultiplier(vault: RolloverVault): void .plus(vaultPerpBalance) .plus(vaultZBalance) .plus(vaultUnderlyingBalance) - if(denominator.gt(BIGDECIMAL_ZERO)){ + if (denominator.gt(BIGDECIMAL_ZERO)) { vault.rebaseMultiplier = numerator.div(denominator) } - vault.save() + vault.save() } export function refreshRolloverVaultDailyStat(dailyStat: RolloverVaultDailyStat): void { @@ -246,6 +246,8 @@ export function fetchRolloverVaultDailyStat( dailyStat.price = BIGDECIMAL_ZERO dailyStat.totalSupply = BIGDECIMAL_ZERO dailyStat.totalSwapValue = BIGDECIMAL_ZERO + dailyStat.totalUnderlyingToPerpSwapValue = BIGDECIMAL_ZERO + dailyStat.totalPerpToUnderlyingSwapValue = BIGDECIMAL_ZERO } return dailyStat as RolloverVaultDailyStat } diff --git a/spot-subgraph/src/mappings/rolloverVault.ts b/spot-subgraph/src/mappings/rolloverVault.ts index d29317c7..0aad7c70 100644 --- a/spot-subgraph/src/mappings/rolloverVault.ts +++ b/spot-subgraph/src/mappings/rolloverVault.ts @@ -135,6 +135,9 @@ export function handleUnderlyingToPerpSwap(call: SwapUnderlyingForPerpsCall): vo let dailyStat = fetchRolloverVaultDailyStat(vault, dayTimestamp(call.block.timestamp)) dailyStat.totalSwapValue = dailyStat.totalSwapValue.plus(underlyingAmtIn) + dailyStat.totalUnderlyingToPerpSwapValue = dailyStat.totalUnderlyingToPerpSwapValue.plus( + underlyingAmtIn, + ) dailyStat.save() } @@ -153,5 +156,8 @@ export function handlePerpToUnderlyingSwap(call: SwapPerpsForUnderlyingCall): vo let dailyStat = fetchRolloverVaultDailyStat(vault, dayTimestamp(call.block.timestamp)) dailyStat.totalSwapValue = dailyStat.totalSwapValue.plus(perpAmtIn.times(perp.price)) + dailyStat.totalPerpToUnderlyingSwapValue = dailyStat.totalPerpToUnderlyingSwapValue.plus( + perpAmtIn.times(perp.price), + ) dailyStat.save() }