@moonbeam-network/mrl 1.0.0-dev.284 → 1.0.0-dev.285

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,22 +28,18 @@ interface TransferParams {
28
28
  statusCallback?: (status: ISubmittableResult) => void;
29
29
  sendOnlyRemoteExecution?: boolean;
30
30
  }
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;
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;
40
36
  }
41
37
  interface SourceTransferData extends SourceChainTransferData {
42
38
  destinationFeeBalance: AssetAmount;
43
39
  bridgeChainFeeBalance?: AssetAmount;
44
40
  feeBalance: AssetAmount;
45
41
  max: AssetAmount;
46
- extraFees: MrlExtraFees;
42
+ otherFees: MrlOtherFees;
47
43
  }
48
44
  interface DestinationTransferData extends ChainTransferData {
49
45
  }
@@ -92,4 +88,4 @@ declare function Mrl(options?: MrlOptions): {
92
88
  getExecuteTransferData({ txId, chain }: WormholeExecuteTransferParams): Promise<ExecuteTransferData>;
93
89
  };
94
90
 
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 };
91
+ export { type BridgeChainTransferData, type ChainTransferData, type DestinationTransferData, type ExecuteTransferData, Mrl, type MrlOptions, type MrlOtherFees, 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 EvmParachain3
16798
+ EvmParachain as EvmParachain4
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";
@@ -16808,7 +16808,6 @@ import {
16808
16808
  } from "@moonbeam-network/xcm-builder";
16809
16809
  import { EvmService as EvmService2 } from "@moonbeam-network/xcm-sdk";
16810
16810
  import { EvmChain } from "@moonbeam-network/xcm-types";
16811
- import { isEthAddress } from "@moonbeam-network/xcm-utils";
16812
16811
  import { u8aToHex } from "@polkadot/util";
16813
16812
  import { decodeAddress } from "@polkadot/util-crypto";
16814
16813
  import { encodeFunctionData } from "viem";
@@ -16870,21 +16869,18 @@ var SnowbridgeService = class _SnowbridgeService {
16870
16869
  destinationAddress,
16871
16870
  destinationParaId,
16872
16871
  amount,
16873
- bridgeFeeAmount,
16874
- bridgeChainFee,
16875
- requiresApproval
16872
+ value
16876
16873
  } = args;
16877
- const value = requiresApproval ? bridgeFeeAmount : amount + bridgeFeeAmount;
16878
- const isEthereumDestination = isEthAddress(destinationAddress);
16879
- const destination = isEthereumDestination ? { kind: 2, data: destinationAddress } : { kind: 1, data: u8aToHex(decodeAddress(destinationAddress)) };
16880
16874
  const contractArgs = [
16881
16875
  tokenAddress,
16882
16876
  destinationParaId,
16883
- destination,
16884
- bridgeChainFee,
16877
+ {
16878
+ kind: 1,
16879
+ data: u8aToHex(decodeAddress(destinationAddress))
16880
+ },
16881
+ 0n,
16885
16882
  amount
16886
16883
  ];
16887
- console.log("contractArgs", contractArgs);
16888
16884
  return new ContractConfig({
16889
16885
  address: this.#gatewayAddress,
16890
16886
  abi: GATEWAY_ABI,
@@ -16963,10 +16959,7 @@ var SnowbridgeService = class _SnowbridgeService {
16963
16959
  // src/getTransferData/getBridgeChainData.ts
16964
16960
  import { getBalance, getDestinationFee } from "@moonbeam-network/xcm-sdk";
16965
16961
  import { EvmParachain, Parachain } from "@moonbeam-network/xcm-types";
16966
- import {
16967
- getMultilocationDerivedAddresses,
16968
- isEthAddress as isEthAddress2
16969
- } from "@moonbeam-network/xcm-utils";
16962
+ import { getMultilocationDerivedAddresses } from "@moonbeam-network/xcm-utils";
16970
16963
  import { evmToAddress } from "@polkadot/util-crypto";
16971
16964
  async function getBridgeChainData({
16972
16965
  route,
@@ -17023,10 +17016,6 @@ function getBridgeChainAddress({
17023
17016
  const isDestinationBridgeChain = bridgeChain.isEqual(destination);
17024
17017
  const isSourceBridgeChain = bridgeChain.isEqual(source);
17025
17018
  let bridgeChainAddress = isDestinationBridgeChain ? destinationAddress : sourceAddress;
17026
- if (Parachain.isExactly(bridgeChain) && isEthAddress2(bridgeChainAddress)) {
17027
- bridgeChainAddress = evmToAddress(bridgeChainAddress);
17028
- return bridgeChainAddress;
17029
- }
17030
17019
  if (Parachain.is(source) && !isSourceBridgeChain) {
17031
17020
  const isSourceEvmSigner = EvmParachain.is(source) && source.isEvmSigner;
17032
17021
  const { address20: computedOriginAccount } = getMultilocationDerivedAddresses({
@@ -17061,7 +17050,8 @@ import {
17061
17050
  } from "@moonbeam-network/xcm-sdk";
17062
17051
  import {
17063
17052
  AssetAmount as AssetAmount2,
17064
- EvmChain as EvmChain2
17053
+ EvmChain as EvmChain2,
17054
+ EvmParachain as EvmParachain3
17065
17055
  } from "@moonbeam-network/xcm-types";
17066
17056
  import { toBigInt as toBigInt2 } from "@moonbeam-network/xcm-utils";
17067
17057
 
@@ -17131,7 +17121,7 @@ function getMrlMin({
17131
17121
  bridgeChainData,
17132
17122
  sourceData
17133
17123
  });
17134
- const relayerFee = sourceData.extraFees?.remote?.fee.amount ? sourceData.extraFees.remote?.fee.toBig() : Big(0);
17124
+ const relayerFee = sourceData.otherFees?.relayer?.amount ? sourceData.otherFees.relayer.toBig() : Big(0);
17135
17125
  return min.copyWith({
17136
17126
  amount: BigInt(min.toBig().add(bridgeChainFee).add(relayerFee).toFixed())
17137
17127
  });
@@ -17160,7 +17150,6 @@ async function buildTransfer(params) {
17160
17150
  async function getMrlBuilderParams({
17161
17151
  asset,
17162
17152
  protocolFee,
17163
- bridgeChainFee,
17164
17153
  destinationAddress,
17165
17154
  feeAsset,
17166
17155
  isAutomatic,
@@ -17184,7 +17173,6 @@ async function getMrlBuilderParams({
17184
17173
  return {
17185
17174
  asset,
17186
17175
  protocolFee,
17187
- bridgeChainFee,
17188
17176
  destination,
17189
17177
  destinationAddress,
17190
17178
  destinationApi,
@@ -17277,9 +17265,6 @@ async function getBridgeChainGasLimit(params) {
17277
17265
  return gasEstimation * 110n / 100n;
17278
17266
  }
17279
17267
  function getAmountForTransferSimulation(balance, protocolFee) {
17280
- if (!protocolFee) {
17281
- return balance;
17282
- }
17283
17268
  return balance.copyWith({
17284
17269
  amount: balance.amount - protocolFee.amount > 0 ? balance.amount - protocolFee.amount : 0n
17285
17270
  });
@@ -17291,8 +17276,7 @@ async function getSourceData({
17291
17276
  route,
17292
17277
  destinationAddress,
17293
17278
  destinationFee,
17294
- sourceAddress,
17295
- bridgeChainData
17279
+ sourceAddress
17296
17280
  }) {
17297
17281
  if (!route.mrl) {
17298
17282
  throw new Error(
@@ -17301,7 +17285,6 @@ async function getSourceData({
17301
17285
  }
17302
17286
  const source = route.source.chain;
17303
17287
  const destination = route.destination.chain;
17304
- const bridgeChain = route.mrl.bridgeChain.chain;
17305
17288
  const asset = source.getChainAsset(route.source.asset);
17306
17289
  const feeAsset = route.source.fee ? source.getChainAsset(route.source.fee.asset) : asset;
17307
17290
  const balance = await getBalance2({
@@ -17341,14 +17324,11 @@ async function getSourceData({
17341
17324
  feeAsset,
17342
17325
  balance,
17343
17326
  protocolFee: route.source.protocolFee,
17344
- address: destinationAddress,
17345
- bridgeChain,
17346
- bridgeChainFee: bridgeChainData.fee
17327
+ address: destinationAddress
17347
17328
  });
17348
17329
  const transfer = await buildTransfer({
17349
17330
  asset: getAmountForTransferSimulation(balance, protocolFee),
17350
17331
  protocolFee,
17351
- bridgeChainFee: bridgeChainData.fee,
17352
17332
  destinationAddress,
17353
17333
  feeAsset: feeBalance,
17354
17334
  isAutomatic,
@@ -17364,13 +17344,7 @@ async function getSourceData({
17364
17344
  feeConfig: route.source.fee,
17365
17345
  sourceAddress
17366
17346
  });
17367
- const max = getMax({
17368
- balance,
17369
- existentialDeposit,
17370
- fee,
17371
- min
17372
- });
17373
- const extraFees = await getExtraFees({
17347
+ const relayerFee = await getRelayerFee({
17374
17348
  chain: source,
17375
17349
  transfer,
17376
17350
  asset: balance,
@@ -17378,9 +17352,13 @@ async function getSourceData({
17378
17352
  isAutomatic,
17379
17353
  destinationAddress,
17380
17354
  route,
17381
- sourceAddress,
17382
- bridgeChainFee: bridgeChainData.fee,
17383
- protocolFee
17355
+ sourceAddress
17356
+ });
17357
+ const max = getMax({
17358
+ balance,
17359
+ existentialDeposit,
17360
+ fee,
17361
+ min
17384
17362
  });
17385
17363
  return {
17386
17364
  balance,
@@ -17393,7 +17371,10 @@ async function getSourceData({
17393
17371
  feeBalance,
17394
17372
  max,
17395
17373
  min,
17396
- extraFees
17374
+ otherFees: {
17375
+ protocol: protocolFee,
17376
+ relayer: relayerFee?.amount ? relayerFee : void 0
17377
+ }
17397
17378
  };
17398
17379
  }
17399
17380
  async function getFee({
@@ -17455,8 +17436,7 @@ async function getRelayerFee({
17455
17436
  isAutomatic,
17456
17437
  route,
17457
17438
  sourceAddress,
17458
- transfer,
17459
- bridgeChainFee
17439
+ transfer
17460
17440
  }) {
17461
17441
  if (route.mrl.transfer.provider === Provider2.Snowbridge || SnowbridgeConfig.is(transfer)) {
17462
17442
  return void 0;
@@ -17471,8 +17451,7 @@ async function getRelayerFee({
17471
17451
  feeAsset,
17472
17452
  isAutomatic,
17473
17453
  route,
17474
- sourceAddress,
17475
- bridgeChainFee
17454
+ sourceAddress
17476
17455
  });
17477
17456
  const wormholeConfig = MrlBuilder3().wormhole().wormhole().tokenTransfer().build(builderParams);
17478
17457
  return getWormholeFee({ asset, chain: chain2, config: wormholeConfig });
@@ -17524,30 +17503,24 @@ async function getBridgeChainFeeBalance({
17524
17503
  async function getProtocolFee({
17525
17504
  address,
17526
17505
  asset,
17506
+ feeAsset,
17527
17507
  balance,
17528
17508
  protocolFee,
17529
17509
  destination,
17530
- source,
17531
- bridgeChain,
17532
- bridgeChainFee
17510
+ source
17533
17511
  }) {
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
17512
+ if (typeof protocolFee === "number") {
17513
+ return AssetAmount2.fromChainAsset(feeAsset, {
17514
+ amount: protocolFee
17541
17515
  });
17542
17516
  }
17543
- const config = protocolFee?.amount?.build({
17517
+ const config = protocolFee?.build({
17544
17518
  address,
17545
17519
  asset,
17546
- feeAsset: protocolFeeAsset,
17520
+ feeAsset,
17547
17521
  balance,
17548
17522
  destination,
17549
- source,
17550
- bridgeChainFee
17523
+ source
17551
17524
  });
17552
17525
  if (ContractConfig2.is(config) && EvmChain2.is(source)) {
17553
17526
  const evm = EvmService3.create(source);
@@ -17557,58 +17530,21 @@ async function getProtocolFee({
17557
17530
  `Error getting bridge fee: expected bigint from contract call, but received ${typeof amount}. `
17558
17531
  );
17559
17532
  }
17560
- return AssetAmount2.fromChainAsset(protocolFeeAsset, {
17533
+ return AssetAmount2.fromChainAsset(feeAsset, {
17561
17534
  amount
17562
17535
  });
17563
17536
  }
17564
- if (SubstrateQueryConfig.is(config)) {
17565
- const polkadot = await PolkadotService2.create(bridgeChain);
17537
+ if (SubstrateQueryConfig.is(config) && EvmParachain3.isAnyParachain(source)) {
17538
+ const polkadot = await PolkadotService2.create(source);
17566
17539
  const amount = await polkadot.query(config);
17567
- return AssetAmount2.fromChainAsset(protocolFeeAsset, {
17540
+ return AssetAmount2.fromChainAsset(feeAsset, {
17568
17541
  amount
17569
17542
  });
17570
17543
  }
17571
- return AssetAmount2.fromChainAsset(protocolFeeAsset, {
17544
+ return AssetAmount2.fromChainAsset(feeAsset, {
17572
17545
  amount: 0n
17573
17546
  });
17574
17547
  }
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
- }
17612
17548
 
17613
17549
  // src/getTransferData/getTransferData.ts
17614
17550
  async function getTransferData({
@@ -17630,18 +17566,17 @@ async function getTransferData({
17630
17566
  asset: destinationData.fee,
17631
17567
  target: route.getDestinationFeeAssetOnSource()
17632
17568
  });
17633
- const bridgeChainData = await getBridgeChainData({
17634
- route,
17635
- sourceAddress,
17636
- destinationAddress
17637
- });
17638
17569
  const sourceData = await getSourceData({
17639
17570
  isAutomatic: route.mrl.isAutomaticPossible && isAutomatic,
17640
17571
  route,
17641
17572
  destinationAddress,
17642
17573
  destinationFee,
17574
+ sourceAddress
17575
+ });
17576
+ const bridgeChainData = await getBridgeChainData({
17577
+ route,
17643
17578
  sourceAddress,
17644
- bridgeChainData
17579
+ destinationAddress
17645
17580
  });
17646
17581
  return {
17647
17582
  destination: destinationData,
@@ -17657,7 +17592,7 @@ async function getTransferData({
17657
17592
  });
17658
17593
  const result = bigAmount.minus(
17659
17594
  isSameAssetPayingDestinationFee ? destinationFee.toBig() : Big2(0)
17660
- ).minus(fee).minus(sourceData.extraFees.remote?.fee.toBig() || Big2(0));
17595
+ ).minus(fee).minus(sourceData.otherFees?.relayer?.toBig() || Big2(0));
17661
17596
  return sourceData.balance.copyWith({
17662
17597
  amount: result.lt(0) ? 0n : BigInt(result.toFixed())
17663
17598
  });
@@ -17692,8 +17627,7 @@ async function getTransferData({
17692
17627
  );
17693
17628
  const transfer = await buildTransfer({
17694
17629
  asset,
17695
- protocolFee: sourceData.extraFees.local?.fee,
17696
- bridgeChainFee: bridgeChainData.fee,
17630
+ protocolFee: sourceData.otherFees?.protocol,
17697
17631
  destinationAddress,
17698
17632
  feeAsset,
17699
17633
  isAutomatic: isAutomatic2,
@@ -17701,7 +17635,7 @@ async function getTransferData({
17701
17635
  sendOnlyRemoteExecution,
17702
17636
  sourceAddress
17703
17637
  });
17704
- if (ContractConfig3.is(transfer) && (EvmChain3.is(source) || EvmParachain3.is(source))) {
17638
+ if (ContractConfig3.is(transfer) && (EvmChain3.is(source) || EvmParachain4.is(source))) {
17705
17639
  if (!evmSigner) {
17706
17640
  throw new Error("EVM Signer must be provided");
17707
17641
  }
@@ -17709,7 +17643,7 @@ async function getTransferData({
17709
17643
  const hash = await evm.transfer(evmSigner, transfer);
17710
17644
  return [hash];
17711
17645
  }
17712
- if (ExtrinsicConfig.is(transfer) && EvmParachain3.isAnyParachain(source)) {
17646
+ if (ExtrinsicConfig.is(transfer) && EvmParachain4.isAnyParachain(source)) {
17713
17647
  if (!polkadotSigner) {
17714
17648
  throw new Error("Polkadot signer must be provided");
17715
17649
  }
@@ -17722,14 +17656,14 @@ async function getTransferData({
17722
17656
  );
17723
17657
  return [hash];
17724
17658
  }
17725
- if (WormholeConfig2.is(transfer) && (EvmChain3.is(source) || EvmParachain3.is(source))) {
17659
+ if (WormholeConfig2.is(transfer) && (EvmChain3.is(source) || EvmParachain4.is(source))) {
17726
17660
  if (!evmSigner) {
17727
17661
  throw new Error("EVM Signer must be provided");
17728
17662
  }
17729
17663
  const wh = WormholeService.create(source);
17730
17664
  return wh.transfer(evmSigner, transfer);
17731
17665
  }
17732
- if (SnowbridgeConfig2.is(transfer) && (EvmChain3.is(source) || EvmParachain3.is(source))) {
17666
+ if (SnowbridgeConfig2.is(transfer) && (EvmChain3.is(source) || EvmParachain4.is(source))) {
17733
17667
  if (!evmSigner) {
17734
17668
  throw new Error("EVM Signer must be provided");
17735
17669
  }