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

SQN-1397 #70

Merged
merged 5 commits into from
May 15, 2023
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 .project-cid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
QmWMGNiQqyud3k3BCo7a5q1WTBBuq4cgbeajHnp21VwvFd
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
},
"dependencies": {
"@ethersproject/abi": "^5.7.0",
"@subql/contract-sdk": "^0.12.5-2",
"@subql/contract-sdk": "0.13.1-2",
"@subql/types-ethereum": "dev",
"@types/pino": "^7.0.5",
"@types/validator": "latest",
Expand Down
4 changes: 2 additions & 2 deletions project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ dataSources:
kind: ethereum/LogHandler
filter:
topics:
- UnbondWithdrawn(address indexed source, uint256 amount, uint256 index)
- UnbondWithdrawn(address indexed source, uint256 amount, uint256 fee, uint256 index)
- handler: handleWithdrawCancelled
kind: ethereum/LogHandler
filter:
Expand Down Expand Up @@ -231,7 +231,7 @@ dataSources:
kind: ethereum/LogHandler
filter:
topics:
- DistributeRewards(address indexed indexer, uint256 indexed eraIdx, uint256 rewards)
- DistributeRewards(address indexed indexer, uint256 indexed eraIdx, uint256 rewards, uint256 commission)
- handler: handleRewardsClaimed
kind: ethereum/LogHandler
filter:
Expand Down
23 changes: 20 additions & 3 deletions src/mappings/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-unsafe-call */

import { EraManager__factory } from '@subql/contract-sdk';
import { EraManager__factory, Staking__factory } from '@subql/contract-sdk';
import {
DelegationAddedEvent,
DelegationRemovedEvent,
Expand All @@ -13,7 +13,12 @@ import {
UnbondCancelledEvent,
} from '@subql/contract-sdk/typechain/Staking';
import assert from 'assert';
import { Delegation, Withdrawl, WithdrawalStatus } from '../types';
import {
Delegation,
Withdrawl,
WithdrawalStatus,
WithdrawalType,
} from '../types';
import {
ERA_MANAGER_ADDRESS,
updateTotalStake,
Expand All @@ -26,6 +31,7 @@ import {
getDelegationId,
updateMaxUnstakeAmount,
biToDate,
STAKING_ADDRESS,
} from './utils';
import { EthereumLog } from '@subql/types-ethereum';
import { CreateWithdrawlParams } from '../interfaces';
Expand Down Expand Up @@ -173,12 +179,23 @@ export async function handleWithdrawRequested(
const { source, indexer, amount, index, _type } = event.args;
const id = getWithdrawlId(source, index);

let updatedAmount = amount;

if (getWithdrawalType(_type) === WithdrawalType.MERGE) {
const staking = Staking__factory.connect(STAKING_ADDRESS, api);
const { amount: unbondingAmount } = await staking.unbondingAmount(
indexer,
index
);
updatedAmount = updatedAmount.add(unbondingAmount);
}

await createWithdrawl({
id,
delegator: source,
indexer,
index,
amount,
amount: updatedAmount,
type: getWithdrawalType(_type),
status: ONGOING,
event,
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1518,10 +1518,10 @@
reflect-metadata "^0.1.13"
semver "^7.3.5"

"@subql/contract-sdk@^0.12.5-2":
version "0.12.5-2"
resolved "https://registry.yarnpkg.com/@subql/contract-sdk/-/contract-sdk-0.12.5-2.tgz#6dbfe256d785737c435f4ce9246b7bd77dba9d3d"
integrity sha512-opt9HDPdNx5+p8/Gm3IxgWSqKW/6uQSQWYIq/37a0da74Nqn50Cbp4B18NIUb1Z3Xi8Cz//ckB3etaYiNYkbFA==
"@subql/contract-sdk@0.13.1-2":
version "0.13.1-2"
resolved "https://registry.yarnpkg.com/@subql/contract-sdk/-/contract-sdk-0.13.1-2.tgz#34cfc66dd2b8079c70ec480ed9ba2b37afdc422b"
integrity sha512-FRvAlLUtH9AFoqUESUOwtraKjiDPaZT5FW1FJUUxQcJMy3j231EqOWTZJBtCP33swzTa2Uzb442YbzLPheCw+A==
dependencies:
"@openzeppelin/contracts-upgradeable" "^4.5.2"

Expand Down