Pool Implementation

This contract is called by Pool-proxy. Users interact with it to supply, borrow, repay, withdraw, flash loan, and configure collateral usag. Admins use it to initialize reserves and update parameters.

🔹 Constructor

  • constructor(IPoolAddressesProvider provider) Initializes the pool with the address provider that manages system-wide addresses.


🔹 Core State-Changing Functions

  • supply(asset, amount, onBehalfOf, referralCode) Deposit an asset into the protocol to earn yield. onBehalfOf allows crediting another user.

  • supplyWithPermit(asset, amount, onBehalfOf, referralCode, deadline, v, r, s) Same as supply, but uses EIP-2612 permit signatures to approve in a gas-efficient way.

  • withdraw(asset, amount, to)uint256 Withdraw supplied assets from the protocol and send them to to.

  • borrow(asset, amount, interestRateMode, referralCode, onBehalfOf) Borrow funds from the pool, choosing stable or variable interest rate.

  • repay(asset, amount, interestRateMode, onBehalfOf)uint256 Repay borrowed funds.

  • repayWithATokens(asset, amount, interestRateMode)uint256 Repay debt using aTokens instead of underlying asset.

  • repayWithPermit(asset, amount, interestRateMode, onBehalfOf, deadline, v, r, s)uint256 Repay using ERC-20 permit authorization.

  • swapBorrowRateMode(asset, interestRateMode) Switch between stable and variable borrowing modes.

  • rebalanceStableBorrowRate(asset, user) Adjust a user’s stable borrow rate to the current optimal one.

  • setUserUseReserveAsCollateral(asset, useAsCollateral) Enable or disable an asset as collateral.

  • liquidationCall(collateralAsset, debtAsset, user, debtToCover, receiveAToken) Liquidate a user’s debt if their health factor is too low. Liquidator repays debt and receives collateral.


🔹 Flash Loans

  • flashLoan(receiver, assets[], amounts[], interestRateModes[], onBehalfOf, params, referralCode) Multi-asset flash loan.

  • flashLoanSimple(receiver, asset, amount, params, referralCode) Simpler single-asset flash loan.


🔹 Treasury / Protocol Functions

  • mintUnbacked(asset, amount, onBehalfOf, referralCode) Mint aTokens without providing liquidity (used in bridges).

  • backUnbacked(asset, amount, fee)uint256 Provide the underlying liquidity to back unbacked aTokens.

  • mintToTreasury(assets[]) Mint reserves accrued to the protocol treasury.

  • rescueTokens(token, to, amount) Recover ERC-20 tokens mistakenly sent to the pool.


🔹 Configuration / Admin Functions

  • initReserve(asset, aToken, stableDebtToken, variableDebtToken, interestRateStrategy) Initialize a new reserve (asset market).

  • dropReserve(asset) Remove a reserve from the pool.

  • setConfiguration(asset, config) Update reserve risk parameters.

  • setReserveInterestRateStrategyAddress(asset, strategy) Change the interest rate strategy for a reserve.

  • configureEModeCategory(id, category) Create/update an eMode category (optimized LTVs for correlated assets).

  • setUserEMode(categoryId) Set a user’s efficiency mode.

  • updateBridgeProtocolFee(protocolFee) Adjust fee for bridge usage.

  • updateFlashloanPremiums(totalPremium, premiumToProtocol) Adjust flash loan fee parameters.

  • resetIsolationModeTotalDebt(asset) Reset debt tracking for isolation-mode assets.

  • finalizeTransfer(asset, from, to, amount, balanceFromBefore, balanceToBefore) Internal bookkeeping when aTokens are transferred.


🔹 View / Read Functions

  • ADDRESSES_PROVIDER() → address Returns the address provider.

  • BRIDGE_PROTOCOL_FEE() → uint256 Fee applied to bridge mints.

  • FLASHLOAN_PREMIUM_TOTAL() → uint128 Total flash loan fee (bps).

  • FLASHLOAN_PREMIUM_TO_PROTOCOL() → uint128 Portion of fee directed to protocol treasury.

  • MAX_NUMBER_RESERVES() → uint16 Maximum number of reserves allowed.

  • MAX_STABLE_RATE_BORROW_SIZE_PERCENT() → uint256 Limit on stable-rate borrowing as % of liquidity.

  • POOL_REVISION() → uint256 Contract revision number.

  • getConfiguration(asset) Returns the encoded reserve configuration.

  • getReserveData(asset) Returns detailed reserve state (indexes, rates, addresses, treasury accruals, etc.).

  • getReserveNormalizedIncome(asset) → uint256 Normalized liquidity index.

  • getReserveNormalizedVariableDebt(asset) → uint256 Normalized variable debt index.

  • getReservesList() → address[] Returns the list of all active reserves.

  • getReserveAddressById(id) → address Get reserve address by internal ID.

  • getEModeCategoryData(id) Returns parameters of an eMode category (LTV, liquidation thresholds, etc.).

  • getUserAccountData(user) Returns total collateral, total debt, available borrows, liquidation threshold, LTV, and health factor.

  • getUserConfiguration(user) Returns bitmaps of user’s asset usage (collateral/borrow).

  • getUserEMode(user) → uint256 Returns the efficiency mode category a user is in.


🔹 Events

  • Supply, Withdraw, Borrow, Repay, LiquidationCall, FlashLoan, MintUnbacked, BackUnbacked, ReserveDataUpdated, ReserveUsedAsCollateralEnabled/Disabled, UserEModeSet All these track on-chain state changes for transparency and analytics.

Last updated

Was this helpful?