Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(internal): cleanup structure for args passed into calls #328

Merged
merged 3 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 34 additions & 139 deletions src/AssetTransferApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,24 +271,31 @@ export class AssetTransferApi {
});
}
}

await checkXcmTxInputs(
_api,
destChainId,
const baseArgs = {
api: _api,
direction: xcmDirection as XcmDirection,
destAddr: addr,
assetIds,
amounts,
xcmDirection,
xcmPallet,
_specName,
registry,
isForeignAssetsTransfer,
destChainId,
xcmVersion: declaredXcmVersion,
specName: _specName,
registry: this.registry,
};

const baseOpts = {
isLimited,
weightLimit,
paysWithFeeDest,
isLiquidTokenTransfer,
isPrimaryParachainNativeAsset,
isForeignAssetsTransfer,
};

await checkXcmTxInputs(
{ ...baseArgs, xcmPallet },
{
xcmVersion: declaredXcmVersion,
paysWithFeeDest,
isLimited,
weightLimit,
...baseOpts,
isPrimaryParachainNativeAsset,
}
);

Expand All @@ -315,147 +322,35 @@ export class AssetTransferApi {
// This ensures paraToRelay always uses `transferMultiAsset`.
if (xcmDirection === Direction.ParaToRelay || (!paysWithFeeDest && assetIds.length < 2)) {
txMethod = 'transferMultiasset';
transaction = await transferMultiasset(
_api,
xcmDirection,
addr,
assetIds,
amounts,
destChainId,
declaredXcmVersion,
_specName,
this.registry,
xcmPallet,
{
isLimited,
weightLimit,
paysWithFeeDest,
isForeignAssetsTransfer,
isLiquidTokenTransfer,
}
);
transaction = await transferMultiasset({ ...baseArgs, xcmPallet }, baseOpts);
} else if (paysWithFeeDest && paysWithFeeDest.includes('parents')) {
txMethod = 'transferMultiassetWithFee';
transaction = await transferMultiassetWithFee(
_api,
xcmDirection,
addr,
assetIds,
amounts,
destChainId,
declaredXcmVersion,
_specName,
this.registry,
xcmPallet,
{
isLimited,
weightLimit,
paysWithFeeDest,
isForeignAssetsTransfer,
isLiquidTokenTransfer,
}
);
transaction = await transferMultiassetWithFee({ ...baseArgs, xcmPallet }, baseOpts);
} else {
txMethod = 'transferMultiassets';
transaction = await transferMultiassets(
_api,
xcmDirection,
addr,
assetIds,
amounts,
destChainId,
declaredXcmVersion,
_specName,
this.registry,
xcmPallet,
{
isLimited,
weightLimit,
paysWithFeeDest,
isForeignAssetsTransfer,
isLiquidTokenTransfer,
}
);
transaction = await transferMultiassets({ ...baseArgs, xcmPallet }, baseOpts);
}
} else if (assetCallType === AssetCallType.Reserve) {
if (isLimited) {
txMethod = 'limitedReserveTransferAssets';
transaction = await limitedReserveTransferAssets(
_api,
xcmDirection as XcmDirection,
addr,
assetIds,
amounts,
destChainId,
declaredXcmVersion,
_specName,
this.registry,
{
isLimited,
weightLimit,
paysWithFeeDest,
isLiquidTokenTransfer,
isForeignAssetsTransfer,
}
);
transaction = await limitedReserveTransferAssets(baseArgs, baseOpts);
} else {
txMethod = 'reserveTransferAssets';
transaction = await reserveTransferAssets(
_api,
xcmDirection as XcmDirection,
addr,
assetIds,
amounts,
destChainId,
declaredXcmVersion,
_specName,
this.registry,
{
paysWithFeeDest,
isLiquidTokenTransfer,
isForeignAssetsTransfer,
}
);
transaction = await reserveTransferAssets(baseArgs, baseOpts);
}
} else {
if (isLimited) {
txMethod = 'limitedTeleportAssets';
transaction = await limitedTeleportAssets(
_api,
xcmDirection as XcmDirection,
addr,
assetIds,
amounts,
destChainId,
declaredXcmVersion,
_specName,
this.registry,
{
isLimited,
weightLimit,
paysWithFeeDest,
isForeignAssetsTransfer,
isLiquidTokenTransfer: false,
}
);
transaction = await limitedTeleportAssets(baseArgs, {
...baseOpts,
isLiquidTokenTransfer: false,
});
} else {
txMethod = 'teleportAssets';
transaction = await teleportAssets(
_api,
xcmDirection as XcmDirection,
addr,
assetIds,
amounts,
destChainId,
declaredXcmVersion,
_specName,
this.registry,
{
paysWithFeeDest,
isForeignAssetsTransfer,
isLiquidTokenTransfer: false,
}
);
transaction = await teleportAssets(baseArgs, {
...baseOpts,
isLiquidTokenTransfer: false,
});
}
}

Expand Down
Loading