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

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,7 +17265,7 @@ async function getBridgeChainGasLimit(params) {
17277
17265
  return gasEstimation * 110n / 100n;
17278
17266
  }
17279
17267
  function getAmountForTransferSimulation(balance, protocolFee) {
17280
- if (!protocolFee) {
17268
+ if (!balance.isSame(protocolFee)) {
17281
17269
  return balance;
17282
17270
  }
17283
17271
  return balance.copyWith({
@@ -17291,8 +17279,7 @@ async function getSourceData({
17291
17279
  route,
17292
17280
  destinationAddress,
17293
17281
  destinationFee,
17294
- sourceAddress,
17295
- bridgeChainData
17282
+ sourceAddress
17296
17283
  }) {
17297
17284
  if (!route.mrl) {
17298
17285
  throw new Error(
@@ -17301,7 +17288,6 @@ async function getSourceData({
17301
17288
  }
17302
17289
  const source = route.source.chain;
17303
17290
  const destination = route.destination.chain;
17304
- const bridgeChain = route.mrl.bridgeChain.chain;
17305
17291
  const asset = source.getChainAsset(route.source.asset);
17306
17292
  const feeAsset = route.source.fee ? source.getChainAsset(route.source.fee.asset) : asset;
17307
17293
  const balance = await getBalance2({
@@ -17341,14 +17327,11 @@ async function getSourceData({
17341
17327
  feeAsset,
17342
17328
  balance,
17343
17329
  protocolFee: route.source.protocolFee,
17344
- address: destinationAddress,
17345
- bridgeChain,
17346
- bridgeChainFee: bridgeChainData.fee
17330
+ address: destinationAddress
17347
17331
  });
17348
17332
  const transfer = await buildTransfer({
17349
17333
  asset: getAmountForTransferSimulation(balance, protocolFee),
17350
17334
  protocolFee,
17351
- bridgeChainFee: bridgeChainData.fee,
17352
17335
  destinationAddress,
17353
17336
  feeAsset: feeBalance,
17354
17337
  isAutomatic,
@@ -17364,13 +17347,7 @@ async function getSourceData({
17364
17347
  feeConfig: route.source.fee,
17365
17348
  sourceAddress
17366
17349
  });
17367
- const max = getMax({
17368
- balance,
17369
- existentialDeposit,
17370
- fee,
17371
- min
17372
- });
17373
- const extraFees = await getExtraFees({
17350
+ const relayerFee = await getRelayerFee({
17374
17351
  chain: source,
17375
17352
  transfer,
17376
17353
  asset: balance,
@@ -17378,9 +17355,13 @@ async function getSourceData({
17378
17355
  isAutomatic,
17379
17356
  destinationAddress,
17380
17357
  route,
17381
- sourceAddress,
17382
- bridgeChainFee: bridgeChainData.fee,
17383
- protocolFee
17358
+ sourceAddress
17359
+ });
17360
+ const max = getMax({
17361
+ balance,
17362
+ existentialDeposit,
17363
+ fee,
17364
+ min
17384
17365
  });
17385
17366
  return {
17386
17367
  balance,
@@ -17393,7 +17374,10 @@ async function getSourceData({
17393
17374
  feeBalance,
17394
17375
  max,
17395
17376
  min,
17396
- extraFees
17377
+ otherFees: {
17378
+ protocol: protocolFee,
17379
+ relayer: relayerFee?.amount ? relayerFee : void 0
17380
+ }
17397
17381
  };
17398
17382
  }
17399
17383
  async function getFee({
@@ -17455,8 +17439,7 @@ async function getRelayerFee({
17455
17439
  isAutomatic,
17456
17440
  route,
17457
17441
  sourceAddress,
17458
- transfer,
17459
- bridgeChainFee
17442
+ transfer
17460
17443
  }) {
17461
17444
  if (route.mrl.transfer.provider === Provider2.Snowbridge || SnowbridgeConfig.is(transfer)) {
17462
17445
  return void 0;
@@ -17471,8 +17454,7 @@ async function getRelayerFee({
17471
17454
  feeAsset,
17472
17455
  isAutomatic,
17473
17456
  route,
17474
- sourceAddress,
17475
- bridgeChainFee
17457
+ sourceAddress
17476
17458
  });
17477
17459
  const wormholeConfig = MrlBuilder3().wormhole().wormhole().tokenTransfer().build(builderParams);
17478
17460
  return getWormholeFee({ asset, chain: chain2, config: wormholeConfig });
@@ -17524,30 +17506,24 @@ async function getBridgeChainFeeBalance({
17524
17506
  async function getProtocolFee({
17525
17507
  address,
17526
17508
  asset,
17509
+ feeAsset,
17527
17510
  balance,
17528
17511
  protocolFee,
17529
17512
  destination,
17530
- source,
17531
- bridgeChain,
17532
- bridgeChainFee
17513
+ source
17533
17514
  }) {
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
17515
+ if (typeof protocolFee === "number") {
17516
+ return AssetAmount2.fromChainAsset(feeAsset, {
17517
+ amount: protocolFee
17541
17518
  });
17542
17519
  }
17543
- const config = protocolFee?.amount?.build({
17520
+ const config = protocolFee?.build({
17544
17521
  address,
17545
17522
  asset,
17546
- feeAsset: protocolFeeAsset,
17523
+ feeAsset,
17547
17524
  balance,
17548
17525
  destination,
17549
- source,
17550
- bridgeChainFee
17526
+ source
17551
17527
  });
17552
17528
  if (ContractConfig2.is(config) && EvmChain2.is(source)) {
17553
17529
  const evm = EvmService3.create(source);
@@ -17557,58 +17533,21 @@ async function getProtocolFee({
17557
17533
  `Error getting bridge fee: expected bigint from contract call, but received ${typeof amount}. `
17558
17534
  );
17559
17535
  }
17560
- return AssetAmount2.fromChainAsset(protocolFeeAsset, {
17536
+ return AssetAmount2.fromChainAsset(feeAsset, {
17561
17537
  amount
17562
17538
  });
17563
17539
  }
17564
- if (SubstrateQueryConfig.is(config)) {
17565
- const polkadot = await PolkadotService2.create(bridgeChain);
17540
+ if (SubstrateQueryConfig.is(config) && EvmParachain3.isAnyParachain(source)) {
17541
+ const polkadot = await PolkadotService2.create(source);
17566
17542
  const amount = await polkadot.query(config);
17567
- return AssetAmount2.fromChainAsset(protocolFeeAsset, {
17543
+ return AssetAmount2.fromChainAsset(feeAsset, {
17568
17544
  amount
17569
17545
  });
17570
17546
  }
17571
- return AssetAmount2.fromChainAsset(protocolFeeAsset, {
17547
+ return AssetAmount2.fromChainAsset(feeAsset, {
17572
17548
  amount: 0n
17573
17549
  });
17574
17550
  }
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
17551
 
17613
17552
  // src/getTransferData/getTransferData.ts
17614
17553
  async function getTransferData({
@@ -17630,18 +17569,17 @@ async function getTransferData({
17630
17569
  asset: destinationData.fee,
17631
17570
  target: route.getDestinationFeeAssetOnSource()
17632
17571
  });
17633
- const bridgeChainData = await getBridgeChainData({
17634
- route,
17635
- sourceAddress,
17636
- destinationAddress
17637
- });
17638
17572
  const sourceData = await getSourceData({
17639
17573
  isAutomatic: route.mrl.isAutomaticPossible && isAutomatic,
17640
17574
  route,
17641
17575
  destinationAddress,
17642
17576
  destinationFee,
17577
+ sourceAddress
17578
+ });
17579
+ const bridgeChainData = await getBridgeChainData({
17580
+ route,
17643
17581
  sourceAddress,
17644
- bridgeChainData
17582
+ destinationAddress
17645
17583
  });
17646
17584
  return {
17647
17585
  destination: destinationData,
@@ -17657,7 +17595,7 @@ async function getTransferData({
17657
17595
  });
17658
17596
  const result = bigAmount.minus(
17659
17597
  isSameAssetPayingDestinationFee ? destinationFee.toBig() : Big2(0)
17660
- ).minus(fee).minus(sourceData.extraFees.remote?.fee.toBig() || Big2(0));
17598
+ ).minus(fee).minus(sourceData.otherFees?.relayer?.toBig() || Big2(0));
17661
17599
  return sourceData.balance.copyWith({
17662
17600
  amount: result.lt(0) ? 0n : BigInt(result.toFixed())
17663
17601
  });
@@ -17692,8 +17630,7 @@ async function getTransferData({
17692
17630
  );
17693
17631
  const transfer = await buildTransfer({
17694
17632
  asset,
17695
- protocolFee: sourceData.extraFees.local?.fee,
17696
- bridgeChainFee: bridgeChainData.fee,
17633
+ protocolFee: sourceData.otherFees?.protocol,
17697
17634
  destinationAddress,
17698
17635
  feeAsset,
17699
17636
  isAutomatic: isAutomatic2,
@@ -17701,7 +17638,7 @@ async function getTransferData({
17701
17638
  sendOnlyRemoteExecution,
17702
17639
  sourceAddress
17703
17640
  });
17704
- if (ContractConfig3.is(transfer) && (EvmChain3.is(source) || EvmParachain3.is(source))) {
17641
+ if (ContractConfig3.is(transfer) && (EvmChain3.is(source) || EvmParachain4.is(source))) {
17705
17642
  if (!evmSigner) {
17706
17643
  throw new Error("EVM Signer must be provided");
17707
17644
  }
@@ -17709,7 +17646,7 @@ async function getTransferData({
17709
17646
  const hash = await evm.transfer(evmSigner, transfer);
17710
17647
  return [hash];
17711
17648
  }
17712
- if (ExtrinsicConfig.is(transfer) && EvmParachain3.isAnyParachain(source)) {
17649
+ if (ExtrinsicConfig.is(transfer) && EvmParachain4.isAnyParachain(source)) {
17713
17650
  if (!polkadotSigner) {
17714
17651
  throw new Error("Polkadot signer must be provided");
17715
17652
  }
@@ -17722,14 +17659,14 @@ async function getTransferData({
17722
17659
  );
17723
17660
  return [hash];
17724
17661
  }
17725
- if (WormholeConfig2.is(transfer) && (EvmChain3.is(source) || EvmParachain3.is(source))) {
17662
+ if (WormholeConfig2.is(transfer) && (EvmChain3.is(source) || EvmParachain4.is(source))) {
17726
17663
  if (!evmSigner) {
17727
17664
  throw new Error("EVM Signer must be provided");
17728
17665
  }
17729
17666
  const wh = WormholeService.create(source);
17730
17667
  return wh.transfer(evmSigner, transfer);
17731
17668
  }
17732
- if (SnowbridgeConfig2.is(transfer) && (EvmChain3.is(source) || EvmParachain3.is(source))) {
17669
+ if (SnowbridgeConfig2.is(transfer) && (EvmChain3.is(source) || EvmParachain4.is(source))) {
17733
17670
  if (!evmSigner) {
17734
17671
  throw new Error("EVM Signer must be provided");
17735
17672
  }