diff --git a/packages/builder/src/contract/contracts/Xtokens/Xtokens.ts b/packages/builder/src/contract/contracts/Xtokens/Xtokens.ts index f2285a62..5d7ec14e 100644 --- a/packages/builder/src/contract/contracts/Xtokens/Xtokens.ts +++ b/packages/builder/src/contract/contracts/Xtokens/Xtokens.ts @@ -29,33 +29,40 @@ export function Xtokens() { module: 'Xtokens', }), }), - transferMultiCurrencies: (weight = U_64_MAX): ContractConfigBuilder => ({ - build: ({ asset, destination, destinationAddress, fee }) => - new ContractConfig({ + transferMultiCurrencies: ( + shouldTransferAssetPrecedeFeeAsset = true, + weight = U_64_MAX, + ): ContractConfigBuilder => ({ + build: ({ asset, destination, destinationAddress, fee }) => { + const transferAsset = [ + asset.address + ? formatAssetIdToERC20(asset.address) + : asset.getAssetId(), + asset.amount, + ]; + + const feeAsset = [ + fee.address ? formatAssetIdToERC20(fee.address) : fee.getAssetId(), + fee.amount, + ]; + + const assets = shouldTransferAssetPrecedeFeeAsset + ? [transferAsset, feeAsset] + : [feeAsset, transferAsset]; + const feeAssetIndex = shouldTransferAssetPrecedeFeeAsset ? 1 : 0; + return new ContractConfig({ address: XTOKENS_CONTRACT_ADDRESS, abi: XTOKENS_ABI, args: [ - [ - [ - asset.address - ? formatAssetIdToERC20(asset.address) - : asset.getAssetId(), - asset.amount, - ], - [ - fee.address - ? formatAssetIdToERC20(fee.address) - : fee.getAssetId(), - fee.amount, - ], - ], - 1, // index of the fee asset + assets, + feeAssetIndex, getDestinationMultilocation(destinationAddress, destination), weight, ], func: 'transferMultiCurrencies', module: 'Xtokens', - }), + }); + }, }), transferWithEvmTo32: (weight = U_64_MAX): ContractConfigBuilder => ({ build: ({ destinationAddress, asset, destination }) => { diff --git a/packages/builder/src/extrinsic/pallets/polkadotXcm/__snapshots__/polkadotXcm.test.ts.snap b/packages/builder/src/extrinsic/pallets/polkadotXcm/__snapshots__/polkadotXcm.test.ts.snap index 7866c313..ae0648e3 100644 --- a/packages/builder/src/extrinsic/pallets/polkadotXcm/__snapshots__/polkadotXcm.test.ts.snap +++ b/packages/builder/src/extrinsic/pallets/polkadotXcm/__snapshots__/polkadotXcm.test.ts.snap @@ -455,6 +455,132 @@ exports[`polkadotXcm > limitedReserveWithdrawAssets > x2 > should get correct ar ] `; +exports[`polkadotXcm > transferAssets > X2AndFeeHere > should be correct config 1`] = ` +ExtrinsicConfig { + "func": "transferAssets", + "getArgs": [Function], + "module": "polkadotXcm", +} +`; + +exports[`polkadotXcm > transferAssets > X2AndFeeHere > should get correct arguments 1`] = ` +[ + { + "V1": { + "interior": { + "X1": { + "Parachain": 2032, + }, + }, + "parents": 1, + }, + }, + { + "V1": { + "interior": { + "X1": { + "AccountId32": { + "id": "0x18e6c7ad45fbab18778710642072fdd057470b76d4d568b44dea6accd5b0c423", + "network": null, + }, + }, + }, + "parents": 0, + }, + }, + { + "V1": [ + { + "fun": { + "Fungible": 99000000000n, + }, + "id": { + "Concrete": { + "interior": { + "X2": [ + { + "PalletInstance": 10, + }, + { + "GeneralIndex": "USDT", + }, + ], + }, + "parents": 0, + }, + }, + }, + { + "fun": { + "Fungible": 5000000000n, + }, + "id": { + "Concrete": { + "interior": "Here", + "parents": 1, + }, + }, + }, + ], + }, + 1, + "Unlimited", +] +`; + +exports[`polkadotXcm > transferAssets > here > should be correct config 1`] = ` +ExtrinsicConfig { + "func": "transferAssets", + "getArgs": [Function], + "module": "polkadotXcm", +} +`; + +exports[`polkadotXcm > transferAssets > here > should get correct arguments 1`] = ` +[ + { + "V1": { + "interior": { + "X1": { + "Parachain": 2032, + }, + }, + "parents": 1, + }, + }, + { + "V1": { + "interior": { + "X1": { + "AccountId32": { + "id": "0x18e6c7ad45fbab18778710642072fdd057470b76d4d568b44dea6accd5b0c423", + "network": null, + }, + }, + }, + "parents": 0, + }, + }, + { + "V1": [ + { + "fun": { + "Fungible": 99000000000n, + }, + "id": { + "Concrete": { + "interior": "Here", + "parents": 1, + }, + }, + }, + ], + }, + 0, + "Unlimited", +] +`; + exports[`polkadotXcm > transferAssetsUsingTypeAndThen > globalConsensusEthereum > should be correct config 1`] = ` ExtrinsicConfig { "func": "transferAssetsUsingTypeAndThen", diff --git a/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.test.ts b/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.test.ts index 54d83da8..91634d2b 100644 --- a/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.test.ts +++ b/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.test.ts @@ -119,6 +119,40 @@ describe('polkadotXcm', () => { }); }); + describe('transferAssets', () => { + describe('here', () => { + const extrinsic = polkadotXcm() + .transferAssets() + .here() + .build(buildParachainParamsMock); + + it('should be correct config', () => { + expect(extrinsic).toMatchSnapshot(); + }); + + it('should get correct arguments', () => { + expect(extrinsic.getArgs()).toMatchSnapshot(); + }); + }); + }); + + describe('transferAssets', () => { + describe('X2AndFeeHere', () => { + const extrinsic = polkadotXcm() + .transferAssets() + .X2AndFeeHere() + .build(buildParachainParamsMock); + + it('should be correct config', () => { + expect(extrinsic).toMatchSnapshot(); + }); + + it('should get correct arguments', () => { + expect(extrinsic.getArgs()).toMatchSnapshot(); + }); + }); + }); + describe('transferAssetsUsingTypeAndThen', () => { describe('globalConsensusEthereum', () => { const extrinsic = polkadotXcm() diff --git a/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.ts b/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.ts index 029f8c64..e4d54501 100644 --- a/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.ts +++ b/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.ts @@ -222,6 +222,53 @@ export function polkadotXcm() { }, }), }), + X2AndFeeHere: (): ExtrinsicConfigBuilder => ({ + build: (params) => + new ExtrinsicConfig({ + module: pallet, + func, + getArgs: (extrinsicFunction) => { + const version = getExtrinsicArgumentVersion(extrinsicFunction); + + return getPolkadotXcmExtrinsicArgs({ + ...params, + func: extrinsicFunction, + asset: [ + { + id: normalizeConcrete(version, { + parents: 0, + interior: { + X2: [ + { + PalletInstance: + params.asset.getAssetPalletInstance(), + }, + { + GeneralIndex: params.asset.getAssetId(), + }, + ], + }, + }), + fun: { + Fungible: params.asset.amount, + }, + }, + // Fee Asset + { + id: normalizeConcrete(version, { + parents: 1, + interior: 'Here', + }), + fun: { + Fungible: params.fee.amount, + }, + }, + ], + feeIndex: 1, + }); + }, + }), + }), }; }, transferAssetsUsingTypeAndThen: () => { diff --git a/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.util.ts b/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.util.ts index fa72ebf4..2f89307d 100644 --- a/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.util.ts +++ b/packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.util.ts @@ -22,8 +22,7 @@ export function getPolkadotXcmExtrinsicArgs({ func, parents = 1, feeIndex = 0, - // biome-ignore lint/suspicious/noExplicitAny: not sure how to fix this -}: GetExtrinsicParams): any[] { +}: GetExtrinsicParams) { const version = getExtrinsicArgumentVersion(func); return [ diff --git a/packages/config/src/chains.ts b/packages/config/src/chains.ts index 8f23cbba..39fe7552 100644 --- a/packages/config/src/chains.ts +++ b/packages/config/src/chains.ts @@ -1106,6 +1106,9 @@ export const moonbeam = new EvmParachain({ ChainAsset.fromAsset(axlusdc, { address: '0xCa01a1D0993565291051daFF390892518ACfAD3A', decimals: 6, + ids: { + palletInstance: 110, + }, }), ChainAsset.fromAsset(bnc, { address: '0xFFffffFf7cC06abdF7201b350A1265c62C8601d2', diff --git a/packages/config/src/xcm-configs/moonbeam.ts b/packages/config/src/xcm-configs/moonbeam.ts index 7748ee83..ea191878 100644 --- a/packages/config/src/xcm-configs/moonbeam.ts +++ b/packages/config/src/xcm-configs/moonbeam.ts @@ -189,25 +189,6 @@ export const moonbeamRoutes = new ChainRoutes({ }, contract: ContractBuilder().Xtokens().transfer(), }, - { - source: { - asset: glmr, - balance: BalanceBuilder().substrate().system().account(), - destinationFee: { - balance: BalanceBuilder().substrate().system().account(), - }, - }, - destination: { - asset: glmr, - chain: phala, - balance: BalanceBuilder().substrate().assets().account(), - fee: { - amount: 0.0002, - asset: glmr, - }, - }, - contract: ContractBuilder().Xtokens().transfer(), - }, { source: { asset: glmr, @@ -286,7 +267,7 @@ export const moonbeamRoutes = new ChainRoutes({ chain: astar, balance: BalanceBuilder().substrate().system().account(), fee: { - amount: 0.032, + amount: 0.1, asset: astr, }, }, @@ -658,13 +639,13 @@ export const moonbeamRoutes = new ChainRoutes({ chain: polkadotAssetHub, balance: BalanceBuilder().substrate().assets().account(), fee: { - amount: 0.05, - asset: usdt, - balance: BalanceBuilder().substrate().assets().account(), // TODO change when DOT pays for fees + amount: 0.01, + asset: dot, + balance: BalanceBuilder().substrate().system().account(), }, min: AssetMinBuilder().assets().asset(), }, - contract: ContractBuilder().Xtokens().transferMultiCurrencies(), + contract: ContractBuilder().Xtokens().transferMultiCurrencies(false), }, { source: { @@ -683,16 +664,13 @@ export const moonbeamRoutes = new ChainRoutes({ chain: polkadotAssetHub, balance: BalanceBuilder().substrate().assets().account(), fee: { - amount: 0.05, - asset: usdt, - balance: BalanceBuilder().substrate().assets().account(), - // TODO change when DOT pays for fees - // asset: dot, - // balance: BalanceBuilder().substrate().system().account(), + amount: 0.01, + asset: dot, + balance: BalanceBuilder().substrate().system().account(), }, min: AssetMinBuilder().assets().asset(), }, - contract: ContractBuilder().Xtokens().transferMultiCurrencies(), + contract: ContractBuilder().Xtokens().transferMultiCurrencies(false), }, { source: { @@ -711,13 +689,13 @@ export const moonbeamRoutes = new ChainRoutes({ chain: polkadotAssetHub, balance: BalanceBuilder().substrate().assets().account(), fee: { - amount: 0.05, - asset: usdt, - balance: BalanceBuilder().substrate().assets().account(), // TODO change when DOT pays for fees + amount: 0.01, + asset: dot, + balance: BalanceBuilder().substrate().system().account(), }, min: AssetMinBuilder().assets().asset(), }, - contract: ContractBuilder().Xtokens().transferMultiCurrencies(), + contract: ContractBuilder().Xtokens().transferMultiCurrencies(false), }, { source: { @@ -736,13 +714,13 @@ export const moonbeamRoutes = new ChainRoutes({ chain: polkadotAssetHub, balance: BalanceBuilder().substrate().assets().account(), fee: { - amount: 0.05, - asset: usdt, - balance: BalanceBuilder().substrate().assets().account(), // TODO change when DOT pays for fees + amount: 0.01, + asset: dot, + balance: BalanceBuilder().substrate().system().account(), }, min: AssetMinBuilder().assets().asset(), }, - contract: ContractBuilder().Xtokens().transferMultiCurrencies(), + contract: ContractBuilder().Xtokens().transferMultiCurrencies(false), }, { source: { @@ -876,7 +854,7 @@ export const moonbeamRoutes = new ChainRoutes({ chain: bifrostPolkadot, balance: BalanceBuilder().substrate().tokens().accounts(), fee: { - amount: 0.00001, + amount: 0.7, asset: vastr, }, min: AssetMinBuilder().assetRegistry().currencyMetadatas(), @@ -900,7 +878,7 @@ export const moonbeamRoutes = new ChainRoutes({ balance: BalanceBuilder().substrate().tokens().accounts(), chain: bifrostPolkadot, fee: { - amount: 0.0000001, + amount: 0.05, asset: vdot, }, min: AssetMinBuilder().assetRegistry().currencyMetadatas(), @@ -924,7 +902,7 @@ export const moonbeamRoutes = new ChainRoutes({ chain: bifrostPolkadot, balance: BalanceBuilder().substrate().tokens().accounts(), fee: { - amount: 0.00000001, + amount: 0.1, asset: vfil, }, min: AssetMinBuilder().assetRegistry().currencyMetadatas(), @@ -948,7 +926,7 @@ export const moonbeamRoutes = new ChainRoutes({ chain: bifrostPolkadot, balance: BalanceBuilder().substrate().tokens().accounts(), fee: { - amount: 0.00000001, + amount: 0.2, asset: vglmr, }, min: AssetMinBuilder().assetRegistry().currencyMetadatas(), @@ -972,7 +950,7 @@ export const moonbeamRoutes = new ChainRoutes({ chain: bifrostPolkadot, balance: BalanceBuilder().substrate().tokens().accounts(), fee: { - amount: 0.00000001, + amount: 0.05, asset: vmanta, }, min: AssetMinBuilder().assetRegistry().currencyMetadatas(), @@ -1042,7 +1020,7 @@ export const moonbeamRoutes = new ChainRoutes({ chain: bifrostPolkadot, balance: BalanceBuilder().substrate().tokens().accounts(), fee: { - amount: 0.00000001, + amount: 0.01, asset: fil, }, min: AssetMinBuilder().assetRegistry().currencyMetadatas(), @@ -1089,7 +1067,7 @@ export const moonbeamRoutes = new ChainRoutes({ chain: subsocial, balance: BalanceBuilder().substrate().system().account(), fee: { - amount: 0.1, + amount: 1, asset: sub, }, }, @@ -1439,29 +1417,34 @@ export const moonbeamRoutes = new ChainRoutes({ chain: polkadotAssetHub, balance: BalanceBuilder().substrate().assets().account(), fee: { - amount: 0.05, - asset: usdt, - balance: BalanceBuilder().substrate().assets().account(), // TODO change when DOT pays for fees + amount: 0.01, + asset: dot, + balance: BalanceBuilder().substrate().system().account(), }, min: AssetMinBuilder().assets().asset(), }, - contract: ContractBuilder().Xtokens().transferMultiCurrencies(), + contract: ContractBuilder().Xtokens().transferMultiCurrencies(false), }, { source: { asset: axlusdc, balance: BalanceBuilder().evm().erc20(), - destinationFee: { + fee: { + asset: glmr, balance: BalanceBuilder().substrate().system().account(), }, + destinationFee: { + balance: BalanceBuilder().evm().erc20(), + }, }, destination: { asset: axlusdc, chain: pendulum, balance: BalanceBuilder().substrate().tokens().accounts(), fee: { - amount: 0.04, - asset: glmr, + amount: 0.02, + asset: axlusdc, + balance: BalanceBuilder().substrate().tokens().accounts(), }, }, contract: ContractBuilder().Xtokens().transfer(), @@ -1508,7 +1491,7 @@ export const moonbeamRoutes = new ChainRoutes({ chain: polkadotAssetHub, balance: BalanceBuilder().substrate().foreignAssets().account(), fee: { - amount: 0.0000035, + amount: 0.00001, asset: wethe, balance: BalanceBuilder().substrate().foreignAssets().account(), }, diff --git a/packages/config/src/xcm-configs/pendulum.ts b/packages/config/src/xcm-configs/pendulum.ts index 19f91395..0423070c 100644 --- a/packages/config/src/xcm-configs/pendulum.ts +++ b/packages/config/src/xcm-configs/pendulum.ts @@ -79,7 +79,7 @@ export const pendulumRoutes = new ChainRoutes({ asset: glmr, }, }, - extrinsic: ExtrinsicBuilder().xTokens().transfer(), + extrinsic: ExtrinsicBuilder().xTokens().transferMultiCurrencies(), }, ], }); diff --git a/packages/config/src/xcm-configs/phala.ts b/packages/config/src/xcm-configs/phala.ts index a477630d..536963c8 100644 --- a/packages/config/src/xcm-configs/phala.ts +++ b/packages/config/src/xcm-configs/phala.ts @@ -3,7 +3,7 @@ import { ExtrinsicBuilder, FeeBuilder, } from '@moonbeam-network/xcm-builder'; -import { glmr, pha } from '../assets'; +import { pha } from '../assets'; import { moonbeam, phala } from '../chains'; import { ChainRoutes } from '../types/ChainRoutes'; @@ -31,30 +31,5 @@ export const phalaRoutes = new ChainRoutes({ }, extrinsic: ExtrinsicBuilder().xTransfer().transfer().here(), }, - { - source: { - asset: glmr, - balance: BalanceBuilder().substrate().assets().account(), - fee: { - asset: pha, - balance: BalanceBuilder().substrate().system().account(), - }, - destinationFee: { - balance: BalanceBuilder().substrate().assets().account(), - }, - }, - destination: { - asset: glmr, - chain: moonbeam, - balance: BalanceBuilder().substrate().system().account(), - fee: { - amount: FeeBuilder() - .xcmPaymentApi() - .xcmPaymentFee({ isAssetReserveChain: true }), - asset: glmr, - }, - }, - extrinsic: ExtrinsicBuilder().xTransfer().transfer().X2(), - }, ], }); diff --git a/packages/config/src/xcm-configs/polkadotAssetHub.ts b/packages/config/src/xcm-configs/polkadotAssetHub.ts index 4f539e6f..03526162 100644 --- a/packages/config/src/xcm-configs/polkadotAssetHub.ts +++ b/packages/config/src/xcm-configs/polkadotAssetHub.ts @@ -132,15 +132,14 @@ export const polkadotAssetHubRoutes = new ChainRoutes({ fee: { amount: FeeBuilder().xcmPaymentApi().xcmPaymentFee({ isAssetReserveChain: false, - shouldTransferAssetPrecedeFeeAsset: true, }), - asset: usdt, + asset: dot, }, }, extrinsic: ExtrinsicBuilder() .polkadotXcm() - .limitedReserveTransferAssets() - .X2(), + .transferAssets() + .X2AndFeeHere(), }, { source: { @@ -163,15 +162,14 @@ export const polkadotAssetHubRoutes = new ChainRoutes({ fee: { amount: FeeBuilder().xcmPaymentApi().xcmPaymentFee({ isAssetReserveChain: false, - shouldTransferAssetPrecedeFeeAsset: true, }), - asset: usdt, + asset: dot, }, }, extrinsic: ExtrinsicBuilder() .polkadotXcm() - .limitedReserveTransferAssets() - .X2(), + .transferAssets() + .X2AndFeeHere(), }, { source: { @@ -195,13 +193,13 @@ export const polkadotAssetHubRoutes = new ChainRoutes({ amount: FeeBuilder() .xcmPaymentApi() .xcmPaymentFee({ isAssetReserveChain: false }), - asset: usdt, + asset: dot, }, }, extrinsic: ExtrinsicBuilder() .polkadotXcm() - .limitedReserveTransferAssets() - .X2(), + .transferAssets() + .X2AndFeeHere(), }, { source: { @@ -224,15 +222,14 @@ export const polkadotAssetHubRoutes = new ChainRoutes({ fee: { amount: FeeBuilder().xcmPaymentApi().xcmPaymentFee({ isAssetReserveChain: false, - shouldTransferAssetPrecedeFeeAsset: true, }), - asset: usdt, + asset: dot, }, }, extrinsic: ExtrinsicBuilder() .polkadotXcm() - .limitedReserveTransferAssets() - .X2(), + .transferAssets() + .X2AndFeeHere(), }, { source: { @@ -255,15 +252,14 @@ export const polkadotAssetHubRoutes = new ChainRoutes({ fee: { amount: FeeBuilder().xcmPaymentApi().xcmPaymentFee({ isAssetReserveChain: false, - shouldTransferAssetPrecedeFeeAsset: true, }), - asset: usdt, + asset: dot, }, }, extrinsic: ExtrinsicBuilder() .polkadotXcm() - .limitedReserveTransferAssets() - .X2(), + .transferAssets() + .X2AndFeeHere(), }, { source: { diff --git a/packages/sdk/tests/acceptance/__snapshots__/sdk.test.ts.snap b/packages/sdk/tests/acceptance/__snapshots__/sdk.test.ts.snap index 3aa1409f..abf68d5e 100644 --- a/packages/sdk/tests/acceptance/__snapshots__/sdk.test.ts.snap +++ b/packages/sdk/tests/acceptance/__snapshots__/sdk.test.ts.snap @@ -554,7 +554,9 @@ exports[`sdk > getParachainBalances > on 'Moonbeam' for address: '0x4E82143Af671 "address": "0xCa01a1D0993565291051daFF390892518ACfAD3A", "amount": 0n, "decimals": 6, - "ids": undefined, + "ids": { + "palletInstance": 110, + }, "key": "axlusdc", "min": undefined, "originSymbol": "axlUSDC",