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
This commit is contained in:
@@ -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<Uint8Array & Codec>` 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(<typeName>)`, 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
|
||||
|
||||
|
||||
@@ -18,3 +18,33 @@ export type RelayDispatchQueue = Vec<UpwardMessage>
|
||||
export type RelayDispatchQueueSize = ITuple<[u32, u32]>;
|
||||
export type Watermarks = Option<BlockNumber>;
|
||||
export type DidUpdate = Option<Vec<ParaId>>;
|
||||
|
||||
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)[];
|
||||
}
|
||||
|
||||
@@ -44,28 +44,32 @@ function queryNoActive (api: ApiInterfaceRx): Observable<Result> {
|
||||
|
||||
// query based on latest
|
||||
function query (api: ApiInterfaceRx): Observable<Result> {
|
||||
return api.queryMulti<[ActiveEraInfo, Option<EraIndex>, SessionIndex, u32]>([
|
||||
return api.queryMulti<[Option<ActiveEraInfo>, Option<EraIndex>, 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<Result> {
|
||||
return of([
|
||||
createType(api.registry, 'EraIndex', 1),
|
||||
createType(api.registry, 'EraIndex'),
|
||||
createType(api.registry, 'Option<Moment>'),
|
||||
createType(api.registry, 'EraIndex', 1),
|
||||
createType(api.registry, 'EraIndex'),
|
||||
createType(api.registry, 'SessionIndex', 1),
|
||||
createType(api.registry, 'u32')
|
||||
]);
|
||||
|
||||
@@ -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<Moment>;
|
||||
currentEra: EraIndex;
|
||||
currentIndex: SessionIndex;
|
||||
validatorCount: u32;
|
||||
}
|
||||
|
||||
export interface DerivedSessionInfo extends DeriveSessionIndexes {
|
||||
eraLength: BlockNumber;
|
||||
eraProgress: BlockNumber;
|
||||
isEpoch: boolean;
|
||||
sessionLength: BlockNumber;
|
||||
sessionsPerEra: SessionIndex;
|
||||
sessionProgress: BlockNumber;
|
||||
}
|
||||
@@ -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<Exposure>(indexes)
|
||||
: of([] as Exposure[])
|
||||
]);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export function erasExposure (api: ApiInterfaceRx): () => Observable<DeriveEraExposure[]> {
|
||||
return memo((): Observable<DeriveEraExposure[]> =>
|
||||
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;
|
||||
}, [])
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -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<EraIndex[]> {
|
||||
return api.query.staking?.activeEra
|
||||
? api.queryMulti<[Option<ActiveEraInfo>, 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<DeriveEraPointsAll[]> {
|
||||
return memo((): Observable<DeriveEraPointsAll[]> =>
|
||||
getAvailableIndexes(api).pipe(
|
||||
switchMap((indexes): Observable<[EraIndex[], EraRewardPoints[]]> =>
|
||||
combineLatest([
|
||||
of(indexes),
|
||||
indexes.length
|
||||
? api.query.staking.erasRewardPoints.multi<EraRewardPoints>(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<string, RewardPoint>, [validatorId, points]): Record<string, RewardPoint> => {
|
||||
all[validatorId.toString()] = points;
|
||||
|
||||
return all;
|
||||
}, {}),
|
||||
era,
|
||||
total: rewards[index].total
|
||||
}))
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -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<DeriveEraRewardsAll[]> {
|
||||
return memo((): Observable<DeriveEraRewardsAll[]> =>
|
||||
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: {} })
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -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';
|
||||
|
||||
@@ -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<DeriveStakerReward[]> {
|
||||
return memo((accountId: Uint8Array | string): Observable<DeriveStakerReward[]> => {
|
||||
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<string, Exposure> = {};
|
||||
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)
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -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<string, RewardPoint>;
|
||||
era: EraIndex;
|
||||
total: RewardPoint;
|
||||
}
|
||||
|
||||
export interface DeriveEraPoints {
|
||||
era: EraIndex;
|
||||
own: RewardPoint;
|
||||
total: RewardPoint;
|
||||
}
|
||||
|
||||
export interface DeriveEraExposure {
|
||||
all: Record<string, Exposure>;
|
||||
era: EraIndex;
|
||||
}
|
||||
|
||||
export interface DeriveEraRewardsAll {
|
||||
era: EraIndex;
|
||||
nominators: Record<string, [string, number][]>;
|
||||
validators: Record<string, Exposure>;
|
||||
}
|
||||
|
||||
export interface DeriveStakerReward {
|
||||
era: EraIndex;
|
||||
isValidator: boolean;
|
||||
nominating: [string, number][];
|
||||
validators: Record<string, Exposure>;
|
||||
}
|
||||
|
||||
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;
|
||||
};
|
||||
@@ -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<DeriveEraPoints[]> {
|
||||
return memo((_accountId: Uint8Array | string): Observable<DeriveEraPoints[]> => {
|
||||
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
|
||||
}))
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -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<string, AccountIndex>;
|
||||
|
||||
@@ -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<Moment>;
|
||||
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;
|
||||
|
||||
@@ -69,13 +69,20 @@ async function query (api: ApiPromise, keyring: TestKeyringMap): Promise<void> {
|
||||
|
||||
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<Balance>(['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<void> {
|
||||
|
||||
@@ -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<StakingLedgerTo223>': Option<StakingLedgerTo223>;
|
||||
'Vec<StakingLedgerTo223>': Vec<StakingLedgerTo223>;
|
||||
StakingLedgerNew: StakingLedgerNew;
|
||||
'Option<StakingLedgerNew>': Option<StakingLedgerNew>;
|
||||
'Vec<StakingLedgerNew>': Vec<StakingLedgerNew>;
|
||||
StakingLedger: StakingLedger;
|
||||
'Option<StakingLedger>': Option<StakingLedger>;
|
||||
'Vec<StakingLedger>': Vec<StakingLedger>;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<T extends CompactEncodable> extends Base<T> 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<T extends CompactEncodable> extends Base<T> impleme
|
||||
/**
|
||||
* @description Returns the number of bits in the value
|
||||
*/
|
||||
public bitLength (): UIntBitLength {
|
||||
public bitLength (): number {
|
||||
return this.raw.bitLength();
|
||||
}
|
||||
|
||||
|
||||
@@ -122,14 +122,13 @@ export default {
|
||||
unlocking: 'Vec<UnlockChunk>'
|
||||
},
|
||||
// TODO Enable as default when new staking payouts go live
|
||||
StakingLedgerNew: {
|
||||
StakingLedger: {
|
||||
stash: 'AccountId',
|
||||
total: 'Compact<Balance>',
|
||||
active: 'Compact<Balance>',
|
||||
unlocking: 'Vec<UnlockChunk>',
|
||||
nextReward: 'EraIndex'
|
||||
lastReward: 'Option<EraIndex>'
|
||||
},
|
||||
StakingLedger: 'StakingLedgerTo223',
|
||||
UnappliedSlashOther: '(AccountId, Balance)',
|
||||
UnappliedSlash: {
|
||||
validator: 'AccountId',
|
||||
|
||||
@@ -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<Balance>;
|
||||
readonly active: Compact<Balance>;
|
||||
readonly unlocking: Vec<UnlockChunk>;
|
||||
readonly nextReward: EraIndex;
|
||||
readonly lastReward: Option<EraIndex>;
|
||||
}
|
||||
|
||||
/** @name StakingLedgerTo223 */
|
||||
|
||||
@@ -94,8 +94,7 @@ const TYPES_KUSAMA_VERSIONED: OverrideVersionedType[] = [
|
||||
types: {
|
||||
// Indices optional, not in transaction
|
||||
Address: 'AccountId',
|
||||
Keys: 'SessionKeys5',
|
||||
StakingLedger: 'StakingLedgerTo223'
|
||||
Keys: 'SessionKeys5'
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user