Skip to content

Commit

Permalink
✨ staking: track reward amounts and shared fees
Browse files Browse the repository at this point in the history
  • Loading branch information
itofarina committed Sep 11, 2024
1 parent 8a57fc8 commit 788058a
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 1 deletion.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"node": ">=18"
},
"dependencies": {
"@exactly/protocol": "exactly/protocol#0886922c1be4a9075dbc6d3d4de102c30645b114",
"@exactly/protocol": "exactly/protocol#0890c2e27e00054e1643608eac413f8548ce1ded",
"@graphprotocol/graph-ts": "^0.35.1"
},
"devDependencies": {
Expand Down
15 changes: 15 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -487,3 +487,18 @@ 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!
reward: Bytes!
amount: BigInt!
lastUpdate: Int!
}
35 changes: 35 additions & 0 deletions src/StakedEXA.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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.reward = reward;
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();
}
}
22 changes: 22 additions & 0 deletions subgraph.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
1 change: 1 addition & 0 deletions views/protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

0 comments on commit 788058a

Please sign in to comment.