Skip to content

Commit

Permalink
Add Kusama and Kusama Asset Hub max xcm delivery fees (#198)
Browse files Browse the repository at this point in the history
* add manually max Xcm Delivery fees for Kusama and Kusama Asset Hub

* add changeset
  • Loading branch information
mmaurello authored Jan 29, 2024
1 parent ce63c3e commit 7e356c4
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/eight-parrots-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@moonbeam-network/xcm-config': patch
'@moonbeam-network/xcm-sdk': patch
---

Xcm Delivery fees for Kusama and Kusama Asset Hub
5 changes: 5 additions & 0 deletions packages/config/src/configs/kusama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions packages/config/src/configs/kusamaAssetHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const kusamaAssetHubConfig = new ChainConfig({
fee: {
asset: ksm,
balance: BalanceBuilder().substrate().system().account(),
xcmDeliveryFeeAmount: 0.00115,
},
min: AssetMinBuilder().assets().asset(),
}),
Expand All @@ -46,6 +47,7 @@ export const kusamaAssetHubConfig = new ChainConfig({
fee: {
asset: ksm,
balance: BalanceBuilder().substrate().system().account(),
xcmDeliveryFeeAmount: 0.00115,
},
min: AssetMinBuilder().assets().asset(),
}),
Expand Down
1 change: 1 addition & 0 deletions packages/config/src/types/AssetConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface DestinationFeeConfig extends FeeAssetConfig {
export interface FeeAssetConfig {
asset: Asset;
balance: BalanceConfigBuilder;
xcmDeliveryFeeAmount?: number;
}

export class AssetConfig {
Expand Down
25 changes: 23 additions & 2 deletions packages/sdk/src/getTransferData/getSourceData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -121,6 +121,7 @@ export async function getSourceData({
decimals: zeroFeeAmount.decimals,
evmSigner,
extrinsic,
feeConfig: config.fee,
polkadot,
sourceAddress,
});
Expand Down Expand Up @@ -181,6 +182,7 @@ export interface GetFeeParams {
decimals: number;
evmSigner?: EvmSigner;
extrinsic?: ExtrinsicConfig;
feeConfig?: FeeAssetConfig;
polkadot: PolkadotService;
sourceAddress: string;
}
Expand All @@ -191,6 +193,7 @@ export async function getFee({
decimals,
evmSigner,
extrinsic,
feeConfig,
polkadot,
sourceAddress,
}: GetFeeParams): Promise<bigint> {
Expand All @@ -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');
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 7e356c4

Please sign in to comment.