Skip to content

Commit 72e64d0

Browse files
committed
cleaned up spot subgraph
1 parent 77b26a7 commit 72e64d0

File tree

8 files changed

+77
-180
lines changed

8 files changed

+77
-180
lines changed

spot-subgraph/schema.graphql

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -232,18 +232,6 @@ type PerpetualTrancheDailyStat @entity {
232232
" the timestamp of the given day "
233233
timestamp: BigInt!
234234

235-
" the total perp tokens minted on the given day "
236-
totalMints: BigDecimal!
237-
238-
" the total perp tokens redeemed on the given day "
239-
totalRedemptions: BigDecimal!
240-
241-
" the total value of perp tokens minted on the given day "
242-
totalMintValue: BigDecimal!
243-
244-
" the total value of perp tokens redeemed on the given day "
245-
totalRedemptionValue: BigDecimal!
246-
247235
" the tvl on the given day "
248236
tvl: BigDecimal!
249237

@@ -253,9 +241,6 @@ type PerpetualTrancheDailyStat @entity {
253241
" the perp token supply on the given day "
254242
totalSupply: BigDecimal!
255243

256-
" the total amount of perp tokens paid as fees "
257-
totalPerpFeeAmt: BigDecimal!
258-
259244
" the total underlying value of fees "
260245
totalUnderlyingFeeValue: BigDecimal!
261246
}
@@ -279,12 +264,6 @@ type RolloverVault @entity {
279264
" addresses of assets currently in the reserve "
280265
activeReserves: [RolloverVaultAsset!]!
281266

282-
" the total fixed mc share of underlying tokens deposited into the system "
283-
totalScaledUnderlyingDeposited: BigDecimal!
284-
285-
" the total fixed mc share of underlying tokens deposited by each user "
286-
scaledUnderlyingBalances: [ScaledUnderlyingVaultDepositorBalance!]! @derivedFrom(field: "vault")
287-
288267
" the current tvl based on the active reserves "
289268
tvl: BigDecimal!
290269

@@ -304,13 +283,6 @@ type RolloverVault @entity {
304283
dailyStats: [RolloverVaultDailyStat!]! @derivedFrom(field: "vault")
305284
}
306285

307-
type ScaledUnderlyingVaultDepositorBalance @entity {
308-
id: ID!
309-
vault: RolloverVault!
310-
account: Bytes!
311-
value: BigDecimal!
312-
}
313-
314286
type RolloverVaultAsset @entity {
315287
" Equals to: <vaultTokenAddress>-<assetTokenAddress>"
316288
id: ID!
@@ -341,18 +313,6 @@ type RolloverVaultDailyStat @entity {
341313
" the timestamp of the given day "
342314
timestamp: BigInt!
343315

344-
" the total vault notes minted on the given day "
345-
totalMints: BigDecimal!
346-
347-
" the total vault notes redeemed on the given day "
348-
totalRedemptions: BigDecimal!
349-
350-
" the total value of vault notes minted on the given day "
351-
totalMintValue: BigDecimal!
352-
353-
" the total value of vault notes redeemed on the given day "
354-
totalRedemptionValue: BigDecimal!
355-
356316
" the tvl on the given day "
357317
tvl: BigDecimal!
358318

@@ -365,15 +325,6 @@ type RolloverVaultDailyStat @entity {
365325
" the vault note supply on the given day "
366326
totalSupply: BigDecimal!
367327

368-
" the total value of swaps on the given day "
369-
totalSwapValue: BigDecimal!
370-
371-
" the total value of underlying to perp swaps on the given day "
372-
totalUnderlyingToPerpSwapValue: BigDecimal!
373-
374-
" the total value of perp to underlying swaps on the given day "
375-
totalPerpToUnderlyingSwapValue: BigDecimal!
376-
377328
" the system deviation ratio "
378329
deviationRatio: BigDecimal!
379330

spot-subgraph/scripts/deploy.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ yarn codegen
77

88
yarn build
99

10+
echo "NOTE: graph deploy to Alchemy fails when you redeploy with the same IPFS hash"
11+
12+
# yarn graph auth $THE_GRAPH_API_KEY
13+
# yarn graph deploy $2
1014
yarn graph deploy $2 \
1115
--node https://subgraphs.alchemy.com/api/subgraphs/deploy \
12-
--deploy-key $GRAPH_AUTH
16+
--deploy-key $GRAPH_AUTH
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
# generate-ipfs-cid.sh
4+
# Computes IPFS CID of a given directory using IPFS in Docker without uploading
5+
6+
set -e
7+
8+
TARGET_PATH=${1:-build}
9+
10+
if [ ! -d "$TARGET_PATH" ]; then
11+
echo "❌ Error: Directory '$TARGET_PATH' does not exist."
12+
echo "Usage: $0 [path-to-directory]"
13+
exit 1
14+
fi
15+
16+
echo "📦 Computing IPFS CID for '$TARGET_PATH'..."
17+
18+
CID=$(docker run --rm \
19+
-v "$(pwd):/data" \
20+
-e IPFS_PATH=/tmp/ipfs \
21+
--entrypoint sh \
22+
ipfs/kubo \
23+
-c "ipfs init >/dev/null && ipfs add -r --only-hash --quiet /data/$TARGET_PATH" | tail -n 1)
24+
25+
if [ -z "$CID" ]; then
26+
echo "❌ Failed to generate IPFS CID."
27+
exit 1
28+
fi
29+
30+
echo "✅ IPFS CID: $CID"

spot-subgraph/src/data/perpetualTranche.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,9 @@ export function fetchPerpetualTrancheDailyStat(
172172
dailyStat = new PerpetualTrancheDailyStat(id)
173173
dailyStat.perp = perp.id
174174
dailyStat.timestamp = timestamp
175-
dailyStat.totalMints = BIGDECIMAL_ZERO
176-
dailyStat.totalRedemptions = BIGDECIMAL_ZERO
177-
dailyStat.totalMintValue = BIGDECIMAL_ZERO
178-
dailyStat.totalRedemptionValue = BIGDECIMAL_ZERO
179175
dailyStat.tvl = BIGDECIMAL_ZERO
180176
dailyStat.price = BIGDECIMAL_ZERO
181177
dailyStat.totalSupply = BIGDECIMAL_ZERO
182-
dailyStat.totalPerpFeeAmt = BIGDECIMAL_ZERO
183178
dailyStat.totalUnderlyingFeeValue = BIGDECIMAL_ZERO
184179
}
185180
return dailyStat as PerpetualTrancheDailyStat

spot-subgraph/src/data/rolloverVault.ts

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { log, BigDecimal, BigInt, Address, DataSourceContext } from '@graphproto
22
import {
33
RolloverVault,
44
RolloverVaultAsset,
5-
ScaledUnderlyingVaultDepositorBalance,
65
RolloverVaultDailyStat,
76
Tranche,
87
} from '../../generated/schema'
@@ -173,7 +172,6 @@ export function fetchRolloverVault(address: Address): RolloverVault {
173172
vaultToken.save()
174173
vault = new RolloverVault(id)
175174
vault.token = vaultToken.id
176-
vault.totalScaledUnderlyingDeposited = BIGDECIMAL_ZERO
177175
vault.activeReserves = []
178176
vault.tvl = BIGDECIMAL_ZERO
179177
vault.rebaseMultiplier = BIGDECIMAL_ONE
@@ -219,21 +217,6 @@ export function fetchRolloverVaultAsset(
219217
return assetToken as RolloverVaultAsset
220218
}
221219

222-
export function fetchScaledUnderlyingVaultDepositorBalance(
223-
vault: RolloverVault,
224-
account: Address,
225-
): ScaledUnderlyingVaultDepositorBalance {
226-
let id = vault.id.concat('-').concat(account.toHexString())
227-
let balance = ScaledUnderlyingVaultDepositorBalance.load(id)
228-
if (balance == null) {
229-
balance = new ScaledUnderlyingVaultDepositorBalance(id)
230-
balance.vault = vault.id
231-
balance.account = account
232-
balance.value = BIGDECIMAL_ZERO
233-
}
234-
return balance as ScaledUnderlyingVaultDepositorBalance
235-
}
236-
237220
export function fetchRolloverVaultDailyStat(
238221
vault: RolloverVault,
239222
timestamp: BigInt,
@@ -244,17 +227,10 @@ export function fetchRolloverVaultDailyStat(
244227
dailyStat = new RolloverVaultDailyStat(id)
245228
dailyStat.vault = vault.id
246229
dailyStat.timestamp = timestamp
247-
dailyStat.totalMints = BIGDECIMAL_ZERO
248-
dailyStat.totalRedemptions = BIGDECIMAL_ZERO
249-
dailyStat.totalMintValue = BIGDECIMAL_ZERO
250-
dailyStat.totalRedemptionValue = BIGDECIMAL_ZERO
251230
dailyStat.tvl = BIGDECIMAL_ZERO
252231
dailyStat.rebaseMultiplier = BIGDECIMAL_ONE
253232
dailyStat.price = BIGDECIMAL_ZERO
254233
dailyStat.totalSupply = BIGDECIMAL_ZERO
255-
dailyStat.totalSwapValue = BIGDECIMAL_ZERO
256-
dailyStat.totalUnderlyingToPerpSwapValue = BIGDECIMAL_ZERO
257-
dailyStat.totalPerpToUnderlyingSwapValue = BIGDECIMAL_ZERO
258234
dailyStat.deviationRatio = BIGDECIMAL_ZERO
259235
dailyStat.totalUnderlyingFeeValue = BIGDECIMAL_ZERO
260236
}
@@ -276,13 +252,13 @@ function fetchTargetSystemRatio(vaultAddress: Address): BigDecimal {
276252
let vaultContract = RolloverVaultABI.bind(vaultAddress)
277253
let r1 = vaultContract.try_feePolicy()
278254
if (r1.reverted) {
279-
log.debug('fee policy not set', [])
255+
log.error('fee policy not set', [])
280256
return SYSTEM_RATIO_START
281257
}
282258
let feePolicyContract = FeePolicyABI.bind(r1.value)
283259
let r2 = feePolicyContract.try_targetSystemRatio()
284260
if (r2.reverted) {
285-
log.debug('fee policy version incorrect', [])
261+
log.error('fee policy version incorrect', [])
286262
return SYSTEM_RATIO_START
287263
}
288264
return formatBalance(r2.value, BigInt.fromI32(feePolicyContract.decimals()))
@@ -307,7 +283,7 @@ export function computeFeePerc(
307283
let vaultContract = RolloverVaultABI.bind(vaultAddress)
308284
let r1 = vaultContract.try_feePolicy()
309285
if (r1.reverted) {
310-
log.debug('fee policy not set', [])
286+
log.error('fee policy not set', [])
311287
return BIGDECIMAL_ZERO
312288
}
313289
let feePolicyContract = FeePolicyABI.bind(r1.value)
@@ -322,7 +298,7 @@ export function computeFeePerc(
322298
)
323299
let r2 = feePolicyContract.try_computeFeePerc(drPre, drPost)
324300
if (r2.reverted) {
325-
log.debug('fee policy version incorrect', [])
301+
log.error('fee policy version incorrect', [])
326302
return BIGDECIMAL_ZERO
327303
}
328304
return formatBalance(r2.value, feePolicyDecimals)

spot-subgraph/src/mappings/perpetualTranche.ts

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -63,44 +63,28 @@ export function handleTransfer(event: Transfer): void {
6363
log.debug('triggered mint', [])
6464
let perpToken = fetchToken(event.address)
6565
refreshSupply(perpToken)
66-
6766
let perp = fetchPerpetualTranche(event.address)
6867
refreshPerpetualTrancheTVL(perp)
68+
}
6969

70-
let perpAmtMinted = formatBalance(event.params.value, perpToken.decimals)
71-
let dailyStat = fetchPerpetualTrancheDailyStat(perp, dayTimestamp(event.block.timestamp))
72-
dailyStat.totalMints = dailyStat.totalMints.plus(perpAmtMinted)
73-
dailyStat.totalMintValue = dailyStat.totalMintValue.plus(perpAmtMinted.times(perp.price))
74-
dailyStat.save()
70+
if (to == ADDRESS_ZERO) {
71+
log.debug('triggered burn', [])
72+
let perpToken = fetchToken(event.address)
73+
refreshSupply(perpToken)
74+
let perp = fetchPerpetualTranche(event.address)
75+
refreshPerpetualTrancheTVL(perp)
7576
}
7677

7778
// Mint and burn fees are handled by sending perp tokens to the perp contract
7879
if (to == event.address) {
80+
log.debug('perp fees paid', [])
7981
let perpToken = fetchToken(event.address)
8082
let perp = fetchPerpetualTranche(event.address)
8183
let perpFeeAmt = formatBalance(event.params.value, perpToken.decimals)
8284
let dailyStat = fetchPerpetualTrancheDailyStat(perp, dayTimestamp(event.block.timestamp))
83-
dailyStat.totalPerpFeeAmt = dailyStat.totalPerpFeeAmt.plus(perpFeeAmt)
8485
dailyStat.totalUnderlyingFeeValue = dailyStat.totalUnderlyingFeeValue.plus(
8586
perpFeeAmt.times(perp.price),
8687
)
8788
dailyStat.save()
8889
}
8990
}
90-
91-
export function handleRedeem(call: RedeemCall): void {
92-
log.debug('triggered redeem', [])
93-
let perpToken = fetchToken(call.to)
94-
refreshSupply(perpToken)
95-
96-
let perp = fetchPerpetualTranche(call.to)
97-
refreshPerpetualTrancheTVL(perp)
98-
99-
let perpAmtBurnt = formatBalance(call.inputs.perpAmtBurnt, perpToken.decimals)
100-
let dailyStat = fetchPerpetualTrancheDailyStat(perp, dayTimestamp(call.block.timestamp))
101-
dailyStat.totalRedemptions = dailyStat.totalRedemptions.plus(perpAmtBurnt)
102-
dailyStat.totalRedemptionValue = dailyStat.totalRedemptionValue.plus(
103-
perpAmtBurnt.times(perp.price),
104-
)
105-
dailyStat.save()
106-
}

0 commit comments

Comments
 (0)