@moonbeam-network/mrl 1.0.0-dev.293 → 1.0.0-dev.294
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 +35 -17
- package/build/index.mjs.map +1 -1
- package/package.json +6 -6
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,9 +16927,13 @@ 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;
|
|
16931
16939
|
const contract = this.buildContractConfig(transfer);
|
|
@@ -16940,19 +16948,24 @@ var SnowbridgeService = class _SnowbridgeService {
|
|
|
16940
16948
|
to: tokenAddress,
|
|
16941
16949
|
data: approveData
|
|
16942
16950
|
});
|
|
16943
|
-
const
|
|
16944
|
-
|
|
16945
|
-
|
|
16946
|
-
|
|
16947
|
-
|
|
16948
|
-
const
|
|
16949
|
-
|
|
16950
|
-
|
|
16951
|
-
|
|
16952
|
-
|
|
16953
|
-
|
|
16951
|
+
const allowanceSlot = getAllowanceSlot(
|
|
16952
|
+
address,
|
|
16953
|
+
this.#gatewayAddress,
|
|
16954
|
+
allowanceSlotNumber
|
|
16955
|
+
);
|
|
16956
|
+
const sendFee = await this.#evmService.getFee(address, contract, [
|
|
16957
|
+
{
|
|
16958
|
+
address: tokenAddress,
|
|
16959
|
+
stateDiff: [
|
|
16960
|
+
{
|
|
16961
|
+
slot: allowanceSlot,
|
|
16962
|
+
value: MAX_ALLOWANCE_HEX
|
|
16963
|
+
}
|
|
16964
|
+
]
|
|
16965
|
+
}
|
|
16966
|
+
]);
|
|
16954
16967
|
const gasPrice = await this.#evmService.client.getGasPrice();
|
|
16955
|
-
return
|
|
16968
|
+
return approveGas * gasPrice + sendFee;
|
|
16956
16969
|
} catch (error) {
|
|
16957
16970
|
console.error("Error estimating approve + send fee:", error);
|
|
16958
16971
|
return 0n;
|
|
@@ -17434,7 +17447,12 @@ async function getFee({
|
|
|
17434
17447
|
if (SnowbridgeConfig.is(transfer)) {
|
|
17435
17448
|
const snowbridge = SnowbridgeService.create(chain2);
|
|
17436
17449
|
try {
|
|
17437
|
-
const
|
|
17450
|
+
const allowanceSlot = balance.ids?.allowanceSlot;
|
|
17451
|
+
const feeAmount = await snowbridge.getFee(
|
|
17452
|
+
sourceAddress,
|
|
17453
|
+
transfer,
|
|
17454
|
+
allowanceSlot
|
|
17455
|
+
);
|
|
17438
17456
|
return AssetAmount2.fromChainAsset(chain2.getChainAsset(feeBalance), {
|
|
17439
17457
|
amount: feeAmount
|
|
17440
17458
|
});
|