const { ethers, JsonRpcProvider } = require("ethers");
const ERC20_ABI = [
"function allowance(address owner, address spender) view returns (uint256)",
"function approve(address spender, uint256 amount) returns (bool)",
];
const PERMIT2_ABI = [
"function allowance(address owner, address token, address spender) view returns (uint160 amount, uint48 expiration, uint48 nonce)",
"function approve(address token, address spender, uint160 amount, uint48 expiration)",
];
const privateKey =
"";
const provider = new JsonRpcProvider("https://ethereum-rpc.publicnode.com");
const walletSigner = new ethers.Wallet(privateKey, provider); // NOTE: add private key
async function executeUniswapSwap(signer) {
const USDT_ADDRESS = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"; // input token
const usdt = new ethers.Contract(USDT_ADDRESS, ERC20_ABI, signer);
const walletAddress = await signer.getAddress();
let address = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
const usdtToPermit2Allowance = await usdt.allowance(walletAddress, address);
console.log(
"USDT allowance to Permit2:",
usdtToPermit2Allowance.toString(),
);
// const resetTx = await usdt.approve(address, 0n);
// await resetTx.wait();
// console.log(
// "USDT allowance to Permit2:",
// usdtToPermit2Allowance.toString(),
// );
// const usdtToPermit2Allowance2 = await usdt.allowance(walletAddress, address);
// console.log("USDT allowance to Permit2:", usdtToPermit2Allowance2.toString());
}
async function permitAllowance(signer) {
const USDT_ADDRESS = "0xdAC17F958D2ee523a2206206994597C13D831ec7";
let address = "0x000000000022D473030F116dDEE9F6B43aC78BA3"; // uniswap permit address
const swapTo = "0x66a9893cC07D91D95644AEDD05D03f95e1dBA8Af"; // uniswap swap routers
const walletAddress = await signer.getAddress();
const permit2Contract = new ethers.Contract(
address,
PERMIT2_ABI,
walletSigner,
);
const [permit2Amount, permit2Expiration] = await permit2Contract.allowance(
walletAddress,
USDT_ADDRESS,
swapTo,
);
console.log("Permit2 allowance:", permit2Amount.toString());
console.log("Permit2 expiration:", permit2Expiration);
// console.log("Permit2 allowance reseting.....");
// const tx = await permit2Contract.approve(
// USDT_ADDRESS,
// swapTo, // <-- Same spender you queried
// 0,
// 0,
// );
// await tx.wait();
// console.log("Reset to zero Permit2 allowance:");
}
permitAllowance(walletSigner);
// executeUniswapSwap(walletSigner);
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)