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

fix runtime upgrade, bump polkadotjs api #50

Merged
merged 3 commits into from
Apr 25, 2024
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
4 changes: 2 additions & 2 deletions charts/polkadot-k8s-payouts/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
description: Polkadot K8s Payouts
name: polkadot-k8s-payouts
version: v1.2.8
appVersion: v1.2.8
version: v1.2.9
appVersion: v1.2.9
apiVersion: v2
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "polkadot-payouts",
"version": "1.2.8",
"version": "1.2.9",
"description": "Automated transfers among accounts",
"repository": "[email protected]:w3f/accountant.git",
"author": "W3F Infrastructure Team <[email protected]>",
Expand All @@ -20,7 +20,7 @@
"start": "NODE_OPTIONS='--max-old-space-size=4096' node ./dist/index.js start"
},
"dependencies": {
"@polkadot/api": "^10.13.1",
"@polkadot/api": "^11.0.1",
"@w3f/config": "^0.1.1",
"@w3f/logger": "^0.4.3",
"async-wait-until": "^1.2.6",
Expand Down
46 changes: 32 additions & 14 deletions src/claimer.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { ClaimerInputConfig, Target, GracePeriod, ValidatorInfo, ValidatorsMap, ClaimPool } from './types';
import { getActiveEraIndex, initKey } from './utils';
import { getActiveEraIndex, initKey, setDifference } from './utils';
import { Logger, LoggerSingleton } from './logger';
import { ApiPromise, Keyring } from '@polkadot/api';
import { KeyringPair } from '@polkadot/keyring/types';
import waitUntil from 'async-wait-until';
import { BN } from 'bn.js';
import { batchSize, claimAttempts, gracePeriod, isDeepCheckEnabled } from './constants';
import { DeriveOwnExposure } from '@polkadot/api-derive/types';

export class Claimer {
private isDeepCheckEnabled = isDeepCheckEnabled
Expand Down Expand Up @@ -135,21 +136,38 @@ export class Claimer {


private async gatherUnclaimedInfo(validatorAddress: string, validatorInfo: ValidatorInfo): Promise<number[]> {

const ownRewardsIdx: Set<number> = new Set<number>
const exposure: DeriveOwnExposure[] = await this.api.derive.staking.ownExposures(validatorAddress)
exposure.forEach(e=>{
if(e.exposure.total.toBn().gt(new BN(0))) ownRewardsIdx.add(e.era.toNumber()) //legacy
if(e.exposureMeta?.value.total?.toBn().gt(new BN(0))) ownRewardsIdx.add(e.era.toNumber()) //new
})

const lastReward = validatorInfo.lastReward

const numOfPotentialUnclaimedPayouts = this.currentEraIndex - lastReward - 1;
const unclaimedPayouts: number[] = []
for ( let i = 1; i <= numOfPotentialUnclaimedPayouts; i++) {
const idx = lastReward + i;
const exposure = await this.api.query.staking.erasStakers(idx, validatorAddress);
if (exposure.total.toBn().gt(new BN(0))) {
unclaimedPayouts.push(idx)
const claimedIdx: Set<number> = new Set<number>
const stakingQuery = await this.api.derive.staking.query(validatorAddress,{withLedger:true, withClaimedRewardsEras: true})
stakingQuery.stakingLedger.legacyClaimedRewards.forEach(r=>claimedIdx.add(r.toNumber()))
stakingQuery.claimedRewardsEras.forEach(r=>claimedIdx.add(r.toNumber()))

const unclaimed: number[] = Array.from(setDifference(ownRewardsIdx,claimedIdx))
this.logger.debug(unclaimed.toString())

//bugFix: https://github.com/polkadot-js/api/issues/5859
//temporary solution
const chainName = (await this.api.rpc.system.chain()).toString().toLowerCase()
const unclaimedFixed = unclaimed.filter(x => {
switch (chainName) {
case "kusama":
return x>6513
case "polkadot":
return x>1419
default:
return true
}
}
validatorInfo.unclaimedPayouts=unclaimedPayouts

return unclaimedPayouts
})

validatorInfo.unclaimedPayouts=unclaimedFixed
return unclaimedFixed
}

private async buildClaimPool(validatorsMap: ValidatorsMap): Promise<ClaimPool[]> {
Expand Down
4 changes: 4 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ export const initKey = (keystoreFilePath: string, passwordFilePath): any =>{ //s
logger.error(`problem unlocking the wallet, exiting ...`)
process.exit(1)
} else return keyPair
}

export const setDifference = <T>(setA: Set<T>, setB: Set<T>): Set<T> => {
return new Set([...setA].filter(x=>!setB.has(x)))
}
Loading
Loading