Liquidity sufficiency check in the function _flashLoan
s.totalSupplyAssets records the total supply of loan tokens in the contract AvonPool, while s.totalBorrowAssets records the amount of loan tokens currently borrowed. Therefore, before executing a flash loan, the function _flashLoan can check whether the sum of s.totalBorrowAssets and the amount of tokens to be sent (assets) exceeds s.totalSupplyAssets to determine whether the contract has sufficient liquidity.
function _flashLoan(
PoolStorage.PoolState storage s,
address token,
uint256 assets,
bytes calldata data
) internal {
if (assets == 0) revert PoolErrors.ZeroAddress();
if (token != s.config.loanToken) revert PoolErrors.InvalidInput();
! if (s.totalBorrowAssets > s.totalSupplyAssets) revert PoolErrors.InsufficientLiquidity();
// [...]
}