Skip to content

Commit

Permalink
V3 xcm adjustments (#412)
Browse files Browse the repository at this point in the history
* adjustments in xcm configs and enable asset sorting in Xtokens TransferMultiCurrencies

* adjust bifrost token fees

* update snapshot

* add DOT as feeAsset in config for Moonbeam to AssetHub (#413)

* add DOT as feeAsset in config for Moonbeam to AssetHub

* change polkadot asset hub configs to use DOT for fees and write builder for new function
  • Loading branch information
mmaurello authored Jan 2, 2025
1 parent b760223 commit 5a3fd59
Show file tree
Hide file tree
Showing 11 changed files with 294 additions and 122 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
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
47 changes: 47 additions & 0 deletions packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
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
Loading

0 comments on commit 5a3fd59

Please sign in to comment.