|
@@ -8,7 +8,7 @@ import swapAbi from "../abi/swapAbi.js";
|
|
|
const router = express.Router();
|
|
|
|
|
|
async function sendSwapTx(amountNumber, router, signer, provider, wallet, approveGas) {
|
|
|
- const amountIn = amountNumber * 1000000;
|
|
|
+ const amountIn = amountNumber;
|
|
|
const path = ["0x3355df6D4c9C3035724Fd0e3914dE96A5a83aaf4", "0x5AEa5775959fBC2557Cc8789bC1bf90A239D9a91"];
|
|
|
const stable = [false, false]
|
|
|
let timestamp = new Date().getTime();
|
|
@@ -41,7 +41,7 @@ router.post("/", async (req, res) => {
|
|
|
const amountMin = params.amountMin;
|
|
|
const amountMax = params.amountMax;
|
|
|
const accuracy = params.accuracy;
|
|
|
- const amountNumber = mathUtil.getRandomNumber(amountMin, amountMax, accuracy);
|
|
|
+ const amountNumber = mathUtil.getRandomNumber(amountMin, amountMax, accuracy) * 1000000;
|
|
|
const signer = req.body.wallet;
|
|
|
const provider = new Provider('https://mainnet.era.zksync.io');
|
|
|
|
|
@@ -49,23 +49,23 @@ router.post("/", async (req, res) => {
|
|
|
const router = "0x8b791913eb07c32779a16750e3868aa8495f5964";
|
|
|
const usdc = new Contract("0x3355df6d4c9c3035724fd0e3914de96a5a83aaf4", erc20, wallet);
|
|
|
const routerContract = new Contract(router, swapAbi, wallet);
|
|
|
- const allowance = await usdc.allowance(signer.address, router);
|
|
|
+ // const allowance = await usdc.allowance(signer.address, router);
|
|
|
|
|
|
let result = {};
|
|
|
- if (allowance <= 0) {
|
|
|
- const approveTx = await usdc.approve(router, 0xFFFFFFFF);
|
|
|
- await approveTx.wait();
|
|
|
- const txReceipt = await provider.getTransactionReceipt(approveTx.hash);
|
|
|
- const approveGas = utils.formatEther((txReceipt.gasUsed * approveTx.gasPrice).toFixed(0));
|
|
|
- if (txReceipt.status === 1) {
|
|
|
- result = await sendSwapTx(amountNumber, routerContract, signer, provider, wallet, approveGas);
|
|
|
- } else {
|
|
|
- throw new Error("approve error");
|
|
|
- }
|
|
|
-
|
|
|
+ // if (allowance <= 0) {
|
|
|
+ const approveTx = await usdc.approve(router, amountNumber);
|
|
|
+ await approveTx.wait();
|
|
|
+ const txReceipt = await provider.getTransactionReceipt(approveTx.hash);
|
|
|
+ const approveGas = utils.formatEther((txReceipt.gasUsed * approveTx.gasPrice).toFixed(0));
|
|
|
+ if (txReceipt.status === 1) {
|
|
|
+ result = await sendSwapTx(amountNumber, routerContract, signer, provider, wallet, approveGas);
|
|
|
} else {
|
|
|
- result = await sendSwapTx(amountNumber, routerContract, signer, provider, wallet, 0);
|
|
|
+ throw new Error("approve error");
|
|
|
}
|
|
|
+
|
|
|
+ // } else {
|
|
|
+ // result = await sendSwapTx(amountNumber, routerContract, signer, provider, wallet, 0);
|
|
|
+ // }
|
|
|
res.send(result);
|
|
|
})
|
|
|
|