@moonbeam-network/mrl 1.0.0-dev.280 → 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 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 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";
@@ -16808,6 +16808,7 @@ 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";
16811
16812
  import { u8aToHex } from "@polkadot/util";
16812
16813
  import { decodeAddress } from "@polkadot/util-crypto";
16813
16814
  import { encodeFunctionData } from "viem";
@@ -16870,19 +16871,20 @@ var SnowbridgeService = class _SnowbridgeService {
16870
16871
  destinationParaId,
16871
16872
  amount,
16872
16873
  bridgeFeeAmount,
16874
+ bridgeChainFee,
16873
16875
  requiresApproval
16874
16876
  } = args;
16875
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)) };
16876
16880
  const contractArgs = [
16877
16881
  tokenAddress,
16878
16882
  destinationParaId,
16879
- {
16880
- kind: 1,
16881
- data: u8aToHex(decodeAddress(destinationAddress))
16882
- },
16883
- 0n,
16883
+ destination,
16884
+ bridgeChainFee,
16884
16885
  amount
16885
16886
  ];
16887
+ console.log("contractArgs", contractArgs);
16886
16888
  return new ContractConfig({
16887
16889
  address: this.#gatewayAddress,
16888
16890
  abi: GATEWAY_ABI,
@@ -16961,7 +16963,10 @@ var SnowbridgeService = class _SnowbridgeService {
16961
16963
  // src/getTransferData/getBridgeChainData.ts
16962
16964
  import { getBalance, getDestinationFee } from "@moonbeam-network/xcm-sdk";
16963
16965
  import { EvmParachain, Parachain } from "@moonbeam-network/xcm-types";
16964
- import { getMultilocationDerivedAddresses } from "@moonbeam-network/xcm-utils";
16966
+ import {
16967
+ getMultilocationDerivedAddresses,
16968
+ isEthAddress as isEthAddress2
16969
+ } from "@moonbeam-network/xcm-utils";
16965
16970
  import { evmToAddress } from "@polkadot/util-crypto";
16966
16971
  async function getBridgeChainData({
16967
16972
  route,
@@ -17018,6 +17023,10 @@ function getBridgeChainAddress({
17018
17023
  const isDestinationBridgeChain = bridgeChain.isEqual(destination);
17019
17024
  const isSourceBridgeChain = bridgeChain.isEqual(source);
17020
17025
  let bridgeChainAddress = isDestinationBridgeChain ? destinationAddress : sourceAddress;
17026
+ if (Parachain.isExactly(bridgeChain) && isEthAddress2(bridgeChainAddress)) {
17027
+ bridgeChainAddress = evmToAddress(bridgeChainAddress);
17028
+ return bridgeChainAddress;
17029
+ }
17021
17030
  if (Parachain.is(source) && !isSourceBridgeChain) {
17022
17031
  const isSourceEvmSigner = EvmParachain.is(source) && source.isEvmSigner;
17023
17032
  const { address20: computedOriginAccount } = getMultilocationDerivedAddresses({
@@ -17052,8 +17061,7 @@ import {
17052
17061
  } from "@moonbeam-network/xcm-sdk";
17053
17062
  import {
17054
17063
  AssetAmount as AssetAmount2,
17055
- EvmChain as EvmChain2,
17056
- EvmParachain as EvmParachain3
17064
+ EvmChain as EvmChain2
17057
17065
  } from "@moonbeam-network/xcm-types";
17058
17066
  import { toBigInt as toBigInt2 } from "@moonbeam-network/xcm-utils";
17059
17067
 
@@ -17152,6 +17160,7 @@ async function buildTransfer(params) {
17152
17160
  async function getMrlBuilderParams({
17153
17161
  asset,
17154
17162
  protocolFee,
17163
+ bridgeChainFee,
17155
17164
  destinationAddress,
17156
17165
  feeAsset,
17157
17166
  isAutomatic,
@@ -17175,6 +17184,7 @@ async function getMrlBuilderParams({
17175
17184
  return {
17176
17185
  asset,
17177
17186
  protocolFee,
17187
+ bridgeChainFee,
17178
17188
  destination,
17179
17189
  destinationAddress,
17180
17190
  destinationApi,
@@ -17267,6 +17277,9 @@ async function getBridgeChainGasLimit(params) {
17267
17277
  return gasEstimation * 110n / 100n;
17268
17278
  }
17269
17279
  function getAmountForTransferSimulation(balance, protocolFee) {
17280
+ if (!protocolFee) {
17281
+ return balance;
17282
+ }
17270
17283
  return balance.copyWith({
17271
17284
  amount: balance.amount - protocolFee.amount > 0 ? balance.amount - protocolFee.amount : 0n
17272
17285
  });
@@ -17278,7 +17291,8 @@ async function getSourceData({
17278
17291
  route,
17279
17292
  destinationAddress,
17280
17293
  destinationFee,
17281
- sourceAddress
17294
+ sourceAddress,
17295
+ bridgeChainData
17282
17296
  }) {
17283
17297
  if (!route.mrl) {
17284
17298
  throw new Error(
@@ -17287,6 +17301,7 @@ async function getSourceData({
17287
17301
  }
17288
17302
  const source = route.source.chain;
17289
17303
  const destination = route.destination.chain;
17304
+ const bridgeChain = route.mrl.bridgeChain.chain;
17290
17305
  const asset = source.getChainAsset(route.source.asset);
17291
17306
  const feeAsset = route.source.fee ? source.getChainAsset(route.source.fee.asset) : asset;
17292
17307
  const balance = await getBalance2({
@@ -17326,11 +17341,21 @@ async function getSourceData({
17326
17341
  feeAsset,
17327
17342
  balance,
17328
17343
  protocolFee: route.source.protocolFee,
17329
- address: destinationAddress
17344
+ address: destinationAddress,
17345
+ bridgeChain,
17346
+ bridgeChainFee: bridgeChainData.fee
17330
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;
17331
17355
  const transfer = await buildTransfer({
17332
17356
  asset: getAmountForTransferSimulation(balance, protocolFee),
17333
17357
  protocolFee,
17358
+ bridgeChainFee: bridgeChainData.fee,
17334
17359
  destinationAddress,
17335
17360
  feeAsset: feeBalance,
17336
17361
  isAutomatic,
@@ -17354,7 +17379,8 @@ async function getSourceData({
17354
17379
  isAutomatic,
17355
17380
  destinationAddress,
17356
17381
  route,
17357
- sourceAddress
17382
+ sourceAddress,
17383
+ bridgeChainFee: bridgeChainData.fee
17358
17384
  });
17359
17385
  const max = getMax({
17360
17386
  balance,
@@ -17368,6 +17394,7 @@ async function getSourceData({
17368
17394
  destinationFee,
17369
17395
  destinationFeeBalance,
17370
17396
  bridgeChainFeeBalance,
17397
+ protocolFeeBalance,
17371
17398
  existentialDeposit,
17372
17399
  fee,
17373
17400
  feeBalance,
@@ -17438,7 +17465,8 @@ async function getRelayerFee({
17438
17465
  isAutomatic,
17439
17466
  route,
17440
17467
  sourceAddress,
17441
- transfer
17468
+ transfer,
17469
+ bridgeChainFee
17442
17470
  }) {
17443
17471
  if (route.mrl.transfer.provider === Provider2.Snowbridge || SnowbridgeConfig.is(transfer)) {
17444
17472
  return void 0;
@@ -17453,7 +17481,8 @@ async function getRelayerFee({
17453
17481
  feeAsset,
17454
17482
  isAutomatic,
17455
17483
  route,
17456
- sourceAddress
17484
+ sourceAddress,
17485
+ bridgeChainFee
17457
17486
  });
17458
17487
  const wormholeConfig = MrlBuilder3().wormhole().wormhole().tokenTransfer().build(builderParams);
17459
17488
  return getWormholeFee({ asset, chain: chain2, config: wormholeConfig });
@@ -17509,20 +17538,27 @@ async function getProtocolFee({
17509
17538
  balance,
17510
17539
  protocolFee,
17511
17540
  destination,
17512
- source
17541
+ source,
17542
+ bridgeChain,
17543
+ bridgeChainFee
17513
17544
  }) {
17514
- if (typeof protocolFee === "number") {
17515
- return AssetAmount2.fromChainAsset(asset, {
17516
- amount: protocolFee
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
17517
17552
  });
17518
17553
  }
17519
- const config = protocolFee?.build({
17554
+ const config = protocolFee?.amount?.build({
17520
17555
  address,
17521
17556
  asset,
17522
- feeAsset,
17557
+ feeAsset: protocolFeeAsset,
17523
17558
  balance,
17524
17559
  destination,
17525
- source
17560
+ source,
17561
+ bridgeChainFee
17526
17562
  });
17527
17563
  if (ContractConfig2.is(config) && EvmChain2.is(source)) {
17528
17564
  const evm = EvmService3.create(source);
@@ -17536,8 +17572,8 @@ async function getProtocolFee({
17536
17572
  amount
17537
17573
  });
17538
17574
  }
17539
- if (SubstrateQueryConfig.is(config) && EvmParachain3.isAnyParachain(source)) {
17540
- const polkadot = await PolkadotService2.create(source);
17575
+ if (SubstrateQueryConfig.is(config)) {
17576
+ const polkadot = await PolkadotService2.create(bridgeChain);
17541
17577
  const amount = await polkadot.query(config);
17542
17578
  return AssetAmount2.fromChainAsset(feeAsset, {
17543
17579
  amount
@@ -17568,17 +17604,18 @@ async function getTransferData({
17568
17604
  asset: destinationData.fee,
17569
17605
  target: route.getDestinationFeeAssetOnSource()
17570
17606
  });
17607
+ const bridgeChainData = await getBridgeChainData({
17608
+ route,
17609
+ sourceAddress,
17610
+ destinationAddress
17611
+ });
17571
17612
  const sourceData = await getSourceData({
17572
17613
  isAutomatic: route.mrl.isAutomaticPossible && isAutomatic,
17573
17614
  route,
17574
17615
  destinationAddress,
17575
17616
  destinationFee,
17576
- sourceAddress
17577
- });
17578
- const bridgeChainData = await getBridgeChainData({
17579
- route,
17580
17617
  sourceAddress,
17581
- destinationAddress
17618
+ bridgeChainData
17582
17619
  });
17583
17620
  return {
17584
17621
  destination: destinationData,
@@ -17630,6 +17667,7 @@ async function getTransferData({
17630
17667
  const transfer = await buildTransfer({
17631
17668
  asset,
17632
17669
  protocolFee: sourceData.otherFees?.protocol,
17670
+ bridgeChainFee: bridgeChainData.fee,
17633
17671
  destinationAddress,
17634
17672
  feeAsset,
17635
17673
  isAutomatic: isAutomatic2,
@@ -17637,7 +17675,7 @@ async function getTransferData({
17637
17675
  sendOnlyRemoteExecution,
17638
17676
  sourceAddress
17639
17677
  });
17640
- if (ContractConfig3.is(transfer) && (EvmChain3.is(source) || EvmParachain4.is(source))) {
17678
+ if (ContractConfig3.is(transfer) && (EvmChain3.is(source) || EvmParachain3.is(source))) {
17641
17679
  if (!evmSigner) {
17642
17680
  throw new Error("EVM Signer must be provided");
17643
17681
  }
@@ -17645,7 +17683,7 @@ async function getTransferData({
17645
17683
  const hash = await evm.transfer(evmSigner, transfer);
17646
17684
  return [hash];
17647
17685
  }
17648
- if (ExtrinsicConfig.is(transfer) && EvmParachain4.isAnyParachain(source)) {
17686
+ if (ExtrinsicConfig.is(transfer) && EvmParachain3.isAnyParachain(source)) {
17649
17687
  if (!polkadotSigner) {
17650
17688
  throw new Error("Polkadot signer must be provided");
17651
17689
  }
@@ -17658,14 +17696,14 @@ async function getTransferData({
17658
17696
  );
17659
17697
  return [hash];
17660
17698
  }
17661
- if (WormholeConfig2.is(transfer) && (EvmChain3.is(source) || EvmParachain4.is(source))) {
17699
+ if (WormholeConfig2.is(transfer) && (EvmChain3.is(source) || EvmParachain3.is(source))) {
17662
17700
  if (!evmSigner) {
17663
17701
  throw new Error("EVM Signer must be provided");
17664
17702
  }
17665
17703
  const wh = WormholeService.create(source);
17666
17704
  return wh.transfer(evmSigner, transfer);
17667
17705
  }
17668
- if (SnowbridgeConfig2.is(transfer) && (EvmChain3.is(source) || EvmParachain4.is(source))) {
17706
+ if (SnowbridgeConfig2.is(transfer) && (EvmChain3.is(source) || EvmParachain3.is(source))) {
17669
17707
  if (!evmSigner) {
17670
17708
  throw new Error("EVM Signer must be provided");
17671
17709
  }