Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't call POOL.flashLoan provided by Aave #69

Open
Utatistics opened this issue Oct 27, 2024 · 0 comments
Open

Can't call POOL.flashLoan provided by Aave #69

Utatistics opened this issue Oct 27, 2024 · 0 comments

Comments

@Utatistics
Copy link

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:


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?

sakulstra added a commit to bgd-labs/aave-v3-origin that referenced this issue Dec 10, 2024
- adding `getReserveVariableDebtToken` getter
- adjusting close factor to apply to whole position, not per reserve
- adjusting close factor to increase to 100% when debt/collateral are below a threshold
- adjusting liquidations to force full liquidation/or keep a leftover that is high enough to allow further liqudiations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant