-
Notifications
You must be signed in to change notification settings - Fork 151
Description
I'm trying to call POOL.flashLoan provided by Aave core v3. This is for a test and done on forked mainnet using ganache/truffle.
contract FlashLoanArbitrage {
IPool public POOL;
constructor(
address _poolAddressesProvider,
)
{
IPoolAddressesProvider provider = IPoolAddressesProvider(_poolAddressesProvider);
POOL = IPool(provider.getPool()); // Initialize the POOL contract
}
function executeFlashLoan(
address[] calldata assets,
uint256[] calldata flashLoanAmounts,
uint256[] calldata modes,
address onBehalfOf,
bytes calldata params
) external {
POOL.flashLoan(address(this), assets, flashLoanAmounts, modes, onBehalfOf, params, 0);
}
}
In above Solidity code, as recommended in the official Aave documentation, I am using poolAddressProvider contract to obtain the address of the POOL contract. Then calling executeFlashLoan, which is my endpoint, shuold run POOL.flashloan to request the loan. However, callng this endpoint failes due to flashLoan not properly being called.
Since truffle debug did not provide much information to indicate what went wrong, I tried to directly call flashLoan via web3 python, which did not work either.
pool_contract = w3.eth.contract(address=pool_address, abi=pool_abi)
# Proceed with your existing code using POOL_contract
address = '0xb9af6288810670DAb8bb01CB51A37Af334A90304'
assets = ["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"]
amounts = [Web3.to_wei(100, 'ether')]
modes = [0]
on_behalf_of = address
params = b""
logger.info(f'{address=}')
logger.info(f'{assets=}')
logger.info(f'{amounts=}')
logger.info(f'{modes=}')
logger.info(f'{on_behalf_of=}')
logger.info(f'{params=}')
try:
result = pool_contract.functions.flashLoan(
address,
assets,
amounts,
modes,
on_behalf_of,
params,
0
).call({'from': address})
logger.info("Flash loan simulation successful. Result:", result)
except Exception as e:
logger.error("Flash loan simulation error: %s", e)
2024-10-27 12:13:09 [INFO] address='0xb9af6288810670DAb8bb01CB51A37Af334A90304'
2024-10-27 12:13:09 [INFO] assets=['0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2']
2024-10-27 12:13:09 [INFO] amounts=[100000000000000000000]
2024-10-27 12:13:09 [INFO] modes=[0]
2024-10-27 12:13:09 [INFO] on_behalf_of='0xb9af6288810670DAb8bb01CB51A37Af334A90304'
2024-10-27 12:13:09 [INFO] params=b''
2024-10-27 12:14:15 [ERROR] Flash loan simulation error: ("The function 'flashLoan' was not found in this contract's abi.", ' Are you sure you provided the correct contract abi?')
Since the erorr suggests that contract abi (or its address) is not accurate, I checked the following:
-
I'm passing the '0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e' to instanciate 'IPoolAddressesProvider,and it can be confirmed that this indeed belongs to the contract 'PoolAddressesProvider'
-
The address given to IPOOL to instantiate POOL contract is '0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2', and it can be confirmed that this belongs to 'InitializableImmutableAdminUpgradeabilityProxy'
- On etherscan,at contract tab, 'InitializableImmutableAdminUpgradeabilityProxy' includes the
flashLoanimplementation in POOL.sol (this can be confirmed by looking into IDE)
- On etherscan,at contract tab, 'InitializableImmutableAdminUpgradeabilityProxy' includes the
function flashLoan(
address receiverAddress,
address[] calldata assets,
uint256[] calldata amounts,
uint256[] calldata interestRateModes,
address onBehalfOf,
bytes calldata params,
uint16 referralCode
) public virtual override {
DataTypes.FlashloanParams memory flashParams = DataTypes.FlashloanParams({
receiverAddress: receiverAddress,
assets: assets,
amounts: amounts,
interestRateModes: interestRateModes,
onBehalfOf: onBehalfOf,
params: params,
referralCode: referralCode,
flashLoanPremiumToProtocol: _flashLoanPremiumToProtocol,
flashLoanPremiumTotal: _flashLoanPremiumTotal,
reservesCount: _reservesCount,
addressesProvider: address(ADDRESSES_PROVIDER),
pool: address(this),
userEModeCategory: _usersEModeCategory[onBehalfOf],
isAuthorizedFlashBorrower: IACLManager(ADDRESSES_PROVIDER.getACLManager()).isFlashBorrower(
msg.sender
)
});
I suspect that I might not be passing the parameters in the expected format, or not instanciating the POOL contract right, etc. Could anybody help me resolve this?