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

Add Kusama and Kusama Asset Hub max xcm delivery fees #198

Merged
merged 2 commits into from
Jan 29, 2024
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
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
Loading