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

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
@@ -30,7 +30,8 @@ interface SourceTransferData extends SourceChainTransferData {
30
30
  }
31
31
  interface DestinationTransferData extends ChainTransferData {
32
32
  }
33
- type MoonChainTransferData = Omit<ChainTransferData, 'min' | 'balance'> & {
33
+ type MoonChainTransferData = Omit<ChainTransferData, 'min'> & {
34
+ address: string;
34
35
  feeBalance: AssetAmount;
35
36
  };
36
37
  interface ChainTransferData {
package/build/index.mjs CHANGED
@@ -11085,8 +11085,8 @@ import {
11085
11085
  } from "@moonbeam-network/xcm-sdk";
11086
11086
  import {
11087
11087
  AssetAmount as AssetAmount3,
11088
- EvmChain,
11089
- EvmParachain as EvmParachain2
11088
+ EvmChain as EvmChain2,
11089
+ EvmParachain as EvmParachain3
11090
11090
  } from "@moonbeam-network/xcm-types";
11091
11091
  import { toBigInt as toBigInt3 } from "@moonbeam-network/xcm-utils";
11092
11092
  import Big2 from "big.js";
@@ -11094,11 +11094,13 @@ import Big2 from "big.js";
11094
11094
  // src/getTransferData/getMoonChainData.ts
11095
11095
  import { getMoonChain } from "@moonbeam-network/xcm-config";
11096
11096
  import { getBalance, getDestinationFee } from "@moonbeam-network/xcm-sdk";
11097
- import { Parachain } from "@moonbeam-network/xcm-types";
11097
+ import { EvmParachain, Parachain } from "@moonbeam-network/xcm-types";
11098
11098
  import { getMultilocationDerivedAddresses } from "@moonbeam-network/xcm-utils";
11099
+ import { evmToAddress } from "@polkadot/util-crypto";
11099
11100
  async function getMoonChainData({
11100
11101
  route,
11101
- sourceAddress
11102
+ sourceAddress,
11103
+ destinationAddress
11102
11104
  }) {
11103
11105
  if (!route.mrl) {
11104
11106
  throw new Error(
@@ -11106,23 +11108,30 @@ async function getMoonChainData({
11106
11108
  );
11107
11109
  }
11108
11110
  const moonChain = getMoonChain(route.source.chain);
11111
+ const isDestinationMoonChain = moonChain.isEqual(route.destination.chain);
11112
+ let address = isDestinationMoonChain ? destinationAddress : sourceAddress;
11109
11113
  const fee = await getDestinationFee({
11110
- address: sourceAddress,
11111
- // TODO not correct
11114
+ address,
11112
11115
  asset: route.source.asset,
11113
11116
  destination: moonChain,
11114
11117
  fee: route.mrl.moonChain.fee.amount,
11115
11118
  feeAsset: route.mrl.moonChain.fee.asset
11116
11119
  });
11117
- let address = sourceAddress;
11118
11120
  if (Parachain.is(route.source.chain) && !route.source.chain.isEqual(moonChain)) {
11121
+ const addressToUse = EvmParachain.is(route.source.chain) ? evmToAddress(sourceAddress) : sourceAddress;
11119
11122
  const { address20 } = getMultilocationDerivedAddresses({
11120
- address: sourceAddress,
11123
+ address: addressToUse,
11121
11124
  paraId: route.source.chain.parachainId,
11122
11125
  isParents: true
11123
11126
  });
11124
11127
  address = address20;
11125
11128
  }
11129
+ const balance = await getBalance({
11130
+ address,
11131
+ asset: moonChain.getChainAsset(route.mrl.moonChain.asset),
11132
+ builder: route.mrl.moonChain.balance,
11133
+ chain: moonChain
11134
+ });
11126
11135
  const feeBalance = await getBalance({
11127
11136
  address,
11128
11137
  asset: moonChain.getChainAsset(route.mrl.moonChain.fee.asset),
@@ -11130,6 +11139,8 @@ async function getMoonChainData({
11130
11139
  chain: moonChain
11131
11140
  });
11132
11141
  return {
11142
+ address,
11143
+ balance,
11133
11144
  feeBalance,
11134
11145
  chain: moonChain,
11135
11146
  fee
@@ -11173,7 +11184,7 @@ import {
11173
11184
  convertToChainDecimals,
11174
11185
  getMin
11175
11186
  } from "@moonbeam-network/xcm-sdk";
11176
- import { AssetAmount, EvmParachain } from "@moonbeam-network/xcm-types";
11187
+ import { AssetAmount, EvmParachain as EvmParachain2 } from "@moonbeam-network/xcm-types";
11177
11188
  import {
11178
11189
  getMultilocationDerivedAddresses as getMultilocationDerivedAddresses2,
11179
11190
  getPolkadotApi
@@ -11193,7 +11204,7 @@ function getMoonChainFeeValueOnSource({
11193
11204
  moonChainData,
11194
11205
  sourceData
11195
11206
  }) {
11196
- const isSourceParachain = EvmParachain.isAnyParachain(sourceData.chain);
11207
+ const isSourceParachain = EvmParachain2.isAnyParachain(sourceData.chain);
11197
11208
  const isDestinationMoonChain = destinationData.chain.isEqual(
11198
11209
  moonChainData.chain
11199
11210
  );
@@ -11242,7 +11253,7 @@ async function buildTransfer(params) {
11242
11253
  const builderParams = await getMrlBuilderParams(params);
11243
11254
  return route.mrl.transfer.build({
11244
11255
  ...builderParams,
11245
- transact: EvmParachain.isAnyParachain(route.source.chain) ? await getTransact(builderParams) : void 0
11256
+ transact: EvmParachain2.isAnyParachain(route.source.chain) ? await getTransact(builderParams) : void 0
11246
11257
  });
11247
11258
  }
11248
11259
  async function getMrlBuilderParams({
@@ -11263,8 +11274,8 @@ async function getMrlBuilderParams({
11263
11274
  const destination = route.destination.chain;
11264
11275
  const moonChain = getMoonChain2(source);
11265
11276
  const [sourceApi, destinationApi, moonApi] = await Promise.all([
11266
- EvmParachain.isAnyParachain(source) ? getPolkadotApi(source.ws) : void 0,
11267
- EvmParachain.isAnyParachain(destination) ? getPolkadotApi(destination.ws) : void 0,
11277
+ EvmParachain2.isAnyParachain(source) ? getPolkadotApi(source.ws) : void 0,
11278
+ EvmParachain2.isAnyParachain(destination) ? getPolkadotApi(destination.ws) : void 0,
11268
11279
  getPolkadotApi(moonChain.ws)
11269
11280
  ]);
11270
11281
  return {
@@ -11287,7 +11298,7 @@ async function getTransact(params) {
11287
11298
  const { sourceAddress, source, moonChain } = params;
11288
11299
  const polkadot = await PolkadotService.create(moonChain);
11289
11300
  const moonGasLimit = await getMoonGasLimit(params);
11290
- if (!EvmParachain.isAnyParachain(source)) {
11301
+ if (!EvmParachain2.isAnyParachain(source)) {
11291
11302
  throw new Error("Source chain must be Parachain or EvmParachain");
11292
11303
  }
11293
11304
  const { address20 } = getMultilocationDerivedAddresses2({
@@ -11307,7 +11318,7 @@ async function getTransact(params) {
11307
11318
  }
11308
11319
  async function getMoonGasLimit(params) {
11309
11320
  const { asset, isAutomatic, moonChain, source, sourceAddress } = params;
11310
- if (!EvmParachain.isAnyParachain(source)) {
11321
+ if (!EvmParachain2.isAnyParachain(source)) {
11311
11322
  throw new Error("Source chain must be Parachain or EvmParachain");
11312
11323
  }
11313
11324
  const client = createPublicClient2({
@@ -11580,7 +11591,8 @@ async function getTransferData({
11580
11591
  });
11581
11592
  const moonChainData = await getMoonChainData({
11582
11593
  route,
11583
- sourceAddress
11594
+ sourceAddress,
11595
+ destinationAddress
11584
11596
  });
11585
11597
  return {
11586
11598
  destination: destinationData,
@@ -11632,7 +11644,7 @@ async function getTransferData({
11632
11644
  sendOnlyRemoteExecution,
11633
11645
  sourceAddress
11634
11646
  });
11635
- if (ContractConfig2.is(transfer) && (EvmChain.is(source) || EvmParachain2.is(source))) {
11647
+ if (ContractConfig2.is(transfer) && (EvmChain2.is(source) || EvmParachain3.is(source))) {
11636
11648
  if (!evmSigner) {
11637
11649
  throw new Error("EVM Signer must be provided");
11638
11650
  }
@@ -11640,7 +11652,7 @@ async function getTransferData({
11640
11652
  const hash = await evm.transfer(evmSigner, transfer);
11641
11653
  return [hash];
11642
11654
  }
11643
- if (ExtrinsicConfig.is(transfer) && EvmParachain2.isAnyParachain(source)) {
11655
+ if (ExtrinsicConfig.is(transfer) && EvmParachain3.isAnyParachain(source)) {
11644
11656
  if (!polkadotSigner) {
11645
11657
  throw new Error("Polkadot signer must be provided");
11646
11658
  }
@@ -11653,7 +11665,7 @@ async function getTransferData({
11653
11665
  );
11654
11666
  return [hash];
11655
11667
  }
11656
- if (WormholeConfig2.is(transfer) && (EvmChain.is(source) || EvmParachain2.is(source))) {
11668
+ if (WormholeConfig2.is(transfer) && (EvmChain2.is(source) || EvmParachain3.is(source))) {
11657
11669
  if (!evmSigner) {
11658
11670
  throw new Error("EVM Signer must be provided");
11659
11671
  }