@moonbeam-network/mrl 1.0.0-dev.295 → 1.0.0-dev.296
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.mjs +40 -60
- package/build/index.mjs.map +1 -1
- package/package.json +6 -6
package/build/index.mjs
CHANGED
|
@@ -16798,7 +16798,7 @@ import {
|
|
|
16798
16798
|
import {
|
|
16799
16799
|
AssetAmount as AssetAmount3,
|
|
16800
16800
|
EvmChain as EvmChain3,
|
|
16801
|
-
EvmParachain as
|
|
16801
|
+
EvmParachain as EvmParachain2
|
|
16802
16802
|
} from "@moonbeam-network/xcm-types";
|
|
16803
16803
|
import { toBigInt as toBigInt3 } from "@moonbeam-network/xcm-utils";
|
|
16804
16804
|
import Big2 from "big.js";
|
|
@@ -16809,11 +16809,7 @@ import {
|
|
|
16809
16809
|
ERC20_ABI,
|
|
16810
16810
|
GATEWAY_ABI
|
|
16811
16811
|
} from "@moonbeam-network/xcm-builder";
|
|
16812
|
-
import {
|
|
16813
|
-
EvmService as EvmService2,
|
|
16814
|
-
getAllowanceSlot,
|
|
16815
|
-
MAX_ALLOWANCE_HEX
|
|
16816
|
-
} from "@moonbeam-network/xcm-sdk";
|
|
16812
|
+
import { EvmService as EvmService2 } from "@moonbeam-network/xcm-sdk";
|
|
16817
16813
|
import { EvmChain } from "@moonbeam-network/xcm-types";
|
|
16818
16814
|
import { isEthAddress } from "@moonbeam-network/xcm-utils";
|
|
16819
16815
|
import { u8aToHex } from "@polkadot/util";
|
|
@@ -16912,7 +16908,7 @@ var SnowbridgeService = class _SnowbridgeService {
|
|
|
16912
16908
|
});
|
|
16913
16909
|
return hash;
|
|
16914
16910
|
}
|
|
16915
|
-
async getFee(address, transfer
|
|
16911
|
+
async getFee(address, transfer) {
|
|
16916
16912
|
const { args } = transfer;
|
|
16917
16913
|
const { tokenAddress, amount, requiresApproval } = args;
|
|
16918
16914
|
const contract = this.buildContractConfig(transfer);
|
|
@@ -16927,20 +16923,11 @@ var SnowbridgeService = class _SnowbridgeService {
|
|
|
16927
16923
|
if (currentAllowance >= amount) {
|
|
16928
16924
|
return await this.#evmService.getFee(address, contract);
|
|
16929
16925
|
}
|
|
16930
|
-
return await this.estimateApproveAndSendFee(
|
|
16931
|
-
address,
|
|
16932
|
-
transfer,
|
|
16933
|
-
allowanceSlot
|
|
16934
|
-
);
|
|
16926
|
+
return await this.estimateApproveAndSendFee(address, transfer);
|
|
16935
16927
|
}
|
|
16936
|
-
async estimateApproveAndSendFee(address, transfer
|
|
16928
|
+
async estimateApproveAndSendFee(address, transfer) {
|
|
16937
16929
|
const { args } = transfer;
|
|
16938
16930
|
const { tokenAddress, amount } = args;
|
|
16939
|
-
if (!allowanceSlotNumber) {
|
|
16940
|
-
throw new Error(
|
|
16941
|
-
"Allowance slot is required to calculate the fee for approve and send"
|
|
16942
|
-
);
|
|
16943
|
-
}
|
|
16944
16931
|
const contract = this.buildContractConfig(transfer);
|
|
16945
16932
|
try {
|
|
16946
16933
|
const approveData = encodeFunctionData({
|
|
@@ -16953,24 +16940,19 @@ var SnowbridgeService = class _SnowbridgeService {
|
|
|
16953
16940
|
to: tokenAddress,
|
|
16954
16941
|
data: approveData
|
|
16955
16942
|
});
|
|
16956
|
-
const
|
|
16957
|
-
|
|
16958
|
-
|
|
16959
|
-
|
|
16960
|
-
);
|
|
16961
|
-
const
|
|
16962
|
-
|
|
16963
|
-
|
|
16964
|
-
|
|
16965
|
-
|
|
16966
|
-
|
|
16967
|
-
value: MAX_ALLOWANCE_HEX
|
|
16968
|
-
}
|
|
16969
|
-
]
|
|
16970
|
-
}
|
|
16971
|
-
]);
|
|
16943
|
+
const sendData = encodeFunctionData({
|
|
16944
|
+
abi: contract.abi,
|
|
16945
|
+
functionName: contract.func,
|
|
16946
|
+
args: contract.args
|
|
16947
|
+
});
|
|
16948
|
+
const sendGas = await this.#evmService.client.estimateGas({
|
|
16949
|
+
account: address,
|
|
16950
|
+
to: contract.address,
|
|
16951
|
+
data: sendData,
|
|
16952
|
+
value: contract.value
|
|
16953
|
+
});
|
|
16972
16954
|
const gasPrice = await this.#evmService.client.getGasPrice();
|
|
16973
|
-
return approveGas * gasPrice
|
|
16955
|
+
return (approveGas + sendGas) * gasPrice;
|
|
16974
16956
|
} catch (error) {
|
|
16975
16957
|
console.error("Error estimating approve + send fee:", error);
|
|
16976
16958
|
return 0n;
|
|
@@ -16980,7 +16962,7 @@ var SnowbridgeService = class _SnowbridgeService {
|
|
|
16980
16962
|
|
|
16981
16963
|
// src/getTransferData/getBridgeChainData.ts
|
|
16982
16964
|
import { getBalance, getDestinationFee } from "@moonbeam-network/xcm-sdk";
|
|
16983
|
-
import {
|
|
16965
|
+
import { Parachain } from "@moonbeam-network/xcm-types";
|
|
16984
16966
|
import {
|
|
16985
16967
|
getMultilocationDerivedAddresses,
|
|
16986
16968
|
isEthAddress as isEthAddress2
|
|
@@ -17040,17 +17022,17 @@ function getBridgeChainAddress({
|
|
|
17040
17022
|
const bridgeChain = route.mrl.bridgeChain.chain;
|
|
17041
17023
|
const isDestinationBridgeChain = bridgeChain.isEqual(destination);
|
|
17042
17024
|
const isSourceBridgeChain = bridgeChain.isEqual(source);
|
|
17025
|
+
const isDifferentEcosystem = source.ecosystem !== bridgeChain.ecosystem;
|
|
17043
17026
|
let bridgeChainAddress = isDestinationBridgeChain ? destinationAddress : sourceAddress;
|
|
17044
17027
|
if (Parachain.isExactly(bridgeChain) && isEthAddress2(bridgeChainAddress)) {
|
|
17045
17028
|
bridgeChainAddress = evmToAddress(bridgeChainAddress);
|
|
17046
17029
|
return bridgeChainAddress;
|
|
17047
17030
|
}
|
|
17048
17031
|
if (Parachain.is(source) && !isSourceBridgeChain) {
|
|
17049
|
-
const isSourceEvmSigner = EvmParachain.is(source) && source.isEvmSigner;
|
|
17050
17032
|
const { address20: computedOriginAccount } = getMultilocationDerivedAddresses({
|
|
17051
|
-
address:
|
|
17033
|
+
address: sourceAddress,
|
|
17052
17034
|
paraId: source.parachainId,
|
|
17053
|
-
|
|
17035
|
+
parents: isDifferentEcosystem ? 2 : 1
|
|
17054
17036
|
});
|
|
17055
17037
|
bridgeChainAddress = computedOriginAccount;
|
|
17056
17038
|
}
|
|
@@ -17092,7 +17074,8 @@ import {
|
|
|
17092
17074
|
} from "@moonbeam-network/xcm-builder";
|
|
17093
17075
|
import {
|
|
17094
17076
|
moonbaseAlpha,
|
|
17095
|
-
moonbeam
|
|
17077
|
+
moonbeam,
|
|
17078
|
+
moonriver
|
|
17096
17079
|
} from "@moonbeam-network/xcm-config";
|
|
17097
17080
|
import {
|
|
17098
17081
|
convertToChainDecimals,
|
|
@@ -17100,7 +17083,7 @@ import {
|
|
|
17100
17083
|
getMin,
|
|
17101
17084
|
PolkadotService
|
|
17102
17085
|
} from "@moonbeam-network/xcm-sdk";
|
|
17103
|
-
import { AssetAmount, EvmParachain
|
|
17086
|
+
import { AssetAmount, EvmParachain } from "@moonbeam-network/xcm-types";
|
|
17104
17087
|
import {
|
|
17105
17088
|
getMultilocationDerivedAddresses as getMultilocationDerivedAddresses2,
|
|
17106
17089
|
getPolkadotApi
|
|
@@ -17113,6 +17096,7 @@ import {
|
|
|
17113
17096
|
} from "viem";
|
|
17114
17097
|
var MOON_CHAIN_AUTOMATIC_GAS_ESTIMATION = {
|
|
17115
17098
|
[moonbeam.key]: 1273110n,
|
|
17099
|
+
[moonriver.key]: 1273110n,
|
|
17116
17100
|
[moonbaseAlpha.key]: 1470417n
|
|
17117
17101
|
};
|
|
17118
17102
|
function getBridgeChainFeeValueOnSource({
|
|
@@ -17120,7 +17104,7 @@ function getBridgeChainFeeValueOnSource({
|
|
|
17120
17104
|
bridgeChainData,
|
|
17121
17105
|
sourceData
|
|
17122
17106
|
}) {
|
|
17123
|
-
const isSourceParachain =
|
|
17107
|
+
const isSourceParachain = EvmParachain.isAnyParachain(sourceData.chain);
|
|
17124
17108
|
const isDestinationBridgeChain = destinationData.chain.isEqual(
|
|
17125
17109
|
bridgeChainData.chain
|
|
17126
17110
|
);
|
|
@@ -17155,7 +17139,7 @@ function getMrlMin({
|
|
|
17155
17139
|
});
|
|
17156
17140
|
}
|
|
17157
17141
|
function requiresTransact(route) {
|
|
17158
|
-
return route.mrl?.transfer.provider === Provider.Wormhole &&
|
|
17142
|
+
return route.mrl?.transfer.provider === Provider.Wormhole && EvmParachain.isAnyParachain(route.source.chain);
|
|
17159
17143
|
}
|
|
17160
17144
|
async function buildTransfer(params) {
|
|
17161
17145
|
const { route } = params;
|
|
@@ -17195,8 +17179,8 @@ async function getMrlBuilderParams({
|
|
|
17195
17179
|
const destination = route.destination.chain;
|
|
17196
17180
|
const bridgeChain = route.mrl.bridgeChain.chain;
|
|
17197
17181
|
const [sourceApi, destinationApi, bridgeApi] = await Promise.all([
|
|
17198
|
-
|
|
17199
|
-
|
|
17182
|
+
EvmParachain.isAnyParachain(source) ? getPolkadotApi(source.ws) : void 0,
|
|
17183
|
+
EvmParachain.isAnyParachain(destination) ? getPolkadotApi(destination.ws) : void 0,
|
|
17200
17184
|
getPolkadotApi(bridgeChain.ws)
|
|
17201
17185
|
]);
|
|
17202
17186
|
return {
|
|
@@ -17221,13 +17205,14 @@ async function getTransact(params) {
|
|
|
17221
17205
|
const { sourceAddress, source, bridgeChain } = params;
|
|
17222
17206
|
const polkadot = await PolkadotService.create(bridgeChain);
|
|
17223
17207
|
const bridgeChainGasLimit = await getBridgeChainGasLimit(params);
|
|
17224
|
-
if (!
|
|
17208
|
+
if (!EvmParachain.isAnyParachain(source)) {
|
|
17225
17209
|
throw new Error("Source chain must be Parachain or EvmParachain");
|
|
17226
17210
|
}
|
|
17211
|
+
const isDifferentEcosystem = source.ecosystem !== bridgeChain.ecosystem;
|
|
17227
17212
|
const { address20 } = getMultilocationDerivedAddresses2({
|
|
17228
17213
|
address: sourceAddress,
|
|
17229
17214
|
paraId: source.parachainId,
|
|
17230
|
-
|
|
17215
|
+
parents: isDifferentEcosystem ? 2 : 1
|
|
17231
17216
|
});
|
|
17232
17217
|
const extrinsic = MrlBuilder2().wormhole().extrinsic().ethereumXcm().transact().build({ ...params, bridgeChainGasLimit });
|
|
17233
17218
|
const { weight } = await polkadot.getPaymentInfo(address20, extrinsic);
|
|
@@ -17241,10 +17226,10 @@ async function getTransact(params) {
|
|
|
17241
17226
|
}
|
|
17242
17227
|
async function getBridgeChainGasLimit(params) {
|
|
17243
17228
|
const { asset, isAutomatic, bridgeChain, source, sourceAddress } = params;
|
|
17244
|
-
if (!
|
|
17229
|
+
if (!EvmParachain.isAnyParachain(source)) {
|
|
17245
17230
|
throw new Error("Source chain must be Parachain or EvmParachain");
|
|
17246
17231
|
}
|
|
17247
|
-
if (!
|
|
17232
|
+
if (!EvmParachain.is(bridgeChain)) {
|
|
17248
17233
|
throw new Error("Bridge chain must be an EvmParachain");
|
|
17249
17234
|
}
|
|
17250
17235
|
const client = createPublicClient2({
|
|
@@ -17254,7 +17239,7 @@ async function getBridgeChainGasLimit(params) {
|
|
|
17254
17239
|
const { address20 } = getMultilocationDerivedAddresses2({
|
|
17255
17240
|
address: sourceAddress,
|
|
17256
17241
|
paraId: source.parachainId,
|
|
17257
|
-
|
|
17242
|
+
parents: 1
|
|
17258
17243
|
});
|
|
17259
17244
|
if (isAutomatic) {
|
|
17260
17245
|
return MOON_CHAIN_AUTOMATIC_GAS_ESTIMATION[bridgeChain.key] * 110n / 100n;
|
|
@@ -17452,12 +17437,7 @@ async function getFee({
|
|
|
17452
17437
|
if (SnowbridgeConfig.is(transfer)) {
|
|
17453
17438
|
const snowbridge = SnowbridgeService.create(chain2);
|
|
17454
17439
|
try {
|
|
17455
|
-
const
|
|
17456
|
-
const feeAmount = await snowbridge.getFee(
|
|
17457
|
-
sourceAddress,
|
|
17458
|
-
transfer,
|
|
17459
|
-
allowanceSlot
|
|
17460
|
-
);
|
|
17440
|
+
const feeAmount = await snowbridge.getFee(sourceAddress, transfer);
|
|
17461
17441
|
return AssetAmount2.fromChainAsset(chain2.getChainAsset(feeBalance), {
|
|
17462
17442
|
amount: feeAmount
|
|
17463
17443
|
});
|
|
@@ -17745,7 +17725,7 @@ async function getTransferData({
|
|
|
17745
17725
|
sendOnlyRemoteExecution,
|
|
17746
17726
|
sourceAddress
|
|
17747
17727
|
});
|
|
17748
|
-
if (ContractConfig3.is(transfer) && (EvmChain3.is(source) ||
|
|
17728
|
+
if (ContractConfig3.is(transfer) && (EvmChain3.is(source) || EvmParachain2.is(source))) {
|
|
17749
17729
|
if (!evmSigner) {
|
|
17750
17730
|
throw new Error("EVM Signer must be provided");
|
|
17751
17731
|
}
|
|
@@ -17753,7 +17733,7 @@ async function getTransferData({
|
|
|
17753
17733
|
const hash = await evm.transfer(evmSigner, transfer);
|
|
17754
17734
|
return [hash];
|
|
17755
17735
|
}
|
|
17756
|
-
if (ExtrinsicConfig.is(transfer) &&
|
|
17736
|
+
if (ExtrinsicConfig.is(transfer) && EvmParachain2.isAnyParachain(source)) {
|
|
17757
17737
|
if (!polkadotSigner) {
|
|
17758
17738
|
throw new Error("Polkadot signer must be provided");
|
|
17759
17739
|
}
|
|
@@ -17766,14 +17746,14 @@ async function getTransferData({
|
|
|
17766
17746
|
);
|
|
17767
17747
|
return [hash];
|
|
17768
17748
|
}
|
|
17769
|
-
if (WormholeConfig2.is(transfer) && (EvmChain3.is(source) ||
|
|
17749
|
+
if (WormholeConfig2.is(transfer) && (EvmChain3.is(source) || EvmParachain2.is(source))) {
|
|
17770
17750
|
if (!evmSigner) {
|
|
17771
17751
|
throw new Error("EVM Signer must be provided");
|
|
17772
17752
|
}
|
|
17773
17753
|
const wh = WormholeService.create(source);
|
|
17774
17754
|
return wh.transfer(evmSigner, transfer);
|
|
17775
17755
|
}
|
|
17776
|
-
if (SnowbridgeConfig2.is(transfer) && (EvmChain3.is(source) ||
|
|
17756
|
+
if (SnowbridgeConfig2.is(transfer) && (EvmChain3.is(source) || EvmParachain2.is(source))) {
|
|
17777
17757
|
if (!evmSigner) {
|
|
17778
17758
|
throw new Error("EVM Signer must be provided");
|
|
17779
17759
|
}
|