@moonbeam-network/mrl 1.0.0-dev.153 → 1.0.0-dev.157
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 +20 -9
- package/build/index.mjs +36 -35
- package/build/index.mjs.map +1 -1
- package/package.json +10 -10
package/build/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import * as _moonbeam_network_xcm_sdk from '@moonbeam-network/xcm-sdk';
|
|
2
|
-
import { SourceChainTransferData } from '@moonbeam-network/xcm-sdk';
|
|
2
|
+
import { SourceChainTransferData, EvmSigner } from '@moonbeam-network/xcm-sdk';
|
|
3
3
|
import * as _wormhole_foundation_sdk_connect from '@wormhole-foundation/sdk-connect';
|
|
4
|
+
import { TokenTransfer } from '@wormhole-foundation/sdk-connect';
|
|
4
5
|
import * as _moonbeam_network_xcm_types from '@moonbeam-network/xcm-types';
|
|
5
6
|
import { AssetAmount, AnyChain, EvmChain, EvmParachain, Ecosystem, AnyAsset } from '@moonbeam-network/xcm-types';
|
|
6
7
|
import { Signer } from '@polkadot/api/types';
|
|
7
|
-
import { IKeyringPair } from '@polkadot/types/types';
|
|
8
|
+
import { IKeyringPair, ISubmittableResult } from '@polkadot/types/types';
|
|
8
9
|
import { WalletClient } from 'viem';
|
|
9
10
|
import { ConfigService } from '@moonbeam-network/xcm-config';
|
|
10
11
|
|
|
@@ -15,11 +16,12 @@ interface Signers {
|
|
|
15
16
|
interface TransferData {
|
|
16
17
|
destination: DestinationTransferData;
|
|
17
18
|
getEstimate(amount: number | string): AssetAmount;
|
|
19
|
+
isAutomaticPossible: boolean;
|
|
18
20
|
max: AssetAmount;
|
|
19
21
|
min: AssetAmount;
|
|
20
22
|
moonChain: MoonChainTransferData;
|
|
21
23
|
source: SourceTransferData;
|
|
22
|
-
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[]>;
|
|
23
25
|
}
|
|
24
26
|
interface SourceTransferData extends SourceChainTransferData {
|
|
25
27
|
destinationFeeBalance: AssetAmount;
|
|
@@ -30,13 +32,20 @@ interface SourceTransferData extends SourceChainTransferData {
|
|
|
30
32
|
}
|
|
31
33
|
interface DestinationTransferData extends ChainTransferData {
|
|
32
34
|
}
|
|
33
|
-
type MoonChainTransferData = Omit<ChainTransferData, 'min'
|
|
35
|
+
type MoonChainTransferData = Omit<ChainTransferData, 'min' | 'balance'> & {
|
|
36
|
+
feeBalance: AssetAmount;
|
|
37
|
+
};
|
|
34
38
|
interface ChainTransferData {
|
|
35
39
|
chain: AnyChain;
|
|
36
40
|
balance: AssetAmount;
|
|
37
41
|
fee: AssetAmount;
|
|
38
42
|
min: AssetAmount;
|
|
39
43
|
}
|
|
44
|
+
type RedeemData = {
|
|
45
|
+
vaa: TokenTransfer.VAA;
|
|
46
|
+
tokenTransfer: TokenTransfer;
|
|
47
|
+
transfer(signer: EvmSigner): Promise<string[]>;
|
|
48
|
+
};
|
|
40
49
|
|
|
41
50
|
interface WormholeRedeemParams {
|
|
42
51
|
txId: string;
|
|
@@ -54,10 +63,12 @@ declare function Mrl(options?: MrlOptions): {
|
|
|
54
63
|
setDestination(destination: string | AnyChain): {
|
|
55
64
|
assets: _moonbeam_network_xcm_types.Asset[];
|
|
56
65
|
setAsset(asset: string | AnyAsset): {
|
|
57
|
-
|
|
58
|
-
sourceAddress:
|
|
59
|
-
|
|
60
|
-
|
|
66
|
+
setIsAutomatic(isAutomatic: boolean): {
|
|
67
|
+
setAddresses({ sourceAddress, destinationAddress, }: {
|
|
68
|
+
sourceAddress: string;
|
|
69
|
+
destinationAddress: string;
|
|
70
|
+
}): Promise<TransferData>;
|
|
71
|
+
};
|
|
61
72
|
};
|
|
62
73
|
};
|
|
63
74
|
};
|
|
@@ -68,4 +79,4 @@ declare function Mrl(options?: MrlOptions): {
|
|
|
68
79
|
}>;
|
|
69
80
|
};
|
|
70
81
|
|
|
71
|
-
export { Mrl, type MrlOptions };
|
|
82
|
+
export { type ChainTransferData, type DestinationTransferData, type MoonChainTransferData, Mrl, type MrlOptions, type RedeemData, type Signers, type SourceTransferData, type TransferData };
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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,
|
|
11608
|
+
async transfer(amount, isAutomatic2, { evmSigner, polkadotSigner }, statusCallback) {
|
|
11614
11609
|
const source = route.source.chain;
|
|
11615
|
-
const bigintAmount =
|
|
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
|
-
|
|
11689
|
-
|
|
11690
|
-
|
|
11691
|
-
|
|
11692
|
-
|
|
11693
|
-
|
|
11694
|
-
|
|
11695
|
-
|
|
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
|
}
|