L2
Last updated
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 (explorer):
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.
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.
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.
assetId
: The function fetches the id
of the asset
from the DataTypes.ReserveData
struct.
shortenedAmount
: The amount
is converted to a 128-bit unsigned integer (uint128) to save space.
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.
Finally, the function returns res
, which is the compact representation of the supply parameters.