Skip to content

Commit dace403

Browse files
committed
Adds round payout script
1 parent 9b69ae5 commit dace403

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

src/tools/get-round-rewards.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { getApiFor, NETWORK_YARGS_OPTIONS } from "src/utils/networks.ts";
2+
import yargs from "yargs";
3+
4+
export const NETWORK_WS_URLS: { [name: string]: string } = {
5+
rococo: "wss://rococo-rpc.polkadot.io",
6+
westend: "wss://westend.api.onfinality.io/public-ws",
7+
kusama: "wss://kusama.api.onfinality.io/public-ws",
8+
polkadot: "wss://polkadot.api.onfinality.io/public-ws",
9+
};
10+
11+
const argv = yargs(process.argv.slice(2))
12+
.usage("Usage: $0")
13+
.version("1.0.0")
14+
.options({
15+
...NETWORK_YARGS_OPTIONS,
16+
at: {
17+
type: "number",
18+
description: "Block number",
19+
},
20+
}).argv;
21+
22+
const main = async () => {
23+
const api = await getApiFor(argv);
24+
25+
const blockHash = argv.at
26+
? await api.rpc.chain.getBlockHash(argv.at)
27+
: await api.rpc.chain.getBlockHash();
28+
const block = await api.rpc.chain.getBlock(blockHash);
29+
const apiAt = await api.at(blockHash);
30+
31+
const round = await apiAt.query.parachainStaking.round();
32+
const roundBlockApiAt = await api.at(await api.rpc.chain.getBlockHash(round.first));
33+
34+
const atStake = await roundBlockApiAt.query.parachainStaking.atStake.entries();
35+
const awardedPts = await roundBlockApiAt.query.parachainStaking.awardedPts.entries();
36+
const collatorsPoints = {};
37+
console.log(`Using previous round: ${round.current.toNumber() - 1}`);
38+
for (const [key, value] of awardedPts) {
39+
const [stakeRound, collator] = key.args;
40+
if (stakeRound.toNumber() !== round.current.toNumber() - 1) {
41+
continue;
42+
}
43+
collatorsPoints[collator.toHex()] = (value as any).toNumber();
44+
}
45+
let paidBlock = round.first.toNumber() + 1;
46+
for (const [key] of atStake) {
47+
const [stakeRound, collator] = key.args;
48+
if (stakeRound.toNumber() !== round.current.toNumber() - 1) {
49+
continue;
50+
}
51+
console.log(
52+
`Account ${collator.toHuman()} had ${collatorsPoints[collator.toHex()]} at ${paidBlock++}`,
53+
);
54+
}
55+
await api.disconnect();
56+
};
57+
58+
main();

0 commit comments

Comments
 (0)