6
6
} from '@moonbeam-network/xcm-builder' ;
7
7
import { FeeAssetConfig , TransferConfig } from '@moonbeam-network/xcm-config' ;
8
8
import { AssetAmount } from '@moonbeam-network/xcm-types' ;
9
- import { convertDecimals } from '@moonbeam-network/xcm-utils' ;
9
+ import { convertDecimals , toBigInt } from '@moonbeam-network/xcm-utils' ;
10
10
import Big from 'big.js' ;
11
11
import { TransferContractInterface , createContract } from '../contract' ;
12
12
import { PolkadotService } from '../polkadot' ;
@@ -121,6 +121,7 @@ export async function getSourceData({
121
121
decimals : zeroFeeAmount . decimals ,
122
122
evmSigner,
123
123
extrinsic,
124
+ feeConfig : config . fee ,
124
125
polkadot,
125
126
sourceAddress,
126
127
} ) ;
@@ -181,6 +182,7 @@ export interface GetFeeParams {
181
182
decimals : number ;
182
183
evmSigner ?: EvmSigner ;
183
184
extrinsic ?: ExtrinsicConfig ;
185
+ feeConfig ?: FeeAssetConfig ;
184
186
polkadot : PolkadotService ;
185
187
sourceAddress : string ;
186
188
}
@@ -191,6 +193,7 @@ export async function getFee({
191
193
decimals,
192
194
evmSigner,
193
195
extrinsic,
196
+ feeConfig,
194
197
polkadot,
195
198
sourceAddress,
196
199
} : GetFeeParams ) : Promise < bigint > {
@@ -203,7 +206,16 @@ export async function getFee({
203
206
}
204
207
205
208
if ( extrinsic ) {
206
- return getExtrinsicFee ( balance , extrinsic , polkadot , sourceAddress ) ;
209
+ const extrinsicFee = await getExtrinsicFee (
210
+ balance ,
211
+ extrinsic ,
212
+ polkadot ,
213
+ sourceAddress ,
214
+ ) ;
215
+
216
+ const xcmDeliveryFee = getXcmDeliveryFee ( decimals , feeConfig ) ;
217
+
218
+ return extrinsicFee + xcmDeliveryFee ;
207
219
}
208
220
209
221
throw new Error ( 'Either contract or extrinsic must be provided' ) ;
@@ -246,6 +258,15 @@ export async function getExtrinsicFee(
246
258
}
247
259
}
248
260
261
+ function getXcmDeliveryFee (
262
+ decimals : number ,
263
+ feeConfig ?: FeeAssetConfig ,
264
+ ) : bigint {
265
+ return feeConfig ?. xcmDeliveryFeeAmount
266
+ ? toBigInt ( feeConfig . xcmDeliveryFeeAmount , decimals )
267
+ : 0n ;
268
+ }
269
+
249
270
export interface GetMaxParams {
250
271
balanceAmount : AssetAmount ;
251
272
existentialDeposit : AssetAmount ;
0 commit comments