Skip to content

Commit

Permalink
always use unlimited weight limit to fix bifrost issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaurello committed Jan 17, 2024
1 parent 4e6e0f0 commit a0612e5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 33 deletions.
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 a0612e5

Please sign in to comment.