From 2df457582404fe50dc1c874ca1d37820612fd8bf Mon Sep 17 00:00:00 2001 From: Mario J Maurello Date: Thu, 26 Dec 2024 15:54:56 +0100 Subject: [PATCH] adjustments in xcm configs and enable asset sorting in Xtokens TransferMultiCurrencies --- .../src/contract/contracts/Xtokens/Xtokens.ts | 45 +++++++++++-------- packages/config/src/chains.ts | 3 ++ packages/config/src/xcm-configs/moonbeam.ts | 40 ++++++----------- packages/config/src/xcm-configs/pendulum.ts | 2 +- packages/config/src/xcm-configs/phala.ts | 27 +---------- 5 files changed, 44 insertions(+), 73 deletions(-) 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/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..0c8e4384 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, }, }, @@ -717,7 +698,7 @@ export const moonbeamRoutes = new ChainRoutes({ }, min: AssetMinBuilder().assets().asset(), }, - contract: ContractBuilder().Xtokens().transferMultiCurrencies(), + contract: ContractBuilder().Xtokens().transferMultiCurrencies(false), }, { source: { @@ -1042,7 +1023,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 +1070,7 @@ export const moonbeamRoutes = new ChainRoutes({ chain: subsocial, balance: BalanceBuilder().substrate().system().account(), fee: { - amount: 0.1, + amount: 1, asset: sub, }, }, @@ -1451,17 +1432,22 @@ export const moonbeamRoutes = new ChainRoutes({ 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 +1494,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(), - }, ], });