diff --git a/.eslintrc.js b/.eslintrc.js index 25edb32..8a9ee74 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -9,6 +9,7 @@ module.exports = { rules: { 'no-plusplus': 'off', 'eslint-comments/no-unused-disable': 'error', + 'prefer-destructuring': 'off', // not supported }, overrides: [ { diff --git a/bun.lockb b/bun.lockb index 4834cb0..3ca762b 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 22a857c..7afc4f4 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "node": ">=18" }, "dependencies": { - "@exactly/protocol": "exactly/protocol#0886922c1be4a9075dbc6d3d4de102c30645b114", + "@exactly/protocol": "exactly/protocol#0890c2e27e00054e1643608eac413f8548ce1ded", "@graphprotocol/graph-ts": "^0.35.1" }, "devDependencies": { diff --git a/schema.graphql b/schema.graphql index f422363..d16f0fd 100644 --- a/schema.graphql +++ b/schema.graphql @@ -487,3 +487,17 @@ type TimelockControllerMinDelaySet @entity { block: Int! timestamp: Int! } + +type RewardAmountNotified @entity { + id: ID! # + reward: Bytes! + amount: BigInt! + notifier: Bytes! + timestamp: Int! +} + +type StakingSharedFee @entity { + id: ID! + amount: BigInt! + lastUpdate: Int! +} diff --git a/src/StakedEXA.ts b/src/StakedEXA.ts new file mode 100644 index 0000000..cdc8723 --- /dev/null +++ b/src/StakedEXA.ts @@ -0,0 +1,34 @@ +import { BigInt, Bytes } from '@graphprotocol/graph-ts'; +import { RewardAmountNotified as RewardAmountNotifiedEvent } from '../generated/StakedEXA/StakedEXA'; +import { RewardAmountNotified, StakingSharedFee } from '../generated/schema'; +import toId from './utils/toId'; + +function loadStakingSharedFee(reward: Bytes): StakingSharedFee { + const id = reward.toHexString(); + let sharedFee = StakingSharedFee.load(id); + if (sharedFee) return sharedFee; + + sharedFee = new StakingSharedFee(id); + sharedFee.amount = BigInt.zero(); + return sharedFee; +} + +export default function handleRewardAmountNotified(event: RewardAmountNotifiedEvent): void { + const rewardAmountNotified = new RewardAmountNotified(toId(event)); + const amount = event.params.amount; + const notifier = event.params.notifier; + const reward = event.params.reward; + const timestamp = event.block.timestamp.toI32(); + rewardAmountNotified.amount = amount; + rewardAmountNotified.reward = reward; + rewardAmountNotified.notifier = notifier; + rewardAmountNotified.timestamp = timestamp; + rewardAmountNotified.save(); + + if (event.address.equals(notifier)) { + const stakingSharedFee = loadStakingSharedFee(reward); + stakingSharedFee.amount = stakingSharedFee.amount.plus(amount); + stakingSharedFee.lastUpdate = timestamp; + stakingSharedFee.save(); + } +} diff --git a/subgraph.template.yaml b/subgraph.template.yaml index dc96fcc..c857210 100644 --- a/subgraph.template.yaml +++ b/subgraph.template.yaml @@ -203,3 +203,25 @@ dataSources: handler: handleMinDelayChange file: src/TimelockController.ts {{/ TimelockController }} +{{# StakedEXA }} + - kind: ethereum/contract + name: StakedEXA + network: {{ graphNetwork }} + source: + address: '{{ address }}' + startBlock: {{ startBlock }} + abi: StakedEXA + mapping: + kind: ethereum/events + apiVersion: 0.0.7 + language: wasm/assemblyscript + entities: + - RewardAmountNotified + abis: + - name: StakedEXA + file: node_modules/@exactly/protocol/deployments/{{ network }}/stEXA.json + eventHandlers: + - event: RewardAmountNotified(indexed address,indexed address,uint256) + handler: handleRewardAmountNotified + file: src/StakedEXA.ts +{{/ StakedEXA }} diff --git a/views/protocol.js b/views/protocol.js index 747f352..0bfb3fd 100644 --- a/views/protocol.js +++ b/views/protocol.js @@ -31,6 +31,7 @@ module.exports = { return from(deployment, name); }).filter(Boolean), TimelockController: from(get('TimelockController'), 'TimelockController'), + StakedEXA: from(get('stEXA'), 'stEXA'), }; /** @typedef {{ address: string, receipt?: { blockNumber?: number }, args?: any[] }} Deployment */