@moonbeam-network/mrl 1.0.0-dev.268 → 1.0.0-dev.269

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.mjs CHANGED
@@ -16755,189 +16755,34 @@ async function getExecuteTransferData({
16755
16755
 
16756
16756
  // src/getTransferData/getTransferData.ts
16757
16757
  import {
16758
- ContractConfig as ContractConfig3,
16758
+ ContractConfig as ContractConfig2,
16759
16759
  ExtrinsicConfig,
16760
- SnowbridgeConfig as SnowbridgeConfig2,
16761
16760
  WormholeConfig as WormholeConfig2
16762
16761
  } from "@moonbeam-network/xcm-builder";
16763
16762
  import {
16764
16763
  convertToChainDecimals as convertToChainDecimals2,
16765
- EvmService as EvmService4,
16764
+ EvmService as EvmService2,
16766
16765
  getDestinationData,
16767
- PolkadotService as PolkadotService3
16766
+ PolkadotService as PolkadotService2
16768
16767
  } from "@moonbeam-network/xcm-sdk";
16769
16768
  import {
16770
16769
  AssetAmount as AssetAmount3,
16771
- EvmChain as EvmChain3,
16772
- EvmParachain as EvmParachain4
16770
+ EvmChain,
16771
+ EvmParachain as EvmParachain3
16773
16772
  } from "@moonbeam-network/xcm-types";
16774
16773
  import { toBigInt as toBigInt3 } from "@moonbeam-network/xcm-utils";
16775
16774
  import Big2 from "big.js";
16776
16775
 
16777
- // src/services/snowbridge/SnowbridgeService.ts
16778
- import {
16779
- ContractConfig,
16780
- ERC20_ABI,
16781
- GATEWAY_ABI
16782
- } from "@moonbeam-network/xcm-builder";
16783
- import { EvmService as EvmService2 } from "@moonbeam-network/xcm-sdk";
16784
- import { EvmChain } from "@moonbeam-network/xcm-types";
16785
- import { u8aToHex } from "@polkadot/util";
16786
- import { decodeAddress } from "@polkadot/util-crypto";
16787
- import { encodeFunctionData } from "viem";
16788
- var SnowbridgeService = class _SnowbridgeService {
16789
- chain;
16790
- #evmService;
16791
- #gatewayAddress;
16792
- static create(chain2) {
16793
- return new _SnowbridgeService(chain2);
16794
- }
16795
- constructor(chain2) {
16796
- if (!EvmChain.is(chain2) || !chain2.contracts?.Gateway) {
16797
- throw new Error(
16798
- "Chain must be an EVMChain with the Gateway contract address configured for Snowbridge operations"
16799
- );
16800
- }
16801
- this.chain = chain2;
16802
- this.#gatewayAddress = chain2.contracts.Gateway;
16803
- this.#evmService = EvmService2.create(chain2);
16804
- }
16805
- async checkAllowance(ownerAddress, tokenAddress, spenderAddress) {
16806
- const allowance = await this.#evmService.client.readContract({
16807
- abi: ERC20_ABI,
16808
- address: tokenAddress,
16809
- args: [ownerAddress, spenderAddress],
16810
- functionName: "allowance"
16811
- });
16812
- if (typeof allowance !== "bigint") {
16813
- throw new Error(
16814
- `Could not get allowance on ${this.chain.name} for token ${tokenAddress}`
16815
- );
16816
- }
16817
- return allowance;
16818
- }
16819
- async transfer(signer, transfer) {
16820
- const { args } = transfer;
16821
- const { tokenAddress, amount, requiresApproval } = args;
16822
- if (!signer.account) {
16823
- throw new Error("Signer account is required");
16824
- }
16825
- const contract = this.buildContractConfig(transfer);
16826
- if (!requiresApproval) {
16827
- return await this.#evmService.transfer(signer, contract);
16828
- }
16829
- const currentAllowance = await this.checkAllowance(
16830
- signer.account.address,
16831
- tokenAddress,
16832
- this.#gatewayAddress
16833
- );
16834
- if (currentAllowance < amount) {
16835
- await this.approve(signer, tokenAddress, this.#gatewayAddress, amount);
16836
- }
16837
- return await this.#evmService.transfer(signer, contract);
16838
- }
16839
- buildContractConfig(transfer) {
16840
- const { args } = transfer;
16841
- const {
16842
- tokenAddress,
16843
- destinationAddress,
16844
- destinationParaId,
16845
- amount,
16846
- bridgeFeeAmount,
16847
- requiresApproval
16848
- } = args;
16849
- const value = requiresApproval ? bridgeFeeAmount : amount + bridgeFeeAmount;
16850
- const contractArgs = [
16851
- tokenAddress,
16852
- destinationParaId,
16853
- {
16854
- kind: 1,
16855
- data: u8aToHex(decodeAddress(destinationAddress))
16856
- },
16857
- 0n,
16858
- amount
16859
- ];
16860
- return new ContractConfig({
16861
- address: this.#gatewayAddress,
16862
- abi: GATEWAY_ABI,
16863
- args: contractArgs,
16864
- func: "sendToken",
16865
- value,
16866
- module: "Gateway"
16867
- });
16868
- }
16869
- async approve(signer, tokenAddress, spenderAddress, amount) {
16870
- const { request } = await this.#evmService.client.simulateContract({
16871
- abi: ERC20_ABI,
16872
- account: signer.account,
16873
- address: tokenAddress,
16874
- functionName: "approve",
16875
- args: [spenderAddress, amount]
16876
- });
16877
- const hash = await signer.writeContract(request);
16878
- await this.#evmService.client.waitForTransactionReceipt({
16879
- hash
16880
- });
16881
- return hash;
16882
- }
16883
- async getFee(address, transfer) {
16884
- const { args } = transfer;
16885
- const { tokenAddress, amount, requiresApproval } = args;
16886
- const contract = this.buildContractConfig(transfer);
16887
- if (!requiresApproval) {
16888
- return await this.#evmService.getFee(address, contract);
16889
- }
16890
- const currentAllowance = await this.checkAllowance(
16891
- address,
16892
- tokenAddress,
16893
- this.#gatewayAddress
16894
- );
16895
- if (currentAllowance >= amount) {
16896
- return await this.#evmService.getFee(address, contract);
16897
- }
16898
- return await this.estimateApproveAndSendFee(address, transfer);
16899
- }
16900
- async estimateApproveAndSendFee(address, transfer) {
16901
- const { args } = transfer;
16902
- const { tokenAddress, amount } = args;
16903
- const contract = this.buildContractConfig(transfer);
16904
- try {
16905
- const approveData = encodeFunctionData({
16906
- abi: ERC20_ABI,
16907
- functionName: "approve",
16908
- args: [this.#gatewayAddress, amount]
16909
- });
16910
- const approveGas = await this.#evmService.client.estimateGas({
16911
- account: address,
16912
- to: tokenAddress,
16913
- data: approveData
16914
- });
16915
- const sendData = encodeFunctionData({
16916
- abi: contract.abi,
16917
- functionName: contract.func,
16918
- args: contract.args
16919
- });
16920
- const sendGas = await this.#evmService.client.estimateGas({
16921
- account: address,
16922
- to: contract.address,
16923
- data: sendData,
16924
- value: contract.value
16925
- });
16926
- const gasPrice = await this.#evmService.client.getGasPrice();
16927
- return (approveGas + sendGas) * gasPrice;
16928
- } catch (error) {
16929
- console.error("Error estimating approve + send fee:", error);
16930
- return 0n;
16931
- }
16932
- }
16933
- };
16934
-
16935
- // src/getTransferData/getBridgeChainData.ts
16776
+ // src/getTransferData/getMoonChainData.ts
16777
+ import { getMoonChain } from "@moonbeam-network/xcm-config";
16936
16778
  import { getBalance, getDestinationFee } from "@moonbeam-network/xcm-sdk";
16937
- import { EvmParachain, Parachain } from "@moonbeam-network/xcm-types";
16779
+ import {
16780
+ EvmParachain,
16781
+ Parachain
16782
+ } from "@moonbeam-network/xcm-types";
16938
16783
  import { getMultilocationDerivedAddresses } from "@moonbeam-network/xcm-utils";
16939
16784
  import { evmToAddress } from "@polkadot/util-crypto";
16940
- async function getBridgeChainData({
16785
+ async function getMoonChainData({
16941
16786
  route,
16942
16787
  sourceAddress,
16943
16788
  destinationAddress
@@ -16947,86 +16792,80 @@ async function getBridgeChainData({
16947
16792
  `MRL config is not defined for source chain ${route.source.chain.name} and asset ${route.source.asset.originSymbol}`
16948
16793
  );
16949
16794
  }
16950
- const bridgeChain = route.mrl.bridgeChain.chain;
16951
- const bridgeChainAddress = getBridgeChainAddress({
16952
- route,
16795
+ const moonChain = getMoonChain(route.source.chain);
16796
+ const moonChainAddress = getMoonChainAddress({
16797
+ source: route.source.chain,
16798
+ destination: route.destination.chain,
16953
16799
  sourceAddress,
16954
16800
  destinationAddress
16955
16801
  });
16956
16802
  const fee = await getDestinationFee({
16957
- address: bridgeChainAddress,
16803
+ address: moonChainAddress,
16958
16804
  asset: route.source.asset,
16959
- destination: bridgeChain,
16960
- fee: route.mrl.bridgeChain.fee.amount,
16961
- feeAsset: route.mrl.bridgeChain.fee.asset,
16805
+ destination: moonChain,
16806
+ fee: route.mrl.moonChain.fee.amount,
16807
+ feeAsset: route.mrl.moonChain.fee.asset,
16962
16808
  source: route.source.chain
16963
16809
  });
16964
16810
  const balance = await getBalance({
16965
- address: bridgeChainAddress,
16966
- asset: bridgeChain.getChainAsset(route.mrl.bridgeChain.asset),
16967
- builder: route.mrl.bridgeChain.balance,
16968
- chain: bridgeChain
16811
+ address: moonChainAddress,
16812
+ asset: moonChain.getChainAsset(route.mrl.moonChain.asset),
16813
+ builder: route.mrl.moonChain.balance,
16814
+ chain: moonChain
16969
16815
  });
16970
16816
  const feeBalance = await getBalance({
16971
- address: bridgeChainAddress,
16972
- asset: bridgeChain.getChainAsset(route.mrl.bridgeChain.fee.asset),
16973
- builder: route.mrl.bridgeChain.fee.balance,
16974
- chain: bridgeChain
16817
+ address: moonChainAddress,
16818
+ asset: moonChain.getChainAsset(route.mrl.moonChain.fee.asset),
16819
+ builder: route.mrl.moonChain.fee.balance,
16820
+ chain: moonChain
16975
16821
  });
16976
16822
  return {
16977
- address: bridgeChainAddress,
16823
+ address: moonChainAddress,
16978
16824
  balance,
16979
16825
  feeBalance,
16980
- chain: bridgeChain,
16826
+ chain: moonChain,
16981
16827
  fee
16982
16828
  };
16983
16829
  }
16984
- function getBridgeChainAddress({
16985
- route,
16830
+ function getMoonChainAddress({
16831
+ source,
16832
+ destination,
16986
16833
  sourceAddress,
16987
16834
  destinationAddress
16988
16835
  }) {
16989
- const source = route.source.chain;
16990
- const destination = route.destination.chain;
16991
- const bridgeChain = route.mrl.bridgeChain.chain;
16992
- const isDestinationBridgeChain = bridgeChain.isEqual(destination);
16993
- const isSourceBridgeChain = bridgeChain.isEqual(source);
16994
- let bridgeChainAddress = isDestinationBridgeChain ? destinationAddress : sourceAddress;
16995
- if (Parachain.is(source) && !isSourceBridgeChain) {
16836
+ const moonChain = getMoonChain(source);
16837
+ const isDestinationMoonChain = moonChain.isEqual(destination);
16838
+ const isSourceMoonChain = moonChain.isEqual(source);
16839
+ let moonChainAddress = isDestinationMoonChain ? destinationAddress : sourceAddress;
16840
+ if (Parachain.is(source) && !isSourceMoonChain) {
16996
16841
  const isSourceEvmSigner = EvmParachain.is(source) && source.isEvmSigner;
16997
16842
  const { address20: computedOriginAccount } = getMultilocationDerivedAddresses({
16998
16843
  address: isSourceEvmSigner ? evmToAddress(sourceAddress) : sourceAddress,
16999
16844
  paraId: source.parachainId,
17000
16845
  isParents: true
17001
16846
  });
17002
- bridgeChainAddress = computedOriginAccount;
16847
+ moonChainAddress = computedOriginAccount;
17003
16848
  }
17004
- return bridgeChainAddress;
16849
+ return moonChainAddress;
17005
16850
  }
17006
16851
 
17007
16852
  // src/getTransferData/getSourceData.ts
17008
16853
  import {
17009
- ContractConfig as ContractConfig2,
16854
+ ContractConfig,
17010
16855
  MrlBuilder as MrlBuilder3,
17011
- SnowbridgeConfig,
17012
- SubstrateQueryConfig,
17013
16856
  WormholeConfig
17014
16857
  } from "@moonbeam-network/xcm-builder";
17015
16858
  import {
17016
- EvmService as EvmService3,
17017
16859
  getAssetMin,
17018
16860
  getBalance as getBalance2,
17019
16861
  getContractFee,
17020
16862
  getDestinationFeeBalance,
17021
16863
  getExistentialDeposit,
17022
16864
  getExtrinsicFee,
17023
- getMax,
17024
- PolkadotService as PolkadotService2
16865
+ getMax
17025
16866
  } from "@moonbeam-network/xcm-sdk";
17026
16867
  import {
17027
- AssetAmount as AssetAmount2,
17028
- EvmChain as EvmChain2,
17029
- EvmParachain as EvmParachain3
16868
+ AssetAmount as AssetAmount2
17030
16869
  } from "@moonbeam-network/xcm-types";
17031
16870
  import { toBigInt as toBigInt2 } from "@moonbeam-network/xcm-utils";
17032
16871
 
@@ -17034,12 +16873,14 @@ import { toBigInt as toBigInt2 } from "@moonbeam-network/xcm-utils";
17034
16873
  import {
17035
16874
  BATCH_CONTRACT_ABI,
17036
16875
  BATCH_CONTRACT_ADDRESS,
17037
- ERC20_ABI as ERC20_ABI2,
16876
+ ERC20_ABI,
17038
16877
  MrlBuilder as MrlBuilder2
17039
16878
  } from "@moonbeam-network/xcm-builder";
17040
16879
  import {
16880
+ getMoonChain as getMoonChain2,
17041
16881
  moonbaseAlpha,
17042
- moonbeam
16882
+ moonbeam,
16883
+ moonriver
17043
16884
  } from "@moonbeam-network/xcm-config";
17044
16885
  import {
17045
16886
  convertToChainDecimals,
@@ -17054,33 +16895,34 @@ import {
17054
16895
  import Big from "big.js";
17055
16896
  import {
17056
16897
  createPublicClient as createPublicClient2,
17057
- encodeFunctionData as encodeFunctionData2,
16898
+ encodeFunctionData,
17058
16899
  http as http2
17059
16900
  } from "viem";
17060
16901
  var MOON_CHAIN_AUTOMATIC_GAS_ESTIMATION = {
17061
16902
  [moonbeam.key]: 1273110n,
16903
+ [moonriver.key]: 1273110n,
17062
16904
  [moonbaseAlpha.key]: 1470417n
17063
16905
  };
17064
- function getBridgeChainFeeValueOnSource({
16906
+ function getMoonChainFeeValueOnSource({
17065
16907
  destinationData,
17066
- bridgeChainData,
16908
+ moonChainData,
17067
16909
  sourceData
17068
16910
  }) {
17069
16911
  const isSourceParachain = EvmParachain2.isAnyParachain(sourceData.chain);
17070
- const isDestinationBridgeChain = destinationData.chain.isEqual(
17071
- bridgeChainData.chain
16912
+ const isDestinationMoonChain = destinationData.chain.isEqual(
16913
+ moonChainData.chain
17072
16914
  );
17073
- const isSameAssetPayingBridgeChainFee = sourceData.balance.isSame(
17074
- bridgeChainData.fee
16915
+ const isSameAssetPayingMoonChainFee = sourceData.balance.isSame(
16916
+ moonChainData.fee
17075
16917
  );
17076
- return !isDestinationBridgeChain && isSourceParachain && isSameAssetPayingBridgeChainFee ? convertToChainDecimals({
17077
- asset: bridgeChainData.fee,
17078
- target: sourceData.chain.getChainAsset(bridgeChainData.fee)
16918
+ return !isDestinationMoonChain && isSourceParachain && isSameAssetPayingMoonChainFee ? convertToChainDecimals({
16919
+ asset: moonChainData.fee,
16920
+ target: sourceData.chain.getChainAsset(moonChainData.fee)
17079
16921
  }).toBig() : Big(0);
17080
16922
  }
17081
16923
  function getMrlMin({
17082
16924
  destinationData,
17083
- bridgeChainData,
16925
+ moonChainData,
17084
16926
  sourceData
17085
16927
  }) {
17086
16928
  const minInDestination = getMin(destinationData);
@@ -17090,19 +16932,16 @@ function getMrlMin({
17090
16932
  amount: minInDestination.amount
17091
16933
  }
17092
16934
  );
17093
- const bridgeChainFee = getBridgeChainFeeValueOnSource({
16935
+ const moonChainFee = getMoonChainFeeValueOnSource({
17094
16936
  destinationData,
17095
- bridgeChainData,
16937
+ moonChainData,
17096
16938
  sourceData
17097
16939
  });
17098
- const relayerFee = sourceData.otherFees?.relayer?.amount ? sourceData.otherFees.relayer.toBig() : Big(0);
16940
+ const relayerFee = sourceData.relayerFee?.amount ? sourceData.relayerFee.toBig() : Big(0);
17099
16941
  return min.copyWith({
17100
- amount: BigInt(min.toBig().add(bridgeChainFee).add(relayerFee).toFixed())
16942
+ amount: BigInt(min.toBig().add(moonChainFee).add(relayerFee).toFixed())
17101
16943
  });
17102
16944
  }
17103
- function requiresTransact(route) {
17104
- return route.mrl?.transfer.provider === "wormhole" && EvmParachain2.isAnyParachain(route.source.chain);
17105
- }
17106
16945
  async function buildTransfer(params) {
17107
16946
  const { route } = params;
17108
16947
  if (!route.mrl) {
@@ -17118,12 +16957,11 @@ async function buildTransfer(params) {
17118
16957
  const builderParams = await getMrlBuilderParams(params);
17119
16958
  return route.mrl.transfer.build({
17120
16959
  ...builderParams,
17121
- transact: requiresTransact(route) ? await getTransact(builderParams) : void 0
16960
+ transact: EvmParachain2.isAnyParachain(route.source.chain) ? await getTransact(builderParams) : void 0
17122
16961
  });
17123
16962
  }
17124
16963
  async function getMrlBuilderParams({
17125
16964
  asset,
17126
- protocolFee,
17127
16965
  destinationAddress,
17128
16966
  feeAsset,
17129
16967
  isAutomatic,
@@ -17138,23 +16976,22 @@ async function getMrlBuilderParams({
17138
16976
  }
17139
16977
  const source = route.source.chain;
17140
16978
  const destination = route.destination.chain;
17141
- const bridgeChain = route.mrl.bridgeChain.chain;
17142
- const [sourceApi, destinationApi, bridgeApi] = await Promise.all([
16979
+ const moonChain = getMoonChain2(source);
16980
+ const [sourceApi, destinationApi, moonApi] = await Promise.all([
17143
16981
  EvmParachain2.isAnyParachain(source) ? getPolkadotApi(source.ws) : void 0,
17144
16982
  EvmParachain2.isAnyParachain(destination) ? getPolkadotApi(destination.ws) : void 0,
17145
- getPolkadotApi(bridgeChain.ws)
16983
+ getPolkadotApi(moonChain.ws)
17146
16984
  ]);
17147
16985
  return {
17148
16986
  asset,
17149
- protocolFee,
17150
16987
  destination,
17151
16988
  destinationAddress,
17152
16989
  destinationApi,
17153
16990
  fee: feeAsset,
17154
16991
  isAutomatic,
17155
- moonApi: bridgeApi,
17156
- moonAsset: bridgeChain.nativeAsset,
17157
- bridgeChain,
16992
+ moonApi,
16993
+ moonAsset: moonChain.nativeAsset,
16994
+ moonChain,
17158
16995
  sendOnlyRemoteExecution,
17159
16996
  source,
17160
16997
  sourceAddress,
@@ -17162,9 +16999,9 @@ async function getMrlBuilderParams({
17162
16999
  };
17163
17000
  }
17164
17001
  async function getTransact(params) {
17165
- const { sourceAddress, source, bridgeChain } = params;
17166
- const polkadot = await PolkadotService.create(bridgeChain);
17167
- const bridgeChainGasLimit = await getBridgeChainGasLimit(params);
17002
+ const { sourceAddress, source, moonChain } = params;
17003
+ const polkadot = await PolkadotService.create(moonChain);
17004
+ const moonGasLimit = await getMoonGasLimit(params);
17168
17005
  if (!EvmParachain2.isAnyParachain(source)) {
17169
17006
  throw new Error("Source chain must be Parachain or EvmParachain");
17170
17007
  }
@@ -17173,8 +17010,9 @@ async function getTransact(params) {
17173
17010
  paraId: source.parachainId,
17174
17011
  isParents: true
17175
17012
  });
17176
- const extrinsic = MrlBuilder2().wormhole().extrinsic().ethereumXcm().transact().build({ ...params, bridgeChainGasLimit });
17013
+ const extrinsic = MrlBuilder2().wormhole().extrinsic().ethereumXcm().transact().build({ ...params, moonGasLimit });
17177
17014
  const { weight } = await polkadot.getPaymentInfo(address20, extrinsic);
17015
+ console.log("extrinsic", extrinsic.getArgs());
17178
17016
  return {
17179
17017
  call: polkadot.getExtrinsicCallHash(extrinsic),
17180
17018
  txWeight: {
@@ -17183,16 +17021,13 @@ async function getTransact(params) {
17183
17021
  }
17184
17022
  };
17185
17023
  }
17186
- async function getBridgeChainGasLimit(params) {
17187
- const { asset, isAutomatic, bridgeChain, source, sourceAddress } = params;
17024
+ async function getMoonGasLimit(params) {
17025
+ const { asset, isAutomatic, moonChain, source, sourceAddress } = params;
17188
17026
  if (!EvmParachain2.isAnyParachain(source)) {
17189
17027
  throw new Error("Source chain must be Parachain or EvmParachain");
17190
17028
  }
17191
- if (!EvmParachain2.is(bridgeChain)) {
17192
- throw new Error("Bridge chain must be an EvmParachain");
17193
- }
17194
17029
  const client = createPublicClient2({
17195
- chain: bridgeChain.getViemChain(),
17030
+ chain: moonChain.getViemChain(),
17196
17031
  transport: http2()
17197
17032
  });
17198
17033
  const { address20 } = getMultilocationDerivedAddresses2({
@@ -17201,28 +17036,28 @@ async function getBridgeChainGasLimit(params) {
17201
17036
  isParents: true
17202
17037
  });
17203
17038
  if (isAutomatic) {
17204
- return MOON_CHAIN_AUTOMATIC_GAS_ESTIMATION[bridgeChain.key] * 110n / 100n;
17039
+ return MOON_CHAIN_AUTOMATIC_GAS_ESTIMATION[moonChain.key] * 110n / 100n;
17205
17040
  }
17206
17041
  const contract = MrlBuilder2().wormhole().contract().TokenBridge().transferTokens().build({
17207
17042
  ...params,
17208
17043
  asset: asset.copyWith({ amount: 0n })
17209
17044
  });
17210
- const approveTx = encodeFunctionData2({
17211
- abi: ERC20_ABI2,
17045
+ const approveTx = encodeFunctionData({
17046
+ abi: ERC20_ABI,
17212
17047
  functionName: "approve",
17213
17048
  args: [contract.address, 0n]
17214
17049
  });
17215
- const tokenAddressOnBridgeChain = bridgeChain.getChainAsset(asset).address;
17216
- if (!tokenAddressOnBridgeChain) {
17050
+ const tokenAddressOnMoonChain = moonChain.getChainAsset(asset).address;
17051
+ if (!tokenAddressOnMoonChain) {
17217
17052
  throw new Error(
17218
- `Asset ${asset.symbol} does not have a token address on chain ${bridgeChain.name}`
17053
+ `Asset ${asset.symbol} does not have a token address on chain ${moonChain.name}`
17219
17054
  );
17220
17055
  }
17221
- const batchAll = encodeFunctionData2({
17056
+ const batchAll = encodeFunctionData({
17222
17057
  abi: BATCH_CONTRACT_ABI,
17223
17058
  functionName: "batchAll",
17224
17059
  args: [
17225
- [tokenAddressOnBridgeChain, contract.address],
17060
+ [tokenAddressOnMoonChain, contract.address],
17226
17061
  [0n, 0n],
17227
17062
  // Value to send for each call
17228
17063
  [approveTx, contract.encodeFunctionData()],
@@ -17253,7 +17088,6 @@ async function getSourceData({
17253
17088
  );
17254
17089
  }
17255
17090
  const source = route.source.chain;
17256
- const destination = route.destination.chain;
17257
17091
  const asset = source.getChainAsset(route.source.asset);
17258
17092
  const feeAsset = route.source.fee ? source.getChainAsset(route.source.fee.asset) : asset;
17259
17093
  const balance = await getBalance2({
@@ -17274,7 +17108,7 @@ async function getSourceData({
17274
17108
  route,
17275
17109
  sourceAddress
17276
17110
  });
17277
- const bridgeChainFeeBalance = await getBridgeChainFeeBalance({
17111
+ const moonChainFeeBalance = await getMoonChainFeeBalance({
17278
17112
  balance,
17279
17113
  feeBalance,
17280
17114
  route,
@@ -17286,19 +17120,8 @@ async function getSourceData({
17286
17120
  builder: route.source.min,
17287
17121
  chain: source
17288
17122
  });
17289
- const protocolFee = await getProtocolFee({
17290
- source,
17291
- destination,
17292
- // For now, the fee asset is always the one used for the protocol fee
17293
- // If it where to change, we need make protocolFee a FeeConfig in MrlSourceConfig
17294
- asset: feeAsset,
17295
- balance,
17296
- protocolFee: route.source.protocolFee,
17297
- address: destinationAddress
17298
- });
17299
17123
  const transfer = await buildTransfer({
17300
- asset: balance.copyWith({ amount: balance.amount - protocolFee.amount }),
17301
- protocolFee,
17124
+ asset: balance,
17302
17125
  destinationAddress,
17303
17126
  feeAsset: feeBalance,
17304
17127
  isAutomatic,
@@ -17335,16 +17158,13 @@ async function getSourceData({
17335
17158
  chain: source,
17336
17159
  destinationFee,
17337
17160
  destinationFeeBalance,
17338
- bridgeChainFeeBalance,
17161
+ moonChainFeeBalance,
17339
17162
  existentialDeposit,
17340
17163
  fee,
17341
17164
  feeBalance,
17342
17165
  max,
17343
17166
  min,
17344
- otherFees: {
17345
- protocol: protocolFee,
17346
- relayer: relayerFee?.amount ? relayerFee : void 0
17347
- }
17167
+ relayerFee
17348
17168
  };
17349
17169
  }
17350
17170
  async function getFee({
@@ -17361,29 +17181,17 @@ async function getFee({
17361
17181
  amount: 0n
17362
17182
  });
17363
17183
  }
17364
- if (SnowbridgeConfig.is(transfer)) {
17365
- const snowbridge = SnowbridgeService.create(chain2);
17366
- const feeAmount = await snowbridge.getFee(sourceAddress, transfer);
17367
- return AssetAmount2.fromChainAsset(chain2.getChainAsset(feeBalance), {
17368
- amount: feeAmount
17184
+ if (ContractConfig.is(transfer)) {
17185
+ return getContractFee({
17186
+ address: sourceAddress,
17187
+ balance,
17188
+ chain: chain2,
17189
+ contract: transfer,
17190
+ destinationFee,
17191
+ feeBalance,
17192
+ feeConfig
17369
17193
  });
17370
17194
  }
17371
- if (ContractConfig2.is(transfer)) {
17372
- try {
17373
- return getContractFee({
17374
- address: sourceAddress,
17375
- balance,
17376
- chain: chain2,
17377
- contract: transfer,
17378
- destinationFee,
17379
- feeBalance,
17380
- feeConfig
17381
- });
17382
- } catch (error) {
17383
- console.error(error);
17384
- return feeBalance.copyWith({ amount: 0n });
17385
- }
17386
- }
17387
17195
  return getExtrinsicFee({
17388
17196
  address: sourceAddress,
17389
17197
  balance,
@@ -17403,25 +17211,19 @@ async function getRelayerFee({
17403
17211
  sourceAddress,
17404
17212
  transfer
17405
17213
  }) {
17406
- if (route.mrl.transfer.provider === "snowbridge" || SnowbridgeConfig.is(transfer)) {
17407
- return void 0;
17408
- }
17409
17214
  if (WormholeConfig.is(transfer)) {
17410
17215
  return getWormholeFee({ asset, chain: chain2, config: transfer });
17411
17216
  }
17412
- if (route.mrl.transfer.provider === "wormhole") {
17413
- const builderParams = await getMrlBuilderParams({
17414
- asset,
17415
- destinationAddress,
17416
- feeAsset,
17417
- isAutomatic,
17418
- route,
17419
- sourceAddress
17420
- });
17421
- const wormholeConfig = MrlBuilder3().wormhole().wormhole().tokenTransfer().build(builderParams);
17422
- return getWormholeFee({ asset, chain: chain2, config: wormholeConfig });
17423
- }
17424
- return;
17217
+ const builderParams = await getMrlBuilderParams({
17218
+ asset,
17219
+ destinationAddress,
17220
+ feeAsset,
17221
+ isAutomatic,
17222
+ route,
17223
+ sourceAddress
17224
+ });
17225
+ const wormholeConfig = MrlBuilder3().wormhole().wormhole().tokenTransfer().build(builderParams);
17226
+ return getWormholeFee({ asset, chain: chain2, config: wormholeConfig });
17425
17227
  }
17426
17228
  async function getWormholeFee({
17427
17229
  asset,
@@ -17438,76 +17240,33 @@ async function getWormholeFee({
17438
17240
  }
17439
17241
  return;
17440
17242
  }
17441
- async function getBridgeChainFeeBalance({
17243
+ async function getMoonChainFeeBalance({
17442
17244
  balance,
17443
17245
  feeBalance,
17444
17246
  route,
17445
17247
  sourceAddress
17446
17248
  }) {
17447
- if (!route.source.bridgeChainFee) {
17249
+ if (!route.source.moonChainFee) {
17448
17250
  return void 0;
17449
17251
  }
17450
- if (route.mrl?.bridgeChain.fee.asset.isEqual(balance)) {
17252
+ if (route.mrl?.moonChain.fee.asset.isEqual(balance)) {
17451
17253
  return balance;
17452
17254
  }
17453
- if (route.mrl?.bridgeChain.fee.asset.isEqual(feeBalance)) {
17255
+ if (route.mrl?.moonChain.fee.asset.isEqual(feeBalance)) {
17454
17256
  return feeBalance;
17455
17257
  }
17456
- if (!route.source.bridgeChainFee.balance) {
17258
+ if (!route.source.moonChainFee.balance) {
17457
17259
  throw new Error(
17458
- "BalanceBuilder must be defined for source.bridgeChainFee.balance for MrlAssetRoute"
17260
+ "BalanceBuilder must be defined for source.moonChainFee.balance for MrlAssetRoute"
17459
17261
  );
17460
17262
  }
17461
17263
  return getBalance2({
17462
17264
  address: sourceAddress,
17463
- asset: route.source.chain.getChainAsset(route.source.bridgeChainFee.asset),
17464
- builder: route.source.bridgeChainFee.balance,
17265
+ asset: route.source.chain.getChainAsset(route.source.moonChainFee.asset),
17266
+ builder: route.source.moonChainFee.balance,
17465
17267
  chain: route.source.chain
17466
17268
  });
17467
17269
  }
17468
- async function getProtocolFee({
17469
- address,
17470
- asset,
17471
- balance,
17472
- protocolFee,
17473
- destination,
17474
- source
17475
- }) {
17476
- if (typeof protocolFee === "number") {
17477
- return AssetAmount2.fromChainAsset(asset, {
17478
- amount: protocolFee
17479
- });
17480
- }
17481
- const config = protocolFee?.build({
17482
- address,
17483
- asset,
17484
- balance,
17485
- destination,
17486
- source
17487
- });
17488
- if (ContractConfig2.is(config) && EvmChain2.is(source)) {
17489
- const evm = EvmService3.create(source);
17490
- const amount = await evm.read(config);
17491
- if (typeof amount !== "bigint") {
17492
- throw new Error(
17493
- `Error getting bridge fee: expected bigint from contract call, but received ${typeof amount}. `
17494
- );
17495
- }
17496
- return AssetAmount2.fromChainAsset(asset, {
17497
- amount
17498
- });
17499
- }
17500
- if (SubstrateQueryConfig.is(config) && EvmParachain3.isAnyParachain(source)) {
17501
- const polkadot = await PolkadotService2.create(source);
17502
- const amount = await polkadot.query(config);
17503
- return AssetAmount2.fromChainAsset(asset, {
17504
- amount
17505
- });
17506
- }
17507
- return AssetAmount2.fromChainAsset(source.getChainAsset(asset), {
17508
- amount: 0n
17509
- });
17510
- }
17511
17270
 
17512
17271
  // src/getTransferData/getTransferData.ts
17513
17272
  async function getTransferData({
@@ -17536,7 +17295,7 @@ async function getTransferData({
17536
17295
  destinationFee,
17537
17296
  sourceAddress
17538
17297
  });
17539
- const bridgeChainData = await getBridgeChainData({
17298
+ const moonChainData = await getMoonChainData({
17540
17299
  route,
17541
17300
  sourceAddress,
17542
17301
  destinationAddress
@@ -17548,14 +17307,14 @@ async function getTransferData({
17548
17307
  const bigAmount = Big2(
17549
17308
  toBigInt3(amount, sourceData.balance.decimals).toString()
17550
17309
  );
17551
- const fee = getBridgeChainFeeValueOnSource({
17310
+ const fee = getMoonChainFeeValueOnSource({
17552
17311
  destinationData,
17553
- bridgeChainData,
17312
+ moonChainData,
17554
17313
  sourceData
17555
17314
  });
17556
17315
  const result = bigAmount.minus(
17557
17316
  isSameAssetPayingDestinationFee ? destinationFee.toBig() : Big2(0)
17558
- ).minus(fee).minus(sourceData.otherFees?.relayer?.toBig() || Big2(0));
17317
+ ).minus(fee).minus(sourceData.relayerFee?.toBig() || Big2(0));
17559
17318
  return sourceData.balance.copyWith({
17560
17319
  amount: result.lt(0) ? 0n : BigInt(result.toFixed())
17561
17320
  });
@@ -17564,10 +17323,10 @@ async function getTransferData({
17564
17323
  max: sourceData.max,
17565
17324
  min: getMrlMin({
17566
17325
  destinationData,
17567
- bridgeChainData,
17326
+ moonChainData,
17568
17327
  sourceData
17569
17328
  }),
17570
- bridgeChain: bridgeChainData,
17329
+ moonChain: moonChainData,
17571
17330
  source: sourceData,
17572
17331
  async transfer({
17573
17332
  amount,
@@ -17590,7 +17349,6 @@ async function getTransferData({
17590
17349
  );
17591
17350
  const transfer = await buildTransfer({
17592
17351
  asset,
17593
- protocolFee: sourceData.otherFees?.protocol,
17594
17352
  destinationAddress,
17595
17353
  feeAsset,
17596
17354
  isAutomatic: isAutomatic2,
@@ -17598,19 +17356,19 @@ async function getTransferData({
17598
17356
  sendOnlyRemoteExecution,
17599
17357
  sourceAddress
17600
17358
  });
17601
- if (ContractConfig3.is(transfer) && (EvmChain3.is(source) || EvmParachain4.is(source))) {
17359
+ if (ContractConfig2.is(transfer) && (EvmChain.is(source) || EvmParachain3.is(source))) {
17602
17360
  if (!evmSigner) {
17603
17361
  throw new Error("EVM Signer must be provided");
17604
17362
  }
17605
- const evm = EvmService4.create(source);
17363
+ const evm = EvmService2.create(source);
17606
17364
  const hash = await evm.transfer(evmSigner, transfer);
17607
17365
  return [hash];
17608
17366
  }
17609
- if (ExtrinsicConfig.is(transfer) && EvmParachain4.isAnyParachain(source)) {
17367
+ if (ExtrinsicConfig.is(transfer) && EvmParachain3.isAnyParachain(source)) {
17610
17368
  if (!polkadotSigner) {
17611
17369
  throw new Error("Polkadot signer must be provided");
17612
17370
  }
17613
- const polkadot = await PolkadotService3.create(source);
17371
+ const polkadot = await PolkadotService2.create(source);
17614
17372
  const hash = await polkadot.transfer(
17615
17373
  sourceAddress,
17616
17374
  transfer,
@@ -17619,21 +17377,13 @@ async function getTransferData({
17619
17377
  );
17620
17378
  return [hash];
17621
17379
  }
17622
- if (WormholeConfig2.is(transfer) && (EvmChain3.is(source) || EvmParachain4.is(source))) {
17380
+ if (WormholeConfig2.is(transfer) && (EvmChain.is(source) || EvmParachain3.is(source))) {
17623
17381
  if (!evmSigner) {
17624
17382
  throw new Error("EVM Signer must be provided");
17625
17383
  }
17626
17384
  const wh = WormholeService.create(source);
17627
17385
  return wh.transfer(evmSigner, transfer);
17628
17386
  }
17629
- if (SnowbridgeConfig2.is(transfer) && (EvmChain3.is(source) || EvmParachain4.is(source))) {
17630
- if (!evmSigner) {
17631
- throw new Error("EVM Signer must be provided");
17632
- }
17633
- const snowbridge = SnowbridgeService.create(source);
17634
- const hash = await snowbridge.transfer(evmSigner, transfer);
17635
- return [hash];
17636
- }
17637
17387
  throw new Error("Either contract or extrinsic must be provided");
17638
17388
  }
17639
17389
  };