Skip to content

Commit

Permalink
Index TVL events
Browse files Browse the repository at this point in the history
  • Loading branch information
prevostc committed Feb 4, 2025
1 parent 2a966b9 commit 14f1e25
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
24 changes: 24 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down
1 change: 1 addition & 0 deletions src/clm/mapping/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export { handleClmStrategyHarvestAmounts } from "../compound"
export { handleClmStrategyHarvestRewards } from "../compound"
export { handleClmStrategyClaimedFees } from "../compound"
export { handleClmStrategyClaimedRewards } from "../compound"
export { handleClmStrategyTVL } from "../operations"
31 changes: 31 additions & 0 deletions src/clm/operations.ts
Original file line number Diff line number Diff line change
@@ -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()
}
2 changes: 2 additions & 0 deletions subgraph.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ templates:
handler: handleClmStrategyClaimedFees
- event: ClaimedRewards(uint256)
handler: handleClmStrategyClaimedRewards
- event: TVL(uint256,uint256)
handler: handleClmStrategyTVL

- name: RewardPool
kind: ethereum/contract
Expand Down

0 comments on commit 14f1e25

Please sign in to comment.