Skip to content

Commit

Permalink
add function to determine feeAsset position repsecting asset
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaurello committed Jun 21, 2024
1 parent ad1b2e1 commit 55db736
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
24 changes: 18 additions & 6 deletions packages/builder/src/extrinsic/pallets/polkadotXcm/polkadotXcm.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/* eslint-disable sort-keys */
import { ExtrinsicConfigBuilder } from '../../ExtrinsicBuilder.interfaces';
import { ExtrinsicConfig } from '../../ExtrinsicConfig';
import { getPolkadotXcmExtrinsicArgs } from './polkadotXcm.util';
import {
getPolkadotXcmExtrinsicArgs,
shouldFeeAssetPrecedeAsset,
} from './polkadotXcm.util';

const pallet = 'polkadotXcm';

Expand Down Expand Up @@ -73,7 +76,7 @@ export function polkadotXcm() {
getArgs: (extrinsicFunction) => {
const isAssetDifferent =
!!params.feeAsset && params.asset !== params.feeAsset;
const asset = [
const assets = [
{
id: {
Concrete: {
Expand All @@ -96,8 +99,11 @@ export function polkadotXcm() {
},
];

const shouldFeeAssetPrecede =
shouldFeeAssetPrecedeAsset(params);

if (isAssetDifferent) {
asset.push({
const feeAsset = {
id: {
Concrete: {
parents: 0,
Expand All @@ -116,14 +122,20 @@ export function polkadotXcm() {
fun: {
Fungible: params.fee,
},
});
};

if (shouldFeeAssetPrecede) {
assets.unshift(feeAsset);
} else {
assets.push(feeAsset);
}
}

return getPolkadotXcmExtrinsicArgs({
...params,
func: extrinsicFunction,
asset,
feeIndex: isAssetDifferent ? 1 : 0,
asset: assets,
feeIndex: isAssetDifferent && !shouldFeeAssetPrecede ? 1 : 0,
});
},
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,17 @@ export function getPolkadotXcmExtrinsicArgs({
'Unlimited',
];
}

export function shouldFeeAssetPrecedeAsset({
asset,
feeAsset,
}: ExtrinsicConfigBuilderPrams): boolean {
const assetIdNumber = Number(asset);
const feeAssetIdNumber = Number(feeAsset);

if (Number.isNaN(assetIdNumber) || Number.isNaN(feeAssetIdNumber)) {
return false;
}

return assetIdNumber > feeAssetIdNumber;
}
2 changes: 1 addition & 1 deletion packages/config/src/configs/moonbeam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ export const moonbeamConfig = new ChainConfig({
contract: ContractBuilder().Xtokens().transferMultiCurrencies(),
destination: polkadotAssetHub,
destinationFee: {
amount: 0.7, // TODO
amount: 0.2,
asset: usdt,
balance: BalanceBuilder().substrate().assets().account(),
},
Expand Down
2 changes: 1 addition & 1 deletion packages/config/src/configs/polkadotAssetHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const polkadotAssetHubConfig = new ChainConfig({
balance: BalanceBuilder().substrate().assets().account(),
destination: moonbeam,
destinationFee: {
amount: 0.03, // TODO
amount: 0.03,
asset: usdt,
balance: BalanceBuilder().substrate().assets().account(),
},
Expand Down

0 comments on commit 55db736

Please sign in to comment.