From 88b6322327b30baa0fb2bf55f99497e2944c95ef Mon Sep 17 00:00:00 2001 From: mmaurello <93129175+mmaurello@users.noreply.github.com> Date: Wed, 17 Jan 2024 21:34:49 +1300 Subject: [PATCH] Adjust weight limit, always use unlimited (fix Bifrost issue) (#184) * always use unlimited weight limit to fix bifrost issues * update snapshot * add changeset --- .changeset/late-carpets-suffer.md | 6 +++++ .../__snapshots__/xTokens.test.ts.snap | 6 ++--- .../src/extrinsic/pallets/xTokens/xTokens.ts | 14 +++++----- .../pallets/xTokens/xTokens.utils.ts | 27 +++---------------- .../types/src/chain/parachain/Parachain.ts | 4 +-- 5 files changed, 21 insertions(+), 36 deletions(-) create mode 100644 .changeset/late-carpets-suffer.md diff --git a/.changeset/late-carpets-suffer.md b/.changeset/late-carpets-suffer.md new file mode 100644 index 00000000..584c223b --- /dev/null +++ b/.changeset/late-carpets-suffer.md @@ -0,0 +1,6 @@ +--- +'@moonbeam-network/xcm-builder': patch +'@moonbeam-network/xcm-types': patch +--- + +Use unlimited weight in all transactions for the xTokens pallet diff --git a/packages/builder/src/extrinsic/pallets/xTokens/__snapshots__/xTokens.test.ts.snap b/packages/builder/src/extrinsic/pallets/xTokens/__snapshots__/xTokens.test.ts.snap index e388f1bd..00588e79 100644 --- a/packages/builder/src/extrinsic/pallets/xTokens/__snapshots__/xTokens.test.ts.snap +++ b/packages/builder/src/extrinsic/pallets/xTokens/__snapshots__/xTokens.test.ts.snap @@ -30,7 +30,7 @@ exports[`xTokens transfer should get correct arguments 1`] = ` "parents": 1, }, }, - 1000000000, + "Unlimited", ] `; @@ -85,7 +85,7 @@ exports[`xTokens transferMultiAsset parachain should get correct arguments 1`] = "parents": 1, }, }, - 1000000000, + "Unlimited", ] `; @@ -188,7 +188,7 @@ exports[`xTokens transferMultiAsset x2 should get correct arguments 1`] = ` "parents": 1, }, }, - 1000000000, + "Unlimited", ] `; diff --git a/packages/builder/src/extrinsic/pallets/xTokens/xTokens.ts b/packages/builder/src/extrinsic/pallets/xTokens/xTokens.ts index 5a55f22a..b05ec066 100644 --- a/packages/builder/src/extrinsic/pallets/xTokens/xTokens.ts +++ b/packages/builder/src/extrinsic/pallets/xTokens/xTokens.ts @@ -12,7 +12,7 @@ const pallet = 'xTokens'; export function xTokens() { return { transfer: (): ExtrinsicConfigBuilder => ({ - build: ({ address, amount, asset, destination, source }) => + build: ({ address, amount, asset, destination }) => new ExtrinsicConfig({ module: pallet, func: 'transfer', @@ -23,7 +23,7 @@ export function xTokens() { asset, amount, getDestination(version, address, destination), - getWeight(source.weight, func), + getWeight(), ]; }, }), @@ -55,7 +55,7 @@ export function xTokens() { }, }, getDestination(version, address, destination), - 'Unlimited', + getWeight(), ]; }, }), @@ -87,13 +87,13 @@ export function xTokens() { }, }, getDestination(version, address, destination), - 'Unlimited', + getWeight(), ]; }, }), }), X2: (): ExtrinsicConfigBuilder => ({ - build: ({ address, amount, asset, destination, source }) => + build: ({ address, amount, asset, destination }) => new ExtrinsicConfig({ module: pallet, func: funcName, @@ -124,7 +124,7 @@ export function xTokens() { }, }, getDestination(version, address, destination), - getWeight(source.weight, func), + getWeight(), ]; }, }), @@ -143,7 +143,7 @@ export function xTokens() { ], 1, getDestination(XcmVersion.v3, address, destination), - 'Unlimited', + getWeight(), ], }), }), diff --git a/packages/builder/src/extrinsic/pallets/xTokens/xTokens.utils.ts b/packages/builder/src/extrinsic/pallets/xTokens/xTokens.utils.ts index 2b44f740..1a6518af 100644 --- a/packages/builder/src/extrinsic/pallets/xTokens/xTokens.utils.ts +++ b/packages/builder/src/extrinsic/pallets/xTokens/xTokens.utils.ts @@ -1,34 +1,13 @@ import { AnyChain } from '@moonbeam-network/xcm-types'; -import { SubmittableExtrinsicFunction } from '@polkadot/api/types'; import { XcmVersion } from '../../ExtrinsicBuilder.interfaces'; import { getExtrinsicAccount } from '../../ExtrinsicBuilder.utils'; import { XTokensWeightLimit } from './xTokens.interfaces'; /** - * Workaround for weight parameter type change in xTokens pallet - * https://github.com/open-web3-stack/open-runtime-module-library/pull/841 + * It is safer to always use unlimited */ -export function getWeight( - weight: number, - func?: SubmittableExtrinsicFunction<'promise'>, -): XTokensWeightLimit { - const type = func?.meta.args.at(-1)?.type; - - if (!type) { - return weight; - } - - if (type.eq('XcmV2WeightLimit')) { - return { - Limited: weight, - }; - } - - if (type.eq('XcmV3WeightLimit')) { - return 'Unlimited'; - } - - return weight; +export function getWeight(): XTokensWeightLimit { + return 'Unlimited'; } export function getDestination( diff --git a/packages/types/src/chain/parachain/Parachain.ts b/packages/types/src/chain/parachain/Parachain.ts index b7f57950..03cb14ae 100644 --- a/packages/types/src/chain/parachain/Parachain.ts +++ b/packages/types/src/chain/parachain/Parachain.ts @@ -23,7 +23,7 @@ export class Parachain extends Chain { readonly ss58Format: number; - readonly weight: number; + readonly weight: number | undefined; readonly ws: string; @@ -46,7 +46,7 @@ export class Parachain extends Chain { this.genesisHash = genesisHash; this.parachainId = parachainId; this.ss58Format = ss58Format; - this.weight = weight ?? 1_000_000_000; + this.weight = weight; this.ws = ws; }