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

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
@@ -11086,7 +11086,7 @@ import {
11086
11086
  import {
11087
11087
  AssetAmount as AssetAmount3,
11088
11088
  EvmChain,
11089
- EvmParachain as EvmParachain2
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,16 @@ 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 {
11098
+ EvmParachain,
11099
+ Parachain
11100
+ } from "@moonbeam-network/xcm-types";
11098
11101
  import { getMultilocationDerivedAddresses } from "@moonbeam-network/xcm-utils";
11102
+ import { evmToAddress } from "@polkadot/util-crypto";
11099
11103
  async function getMoonChainData({
11100
11104
  route,
11101
- sourceAddress
11105
+ sourceAddress,
11106
+ destinationAddress
11102
11107
  }) {
11103
11108
  if (!route.mrl) {
11104
11109
  throw new Error(
@@ -11106,35 +11111,60 @@ async function getMoonChainData({
11106
11111
  );
11107
11112
  }
11108
11113
  const moonChain = getMoonChain(route.source.chain);
11114
+ const moonChainAddress = getMoonChainAddress({
11115
+ source: route.source.chain,
11116
+ destination: route.destination.chain,
11117
+ sourceAddress,
11118
+ destinationAddress
11119
+ });
11109
11120
  const fee = await getDestinationFee({
11110
- address: sourceAddress,
11111
- // TODO not correct
11121
+ address: moonChainAddress,
11112
11122
  asset: route.source.asset,
11113
11123
  destination: moonChain,
11114
11124
  fee: route.mrl.moonChain.fee.amount,
11115
11125
  feeAsset: route.mrl.moonChain.fee.asset
11116
11126
  });
11117
- let address = sourceAddress;
11118
- if (Parachain.is(route.source.chain) && !route.source.chain.isEqual(moonChain)) {
11119
- const { address20 } = getMultilocationDerivedAddresses({
11120
- address: sourceAddress,
11121
- paraId: route.source.chain.parachainId,
11122
- isParents: true
11123
- });
11124
- address = address20;
11125
- }
11127
+ const balance = await getBalance({
11128
+ address: moonChainAddress,
11129
+ asset: moonChain.getChainAsset(route.mrl.moonChain.asset),
11130
+ builder: route.mrl.moonChain.balance,
11131
+ chain: moonChain
11132
+ });
11126
11133
  const feeBalance = await getBalance({
11127
- address,
11134
+ address: moonChainAddress,
11128
11135
  asset: moonChain.getChainAsset(route.mrl.moonChain.fee.asset),
11129
11136
  builder: route.mrl.moonChain.fee.balance,
11130
11137
  chain: moonChain
11131
11138
  });
11132
11139
  return {
11140
+ address: moonChainAddress,
11141
+ balance,
11133
11142
  feeBalance,
11134
11143
  chain: moonChain,
11135
11144
  fee
11136
11145
  };
11137
11146
  }
11147
+ function getMoonChainAddress({
11148
+ source,
11149
+ destination,
11150
+ sourceAddress,
11151
+ destinationAddress
11152
+ }) {
11153
+ const moonChain = getMoonChain(source);
11154
+ const isDestinationMoonChain = moonChain.isEqual(destination);
11155
+ const isSourceMoonChain = moonChain.isEqual(source);
11156
+ let moonChainAddress = isDestinationMoonChain ? destinationAddress : sourceAddress;
11157
+ if (Parachain.is(source) && !isSourceMoonChain) {
11158
+ const isSourceEvmSigner = EvmParachain.is(source) && source.isEvmSigner;
11159
+ const { address20: computedOriginAccount } = getMultilocationDerivedAddresses({
11160
+ address: isSourceEvmSigner ? evmToAddress(sourceAddress) : sourceAddress,
11161
+ paraId: source.parachainId,
11162
+ isParents: true
11163
+ });
11164
+ moonChainAddress = computedOriginAccount;
11165
+ }
11166
+ return moonChainAddress;
11167
+ }
11138
11168
 
11139
11169
  // src/getTransferData/getSourceData.ts
11140
11170
  import {
@@ -11173,7 +11203,7 @@ import {
11173
11203
  convertToChainDecimals,
11174
11204
  getMin
11175
11205
  } from "@moonbeam-network/xcm-sdk";
11176
- import { AssetAmount, EvmParachain } from "@moonbeam-network/xcm-types";
11206
+ import { AssetAmount, EvmParachain as EvmParachain2 } from "@moonbeam-network/xcm-types";
11177
11207
  import {
11178
11208
  getMultilocationDerivedAddresses as getMultilocationDerivedAddresses2,
11179
11209
  getPolkadotApi
@@ -11193,7 +11223,7 @@ function getMoonChainFeeValueOnSource({
11193
11223
  moonChainData,
11194
11224
  sourceData
11195
11225
  }) {
11196
- const isSourceParachain = EvmParachain.isAnyParachain(sourceData.chain);
11226
+ const isSourceParachain = EvmParachain2.isAnyParachain(sourceData.chain);
11197
11227
  const isDestinationMoonChain = destinationData.chain.isEqual(
11198
11228
  moonChainData.chain
11199
11229
  );
@@ -11242,7 +11272,7 @@ async function buildTransfer(params) {
11242
11272
  const builderParams = await getMrlBuilderParams(params);
11243
11273
  return route.mrl.transfer.build({
11244
11274
  ...builderParams,
11245
- transact: EvmParachain.isAnyParachain(route.source.chain) ? await getTransact(builderParams) : void 0
11275
+ transact: EvmParachain2.isAnyParachain(route.source.chain) ? await getTransact(builderParams) : void 0
11246
11276
  });
11247
11277
  }
11248
11278
  async function getMrlBuilderParams({
@@ -11263,8 +11293,8 @@ async function getMrlBuilderParams({
11263
11293
  const destination = route.destination.chain;
11264
11294
  const moonChain = getMoonChain2(source);
11265
11295
  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,
11296
+ EvmParachain2.isAnyParachain(source) ? getPolkadotApi(source.ws) : void 0,
11297
+ EvmParachain2.isAnyParachain(destination) ? getPolkadotApi(destination.ws) : void 0,
11268
11298
  getPolkadotApi(moonChain.ws)
11269
11299
  ]);
11270
11300
  return {
@@ -11287,7 +11317,7 @@ async function getTransact(params) {
11287
11317
  const { sourceAddress, source, moonChain } = params;
11288
11318
  const polkadot = await PolkadotService.create(moonChain);
11289
11319
  const moonGasLimit = await getMoonGasLimit(params);
11290
- if (!EvmParachain.isAnyParachain(source)) {
11320
+ if (!EvmParachain2.isAnyParachain(source)) {
11291
11321
  throw new Error("Source chain must be Parachain or EvmParachain");
11292
11322
  }
11293
11323
  const { address20 } = getMultilocationDerivedAddresses2({
@@ -11307,7 +11337,7 @@ async function getTransact(params) {
11307
11337
  }
11308
11338
  async function getMoonGasLimit(params) {
11309
11339
  const { asset, isAutomatic, moonChain, source, sourceAddress } = params;
11310
- if (!EvmParachain.isAnyParachain(source)) {
11340
+ if (!EvmParachain2.isAnyParachain(source)) {
11311
11341
  throw new Error("Source chain must be Parachain or EvmParachain");
11312
11342
  }
11313
11343
  const client = createPublicClient2({
@@ -11580,7 +11610,8 @@ async function getTransferData({
11580
11610
  });
11581
11611
  const moonChainData = await getMoonChainData({
11582
11612
  route,
11583
- sourceAddress
11613
+ sourceAddress,
11614
+ destinationAddress
11584
11615
  });
11585
11616
  return {
11586
11617
  destination: destinationData,
@@ -11632,7 +11663,7 @@ async function getTransferData({
11632
11663
  sendOnlyRemoteExecution,
11633
11664
  sourceAddress
11634
11665
  });
11635
- if (ContractConfig2.is(transfer) && (EvmChain.is(source) || EvmParachain2.is(source))) {
11666
+ if (ContractConfig2.is(transfer) && (EvmChain.is(source) || EvmParachain3.is(source))) {
11636
11667
  if (!evmSigner) {
11637
11668
  throw new Error("EVM Signer must be provided");
11638
11669
  }
@@ -11640,7 +11671,7 @@ async function getTransferData({
11640
11671
  const hash = await evm.transfer(evmSigner, transfer);
11641
11672
  return [hash];
11642
11673
  }
11643
- if (ExtrinsicConfig.is(transfer) && EvmParachain2.isAnyParachain(source)) {
11674
+ if (ExtrinsicConfig.is(transfer) && EvmParachain3.isAnyParachain(source)) {
11644
11675
  if (!polkadotSigner) {
11645
11676
  throw new Error("Polkadot signer must be provided");
11646
11677
  }
@@ -11653,7 +11684,7 @@ async function getTransferData({
11653
11684
  );
11654
11685
  return [hash];
11655
11686
  }
11656
- if (WormholeConfig2.is(transfer) && (EvmChain.is(source) || EvmParachain2.is(source))) {
11687
+ if (WormholeConfig2.is(transfer) && (EvmChain.is(source) || EvmParachain3.is(source))) {
11657
11688
  if (!evmSigner) {
11658
11689
  throw new Error("EVM Signer must be provided");
11659
11690
  }