diff --git a/packages/builder/src/asset-min/AssetMinBuilder.ts b/packages/builder/src/asset-min/AssetMinBuilder.ts index fa2c814a..24b65552 100644 --- a/packages/builder/src/asset-min/AssetMinBuilder.ts +++ b/packages/builder/src/asset-min/AssetMinBuilder.ts @@ -3,6 +3,7 @@ import { Option } from '@polkadot/types'; import { PalletAssetsAssetDetails } from '@polkadot/types/lookup'; +import { getExtrinsicAccount } from '../extrinsic/ExtrinsicBuilder.utils'; import { SubstrateQueryConfig } from '../types/substrate/SubstrateQueryConfig'; import { AssetMinConfigBuilder } from './AssetMinBuilder.interfaces'; @@ -10,6 +11,7 @@ export function AssetMinBuilder() { return { assetRegistry, assets, + foreignAssets, }; } @@ -57,3 +59,36 @@ function assets() { }), }; } + +function foreignAssets() { + return { + asset: (): AssetMinConfigBuilder => ({ + build: ({ asset }) => { + const multilocation = { + parents: 2, + interior: { + X2: [ + { + globalconsensus: { + ethereum: { + chainId: 1, + }, + }, + }, + getExtrinsicAccount(asset as string), + ], + }, + }; + return new SubstrateQueryConfig({ + module: 'foreignAssets', + func: 'asset', + args: [multilocation], + transform: async ( + response: Option, + ): Promise => + response.unwrapOrDefault().minBalance.toBigInt(), + }); + }, + }), + }; +} diff --git a/packages/builder/src/balance/BalanceBuilder.interfaces.ts b/packages/builder/src/balance/BalanceBuilder.interfaces.ts index 5984f1cc..633ca285 100644 --- a/packages/builder/src/balance/BalanceBuilder.interfaces.ts +++ b/packages/builder/src/balance/BalanceBuilder.interfaces.ts @@ -12,7 +12,6 @@ export interface BalanceConfigBuilder { export interface BalanceConfigBuilderPrams { address: string; asset: ChainAssetId; - globalConcensusId?: ChainAssetId; } export interface PalletBalancesAccountDataOld extends Struct { diff --git a/packages/builder/src/balance/BalanceBuilder.ts b/packages/builder/src/balance/BalanceBuilder.ts index 7d2d4fc1..68bf2987 100644 --- a/packages/builder/src/balance/BalanceBuilder.ts +++ b/packages/builder/src/balance/BalanceBuilder.ts @@ -10,6 +10,7 @@ import { import { isString } from '@polkadot/util'; import { evmToAddress } from '@polkadot/util-crypto'; import { ContractConfig } from '../contract'; +import { getExtrinsicAccount } from '../extrinsic/ExtrinsicBuilder.utils'; import { SubstrateQueryConfig } from '../types/substrate/SubstrateQueryConfig'; import { BalanceConfigBuilder, @@ -76,19 +77,15 @@ function assets() { function foreignAssets() { return { account: (): BalanceConfigBuilder => ({ - build: ({ address, asset, globalConcensusId }) => { - // TODO verify + build: ({ address, asset }) => { const multilocation = { parents: 2, - interior: [ - { globalConsensus: globalConcensusId }, - { - accountKey20: { - network: null, - key: asset, - }, - }, - ], + interior: { + X2: [ + { GlobalConsensus: { ethereum: { chainId: 1 } } }, + getExtrinsicAccount(asset as string), + ], + }, }; return new SubstrateQueryConfig({ diff --git a/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.ts b/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.ts index a4146e6d..8143c980 100644 --- a/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.ts +++ b/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.ts @@ -1,5 +1,9 @@ /* eslint-disable sort-keys */ -import { ExtrinsicConfigBuilder } from '../../ExtrinsicBuilder.interfaces'; +import { + ExtrinsicConfigBuilder, + XcmVersion, +} from '../../ExtrinsicBuilder.interfaces'; +import { getExtrinsicAccount } from '../../ExtrinsicBuilder.utils'; import { ExtrinsicConfig } from '../../ExtrinsicConfig'; import { getPolkadotXcmExtrinsicArgs, @@ -213,5 +217,83 @@ export function polkadotXcm() { }), }; }, + transferAssetsUsingTypeAndThen: () => { + const func = 'transferAssetsUsingTypeAndThen'; + return { + // TODO we could pass a parameter globalConcensus in the chain asset + // but we can do it in V3 + globalConcensusEthereum: (): ExtrinsicConfigBuilder => ({ + build: ({ destination, address, amount, asset }) => { + const version = XcmVersion.v4; + return new ExtrinsicConfig({ + module: pallet, + func, + + getArgs: () => [ + { + [version]: { + parents: 1, + interior: { + X1: [ + { + Parachain: destination.parachainId, + }, + ], + }, + }, + }, + { + [version]: [ + { + id: { + parents: 2, + interior: { + X2: [ + { globalConsensus: { Ethereum: { ChainId: 1 } } }, + getExtrinsicAccount(asset as string), + ], + }, + }, + fun: { fungible: amount }, + }, + ], + }, + 'LocalReserve', + { + [version]: { + parents: 2, + interior: { + X2: [ + { globalConsensus: { Ethereum: { ChainId: 1 } } }, + getExtrinsicAccount(asset as string), + ], + }, + }, + }, + 'LocalReserve', + { + [version]: [ + { + DepositAsset: { + assets: { + Wild: { AllCounted: 1 }, + }, + beneficiary: { + parents: 0, + interior: { + X1: [getExtrinsicAccount(address)], + }, + }, + }, + }, + ], + }, + 'Unlimited', + ], + }); + }, + }), + }; + }, }; } diff --git a/packages/config/src/chains.ts b/packages/config/src/chains.ts index 8e07f152..ed9851a6 100644 --- a/packages/config/src/chains.ts +++ b/packages/config/src/chains.ts @@ -1737,17 +1737,20 @@ export const polkadotAssetHub = new Parachain({ { address: '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599', asset: wbtce, - globalConcensusId: { ethereum: { chainId: 1 } }, + decimals: 8, + id: '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599', }, { address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', asset: wethe, - globalConcensusId: { ethereum: { chainId: 1 } }, + decimals: 18, + id: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', }, { address: '0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0', asset: wstethe, - globalConcensusId: { ethereum: { chainId: 1 } }, + decimals: 18, + id: '0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0', }, ], checkSovereignAccountBalances: true, diff --git a/packages/config/src/configs/moonbeam.ts b/packages/config/src/configs/moonbeam.ts index c8d666d0..e9309092 100644 --- a/packages/config/src/configs/moonbeam.ts +++ b/packages/config/src/configs/moonbeam.ts @@ -37,8 +37,8 @@ import { vglmr, vmanta, wbtc, - wbtce, weth, + wethe, wifd, ztg, } from '../assets'; @@ -953,15 +953,19 @@ export const moonbeamConfig = new ChainConfig({ }, }), new AssetConfig({ - asset: wbtce, + asset: wethe, balance: BalanceBuilder().substrate().assets().account(), contract: ContractBuilder().Xtokens().transfer(), destination: polkadotAssetHub, destinationFee: { - amount: 0.02, // TODO - asset: usdt, // TODO + amount: 0.0000035, + asset: wethe, balance: BalanceBuilder().substrate().assets().account(), }, + fee: { + asset: glmr, + balance: BalanceBuilder().substrate().system().account(), + }, }), ], chain: moonbeam, diff --git a/packages/config/src/configs/polkadotAssetHub.ts b/packages/config/src/configs/polkadotAssetHub.ts index 29617370..7ac18783 100644 --- a/packages/config/src/configs/polkadotAssetHub.ts +++ b/packages/config/src/configs/polkadotAssetHub.ts @@ -12,7 +12,7 @@ import { stink, usdc, usdt, - wbtce, + wethe, wifd, } from '../assets'; import { moonbeam, polkadotAssetHub } from '../chains'; @@ -200,28 +200,26 @@ export const polkadotAssetHubConfig = new ChainConfig({ min: AssetMinBuilder().assets().asset(), }), new AssetConfig({ - asset: wbtce, + asset: wethe, balance: BalanceBuilder().substrate().foreignAssets().account(), destination: moonbeam, destinationFee: { amount: FeeBuilder().xcmPaymentApi().xcmPaymentFee({ isAssetReserveChain: false, - shouldTransferAssetPrecedeAsset: true, }), - asset: usdt, + asset: wethe, balance: BalanceBuilder().substrate().assets().account(), }, - // TODO extrinsic: ExtrinsicBuilder() .polkadotXcm() - .limitedReserveTransferAssets() - .X2(), + .transferAssetsUsingTypeAndThen() + .globalConcensusEthereum(), fee: { asset: dot, balance: BalanceBuilder().substrate().system().account(), xcmDeliveryFeeAmount, }, - min: AssetMinBuilder().assets().asset(), + min: AssetMinBuilder().foreignAssets().asset(), }), ], chain: polkadotAssetHub, diff --git a/packages/sdk/src/getTransferData/getTransferData.utils.ts b/packages/sdk/src/getTransferData/getTransferData.utils.ts index df9ef843..b59df1c7 100644 --- a/packages/sdk/src/getTransferData/getTransferData.utils.ts +++ b/packages/sdk/src/getTransferData/getTransferData.utils.ts @@ -46,9 +46,6 @@ export async function getBalance({ const cfg = balanceBuilder.build({ address, asset: polkadot.chain.getBalanceAssetId(asset), - // TODO temporary low effort solution because this will not be needed in V3, with the concept of ChainAsset - globalConcensusId: polkadot.chain.assetsData.get(asset.key) - ?.globalConcensusId, }); if (cfg.type === CallType.Substrate) { const balance = await polkadot.query(cfg as SubstrateQueryConfig);