Compound V3
In this section, we will introduce the Compound V3 SDK interfaces, which provide developers with a convenient and efficient way to interact with the Compound V3 protocol. These interfaces cover various aspects of the protocol, including supply, withdraw, borrow, repay, and claim. They are designed to be used easily and flexibly.
Before we dive into the SDK interfaces, we would like to provide an overview of the features of Compound V3. If you are already familiar with Compound V3, feel free to skip this section. For those who are new to Compound V3, here's a brief explanation:
Each market in Compound V3 is independent, meaning that any action performed on the protocol must specify which market it's interacting with. For example, Ethereum has markets for USDC and ETH. Polygon has a USDC market.
Once you have identified the market you want to interact with, you can choose to either be a Lender or a Borrower.
If you want to be a Lender, you need to supply the base token, such as USDC in the Ethereum USDC market. In return, the market will mint cUSDCv3 tokens for you.
If you want to be a Borrower, you must deposit non-base tokens as collateral and borrow base token. For instance, in the Ethereum USDC market, you can deposit ETH or WBTC as collateral, but the market won't mint any cTokens for you. Instead, it will update the collateral value in the contract, and you can then borrow USDC.
Please note that Compound V3 is subject to change and improvements, and we will update our SDK accordingly.
The following section will introduce the interfaces related to the Compound V3 protocol, which can be accessed through the api.protocols.compoundv3.
prefix.
SupplyBase
The following code defines interfaces and functions related to the Compound V3 supply base logic:
Types
SupplyBaseParams: A type that represents the input parameters for the Compound V3 supply base logic
SupplyBaseFields: A type that represents the fields required for the Compound V3 supply base logic.
SupplyBaseLogic: An interface that extends the
Logic
interface and represents the Compound V3 supply base logic. It includes therid
, andfields
properties.
Functions
getSupplyBaseTokenList(chainId: number): An asynchronous function that retrieves the list of tokens supported by the Compound V3 supply base logic on the specified
chainId
.getSupplyBaseQuotation(chainId: number, params: SupplyBaseParams): An asynchronous function that retrieves a quotation for supplying base token on the Compound V3 protocol with the specified
params
object on the specifiedchainId
.newSupplyBaseLogic(fields: SupplyBaseFields): A function that creates the Compound V3 supply base logic data with the given
fields
object.
Example Code
SupplyCollateral
The following code defines interfaces and functions related to the Compound V3 supply collateral logic:
Types
SupplyCollateralFields: A type that represents the fields required for the Compound V3 supply collateral logic.
SupplyCollateralLogic: An interface that extends the
Logic
interface and represents the Compound V3 supply collateral logic. It includes therid
, andfields
properties.
Functions
getSupplyCollateralTokenList(chainId: number): An asynchronous function that retrieves the list of tokens supported by the Compound V3 supply collateral logic on the specified
chainId
.newSupplyCollateralLogic(fields: SupplyCollateralFields): A function that creates the Compound V3 supply collateral logic data with the given
fields
object.
Example Code
WithdrawBase
The following code defines interfaces and functions related to the Compound V3 withdraw base logic:
Types
WithdrawBaseParams: A type that represents the input parameters for the Compound V3 withdraw base logic
WithdrawBaseFields: A type that represents the fields required for the Compound V3 withdraw base logic.
WithdrawBaseLogic: An interface that extends the
Logic
interface and represents the Compound V3 withdraw base logic. It includes therid
, andfields
properties.
Functions
getWithdrawBaseTokenList(chainId: number): An asynchronous function that retrieves the list of tokens supported by the Compound V3 withdraw base logic on the specified
chainId
.getWithdrawBaseQuotation(chainId: number, params: WithdrawBaseParams): An asynchronous function that retrieves a quotation for withdrawing base token from the Compound V3 protocol with the specified
params
object on the specifiedchainId
.newWithdrawBaseLogic(fields: WithdrawBaseFields): A function that creates the Compound V3 withdraw base logic data with the given
fields
object.
Example Code
WithdrawCollateral
The following code defines interfaces and functions related to the Compound V3 withdraw collateral logic:
Types
WithdrawCollateralFields: A type that represents the fields required for the Compound V3 withdraw collateral logic.
WithdrawCollateralLogic: An interface that extends the
Logic
interface and represents the Compound V3 withdraw collateral logic. It includes therid
, andfields
properties.
Functions
getWithdrawCollateralTokenList(chainId: number): An asynchronous function that retrieves the list of tokens supported by the Compound V3 withdraw collateral logic on the specified
chainId
.newWithdrawCollateralLogic(fields: WithdrawCollateralFields): A function that creates the Compound V3 withdraw collateral logic data with the given
fields
object.
Example Code
Borrow
The following code defines interfaces and functions related to the Compound V3 borrow logic:
Types
BorrowFields: A type that represents the fields required for the Compound V3 borrow logic.
BorrowLogic: An interface that extends the
Logic
interface and represents the Compound V3 borrow logic. It includes therid
, andfields
properties.
Functions
getBorrowTokenList(chainId: number): An asynchronous function that retrieves the list of tokens supported by the Compound V3 borrow logic on the specified
chainId
.newBorrowLogic(fields: BorrowFields): A function that creates the Compound V3 borrow logic data with the given
fields
object.
Example Code
Repay
The following code defines interfaces and functions related to the Compound V3 repay logic:
Types
RepayParams: A type that represents the input parameters for the Compound V3 repay logic
RepayFields: A type that represents the fields required for the Compound V3 repay logic.
RepayLogic: An interface that extends the
Logic
interface and represents the Compound V3 repay logic. It includes therid
, andfields
properties.
Functions
getRepayTokenList(chainId: number): An asynchronous function that retrieves the list of tokens supported by the Compound V3 repay logic on the specified
chainId
.getRepayQuotation(chainId: number, params: RepayParams): An asynchronous function that retrieves a quotation for repaying a loan on the Compound V3 protocol with the specified
params
object on the specifiedchainId
.newRepayLogic(fields: RepayFields): A function that creates the Compound V3 repay logic data with the given
fields
object.
Example Code
Claim
The following code defines interfaces and functions related to the Compound V3 claim logic:
Types
ClaimParams: A type that represents the input parameters for the Compound V3 claim logic
ClaimFields: A type that represents the fields required for the Compound V3 claim logic.
ClaimLogic: An interface that extends the
Logic
interface and represents the Compound V3 claim logic. It includes therid
, andfields
properties.
Functions
getClaimTokenList(chainId: number): An asynchronous function that retrieves the list of tokens supported by the Compound V3 withdraw base logic on the specified
chainId
.getClaimQuotation(chainId: number, params: ClaimParams): An asynchronous function that retrieves a quotation for claiming COMP on the Compound V3 protocol with the specified
params
object on the specifiedchainId
.newClaimLogic(fields: ClaimFields): A function that creates the Compound V3 claim logic data with the given
fields
object.
Example Code
Last updated