@moonbeam-network/mrl 1.0.0-dev.294 → 1.0.0-dev.296

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
@@ -16798,7 +16798,7 @@ import {
16798
16798
  import {
16799
16799
  AssetAmount as AssetAmount3,
16800
16800
  EvmChain as EvmChain3,
16801
- EvmParachain as EvmParachain3
16801
+ EvmParachain as EvmParachain2
16802
16802
  } from "@moonbeam-network/xcm-types";
16803
16803
  import { toBigInt as toBigInt3 } from "@moonbeam-network/xcm-utils";
16804
16804
  import Big2 from "big.js";
@@ -16809,11 +16809,7 @@ import {
16809
16809
  ERC20_ABI,
16810
16810
  GATEWAY_ABI
16811
16811
  } from "@moonbeam-network/xcm-builder";
16812
- import {
16813
- EvmService as EvmService2,
16814
- getAllowanceSlot,
16815
- MAX_ALLOWANCE_HEX
16816
- } from "@moonbeam-network/xcm-sdk";
16812
+ import { EvmService as EvmService2 } from "@moonbeam-network/xcm-sdk";
16817
16813
  import { EvmChain } from "@moonbeam-network/xcm-types";
16818
16814
  import { isEthAddress } from "@moonbeam-network/xcm-utils";
16819
16815
  import { u8aToHex } from "@polkadot/util";
@@ -16912,7 +16908,7 @@ var SnowbridgeService = class _SnowbridgeService {
16912
16908
  });
16913
16909
  return hash;
16914
16910
  }
16915
- async getFee(address, transfer, allowanceSlot) {
16911
+ async getFee(address, transfer) {
16916
16912
  const { args } = transfer;
16917
16913
  const { tokenAddress, amount, requiresApproval } = args;
16918
16914
  const contract = this.buildContractConfig(transfer);
@@ -16927,13 +16923,9 @@ var SnowbridgeService = class _SnowbridgeService {
16927
16923
  if (currentAllowance >= amount) {
16928
16924
  return await this.#evmService.getFee(address, contract);
16929
16925
  }
16930
- return await this.estimateApproveAndSendFee(
16931
- address,
16932
- transfer,
16933
- allowanceSlot
16934
- );
16926
+ return await this.estimateApproveAndSendFee(address, transfer);
16935
16927
  }
16936
- async estimateApproveAndSendFee(address, transfer, allowanceSlotNumber) {
16928
+ async estimateApproveAndSendFee(address, transfer) {
16937
16929
  const { args } = transfer;
16938
16930
  const { tokenAddress, amount } = args;
16939
16931
  const contract = this.buildContractConfig(transfer);
@@ -16948,24 +16940,19 @@ var SnowbridgeService = class _SnowbridgeService {
16948
16940
  to: tokenAddress,
16949
16941
  data: approveData
16950
16942
  });
16951
- const allowanceSlot = getAllowanceSlot(
16952
- address,
16953
- this.#gatewayAddress,
16954
- allowanceSlotNumber
16955
- );
16956
- const sendFee = await this.#evmService.getFee(address, contract, [
16957
- {
16958
- address: tokenAddress,
16959
- stateDiff: [
16960
- {
16961
- slot: allowanceSlot,
16962
- value: MAX_ALLOWANCE_HEX
16963
- }
16964
- ]
16965
- }
16966
- ]);
16943
+ const sendData = encodeFunctionData({
16944
+ abi: contract.abi,
16945
+ functionName: contract.func,
16946
+ args: contract.args
16947
+ });
16948
+ const sendGas = await this.#evmService.client.estimateGas({
16949
+ account: address,
16950
+ to: contract.address,
16951
+ data: sendData,
16952
+ value: contract.value
16953
+ });
16967
16954
  const gasPrice = await this.#evmService.client.getGasPrice();
16968
- return approveGas * gasPrice + sendFee;
16955
+ return (approveGas + sendGas) * gasPrice;
16969
16956
  } catch (error) {
16970
16957
  console.error("Error estimating approve + send fee:", error);
16971
16958
  return 0n;
@@ -16975,7 +16962,7 @@ var SnowbridgeService = class _SnowbridgeService {
16975
16962
 
16976
16963
  // src/getTransferData/getBridgeChainData.ts
16977
16964
  import { getBalance, getDestinationFee } from "@moonbeam-network/xcm-sdk";
16978
- import { EvmParachain, Parachain } from "@moonbeam-network/xcm-types";
16965
+ import { Parachain } from "@moonbeam-network/xcm-types";
16979
16966
  import {
16980
16967
  getMultilocationDerivedAddresses,
16981
16968
  isEthAddress as isEthAddress2
@@ -17035,17 +17022,17 @@ function getBridgeChainAddress({
17035
17022
  const bridgeChain = route.mrl.bridgeChain.chain;
17036
17023
  const isDestinationBridgeChain = bridgeChain.isEqual(destination);
17037
17024
  const isSourceBridgeChain = bridgeChain.isEqual(source);
17025
+ const isDifferentEcosystem = source.ecosystem !== bridgeChain.ecosystem;
17038
17026
  let bridgeChainAddress = isDestinationBridgeChain ? destinationAddress : sourceAddress;
17039
17027
  if (Parachain.isExactly(bridgeChain) && isEthAddress2(bridgeChainAddress)) {
17040
17028
  bridgeChainAddress = evmToAddress(bridgeChainAddress);
17041
17029
  return bridgeChainAddress;
17042
17030
  }
17043
17031
  if (Parachain.is(source) && !isSourceBridgeChain) {
17044
- const isSourceEvmSigner = EvmParachain.is(source) && source.isEvmSigner;
17045
17032
  const { address20: computedOriginAccount } = getMultilocationDerivedAddresses({
17046
- address: isSourceEvmSigner ? evmToAddress(sourceAddress) : sourceAddress,
17033
+ address: sourceAddress,
17047
17034
  paraId: source.parachainId,
17048
- isParents: true
17035
+ parents: isDifferentEcosystem ? 2 : 1
17049
17036
  });
17050
17037
  bridgeChainAddress = computedOriginAccount;
17051
17038
  }
@@ -17087,7 +17074,8 @@ import {
17087
17074
  } from "@moonbeam-network/xcm-builder";
17088
17075
  import {
17089
17076
  moonbaseAlpha,
17090
- moonbeam
17077
+ moonbeam,
17078
+ moonriver
17091
17079
  } from "@moonbeam-network/xcm-config";
17092
17080
  import {
17093
17081
  convertToChainDecimals,
@@ -17095,7 +17083,7 @@ import {
17095
17083
  getMin,
17096
17084
  PolkadotService
17097
17085
  } from "@moonbeam-network/xcm-sdk";
17098
- import { AssetAmount, EvmParachain as EvmParachain2 } from "@moonbeam-network/xcm-types";
17086
+ import { AssetAmount, EvmParachain } from "@moonbeam-network/xcm-types";
17099
17087
  import {
17100
17088
  getMultilocationDerivedAddresses as getMultilocationDerivedAddresses2,
17101
17089
  getPolkadotApi
@@ -17108,6 +17096,7 @@ import {
17108
17096
  } from "viem";
17109
17097
  var MOON_CHAIN_AUTOMATIC_GAS_ESTIMATION = {
17110
17098
  [moonbeam.key]: 1273110n,
17099
+ [moonriver.key]: 1273110n,
17111
17100
  [moonbaseAlpha.key]: 1470417n
17112
17101
  };
17113
17102
  function getBridgeChainFeeValueOnSource({
@@ -17115,7 +17104,7 @@ function getBridgeChainFeeValueOnSource({
17115
17104
  bridgeChainData,
17116
17105
  sourceData
17117
17106
  }) {
17118
- const isSourceParachain = EvmParachain2.isAnyParachain(sourceData.chain);
17107
+ const isSourceParachain = EvmParachain.isAnyParachain(sourceData.chain);
17119
17108
  const isDestinationBridgeChain = destinationData.chain.isEqual(
17120
17109
  bridgeChainData.chain
17121
17110
  );
@@ -17150,7 +17139,7 @@ function getMrlMin({
17150
17139
  });
17151
17140
  }
17152
17141
  function requiresTransact(route) {
17153
- return route.mrl?.transfer.provider === Provider.Wormhole && EvmParachain2.isAnyParachain(route.source.chain);
17142
+ return route.mrl?.transfer.provider === Provider.Wormhole && EvmParachain.isAnyParachain(route.source.chain);
17154
17143
  }
17155
17144
  async function buildTransfer(params) {
17156
17145
  const { route } = params;
@@ -17190,8 +17179,8 @@ async function getMrlBuilderParams({
17190
17179
  const destination = route.destination.chain;
17191
17180
  const bridgeChain = route.mrl.bridgeChain.chain;
17192
17181
  const [sourceApi, destinationApi, bridgeApi] = await Promise.all([
17193
- EvmParachain2.isAnyParachain(source) ? getPolkadotApi(source.ws) : void 0,
17194
- EvmParachain2.isAnyParachain(destination) ? getPolkadotApi(destination.ws) : void 0,
17182
+ EvmParachain.isAnyParachain(source) ? getPolkadotApi(source.ws) : void 0,
17183
+ EvmParachain.isAnyParachain(destination) ? getPolkadotApi(destination.ws) : void 0,
17195
17184
  getPolkadotApi(bridgeChain.ws)
17196
17185
  ]);
17197
17186
  return {
@@ -17216,13 +17205,14 @@ async function getTransact(params) {
17216
17205
  const { sourceAddress, source, bridgeChain } = params;
17217
17206
  const polkadot = await PolkadotService.create(bridgeChain);
17218
17207
  const bridgeChainGasLimit = await getBridgeChainGasLimit(params);
17219
- if (!EvmParachain2.isAnyParachain(source)) {
17208
+ if (!EvmParachain.isAnyParachain(source)) {
17220
17209
  throw new Error("Source chain must be Parachain or EvmParachain");
17221
17210
  }
17211
+ const isDifferentEcosystem = source.ecosystem !== bridgeChain.ecosystem;
17222
17212
  const { address20 } = getMultilocationDerivedAddresses2({
17223
17213
  address: sourceAddress,
17224
17214
  paraId: source.parachainId,
17225
- isParents: true
17215
+ parents: isDifferentEcosystem ? 2 : 1
17226
17216
  });
17227
17217
  const extrinsic = MrlBuilder2().wormhole().extrinsic().ethereumXcm().transact().build({ ...params, bridgeChainGasLimit });
17228
17218
  const { weight } = await polkadot.getPaymentInfo(address20, extrinsic);
@@ -17236,10 +17226,10 @@ async function getTransact(params) {
17236
17226
  }
17237
17227
  async function getBridgeChainGasLimit(params) {
17238
17228
  const { asset, isAutomatic, bridgeChain, source, sourceAddress } = params;
17239
- if (!EvmParachain2.isAnyParachain(source)) {
17229
+ if (!EvmParachain.isAnyParachain(source)) {
17240
17230
  throw new Error("Source chain must be Parachain or EvmParachain");
17241
17231
  }
17242
- if (!EvmParachain2.is(bridgeChain)) {
17232
+ if (!EvmParachain.is(bridgeChain)) {
17243
17233
  throw new Error("Bridge chain must be an EvmParachain");
17244
17234
  }
17245
17235
  const client = createPublicClient2({
@@ -17249,7 +17239,7 @@ async function getBridgeChainGasLimit(params) {
17249
17239
  const { address20 } = getMultilocationDerivedAddresses2({
17250
17240
  address: sourceAddress,
17251
17241
  paraId: source.parachainId,
17252
- isParents: true
17242
+ parents: 1
17253
17243
  });
17254
17244
  if (isAutomatic) {
17255
17245
  return MOON_CHAIN_AUTOMATIC_GAS_ESTIMATION[bridgeChain.key] * 110n / 100n;
@@ -17447,12 +17437,7 @@ async function getFee({
17447
17437
  if (SnowbridgeConfig.is(transfer)) {
17448
17438
  const snowbridge = SnowbridgeService.create(chain2);
17449
17439
  try {
17450
- const allowanceSlot = balance.ids?.allowanceSlot;
17451
- const feeAmount = await snowbridge.getFee(
17452
- sourceAddress,
17453
- transfer,
17454
- allowanceSlot
17455
- );
17440
+ const feeAmount = await snowbridge.getFee(sourceAddress, transfer);
17456
17441
  return AssetAmount2.fromChainAsset(chain2.getChainAsset(feeBalance), {
17457
17442
  amount: feeAmount
17458
17443
  });
@@ -17740,7 +17725,7 @@ async function getTransferData({
17740
17725
  sendOnlyRemoteExecution,
17741
17726
  sourceAddress
17742
17727
  });
17743
- if (ContractConfig3.is(transfer) && (EvmChain3.is(source) || EvmParachain3.is(source))) {
17728
+ if (ContractConfig3.is(transfer) && (EvmChain3.is(source) || EvmParachain2.is(source))) {
17744
17729
  if (!evmSigner) {
17745
17730
  throw new Error("EVM Signer must be provided");
17746
17731
  }
@@ -17748,7 +17733,7 @@ async function getTransferData({
17748
17733
  const hash = await evm.transfer(evmSigner, transfer);
17749
17734
  return [hash];
17750
17735
  }
17751
- if (ExtrinsicConfig.is(transfer) && EvmParachain3.isAnyParachain(source)) {
17736
+ if (ExtrinsicConfig.is(transfer) && EvmParachain2.isAnyParachain(source)) {
17752
17737
  if (!polkadotSigner) {
17753
17738
  throw new Error("Polkadot signer must be provided");
17754
17739
  }
@@ -17761,14 +17746,14 @@ async function getTransferData({
17761
17746
  );
17762
17747
  return [hash];
17763
17748
  }
17764
- if (WormholeConfig2.is(transfer) && (EvmChain3.is(source) || EvmParachain3.is(source))) {
17749
+ if (WormholeConfig2.is(transfer) && (EvmChain3.is(source) || EvmParachain2.is(source))) {
17765
17750
  if (!evmSigner) {
17766
17751
  throw new Error("EVM Signer must be provided");
17767
17752
  }
17768
17753
  const wh = WormholeService.create(source);
17769
17754
  return wh.transfer(evmSigner, transfer);
17770
17755
  }
17771
- if (SnowbridgeConfig2.is(transfer) && (EvmChain3.is(source) || EvmParachain3.is(source))) {
17756
+ if (SnowbridgeConfig2.is(transfer) && (EvmChain3.is(source) || EvmParachain2.is(source))) {
17772
17757
  if (!evmSigner) {
17773
17758
  throw new Error("EVM Signer must be provided");
17774
17759
  }