override balance derive api for mangata nodes with tokens pallet call (#9263)
* override balance derive api for mangata nodes with tokens pallet call * add derives for balance support on mangata
This commit is contained in:
parent
46ac37c00b
commit
7b7f23efd2
@ -31,7 +31,6 @@
|
||||
"@kiltprotocol/type-definitions": "0.32.0",
|
||||
"@laminar/type-definitions": "0.3.1",
|
||||
"@logion/node-api": "0.9.0-3",
|
||||
"@mangata-finance/types": "0.18.0",
|
||||
"@metaverse-network-sdk/type-definitions": "0.0.1-16",
|
||||
"@parallel-finance/type-definitions": "1.7.16",
|
||||
"@phala/typedefs": "0.2.33",
|
||||
|
||||
@ -6,13 +6,15 @@ import type { OverrideBundleDefinition, OverrideBundleType } from '@polkadot/typ
|
||||
import equilibrium from './spec/equilibrium.js';
|
||||
import genshiro from './spec/genshiro.js';
|
||||
import interbtc from './spec/interbtc.js';
|
||||
import mangata from './spec/mangata.js';
|
||||
import subspace from './spec/subspace.js';
|
||||
|
||||
const mapping: [OverrideBundleDefinition, string[]][] = [
|
||||
[equilibrium, ['Equilibrium']],
|
||||
[genshiro, ['Genshiro', 'Genshiro Rococo Testnet']],
|
||||
[interbtc, ['interbtc-parachain', 'interbtc-standalone', 'interlay-parachain', 'kintsugi-parachain', 'testnet-kintsugi', 'testnet-interlay']],
|
||||
[subspace, ['subspace']]
|
||||
[subspace, ['subspace']],
|
||||
[mangata, ['mangata', 'mangata-parachain']]
|
||||
];
|
||||
|
||||
export function applyDerives (typesBundle: OverrideBundleType): OverrideBundleType {
|
||||
|
||||
@ -1,6 +1,95 @@
|
||||
// Copyright 2017-2023 @polkadot/apps-config authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { typesBundleForPolkadotApps } from '@mangata-finance/types';
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { OverrideBundleDefinition } from '@polkadot/types/types';
|
||||
|
||||
export default typesBundleForPolkadotApps;
|
||||
import { combineLatest, map } from 'rxjs';
|
||||
|
||||
import { DeriveBalancesAll } from '@polkadot/api-derive/types';
|
||||
import { memo } from '@polkadot/api-derive/util';
|
||||
import { TypeRegistry, U128 } from '@polkadot/types';
|
||||
import { Balance } from '@polkadot/types/interfaces';
|
||||
import { FrameSystemAccountInfo } from '@polkadot/types/lookup';
|
||||
import { BN } from '@polkadot/util';
|
||||
|
||||
function balanceOf (number: number | string): U128 {
|
||||
return new U128(new TypeRegistry(), number);
|
||||
}
|
||||
|
||||
function defaultAccountBalance (): DeriveBalancesAll {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return {
|
||||
accountNonce: new BN(1),
|
||||
additional: [],
|
||||
availableBalance: balanceOf(0),
|
||||
freeBalance: balanceOf(0),
|
||||
lockedBalance: balanceOf(0),
|
||||
lockedBreakdown: [],
|
||||
namedReserves: [],
|
||||
reservedBalance: balanceOf(0),
|
||||
vestingLocked: balanceOf(0)
|
||||
} as any;
|
||||
}
|
||||
|
||||
interface OrmlAccountData {
|
||||
free: Balance,
|
||||
reserved: Balance,
|
||||
frozen: Balance,
|
||||
}
|
||||
|
||||
export function getBalance (
|
||||
instanceId: string,
|
||||
api: ApiInterfaceRx
|
||||
): () => Observable<DeriveBalancesAll> {
|
||||
return memo(
|
||||
instanceId,
|
||||
(account: string): Observable<DeriveBalancesAll> =>
|
||||
combineLatest<[any, any]>([api.query.tokens.accounts(account, 0), api.query.system.account(account)]).pipe(
|
||||
map(([data, systemAccount]: [OrmlAccountData, FrameSystemAccountInfo]): DeriveBalancesAll => {
|
||||
return {
|
||||
...defaultAccountBalance(),
|
||||
accountId: api.registry.createType('AccountId', account),
|
||||
accountNonce: systemAccount.nonce,
|
||||
availableBalance: api.registry.createType('Balance', data.free.sub(data.frozen)),
|
||||
freeBalance: data.free,
|
||||
lockedBalance: data.frozen,
|
||||
reservedBalance: data.reserved
|
||||
};
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
const definitions: OverrideBundleDefinition = {
|
||||
derives: {
|
||||
balances: {
|
||||
account: getBalance,
|
||||
all: getBalance
|
||||
}
|
||||
},
|
||||
types: [
|
||||
{
|
||||
// on all versions
|
||||
minmax: [0, undefined],
|
||||
types: {
|
||||
Header: {
|
||||
count: 'BlockNumber',
|
||||
digest: 'Digest',
|
||||
extrinsicsRoot: 'Hash',
|
||||
number: 'Compact<BlockNumber>',
|
||||
parentHash: 'Hash',
|
||||
seed: 'ShufflingSeed',
|
||||
stateRoot: 'Hash'
|
||||
},
|
||||
ShufflingSeed: {
|
||||
proof: 'H512',
|
||||
seed: 'H256'
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
export default definitions;
|
||||
|
||||
@ -990,13 +990,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@mangata-finance/types@npm:0.18.0":
|
||||
version: 0.18.0
|
||||
resolution: "@mangata-finance/types@npm:0.18.0"
|
||||
checksum: 0dda1490321971bb9e75faaa7f2ec41eb640864607c2d3b7b560d888b634aa68d1a66e1f65afcd82651e77f417d1af3177d0c7fdb4898554930f83bb5cae86f4
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@metamask/detect-provider@npm:^1.2.0":
|
||||
version: 1.2.0
|
||||
resolution: "@metamask/detect-provider@npm:1.2.0"
|
||||
@ -1702,7 +1695,6 @@ __metadata:
|
||||
"@kiltprotocol/type-definitions": 0.32.0
|
||||
"@laminar/type-definitions": 0.3.1
|
||||
"@logion/node-api": 0.9.0-3
|
||||
"@mangata-finance/types": 0.18.0
|
||||
"@metaverse-network-sdk/type-definitions": 0.0.1-16
|
||||
"@parallel-finance/type-definitions": 1.7.16
|
||||
"@phala/typedefs": 0.2.33
|
||||
|
||||
Loading…
Reference in New Issue
Block a user