@moonbeam-network/mrl 1.0.0-dev.265 → 1.0.0-dev.267

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
@@ -16768,7 +16768,7 @@ import {
16768
16768
  } from "@moonbeam-network/xcm-sdk";
16769
16769
  import {
16770
16770
  AssetAmount as AssetAmount3,
16771
- EvmChain as EvmChain2,
16771
+ EvmChain as EvmChain3,
16772
16772
  EvmParachain as EvmParachain4
16773
16773
  } from "@moonbeam-network/xcm-types";
16774
16774
  import { toBigInt as toBigInt3 } from "@moonbeam-network/xcm-utils";
@@ -16778,21 +16778,28 @@ import Big2 from "big.js";
16778
16778
  import {
16779
16779
  ContractConfig,
16780
16780
  ERC20_ABI,
16781
- GATEWAY_ABI,
16782
- GATEWAY_CONTRACT_ADDRESS
16781
+ GATEWAY_ABI
16783
16782
  } from "@moonbeam-network/xcm-builder";
16784
16783
  import { EvmService as EvmService2 } from "@moonbeam-network/xcm-sdk";
16784
+ import { EvmChain } from "@moonbeam-network/xcm-types";
16785
16785
  import { u8aToHex } from "@polkadot/util";
16786
16786
  import { decodeAddress } from "@polkadot/util-crypto";
16787
16787
  import { encodeFunctionData } from "viem";
16788
16788
  var SnowbridgeService = class _SnowbridgeService {
16789
16789
  chain;
16790
16790
  #evmService;
16791
+ #gatewayAddress;
16791
16792
  static create(chain2) {
16792
16793
  return new _SnowbridgeService(chain2);
16793
16794
  }
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
+ }
16795
16801
  this.chain = chain2;
16802
+ this.#gatewayAddress = chain2.contracts.Gateway;
16796
16803
  this.#evmService = EvmService2.create(chain2);
16797
16804
  }
16798
16805
  async checkAllowance(ownerAddress, tokenAddress, spenderAddress) {
@@ -16822,16 +16829,11 @@ var SnowbridgeService = class _SnowbridgeService {
16822
16829
  const currentAllowance = await this.checkAllowance(
16823
16830
  signer.account.address,
16824
16831
  tokenAddress,
16825
- GATEWAY_CONTRACT_ADDRESS
16832
+ this.#gatewayAddress
16826
16833
  );
16827
16834
  console.log("currentAllowance", currentAllowance);
16828
16835
  if (currentAllowance < amount) {
16829
- await this.approve(
16830
- signer,
16831
- tokenAddress,
16832
- GATEWAY_CONTRACT_ADDRESS,
16833
- amount
16834
- );
16836
+ await this.approve(signer, tokenAddress, this.#gatewayAddress, amount);
16835
16837
  }
16836
16838
  return await this.#evmService.transfer(signer, contract);
16837
16839
  }
@@ -16857,7 +16859,7 @@ var SnowbridgeService = class _SnowbridgeService {
16857
16859
  amount
16858
16860
  ];
16859
16861
  return new ContractConfig({
16860
- address: GATEWAY_CONTRACT_ADDRESS,
16862
+ address: this.#gatewayAddress,
16861
16863
  abi: GATEWAY_ABI,
16862
16864
  args: contractArgs,
16863
16865
  func: "sendToken",
@@ -16889,7 +16891,7 @@ var SnowbridgeService = class _SnowbridgeService {
16889
16891
  const currentAllowance = await this.checkAllowance(
16890
16892
  address,
16891
16893
  tokenAddress,
16892
- GATEWAY_CONTRACT_ADDRESS
16894
+ this.#gatewayAddress
16893
16895
  );
16894
16896
  if (currentAllowance >= amount) {
16895
16897
  return await this.#evmService.getFee(address, contract);
@@ -16904,7 +16906,7 @@ var SnowbridgeService = class _SnowbridgeService {
16904
16906
  const approveData = encodeFunctionData({
16905
16907
  abi: ERC20_ABI,
16906
16908
  functionName: "approve",
16907
- args: [GATEWAY_CONTRACT_ADDRESS, amount]
16909
+ args: [this.#gatewayAddress, amount]
16908
16910
  });
16909
16911
  const approveGas = await this.#evmService.client.estimateGas({
16910
16912
  account: address,
@@ -17027,7 +17029,7 @@ import {
17027
17029
  } from "@moonbeam-network/xcm-sdk";
17028
17030
  import {
17029
17031
  AssetAmount as AssetAmount2,
17030
- EvmChain,
17032
+ EvmChain as EvmChain2,
17031
17033
  EvmParachain as EvmParachain3
17032
17034
  } from "@moonbeam-network/xcm-types";
17033
17035
  import { toBigInt as toBigInt2 } from "@moonbeam-network/xcm-utils";
@@ -17364,9 +17366,7 @@ async function getFee({
17364
17366
  });
17365
17367
  }
17366
17368
  if (SnowbridgeConfig.is(transfer)) {
17367
- const snowbridge = SnowbridgeService.create(
17368
- chain2
17369
- );
17369
+ const snowbridge = SnowbridgeService.create(chain2);
17370
17370
  const feeAmount = await snowbridge.getFee(sourceAddress, transfer);
17371
17371
  return AssetAmount2.fromChainAsset(chain2.getChainAsset(feeBalance), {
17372
17372
  amount: feeAmount
@@ -17489,7 +17489,7 @@ async function getProtocolFee({
17489
17489
  destination,
17490
17490
  source
17491
17491
  });
17492
- if (ContractConfig2.is(config) && EvmChain.is(source)) {
17492
+ if (ContractConfig2.is(config) && EvmChain2.is(source)) {
17493
17493
  const evm = EvmService3.create(source);
17494
17494
  const amount = await evm.read(config);
17495
17495
  if (typeof amount !== "bigint") {
@@ -17606,7 +17606,7 @@ async function getTransferData({
17606
17606
  sendOnlyRemoteExecution,
17607
17607
  sourceAddress
17608
17608
  });
17609
- if (ContractConfig3.is(transfer) && (EvmChain2.is(source) || EvmParachain4.is(source))) {
17609
+ if (ContractConfig3.is(transfer) && (EvmChain3.is(source) || EvmParachain4.is(source))) {
17610
17610
  if (!evmSigner) {
17611
17611
  throw new Error("EVM Signer must be provided");
17612
17612
  }
@@ -17627,14 +17627,14 @@ async function getTransferData({
17627
17627
  );
17628
17628
  return [hash];
17629
17629
  }
17630
- if (WormholeConfig2.is(transfer) && (EvmChain2.is(source) || EvmParachain4.is(source))) {
17630
+ if (WormholeConfig2.is(transfer) && (EvmChain3.is(source) || EvmParachain4.is(source))) {
17631
17631
  if (!evmSigner) {
17632
17632
  throw new Error("EVM Signer must be provided");
17633
17633
  }
17634
17634
  const wh = WormholeService.create(source);
17635
17635
  return wh.transfer(evmSigner, transfer);
17636
17636
  }
17637
- if (SnowbridgeConfig2.is(transfer) && (EvmChain2.is(source) || EvmParachain4.is(source))) {
17637
+ if (SnowbridgeConfig2.is(transfer) && (EvmChain3.is(source) || EvmParachain4.is(source))) {
17638
17638
  if (!evmSigner) {
17639
17639
  throw new Error("EVM Signer must be provided");
17640
17640
  }