I'm trying to call Uniswap V2 addLiquidity
function, which calls transferFrom
internally, and therefore approve
must be called beforehand.
I would like to do it from a TypeScript code. In that case, it calls approve
in the first transaction, and then calls addLiquidity
in the second transaction. My question is what happens if the second transaction is failed due to some reasons, such as network trouble or insufficient ETH? Is there a risk that the allowance will remain and be exploited?
I found this code is taking the two transactions approach. Maybe not a good approach?
await token1.approve(routerContract.address, amountIn1);
await token2.approve(routerContract.address, amountIn2);
await routerContract.addLiquidity(
address1, address2, amountIn1, amountIn2, amount1Min, amount2Min, account, deadline
);
Can I avoid this kind of complication without writing a Solidity code?