@moonbeam-network/mrl 1.0.0-dev.161 → 1.0.0-dev.163

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
@@ -10996,6 +10996,10 @@ var WormholeService = class _WormholeService {
10996
10996
  this.#wh = wormholeFactory(chain);
10997
10997
  }
10998
10998
  async getFee(transfer) {
10999
+ const amount = transfer.args[1];
11000
+ if (amount === 0n) {
11001
+ return void 0;
11002
+ }
10999
11003
  const xfer = await this.#wh[transfer.func](...transfer.args);
11000
11004
  return TokenTransfer.quoteTransfer(
11001
11005
  this.#wh,
@@ -11085,7 +11089,7 @@ import {
11085
11089
  } from "@moonbeam-network/xcm-sdk";
11086
11090
  import {
11087
11091
  AssetAmount as AssetAmount3,
11088
- EvmChain as EvmChain2,
11092
+ EvmChain,
11089
11093
  EvmParachain as EvmParachain3
11090
11094
  } from "@moonbeam-network/xcm-types";
11091
11095
  import { toBigInt as toBigInt3 } from "@moonbeam-network/xcm-utils";
@@ -11094,7 +11098,10 @@ import Big2 from "big.js";
11094
11098
  // src/getTransferData/getMoonChainData.ts
11095
11099
  import { getMoonChain } from "@moonbeam-network/xcm-config";
11096
11100
  import { getBalance, getDestinationFee } from "@moonbeam-network/xcm-sdk";
11097
- import { EvmParachain, Parachain } from "@moonbeam-network/xcm-types";
11101
+ import {
11102
+ EvmParachain,
11103
+ Parachain
11104
+ } from "@moonbeam-network/xcm-types";
11098
11105
  import { getMultilocationDerivedAddresses } from "@moonbeam-network/xcm-utils";
11099
11106
  import { evmToAddress } from "@polkadot/util-crypto";
11100
11107
  async function getMoonChainData({
@@ -11108,44 +11115,60 @@ async function getMoonChainData({
11108
11115
  );
11109
11116
  }
11110
11117
  const moonChain = getMoonChain(route.source.chain);
11111
- const isDestinationMoonChain = moonChain.isEqual(route.destination.chain);
11112
- let address = isDestinationMoonChain ? destinationAddress : sourceAddress;
11118
+ const moonChainAddress = getMoonChainAddress({
11119
+ source: route.source.chain,
11120
+ destination: route.destination.chain,
11121
+ sourceAddress,
11122
+ destinationAddress
11123
+ });
11113
11124
  const fee = await getDestinationFee({
11114
- address,
11125
+ address: moonChainAddress,
11115
11126
  asset: route.source.asset,
11116
11127
  destination: moonChain,
11117
11128
  fee: route.mrl.moonChain.fee.amount,
11118
11129
  feeAsset: route.mrl.moonChain.fee.asset
11119
11130
  });
11120
- if (Parachain.is(route.source.chain) && !route.source.chain.isEqual(moonChain)) {
11121
- const addressToUse = EvmParachain.is(route.source.chain) ? evmToAddress(sourceAddress) : sourceAddress;
11122
- const { address20 } = getMultilocationDerivedAddresses({
11123
- address: addressToUse,
11124
- paraId: route.source.chain.parachainId,
11125
- isParents: true
11126
- });
11127
- address = address20;
11128
- }
11129
11131
  const balance = await getBalance({
11130
- address,
11132
+ address: moonChainAddress,
11131
11133
  asset: moonChain.getChainAsset(route.mrl.moonChain.asset),
11132
11134
  builder: route.mrl.moonChain.balance,
11133
11135
  chain: moonChain
11134
11136
  });
11135
11137
  const feeBalance = await getBalance({
11136
- address,
11138
+ address: moonChainAddress,
11137
11139
  asset: moonChain.getChainAsset(route.mrl.moonChain.fee.asset),
11138
11140
  builder: route.mrl.moonChain.fee.balance,
11139
11141
  chain: moonChain
11140
11142
  });
11141
11143
  return {
11142
- address,
11144
+ address: moonChainAddress,
11143
11145
  balance,
11144
11146
  feeBalance,
11145
11147
  chain: moonChain,
11146
11148
  fee
11147
11149
  };
11148
11150
  }
11151
+ function getMoonChainAddress({
11152
+ source,
11153
+ destination,
11154
+ sourceAddress,
11155
+ destinationAddress
11156
+ }) {
11157
+ const moonChain = getMoonChain(source);
11158
+ const isDestinationMoonChain = moonChain.isEqual(destination);
11159
+ const isSourceMoonChain = moonChain.isEqual(source);
11160
+ let moonChainAddress = isDestinationMoonChain ? destinationAddress : sourceAddress;
11161
+ if (Parachain.is(source) && !isSourceMoonChain) {
11162
+ const isSourceEvmSigner = EvmParachain.is(source) && source.isEvmSigner;
11163
+ const { address20: computedOriginAccount } = getMultilocationDerivedAddresses({
11164
+ address: isSourceEvmSigner ? evmToAddress(sourceAddress) : sourceAddress,
11165
+ paraId: source.parachainId,
11166
+ isParents: true
11167
+ });
11168
+ moonChainAddress = computedOriginAccount;
11169
+ }
11170
+ return moonChainAddress;
11171
+ }
11149
11172
 
11150
11173
  // src/getTransferData/getSourceData.ts
11151
11174
  import {
@@ -11479,6 +11502,7 @@ async function getFee({
11479
11502
  if (ContractConfig.is(transfer)) {
11480
11503
  return getContractFee({
11481
11504
  address: sourceAddress,
11505
+ balance,
11482
11506
  chain,
11483
11507
  contract: transfer,
11484
11508
  destinationFee,
@@ -11529,7 +11553,7 @@ async function getWormholeFee({
11529
11553
  const wh = WormholeService.create(chain);
11530
11554
  const fee = await wh.getFee(config);
11531
11555
  return AssetAmount2.fromChainAsset(chain.getChainAsset(asset), {
11532
- amount: fee.relayFee ? fee.relayFee.amount + safetyAmount : 0n
11556
+ amount: fee?.relayFee ? fee.relayFee.amount + safetyAmount : 0n
11533
11557
  });
11534
11558
  }
11535
11559
  return;
@@ -11644,7 +11668,7 @@ async function getTransferData({
11644
11668
  sendOnlyRemoteExecution,
11645
11669
  sourceAddress
11646
11670
  });
11647
- if (ContractConfig2.is(transfer) && (EvmChain2.is(source) || EvmParachain3.is(source))) {
11671
+ if (ContractConfig2.is(transfer) && (EvmChain.is(source) || EvmParachain3.is(source))) {
11648
11672
  if (!evmSigner) {
11649
11673
  throw new Error("EVM Signer must be provided");
11650
11674
  }
@@ -11665,7 +11689,7 @@ async function getTransferData({
11665
11689
  );
11666
11690
  return [hash];
11667
11691
  }
11668
- if (WormholeConfig2.is(transfer) && (EvmChain2.is(source) || EvmParachain3.is(source))) {
11692
+ if (WormholeConfig2.is(transfer) && (EvmChain.is(source) || EvmParachain3.is(source))) {
11669
11693
  if (!evmSigner) {
11670
11694
  throw new Error("EVM Signer must be provided");
11671
11695
  }