Skip to content

Commit

Permalink
Merge pull request #53 from maticnetwork/share-transfer
Browse files Browse the repository at this point in the history
new: share transfer event added
  • Loading branch information
nitinmittal23 authored Nov 17, 2021
2 parents 10f5aee + 118e93e commit 10fe9f6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion root/abis/EventsHub.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"validatorId","type":"uint256"},{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"DelegatorUnstakeWithId","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"rewardDecreasePerCheckpoint","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"maxRewardedCheckpoints","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"checkpointRewardDelta","type":"uint256"}],"name":"RewardParams","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"validatorId","type":"uint256"},{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tokens","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"ShareBurnedWithId","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"validatorId","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"newCommissionRate","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"oldCommissionRate","type":"uint256"}],"name":"UpdateCommissionRate","type":"event"},{"constant":false,"inputs":[{"internalType":"contract Registry","name":"_registry","type":"address"}],"name":"initialize","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"},{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"logDelegatorUnstakedWithId","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"rewardDecreasePerCheckpoint","type":"uint256"},{"internalType":"uint256","name":"maxRewardedCheckpoints","type":"uint256"},{"internalType":"uint256","name":"checkpointRewardDelta","type":"uint256"}],"name":"logRewardParams","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"},{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"tokens","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"logShareBurnedWithId","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"},{"internalType":"uint256","name":"newCommissionRate","type":"uint256"},{"internalType":"uint256","name":"oldCommissionRate","type":"uint256"}],"name":"logUpdateCommissionRate","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"registry","outputs":[{"internalType":"contract Registry","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"}]
[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"validatorId","type":"uint256"},{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"DelegatorUnstakeWithId","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"rewardDecreasePerCheckpoint","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"maxRewardedCheckpoints","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"checkpointRewardDelta","type":"uint256"}],"name":"RewardParams","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"validatorId","type":"uint256"},{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tokens","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"ShareBurnedWithId","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"validatorId","type":"uint256"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"SharesTransfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"validatorId","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"newCommissionRate","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"oldCommissionRate","type":"uint256"}],"name":"UpdateCommissionRate","type":"event"},{"constant":false,"inputs":[{"internalType":"contractRegistry","name":"_registry","type":"address"}],"name":"initialize","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"},{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"logDelegatorUnstakedWithId","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"rewardDecreasePerCheckpoint","type":"uint256"},{"internalType":"uint256","name":"maxRewardedCheckpoints","type":"uint256"},{"internalType":"uint256","name":"checkpointRewardDelta","type":"uint256"}],"name":"logRewardParams","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"},{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"tokens","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"logShareBurnedWithId","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"},{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"logSharesTransfer","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"validatorId","type":"uint256"},{"internalType":"uint256","name":"newCommissionRate","type":"uint256"},{"internalType":"uint256","name":"oldCommissionRate","type":"uint256"}],"name":"logUpdateCommissionRate","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"registry","outputs":[{"internalType":"contractRegistry","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"}]
13 changes: 13 additions & 0 deletions root/src/mappings/staking-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
DelegatorUnstakeWithId,
ShareBurnedWithId,
UpdateCommissionRate,
SharesTransfer,
} from '../../generated/EventsHub/EventsHub'
// using network address from config file
// to be passed to client when creating instance
Expand Down Expand Up @@ -382,6 +383,18 @@ export function handleDelegatorClaimedRewards(event: DelegatorClaimedRewards): v
delegator.save()
}

export function handleSharesTransfer(event: SharesTransfer): void {
let fromDelegator = loadDelegator(event.params.validatorId, event.params.from)
let toDelegator = loadDelegator(event.params.validatorId, event.params.to)

fromDelegator.delegatedAmount = fromDelegator.delegatedAmount.minus(event.params.value)
// update claimed amount
toDelegator.delegatedAmount = toDelegator.delegatedAmount.plus(event.params.value)

fromDelegator.save()
toDelegator.save()
}

//
// Topup
//
Expand Down
2 changes: 2 additions & 0 deletions root/subgraph.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ dataSources:
handler: handleShareBurnedWithId
- event: UpdateCommissionRate(indexed uint256,indexed uint256,indexed uint256)
handler: handleUpdateCommissionRate
- event: SharesTransfer(indexed uint256,indexed address,indexed address,uint256)
handler: handleSharesTransfer
file: ./src/mappings/staking-info.ts

- kind: ethereum/contract
Expand Down

0 comments on commit 10fe9f6

Please sign in to comment.