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

Nomination pools rewards #21

Merged
merged 29 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
86274ed
added base PaidOut support
vovunku Jul 10, 2023
5a607d0
add source(direct/pooled) field to reward
vovunku Jul 10, 2023
9a031b1
add source to AccumulatedReward
vovunku Jul 10, 2023
b057df3
removed source/added new stakingType
vovunku Jul 11, 2023
0091b56
added BondedSlash handler(not tested)
vovunku Jul 11, 2023
f0e335b
pooled slashes implemented(not tested yet)
vovunku Jul 11, 2023
f9c487f
first test for bonded slash added
vovunku Jul 14, 2023
2dfb406
more accounts
vovunku Jul 17, 2023
711cc22
add unbonding test
vovunku Jul 17, 2023
04988f1
fixed member point logic
vovunku Jul 17, 2023
0301848
Merge branch 'feature/nomination-pools-rewards' into feature/nomintai…
vovunku Jul 17, 2023
50d2e23
added all unbonding tests
vovunku Jul 17, 2023
338c501
fixed division by zero if poolPoints === 0
vovunku Jul 17, 2023
83ac959
Merge branch 'feature/nomination-pools-rewards' into feature/nomintai…
vovunku Jul 17, 2023
1b09033
removed copypaste
vovunku Jul 17, 2023
c6faed5
added test for pool rewards
vovunku Jul 17, 2023
5d2e693
added pool handlers to Polkadot, Westend and Aleph-zero
vovunku Jul 17, 2023
b19971f
removed console.log
vovunku Jul 17, 2023
ecc1cf7
renamed test
vovunku Jul 17, 2023
2ff283e
code refactoring
vovunku Jul 18, 2023
adb5e38
Merge branch 'feature/nomination-pools-rewards' into feature/nomintai…
vovunku Jul 18, 2023
72368bd
updated nomination pools path
vovunku Jul 18, 2023
3f34099
merged master for apy
vovunku Jul 18, 2023
f603550
fixed common.ts while merging
vovunku Jul 18, 2023
2837b82
base added
vovunku Jul 20, 2023
8b95164
Merge branch 'feature/nomination-pools-rewards' into feature/nomintai…
vovunku Jul 25, 2023
b457ba9
Revert "base added"
vovunku Jul 25, 2023
eabbd75
Merge branch 'feature/nomination-pools-rewards' into feature/nomintai…
vovunku Jul 25, 2023
8da30b9
Merge pull request #22 from novasamatech/feature/nomintaion_pools_test
vovunku Jul 26, 2023
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
Next Next commit
added base PaidOut support
  • Loading branch information
vovunku committed Jul 10, 2023
commit 86274ed9422b1e628a32bd4fdf137bef7782bc38
6 changes: 6 additions & 0 deletions project-kusama.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ dataSources:
module: staking
method: Rewarded

- handler: handleKusamaPoolStakingReward
kind: substrate/EventHandler
filter:
module: nominationPools
method: PaidOut

- handler: handleKusamaStakingSlash
kind: substrate/EventHandler
filter:
Expand Down
1 change: 1 addition & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@ type Reward @entity {
amount: BigInt!
accumulatedAmount: BigInt!
type: RewardType!
poolId: Int
}
8 changes: 8 additions & 0 deletions src/mappings/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,12 @@ export async function handleNewEra(
)

await stakingStats.indexEraStats()
}

export function stakingTypeDirect(stakingType: string): string {
return `${stakingType}-${"direct"}`
}

export function stakingTypePooled(stakingType: string): string {
return `${stakingType}-${"pooled"}`
}
18 changes: 13 additions & 5 deletions src/mappings/kusama.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import {SubstrateEvent} from "@subql/types";
import {handleNewEra} from "./common";
import {handleNewEra, stakingTypeDirect, stakingTypePooled} from "./common";
import {RelaychainRewardCalculator} from "./rewards/Relaychain";
import {ValidatorEraInfoDataSource} from "./era/ValidatorEraInfoDataSource";
import {Codec} from "@polkadot/types/types";
import {INumber} from "@polkadot/types-codec/types/interfaces";
import {handleRelaychainStakingReward, handleRelaychainStakingSlash} from "./rewards/history/relaychain";
import {handleRelaychainStakingReward, handleRelaychainStakingSlash, handleRelaychainPooledStakingReward} from "./rewards/history/relaychain";

const KUSAMA_GENESIS = "0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe"
const STAKING_TYPE = "relaychain"
const DIRECT_STAKING_TYPE = stakingTypeDirect(STAKING_TYPE)
const POOLED_STAKING_TYPE = stakingTypePooled(STAKING_TYPE)

export async function handleKusamaNewEra(_: SubstrateEvent): Promise<void> {
let validatorEraInfoDataSource = new ValidatorEraInfoDataSource();
Expand All @@ -16,18 +18,24 @@ export async function handleKusamaNewEra(_: SubstrateEvent): Promise<void> {
validatorEraInfoDataSource,
await RelaychainRewardCalculator(validatorEraInfoDataSource),
KUSAMA_GENESIS,
STAKING_TYPE
DIRECT_STAKING_TYPE
)
}

export async function handleKusamaStakingReward(
event: SubstrateEvent<[accountId: Codec, reward: INumber]>,
): Promise<void> {
await handleRelaychainStakingReward(event, KUSAMA_GENESIS, STAKING_TYPE)
await handleRelaychainStakingReward(event, KUSAMA_GENESIS, DIRECT_STAKING_TYPE)
}

export async function handleKusamaStakingSlash(
event: SubstrateEvent<[account: Codec, slash: INumber]>,
): Promise<void> {
await handleRelaychainStakingSlash(event, KUSAMA_GENESIS, STAKING_TYPE)
await handleRelaychainStakingSlash(event, KUSAMA_GENESIS, DIRECT_STAKING_TYPE)
}

export async function handleKusamaPoolStakingReward(
event: SubstrateEvent<[accountId: Codec, poolId: INumber, reward: INumber]>,
): Promise<void> {
await handleRelaychainPooledStakingReward(event, KUSAMA_GENESIS, POOLED_STAKING_TYPE)
}
6 changes: 6 additions & 0 deletions src/mappings/rewards/history/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export interface RewardArgs {
chainId: string

stakingType: string

poolId?: number
}

export async function handleReward(rewardProps: RewardArgs, event: SubstrateEvent) {
Expand All @@ -32,6 +34,10 @@ export async function handleReward(rewardProps: RewardArgs, event: SubstrateEven
stakingType: rewardProps.stakingType
});

if (rewardProps.poolId !== undefined) {
accountReward.poolId = rewardProps.poolId
}

await accountReward.save()
}

Expand Down
19 changes: 19 additions & 0 deletions src/mappings/rewards/history/relaychain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,25 @@ export async function handleRelaychainStakingReward(
await handleRelaychainStakingRewardType(event, RewardType.reward, chainId, stakingType)
}

export async function handleRelaychainPooledStakingReward(
vovunku marked this conversation as resolved.
Show resolved Hide resolved
event: SubstrateEvent<[accountId: Codec, poolId: INumber, reward: INumber]>,
chainId: string,
stakingType: string
): Promise<void> {
const {event: {data: [accountId, poolId, amount]}} = event

const rewardProps: RewardArgs = {
amount: amount.toBigInt(),
address: accountId.toString(),
type: RewardType.reward,
chainId: chainId,
stakingType: stakingType,
poolId: poolId.toNumber()
}

await handleReward(rewardProps, event)
}

export async function handleRelaychainStakingSlash(
event: SubstrateEvent<[account: Codec, slash: INumber]>,
chainId: string,
Expand Down