@moonbeam-network/mrl 4.2.4 → 4.2.6
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 -17
- package/build/index.mjs.map +1 -1
- package/package.json +5 -5
package/build/index.mjs
CHANGED
|
@@ -16809,7 +16809,11 @@ import {
|
|
|
16809
16809
|
ERC20_ABI,
|
|
16810
16810
|
GATEWAY_ABI
|
|
16811
16811
|
} from "@moonbeam-network/xcm-builder";
|
|
16812
|
-
import {
|
|
16812
|
+
import {
|
|
16813
|
+
EvmService as EvmService2,
|
|
16814
|
+
getAllowanceSlot,
|
|
16815
|
+
MAX_ALLOWANCE_HEX
|
|
16816
|
+
} from "@moonbeam-network/xcm-sdk";
|
|
16813
16817
|
import { EvmChain } from "@moonbeam-network/xcm-types";
|
|
16814
16818
|
import { isEthAddress } from "@moonbeam-network/xcm-utils";
|
|
16815
16819
|
import { u8aToHex } from "@polkadot/util";
|
|
@@ -16908,7 +16912,7 @@ var SnowbridgeService = class _SnowbridgeService {
|
|
|
16908
16912
|
});
|
|
16909
16913
|
return hash;
|
|
16910
16914
|
}
|
|
16911
|
-
async getFee(address, transfer) {
|
|
16915
|
+
async getFee(address, transfer, allowanceSlot) {
|
|
16912
16916
|
const { args } = transfer;
|
|
16913
16917
|
const { tokenAddress, amount, requiresApproval } = args;
|
|
16914
16918
|
const contract = this.buildContractConfig(transfer);
|
|
@@ -16923,11 +16927,20 @@ var SnowbridgeService = class _SnowbridgeService {
|
|
|
16923
16927
|
if (currentAllowance >= amount) {
|
|
16924
16928
|
return await this.#evmService.getFee(address, contract);
|
|
16925
16929
|
}
|
|
16926
|
-
return await this.estimateApproveAndSendFee(
|
|
16930
|
+
return await this.estimateApproveAndSendFee(
|
|
16931
|
+
address,
|
|
16932
|
+
transfer,
|
|
16933
|
+
allowanceSlot
|
|
16934
|
+
);
|
|
16927
16935
|
}
|
|
16928
|
-
async estimateApproveAndSendFee(address, transfer) {
|
|
16936
|
+
async estimateApproveAndSendFee(address, transfer, allowanceSlotNumber) {
|
|
16929
16937
|
const { args } = transfer;
|
|
16930
16938
|
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
|
+
}
|
|
16931
16944
|
const contract = this.buildContractConfig(transfer);
|
|
16932
16945
|
try {
|
|
16933
16946
|
const approveData = encodeFunctionData({
|
|
@@ -16940,19 +16953,24 @@ var SnowbridgeService = class _SnowbridgeService {
|
|
|
16940
16953
|
to: tokenAddress,
|
|
16941
16954
|
data: approveData
|
|
16942
16955
|
});
|
|
16943
|
-
const
|
|
16944
|
-
|
|
16945
|
-
|
|
16946
|
-
|
|
16947
|
-
|
|
16948
|
-
const
|
|
16949
|
-
|
|
16950
|
-
|
|
16951
|
-
|
|
16952
|
-
|
|
16953
|
-
|
|
16956
|
+
const allowanceSlot = getAllowanceSlot(
|
|
16957
|
+
address,
|
|
16958
|
+
this.#gatewayAddress,
|
|
16959
|
+
allowanceSlotNumber
|
|
16960
|
+
);
|
|
16961
|
+
const sendFee = await this.#evmService.getFee(address, contract, [
|
|
16962
|
+
{
|
|
16963
|
+
address: tokenAddress,
|
|
16964
|
+
stateDiff: [
|
|
16965
|
+
{
|
|
16966
|
+
slot: allowanceSlot,
|
|
16967
|
+
value: MAX_ALLOWANCE_HEX
|
|
16968
|
+
}
|
|
16969
|
+
]
|
|
16970
|
+
}
|
|
16971
|
+
]);
|
|
16954
16972
|
const gasPrice = await this.#evmService.client.getGasPrice();
|
|
16955
|
-
return
|
|
16973
|
+
return approveGas * gasPrice + sendFee;
|
|
16956
16974
|
} catch (error) {
|
|
16957
16975
|
console.error("Error estimating approve + send fee:", error);
|
|
16958
16976
|
return 0n;
|
|
@@ -17434,7 +17452,12 @@ async function getFee({
|
|
|
17434
17452
|
if (SnowbridgeConfig.is(transfer)) {
|
|
17435
17453
|
const snowbridge = SnowbridgeService.create(chain2);
|
|
17436
17454
|
try {
|
|
17437
|
-
const
|
|
17455
|
+
const allowanceSlot = balance.ids?.allowanceSlot;
|
|
17456
|
+
const feeAmount = await snowbridge.getFee(
|
|
17457
|
+
sourceAddress,
|
|
17458
|
+
transfer,
|
|
17459
|
+
allowanceSlot
|
|
17460
|
+
);
|
|
17438
17461
|
return AssetAmount2.fromChainAsset(chain2.getChainAsset(feeBalance), {
|
|
17439
17462
|
amount: feeAmount
|
|
17440
17463
|
});
|