Skip to content

Commit

Permalink
Adjust weight limit, always use unlimited (fix Bifrost issue) (#184)
Browse files Browse the repository at this point in the history
* always use unlimited weight limit to fix bifrost issues

* update snapshot

* add changeset
  • Loading branch information
mmaurello authored Jan 17, 2024
1 parent 4e6e0f0 commit 88b6322
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 36 deletions.
6 changes: 6 additions & 0 deletions .changeset/late-carpets-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@moonbeam-network/xcm-builder': patch
'@moonbeam-network/xcm-types': patch
---

Use unlimited weight in all transactions for the xTokens pallet
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ exports[`xTokens transfer should get correct arguments 1`] = `
"parents": 1,
},
},
1000000000,
"Unlimited",
]
`;

Expand Down Expand Up @@ -85,7 +85,7 @@ exports[`xTokens transferMultiAsset parachain should get correct arguments 1`] =
"parents": 1,
},
},
1000000000,
"Unlimited",
]
`;

Expand Down Expand Up @@ -188,7 +188,7 @@ exports[`xTokens transferMultiAsset x2 should get correct arguments 1`] = `
"parents": 1,
},
},
1000000000,
"Unlimited",
]
`;

Expand Down
14 changes: 7 additions & 7 deletions packages/builder/src/extrinsic/pallets/xTokens/xTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -23,7 +23,7 @@ export function xTokens() {
asset,
amount,
getDestination(version, address, destination),
getWeight(source.weight, func),
getWeight(),
];
},
}),
Expand Down Expand Up @@ -55,7 +55,7 @@ export function xTokens() {
},
},
getDestination(version, address, destination),
'Unlimited',
getWeight(),
];
},
}),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -124,7 +124,7 @@ export function xTokens() {
},
},
getDestination(version, address, destination),
getWeight(source.weight, func),
getWeight(),
];
},
}),
Expand All @@ -143,7 +143,7 @@ export function xTokens() {
],
1,
getDestination(XcmVersion.v3, address, destination),
'Unlimited',
getWeight(),
],
}),
}),
Expand Down
27 changes: 3 additions & 24 deletions packages/builder/src/extrinsic/pallets/xTokens/xTokens.utils.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
4 changes: 2 additions & 2 deletions packages/types/src/chain/parachain/Parachain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class Parachain extends Chain {

readonly ss58Format: number;

readonly weight: number;
readonly weight: number | undefined;

readonly ws: string;

Expand All @@ -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;
}

Expand Down

0 comments on commit 88b6322

Please sign in to comment.