I am using Polygon mainnet. Below are the steps I am trying to follow.
address private constant _lendingPoolAddressesProvider = 0xd05e3E715d945B59290df0ae8eF85c1BdB684744;
address private constant USDC_POLY_ADDRESS = 0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174;
ILendingPoolAddressesProvider addressesProvider = ILendingPoolAddressesProvider(_lendingPoolAddressesProvider);
ILendingPool lendingPool = ILendingPool(addressesProvider.getLendingPool());
ERC20 usdc = ERC20(USDC_POLY_ADDRESS);
uint16 referralCode = 0;
function deposit(uint256 amount, address to) external {
require(amount > 0, "Amount needs to be greater than 0");
// Transfer USDC to this contract
usdc.transferFrom(msg.sender, address(this), amount);
// Approve contract to deposit it into the lendingPool
usdc.increaseAllowance(address(lendingPool), amount);
// Actually deposit into the lendingPool on behalf of the to address
lendingPool.deposit(address(usdc), amount, to, referralCode);
}
function withdraw(address to) external {
lendingPool.withdraw(address(usdc), type(uint).max, to);
}
The deposit function is working fine but the withdraw function is failing. https://polygonscan.com/tx/0x9621fdfe18ed2c634a2ed4b5c2c9e139968519a5ca9036a3fa0e1e8d10d8c97b
Can someone please help decode this.
Thanks.
to
address I'm using in the withdraw has already used the deposit method and deposit some funds into aave in a separate transaction