@stableflow/wallet-evm 3.1.3 → 3.1.4-rc-0f7f3e64ed-20260731
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/dist/index.js +36 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +37 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -312,6 +312,7 @@ var EVMWallet = class {
|
|
|
312
312
|
originLayerzero,
|
|
313
313
|
destinationLayerzero
|
|
314
314
|
} = params;
|
|
315
|
+
const amountLdClean = bridges.removeOftDust(amountWei || 0, fromToken.decimals);
|
|
315
316
|
const result = {
|
|
316
317
|
needApprove: false,
|
|
317
318
|
approveSpender: originLayerzeroAddress,
|
|
@@ -328,8 +329,12 @@ var EVMWallet = class {
|
|
|
328
329
|
estimateSourceGasUsd: "0",
|
|
329
330
|
estimateTime: 0,
|
|
330
331
|
// seconds - dynamically calculated using LayerZero formula
|
|
331
|
-
outputAmount: core.numberRemoveEndZero(Big__default.default(
|
|
332
|
+
outputAmount: core.numberRemoveEndZero(Big__default.default(amountLdClean || 0).div(10 ** params.fromToken.decimals).toFixed(params.fromToken.decimals, 0))
|
|
332
333
|
};
|
|
334
|
+
if (BigInt(amountLdClean) === 0n) {
|
|
335
|
+
result.errMsg = "Amount below minimum cross-chain unit";
|
|
336
|
+
return result;
|
|
337
|
+
}
|
|
333
338
|
const execTime = new core.ExecTime({ type: `Usdt0 EVM ${fromToken.chainName}->${toToken.chainName}`, logStyle: "stone-100", isDebug: core.OpenAPI.DEBUG });
|
|
334
339
|
const provider = utilsEvm.evmRpcFallbackProvider(fromToken);
|
|
335
340
|
const oftContract = new ethers.ethers.Contract(originLayerzeroAddress, abi, this.signer);
|
|
@@ -356,7 +361,7 @@ var EVMWallet = class {
|
|
|
356
361
|
const sendParam = {
|
|
357
362
|
dstEid,
|
|
358
363
|
to: bridges.addressToBytes32(toToken.chainType, recipient),
|
|
359
|
-
amountLD:
|
|
364
|
+
amountLD: amountLdClean,
|
|
360
365
|
minAmountLD: 0n,
|
|
361
366
|
extraOptions: unMultiHopExtraOptions,
|
|
362
367
|
composeMsg: "0x",
|
|
@@ -392,21 +397,22 @@ var EVMWallet = class {
|
|
|
392
397
|
);
|
|
393
398
|
}
|
|
394
399
|
if (isOriginLegacy || isDestinationLegacy) {
|
|
395
|
-
result.fees.legacyMeshFeeUsd = core.numberRemoveEndZero(Big__default.default(
|
|
396
|
-
result.outputAmount = core.numberRemoveEndZero(Big__default.default(Big__default.default(
|
|
400
|
+
result.fees.legacyMeshFeeUsd = core.numberRemoveEndZero(Big__default.default(amountLdClean || 0).div(10 ** params.fromToken.decimals).times(bridges.USDT0_LEGACY_MESH_TRANSFTER_FEE).toFixed(params.fromToken.decimals));
|
|
401
|
+
result.outputAmount = core.numberRemoveEndZero(Big__default.default(Big__default.default(amountLdClean || 0).div(10 ** params.fromToken.decimals)).minus(result.fees.legacyMeshFeeUsd || 0).toFixed(params.fromToken.decimals, 0));
|
|
397
402
|
}
|
|
398
403
|
if (!dry) {
|
|
399
404
|
execTime.breakpoint();
|
|
400
405
|
const oftData = await oftContractRead.quoteOFT.staticCall(sendParam);
|
|
401
406
|
const [, , oftReceipt] = oftData;
|
|
402
|
-
sendParam.
|
|
407
|
+
sendParam.amountLD = oftReceipt[0].toString();
|
|
408
|
+
sendParam.minAmountLD = Big__default.default(sendParam.amountLD).times(Big__default.default(1).minus(Big__default.default(slippageTolerance || 0).div(100))).toFixed(0);
|
|
403
409
|
result.outputAmount = core.numberRemoveEndZero(Big__default.default(oftReceipt[1].toString()).div(10 ** params.toToken.decimals).toFixed(params.toToken.decimals, 0));
|
|
404
410
|
execTime.log("quoteOFT.staticCall");
|
|
405
411
|
}
|
|
406
412
|
this.csl("EVMWallet quoteOFT", "red-600", "result.outputAmount: %o", result.outputAmount);
|
|
407
413
|
this.csl("EVMWallet quoteOFT", "red-600", "slippageTolerance: %o", slippageTolerance + "%");
|
|
408
|
-
this.csl("EVMWallet quoteOFT", "red-600", "Minimum received amount: %o", Big__default.default(
|
|
409
|
-
if (Big__default.default(result.outputAmount).lt(Big__default.default(
|
|
414
|
+
this.csl("EVMWallet quoteOFT", "red-600", "Minimum received amount: %o", Big__default.default(amountLdClean).div(10 ** fromToken.decimals).times(Big__default.default(1).minus(Big__default.default(slippageTolerance || 0).div(100))).toFixed(6, 0));
|
|
415
|
+
if (Big__default.default(result.outputAmount).lt(Big__default.default(amountLdClean).div(10 ** fromToken.decimals).times(Big__default.default(1).minus(Big__default.default(slippageTolerance || 0).div(100))))) {
|
|
410
416
|
result.errMsg = "Slippage limit exceeded";
|
|
411
417
|
return result;
|
|
412
418
|
}
|
|
@@ -421,7 +427,7 @@ var EVMWallet = class {
|
|
|
421
427
|
contractAddress: fromToken.contractAddress,
|
|
422
428
|
spender: originLayerzeroAddress,
|
|
423
429
|
address: refundTo,
|
|
424
|
-
amountWei,
|
|
430
|
+
amountWei: amountLdClean,
|
|
425
431
|
provider
|
|
426
432
|
})
|
|
427
433
|
);
|
|
@@ -886,6 +892,18 @@ var EVMWallet = class {
|
|
|
886
892
|
eid: dstEid
|
|
887
893
|
} = destinationLayerzero;
|
|
888
894
|
const isFromEthereum = fromToken.chainId === 1;
|
|
895
|
+
const oftAddress = isFromEthereum ? lockbox : fromToken.contractAddress;
|
|
896
|
+
const provider = utilsEvm.evmRpcFallbackProvider(fromToken);
|
|
897
|
+
let amountLdClean = bridges.removeOftDust(amountWei || 0, fromToken.decimals);
|
|
898
|
+
if (!dry) {
|
|
899
|
+
try {
|
|
900
|
+
const oftContractRead = new ethers.ethers.Contract(oftAddress, bridges.OFT_ABI, provider);
|
|
901
|
+
amountLdClean = (await oftContractRead.removeDust.staticCall(amountWei)).toString();
|
|
902
|
+
} catch (error) {
|
|
903
|
+
this.csl("EVM quoteFraxZero", "yellow-500", "removeDust failed, use local: %o", error);
|
|
904
|
+
amountLdClean = bridges.removeOftDust(amountWei || 0, fromToken.decimals);
|
|
905
|
+
}
|
|
906
|
+
}
|
|
889
907
|
const result = {
|
|
890
908
|
needApprove: false,
|
|
891
909
|
approveSpender: remoteHop,
|
|
@@ -899,21 +917,24 @@ var EVMWallet = class {
|
|
|
899
917
|
totalEstimateSourceGas: 0n,
|
|
900
918
|
estimateSourceGasUsd: 0,
|
|
901
919
|
estimateTime: 0,
|
|
902
|
-
outputAmount: core.numberRemoveEndZero(Big__default.default(
|
|
920
|
+
outputAmount: core.numberRemoveEndZero(Big__default.default(amountLdClean || 0).div(10 ** params.fromToken.decimals).toFixed(params.fromToken.decimals, 0))
|
|
903
921
|
};
|
|
904
|
-
|
|
922
|
+
if (BigInt(amountLdClean) === 0n) {
|
|
923
|
+
result.errMsg = "Amount below minimum cross-chain unit";
|
|
924
|
+
return result;
|
|
925
|
+
}
|
|
905
926
|
const execTime = new core.ExecTime({ type: `FraxZero EVM ${fromToken.chainName}->${toToken.chainName}`, logStyle: "stone-500", isDebug: core.OpenAPI.DEBUG });
|
|
906
927
|
const remoteHopContract = new ethers.ethers.Contract(remoteHop, abi, this.signer);
|
|
907
928
|
const remoteHopContractRead = new ethers.ethers.Contract(remoteHop, abi, provider);
|
|
908
929
|
const sendParams = [
|
|
909
930
|
// _oft
|
|
910
|
-
|
|
931
|
+
oftAddress,
|
|
911
932
|
// _dstEid
|
|
912
933
|
dstEid,
|
|
913
934
|
// _to
|
|
914
935
|
bridges.addressToBytes32(toToken.chainType, recipient),
|
|
915
|
-
// _amountLD
|
|
916
|
-
|
|
936
|
+
// _amountLD (OFT sharedDecimals dust removed)
|
|
937
|
+
amountLdClean
|
|
917
938
|
];
|
|
918
939
|
execTime.breakpoint();
|
|
919
940
|
const mergedCalls = [
|
|
@@ -922,7 +943,7 @@ var EVMWallet = class {
|
|
|
922
943
|
contractAddress: fromToken.contractAddress,
|
|
923
944
|
spender: remoteHop,
|
|
924
945
|
address: refundTo,
|
|
925
|
-
amountWei,
|
|
946
|
+
amountWei: amountLdClean,
|
|
926
947
|
provider
|
|
927
948
|
}),
|
|
928
949
|
remoteHopContractRead.quote.staticCall(...sendParams)
|
|
@@ -940,6 +961,7 @@ var EVMWallet = class {
|
|
|
940
961
|
result.fees.nativeFeeUsd = core.numberRemoveEndZero(Big__default.default(nativeFeeUsd).toFixed(20));
|
|
941
962
|
result.fees.lzTokenFeeUsd = core.numberRemoveEndZero(Big__default.default(msgFee[1]?.toString() || 0).div(10 ** fromToken.decimals).toFixed(20));
|
|
942
963
|
this.csl("EVM quoteFraxZero", "blue-700", "msgFee: %o", msgFee);
|
|
964
|
+
this.csl("EVM quoteFraxZero", "blue-700", "amountLdClean: %o", amountLdClean);
|
|
943
965
|
execTime.breakpoint();
|
|
944
966
|
const finalSendParam = [...sendParams, { value: nativeMsgFee }];
|
|
945
967
|
const ett = await this.estimateTransaction({
|