@moonbeam-network/mrl 1.0.0-dev.281 → 1.0.0-dev.282
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.d.ts +1 -0
- package/build/index.mjs +57 -28
- package/build/index.mjs.map +1 -1
- package/package.json +6 -6
package/build/index.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ interface MrlOtherFees {
|
|
|
37
37
|
interface SourceTransferData extends SourceChainTransferData {
|
|
38
38
|
destinationFeeBalance: AssetAmount;
|
|
39
39
|
bridgeChainFeeBalance?: AssetAmount;
|
|
40
|
+
protocolFeeBalance?: AssetAmount;
|
|
40
41
|
feeBalance: AssetAmount;
|
|
41
42
|
max: AssetAmount;
|
|
42
43
|
otherFees: MrlOtherFees;
|
package/build/index.mjs
CHANGED
|
@@ -16795,7 +16795,7 @@ import {
|
|
|
16795
16795
|
import {
|
|
16796
16796
|
AssetAmount as AssetAmount3,
|
|
16797
16797
|
EvmChain as EvmChain3,
|
|
16798
|
-
EvmParachain as
|
|
16798
|
+
EvmParachain as EvmParachain3
|
|
16799
16799
|
} from "@moonbeam-network/xcm-types";
|
|
16800
16800
|
import { toBigInt as toBigInt3 } from "@moonbeam-network/xcm-utils";
|
|
16801
16801
|
import Big2 from "big.js";
|
|
@@ -16871,6 +16871,7 @@ var SnowbridgeService = class _SnowbridgeService {
|
|
|
16871
16871
|
destinationParaId,
|
|
16872
16872
|
amount,
|
|
16873
16873
|
bridgeFeeAmount,
|
|
16874
|
+
bridgeChainFee,
|
|
16874
16875
|
requiresApproval
|
|
16875
16876
|
} = args;
|
|
16876
16877
|
const value = requiresApproval ? bridgeFeeAmount : amount + bridgeFeeAmount;
|
|
@@ -16880,8 +16881,7 @@ var SnowbridgeService = class _SnowbridgeService {
|
|
|
16880
16881
|
tokenAddress,
|
|
16881
16882
|
destinationParaId,
|
|
16882
16883
|
destination,
|
|
16883
|
-
|
|
16884
|
-
// TODO mjm get from config
|
|
16884
|
+
bridgeChainFee,
|
|
16885
16885
|
amount
|
|
16886
16886
|
];
|
|
16887
16887
|
console.log("contractArgs", contractArgs);
|
|
@@ -17061,8 +17061,7 @@ import {
|
|
|
17061
17061
|
} from "@moonbeam-network/xcm-sdk";
|
|
17062
17062
|
import {
|
|
17063
17063
|
AssetAmount as AssetAmount2,
|
|
17064
|
-
EvmChain as EvmChain2
|
|
17065
|
-
EvmParachain as EvmParachain3
|
|
17064
|
+
EvmChain as EvmChain2
|
|
17066
17065
|
} from "@moonbeam-network/xcm-types";
|
|
17067
17066
|
import { toBigInt as toBigInt2 } from "@moonbeam-network/xcm-utils";
|
|
17068
17067
|
|
|
@@ -17161,6 +17160,7 @@ async function buildTransfer(params) {
|
|
|
17161
17160
|
async function getMrlBuilderParams({
|
|
17162
17161
|
asset,
|
|
17163
17162
|
protocolFee,
|
|
17163
|
+
bridgeChainFee,
|
|
17164
17164
|
destinationAddress,
|
|
17165
17165
|
feeAsset,
|
|
17166
17166
|
isAutomatic,
|
|
@@ -17184,6 +17184,7 @@ async function getMrlBuilderParams({
|
|
|
17184
17184
|
return {
|
|
17185
17185
|
asset,
|
|
17186
17186
|
protocolFee,
|
|
17187
|
+
bridgeChainFee,
|
|
17187
17188
|
destination,
|
|
17188
17189
|
destinationAddress,
|
|
17189
17190
|
destinationApi,
|
|
@@ -17276,6 +17277,9 @@ async function getBridgeChainGasLimit(params) {
|
|
|
17276
17277
|
return gasEstimation * 110n / 100n;
|
|
17277
17278
|
}
|
|
17278
17279
|
function getAmountForTransferSimulation(balance, protocolFee) {
|
|
17280
|
+
if (!protocolFee) {
|
|
17281
|
+
return balance;
|
|
17282
|
+
}
|
|
17279
17283
|
return balance.copyWith({
|
|
17280
17284
|
amount: balance.amount - protocolFee.amount > 0 ? balance.amount - protocolFee.amount : 0n
|
|
17281
17285
|
});
|
|
@@ -17287,7 +17291,8 @@ async function getSourceData({
|
|
|
17287
17291
|
route,
|
|
17288
17292
|
destinationAddress,
|
|
17289
17293
|
destinationFee,
|
|
17290
|
-
sourceAddress
|
|
17294
|
+
sourceAddress,
|
|
17295
|
+
bridgeChainData
|
|
17291
17296
|
}) {
|
|
17292
17297
|
if (!route.mrl) {
|
|
17293
17298
|
throw new Error(
|
|
@@ -17296,6 +17301,7 @@ async function getSourceData({
|
|
|
17296
17301
|
}
|
|
17297
17302
|
const source = route.source.chain;
|
|
17298
17303
|
const destination = route.destination.chain;
|
|
17304
|
+
const bridgeChain = route.mrl.bridgeChain.chain;
|
|
17299
17305
|
const asset = source.getChainAsset(route.source.asset);
|
|
17300
17306
|
const feeAsset = route.source.fee ? source.getChainAsset(route.source.fee.asset) : asset;
|
|
17301
17307
|
const balance = await getBalance2({
|
|
@@ -17335,11 +17341,21 @@ async function getSourceData({
|
|
|
17335
17341
|
feeAsset,
|
|
17336
17342
|
balance,
|
|
17337
17343
|
protocolFee: route.source.protocolFee,
|
|
17338
|
-
address: destinationAddress
|
|
17344
|
+
address: destinationAddress,
|
|
17345
|
+
bridgeChain,
|
|
17346
|
+
bridgeChainFee: bridgeChainData.fee
|
|
17339
17347
|
});
|
|
17348
|
+
const protocolFeeConfig = route.source.protocolFee;
|
|
17349
|
+
const protocolFeeBalance = protocolFeeConfig ? await getBalance2({
|
|
17350
|
+
address: sourceAddress,
|
|
17351
|
+
asset: source.getChainAsset(protocolFeeConfig.asset),
|
|
17352
|
+
builder: protocolFeeConfig.balance,
|
|
17353
|
+
chain: source
|
|
17354
|
+
}) : void 0;
|
|
17340
17355
|
const transfer = await buildTransfer({
|
|
17341
17356
|
asset: getAmountForTransferSimulation(balance, protocolFee),
|
|
17342
17357
|
protocolFee,
|
|
17358
|
+
bridgeChainFee: bridgeChainData.fee,
|
|
17343
17359
|
destinationAddress,
|
|
17344
17360
|
feeAsset: feeBalance,
|
|
17345
17361
|
isAutomatic,
|
|
@@ -17363,7 +17379,8 @@ async function getSourceData({
|
|
|
17363
17379
|
isAutomatic,
|
|
17364
17380
|
destinationAddress,
|
|
17365
17381
|
route,
|
|
17366
|
-
sourceAddress
|
|
17382
|
+
sourceAddress,
|
|
17383
|
+
bridgeChainFee: bridgeChainData.fee
|
|
17367
17384
|
});
|
|
17368
17385
|
const max = getMax({
|
|
17369
17386
|
balance,
|
|
@@ -17377,6 +17394,7 @@ async function getSourceData({
|
|
|
17377
17394
|
destinationFee,
|
|
17378
17395
|
destinationFeeBalance,
|
|
17379
17396
|
bridgeChainFeeBalance,
|
|
17397
|
+
protocolFeeBalance,
|
|
17380
17398
|
existentialDeposit,
|
|
17381
17399
|
fee,
|
|
17382
17400
|
feeBalance,
|
|
@@ -17447,7 +17465,8 @@ async function getRelayerFee({
|
|
|
17447
17465
|
isAutomatic,
|
|
17448
17466
|
route,
|
|
17449
17467
|
sourceAddress,
|
|
17450
|
-
transfer
|
|
17468
|
+
transfer,
|
|
17469
|
+
bridgeChainFee
|
|
17451
17470
|
}) {
|
|
17452
17471
|
if (route.mrl.transfer.provider === Provider2.Snowbridge || SnowbridgeConfig.is(transfer)) {
|
|
17453
17472
|
return void 0;
|
|
@@ -17462,7 +17481,8 @@ async function getRelayerFee({
|
|
|
17462
17481
|
feeAsset,
|
|
17463
17482
|
isAutomatic,
|
|
17464
17483
|
route,
|
|
17465
|
-
sourceAddress
|
|
17484
|
+
sourceAddress,
|
|
17485
|
+
bridgeChainFee
|
|
17466
17486
|
});
|
|
17467
17487
|
const wormholeConfig = MrlBuilder3().wormhole().wormhole().tokenTransfer().build(builderParams);
|
|
17468
17488
|
return getWormholeFee({ asset, chain: chain2, config: wormholeConfig });
|
|
@@ -17518,20 +17538,27 @@ async function getProtocolFee({
|
|
|
17518
17538
|
balance,
|
|
17519
17539
|
protocolFee,
|
|
17520
17540
|
destination,
|
|
17521
|
-
source
|
|
17541
|
+
source,
|
|
17542
|
+
bridgeChain,
|
|
17543
|
+
bridgeChainFee
|
|
17522
17544
|
}) {
|
|
17523
|
-
if (
|
|
17524
|
-
return
|
|
17525
|
-
|
|
17545
|
+
if (!protocolFee) {
|
|
17546
|
+
return void 0;
|
|
17547
|
+
}
|
|
17548
|
+
const protocolFeeAsset = source.getChainAsset(protocolFee.asset);
|
|
17549
|
+
if (typeof protocolFee.amount === "number") {
|
|
17550
|
+
return AssetAmount2.fromChainAsset(protocolFeeAsset, {
|
|
17551
|
+
amount: protocolFee.amount
|
|
17526
17552
|
});
|
|
17527
17553
|
}
|
|
17528
|
-
const config = protocolFee?.build({
|
|
17554
|
+
const config = protocolFee?.amount?.build({
|
|
17529
17555
|
address,
|
|
17530
17556
|
asset,
|
|
17531
|
-
feeAsset,
|
|
17557
|
+
feeAsset: protocolFeeAsset,
|
|
17532
17558
|
balance,
|
|
17533
17559
|
destination,
|
|
17534
|
-
source
|
|
17560
|
+
source,
|
|
17561
|
+
bridgeChainFee
|
|
17535
17562
|
});
|
|
17536
17563
|
if (ContractConfig2.is(config) && EvmChain2.is(source)) {
|
|
17537
17564
|
const evm = EvmService3.create(source);
|
|
@@ -17545,8 +17572,8 @@ async function getProtocolFee({
|
|
|
17545
17572
|
amount
|
|
17546
17573
|
});
|
|
17547
17574
|
}
|
|
17548
|
-
if (SubstrateQueryConfig.is(config)
|
|
17549
|
-
const polkadot = await PolkadotService2.create(
|
|
17575
|
+
if (SubstrateQueryConfig.is(config)) {
|
|
17576
|
+
const polkadot = await PolkadotService2.create(bridgeChain);
|
|
17550
17577
|
const amount = await polkadot.query(config);
|
|
17551
17578
|
return AssetAmount2.fromChainAsset(feeAsset, {
|
|
17552
17579
|
amount
|
|
@@ -17577,17 +17604,18 @@ async function getTransferData({
|
|
|
17577
17604
|
asset: destinationData.fee,
|
|
17578
17605
|
target: route.getDestinationFeeAssetOnSource()
|
|
17579
17606
|
});
|
|
17607
|
+
const bridgeChainData = await getBridgeChainData({
|
|
17608
|
+
route,
|
|
17609
|
+
sourceAddress,
|
|
17610
|
+
destinationAddress
|
|
17611
|
+
});
|
|
17580
17612
|
const sourceData = await getSourceData({
|
|
17581
17613
|
isAutomatic: route.mrl.isAutomaticPossible && isAutomatic,
|
|
17582
17614
|
route,
|
|
17583
17615
|
destinationAddress,
|
|
17584
17616
|
destinationFee,
|
|
17585
|
-
sourceAddress
|
|
17586
|
-
});
|
|
17587
|
-
const bridgeChainData = await getBridgeChainData({
|
|
17588
|
-
route,
|
|
17589
17617
|
sourceAddress,
|
|
17590
|
-
|
|
17618
|
+
bridgeChainData
|
|
17591
17619
|
});
|
|
17592
17620
|
return {
|
|
17593
17621
|
destination: destinationData,
|
|
@@ -17639,6 +17667,7 @@ async function getTransferData({
|
|
|
17639
17667
|
const transfer = await buildTransfer({
|
|
17640
17668
|
asset,
|
|
17641
17669
|
protocolFee: sourceData.otherFees?.protocol,
|
|
17670
|
+
bridgeChainFee: bridgeChainData.fee,
|
|
17642
17671
|
destinationAddress,
|
|
17643
17672
|
feeAsset,
|
|
17644
17673
|
isAutomatic: isAutomatic2,
|
|
@@ -17646,7 +17675,7 @@ async function getTransferData({
|
|
|
17646
17675
|
sendOnlyRemoteExecution,
|
|
17647
17676
|
sourceAddress
|
|
17648
17677
|
});
|
|
17649
|
-
if (ContractConfig3.is(transfer) && (EvmChain3.is(source) ||
|
|
17678
|
+
if (ContractConfig3.is(transfer) && (EvmChain3.is(source) || EvmParachain3.is(source))) {
|
|
17650
17679
|
if (!evmSigner) {
|
|
17651
17680
|
throw new Error("EVM Signer must be provided");
|
|
17652
17681
|
}
|
|
@@ -17654,7 +17683,7 @@ async function getTransferData({
|
|
|
17654
17683
|
const hash = await evm.transfer(evmSigner, transfer);
|
|
17655
17684
|
return [hash];
|
|
17656
17685
|
}
|
|
17657
|
-
if (ExtrinsicConfig.is(transfer) &&
|
|
17686
|
+
if (ExtrinsicConfig.is(transfer) && EvmParachain3.isAnyParachain(source)) {
|
|
17658
17687
|
if (!polkadotSigner) {
|
|
17659
17688
|
throw new Error("Polkadot signer must be provided");
|
|
17660
17689
|
}
|
|
@@ -17667,14 +17696,14 @@ async function getTransferData({
|
|
|
17667
17696
|
);
|
|
17668
17697
|
return [hash];
|
|
17669
17698
|
}
|
|
17670
|
-
if (WormholeConfig2.is(transfer) && (EvmChain3.is(source) ||
|
|
17699
|
+
if (WormholeConfig2.is(transfer) && (EvmChain3.is(source) || EvmParachain3.is(source))) {
|
|
17671
17700
|
if (!evmSigner) {
|
|
17672
17701
|
throw new Error("EVM Signer must be provided");
|
|
17673
17702
|
}
|
|
17674
17703
|
const wh = WormholeService.create(source);
|
|
17675
17704
|
return wh.transfer(evmSigner, transfer);
|
|
17676
17705
|
}
|
|
17677
|
-
if (SnowbridgeConfig2.is(transfer) && (EvmChain3.is(source) ||
|
|
17706
|
+
if (SnowbridgeConfig2.is(transfer) && (EvmChain3.is(source) || EvmParachain3.is(source))) {
|
|
17678
17707
|
if (!evmSigner) {
|
|
17679
17708
|
throw new Error("EVM Signer must be provided");
|
|
17680
17709
|
}
|