Skip to content

Commit

Permalink
chore(pjs): update polkadot-js, and fix staking ledger types (#1371)
Browse files Browse the repository at this point in the history
* chore(pjs): update polkadot-js

* update ledger types

* dedupe
  • Loading branch information
TarikGul committed Jan 3, 2024
1 parent 36b4416 commit ceea8eb
Show file tree
Hide file tree
Showing 4 changed files with 314 additions and 309 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
"test:test-release": "yarn build:scripts && node scripts/build/runYarnPack.js"
},
"dependencies": {
"@polkadot/api": "^10.10.1",
"@polkadot/api-contract": "^10.10.1",
"@polkadot/util-crypto": "^12.5.1",
"@polkadot/api": "^10.11.2",
"@polkadot/api-contract": "^10.11.2",
"@polkadot/util-crypto": "^12.6.2",
"@substrate/calc": "^0.3.1",
"argparse": "^2.0.1",
"confmgr": "^1.0.10",
Expand Down
25 changes: 15 additions & 10 deletions src/services/accounts/AccountsStakingPayoutsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import { ApiPromise } from '@polkadot/api';
import { ApiDecoration } from '@polkadot/api/types';
import { DeriveEraExposure, DeriveEraExposureNominating } from '@polkadot/api-derive/staking/types';
import { Option, u32 } from '@polkadot/types';
import { BalanceOf, BlockHash, EraIndex, Perbill, StakingLedger } from '@polkadot/types/interfaces';
import { PalletStakingEraRewardPoints } from '@polkadot/types/lookup';
import type { ApiDecoration } from '@polkadot/api/types';
import type { DeriveEraExposure, DeriveEraExposureNominating } from '@polkadot/api-derive/staking/types';
import type { Option, u32 } from '@polkadot/types';
import type { BalanceOf, BlockHash, EraIndex, Perbill, StakingLedger } from '@polkadot/types/interfaces';
import type { PalletStakingEraRewardPoints, PalletStakingStakingLedger } from '@polkadot/types/lookup';
import { CalcPayout } from '@substrate/calc';
import { BadRequest } from 'http-errors';

import { IAccountStakingPayouts, IEraPayouts, IPayout } from '../../types/responses';
import type { IAccountStakingPayouts, IEraPayouts, IPayout } from '../../types/responses';
import { AbstractService } from '../AbstractService';

/**
Expand All @@ -37,7 +37,7 @@ type IErasGeneral = [DeriveEraExposure, PalletStakingEraRewardPoints, Option<Bal
*/
interface ICommissionAndLedger {
commission: Perbill;
validatorLedger?: StakingLedger;
validatorLedger?: PalletStakingStakingLedger;
}

/**
Expand Down Expand Up @@ -202,7 +202,7 @@ export class AccountsStakingPayoutsService extends AbstractService {
deriveErasExposures: DeriveEraExposure[],
): Promise<ICommissionAndLedger[][]> {
// Cache StakingLedger to reduce redundant queries to node
const validatorLedgerCache: { [id: string]: StakingLedger } = {};
const validatorLedgerCache: { [id: string]: PalletStakingStakingLedger } = {};

const allErasCommissions = deriveErasExposures.map((deriveEraExposure, idx) => {
const currEra = idx + startEra;
Expand Down Expand Up @@ -272,7 +272,12 @@ export class AccountsStakingPayoutsService extends AbstractService {
continue;
}
// Check if the reward has already been claimed
const claimed = validatorLedger.claimedRewards.includes(eraIndex);
let claimed: boolean;
if (validatorLedger.legacyClaimedRewards) {
claimed = validatorLedger.legacyClaimedRewards.includes(eraIndex);
} else {
claimed = (validatorLedger as unknown as StakingLedger).claimedRewards.includes(eraIndex);
}
if (unclaimedOnly && claimed) {
continue;
}
Expand Down Expand Up @@ -317,7 +322,7 @@ export class AccountsStakingPayoutsService extends AbstractService {
historicApi: ApiDecoration<'promise'>,
validatorId: string,
era: number,
validatorLedgerCache: { [id: string]: StakingLedger },
validatorLedgerCache: { [id: string]: PalletStakingStakingLedger },
): Promise<ICommissionAndLedger> {
let commission;
let validatorLedger;
Expand Down
7 changes: 4 additions & 3 deletions src/types/responses/AccountStakingInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import { RewardDestination, StakingLedger } from '@polkadot/types/interfaces';
import { AccountId } from '@polkadot/types/interfaces/runtime';
import type { RewardDestination } from '@polkadot/types/interfaces';
import type { AccountId } from '@polkadot/types/interfaces/runtime';
import type { PalletStakingStakingLedger } from '@polkadot/types/lookup';

import { IAt } from '.';

Expand All @@ -24,5 +25,5 @@ export interface IAccountStakingInfo {
controller: AccountId;
rewardDestination: RewardDestination;
numSlashingSpans: number;
staking: StakingLedger;
staking: PalletStakingStakingLedger;
}
Loading

0 comments on commit ceea8eb

Please sign in to comment.