Lending SDK provides tools and build logics for lending purpose, which works as a part of Protocolink JS SDK. Please refer to Protocolink SDK for complete setup and transaction construction.
The Adapter is the primary role in Lending SDK. The Adapter enables seamless retrieval of user information and interaction with a range of supported protocols, simplifying the process of integrating blockchain functionalities into various applications.
2.1 Configuration
Lending SDK coordinates the interaction between lending protocols and token swappers. Currently Protocolink supports the following protocols:
Lending protocol
Aave V2
Aave V3
Radiant V2
Spark
Compound V3
Morpho Blue
Swapper
Paraswap V5
Openocean V2
User may register the protocols they want to use in the service.
To initialize the Adapter, users must specify a chainId, with the option to include a provider for enhanced flexibility. Once initialized, the Adapter enables seamless retrieval of user information and interaction with a range of supported protocols, simplifying the process of integrating blockchain functionalities into various applications.
import*as common from'@protocolink/common';constchainId=common.ChainId.arbitrum;constadapter=awaitlending.Adapter.createAdapter(chainId/*, provider*/);// Note: Adapter initialization is async starting from version 2.0.0
3. Get the portfolio
Gather the information of a user portfolio. The portfolio is determined by user account, protocol, and market. The portfolio contains information to assist user to identify their position to make further decisions.
Lending SDK supports all the popular operations of position management and lending-related operations across different lending platforms. Every operation includes
User account
User's portfolio on the protocol
Token information includes source token, source token amount, and destination token. The role of the source token and the destination token depends on the operation. Details will be explained in the following section.
The acceptable slippage for token swap in the operation.
The supported operations are
Open by collateral: swap any token to supply collateral, and achieve the desired collateral exposure in a single step by using a flash loan.
Open by debt: swap any token to supply collateral, and achieve the desired debt exposure in a single step by using a flash loan.
Close: empty all positions in a single step by using a flash loan to repay borrowed assets and withdraw deposited assets.
Leverage by collateral: achieve the desired collateral exposure in a single step by using a flash loan.
Leverage by debt: achieve the desired debt exposure in a single step by using a flash loan.
Deleverage: reduce the collateral exposure in a single step by using a flash loan to repay the borrowed asset.
Collateral swap: replace one collateral asset with another in a single step by using a flash loan.
Debt swap: replace one loan asset with another in a single step by using a flash loan.
Zap supply: swap any token to supply token in one transaction.
Zap withdraw: withdraw then swap to any token in one transaction.
Zap repay: swap any token to repay the debt in one transaction.
Zap borrow: borrow then swap to any token in one transaction.
Depending on the selected use case, users will need to input different parameters, and the SDK will generate the expected outcome, including
Destination token amount.
User portfolio after the operation is executed.
Logics involved in the operation.
If users are satisfied with the expected outcome and the fees, they can sign and submit the approval and transaction data. Typically, the approval is a one-time requirement for allowing Protocolink to act as a manager or a Permit2 token approval (which poses no risk as each user has their agent within Protocolink - for further details, please visit Smart Contract).