Skip to content

Commit

Permalink
updated spot subgraph to keep track of vault swap volume
Browse files Browse the repository at this point in the history
  • Loading branch information
aalavandhan committed Nov 6, 2024
1 parent a8ae0ae commit d6e9cf5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
6 changes: 6 additions & 0 deletions spot-subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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!
}
8 changes: 5 additions & 3 deletions spot-subgraph/src/data/rolloverVault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
6 changes: 6 additions & 0 deletions spot-subgraph/src/mappings/rolloverVault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand All @@ -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()
}

0 comments on commit d6e9cf5

Please sign in to comment.