@moonbeam-network/mrl 1.0.0-dev.155 → 1.0.0-dev.158

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
@@ -5,7 +5,7 @@ import { TokenTransfer } from '@wormhole-foundation/sdk-connect';
5
5
  import * as _moonbeam_network_xcm_types from '@moonbeam-network/xcm-types';
6
6
  import { AssetAmount, AnyChain, EvmChain, EvmParachain, Ecosystem, AnyAsset } from '@moonbeam-network/xcm-types';
7
7
  import { Signer } from '@polkadot/api/types';
8
- import { IKeyringPair } from '@polkadot/types/types';
8
+ import { IKeyringPair, ISubmittableResult } from '@polkadot/types/types';
9
9
  import { WalletClient } from 'viem';
10
10
  import { ConfigService } from '@moonbeam-network/xcm-config';
11
11
 
@@ -16,11 +16,12 @@ interface Signers {
16
16
  interface TransferData {
17
17
  destination: DestinationTransferData;
18
18
  getEstimate(amount: number | string): AssetAmount;
19
+ isAutomaticPossible: boolean;
19
20
  max: AssetAmount;
20
21
  min: AssetAmount;
21
22
  moonChain: MoonChainTransferData;
22
23
  source: SourceTransferData;
23
- transfer(amount: bigint | number | string, isAutomatic: boolean, signers: Signers): Promise<string[]>;
24
+ transfer(amount: bigint | number | string, isAutomatic: boolean, signers: Signers, statusCallback?: (params: ISubmittableResult) => void): Promise<string[]>;
24
25
  }
25
26
  interface SourceTransferData extends SourceChainTransferData {
26
27
  destinationFeeBalance: AssetAmount;
@@ -31,7 +32,9 @@ interface SourceTransferData extends SourceChainTransferData {
31
32
  }
32
33
  interface DestinationTransferData extends ChainTransferData {
33
34
  }
34
- type MoonChainTransferData = Omit<ChainTransferData, 'min'>;
35
+ type MoonChainTransferData = Omit<ChainTransferData, 'min' | 'balance'> & {
36
+ feeBalance: AssetAmount;
37
+ };
35
38
  interface ChainTransferData {
36
39
  chain: AnyChain;
37
40
  balance: AssetAmount;
@@ -60,10 +63,12 @@ declare function Mrl(options?: MrlOptions): {
60
63
  setDestination(destination: string | AnyChain): {
61
64
  assets: _moonbeam_network_xcm_types.Asset[];
62
65
  setAsset(asset: string | AnyAsset): {
63
- setAddresses({ sourceAddress, destinationAddress, }: {
64
- sourceAddress: string;
65
- destinationAddress: string;
66
- }): Promise<TransferData>;
66
+ setIsAutomatic(isAutomatic: boolean): {
67
+ setAddresses({ sourceAddress, destinationAddress, }: {
68
+ sourceAddress: string;
69
+ destinationAddress: string;
70
+ }): Promise<TransferData>;
71
+ };
67
72
  };
68
73
  };
69
74
  };
package/build/index.mjs CHANGED
@@ -11085,7 +11085,7 @@ import {
11085
11085
  EvmChain,
11086
11086
  EvmParachain as EvmParachain2
11087
11087
  } from "@moonbeam-network/xcm-types";
11088
- import { toBigInt as toBigInt2 } from "@moonbeam-network/xcm-utils";
11088
+ import { toBigInt as toBigInt3 } from "@moonbeam-network/xcm-utils";
11089
11089
  import Big2 from "big.js";
11090
11090
 
11091
11091
  // src/getTransferData/getMoonChainData.ts
@@ -11094,7 +11094,6 @@ import { getBalance, getDestinationFee } from "@moonbeam-network/xcm-sdk";
11094
11094
  import { Parachain } from "@moonbeam-network/xcm-types";
11095
11095
  import { getMultilocationDerivedAddresses } from "@moonbeam-network/xcm-utils";
11096
11096
  async function getMoonChainData({
11097
- destinationData,
11098
11097
  route,
11099
11098
  sourceAddress
11100
11099
  }) {
@@ -11104,15 +11103,6 @@ async function getMoonChainData({
11104
11103
  );
11105
11104
  }
11106
11105
  const moonChain = getMoonChain(route.source.chain);
11107
- const asset = moonChain.getChainAsset(route.mrl.moonChain.asset);
11108
- const isDestinationMoonChain = route.destination.chain.isEqual(moonChain);
11109
- if (isDestinationMoonChain) {
11110
- return {
11111
- balance: destinationData.balance,
11112
- chain: destinationData.chain,
11113
- fee: destinationData.fee
11114
- };
11115
- }
11116
11106
  const fee = await getDestinationFee({
11117
11107
  address: sourceAddress,
11118
11108
  // TODO not correct
@@ -11122,7 +11112,7 @@ async function getMoonChainData({
11122
11112
  feeAsset: route.mrl.moonChain.fee.asset
11123
11113
  });
11124
11114
  let address = sourceAddress;
11125
- if (Parachain.is(route.source.chain)) {
11115
+ if (Parachain.is(route.source.chain) && !route.source.chain.isEqual(moonChain)) {
11126
11116
  const { address20 } = getMultilocationDerivedAddresses({
11127
11117
  address: sourceAddress,
11128
11118
  paraId: route.source.chain.parachainId,
@@ -11130,14 +11120,14 @@ async function getMoonChainData({
11130
11120
  });
11131
11121
  address = address20;
11132
11122
  }
11133
- const balance = await getBalance({
11123
+ const feeBalance = await getBalance({
11134
11124
  address,
11135
- asset,
11125
+ asset: moonChain.getChainAsset(route.mrl.moonChain.fee.asset),
11136
11126
  builder: route.mrl.moonChain.fee.balance,
11137
11127
  chain: moonChain
11138
11128
  });
11139
11129
  return {
11140
- balance,
11130
+ feeBalance,
11141
11131
  chain: moonChain,
11142
11132
  fee
11143
11133
  };
@@ -11161,6 +11151,7 @@ import {
11161
11151
  import {
11162
11152
  AssetAmount as AssetAmount2
11163
11153
  } from "@moonbeam-network/xcm-types";
11154
+ import { toBigInt as toBigInt2 } from "@moonbeam-network/xcm-utils";
11164
11155
 
11165
11156
  // src/getTransferData/getTransferData.utils.ts
11166
11157
  import {
@@ -11364,6 +11355,7 @@ async function getMoonGasLimit(params) {
11364
11355
 
11365
11356
  // src/getTransferData/getSourceData.ts
11366
11357
  async function getSourceData({
11358
+ isAutomatic,
11367
11359
  route,
11368
11360
  destinationAddress,
11369
11361
  destinationFee,
@@ -11411,7 +11403,7 @@ async function getSourceData({
11411
11403
  asset: balance,
11412
11404
  destinationAddress,
11413
11405
  feeAsset: feeBalance,
11414
- isAutomatic: route.mrl.isAutomaticPossible,
11406
+ isAutomatic,
11415
11407
  route,
11416
11408
  sourceAddress
11417
11409
  });
@@ -11429,7 +11421,7 @@ async function getSourceData({
11429
11421
  transfer,
11430
11422
  asset: balance,
11431
11423
  feeAsset: feeBalance,
11432
- isAutomatic: route.mrl.isAutomaticPossible,
11424
+ isAutomatic,
11433
11425
  destinationAddress,
11434
11426
  route,
11435
11427
  sourceAddress
@@ -11517,10 +11509,11 @@ async function getWormholeFee({
11517
11509
  config
11518
11510
  }) {
11519
11511
  if (WormholeConfig.is(config)) {
11512
+ const safetyAmount = toBigInt2(1e-6, asset.decimals);
11520
11513
  const wh = WormholeService.create(chain);
11521
11514
  const fee = await wh.getFee(config);
11522
11515
  return AssetAmount2.fromChainAsset(chain.getChainAsset(asset), {
11523
- amount: fee.relayFee?.amount || 0n
11516
+ amount: fee.relayFee ? fee.relayFee.amount + safetyAmount : 0n
11524
11517
  });
11525
11518
  }
11526
11519
  return;
@@ -11557,7 +11550,8 @@ async function getMoonChainFeeBalance({
11557
11550
  async function getTransferData({
11558
11551
  route,
11559
11552
  sourceAddress,
11560
- destinationAddress
11553
+ destinationAddress,
11554
+ isAutomatic
11561
11555
  }) {
11562
11556
  if (!route.mrl) {
11563
11557
  throw new Error(
@@ -11573,13 +11567,13 @@ async function getTransferData({
11573
11567
  target: route.getDestinationFeeAssetOnSource()
11574
11568
  });
11575
11569
  const sourceData = await getSourceData({
11570
+ isAutomatic: route.mrl.isAutomaticPossible && isAutomatic,
11576
11571
  route,
11577
11572
  destinationAddress,
11578
11573
  destinationFee,
11579
11574
  sourceAddress
11580
11575
  });
11581
11576
  const moonChainData = await getMoonChainData({
11582
- destinationData,
11583
11577
  route,
11584
11578
  sourceAddress
11585
11579
  });
@@ -11588,7 +11582,7 @@ async function getTransferData({
11588
11582
  getEstimate(amount) {
11589
11583
  const isSameAssetPayingDestinationFee = sourceData.balance.isSame(destinationFee);
11590
11584
  const bigAmount = Big2(
11591
- toBigInt2(amount, sourceData.balance.decimals).toString()
11585
+ toBigInt3(amount, sourceData.balance.decimals).toString()
11592
11586
  );
11593
11587
  const fee = getMoonChainFeeValueOnSource({
11594
11588
  destinationData,
@@ -11597,11 +11591,12 @@ async function getTransferData({
11597
11591
  });
11598
11592
  const result = bigAmount.minus(
11599
11593
  isSameAssetPayingDestinationFee ? destinationFee.toBig() : Big2(0)
11600
- ).minus(fee);
11594
+ ).minus(fee).minus(sourceData.relayerFee?.toBig() || Big2(0));
11601
11595
  return sourceData.balance.copyWith({
11602
11596
  amount: result.lt(0) ? 0n : BigInt(result.toFixed())
11603
11597
  });
11604
11598
  },
11599
+ isAutomaticPossible: route.mrl.isAutomaticPossible,
11605
11600
  max: sourceData.max,
11606
11601
  min: getMrlMin({
11607
11602
  destinationData,
@@ -11610,9 +11605,9 @@ async function getTransferData({
11610
11605
  }),
11611
11606
  moonChain: moonChainData,
11612
11607
  source: sourceData,
11613
- async transfer(amount, isAutomatic, { evmSigner, polkadotSigner }) {
11608
+ async transfer(amount, isAutomatic2, { evmSigner, polkadotSigner }, statusCallback) {
11614
11609
  const source = route.source.chain;
11615
- const bigintAmount = toBigInt2(amount, sourceData.balance.decimals);
11610
+ const bigintAmount = toBigInt3(amount, sourceData.balance.decimals);
11616
11611
  const asset = AssetAmount3.fromChainAsset(
11617
11612
  route.source.chain.getChainAsset(route.source.asset),
11618
11613
  { amount: bigintAmount }
@@ -11627,7 +11622,7 @@ async function getTransferData({
11627
11622
  asset,
11628
11623
  destinationAddress,
11629
11624
  feeAsset,
11630
- isAutomatic,
11625
+ isAutomatic: isAutomatic2,
11631
11626
  route,
11632
11627
  sourceAddress
11633
11628
  });
@@ -11647,7 +11642,8 @@ async function getTransferData({
11647
11642
  const hash = await polkadot.transfer(
11648
11643
  sourceAddress,
11649
11644
  transfer,
11650
- polkadotSigner
11645
+ polkadotSigner,
11646
+ statusCallback
11651
11647
  );
11652
11648
  return [hash];
11653
11649
  }
@@ -11685,15 +11681,20 @@ function Mrl(options) {
11685
11681
  destination
11686
11682
  });
11687
11683
  return {
11688
- setAddresses({
11689
- sourceAddress,
11690
- destinationAddress
11691
- }) {
11692
- return getTransferData({
11693
- route,
11694
- sourceAddress,
11695
- destinationAddress
11696
- });
11684
+ setIsAutomatic(isAutomatic) {
11685
+ return {
11686
+ setAddresses({
11687
+ sourceAddress,
11688
+ destinationAddress
11689
+ }) {
11690
+ return getTransferData({
11691
+ route,
11692
+ sourceAddress,
11693
+ destinationAddress,
11694
+ isAutomatic
11695
+ });
11696
+ }
11697
+ };
11697
11698
  }
11698
11699
  };
11699
11700
  }