-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpolkadot.ts
79 lines (66 loc) · 3.26 KB
/
polkadot.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import {SubstrateEvent} from "@subql/types";
import {handleNewEra, handleNewSession, POOLED_STAKING_TYPE} from "./common";
import {CustomPolkadotRewardCalculator} from "./rewards/Relaychain";
import {NominationPoolRewardCalculator} from "./rewards/NominationPoolRewardCalculator";
import {ValidatorStakingRewardCalculator} from "./rewards/ValidatorStakingRewardCalculator";
import {ValidatorEraInfoDataSource} from "./era/ValidatorEraInfoDataSource";
import {EraInfoDataSource} from "./era/EraInfoDataSource";
import {Codec} from "@polkadot/types/types";
import {INumber} from "@polkadot/types-codec/types/interfaces";
import {handleRelaychainStakingReward, handleRelaychainStakingSlash} from "./rewards/history/relaychain";
import {
handleRelaychainPooledStakingReward,
handleRelaychainPooledStakingBondedSlash,
handleRelaychainPooledStakingUnbondingSlash
} from "./rewards/history/nomination_pools";
const POLKADOT_GENESIS = "0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3"
const DIRECT_STAKING_TYPE = "relaychain"
export async function PolkadotRewardCalculator(eraInfoDataSource: EraInfoDataSource): Promise<ValidatorStakingRewardCalculator> {
return CustomPolkadotRewardCalculator(eraInfoDataSource)
}
export async function handlePolkadotNewEra(_: SubstrateEvent): Promise<void> {
let validatorEraInfoDataSource = new ValidatorEraInfoDataSource();
await handleNewEra(
validatorEraInfoDataSource,
await PolkadotRewardCalculator(validatorEraInfoDataSource),
POLKADOT_GENESIS,
DIRECT_STAKING_TYPE
)
}
export async function handlePolkadotNewSession(_: SubstrateEvent): Promise<void> {
let validatorEraInfoDataSource = new ValidatorEraInfoDataSource();
let mainRewardCalculator = await PolkadotRewardCalculator(validatorEraInfoDataSource)
let poolRewardCalculator = new NominationPoolRewardCalculator(validatorEraInfoDataSource, mainRewardCalculator)
await handleNewSession(
validatorEraInfoDataSource,
await mainRewardCalculator,
POLKADOT_GENESIS,
DIRECT_STAKING_TYPE,
poolRewardCalculator
)
}
export async function handlePolkadotStakingReward(
event: SubstrateEvent<[accountId: Codec, reward: INumber]>,
): Promise<void> {
await handleRelaychainStakingReward(event, POLKADOT_GENESIS, DIRECT_STAKING_TYPE)
}
export async function handlePolkadotStakingSlash(
event: SubstrateEvent<[account: Codec, slash: INumber]>,
): Promise<void> {
await handleRelaychainStakingSlash(event, POLKADOT_GENESIS, DIRECT_STAKING_TYPE)
}
export async function handlePolkadotPoolStakingReward(
event: SubstrateEvent<[accountId: Codec, poolId: INumber, reward: INumber]>,
): Promise<void> {
await handleRelaychainPooledStakingReward(event, POLKADOT_GENESIS, POOLED_STAKING_TYPE)
}
export async function handlePolkadotPoolStakingBondedSlash(
event: SubstrateEvent<[poolId: INumber, slash: INumber]>,
): Promise<void> {
await handleRelaychainPooledStakingBondedSlash(event, POLKADOT_GENESIS, POOLED_STAKING_TYPE)
}
export async function handlePolkadotPoolStakingUnbondingSlash(
event: SubstrateEvent<[era: INumber, poolId: INumber, slash: INumber]>,
): Promise<void> {
await handleRelaychainPooledStakingUnbondingSlash(event, POLKADOT_GENESIS, POOLED_STAKING_TYPE)
}