diff --git a/packages/api-derive/src/balances/account.ts b/packages/api-derive/src/balances/account.ts index 766968d6ee..7f72d99162 100644 --- a/packages/api-derive/src/balances/account.ts +++ b/packages/api-derive/src/balances/account.ts @@ -17,6 +17,12 @@ type BalanceResult = [Balance, Balance, Balance, Balance]; type Result = [Index, BalanceResult[]]; +type DeriveCustomAccount = ApiInterfaceRx['derive'] & { + [custom: string]: { + customAccount?: ApiInterfaceRx['query']['balances']['account'] + } +} + function getBalance (api: ApiInterfaceRx, [freeBalance, reservedBalance, frozenFee, frozenMisc]: BalanceResult): DeriveBalancesAccountData { return { freeBalance, @@ -54,14 +60,10 @@ function queryBalancesFree (api: ApiInterfaceRx, accountId: AccountId): Observab ); } -type DeriveCustomAccount = ApiInterfaceRx['derive'] & { [custom: string]: { - customAccount?: ApiInterfaceRx['query']['balances']['account'] -} } - function queryBalancesAccount (api: ApiInterfaceRx, accountId: AccountId, modules: string[] = ['balances']): Observable { const balances = modules.map( (m): QueryableStorageMultiArg<'rxjs'> => [ - (api.derive as DeriveCustomAccount)[m]?.customAccount ?? api.query[m].account, + (api.derive as DeriveCustomAccount)[m]?.customAccount || api.query[m].account, accountId ] ); @@ -85,9 +87,11 @@ function queryCurrent (api: ApiInterfaceRx, accountId: AccountId): Observable index !== 0).map((l, index) => calcShared(api, bestNumber, data.additional[index], l)), isVesting, vestedBalance, - vestedClaimable, - vestingEndBlock, + vestedClaimable: api.registry.createType('Balance', isVesting ? shared.vestingLocked.sub(vestingTotal.sub(vestedBalance)) : 0), + vestingEndBlock: api.registry.createType('BlockNumber', isVesting ? vestingTotal.div(perBlock).add(startingBlock) : 0), vestingPerBlock: perBlock, vestingTotal }; @@ -114,15 +117,11 @@ function queryOld (api: ApiInterfaceRx, accountId: AccountId): Observable(nullable: T): nullable is NonNullable => !!nullable; -type DeriveCustomLocks = ApiInterfaceRx['derive'] & { [custom: string]: { - customLocks?: ApiInterfaceRx['query']['balances']['locks'] -} } - // current (balances, vesting) function queryCurrent (api: ApiInterfaceRx, accountId: AccountId, balanceInstances: string[] = ['balances']): Observable { const lockCalls = balanceInstances.map( (m): ApiInterfaceRx['query']['balances']['locks'] | undefined => - (api.derive as DeriveCustomLocks)[m]?.customLocks ?? api.query[m as 'balances']?.locks + (api.derive as DeriveCustomLocks)[m]?.customLocks || api.query[m as 'balances']?.locks ); const lockEmpty = lockCalls.map((c) => !c); diff --git a/packages/types-known/src/spec/kusama.ts b/packages/types-known/src/spec/kusama.ts index 01d36243f4..2227cba0dc 100644 --- a/packages/types-known/src/spec/kusama.ts +++ b/packages/types-known/src/spec/kusama.ts @@ -47,7 +47,6 @@ const versioned: OverrideVersionedType[] = [ OpenTip: 'OpenTipTo225', RefCount: 'RefCountTo259', ReferendumInfo: 'ReferendumInfoTo239', - RewardDestination: 'RewardDestinationTo257', SlashingSpans: 'SlashingSpansTo204', StakingLedger: 'StakingLedgerTo223', Votes: 'VotesTo230', @@ -66,7 +65,6 @@ const versioned: OverrideVersionedType[] = [ OpenTip: 'OpenTipTo225', RefCount: 'RefCountTo259', ReferendumInfo: 'ReferendumInfoTo239', - RewardDestination: 'RewardDestinationTo257', SlashingSpans: 'SlashingSpansTo204', StakingLedger: 'StakingLedgerTo223', Votes: 'VotesTo230', @@ -86,7 +84,6 @@ const versioned: OverrideVersionedType[] = [ OpenTip: 'OpenTipTo225', RefCount: 'RefCountTo259', ReferendumInfo: 'ReferendumInfoTo239', - RewardDestination: 'RewardDestinationTo257', StakingLedger: 'StakingLedgerTo223', Votes: 'VotesTo230', Weight: 'u32' @@ -104,7 +101,6 @@ const versioned: OverrideVersionedType[] = [ OpenTip: 'OpenTipTo225', RefCount: 'RefCountTo259', ReferendumInfo: 'ReferendumInfoTo239', - RewardDestination: 'RewardDestinationTo257', StakingLedger: 'StakingLedgerTo240', Weight: 'u32' } @@ -119,7 +115,6 @@ const versioned: OverrideVersionedType[] = [ Multiplier: 'Fixed64', OpenTip: 'OpenTipTo225', RefCount: 'RefCountTo259', - RewardDestination: 'RewardDestinationTo257', StakingLedger: 'StakingLedgerTo240', Weight: 'u32' } @@ -132,8 +127,7 @@ const versioned: OverrideVersionedType[] = [ CompactAssignments: 'CompactAssignmentsTo257', DispatchInfo: 'DispatchInfoTo244', OpenTip: 'OpenTipTo225', - RefCount: 'RefCountTo259', - RewardDestination: 'RewardDestinationTo257' + RefCount: 'RefCountTo259' } }, { @@ -143,8 +137,7 @@ const versioned: OverrideVersionedType[] = [ ...addrAccountIdTypes, CompactAssignments: 'CompactAssignmentsTo257', OpenTip: 'OpenTipTo225', - RefCount: 'RefCountTo259', - RewardDestination: 'RewardDestinationTo257' + RefCount: 'RefCountTo259' } }, { @@ -153,8 +146,7 @@ const versioned: OverrideVersionedType[] = [ ...sharedTypes, ...addrAccountIdTypes, CompactAssignments: 'CompactAssignmentsTo257', - RefCount: 'RefCountTo259', - RewardDestination: 'RewardDestinationTo257' + RefCount: 'RefCountTo259' } }, { diff --git a/packages/types-known/src/spec/polkadot.ts b/packages/types-known/src/spec/polkadot.ts index 792b43e4c7..9460b91af9 100644 --- a/packages/types-known/src/spec/polkadot.ts +++ b/packages/types-known/src/spec/polkadot.ts @@ -41,8 +41,7 @@ const versioned: OverrideVersionedType[] = [ ...addrAccountIdTypes, CompactAssignments: 'CompactAssignmentsTo257', OpenTip: 'OpenTipTo225', - RefCount: 'RefCountTo259', - RewardDestination: 'RewardDestinationTo257' + RefCount: 'RefCountTo259' } }, { @@ -51,8 +50,7 @@ const versioned: OverrideVersionedType[] = [ ...sharedTypes, ...addrAccountIdTypes, CompactAssignments: 'CompactAssignmentsTo257', - RefCount: 'RefCountTo259', - RewardDestination: 'RewardDestinationTo257' + RefCount: 'RefCountTo259' } }, { diff --git a/packages/types-known/src/spec/westend.ts b/packages/types-known/src/spec/westend.ts index 2caa29b226..24d5f4ba8b 100644 --- a/packages/types-known/src/spec/westend.ts +++ b/packages/types-known/src/spec/westend.ts @@ -35,7 +35,6 @@ const versioned: OverrideVersionedType[] = [ Multiplier: 'Fixed64', OpenTip: 'OpenTipTo225', RefCount: 'RefCountTo259', - RewardDestination: 'RewardDestinationTo257', Weight: 'u32' } }, @@ -46,8 +45,7 @@ const versioned: OverrideVersionedType[] = [ ...addrAccountIdTypes, CompactAssignments: 'CompactAssignmentsTo257', OpenTip: 'OpenTipTo225', - RefCount: 'RefCountTo259', - RewardDestination: 'RewardDestinationTo257' + RefCount: 'RefCountTo259' } }, { @@ -56,8 +54,7 @@ const versioned: OverrideVersionedType[] = [ ...sharedTypes, ...addrAccountIdTypes, CompactAssignments: 'CompactAssignmentsTo257', - RefCount: 'RefCountTo259', - RewardDestination: 'RewardDestinationTo257' + RefCount: 'RefCountTo259' } }, { diff --git a/packages/types/src/augment/registry.ts b/packages/types/src/augment/registry.ts index 2d28a0fbc0..9ffe650642 100644 --- a/packages/types/src/augment/registry.ts +++ b/packages/types/src/augment/registry.ts @@ -44,7 +44,7 @@ import type { SiField, SiLookupTypeId, SiPath, SiType, SiTypeDef, SiTypeDefArray import type { Period, Priority, SchedulePeriod, SchedulePriority, Scheduled, ScheduledTo254, TaskAddress } from '@polkadot/types/interfaces/scheduler'; import type { FullIdentification, IdentificationTuple, Keys, MembershipProof, SessionIndex, SessionKeys1, SessionKeys2, SessionKeys3, SessionKeys4, SessionKeys5, SessionKeys6, SessionKeys7, SessionKeys8, SessionKeys9, ValidatorCount } from '@polkadot/types/interfaces/session'; import type { Bid, BidKind, SocietyJudgement, SocietyVote, StrikeCount, VouchingStatus } from '@polkadot/types/interfaces/society'; -import type { ActiveEraInfo, CompactAssignments, CompactAssignmentsTo257, CompactScore, CompactScoreCompact, ElectionCompute, ElectionResult, ElectionScore, ElectionSize, ElectionStatus, EraIndex, EraPoints, EraRewardPoints, EraRewards, Exposure, ExtendedBalance, Forcing, IndividualExposure, KeyType, MomentOf, Nominations, NominatorIndex, NominatorIndexCompact, OffchainAccuracy, OffchainAccuracyCompact, PhragmenScore, Points, RawSolution, ReadySolution, RewardDestination, RewardDestinationTo257, RewardPoint, RoundSnapshot, SeatHolder, SlashJournalEntry, SlashingSpans, SlashingSpansTo204, SolutionOrSnapshotSize, SolutionSupport, SolutionSupports, SpanIndex, SpanRecord, StakingLedger, StakingLedgerTo223, StakingLedgerTo240, UnappliedSlash, UnappliedSlashOther, UnlockChunk, ValidatorIndex, ValidatorIndexCompact, ValidatorPrefs, ValidatorPrefsTo145, ValidatorPrefsTo196, ValidatorPrefsWithBlocked, ValidatorPrefsWithCommission, VoteWeight, Voter } from '@polkadot/types/interfaces/staking'; +import type { ActiveEraInfo, CompactAssignments, CompactAssignmentsTo257, CompactScore, CompactScoreCompact, ElectionCompute, ElectionResult, ElectionScore, ElectionSize, ElectionStatus, EraIndex, EraPoints, EraRewardPoints, EraRewards, Exposure, ExtendedBalance, Forcing, IndividualExposure, KeyType, MomentOf, Nominations, NominatorIndex, NominatorIndexCompact, OffchainAccuracy, OffchainAccuracyCompact, PhragmenScore, Points, RawSolution, ReadySolution, RewardDestination, RewardPoint, RoundSnapshot, SeatHolder, SlashJournalEntry, SlashingSpans, SlashingSpansTo204, SolutionOrSnapshotSize, SolutionSupport, SolutionSupports, SpanIndex, SpanRecord, StakingLedger, StakingLedgerTo223, StakingLedgerTo240, UnappliedSlash, UnappliedSlashOther, UnlockChunk, ValidatorIndex, ValidatorIndexCompact, ValidatorPrefs, ValidatorPrefsTo145, ValidatorPrefsTo196, ValidatorPrefsWithBlocked, ValidatorPrefsWithCommission, VoteWeight, Voter } from '@polkadot/types/interfaces/staking'; import type { ApiId, KeyValueOption, ReadProof, RuntimeVersion, RuntimeVersionApi, StorageChangeSet } from '@polkadot/types/interfaces/state'; import type { WeightToFeeCoefficient } from '@polkadot/types/interfaces/support'; import type { AccountInfo, AccountInfoWithProviders, AccountInfoWithRefCount, ApplyExtrinsicResult, BlockLength, BlockWeights, ChainProperties, ChainType, ConsumedWeight, DigestOf, DispatchClass, DispatchError, DispatchErrorModule, DispatchErrorTo198, DispatchInfo, DispatchInfoTo190, DispatchInfoTo244, DispatchOutcome, DispatchResult, DispatchResultOf, DispatchResultTo198, Event, EventId, EventIndex, EventRecord, Health, InvalidTransaction, Key, LastRuntimeUpgradeInfo, NetworkState, NetworkStatePeerset, NetworkStatePeersetInfo, NodeRole, NotConnectedPeer, Peer, PeerEndpoint, PeerEndpointAddr, PeerInfo, PeerPing, PerDispatchClassU32, PerDispatchClassWeight, PerDispatchClassWeightsPerClass, Phase, RawOrigin, RefCount, RefCountTo259, SyncState, SystemOrigin, TransactionValidityError, UnknownTransaction, WeightPerClass } from '@polkadot/types/interfaces/system'; @@ -687,7 +687,6 @@ declare module '@polkadot/types/types/registry' { 'Option': Option; 'Option': Option; 'Option': Option; - 'Option': Option; 'Option': Option; 'Option': Option; 'Option': Option; @@ -1431,7 +1430,6 @@ declare module '@polkadot/types/types/registry' { 'Vec': Vec; 'Vec': Vec; 'Vec': Vec; - 'Vec': Vec; 'Vec': Vec; 'Vec': Vec; 'Vec': Vec; @@ -2175,7 +2173,6 @@ declare module '@polkadot/types/types/registry' { ReserveAssetDeposit: ReserveAssetDeposit; Retriable: Retriable; RewardDestination: RewardDestination; - RewardDestinationTo257: RewardDestinationTo257; RewardPoint: RewardPoint; RoundSnapshot: RoundSnapshot; RoundState: RoundState; diff --git a/packages/types/src/interfaces/staking/definitions.ts b/packages/types/src/interfaces/staking/definitions.ts index 946141c776..7c5800134f 100644 --- a/packages/types/src/interfaces/staking/definitions.ts +++ b/packages/types/src/interfaces/staking/definitions.ts @@ -166,13 +166,6 @@ export default { Account: 'AccountId' } }, - RewardDestinationTo257: { - _enum: [ - 'Staked', - 'Stash', - 'Controller' - ] - }, RewardPoint: 'u32', SlashJournalEntry: { who: 'AccountId', diff --git a/packages/types/src/interfaces/staking/types.ts b/packages/types/src/interfaces/staking/types.ts index f74d18dfc8..1559414aed 100644 --- a/packages/types/src/interfaces/staking/types.ts +++ b/packages/types/src/interfaces/staking/types.ts @@ -187,13 +187,6 @@ export interface RewardDestination extends Enum { readonly asAccount: AccountId; } -/** @name RewardDestinationTo257 */ -export interface RewardDestinationTo257 extends Enum { - readonly isStaked: boolean; - readonly isStash: boolean; - readonly isController: boolean; -} - /** @name RewardPoint */ export interface RewardPoint extends u32 {}