Skip to content

Commit

Permalink
adjustments in xcm configs and enable asset sorting in Xtokens Transf…
Browse files Browse the repository at this point in the history
…erMultiCurrencies
  • Loading branch information
mmaurello committed Dec 26, 2024
1 parent b27aa48 commit 2df4575
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 73 deletions.
45 changes: 26 additions & 19 deletions packages/builder/src/contract/contracts/Xtokens/Xtokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down
3 changes: 3 additions & 0 deletions packages/config/src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,9 @@ export const moonbeam = new EvmParachain({
ChainAsset.fromAsset(axlusdc, {
address: '0xCa01a1D0993565291051daFF390892518ACfAD3A',
decimals: 6,
ids: {
palletInstance: 110,
},
}),
ChainAsset.fromAsset(bnc, {
address: '0xFFffffFf7cC06abdF7201b350A1265c62C8601d2',
Expand Down
40 changes: 13 additions & 27 deletions packages/config/src/xcm-configs/moonbeam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
},
},
Expand Down Expand Up @@ -717,7 +698,7 @@ export const moonbeamRoutes = new ChainRoutes({
},
min: AssetMinBuilder().assets().asset(),
},
contract: ContractBuilder().Xtokens().transferMultiCurrencies(),
contract: ContractBuilder().Xtokens().transferMultiCurrencies(false),
},
{
source: {
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -1089,7 +1070,7 @@ export const moonbeamRoutes = new ChainRoutes({
chain: subsocial,
balance: BalanceBuilder().substrate().system().account(),
fee: {
amount: 0.1,
amount: 1,
asset: sub,
},
},
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
},
Expand Down
2 changes: 1 addition & 1 deletion packages/config/src/xcm-configs/pendulum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const pendulumRoutes = new ChainRoutes({
asset: glmr,
},
},
extrinsic: ExtrinsicBuilder().xTokens().transfer(),
extrinsic: ExtrinsicBuilder().xTokens().transferMultiCurrencies(),
},
],
});
27 changes: 1 addition & 26 deletions packages/config/src/xcm-configs/phala.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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(),
},
],
});

0 comments on commit 2df4575

Please sign in to comment.