-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ staking: track reward amounts and shared fees
- Loading branch information
Showing
6 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters