👻
Aave Book
  • Introduction
  • TradFi vs DeFi: Lending
  • Market forces x Interest Rate Models
  • On Indexes
    • Why use indexes?
  • Scaling and ATokens
  • Deposit & Borrow Interest
  • Stable borrowing
    • 🚧Under construction
  • Liquidation
    • 🚧TODO: Full example
    • 🚧Under construction: oracles
  • Primer
    • Bitmap & Masks
      • 🚧padding and bytes
    • WadRayLibrary
      • Math Operations
      • 🚧WIP: Scaling different decimal representations
      • 🚧WIP: 2's complement
      • 🚧casting: to uint128
    • PercentageMath
    • Embedded vs Linked Libraries
  • Functions
    • General Execution flow
    • Architecture & Design choices
      • 🚧Upgradability and Proxies
    • Common Functions
      • getReserveFactor, getDecimals
      • .cache
      • .updateState
      • .updateInterestRates
      • SupplyCap, BorrowCap
      • getFlags
        • 🚧more on flags
      • calculateUserAccountData
    • supply
      • validateSupply
      • transfer & mint
      • isFirstSupply
        • isUsingAsCollateralOne, isUsingAsCollateralAny
      • On check-effects-interactions pattern
    • withdraw
      • get user balance & withdraw amount
      • validateWithdraw
      • collateral check
      • burn ATokens
      • Ensure existing loans are collateralized
    • borrow
      • getIsolationModeState
      • .validateBorrow
      • Mint debt token
      • setBorrowing
      • update IsolationMode debt
      • transfer underlying to user
    • repay
      • get current debt
      • validateRepay, paybackAmount
      • burn debt tokens
      • Cleanup + Collect repay
    • liquidate
      • _calculateDebt
      • validateLiquidationCall
      • getConfigurationData
      • calculateAvailableCollateralToLiquidate
      • 🚧_burnDebtTokens
      • liquidate/burn collateral
      • liquidation Fee
      • Wrap-up
    • 🚧swapBorrowRateMode
    • 🚧setUserUseReserveAsCollateral
  • Contracts
    • AToken
      • Simple example: mint & balanceOf
    • StableDebtToken
      • Implementation explained
    • VariableDebtToken
    • DefaultReserveInterestRateStrategy
    • L2
      • 🚧PriceOracleSentinel
  • Audit findings
    • 🚧Under construction
  • Appendix
    • Simple, Compound, APR, APY
  • Aave Features
    • Risk Management
      • Supply & Borrow Caps
      • Isolation Mode
      • Siloed Borrowing
    • Other features
      • Repay with ATokens
      • eMode: High efficiency Mode
      • 🚧Aave Vault
      • 🚧Portal
Powered by GitBook
On this page
  • Background
  • L2Pool
  • L2 encoder
  • Links

Was this helpful?

Edit on GitHub
  1. Contracts

L2

PreviousDefaultReserveInterestRateStrategyNextPriceOracleSentinel

Last updated 1 year ago

Was this helpful?

Background

Moving execution off of the main chain allows for significantly decreased costs for execution and state storage. However, rollups still must post their data to the layer-1 chain to ensure data availability.

This can be seen on the "Advanced TxInfo" tab on any transaction in the ArbiScan block explorer. The transaction fee is broken down into the calldata costs to post to L1, the computation used on L2, and the L2 storage. And in almost all transactions, the L1 calldata will be the primary driver of fees.

For example, breakup of $4.19 Uniswap Trade on Arbitrum ():

  • L1 Fixed Cost: $1.77

  • L1 Calldata Cost: $2.30

  • L2 Computation: $0.12

You can see that, the calldata cost is over 50%. Simply put: posting data to L1 is the primary bottleneck for fees on rollups.

Rollups have cheap execution but expensive data-availability costs.

L2Pool

Due to calldata costs, Aave deploys a calldata optimized version of the Pool contract allowing users to pass compact calldata.

For example, supply:

The compact calldata is decoded into the usual parameters and passed into the usual supply function.

L2 encoder

  • Helper contract to encode calldata, used to optimize calldata size in L2Pool for transaction cost reduction

  • Intended to help generate calldata for users/front-ends.

  • Contains only view functions.

Example: encodeSupplyParams

encodeSupplyParams takes three inputs: asset, amount, and referralCode. It then converts these parameters into a compact representation using a single bytes32 value.

  1. assetId: The function fetches the id of the asset from the DataTypes.ReserveData struct.

  2. shortenedAmount: The amount is converted to a 128-bit unsigned integer (uint128) to save space.

  3. res: The function combines assetId, shortenedAmount, and referralCode into a single 256-bit unsigned integer (uint256) named res. It uses bitwise shifting (shl) to position the values correctly within the uint256 variable and then uses the add operation to combine them into one.

  4. Finally, the function returns res, which is the compact representation of the supply parameters.

Links

https://www.scopelift.co/blog/calldata-optimizooooors
https://ethglobal.com/showcase/l2-optimizoooors-7sio4
https://www.cryptoeq.io/articles/layer-2-fees
https://l2fees.info/blog/rollup-calldata-compression
explorer
https://github.com/aave/aave-v3-core/blob/master/contracts/protocol/pool/L2Pool.sol
L2Pool.sol
CalldataLogic.sol
L2Encoder.sol