-
Notifications
You must be signed in to change notification settings - Fork 2
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
Nomination pools rewards #21
Merged
Merged
Changes from 3 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
86274ed
added base PaidOut support
vovunku 5a607d0
add source(direct/pooled) field to reward
vovunku 9a031b1
add source to AccumulatedReward
vovunku b057df3
removed source/added new stakingType
vovunku 0091b56
added BondedSlash handler(not tested)
vovunku f0e335b
pooled slashes implemented(not tested yet)
vovunku f9c487f
first test for bonded slash added
vovunku 2dfb406
more accounts
vovunku 711cc22
add unbonding test
vovunku 04988f1
fixed member point logic
vovunku 0301848
Merge branch 'feature/nomination-pools-rewards' into feature/nomintai…
vovunku 50d2e23
added all unbonding tests
vovunku 338c501
fixed division by zero if poolPoints === 0
vovunku 83ac959
Merge branch 'feature/nomination-pools-rewards' into feature/nomintai…
vovunku 1b09033
removed copypaste
vovunku c6faed5
added test for pool rewards
vovunku 5d2e693
added pool handlers to Polkadot, Westend and Aleph-zero
vovunku b19971f
removed console.log
vovunku ecc1cf7
renamed test
vovunku 2ff283e
code refactoring
vovunku adb5e38
Merge branch 'feature/nomination-pools-rewards' into feature/nomintai…
vovunku 72368bd
updated nomination pools path
vovunku 3f34099
merged master for apy
vovunku f603550
fixed common.ts while merging
vovunku 2837b82
base added
vovunku 8b95164
Merge branch 'feature/nomination-pools-rewards' into feature/nomintai…
vovunku b457ba9
Revert "base added"
vovunku eabbd75
Merge branch 'feature/nomination-pools-rewards' into feature/nomintai…
vovunku 8da30b9
Merge pull request #22 from novasamatech/feature/nomintaion_pools_test
vovunku File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,106 @@ | ||
import {SubstrateEvent} from "@subql/types"; | ||
import {Codec} from "@polkadot/types/types"; | ||
import {RewardType} from "../../../types"; | ||
import {INumber} from "@polkadot/types-codec/types/interfaces"; | ||
import {handleRelaychainStakingRewardType} from "./relaychain"; | ||
import {PalletNominationPoolsPoolMember} from "@polkadot/types/lookup"; | ||
|
||
export async function handleRelaychainPooledStakingReward( | ||
event: SubstrateEvent<[accountId: Codec, poolId: INumber, reward: INumber]>, | ||
chainId: string, | ||
stakingType: string | ||
): Promise<void> { | ||
const {event: {data: [accountId, poolId, amount]}} = event | ||
|
||
await handleRelaychainStakingRewardType( | ||
event, | ||
amount.toBigInt(), | ||
accountId.toString(), | ||
RewardType.reward, | ||
chainId, stakingType, | ||
poolId.toNumber() | ||
) | ||
} | ||
|
||
export async function handleRelaychainPooledStakingBondedSlash( | ||
event: SubstrateEvent<[poolId: INumber, slash: INumber]>, | ||
chainId: string, | ||
stakingType: string | ||
): Promise<void> { | ||
const {event: {data: [poolId, slash]}} = event | ||
const pid = poolId.toNumber() | ||
|
||
const pool = (await api.query.nominationPools.bondedPools(pid)).unwrap() | ||
|
||
await handleRelaychainPooledStakingSlash( | ||
event, | ||
pid, | ||
pool.points.toBigInt(), | ||
slash.toBigInt(), | ||
chainId, | ||
stakingType, | ||
(member: PalletNominationPoolsPoolMember) : bigint => { | ||
return member.points.toBigInt() | ||
} | ||
) | ||
} | ||
|
||
export async function handleRelaychainPooledStakingUnbondingSlash( | ||
event: SubstrateEvent<[era: INumber, poolId: INumber, slash: INumber]>, | ||
chainId: string, | ||
stakingType: string | ||
): Promise<void> { | ||
const {event: {data: [era, poolId, slash]}} = event | ||
const poolIdNumber = poolId.toNumber() | ||
const eraIdNumber = era.toNumber() | ||
|
||
const unbondingPools = (await api.query.nominationPools.subPoolsStorage(poolIdNumber)).unwrap() | ||
|
||
const pool = unbondingPools.withEra[eraIdNumber] ?? unbondingPools.noEra | ||
|
||
await handleRelaychainPooledStakingSlash( | ||
event, | ||
poolIdNumber, | ||
pool.points.toBigInt(), | ||
slash.toBigInt(), | ||
chainId, | ||
stakingType, | ||
(member: PalletNominationPoolsPoolMember) : bigint => { | ||
return member.unbondingEras[eraIdNumber]?.toBigInt() ?? BigInt(0) | ||
} | ||
) | ||
} | ||
|
||
export async function handleRelaychainPooledStakingSlash( | ||
event: SubstrateEvent, | ||
poolId: number, | ||
poolPoints: bigint, | ||
slash: bigint, | ||
chainId: string, | ||
stakingType: string, | ||
memberPointsCounter: (member: PalletNominationPoolsPoolMember) => bigint | ||
): Promise<void> { | ||
if(poolPoints == BigInt(0)) { | ||
return | ||
} | ||
|
||
const members = await api.query.nominationPools.poolMembers.entries() | ||
|
||
await Promise.all(members.map(async ([accountId, member]) => { | ||
let memberPoints: bigint | ||
if (member.isSome && member.unwrap().poolId.toNumber() === poolId) { | ||
memberPoints = memberPointsCounter(member.unwrap()) | ||
if (memberPoints != BigInt(0)) { | ||
await handleRelaychainStakingRewardType( | ||
event, | ||
(slash / poolPoints) * memberPoints, | ||
accountId.toString(), | ||
RewardType.slash, | ||
chainId, | ||
stakingType, | ||
poolId | ||
) | ||
} | ||
} | ||
})) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's cache this request for a given block number