Withdraw ETH sometimes fails with ERROR 5 on Kovan
Regarding depositWTH/withdrawETH of aave, I've faced to an issue. Withdraw is failed with error 5 (VL_NOT_ENOUGH_AVAILABLE_USER_BALANCE) sometimes on Kovan testnet. No problem on hardhat(mainnet fork).
While repeating depositETH/withdrawETH, I was able to see withdrawing is failed randomly.
AAVE validates the amount and user balance before withdrawing as follows.
function validateWithdraw() {
require(amount != 0, Errors.VL_INVALID_AMOUNT);
require(amount <= userBalance, Errors.VL_NOT_ENOUGH_AVAILABLE_USER_BALANCE);
}
userBalance is gotten by following code in aave.
uint256 userBalance = IAToken(aToken).balanceOf(msg.sender);
I think msg.sender must be WETH GATEWAY.
So it means aTokens are not sent to WETH GATEWAY or delayed or spent by others, etc?
I confirmed my contract receives aTokens correctly after deposit and it has enough amount of aTokens before withdrawing. By using following code.
uint256 lpamount = AToken(aWETHToken).balanceOf(address(this));
AaveDataProviderInterface aave = AaveDataProviderInterface(0x3c73A5E5785cAC854D468F727c606C07488a29D6);//kovan
(uint256 ctokenAmount, , , , , , , , ) = aave.getUserReserveData(wethaddr, address(this));
To summarize what I experienced:
- it receives aTokens correctly after deposit.
- Approved aTokens before withdraw correctly.
- Withdraw works fine sometimes, but failed sometimes.
- Cannot reproduce it on Hardhat-forked mainnet.
- It happens on Kovan test net randomly.
Any ideas why this is happening?
Here is example of transaction which is failed. https://kovan.etherscan.io/tx/0x4fafd5770b768a38d9185b8304955d580dd8c3bb236e8145b4e354722d64b86b
hey did you get a solution to this issue as I am facing the same issue on mumbai testnet -polygon network?