From 7e356c4eb78cfec724e1929a589485bf47f1851a Mon Sep 17 00:00:00 2001 From: mmaurello <93129175+mmaurello@users.noreply.github.com> Date: Tue, 30 Jan 2024 03:36:08 +1300 Subject: [PATCH] Add Kusama and Kusama Asset Hub max xcm delivery fees (#198) * add manually max Xcm Delivery fees for Kusama and Kusama Asset Hub * add changeset --- .changeset/eight-parrots-cheer.md | 6 +++++ 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 +++++++++++++++++-- 5 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 .changeset/eight-parrots-cheer.md diff --git a/.changeset/eight-parrots-cheer.md b/.changeset/eight-parrots-cheer.md new file mode 100644 index 00000000..bac7e9ad --- /dev/null +++ b/.changeset/eight-parrots-cheer.md @@ -0,0 +1,6 @@ +--- +'@moonbeam-network/xcm-config': patch +'@moonbeam-network/xcm-sdk': patch +--- + +Xcm Delivery fees for Kusama and Kusama Asset Hub 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;