diff --git a/root/abis/EventsHub.json b/root/abis/EventsHub.json index e037360..4af5bfb 100644 --- a/root/abis/EventsHub.json +++ b/root/abis/EventsHub.json @@ -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"}] \ No newline at end of file +[{"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"}] \ No newline at end of file diff --git a/root/src/mappings/staking-info.ts b/root/src/mappings/staking-info.ts index 86a6252..3be695f 100644 --- a/root/src/mappings/staking-info.ts +++ b/root/src/mappings/staking-info.ts @@ -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 @@ -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 // diff --git a/root/subgraph.template.yaml b/root/subgraph.template.yaml index c878cf4..63f8ea6 100644 --- a/root/subgraph.template.yaml +++ b/root/subgraph.template.yaml @@ -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