Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ staking: track reward amounts and shared fees #17

Merged
merged 3 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = {
rules: {
'no-plusplus': 'off',
'eslint-comments/no-unused-disable': 'error',
'prefer-destructuring': 'off', // not supported
},
overrides: [
{
Expand Down
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
14 changes: 14 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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!
}
34 changes: 34 additions & 0 deletions src/StakedEXA.ts
Original file line number Diff line number Diff line change
@@ -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();
}
}
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 */
Loading