# safeApprove... forever loop with remix

**URL:** https://forum.openzeppelin.com/t/safeapprove-forever-loop-with-remix/45051
**Category:** Contracts
**Created:** [November 2, 2025, 9:33pm UTC](https://forum.openzeppelin.com/t/safeapprove-forever-loop-with-remix/45051 "2025-11-02T21:33:13Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![EagleDriver](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/eagledriver/32/23198_2.png) [@EagleDriver](https://forum.openzeppelin.com/u/EagleDriver)
#### Post date: [November 2, 2025, 9:33pm UTC](https://forum.openzeppelin.com/t/safeapprove-forever-loop-with-remix/45051/1 "2025-11-02T21:33:13Z")

</div>

Smart Contract infinite loop due to safeApprove SafeERC20

I am attempting to fix code that worked under 0.6.6, but now fails under 0.8.30, and no matter what I do, I can't get past the safeApprove-ERC-SafeERC loop I am in. RemixAI, Grok and ChatGPT all swear by their solutions, but they all loop between these three solution and none of them will compile... how do I get out of this loop? Code snippet of one solution below. Here are the "recommendations" that keep pointing to each other in an endless loop:

Replace:  
'IERC20(token).safeApprove(AAVE, 0);'  
'IERC20(token).safeApprove(AAVE, amount + amount / 1111);'  
With:  
'IERC20 tokenContract = IERC20(token);'  
'tokenContract.safeApprove(AAVE, 0);'  
'tokenContract.safeApprove(AAVE, amount + amount / 1111);'  
Then Replace:  
'tokenContract.safeApprove(AAVE, 0);'  
'tokenContract.safeApprove(AAVE, amount + amount / 1111);'  
With:  
'SafeERC20.safeApprove(IERC20(token), AAVE, 0);'  
'SafeERC20.safeApprove(IERC20(token), AAVE, amount + amount / 1111);'  
Then Replace:  
'SafeERC20.safeApprove(IERC20(token), AAVE, 0);'  
'SafeERC20.safeApprove(IERC20(token), AAVE, amount + amount / 1111);'  
With:  
'IERC20(token).safeApprove(AAVE, 0);'  
'IERC20(token).safeApprove(AAVE, amount + amount / 1111);'  
_sigh_

#### 🔢 Code to reproduce

'''  
\< function go(  
address token,  
uint amount,  
bytes calldata data,  
uint deadline  
) external onlyOwner nonReentrant {  
require(block.timestamp \<= deadline, "deadline passed");  
// Decode the data first to extract r1 and r2  
(address r1, address r2, , , , ) = abi.decode(  
data,  
(address, address, address, address, uint, uint)  
);  
require(routerOk[r1] && routerOk[r2], "bad router");  
address memory assets = new address;  
uint memory amounts = new uint;  
uint memory modes = new uint;  
assets[0] = token;  
amounts[0] = amount;  
modes[0] = 0;  
IERC20 tokenContract = IERC20(token);  
tokenContract.safeApprove(AAVE, 0);  
tokenContract.safeApprove(AAVE, amount + amount / 1111);  
ILendingPool(AAVE).flashLoan(  
address(this), assets, amounts, modes, address(this), data, 0  
);  
}\>  
'''

```auto

```

#### 💻 Environment

I am using remix v1.1.3 and whatever other version of remix I can find.
