L2 Pool
Last updated
Was this helpful?
Last updated
Was this helpful?
The main transaction cost on L2 comes from calldata. To minimize this cost, Nexus uses a different contract on L2 networks that allows calldata of Pool methods to be compressed.
L2Pool is the contract for the L2 optimized user facing methods of the protocol that takes byte encoded input arguments. It exposes the liquidity management methods that can be invoked using either Solidity or Web3 libraries. The L2Pool contract is a calldata optimized extension of the Pool contract allowing users to pass compact calldata representation to reduce transaction costs on L2 rollups.
Pool methods not exposed in L2Pool.sol (such as flashLoan, etc.) are the same on L2 as on other versions of protocol. Refer to docs for the rest of the methods.
Since there are a limited set of supported assets that are already given an individual id, we use the 16 bit asset id in the encoded arguments instead of 160 bit asset address.
The source code is available on GitHub.
There is an additional L2Encoder helper contract with view methods to encode transaction params for compressed methods.
Calldata efficient wrapper of the supply function on behalf of the caller. Supplies asset into the protocol, minting the same amount of corresponding zTokens, and transferring them to msg.sender.
You can use data returned from encodeSupplyParams() method in helper contract to pass to this method.
Input Parameters:
args
bytes32
Arguments for the supply function packed in one bytes32 bit 0-15: uint16 assetId - the index of the asset in the reservesList bit 16-143: uint128 shortenedAmount - cast to 256 bits at decode time, if type(uint128).max the value will be expanded to type(uint256).max bit 144-159: uint16 referralCode - used for 3rd party integrations
Calldata efficient wrapper of the withdraw function, withdrawing to the caller. Withdraws amount of the underlying asset, i.e. redeems the underlying token and burns the zTokens.
If the user has any existing debt backed by the underlying token, the maximum amount available to withdraw is the amount that will not leave the user with a health factor < 1 after the withdrawal.
You can use data returned from encodeWithdrawParams() method in L2Encoder helper contract to pass to this method.
Input Parameters:
args
bytes32
Arguments for the withdraw function packed in one bytes32 bit 0-15: uint16 assetId - the index of the asset in the reservesList bit 16-143: uint128 shortenedAmount - cast to 256 bits at decode time, if type(uint128).max the value will be expanded to type(uint256).max
Return Value:
amount
uint256
The final amount of the underlying asset withdrawn, denominated in the base unit of the asset (e.g., wei for ETH, smallest unit for ERC-20 tokens). This is the amount actually transferred to the caller, accounting for constraints like liquidity and health factor.
Calldata efficient wrapper of the borrow function, borrowing on behalf of the caller. Borrows amount of asset with interestRateMode, sending the amount to msg.sender, with the debt being incurred by onBehalfOf.
You can use data returned from encodeBorrowParams() method in L2Encoder helper contract to pass to this method.
Input Parameters:
args
bytes32
Arguments for the borrow function packed in one bytes32 bit 0-15: uint16 assetId - the index of the asset in the reservesList bit 16-143: uint128 shortenedAmount - cast to 256 bits at decode time, if type(uint128).max the value will be expanded to type(uint256).max bit 144 - 151: uint8 shortenedInterestRateMode bit 152 - 167: uint16 referralCode - used for 3rd party integrations
Calldata efficient wrapper of the repay function, repaying on behalf of the caller. Repays debt of an asset for the given interestRateMode.
You can use data returned from encodeRepayParams() method in L2Encoder helper contract to pass to this method.
Input Parameters:
args
bytes32
Arguments for the repay function packed in one bytes32 bit 0-15: uint16 assetId - the index of the asset in the reservesList bit 16-143: uint128 shortenedAmount - cast to 256 bits at decode time, if type(uint128).max the value will be expanded to type(uint256).max bit 144 - 151: uint8 shortenedInterestRateMode
Return Values:
uint256
The final amount repaid
Calldata efficient wrapper of the setUserUseReserveAsCollateral function. Sets the asset of msg.sender to be used as collateral or not.
Input Parameters:
args
bytes32
Arguments for the setUserUseReserveAsCollateral function packed in one bytes32 bit 0-15: uint16 assetId - the index of the asset in the reservesList bit 16: 0 => enable useAsCollateral, 1 => disable useAsCollateral
Calldata efficient wrapper of the liquidationCall function. Liquidate positions with a health factor below 1. You can use data returned from encodeLiquidationCall() method in L2Encoder helper contract to pass to this method.​
Input Parameters:
args1
bytes32
Part of the arguments for the liquidationCall function packed in one bytes32 bit 0-15: uint16 collateralAssetId - the index of the collateral asset in the reservesList bit 16-31: uint16 debtAssetId - the index of the debt asset in the reservesList bit 32-191: address of the user being liquidated
args2
bytes32
Part of the arguments for the liquidationCall function packed in one bytes32 bit 0-127: uint128 shortenedDebtToCover is cast to 256 bits at decode time, if type(uint128).max the value will be expanded to type(uint256).max bit 128: receiveZToken - 0 => receive zToken, 1 => receive underlying asset
You can use data returned from encodeSetUserUseReserveAsCollateral() method in helper contract to pass to this method.​