@moonbeam-network/mrl 1.0.0-dev.159 → 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
@@ -19,7 +19,7 @@ interface TransferData {
19
19
  min: AssetAmount;
20
20
  moonChain: MoonChainTransferData;
21
21
  source: SourceTransferData;
22
- transfer(amount: bigint | number | string, isAutomatic: boolean, signers: Signers, statusCallback?: (params: ISubmittableResult) => void): Promise<string[]>;
22
+ transfer(amount: bigint | number | string, isAutomatic: boolean, signers: Signers, statusCallback?: (params: ISubmittableResult) => void, sendOnlyRemoteExecution?: boolean): Promise<string[]>;
23
23
  }
24
24
  interface SourceTransferData extends SourceChainTransferData {
25
25
  destinationFeeBalance: AssetAmount;
@@ -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({
@@ -11251,6 +11262,7 @@ async function getMrlBuilderParams({
11251
11262
  feeAsset,
11252
11263
  isAutomatic,
11253
11264
  route,
11265
+ sendOnlyRemoteExecution,
11254
11266
  sourceAddress
11255
11267
  }) {
11256
11268
  if (!route.mrl) {
@@ -11262,8 +11274,8 @@ async function getMrlBuilderParams({
11262
11274
  const destination = route.destination.chain;
11263
11275
  const moonChain = getMoonChain2(source);
11264
11276
  const [sourceApi, destinationApi, moonApi] = await Promise.all([
11265
- EvmParachain.isAnyParachain(source) ? getPolkadotApi(source.ws) : void 0,
11266
- 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,
11267
11279
  getPolkadotApi(moonChain.ws)
11268
11280
  ]);
11269
11281
  return {
@@ -11276,6 +11288,7 @@ async function getMrlBuilderParams({
11276
11288
  moonApi,
11277
11289
  moonAsset: moonChain.nativeAsset,
11278
11290
  moonChain,
11291
+ sendOnlyRemoteExecution,
11279
11292
  source,
11280
11293
  sourceAddress,
11281
11294
  sourceApi
@@ -11285,7 +11298,7 @@ async function getTransact(params) {
11285
11298
  const { sourceAddress, source, moonChain } = params;
11286
11299
  const polkadot = await PolkadotService.create(moonChain);
11287
11300
  const moonGasLimit = await getMoonGasLimit(params);
11288
- if (!EvmParachain.isAnyParachain(source)) {
11301
+ if (!EvmParachain2.isAnyParachain(source)) {
11289
11302
  throw new Error("Source chain must be Parachain or EvmParachain");
11290
11303
  }
11291
11304
  const { address20 } = getMultilocationDerivedAddresses2({
@@ -11305,7 +11318,7 @@ async function getTransact(params) {
11305
11318
  }
11306
11319
  async function getMoonGasLimit(params) {
11307
11320
  const { asset, isAutomatic, moonChain, source, sourceAddress } = params;
11308
- if (!EvmParachain.isAnyParachain(source)) {
11321
+ if (!EvmParachain2.isAnyParachain(source)) {
11309
11322
  throw new Error("Source chain must be Parachain or EvmParachain");
11310
11323
  }
11311
11324
  const client = createPublicClient2({
@@ -11578,7 +11591,8 @@ async function getTransferData({
11578
11591
  });
11579
11592
  const moonChainData = await getMoonChainData({
11580
11593
  route,
11581
- sourceAddress
11594
+ sourceAddress,
11595
+ destinationAddress
11582
11596
  });
11583
11597
  return {
11584
11598
  destination: destinationData,
@@ -11608,7 +11622,7 @@ async function getTransferData({
11608
11622
  }),
11609
11623
  moonChain: moonChainData,
11610
11624
  source: sourceData,
11611
- async transfer(amount, isAutomatic2, { evmSigner, polkadotSigner }, statusCallback) {
11625
+ async transfer(amount, isAutomatic2, { evmSigner, polkadotSigner }, statusCallback, sendOnlyRemoteExecution) {
11612
11626
  const source = route.source.chain;
11613
11627
  const bigintAmount = toBigInt3(amount, sourceData.balance.decimals);
11614
11628
  const asset = AssetAmount3.fromChainAsset(
@@ -11627,9 +11641,10 @@ async function getTransferData({
11627
11641
  feeAsset,
11628
11642
  isAutomatic: isAutomatic2,
11629
11643
  route,
11644
+ sendOnlyRemoteExecution,
11630
11645
  sourceAddress
11631
11646
  });
11632
- if (ContractConfig2.is(transfer) && (EvmChain.is(source) || EvmParachain2.is(source))) {
11647
+ if (ContractConfig2.is(transfer) && (EvmChain2.is(source) || EvmParachain3.is(source))) {
11633
11648
  if (!evmSigner) {
11634
11649
  throw new Error("EVM Signer must be provided");
11635
11650
  }
@@ -11637,7 +11652,7 @@ async function getTransferData({
11637
11652
  const hash = await evm.transfer(evmSigner, transfer);
11638
11653
  return [hash];
11639
11654
  }
11640
- if (ExtrinsicConfig.is(transfer) && EvmParachain2.isAnyParachain(source)) {
11655
+ if (ExtrinsicConfig.is(transfer) && EvmParachain3.isAnyParachain(source)) {
11641
11656
  if (!polkadotSigner) {
11642
11657
  throw new Error("Polkadot signer must be provided");
11643
11658
  }
@@ -11650,7 +11665,7 @@ async function getTransferData({
11650
11665
  );
11651
11666
  return [hash];
11652
11667
  }
11653
- if (WormholeConfig2.is(transfer) && (EvmChain.is(source) || EvmParachain2.is(source))) {
11668
+ if (WormholeConfig2.is(transfer) && (EvmChain2.is(source) || EvmParachain3.is(source))) {
11654
11669
  if (!evmSigner) {
11655
11670
  throw new Error("EVM Signer must be provided");
11656
11671
  }