From 6e543ce1adb1e81d283e1b1811d0eab6bffaad47 Mon Sep 17 00:00:00 2001 From: mmaurello <93129175+mmaurello@users.noreply.github.com> Date: Wed, 9 Oct 2024 17:58:08 +0200 Subject: [PATCH] Get sovereign account balance in destination and KSM in Kusama Asset Hub (#339) * -wip- initial commit get sovereign account balances and validate transfer amount * add variable names to alert message * consider if destination is relay or not to use corresponding sovereign account address * add destinationFee in source config return to use it in sovereign balance validation * do validation only for asset hub and remove logs * remove comment * add isRelay flag * Update packages/sdk/src/getTransferData/getTransferData.utils.ts Co-authored-by: elmar * add flag for checking sovereign account balances * update snapshots * add changeset * change back DED fee token * add KSM to AssetHub configuration * update changeset * update snaps --------- Co-authored-by: elmar --- .changeset/smooth-ghosts-judge.md | 8 + .../pallets/polkadotXcm/polkadotXcm.ts | 31 +++ packages/config/src/chains.ts | 5 + packages/config/src/configs/kusamaAssetHub.ts | 18 ++ packages/config/src/configs/moonbeam.ts | 1 + packages/config/src/configs/moonriver.ts | 15 ++ packages/config/src/types/AssetConfig.ts | 1 + .../src/getTransferData/getDestinationData.ts | 68 +++++- .../sdk/src/getTransferData/getSourceData.ts | 13 +- .../src/getTransferData/getTransferData.ts | 8 + .../getTransferData/getTransferData.utils.ts | 63 +++++- packages/sdk/src/sdk.interfaces.ts | 10 +- .../acceptance/__snapshots__/sdk.test.ts.snap | 196 +++++++++--------- .../types/src/chain/parachain/Parachain.ts | 10 + 14 files changed, 331 insertions(+), 116 deletions(-) create mode 100644 .changeset/smooth-ghosts-judge.md diff --git a/.changeset/smooth-ghosts-judge.md b/.changeset/smooth-ghosts-judge.md new file mode 100644 index 00000000..883a4fcb --- /dev/null +++ b/.changeset/smooth-ghosts-judge.md @@ -0,0 +1,8 @@ +--- +'@moonbeam-network/xcm-config': minor +'@moonbeam-network/xcm-types': minor +'@moonbeam-network/xcm-sdk': minor +'@moonbeam-network/xcm-builder': patch +--- + +Add sovereign account balance checking diff --git a/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.ts b/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.ts index 62c6ecfc..a4146e6d 100644 --- a/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.ts +++ b/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.ts @@ -182,5 +182,36 @@ export function polkadotXcm() { }), }; }, + trasferAssets: () => { + const func = 'transferAssets'; + + return { + here: (): ExtrinsicConfigBuilder => ({ + build: (params) => + new ExtrinsicConfig({ + module: pallet, + func, + getArgs: (extrinsicFunction) => + getPolkadotXcmExtrinsicArgs({ + ...params, + func: extrinsicFunction, + asset: [ + { + id: { + Concrete: { + parents: 1, + interior: 'Here', + }, + }, + fun: { + Fungible: params.amount, + }, + }, + ], + }), + }), + }), + }; + }, }; } diff --git a/packages/config/src/chains.ts b/packages/config/src/chains.ts index 625235a3..6b11b8f4 100644 --- a/packages/config/src/chains.ts +++ b/packages/config/src/chains.ts @@ -150,6 +150,7 @@ export const alphanetRelay = new Parachain({ ecosystem: Ecosystem.AlphanetRelay, genesisHash: '0xe1ea3ab1d46ba8f4898b6b4b9c54ffc05282d299f89e84bd0fd08067758c9443', + isRelay: true, isTestChain: true, key: 'alphanet-relay', name: 'Alphanet Relay', @@ -640,6 +641,7 @@ export const kusama = new Parachain({ ecosystem: Ecosystem.Kusama, genesisHash: '0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe', + isRelay: true, key: 'kusama', name: 'Kusama', parachainId: 0, @@ -669,6 +671,7 @@ export const kusamaAssetHub = new Parachain({ metadataId: 9999999, }, ], + checkSovereignAccountBalances: true, ecosystem: Ecosystem.Kusama, genesisHash: '0x48239ef607d7928874027a43a67689209727dfb3d3dc5e5b03a39bdc2eda771a', @@ -1690,6 +1693,7 @@ export const polkadot = new Parachain({ ecosystem: Ecosystem.Polkadot, genesisHash: '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3', + isRelay: true, key: 'polkadot', name: 'Polkadot', parachainId: 0, @@ -1744,6 +1748,7 @@ export const polkadotAssetHub = new Parachain({ palletInstance: 50, }, ], + checkSovereignAccountBalances: true, ecosystem: Ecosystem.Polkadot, genesisHash: '0x68d56f15f85d3136970ec16946040bc1752654e906147f7e43e9d539d7c3de2f', diff --git a/packages/config/src/configs/kusamaAssetHub.ts b/packages/config/src/configs/kusamaAssetHub.ts index c25f1468..82060d38 100644 --- a/packages/config/src/configs/kusamaAssetHub.ts +++ b/packages/config/src/configs/kusamaAssetHub.ts @@ -57,6 +57,24 @@ export const kusamaAssetHubConfig = new ChainConfig({ }, min: AssetMinBuilder().assets().asset(), }), + new AssetConfig({ + asset: ksm, + balance: BalanceBuilder().substrate().system().account(), + destination: moonriver, + destinationFee: { + amount: FeeBuilder().xcmPaymentApi().xcmPaymentFee({ + isAssetReserveChain: false, + }), + asset: ksm, + balance: BalanceBuilder().substrate().system().account(), + }, + extrinsic: ExtrinsicBuilder().polkadotXcm().trasferAssets().here(), + fee: { + asset: ksm, + balance: BalanceBuilder().substrate().system().account(), + xcmDeliveryFeeAmount, + }, + }), ], chain: kusamaAssetHub, }); diff --git a/packages/config/src/configs/moonbeam.ts b/packages/config/src/configs/moonbeam.ts index 5fa253d1..9b50f8cb 100644 --- a/packages/config/src/configs/moonbeam.ts +++ b/packages/config/src/configs/moonbeam.ts @@ -473,6 +473,7 @@ export const moonbeamConfig = new ChainConfig({ amount: 0.2, asset: usdt, balance: BalanceBuilder().substrate().assets().account(), + destinationBalance: BalanceBuilder().substrate().system().account(), }, fee: { asset: glmr, diff --git a/packages/config/src/configs/moonriver.ts b/packages/config/src/configs/moonriver.ts index 5c7658d1..754fe91b 100644 --- a/packages/config/src/configs/moonriver.ts +++ b/packages/config/src/configs/moonriver.ts @@ -282,6 +282,21 @@ export const moonriverConfig = new ChainConfig({ balance: BalanceBuilder().substrate().system().account(), }, }), + new AssetConfig({ + asset: ksm, + balance: BalanceBuilder().substrate().assets().account(), + contract: ContractBuilder().Xtokens().transfer(), + destination: kusamaAssetHub, + destinationFee: { + amount: 0.0003, + asset: ksm, + balance: BalanceBuilder().substrate().assets().account(), + }, + fee: { + asset: movr, + balance: BalanceBuilder().substrate().system().account(), + }, + }), new AssetConfig({ asset: mgx, balance: BalanceBuilder().substrate().assets().account(), diff --git a/packages/config/src/types/AssetConfig.ts b/packages/config/src/types/AssetConfig.ts index 2d6ddb29..c6207b05 100644 --- a/packages/config/src/types/AssetConfig.ts +++ b/packages/config/src/types/AssetConfig.ts @@ -20,6 +20,7 @@ export interface AssetConfigConstructorParams { export interface DestinationFeeConfig extends FeeAssetConfig { amount: number | FeeConfigBuilder; + destinationBalance?: BalanceConfigBuilder; } export interface FeeAssetConfig { diff --git a/packages/sdk/src/getTransferData/getDestinationData.ts b/packages/sdk/src/getTransferData/getDestinationData.ts index 4d8967df..8fa9d064 100644 --- a/packages/sdk/src/getTransferData/getDestinationData.ts +++ b/packages/sdk/src/getTransferData/getDestinationData.ts @@ -2,7 +2,10 @@ import { FeeConfigBuilder } from '@moonbeam-network/xcm-builder'; import { TransferConfig } from '@moonbeam-network/xcm-config'; import { AssetAmount } from '@moonbeam-network/xcm-types'; -import { toBigInt } from '@moonbeam-network/xcm-utils'; +import { + getSovereignAccountAddresses, + toBigInt, +} from '@moonbeam-network/xcm-utils'; import { PolkadotService } from '../polkadot'; import { DestinationChainTransferData } from '../sdk.interfaces'; import { getBalance, getDecimals, getMin } from './getTransferData.utils'; @@ -35,11 +38,13 @@ export async function getDestinationData({ const balance = await getBalance({ address: destinationAddress, + asset: config.asset, + balanceBuilder: config.balance, chain, - config, decimals: zeroAmount.decimals, polkadot, }); + const min = await getMin(config, polkadot); const balanceAmount = zeroAmount.copyWith({ amount: balance }); @@ -51,12 +56,20 @@ export async function getDestinationData({ polkadot, }); const minAmount = zeroAmount.copyWith({ amount: min }); + return { balance: balanceAmount, chain, existentialDeposit, fee: feeAmount, min: minAmount, + sovereignAccountBalances: chain.checkSovereignAccountBalances + ? await getSovereignAccountBalances({ + decimals: zeroAmount.decimals, + polkadot, + transferConfig, + }) + : undefined, }; } @@ -97,3 +110,54 @@ export async function getFee({ amount: await cfg.call(), }); } + +interface GetSovereignAccountBalancesProps { + transferConfig: TransferConfig; + decimals: number; + polkadot: PolkadotService; +} + +async function getSovereignAccountBalances({ + transferConfig, + decimals, + polkadot, +}: GetSovereignAccountBalancesProps) { + const { + destination: { chain, config }, + source: { config: sourceConfig }, + } = transferConfig; + const sovereignAccountAddresses = getSovereignAccountAddresses( + transferConfig.source.chain.parachainId, + ); + + const destinationFeeAssetBalance = + sourceConfig.destinationFee?.destinationBalance; + + const sovereignAccountAddress = chain.isRelay + ? sovereignAccountAddresses.relay + : sovereignAccountAddresses.generic; + + const sovereignAccountBalance = await getBalance({ + address: sovereignAccountAddress, + asset: config.asset, + balanceBuilder: config.balance, + chain, + decimals, + polkadot, + }); + + const sovereignAccountFeeAssetBalance = destinationFeeAssetBalance + ? await getBalance({ + address: sovereignAccountAddress, + asset: sourceConfig.destinationFee.asset, + balanceBuilder: destinationFeeAssetBalance, + chain, + decimals, // TODO this is not correct but will only affect us if a chain has both checkSovereignAccountBalances and usesChainDecimals flags + polkadot, + }) + : undefined; + return { + feeAssetBalance: sovereignAccountFeeAssetBalance, + transferAssetBalance: sovereignAccountBalance, + }; +} diff --git a/packages/sdk/src/getTransferData/getSourceData.ts b/packages/sdk/src/getTransferData/getSourceData.ts index d4dda6d2..1678a69d 100644 --- a/packages/sdk/src/getTransferData/getSourceData.ts +++ b/packages/sdk/src/getTransferData/getSourceData.ts @@ -31,7 +31,7 @@ import { import { PolkadotService } from '../polkadot'; import { EvmSigner, SourceChainTransferData } from '../sdk.interfaces'; import { - GetBalancesParams, + BaseParams, getBalance, getDecimals, getMin, @@ -112,8 +112,9 @@ export async function getSourceData({ const balance = await getBalance({ address: sourceAddress, + asset: config.asset, + balanceBuilder: config.balance, chain, - config, decimals: zeroAmount.decimals, polkadot, }); @@ -197,6 +198,7 @@ export async function getSourceData({ return { balance: balanceAmount, chain, + destinationFee, destinationFeeBalance: destinationFeeBalanceAmount, existentialDeposit, fee: feeAmount, @@ -206,10 +208,10 @@ export async function getSourceData({ }; } -export interface GetFeeBalanceParams - extends Omit { +export interface GetFeeBalanceParams extends BaseParams { balance: bigint; feeConfig: FeeAssetConfig | undefined; + decimals: number; } export async function getFeeBalance({ @@ -456,8 +458,9 @@ export async function getAssetsBalances({ // eslint-disable-next-line no-await-in-loop const balance = await getBalance({ address, + asset: asset.asset, + balanceBuilder: asset.balance, chain, - config: asset, decimals, polkadot, }); diff --git a/packages/sdk/src/getTransferData/getTransferData.ts b/packages/sdk/src/getTransferData/getTransferData.ts index 36c6774e..d2ded431 100644 --- a/packages/sdk/src/getTransferData/getTransferData.ts +++ b/packages/sdk/src/getTransferData/getTransferData.ts @@ -13,6 +13,7 @@ import { } from '../sdk.interfaces'; import { getDestinationData } from './getDestinationData'; import { getSourceData } from './getSourceData'; +import { validateSovereignAccountBalances } from './getTransferData.utils'; export interface GetTransferDataParams extends Partial { configService: IConfigService; @@ -60,6 +61,7 @@ export async function getTransferData({ const bigAmount = Big( toBigInt(amount, source.balance.decimals).toString(), ); + const result = bigAmount.minus( source.balance.isSame(destinationFee) ? destinationFee.toBig() : Big(0), ); @@ -93,6 +95,12 @@ export async function getTransferData({ }, async transfer(amount): Promise { const bigintAmount = toBigInt(amount, source.balance.decimals); + validateSovereignAccountBalances({ + amount: bigintAmount, + destination, + source, + }); + const { asset, source: { chain, config }, diff --git a/packages/sdk/src/getTransferData/getTransferData.utils.ts b/packages/sdk/src/getTransferData/getTransferData.utils.ts index bb0e4e12..b59df1c7 100644 --- a/packages/sdk/src/getTransferData/getTransferData.utils.ts +++ b/packages/sdk/src/getTransferData/getTransferData.utils.ts @@ -1,9 +1,10 @@ import { + BalanceConfigBuilder, CallType, ContractConfig, SubstrateQueryConfig, } from '@moonbeam-network/xcm-builder'; -import { AssetConfig } from '@moonbeam-network/xcm-config'; +import { AssetConfig, FeeAssetConfig } from '@moonbeam-network/xcm-config'; import { AnyChain, Asset, EvmParachain } from '@moonbeam-network/xcm-types'; import { convertDecimals, toBigInt } from '@moonbeam-network/xcm-utils'; import { @@ -11,30 +12,40 @@ import { createContractWithoutSigner, } from '../contract'; import { PolkadotService } from '../polkadot'; +import { + DestinationChainTransferData, + SourceChainTransferData, +} from '../sdk.interfaces'; -export interface GetBalancesParams { +export interface BaseParams { address: string; - asset?: Asset; chain: AnyChain; - config: AssetConfig; - decimals: number; polkadot: PolkadotService; } -export type GetDecimalsParams = Omit & { +export interface GetBalancesParams extends BaseParams { + asset: Asset; + balanceBuilder: BalanceConfigBuilder; + decimals: number; +} + +export interface GetDecimalsParams extends BaseParams { + asset?: Asset; + config: AssetConfig | FeeAssetConfig; assetBuiltConfig?: SubstrateQueryConfig | ContractConfig; -}; +} export async function getBalance({ address, chain, - config, + balanceBuilder, + asset, decimals, polkadot, }: GetBalancesParams) { - const cfg = config.balance.build({ + const cfg = balanceBuilder.build({ address, - asset: polkadot.chain.getBalanceAssetId(config.asset), + asset: polkadot.chain.getBalanceAssetId(asset), }); if (cfg.type === CallType.Substrate) { const balance = await polkadot.query(cfg as SubstrateQueryConfig); @@ -97,3 +108,35 @@ export async function getMin(config: AssetConfig, polkadot: PolkadotService) { return 0n; } + +interface ValidateSovereignAccountBalancesProps { + amount: bigint; + destination: DestinationChainTransferData; + source: SourceChainTransferData; +} + +export function validateSovereignAccountBalances({ + amount, + source, + destination, +}: ValidateSovereignAccountBalancesProps): void { + if ( + !destination.chain.checkSovereignAccountBalances || + !destination.sovereignAccountBalances + ) { + return; + } + const { feeAssetBalance, transferAssetBalance } = + destination.sovereignAccountBalances; + + if (amount > transferAssetBalance) { + throw new Error( + `${source.chain.name} Sovereign account in ${destination.chain.name} does not have enough balance for this transaction`, + ); + } + if (feeAssetBalance && source.destinationFee.amount > feeAssetBalance) { + throw new Error( + `${source.chain.name} Sovereign account in ${destination.chain.name} does not have enough balance to pay for fees for this transaction`, + ); + } +} diff --git a/packages/sdk/src/sdk.interfaces.ts b/packages/sdk/src/sdk.interfaces.ts index b68aea34..b2fba262 100644 --- a/packages/sdk/src/sdk.interfaces.ts +++ b/packages/sdk/src/sdk.interfaces.ts @@ -27,12 +27,20 @@ export interface TransferData { } export interface SourceChainTransferData extends ChainTransferData { + destinationFee: AssetAmount; destinationFeeBalance: AssetAmount; feeBalance: AssetAmount; max: AssetAmount; } -export interface DestinationChainTransferData extends ChainTransferData {} +export interface SovereignAccountBalance { + feeAssetBalance: bigint | undefined; + transferAssetBalance: bigint; +} + +export interface DestinationChainTransferData extends ChainTransferData { + sovereignAccountBalances?: SovereignAccountBalance; +} export interface ChainTransferData { balance: AssetAmount; diff --git a/packages/sdk/tests/acceptance/__snapshots__/sdk.test.ts.snap b/packages/sdk/tests/acceptance/__snapshots__/sdk.test.ts.snap index 9315e298..211a0b9b 100644 --- a/packages/sdk/tests/acceptance/__snapshots__/sdk.test.ts.snap +++ b/packages/sdk/tests/acceptance/__snapshots__/sdk.test.ts.snap @@ -2,7 +2,7 @@ exports[`sdk > getParachainBalances > on 'Centrifuge' for address: '4fAKSBMGVT9jt1jkuJvXgvMbmqV2BuspFWWEm…' > should get expected balances 1`] = ` [ - a { + r { "amount": 570000000000000000n, "decimals": 18, "key": "cfg", @@ -14,7 +14,7 @@ exports[`sdk > getParachainBalances > on 'Centrifuge' for address: '4fAKSBMGVT9j exports[`sdk > getParachainBalances > on 'Centrifuge' for address: '5FtGz8bgoCQ6pNAYLWCfxKx9ekLnX1ewP9q2T…' > should get expected balances 1`] = ` [ - a { + r { "amount": 570000000000000000n, "decimals": 18, "key": "cfg", @@ -26,28 +26,28 @@ exports[`sdk > getParachainBalances > on 'Centrifuge' for address: '5FtGz8bgoCQ6 exports[`sdk > getParachainBalances > on 'Hydration Alphanet' for address: '5FtGz8bgoCQ6pNAYLWCfxKx9ekLnX1ewP9q2T…' > should get expected balances 1`] = ` [ - a { + r { "amount": 178046239082538836n, "decimals": 18, "key": "ftmwh", "originSymbol": "FTM.wh", "symbol": "FTM.wh", }, - a { + r { "amount": 0n, "decimals": 6, "key": "usdcwh", "originSymbol": "USDC.Wh", "symbol": "USDC.Wh", }, - a { + r { "amount": 0n, "decimals": 18, "key": "dev", "originSymbol": "DEV", "symbol": "DEV", }, - a { + r { "amount": 3000000000000n, "decimals": 12, "key": "hdx", @@ -59,28 +59,28 @@ exports[`sdk > getParachainBalances > on 'Hydration Alphanet' for address: '5FtG exports[`sdk > getParachainBalances > on 'Hydration Alphanet' for address: '7MR8Qxy9sJmN6bfHMggAtFY5DwLxfrssLuTnP…' > should get expected balances 1`] = ` [ - a { + r { "amount": 178046239082538836n, "decimals": 18, "key": "ftmwh", "originSymbol": "FTM.wh", "symbol": "FTM.wh", }, - a { + r { "amount": 0n, "decimals": 6, "key": "usdcwh", "originSymbol": "USDC.Wh", "symbol": "USDC.Wh", }, - a { + r { "amount": 0n, "decimals": 18, "key": "dev", "originSymbol": "DEV", "symbol": "DEV", }, - a { + r { "amount": 3000000000000n, "decimals": 12, "key": "hdx", @@ -92,49 +92,49 @@ exports[`sdk > getParachainBalances > on 'Hydration Alphanet' for address: '7MR8 exports[`sdk > getParachainBalances > on 'Hydration' for address: '5FtGz8bgoCQ6pNAYLWCfxKx9ekLnX1ewP9q2T…' > should get expected balances 1`] = ` [ - a { + r { "amount": 37000000000000n, "decimals": 18, "key": "weth", "originSymbol": "WETH", "symbol": "WETH", }, - a { + r { "amount": 120n, "decimals": 8, "key": "wbtc", "originSymbol": "WBTC", "symbol": "WBTC", }, - a { + r { "amount": 0n, "decimals": 6, "key": "usdtwh", "originSymbol": "USDT.Wh", "symbol": "USDT.Wh", }, - a { + r { "amount": 0n, "decimals": 6, "key": "usdcwh", "originSymbol": "USDC.Wh", "symbol": "USDC.Wh", }, - a { + r { "amount": 0n, "decimals": 18, "key": "dai", "originSymbol": "DAI", "symbol": "DAI", }, - a { + r { "amount": 0n, "decimals": 18, "key": "glmr", "originSymbol": "GLMR", "symbol": "GLMR", }, - a { + r { "amount": 1000000000000n, "decimals": 12, "key": "hdx", @@ -146,49 +146,49 @@ exports[`sdk > getParachainBalances > on 'Hydration' for address: '5FtGz8bgoCQ6p exports[`sdk > getParachainBalances > on 'Hydration' for address: '7MR8Qxy9sJmN6bfHMggAtFY5DwLxfrssLuTnP…' > should get expected balances 1`] = ` [ - a { + r { "amount": 37000000000000n, "decimals": 18, "key": "weth", "originSymbol": "WETH", "symbol": "WETH", }, - a { + r { "amount": 120n, "decimals": 8, "key": "wbtc", "originSymbol": "WBTC", "symbol": "WBTC", }, - a { + r { "amount": 0n, "decimals": 6, "key": "usdtwh", "originSymbol": "USDT.Wh", "symbol": "USDT.Wh", }, - a { + r { "amount": 0n, "decimals": 6, "key": "usdcwh", "originSymbol": "USDC.Wh", "symbol": "USDC.Wh", }, - a { + r { "amount": 0n, "decimals": 18, "key": "dai", "originSymbol": "DAI", "symbol": "DAI", }, - a { + r { "amount": 0n, "decimals": 18, "key": "glmr", "originSymbol": "GLMR", "symbol": "GLMR", }, - a { + r { "amount": 1000000000000n, "decimals": 12, "key": "hdx", @@ -200,91 +200,91 @@ exports[`sdk > getParachainBalances > on 'Hydration' for address: '7MR8Qxy9sJmN6 exports[`sdk > getParachainBalances > on 'Moonbase Alpha' for address: '0x4E82143Af671Cc8201Bc7efCBbCED3A69e8…' > should get expected balances 1`] = ` [ - a { + r { "amount": 0n, "decimals": 18, "key": "agng", "originSymbol": "AGNG", "symbol": "AGNG", }, - a { + r { "amount": 0n, "decimals": 12, "key": "hdx", "originSymbol": "HDX", "symbol": "HDX", }, - a { + r { "amount": 1234567890000000000n, "decimals": 18, "key": "ftmwh", "originSymbol": "FTM.wh", "symbol": "FTM.wh", }, - a { + r { "amount": 10000n, "decimals": 6, "key": "usdcwh", "originSymbol": "USDC.Wh", "symbol": "USDC.Wh", }, - a { + r { "amount": 0n, "decimals": 12, "key": "unit", "originSymbol": "Unit", "symbol": "Unit", }, - a { + r { "amount": 0n, "decimals": 10, "key": "tur", "originSymbol": "TUR", "symbol": "TUR", }, - a { + r { "amount": 0n, "decimals": 18, "key": "tt1", "originSymbol": "TT1", "symbol": "TT1", }, - a { + r { "amount": 0n, "decimals": 12, "key": "pica", "originSymbol": "PICA", "symbol": "PICA", }, - a { + r { "amount": 0n, "decimals": 6, "key": "atom", "originSymbol": "ATOM", "symbol": "ATOM", }, - a { + r { "amount": 0n, "decimals": 12, "key": "otp", "originSymbol": "OTP", "symbol": "OTP", }, - a { + r { "amount": 0n, "decimals": 12, "key": "ampe", "originSymbol": "AMPE", "symbol": "AMPE", }, - a { + r { "amount": 10000000000000000n, "decimals": 18, "key": "alan", "originSymbol": "ALAN", "symbol": "ALAN", }, - a { + r { "amount": 6543210000000000000n, "decimals": 18, "key": "dev", @@ -296,14 +296,14 @@ exports[`sdk > getParachainBalances > on 'Moonbase Alpha' for address: '0x4E8214 exports[`sdk > getParachainBalances > on 'Moonbase Beta' for address: '0x4E82143Af671Cc8201Bc7efCBbCED3A69e8…' > should get expected balances 1`] = ` [ - a { + r { "amount": 1100000000000000000n, "decimals": 18, "key": "alan", "originSymbol": "ALAN", "symbol": "ALAN", }, - a { + r { "amount": 1100000000000000000n, "decimals": 18, "key": "dev", @@ -315,287 +315,287 @@ exports[`sdk > getParachainBalances > on 'Moonbase Beta' for address: '0x4E82143 exports[`sdk > getParachainBalances > on 'Moonbeam' for address: '0x4E82143Af671Cc8201Bc7efCBbCED3A69e8…' > should get expected balances 1`] = ` [ - a { + r { "amount": 0n, "decimals": 6, "key": "axlusdc", "originSymbol": "axlUSDC", "symbol": "axlUSDC", }, - a { + r { "amount": 0n, "decimals": 18, "key": "peaq", "originSymbol": "PEAQ", "symbol": "PEAQ", }, - a { + r { "amount": 0n, "decimals": 12, "key": "bncs", "originSymbol": "BNCS", "symbol": "BNCS", }, - a { + r { "amount": 0n, "decimals": 10, "key": "sub", "originSymbol": "SUB", "symbol": "SUB", }, - a { + r { "amount": 0n, "decimals": 10, "key": "ztg", "originSymbol": "ZTG", "symbol": "ZTG", }, - a { + r { "amount": 0n, "decimals": 18, "key": "fil", "originSymbol": "FIL", "symbol": "FIL", }, - a { + r { "amount": 0n, "decimals": 18, "key": "weth", "originSymbol": "WETH", "symbol": "WETH", }, - a { + r { "amount": 0n, "decimals": 8, "key": "wbtc", "originSymbol": "WBTC", "symbol": "WBTC", }, - a { + r { "amount": 0n, "decimals": 18, "key": "vmanta", "originSymbol": "vMANTA", "symbol": "vMANTA", }, - a { + r { "amount": 0n, "decimals": 18, "key": "vglmr", "originSymbol": "vGLMR", "symbol": "vGLMR", }, - a { + r { "amount": 0n, "decimals": 18, "key": "vfil", "originSymbol": "vFIL", "symbol": "vFIL", }, - a { + r { "amount": 0n, "decimals": 10, "key": "vdot", "originSymbol": "vDOT", "symbol": "vDOT", }, - a { + r { "amount": 0n, "decimals": 18, "key": "vastr", "originSymbol": "vASTR", "symbol": "vASTR", }, - a { + r { "amount": 0n, "decimals": 6, "key": "usdtwh", "originSymbol": "USDT.Wh", "symbol": "USDT.Wh", }, - a { + r { "amount": 0n, "decimals": 6, "key": "usdcwh", "originSymbol": "USDC.Wh", "symbol": "USDC.Wh", }, - a { + r { "amount": 0n, "decimals": 18, "key": "dai", "originSymbol": "DAI", "symbol": "DAI", }, - a { + r { "amount": 0n, "decimals": 12, "key": "hdx", "originSymbol": "HDX", "symbol": "HDX", }, - a { + r { "amount": 0n, "decimals": 18, "key": "apillon", "originSymbol": "NCTR", "symbol": "NCTR", }, - a { + r { "amount": 0n, "decimals": 10, "key": "wifd", "originSymbol": "WIFD", "symbol": "WIFD", }, - a { + r { "amount": 0n, "decimals": 10, "key": "stink", "originSymbol": "STINK", "symbol": "STINK", }, - a { + r { "amount": 0n, "decimals": 10, "key": "ded", "originSymbol": "DED", "symbol": "DED", }, - a { + r { "amount": 0n, "decimals": 10, "key": "pink", "originSymbol": "PINK", "symbol": "PINK", }, - a { + r { "amount": 0n, "decimals": 6, "key": "usdc", "originSymbol": "USDC", "symbol": "USDC", }, - a { + r { "amount": 0n, "decimals": 6, "key": "usdt", "originSymbol": "USDT", "symbol": "USDT", }, - a { + r { "amount": 0n, "decimals": 18, "key": "ring", "originSymbol": "RING", "symbol": "RING", }, - a { + r { "amount": 0n, "decimals": 12, "key": "pha", "originSymbol": "PHA", "symbol": "PHA", }, - a { + r { "amount": 0n, "decimals": 12, "key": "pen", "originSymbol": "PEN", "symbol": "PEN", }, - a { + r { "amount": 0n, "decimals": 12, "key": "para", "originSymbol": "PARA", "symbol": "PARA", }, - a { + r { "amount": 0n, "decimals": 12, "key": "neuro", "originSymbol": "NEURO", "symbol": "NEURO", }, - a { + r { "amount": 0n, "decimals": 11, "key": "nodl", "originSymbol": "NODL", "symbol": "NODL", }, - a { + r { "amount": 0n, "decimals": 18, "key": "manta", "originSymbol": "MANTA", "symbol": "MANTA", }, - a { + r { "amount": 0n, "decimals": 10, "key": "ldot", "originSymbol": "LDOT", "symbol": "LDOT", }, - a { + r { "amount": 0n, "decimals": 10, "key": "intr", "originSymbol": "INTR", "symbol": "INTR", }, - a { + r { "amount": 0n, "decimals": 8, "key": "ibtc", "originSymbol": "IBTC", "symbol": "IBTC", }, - a { + r { "amount": 330000000n, "decimals": 10, "key": "dot", "originSymbol": "DOT", "symbol": "DOT", }, - a { + r { "amount": 0n, "decimals": 18, "key": "cfg", "originSymbol": "CFG", "symbol": "CFG", }, - a { + r { "amount": 0n, "decimals": 12, "key": "bnc", "originSymbol": "BNC", "symbol": "BNC", }, - a { + r { "amount": 0n, "decimals": 12, "key": "aseed", "originSymbol": "aSEED", "symbol": "aSEED", }, - a { + r { "amount": 0n, "decimals": 18, "key": "astr", "originSymbol": "ASTR", "symbol": "ASTR", }, - a { + r { "amount": 0n, "decimals": 12, "key": "aca", "originSymbol": "ACA", "symbol": "ACA", }, - a { + r { "amount": 1330000000000000000n, "decimals": 18, "key": "glmr", @@ -607,21 +607,21 @@ exports[`sdk > getParachainBalances > on 'Moonbeam' for address: '0x4E82143Af671 exports[`sdk > getParachainBalances > on 'peaq Alphanet' for address: '5FtGz8bgoCQ6pNAYLWCfxKx9ekLnX1ewP9q2T…' > should get expected balances 1`] = ` [ - a { + r { "amount": 0n, "decimals": 18, "key": "ftmwh", "originSymbol": "FTM.wh", "symbol": "FTM.wh", }, - a { + r { "amount": 0n, "decimals": 18, "key": "dev", "originSymbol": "DEV", "symbol": "DEV", }, - a { + r { "amount": 1223300000000000000n, "decimals": 18, "key": "agng", @@ -633,14 +633,14 @@ exports[`sdk > getParachainBalances > on 'peaq Alphanet' for address: '5FtGz8bgo exports[`sdk > getParachainBalances > on 'peaq EVM Alphanet' for address: '0x4E82143Af671Cc8201Bc7efCBbCED3A69e8…' > should get expected balances 1`] = ` [ - a { + r { "amount": 330000000000000000n, "decimals": 18, "key": "dev", "originSymbol": "DEV", "symbol": "DEV", }, - a { + r { "amount": 123000000000000000n, "decimals": 18, "key": "ftmwh", @@ -652,42 +652,42 @@ exports[`sdk > getParachainBalances > on 'peaq EVM Alphanet' for address: '0x4E8 exports[`sdk > getParachainBalances > on 'peaq EVM' for address: '0x4E82143Af671Cc8201Bc7efCBbCED3A69e8…' > should get expected balances 1`] = ` [ - a { + r { "amount": 0n, "decimals": 6, "key": "usdtwh", "originSymbol": "USDT.Wh", "symbol": "USDT.Wh", }, - a { + r { "amount": 0n, "decimals": 18, "key": "weth", "originSymbol": "WETH", "symbol": "WETH", }, - a { + r { "amount": 0n, "decimals": 8, "key": "wbtc", "originSymbol": "WBTC", "symbol": "WBTC", }, - a { + r { "amount": 0n, "decimals": 18, "key": "dai", "originSymbol": "DAI", "symbol": "DAI", }, - a { + r { "amount": 0n, "decimals": 6, "key": "usdcwh", "originSymbol": "USDC.Wh", "symbol": "USDC.Wh", }, - a { + r { "amount": 0n, "decimals": 18, "key": "glmr", @@ -699,49 +699,49 @@ exports[`sdk > getParachainBalances > on 'peaq EVM' for address: '0x4E82143Af671 exports[`sdk > getParachainBalances > on 'peaq' for address: '5FtGz8bgoCQ6pNAYLWCfxKx9ekLnX1ewP9q2T…' > should get expected balances 1`] = ` [ - a { + r { "amount": 0n, "decimals": 6, "key": "usdtwh", "originSymbol": "USDT.Wh", "symbol": "USDT.Wh", }, - a { + r { "amount": 0n, "decimals": 18, "key": "weth", "originSymbol": "WETH", "symbol": "WETH", }, - a { + r { "amount": 0n, "decimals": 8, "key": "wbtc", "originSymbol": "WBTC", "symbol": "WBTC", }, - a { + r { "amount": 0n, "decimals": 18, "key": "dai", "originSymbol": "DAI", "symbol": "DAI", }, - a { + r { "amount": 0n, "decimals": 6, "key": "usdcwh", "originSymbol": "USDC.Wh", "symbol": "USDC.Wh", }, - a { + r { "amount": 0n, "decimals": 18, "key": "glmr", "originSymbol": "GLMR", "symbol": "GLMR", }, - a { + r { "amount": 1313000000000000000n, "decimals": 18, "key": "peaq", diff --git a/packages/types/src/chain/parachain/Parachain.ts b/packages/types/src/chain/parachain/Parachain.ts index e7e54577..fc6221fc 100644 --- a/packages/types/src/chain/parachain/Parachain.ts +++ b/packages/types/src/chain/parachain/Parachain.ts @@ -7,7 +7,9 @@ import { ChainAssetId, ChainAssetsData } from './Parachain.interfaces'; export interface ParachainConstructorParams extends SetOptional { assetsData?: Map | ChainAssetsData[]; + checkSovereignAccountBalances?: boolean; genesisHash: string; + isRelay?: boolean; parachainId: number; ss58Format: number; usesChainDecimals?: boolean; @@ -18,8 +20,12 @@ export interface ParachainConstructorParams export class Parachain extends Chain { readonly assetsData: Map; + readonly checkSovereignAccountBalances: boolean; + readonly genesisHash: string; + readonly isRelay: boolean; + readonly parachainId: number; readonly ss58Format: number; @@ -32,7 +38,9 @@ export class Parachain extends Chain { constructor({ assetsData, + checkSovereignAccountBalances, genesisHash, + isRelay, parachainId, usesChainDecimals, ss58Format, @@ -47,7 +55,9 @@ export class Parachain extends Chain { assetsData instanceof Map ? assetsData : new Map(assetsData?.map((data) => [data.asset.key, data])); + this.checkSovereignAccountBalances = !!checkSovereignAccountBalances; this.genesisHash = genesisHash; + this.isRelay = !!isRelay; this.parachainId = parachainId; this.ss58Format = ss58Format; this.usesChainDecimals = !!usesChainDecimals;