@moonbeam-network/mrl 1.0.0-dev.266 → 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.d.ts CHANGED
@@ -36,6 +36,7 @@ interface MrlOtherFees {
36
36
  }
37
37
  interface SourceTransferData extends SourceChainTransferData {
38
38
  destinationFeeBalance: AssetAmount;
39
+ bridgeChainFeeBalance?: AssetAmount;
39
40
  feeBalance: AssetAmount;
40
41
  max: AssetAmount;
41
42
  otherFees: MrlOtherFees;
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";
@@ -17276,6 +17278,12 @@ async function getSourceData({
17276
17278
  route,
17277
17279
  sourceAddress
17278
17280
  });
17281
+ const bridgeChainFeeBalance = await getBridgeChainFeeBalance({
17282
+ balance,
17283
+ feeBalance,
17284
+ route,
17285
+ sourceAddress
17286
+ });
17279
17287
  const existentialDeposit = await getExistentialDeposit(source);
17280
17288
  const min = await getAssetMin({
17281
17289
  asset,
@@ -17331,7 +17339,7 @@ async function getSourceData({
17331
17339
  chain: source,
17332
17340
  destinationFee,
17333
17341
  destinationFeeBalance,
17334
- // bridgeChainFeeBalance,
17342
+ bridgeChainFeeBalance,
17335
17343
  existentialDeposit,
17336
17344
  fee,
17337
17345
  feeBalance,
@@ -17358,9 +17366,7 @@ async function getFee({
17358
17366
  });
17359
17367
  }
17360
17368
  if (SnowbridgeConfig.is(transfer)) {
17361
- const snowbridge = SnowbridgeService.create(
17362
- chain2
17363
- );
17369
+ const snowbridge = SnowbridgeService.create(chain2);
17364
17370
  const feeAmount = await snowbridge.getFee(sourceAddress, transfer);
17365
17371
  return AssetAmount2.fromChainAsset(chain2.getChainAsset(feeBalance), {
17366
17372
  amount: feeAmount
@@ -17436,6 +17442,33 @@ async function getWormholeFee({
17436
17442
  }
17437
17443
  return;
17438
17444
  }
17445
+ async function getBridgeChainFeeBalance({
17446
+ balance,
17447
+ feeBalance,
17448
+ route,
17449
+ sourceAddress
17450
+ }) {
17451
+ if (!route.source.bridgeChainFee) {
17452
+ return void 0;
17453
+ }
17454
+ if (route.mrl?.bridgeChain.fee.asset.isEqual(balance)) {
17455
+ return balance;
17456
+ }
17457
+ if (route.mrl?.bridgeChain.fee.asset.isEqual(feeBalance)) {
17458
+ return feeBalance;
17459
+ }
17460
+ if (!route.source.bridgeChainFee.balance) {
17461
+ throw new Error(
17462
+ "BalanceBuilder must be defined for source.bridgeChainFee.balance for MrlAssetRoute"
17463
+ );
17464
+ }
17465
+ return getBalance2({
17466
+ address: sourceAddress,
17467
+ asset: route.source.chain.getChainAsset(route.source.bridgeChainFee.asset),
17468
+ builder: route.source.bridgeChainFee.balance,
17469
+ chain: route.source.chain
17470
+ });
17471
+ }
17439
17472
  async function getProtocolFee({
17440
17473
  address,
17441
17474
  asset,
@@ -17456,7 +17489,7 @@ async function getProtocolFee({
17456
17489
  destination,
17457
17490
  source
17458
17491
  });
17459
- if (ContractConfig2.is(config) && EvmChain.is(source)) {
17492
+ if (ContractConfig2.is(config) && EvmChain2.is(source)) {
17460
17493
  const evm = EvmService3.create(source);
17461
17494
  const amount = await evm.read(config);
17462
17495
  if (typeof amount !== "bigint") {
@@ -17573,7 +17606,7 @@ async function getTransferData({
17573
17606
  sendOnlyRemoteExecution,
17574
17607
  sourceAddress
17575
17608
  });
17576
- if (ContractConfig3.is(transfer) && (EvmChain2.is(source) || EvmParachain4.is(source))) {
17609
+ if (ContractConfig3.is(transfer) && (EvmChain3.is(source) || EvmParachain4.is(source))) {
17577
17610
  if (!evmSigner) {
17578
17611
  throw new Error("EVM Signer must be provided");
17579
17612
  }
@@ -17594,14 +17627,14 @@ async function getTransferData({
17594
17627
  );
17595
17628
  return [hash];
17596
17629
  }
17597
- if (WormholeConfig2.is(transfer) && (EvmChain2.is(source) || EvmParachain4.is(source))) {
17630
+ if (WormholeConfig2.is(transfer) && (EvmChain3.is(source) || EvmParachain4.is(source))) {
17598
17631
  if (!evmSigner) {
17599
17632
  throw new Error("EVM Signer must be provided");
17600
17633
  }
17601
17634
  const wh = WormholeService.create(source);
17602
17635
  return wh.transfer(evmSigner, transfer);
17603
17636
  }
17604
- if (SnowbridgeConfig2.is(transfer) && (EvmChain2.is(source) || EvmParachain4.is(source))) {
17637
+ if (SnowbridgeConfig2.is(transfer) && (EvmChain3.is(source) || EvmParachain4.is(source))) {
17605
17638
  if (!evmSigner) {
17606
17639
  throw new Error("EVM Signer must be provided");
17607
17640
  }