From aaf127379467667b8fd06c79feb1e61ec42e6835 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Thu, 5 Mar 2020 15:37:34 +0100 Subject: [PATCH] Additional derives for new staking points & rewards (#1994) * Additional derives for new staking points & rewards * Fix method name * StakingLedger update * Expand derives * Cleanups * Cleanup Compact decode * Cleanup derives * Update CHANGELOG * Split types --- CHANGELOG.md | 2 + packages/api-derive/src/parachains/types.ts | 30 ++++++ packages/api-derive/src/session/indexes.ts | 24 +++-- packages/api-derive/src/session/types.ts | 24 +++++ .../api-derive/src/staking/erasExposure.ts | 56 +++++++++++ packages/api-derive/src/staking/erasPoints.ts | 65 ++++++++++++ .../api-derive/src/staking/erasRewards.ts | 36 +++++++ packages/api-derive/src/staking/index.ts | 5 + .../api-derive/src/staking/stakerRewards.ts | 42 ++++++++ packages/api-derive/src/staking/types.ts | 80 +++++++++++++++ .../api-derive/src/staking/validatorPoints.ts | 27 +++++ packages/api-derive/src/types.ts | 99 ++----------------- packages/api/src/checkTypes.manual.ts | 9 +- packages/types/src/augment/registry.ts | 5 +- packages/types/src/codec/AbstractInt.ts | 2 +- packages/types/src/codec/Compact.ts | 6 +- .../src/interfaces/staking/definitions.ts | 5 +- .../types/src/interfaces/staking/types.ts | 7 +- packages/types/src/known/overrides.ts | 3 +- 19 files changed, 405 insertions(+), 122 deletions(-) create mode 100644 packages/api-derive/src/session/types.ts create mode 100644 packages/api-derive/src/staking/erasExposure.ts create mode 100644 packages/api-derive/src/staking/erasPoints.ts create mode 100644 packages/api-derive/src/staking/erasRewards.ts create mode 100644 packages/api-derive/src/staking/stakerRewards.ts create mode 100644 packages/api-derive/src/staking/types.ts create mode 100644 packages/api-derive/src/staking/validatorPoints.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index f922f1076c..9a8a5bb06a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - Add proper support for type generation with an Enum containing an Tuple (Thanks to https://github.com/monitz87) - Fix storage parsing not resulting in rejected Promises (Fix from https://github.com/aniiantt applied) +- Remove use of deprecated `Observable.create` (Thanks to https://github.com/Himself65) - Type generation will now handle the same sub-module name across packages, i.e. `@polkadot/types/interfaces/runtime` & `@mine/interfaces/runtime`) - Add `.range([from, to]: [Hash, Hash?], ...args: any[]): [Hash, Codec][]` on all storage entries - Add `.raw(...args: any[]): Promise` to all RPC calls, returning the un-encoded result @@ -11,6 +12,7 @@ - `Bool` will now correctly return `isEmpty` on false/default values - Refresh the `NetworkState` types as returned by the `rpc.system.networkState()` call to current - Expose `registry.createClass()`, to allow for creating type classes. If you are using `createClass` or `ClassOf` in your code, it is recommended to swap to this instance. +- Add additional derives to `api.derive.staking` to handle lazy-payout calculations # 1.4.2 Feb 27, 2020 diff --git a/packages/api-derive/src/parachains/types.ts b/packages/api-derive/src/parachains/types.ts index fc7ff08cd0..ea25666e13 100644 --- a/packages/api-derive/src/parachains/types.ts +++ b/packages/api-derive/src/parachains/types.ts @@ -18,3 +18,33 @@ export type RelayDispatchQueue = Vec export type RelayDispatchQueueSize = ITuple<[u32, u32]>; export type Watermarks = Option; export type DidUpdate = Option>; + +export interface DeriveParachainActive { + collatorId: CollatorId; + isRetriable: boolean; + retries: number; +} + +export interface DeriveParachainInfo extends ParaInfo { + id: ParaId; + icon?: string; + name?: string; + owner?: string; +} + +export interface DeriveParachain { + didUpdate: boolean; + pendingSwapId: ParaId | null; + id: ParaId; + info: DeriveParachainInfo | null; + relayDispatchQueueSize?: number; + watermark: BlockNumber | null; +} + +export interface DeriveParachainFull extends DeriveParachain { + active: DeriveParachainActive | null; + heads: Bytes | null; + relayDispatchQueue: UpwardMessage[]; + retryCollators: (CollatorId | null)[]; + selectedCollators: (CollatorId | null)[]; +} diff --git a/packages/api-derive/src/session/indexes.ts b/packages/api-derive/src/session/indexes.ts index eb94e1d02b..0e7c519359 100644 --- a/packages/api-derive/src/session/indexes.ts +++ b/packages/api-derive/src/session/indexes.ts @@ -44,28 +44,32 @@ function queryNoActive (api: ApiInterfaceRx): Observable { // query based on latest function query (api: ApiInterfaceRx): Observable { - return api.queryMulti<[ActiveEraInfo, Option, SessionIndex, u32]>([ + return api.queryMulti<[Option, Option, SessionIndex, u32]>([ api.query.staking.activeEra, api.query.staking.currentEra, api.query.session.currentIndex, api.query.staking.validatorCount ]).pipe( - map(([{ index: activeEra, start: activeEraStart }, currentEra, currentIndex, validatorCount]): Result => [ - activeEra, - activeEraStart, - currentEra.unwrapOr(createType(api.registry, 'EraIndex', 1)), - currentIndex, - validatorCount - ]) + map(([activeOpt, currentEra, currentIndex, validatorCount]): Result => { + const { index: activeEra, start: activeEraStart } = activeOpt.unwrapOrDefault(); + + return [ + activeEra, + activeEraStart, + currentEra.unwrapOr(createType(api.registry, 'EraIndex')), + currentIndex, + validatorCount + ]; + }) ); } // empty set when none is available function empty (api: ApiInterfaceRx): Observable { return of([ - createType(api.registry, 'EraIndex', 1), + createType(api.registry, 'EraIndex'), createType(api.registry, 'Option'), - createType(api.registry, 'EraIndex', 1), + createType(api.registry, 'EraIndex'), createType(api.registry, 'SessionIndex', 1), createType(api.registry, 'u32') ]); diff --git a/packages/api-derive/src/session/types.ts b/packages/api-derive/src/session/types.ts new file mode 100644 index 0000000000..73b4c6abf4 --- /dev/null +++ b/packages/api-derive/src/session/types.ts @@ -0,0 +1,24 @@ +// Copyright 2017-2020 @polkadot/api-derive authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +import { BlockNumber, EraIndex, Moment, SessionIndex } from '@polkadot/types/interfaces'; + +import { Option, u32 } from '@polkadot/types'; + +export interface DeriveSessionIndexes { + activeEra: EraIndex; + activeEraStart: Option; + currentEra: EraIndex; + currentIndex: SessionIndex; + validatorCount: u32; +} + +export interface DerivedSessionInfo extends DeriveSessionIndexes { + eraLength: BlockNumber; + eraProgress: BlockNumber; + isEpoch: boolean; + sessionLength: BlockNumber; + sessionsPerEra: SessionIndex; + sessionProgress: BlockNumber; +} diff --git a/packages/api-derive/src/staking/erasExposure.ts b/packages/api-derive/src/staking/erasExposure.ts new file mode 100644 index 0000000000..9eec8e98fb --- /dev/null +++ b/packages/api-derive/src/staking/erasExposure.ts @@ -0,0 +1,56 @@ +// Copyright 2017-2020 @polkadot/api-derive authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +import { ApiInterfaceRx } from '@polkadot/api/types'; +import { EraIndex, Exposure } from '@polkadot/types/interfaces'; +import { DeriveEraExposure } from '../types'; + +import { Observable, combineLatest, of } from 'rxjs'; +import { map, switchMap } from 'rxjs/operators'; + +import { memo } from '../util'; + +function queryClipped (api: ApiInterfaceRx): Observable<[[EraIndex, string][], Exposure[]]> { + return api.derive.staking.erasPoints().pipe( + switchMap((allPoints): Observable<[[EraIndex, string][], Exposure[]]> => { + const indexes: [EraIndex, string][] = []; + + allPoints.forEach(({ all, era }): void => { + Object.keys(all).forEach((validatorId): void => { + indexes.push([era, validatorId]); + }); + }); + + // FIXME use prefix queries, get going first + return combineLatest([ + of(indexes), + indexes.length + ? api.query.staking.erasStakersClipped.multi(indexes) + : of([] as Exposure[]) + ]); + }) + ); +} + +export function erasExposure (api: ApiInterfaceRx): () => Observable { + return memo((): Observable => + queryClipped(api).pipe( + map(([indexes, exposures]): DeriveEraExposure[] => + indexes.reduce((result: DeriveEraExposure[], [era, validatorId], index): DeriveEraExposure[] => { + let entry = result.find((entry): boolean => entry.era.eq(era)); + + if (!entry) { + entry = { all: {}, era }; + + result.push(entry); + } + + entry.all[validatorId] = exposures[index]; + + return result; + }, []) + ) + ) + ); +} diff --git a/packages/api-derive/src/staking/erasPoints.ts b/packages/api-derive/src/staking/erasPoints.ts new file mode 100644 index 0000000000..56e818f0e4 --- /dev/null +++ b/packages/api-derive/src/staking/erasPoints.ts @@ -0,0 +1,65 @@ +// Copyright 2017-2020 @polkadot/api-derive authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +import { ApiInterfaceRx } from '@polkadot/api/types'; +import { ActiveEraInfo, EraIndex, EraRewardPoints, RewardPoint } from '@polkadot/types/interfaces'; +import { DeriveEraPointsAll } from '../types'; + +import { Observable, combineLatest, of } from 'rxjs'; +import { map, switchMap } from 'rxjs/operators'; +import { Option, u32 } from '@polkadot/types'; + +import { memo } from '../util'; + +function getAvailableIndexes (api: ApiInterfaceRx): Observable { + return api.query.staking?.activeEra + ? api.queryMulti<[Option, u32]>([ + api.query.staking.activeEra, + api.query.staking.historyDepth + ]).pipe( + map(([activeEraOpt, historyDepth]): EraIndex[] => { + const result: EraIndex[] = []; + const max = historyDepth.toNumber(); + let lastEra = activeEraOpt.unwrapOrDefault().index.subn(1); + + while (lastEra.gten(0) && result.length < max) { + result.push(api.registry.createType('EraIndex', lastEra)); + + lastEra = lastEra.subn(1); + } + + // go from oldest to newest + return result.reverse(); + }) + ) + : of([]); +} + +export function erasPoints (api: ApiInterfaceRx): () => Observable { + return memo((): Observable => + getAvailableIndexes(api).pipe( + switchMap((indexes): Observable<[EraIndex[], EraRewardPoints[]]> => + combineLatest([ + of(indexes), + indexes.length + ? api.query.staking.erasRewardPoints.multi(indexes) + : of([]) + ]) + ), + map(([eras, rewards]): DeriveEraPointsAll[] => + eras.map((era, index): DeriveEraPointsAll => ({ + all: [...rewards[index].individual.entries()] + .filter(([, points]): boolean => points.gtn(0)) + .reduce((all: Record, [validatorId, points]): Record => { + all[validatorId.toString()] = points; + + return all; + }, {}), + era, + total: rewards[index].total + })) + ) + ) + ); +} diff --git a/packages/api-derive/src/staking/erasRewards.ts b/packages/api-derive/src/staking/erasRewards.ts new file mode 100644 index 0000000000..22a19d3b0f --- /dev/null +++ b/packages/api-derive/src/staking/erasRewards.ts @@ -0,0 +1,36 @@ +// Copyright 2017-2020 @polkadot/api-derive authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +import { ApiInterfaceRx } from '@polkadot/api/types'; +import { DeriveEraRewardsAll } from '../types'; + +import { Observable } from 'rxjs'; +import { map } from 'rxjs/operators'; + +import { memo } from '../util'; + +export function erasRewards (api: ApiInterfaceRx): () => Observable { + return memo((): Observable => + api.derive.staking.erasExposure().pipe( + map((exposures): DeriveEraRewardsAll[] => + exposures.map(({ era, all }): DeriveEraRewardsAll => + Object + .entries(all) + .reduce((rewards: DeriveEraRewardsAll, [validatorId, exposure]): DeriveEraRewardsAll => { + rewards.validators[validatorId] = exposure; + + exposure.others.forEach(({ who }, index): void => { + const nominatorId = who.toString(); + + rewards.nominators[nominatorId] = rewards.nominators[nominatorId] || []; + rewards.nominators[nominatorId].push([validatorId, index]); + }); + + return rewards; + }, { era, nominators: {}, validators: {} }) + ) + ) + ) + ); +} diff --git a/packages/api-derive/src/staking/index.ts b/packages/api-derive/src/staking/index.ts index 668cd3a721..58fb57dd7e 100644 --- a/packages/api-derive/src/staking/index.ts +++ b/packages/api-derive/src/staking/index.ts @@ -3,8 +3,13 @@ // of the Apache-2.0 license. See the LICENSE file for details. export * from './account'; +export * from './erasExposure'; +export * from './erasPoints'; +export * from './erasRewards'; export * from './controllers'; export * from './electedInfo'; export * from './overview'; export * from './query'; +export * from './stakerRewards'; export * from './validators'; +export * from './validatorPoints'; diff --git a/packages/api-derive/src/staking/stakerRewards.ts b/packages/api-derive/src/staking/stakerRewards.ts new file mode 100644 index 0000000000..32ace6fd35 --- /dev/null +++ b/packages/api-derive/src/staking/stakerRewards.ts @@ -0,0 +1,42 @@ +// Copyright 2017-2020 @polkadot/api-derive authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +import { ApiInterfaceRx } from '@polkadot/api/types'; +import { Exposure } from '@polkadot/types/interfaces'; +import { DeriveStakerReward } from '../types'; + +import { Observable } from 'rxjs'; +import { map } from 'rxjs/operators'; + +import { memo } from '../util'; + +export function stakerRewards (api: ApiInterfaceRx): (accountId: Uint8Array | string) => Observable { + return memo((accountId: Uint8Array | string): Observable => { + const stakerId = api.registry.createType('AccountId', accountId).toString(); + + return api.derive.staking.erasRewards().pipe( + map((rewards): DeriveStakerReward[] => + rewards + .map(({ era, nominators: allNominators, validators: allValidators }): DeriveStakerReward => { + const isValidator = !!allValidators[stakerId]; + const validators: Record = {}; + let nominating: [string, number][] = []; + + if (isValidator) { + validators[stakerId] = allValidators[stakerId]; + } else if (allNominators[stakerId]) { + nominating = allNominators[stakerId]; + + nominating.forEach(([validatorId]): void => { + validators[validatorId] = allValidators[validatorId]; + }); + } + + return { era, isValidator, nominating, validators }; + }) + .filter(({ validators }): boolean => Object.keys(validators).length !== 0) + ) + ); + }); +} diff --git a/packages/api-derive/src/staking/types.ts b/packages/api-derive/src/staking/types.ts new file mode 100644 index 0000000000..c5dbecd85f --- /dev/null +++ b/packages/api-derive/src/staking/types.ts @@ -0,0 +1,80 @@ +// Copyright 2017-2020 @polkadot/api-derive authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +import { AccountId, Balance, BlockNumber, EraIndex, EraRewardPoints, Exposure, Keys, RewardDestination, RewardPoint, StakingLedger, ValidatorPrefs } from '@polkadot/types/interfaces'; +import { DeriveSessionIndexes } from '../session/types'; + +export interface DeriveEraPointsAll { + all: Record; + era: EraIndex; + total: RewardPoint; +} + +export interface DeriveEraPoints { + era: EraIndex; + own: RewardPoint; + total: RewardPoint; +} + +export interface DeriveEraExposure { + all: Record; + era: EraIndex; +} + +export interface DeriveEraRewardsAll { + era: EraIndex; + nominators: Record; + validators: Record; +} + +export interface DeriveStakerReward { + era: EraIndex; + isValidator: boolean; + nominating: [string, number][]; + validators: Record; +} + +export interface DerivedStakingElected { + nextElected: AccountId[]; + info: DerivedStakingQuery[]; +} + +export interface DeriveStakingValidators { + nextElected: AccountId[]; + validators: AccountId[]; +} + +export interface DerivedStakingStash { + controllerId?: AccountId; + exposure?: Exposure; + nominators?: AccountId[]; + nominateAt?: EraIndex; + rewardDestination?: RewardDestination; + nextKeys?: Keys; + stashId?: AccountId; + validatorPrefs?: ValidatorPrefs; +} + +export interface DerivedStakingQuery extends DerivedStakingStash { + accountId: AccountId; + nextSessionIds: AccountId[]; + sessionIds: AccountId[]; + stakingLedger?: StakingLedger; +} + +export interface DerivedStakingAccount extends DerivedStakingQuery { + redeemable?: Balance; + unlocking?: DerivedUnlocking[]; +} + +export interface DerivedStakingOverview extends DeriveSessionIndexes { + eraPoints: EraRewardPoints; + nextElected: AccountId[]; + validators: AccountId[]; +} + +export type DerivedUnlocking = { + remainingBlocks: BlockNumber; + value: Balance; +}; diff --git a/packages/api-derive/src/staking/validatorPoints.ts b/packages/api-derive/src/staking/validatorPoints.ts new file mode 100644 index 0000000000..1668b9a9cb --- /dev/null +++ b/packages/api-derive/src/staking/validatorPoints.ts @@ -0,0 +1,27 @@ +// Copyright 2017-2020 @polkadot/api-derive authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +import { ApiInterfaceRx } from '@polkadot/api/types'; +import { DeriveEraPoints } from '../types'; + +import { Observable } from 'rxjs'; +import { map } from 'rxjs/operators'; + +import { memo } from '../util'; + +export function validatorPoints (api: ApiInterfaceRx): (accountId: Uint8Array | string) => Observable { + return memo((_accountId: Uint8Array | string): Observable => { + const accountId = api.registry.createType('AccountId', _accountId).toString(); + + return api.derive.staking.erasPoints().pipe( + map((all): DeriveEraPoints[] => + all.map(({ all, era, total }): DeriveEraPoints => ({ + era, + own: all[accountId] || api.registry.createType('RewardPoint'), + total + })) + ) + ); + }); +} diff --git a/packages/api-derive/src/types.ts b/packages/api-derive/src/types.ts index a84b6b2f17..3e9ffa0feb 100644 --- a/packages/api-derive/src/types.ts +++ b/packages/api-derive/src/types.ts @@ -2,10 +2,14 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { AccountId, AccountIndex, Balance, BalanceLock, BalanceLockTo212, BalanceOf, Bid, BidKind, BlockNumber, CollatorId, EraIndex, EraRewardPoints, Exposure, Hash, Index, Keys, Moment, ParaId, ParaInfo, Proposal, PropIndex, ProposalIndex, ReferendumInfo, RegistrationJudgement, RewardDestination, SessionIndex, SetIndex, SocietyVote, StakingLedger, StrikeCount, TreasuryProposal, UpwardMessage, ValidatorPrefs, Vote, Votes, VoteIndex, VouchingStatus } from '@polkadot/types/interfaces'; +import { AccountId, AccountIndex, Balance, BalanceLock, BalanceLockTo212, BalanceOf, Bid, BidKind, BlockNumber, Hash, Index, Proposal, PropIndex, ProposalIndex, ReferendumInfo, RegistrationJudgement, SetIndex, SocietyVote, StrikeCount, TreasuryProposal, Vote, Votes, VoteIndex, VouchingStatus } from '@polkadot/types/interfaces'; import BN from 'bn.js'; -import { Bytes, Option, u32, Vec } from '@polkadot/types'; +import { u32, Vec } from '@polkadot/types'; + +export * from './parachains/types'; +export * from './session/types'; +export * from './staking/types'; export type AccountIndexes = Record; @@ -108,36 +112,6 @@ export interface RecentlyOffline { count: BN; } -export interface DeriveParachainActive { - collatorId: CollatorId; - isRetriable: boolean; - retries: number; -} - -export interface DeriveParachainInfo extends ParaInfo { - id: ParaId; - icon?: string; - name?: string; - owner?: string; -} - -export interface DeriveParachain { - didUpdate: boolean; - pendingSwapId: ParaId | null; - id: ParaId; - info: DeriveParachainInfo | null; - relayDispatchQueueSize?: number; - watermark: BlockNumber | null; -} - -export interface DeriveParachainFull extends DeriveParachain { - active: DeriveParachainActive | null; - heads: Bytes | null; - relayDispatchQueue: UpwardMessage[]; - retryCollators: (CollatorId | null)[]; - selectedCollators: (CollatorId | null)[]; -} - export interface DeriveProposalPreImage { at: BlockNumber; balance: Balance; @@ -170,23 +144,6 @@ export interface DerivedReferendumVote { vote: Vote; } -export interface DeriveSessionIndexes { - activeEra: EraIndex; - activeEraStart: Option; - currentEra: EraIndex; - currentIndex: SessionIndex; - validatorCount: u32; -} - -export interface DerivedSessionInfo extends DeriveSessionIndexes { - eraLength: BlockNumber; - eraProgress: BlockNumber; - isEpoch: boolean; - sessionLength: BlockNumber; - sessionsPerEra: SessionIndex; - sessionProgress: BlockNumber; -} - export interface DeriveSociety { bids: Bid[]; defender?: AccountId; @@ -213,45 +170,6 @@ export interface DeriveSocietyMember { vouching?: VouchingStatus; } -export interface DerivedStakingElected { - nextElected: AccountId[]; - info: DerivedStakingQuery[]; -} - -export interface DeriveStakingValidators { - nextElected: AccountId[]; - validators: AccountId[]; -} - -export interface DerivedStakingStash { - controllerId?: AccountId; - exposure?: Exposure; - nominators?: AccountId[]; - nominateAt?: EraIndex; - rewardDestination?: RewardDestination; - nextKeys?: Keys; - stashId?: AccountId; - validatorPrefs?: ValidatorPrefs; -} - -export interface DerivedStakingQuery extends DerivedStakingStash { - accountId: AccountId; - nextSessionIds: AccountId[]; - sessionIds: AccountId[]; - stakingLedger?: StakingLedger; -} - -export interface DerivedStakingAccount extends DerivedStakingQuery { - redeemable?: Balance; - unlocking?: DerivedUnlocking[]; -} - -export interface DerivedStakingOverview extends DeriveSessionIndexes { - eraPoints: EraRewardPoints; - nextElected: AccountId[]; - validators: AccountId[]; -} - export interface DerivedTreasuryProposal { council: DerivedCollectiveProposal[]; id: ProposalIndex; @@ -264,11 +182,6 @@ export interface DerivedTreasuryProposals { proposals: DerivedTreasuryProposal[]; } -export type DerivedUnlocking = { - remainingBlocks: BlockNumber; - value: Balance; -}; - export interface VoterPosition { globalIndex: BN; index: BN; diff --git a/packages/api/src/checkTypes.manual.ts b/packages/api/src/checkTypes.manual.ts index be9bbe2605..ac1a26ce15 100644 --- a/packages/api/src/checkTypes.manual.ts +++ b/packages/api/src/checkTypes.manual.ts @@ -69,13 +69,20 @@ async function query (api: ApiPromise, keyring: TestKeyringMap): Promise { console.log(multiRes); + // at queries + const events = await api.query.system.events.at('0x12345'); + console.log(`Received ${events.length} events:`); + // check entries() await api.query.system.account.entries(); // should not take a param await api.query.staking.nominatorSlashInEra.entries(123); // should take a param // check range await api.query.balances.freeBalance.range(['0x1234'], keyring.bob.address); - await api.query.system.events.range(['0x12345', '0x7890']); + + // check range types + const entries = await api.query.system.events.range(['0x12345', '0x7890']); + console.log(`Received ${entries.length} entries, ${entries.map(([hash, events]) => `${hash.toHex()}: ${events.length} events`)}`); } async function rpc (api: ApiPromise): Promise { diff --git a/packages/types/src/augment/registry.ts b/packages/types/src/augment/registry.ts index d7fd13ed21..74b33cde32 100644 --- a/packages/types/src/augment/registry.ts +++ b/packages/types/src/augment/registry.ts @@ -29,7 +29,7 @@ import { ApiId, BlockHash, ChainProperties, ExtrinsicOrHash, ExtrinsicStatus, He import { AccountId, AccountIdOf, AccountIndex, Address, AssetId, Balance, BalanceOf, Block, BlockNumber, Call, ChangesTrieConfiguration, Consensus, ConsensusEngineId, Digest, DigestItem, DispatchClass, DispatchInfo, DispatchInfoTo190, Fixed64, H160, H256, H512, Hash, Header, Index, Justification, KeyTypeId, KeyValue, LockIdentifier, LookupSource, LookupTarget, Moment, Origin, Perbill, Percent, Permill, Perquintill, Phantom, PhantomData, PreRuntime, Seal, SealV0, SignedBlock, StorageData, ValidatorId, Weight, WeightMultiplier } from '@polkadot/types/interfaces/runtime'; import { FullIdentification, IdentificationTuple, Keys, SessionIndex, SessionKeys1, SessionKeys2, SessionKeys3, SessionKeys4, SessionKeys5, SessionKeys6 } from '@polkadot/types/interfaces/session'; import { Bid, BidKind, SocietyJudgement, SocietyVote, StrikeCount, VouchingStatus } from '@polkadot/types/interfaces/society'; -import { ActiveEraInfo, CompactAssignments, CompactScore, ElectionCompute, ElectionResult, ElectionStatus, EraIndex, EraPoints, EraRewardPoints, EraRewards, Exposure, Forcing, IndividualExposure, KeyType, MomentOf, Nominations, PhragmenScore, Points, RewardDestination, RewardPoint, SlashJournalEntry, SlashingSpans, SlashingSpansTo204, SpanIndex, SpanRecord, StakingLedger, StakingLedgerNew, StakingLedgerTo223, UnappliedSlash, UnappliedSlashOther, UnlockChunk, ValidatorIndex, ValidatorPrefs, ValidatorPrefsTo145, ValidatorPrefsTo196 } from '@polkadot/types/interfaces/staking'; +import { ActiveEraInfo, CompactAssignments, CompactScore, ElectionCompute, ElectionResult, ElectionStatus, EraIndex, EraPoints, EraRewardPoints, EraRewards, Exposure, Forcing, IndividualExposure, KeyType, MomentOf, Nominations, PhragmenScore, Points, RewardDestination, RewardPoint, SlashJournalEntry, SlashingSpans, SlashingSpansTo204, SpanIndex, SpanRecord, StakingLedger, StakingLedgerTo223, UnappliedSlash, UnappliedSlashOther, UnlockChunk, ValidatorIndex, ValidatorPrefs, ValidatorPrefsTo145, ValidatorPrefsTo196 } from '@polkadot/types/interfaces/staking'; import { AccountInfo, DigestOf, DispatchError, DispatchErrorModule, DispatchErrorTo198, DispatchResult, DispatchResultOf, DispatchResultTo198, Event, EventId, EventIndex, EventRecord, EventRecordTo76, Key, Phase, RefCount } from '@polkadot/types/interfaces/system'; import { OpenTip, OpenTipFinder, OpenTipTip, TreasuryProposal } from '@polkadot/types/interfaces/treasury'; import { Multiplier } from '@polkadot/types/interfaces/txpayment'; @@ -773,9 +773,6 @@ declare module '@polkadot/types/types/registry' { StakingLedgerTo223: StakingLedgerTo223; 'Option': Option; 'Vec': Vec; - StakingLedgerNew: StakingLedgerNew; - 'Option': Option; - 'Vec': Vec; StakingLedger: StakingLedger; 'Option': Option; 'Vec': Vec; diff --git a/packages/types/src/codec/AbstractInt.ts b/packages/types/src/codec/AbstractInt.ts index 5b3bab4ce5..e5adb31d05 100644 --- a/packages/types/src/codec/AbstractInt.ts +++ b/packages/types/src/codec/AbstractInt.ts @@ -103,7 +103,7 @@ export default abstract class AbstractInt extends BN implements Codec { /** * @description Returns the number of bits in the value */ - public bitLength (): UIntBitLength { + public bitLength (): number { return this.#bitLength; } diff --git a/packages/types/src/codec/Compact.ts b/packages/types/src/codec/Compact.ts index 9a35919c44..dd4e2d52c9 100644 --- a/packages/types/src/codec/Compact.ts +++ b/packages/types/src/codec/Compact.ts @@ -13,7 +13,7 @@ import { UIntBitLength } from './AbstractInt'; import Base from './Base'; export interface CompactEncodable extends Codec { - bitLength (): UIntBitLength; + bitLength (): number; toBn (): BN; toNumber (): number; } @@ -64,7 +64,7 @@ export default class Compact extends Base impleme return new Type(registry, value); } - const [, _value] = Compact.decodeU8a(value, new Type(registry, 0).bitLength()); + const [, _value] = Compact.decodeU8a(value, new Type(registry, 0).bitLength() as UIntBitLength); return new Type(registry, _value); } @@ -72,7 +72,7 @@ export default class Compact extends Base impleme /** * @description Returns the number of bits in the value */ - public bitLength (): UIntBitLength { + public bitLength (): number { return this.raw.bitLength(); } diff --git a/packages/types/src/interfaces/staking/definitions.ts b/packages/types/src/interfaces/staking/definitions.ts index 532df152f9..b24062e2e7 100644 --- a/packages/types/src/interfaces/staking/definitions.ts +++ b/packages/types/src/interfaces/staking/definitions.ts @@ -122,14 +122,13 @@ export default { unlocking: 'Vec' }, // TODO Enable as default when new staking payouts go live - StakingLedgerNew: { + StakingLedger: { stash: 'AccountId', total: 'Compact', active: 'Compact', unlocking: 'Vec', - nextReward: 'EraIndex' + lastReward: 'Option' }, - StakingLedger: 'StakingLedgerTo223', UnappliedSlashOther: '(AccountId, Balance)', UnappliedSlash: { validator: 'AccountId', diff --git a/packages/types/src/interfaces/staking/types.ts b/packages/types/src/interfaces/staking/types.ts index 371090779b..8f4c8742ec 100644 --- a/packages/types/src/interfaces/staking/types.ts +++ b/packages/types/src/interfaces/staking/types.ts @@ -160,15 +160,12 @@ export interface SpanRecord extends Struct { } /** @name StakingLedger */ -export interface StakingLedger extends StakingLedgerTo223 {} - -/** @name StakingLedgerNew */ -export interface StakingLedgerNew extends Struct { +export interface StakingLedger extends Struct { readonly stash: AccountId; readonly total: Compact; readonly active: Compact; readonly unlocking: Vec; - readonly nextReward: EraIndex; + readonly lastReward: Option; } /** @name StakingLedgerTo223 */ diff --git a/packages/types/src/known/overrides.ts b/packages/types/src/known/overrides.ts index cc26ce20df..8c85ea1f50 100644 --- a/packages/types/src/known/overrides.ts +++ b/packages/types/src/known/overrides.ts @@ -94,8 +94,7 @@ const TYPES_KUSAMA_VERSIONED: OverrideVersionedType[] = [ types: { // Indices optional, not in transaction Address: 'AccountId', - Keys: 'SessionKeys5', - StakingLedger: 'StakingLedgerTo223' + Keys: 'SessionKeys5' } } ];