From 14f1e25ba78688c06d989bcababb24065e0cffbd Mon Sep 17 00:00:00 2001 From: prevostc <998369+prevostc@users.noreply.github.com> Date: Tue, 4 Feb 2025 19:17:20 +0100 Subject: [PATCH] Index TVL events --- schema.graphql | 24 ++++++++++++++++++++++++ src/clm/mapping/strategy.ts | 1 + src/clm/operations.ts | 31 +++++++++++++++++++++++++++++++ subgraph.template.yaml | 2 ++ 4 files changed, 58 insertions(+) create mode 100644 src/clm/operations.ts diff --git a/schema.graphql b/schema.graphql index f60e696..6d753ee 100644 --- a/schema.graphql +++ b/schema.graphql @@ -728,6 +728,30 @@ type ClmHarvestEvent @entity(immutable: true) { nativeToUSDPrice: BigInt! } +""" +This event is emitted when the strategy's TVL is updated. +""" +type ClmStrategyTVLEvent @entity(immutable: true) { + "transaction hash + log index" + id: Bytes! + + "The CLM the TVL event is for" + clm: CLM! + "The strategy that the TVL event is for" + strategy: ClmStrategy! + "The transaction that created the TVL event" + createdWith: Transaction! + "The event log index in the transaction that created the TVL event." + logIndex: BigInt! + "The timestamp of the TVL event so you can sort by time" + timestamp: BigInt! + + "Underlying balance of the first token after the TVL event" + underlyingAmount0: BigInt! + "Underlying balance of the second token after the TVL event" + underlyingAmount1: BigInt! +} + """ This event is emitted when we collect earned trading fees from the underlying pool. """ diff --git a/src/clm/mapping/strategy.ts b/src/clm/mapping/strategy.ts index 4568665..3fdd4e5 100644 --- a/src/clm/mapping/strategy.ts +++ b/src/clm/mapping/strategy.ts @@ -5,3 +5,4 @@ export { handleClmStrategyHarvestAmounts } from "../compound" export { handleClmStrategyHarvestRewards } from "../compound" export { handleClmStrategyClaimedFees } from "../compound" export { handleClmStrategyClaimedRewards } from "../compound" +export { handleClmStrategyTVL } from "../operations" diff --git a/src/clm/operations.ts b/src/clm/operations.ts new file mode 100644 index 0000000..1300085 --- /dev/null +++ b/src/clm/operations.ts @@ -0,0 +1,31 @@ +import { BigInt, ethereum } from "@graphprotocol/graph-ts" +import { + TVL as CLMStrategyTVLEvent, +} from "../../generated/templates/ClmStrategy/ClmStrategy" +import { getClmStrategy, getCLM } from "./entity/clm" +import { getTransaction } from "../common/entity/transaction" +import { ClmStrategyTVLEvent } from "../../generated/schema" +import { getEventIdentifier } from "../common/utils/event" + +export function handleClmStrategyTVL(event: CLMStrategyTVLEvent): void { + + const strategy = getClmStrategy(event.address) + const clm = getCLM(strategy.clm) + + const underlyingAmount0 = event.params.bal0 + const underlyingAmount1 = event.params.bal1 + + let tx = getTransaction(event.block, event.transaction) + tx.save() + + const clmStrategyTVLEvent = new ClmStrategyTVLEvent(getEventIdentifier(event)) + clmStrategyTVLEvent.clm = clm.id + clmStrategyTVLEvent.strategy = strategy.id + clmStrategyTVLEvent.createdWith = tx.id + clmStrategyTVLEvent.logIndex = event.logIndex + clmStrategyTVLEvent.timestamp = event.block.timestamp + clmStrategyTVLEvent.underlyingAmount0 = underlyingAmount0 + clmStrategyTVLEvent.underlyingAmount1 = underlyingAmount1 + + clmStrategyTVLEvent.save() +} diff --git a/subgraph.template.yaml b/subgraph.template.yaml index 6e8dff8..4f5d112 100644 --- a/subgraph.template.yaml +++ b/subgraph.template.yaml @@ -238,6 +238,8 @@ templates: handler: handleClmStrategyClaimedFees - event: ClaimedRewards(uint256) handler: handleClmStrategyClaimedRewards + - event: TVL(uint256,uint256) + handler: handleClmStrategyTVL - name: RewardPool kind: ethereum/contract