@moonbeam-network/mrl 1.0.0-dev.281 → 1.0.0-dev.283

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 CHANGED
@@ -28,18 +28,22 @@ interface TransferParams {
28
28
  statusCallback?: (status: ISubmittableResult) => void;
29
29
  sendOnlyRemoteExecution?: boolean;
30
30
  }
31
- interface MrlOtherFees {
32
- /** Protocol bridge fee (e.g., Snowbridge) - deducted from transfer amount */
33
- protocol?: AssetAmount;
34
- /** Relayer service fee for automatic execution - only applies when isAutomatic=true */
35
- relayer?: AssetAmount;
31
+ interface FeeWithBalance {
32
+ fee: AssetAmount;
33
+ balance: AssetAmount;
34
+ }
35
+ interface MrlExtraFees {
36
+ /** Deducted from source balance */
37
+ local?: FeeWithBalance;
38
+ /** Deducted from transfer amount*/
39
+ remote?: FeeWithBalance;
36
40
  }
37
41
  interface SourceTransferData extends SourceChainTransferData {
38
42
  destinationFeeBalance: AssetAmount;
39
43
  bridgeChainFeeBalance?: AssetAmount;
40
44
  feeBalance: AssetAmount;
41
45
  max: AssetAmount;
42
- otherFees: MrlOtherFees;
46
+ extraFees: MrlExtraFees;
43
47
  }
44
48
  interface DestinationTransferData extends ChainTransferData {
45
49
  }
@@ -88,4 +92,4 @@ declare function Mrl(options?: MrlOptions): {
88
92
  getExecuteTransferData({ txId, chain }: WormholeExecuteTransferParams): Promise<ExecuteTransferData>;
89
93
  };
90
94
 
91
- export { type BridgeChainTransferData, type ChainTransferData, type DestinationTransferData, type ExecuteTransferData, Mrl, type MrlOptions, type MrlOtherFees, type Signers, type SourceTransferData, type TransferData, type TransferParams };
95
+ export { type BridgeChainTransferData, type ChainTransferData, type DestinationTransferData, type ExecuteTransferData, type FeeWithBalance, Mrl, type MrlExtraFees, type MrlOptions, type Signers, type SourceTransferData, type TransferData, type TransferParams };
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 EvmParachain4
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
- 10000000000000n,
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
 
@@ -17132,7 +17131,7 @@ function getMrlMin({
17132
17131
  bridgeChainData,
17133
17132
  sourceData
17134
17133
  });
17135
- const relayerFee = sourceData.otherFees?.relayer?.amount ? sourceData.otherFees.relayer.toBig() : Big(0);
17134
+ const relayerFee = sourceData.extraFees?.remote?.fee.amount ? sourceData.extraFees.remote?.fee.toBig() : Big(0);
17136
17135
  return min.copyWith({
17137
17136
  amount: BigInt(min.toBig().add(bridgeChainFee).add(relayerFee).toFixed())
17138
17137
  });
@@ -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,14 @@ 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
  });
17340
17348
  const transfer = await buildTransfer({
17341
17349
  asset: getAmountForTransferSimulation(balance, protocolFee),
17342
17350
  protocolFee,
17351
+ bridgeChainFee: bridgeChainData.fee,
17343
17352
  destinationAddress,
17344
17353
  feeAsset: feeBalance,
17345
17354
  isAutomatic,
@@ -17355,7 +17364,13 @@ async function getSourceData({
17355
17364
  feeConfig: route.source.fee,
17356
17365
  sourceAddress
17357
17366
  });
17358
- const relayerFee = await getRelayerFee({
17367
+ const max = getMax({
17368
+ balance,
17369
+ existentialDeposit,
17370
+ fee,
17371
+ min
17372
+ });
17373
+ const extraFees = await getExtraFees({
17359
17374
  chain: source,
17360
17375
  transfer,
17361
17376
  asset: balance,
@@ -17363,13 +17378,9 @@ async function getSourceData({
17363
17378
  isAutomatic,
17364
17379
  destinationAddress,
17365
17380
  route,
17366
- sourceAddress
17367
- });
17368
- const max = getMax({
17369
- balance,
17370
- existentialDeposit,
17371
- fee,
17372
- min
17381
+ sourceAddress,
17382
+ bridgeChainFee: bridgeChainData.fee,
17383
+ protocolFee
17373
17384
  });
17374
17385
  return {
17375
17386
  balance,
@@ -17382,10 +17393,7 @@ async function getSourceData({
17382
17393
  feeBalance,
17383
17394
  max,
17384
17395
  min,
17385
- otherFees: {
17386
- protocol: protocolFee,
17387
- relayer: relayerFee?.amount ? relayerFee : void 0
17388
- }
17396
+ extraFees
17389
17397
  };
17390
17398
  }
17391
17399
  async function getFee({
@@ -17447,7 +17455,8 @@ async function getRelayerFee({
17447
17455
  isAutomatic,
17448
17456
  route,
17449
17457
  sourceAddress,
17450
- transfer
17458
+ transfer,
17459
+ bridgeChainFee
17451
17460
  }) {
17452
17461
  if (route.mrl.transfer.provider === Provider2.Snowbridge || SnowbridgeConfig.is(transfer)) {
17453
17462
  return void 0;
@@ -17462,7 +17471,8 @@ async function getRelayerFee({
17462
17471
  feeAsset,
17463
17472
  isAutomatic,
17464
17473
  route,
17465
- sourceAddress
17474
+ sourceAddress,
17475
+ bridgeChainFee
17466
17476
  });
17467
17477
  const wormholeConfig = MrlBuilder3().wormhole().wormhole().tokenTransfer().build(builderParams);
17468
17478
  return getWormholeFee({ asset, chain: chain2, config: wormholeConfig });
@@ -17514,24 +17524,30 @@ async function getBridgeChainFeeBalance({
17514
17524
  async function getProtocolFee({
17515
17525
  address,
17516
17526
  asset,
17517
- feeAsset,
17518
17527
  balance,
17519
17528
  protocolFee,
17520
17529
  destination,
17521
- source
17530
+ source,
17531
+ bridgeChain,
17532
+ bridgeChainFee
17522
17533
  }) {
17523
- if (typeof protocolFee === "number") {
17524
- return AssetAmount2.fromChainAsset(asset, {
17525
- amount: protocolFee
17534
+ if (!protocolFee) {
17535
+ return void 0;
17536
+ }
17537
+ const protocolFeeAsset = source.getChainAsset(protocolFee.asset);
17538
+ if (typeof protocolFee.amount === "number") {
17539
+ return AssetAmount2.fromChainAsset(protocolFeeAsset, {
17540
+ amount: protocolFee.amount
17526
17541
  });
17527
17542
  }
17528
- const config = protocolFee?.build({
17543
+ const config = protocolFee?.amount?.build({
17529
17544
  address,
17530
17545
  asset,
17531
- feeAsset,
17546
+ feeAsset: protocolFeeAsset,
17532
17547
  balance,
17533
17548
  destination,
17534
- source
17549
+ source,
17550
+ bridgeChainFee
17535
17551
  });
17536
17552
  if (ContractConfig2.is(config) && EvmChain2.is(source)) {
17537
17553
  const evm = EvmService3.create(source);
@@ -17541,21 +17557,58 @@ async function getProtocolFee({
17541
17557
  `Error getting bridge fee: expected bigint from contract call, but received ${typeof amount}. `
17542
17558
  );
17543
17559
  }
17544
- return AssetAmount2.fromChainAsset(feeAsset, {
17560
+ return AssetAmount2.fromChainAsset(protocolFeeAsset, {
17545
17561
  amount
17546
17562
  });
17547
17563
  }
17548
- if (SubstrateQueryConfig.is(config) && EvmParachain3.isAnyParachain(source)) {
17549
- const polkadot = await PolkadotService2.create(source);
17564
+ if (SubstrateQueryConfig.is(config)) {
17565
+ const polkadot = await PolkadotService2.create(bridgeChain);
17550
17566
  const amount = await polkadot.query(config);
17551
- return AssetAmount2.fromChainAsset(feeAsset, {
17567
+ return AssetAmount2.fromChainAsset(protocolFeeAsset, {
17552
17568
  amount
17553
17569
  });
17554
17570
  }
17555
- return AssetAmount2.fromChainAsset(feeAsset, {
17571
+ return AssetAmount2.fromChainAsset(protocolFeeAsset, {
17556
17572
  amount: 0n
17557
17573
  });
17558
17574
  }
17575
+ async function getExtraFees({
17576
+ asset,
17577
+ chain: chain2,
17578
+ destinationAddress,
17579
+ feeAsset,
17580
+ isAutomatic,
17581
+ route,
17582
+ sourceAddress,
17583
+ transfer,
17584
+ bridgeChainFee,
17585
+ protocolFee
17586
+ }) {
17587
+ const relayerFee = await getRelayerFee({
17588
+ chain: chain2,
17589
+ transfer,
17590
+ asset,
17591
+ feeAsset,
17592
+ isAutomatic,
17593
+ destinationAddress,
17594
+ route,
17595
+ sourceAddress,
17596
+ bridgeChainFee
17597
+ });
17598
+ const protocolFeeConfig = route.source.protocolFee;
17599
+ const protocolFeeBalance = protocolFeeConfig ? await getBalance2({
17600
+ address: sourceAddress,
17601
+ asset: chain2.getChainAsset(protocolFeeConfig.asset),
17602
+ builder: protocolFeeConfig.balance,
17603
+ chain: chain2
17604
+ }) : void 0;
17605
+ const localFee = protocolFee && protocolFeeBalance ? { fee: protocolFee, balance: protocolFeeBalance } : void 0;
17606
+ const remoteFee = relayerFee ? { fee: relayerFee, balance: feeAsset } : void 0;
17607
+ return {
17608
+ local: localFee,
17609
+ remote: remoteFee
17610
+ };
17611
+ }
17559
17612
 
17560
17613
  // src/getTransferData/getTransferData.ts
17561
17614
  async function getTransferData({
@@ -17577,17 +17630,18 @@ async function getTransferData({
17577
17630
  asset: destinationData.fee,
17578
17631
  target: route.getDestinationFeeAssetOnSource()
17579
17632
  });
17633
+ const bridgeChainData = await getBridgeChainData({
17634
+ route,
17635
+ sourceAddress,
17636
+ destinationAddress
17637
+ });
17580
17638
  const sourceData = await getSourceData({
17581
17639
  isAutomatic: route.mrl.isAutomaticPossible && isAutomatic,
17582
17640
  route,
17583
17641
  destinationAddress,
17584
17642
  destinationFee,
17585
- sourceAddress
17586
- });
17587
- const bridgeChainData = await getBridgeChainData({
17588
- route,
17589
17643
  sourceAddress,
17590
- destinationAddress
17644
+ bridgeChainData
17591
17645
  });
17592
17646
  return {
17593
17647
  destination: destinationData,
@@ -17603,7 +17657,7 @@ async function getTransferData({
17603
17657
  });
17604
17658
  const result = bigAmount.minus(
17605
17659
  isSameAssetPayingDestinationFee ? destinationFee.toBig() : Big2(0)
17606
- ).minus(fee).minus(sourceData.otherFees?.relayer?.toBig() || Big2(0));
17660
+ ).minus(fee).minus(sourceData.extraFees.remote?.fee.toBig() || Big2(0));
17607
17661
  return sourceData.balance.copyWith({
17608
17662
  amount: result.lt(0) ? 0n : BigInt(result.toFixed())
17609
17663
  });
@@ -17638,7 +17692,8 @@ async function getTransferData({
17638
17692
  );
17639
17693
  const transfer = await buildTransfer({
17640
17694
  asset,
17641
- protocolFee: sourceData.otherFees?.protocol,
17695
+ protocolFee: sourceData.extraFees.local?.fee,
17696
+ bridgeChainFee: bridgeChainData.fee,
17642
17697
  destinationAddress,
17643
17698
  feeAsset,
17644
17699
  isAutomatic: isAutomatic2,
@@ -17646,7 +17701,7 @@ async function getTransferData({
17646
17701
  sendOnlyRemoteExecution,
17647
17702
  sourceAddress
17648
17703
  });
17649
- if (ContractConfig3.is(transfer) && (EvmChain3.is(source) || EvmParachain4.is(source))) {
17704
+ if (ContractConfig3.is(transfer) && (EvmChain3.is(source) || EvmParachain3.is(source))) {
17650
17705
  if (!evmSigner) {
17651
17706
  throw new Error("EVM Signer must be provided");
17652
17707
  }
@@ -17654,7 +17709,7 @@ async function getTransferData({
17654
17709
  const hash = await evm.transfer(evmSigner, transfer);
17655
17710
  return [hash];
17656
17711
  }
17657
- if (ExtrinsicConfig.is(transfer) && EvmParachain4.isAnyParachain(source)) {
17712
+ if (ExtrinsicConfig.is(transfer) && EvmParachain3.isAnyParachain(source)) {
17658
17713
  if (!polkadotSigner) {
17659
17714
  throw new Error("Polkadot signer must be provided");
17660
17715
  }
@@ -17667,14 +17722,14 @@ async function getTransferData({
17667
17722
  );
17668
17723
  return [hash];
17669
17724
  }
17670
- if (WormholeConfig2.is(transfer) && (EvmChain3.is(source) || EvmParachain4.is(source))) {
17725
+ if (WormholeConfig2.is(transfer) && (EvmChain3.is(source) || EvmParachain3.is(source))) {
17671
17726
  if (!evmSigner) {
17672
17727
  throw new Error("EVM Signer must be provided");
17673
17728
  }
17674
17729
  const wh = WormholeService.create(source);
17675
17730
  return wh.transfer(evmSigner, transfer);
17676
17731
  }
17677
- if (SnowbridgeConfig2.is(transfer) && (EvmChain3.is(source) || EvmParachain4.is(source))) {
17732
+ if (SnowbridgeConfig2.is(transfer) && (EvmChain3.is(source) || EvmParachain3.is(source))) {
17678
17733
  if (!evmSigner) {
17679
17734
  throw new Error("EVM Signer must be provided");
17680
17735
  }