From 9b1153f029d420ddcf8091049cd148213a91cb64 Mon Sep 17 00:00:00 2001 From: Mario J Maurello Date: Tue, 30 Jan 2024 03:11:00 +1300 Subject: [PATCH] add manually max Xcm Delivery fees for Kusama and Kusama Asset Hub --- packages/config/src/configs/kusama.ts | 5 ++++ packages/config/src/configs/kusamaAssetHub.ts | 2 ++ packages/config/src/types/AssetConfig.ts | 1 + .../sdk/src/getTransferData/getSourceData.ts | 25 +++++++++++++++++-- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/packages/config/src/configs/kusama.ts b/packages/config/src/configs/kusama.ts index 00b7dd24..9f8f6dc2 100644 --- a/packages/config/src/configs/kusama.ts +++ b/packages/config/src/configs/kusama.ts @@ -23,6 +23,11 @@ export const kusamaConfig = new ChainConfig({ .xcmPallet() .limitedReserveTransferAssets(0) .here(), + fee: { + asset: ksm, + balance: BalanceBuilder().substrate().system().account(), + xcmDeliveryFeeAmount: 0.0015, + }, }), ], chain: kusama, diff --git a/packages/config/src/configs/kusamaAssetHub.ts b/packages/config/src/configs/kusamaAssetHub.ts index f7c9ea99..e0ff6a0f 100644 --- a/packages/config/src/configs/kusamaAssetHub.ts +++ b/packages/config/src/configs/kusamaAssetHub.ts @@ -27,6 +27,7 @@ export const kusamaAssetHubConfig = new ChainConfig({ fee: { asset: ksm, balance: BalanceBuilder().substrate().system().account(), + xcmDeliveryFeeAmount: 0.00115, }, min: AssetMinBuilder().assets().asset(), }), @@ -46,6 +47,7 @@ export const kusamaAssetHubConfig = new ChainConfig({ fee: { asset: ksm, balance: BalanceBuilder().substrate().system().account(), + xcmDeliveryFeeAmount: 0.00115, }, min: AssetMinBuilder().assets().asset(), }), diff --git a/packages/config/src/types/AssetConfig.ts b/packages/config/src/types/AssetConfig.ts index ed4e1cf8..2d6ddb29 100644 --- a/packages/config/src/types/AssetConfig.ts +++ b/packages/config/src/types/AssetConfig.ts @@ -25,6 +25,7 @@ export interface DestinationFeeConfig extends FeeAssetConfig { export interface FeeAssetConfig { asset: Asset; balance: BalanceConfigBuilder; + xcmDeliveryFeeAmount?: number; } export class AssetConfig { diff --git a/packages/sdk/src/getTransferData/getSourceData.ts b/packages/sdk/src/getTransferData/getSourceData.ts index 7abb32ff..c5b2ff6b 100644 --- a/packages/sdk/src/getTransferData/getSourceData.ts +++ b/packages/sdk/src/getTransferData/getSourceData.ts @@ -6,7 +6,7 @@ import { } from '@moonbeam-network/xcm-builder'; import { FeeAssetConfig, TransferConfig } from '@moonbeam-network/xcm-config'; import { AssetAmount } from '@moonbeam-network/xcm-types'; -import { convertDecimals } from '@moonbeam-network/xcm-utils'; +import { convertDecimals, toBigInt } from '@moonbeam-network/xcm-utils'; import Big from 'big.js'; import { TransferContractInterface, createContract } from '../contract'; import { PolkadotService } from '../polkadot'; @@ -121,6 +121,7 @@ export async function getSourceData({ decimals: zeroFeeAmount.decimals, evmSigner, extrinsic, + feeConfig: config.fee, polkadot, sourceAddress, }); @@ -181,6 +182,7 @@ export interface GetFeeParams { decimals: number; evmSigner?: EvmSigner; extrinsic?: ExtrinsicConfig; + feeConfig?: FeeAssetConfig; polkadot: PolkadotService; sourceAddress: string; } @@ -191,6 +193,7 @@ export async function getFee({ decimals, evmSigner, extrinsic, + feeConfig, polkadot, sourceAddress, }: GetFeeParams): Promise { @@ -203,7 +206,16 @@ export async function getFee({ } if (extrinsic) { - return getExtrinsicFee(balance, extrinsic, polkadot, sourceAddress); + const extrinsicFee = await getExtrinsicFee( + balance, + extrinsic, + polkadot, + sourceAddress, + ); + + const xcmDeliveryFee = getXcmDeliveryFee(decimals, feeConfig); + + return extrinsicFee + xcmDeliveryFee; } throw new Error('Either contract or extrinsic must be provided'); @@ -246,6 +258,15 @@ export async function getExtrinsicFee( } } +function getXcmDeliveryFee( + decimals: number, + feeConfig?: FeeAssetConfig, +): bigint { + return feeConfig?.xcmDeliveryFeeAmount + ? toBigInt(feeConfig.xcmDeliveryFeeAmount, decimals) + : 0n; +} + export interface GetMaxParams { balanceAmount: AssetAmount; existentialDeposit: AssetAmount;