🇺🇲
Protocolink
  • 🔮Overview
  • 🌟Why Protocolink?
  • 💡Use Cases
    • Flash Loans
    • Permit2 Amplifier
    • Zap-in & Zap-out
    • Position Management
    • Multi-Action Bundling
  • 📋Networks & Protocols
  • 🛡️Security & Audits
  • 💎Fees
  • ❓FAQ
  • Protocolink API
    • 🔮Overview
      • Swap & Supply (Example)
    • 📗Swagger
      • Request Protocols
      • Request Tokens
      • Request Quote
      • Estimate Logics Result
      • Request Transaction Data
  • Protocolink SDK
    • 🔮Overview
    • 1️⃣Install SDK
    • 2️⃣Build Logics
    • 3️⃣Estimate Router Data
    • 4️⃣Send Router Transaction
    • ⚒️API SDK Interfaces
      • Global Types
      • FlashLoan Logic
      • Aave V2
      • Aave V3
      • Balancer V2
      • Compound V3
      • Iolend
      • Magicsea
      • Morphoblue
      • OpenOcean V2
      • ParaSwap V5
      • Permit2
      • Spark
      • Stargate
      • Stargate V2
      • SyncSwap
      • Uniswap V3
      • Utility
      • Wagmi
      • ZeroEx V4
    • ⚒️Common SDK Interfaces
      • Constants
      • Network
      • Token
      • Web3Toolkit
      • Utility Functions
  • Lending SDK
    • 🔮Overview
    • ✳️SDK
      • Open By Collateral
      • Open By Debt
      • Close
      • Leverage By Collateral
      • Leverage By Debt
      • Deleverage
      • Collateral swap
      • Debt swap
      • Zap supply
      • Zap withdraw
      • Zap repay
      • Zap borrow
  • Smart Contract
    • 🔮Overview
      • Router
      • Agent
      • Callback
      • Fees
      • Utility
      • Data Type
      • ERC721/ERC1155 Support
    • 📑Deployment Addresses
    • 🧑‍💻Security Review Details
  • COMPOUND KIT
    • 🔮Overview
    • ✳️SDK
      • Leverage
      • Deleverage
      • Collateral Swap
      • Zap Supply
      • Zap Withdraw
      • Zap Repay
      • Zap Borrow
    • 📗API
  • Video Tutorials
    • 1. Introducing Protocolink
    • 2. Lending SDK
    • 3. Protocolink Q&A
  • Social medias
    • Twitter
  • Support
Powered by GitBook
On this page
  • GitHub
  • 1. Install
  • 2. Markets List
  • 3. Market Information & Positions for Accounts
  • 4. Select an use case
  1. COMPOUND KIT

SDK

PreviousOverviewNextLeverage

Last updated 4 months ago

For a more comprehensive protocol support and enhanced position and market information, we recommend using the Lending SDK.

GitHub

1. Install

yarn add @protocolink/compound-kit

2. Markets List

List all Compound markets available across multiple chains. This function will return a list of market groups, each containing the chain ID and the markets available on that chain.

import * as compoundkit from '@protocolink/compound-kit';

const marketGroups = await compoundkit.getMarketGroups();
// {
//   "marketGroups": [
//     {
//       "chainId": 1,
//       "markets": [
//         {
//           "id": "USDC",
//           "label": "USDC"
//         },
//         {
//           "id": "ETH",
//           "label": "ETH"
//         }
//       ]
//     },
//     {
//       "chainId": 137,
//       "markets": [
//         {
//           "id": "USDC",
//           "label": "USDC"
//         }
//       ]
//     },
//     {
//       "chainId": 42161,
//       "markets": [
//         {
//           "id": "USDC",
//           "label": "USDC.e"
//         }
//       ]
//     }
//   ]
// }

3. Market Information & Positions for Accounts

Gather market information and positions for a specific account. The account parameter is optional. If an account address is provided, this function will also return the position details for that account in that particular market. This organized information can be presented to users to assist them in making decisions.

import * as compoundkit from '@protocolink/compound-kit';
import * as common from '@protocolink/common';

const chainId = common.ChainId.polygon;
const marketId = compoundkit.MarketId.USDC;
const account = '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa';
const marketInfo = await compoundkit.getMarketInfo(chainId, marketId, account);
// {
//   "baseToken": {
//     "chainId": 137,
//     "address": "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
//     "decimals": 6,
//     "symbol": "USDC",
//     "name": "USD Coin (PoS)"
//   },
//   "baseTokenPrice": "0.999956",
//   "baseBorrowMin": "100",
//   "supplyAPR": "0.034",
//   "supplyBalance": "0",
//   "supplyUSD": "0",
//   "borrowAPR": "0.048",
//   "borrowBalance": "76857.439242",
//   "borrowUSD": "76854.06",
//   "collateralUSD": "161888.83",
//   "borrowCapacity": "117764.28294",
//   "borrowCapacityUSD": "117759.1",
//   "availableToBorrow": "40906.843698",
//   "availableToBorrowUSD": "40905.04",
//   "liquidationLimit": "125853.54",
//   "liquidationThreshold": "0.7774",
//   "liquidationRisk": "0.61",
//   "liquidationPoint": "98756.531272",
//   "liquidationPointUSD": "98752.19",
//   "utilization": "0.6526",
//   "healthRate": "1.64",
//   "netAPR": "-0.0434",
//   "collaterals": [
//     {
//       "asset": {
//         "chainId": 137,
//         "address": "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
//         "decimals": 18,
//         "symbol": "WETH",
//         "name": "Wrapped Ether"
//       },
//       "assetPrice": "1792.148",
//       "borrowCollateralFactor": "0.775",
//       "liquidateCollateralFactor": "0.825",
//       "collateralBalance": "42.561192291871282298",
//       "collateralUSD": "76275.96",
//       "borrowCapacity": "59116.466748",
//       "borrowCapacityUSD": "59113.87"
//     },
//     {
//       "asset": {
//         "chainId": 137,
//         "address": "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6",
//         "decimals": 8,
//         "symbol": "WBTC",
//         "name": "(PoS) Wrapped BTC"
//       },
//       "assetPrice": "28536.334695",
//       "borrowCollateralFactor": "0.7",
//       "liquidateCollateralFactor": "0.75",
//       "collateralBalance": "2.10038726",
//       "collateralUSD": "59937.35",
//       "borrowCapacity": "41957.99384",
//       "borrowCapacityUSD": "41956.15"
//     },
//     {
//       "asset": {
//         "chainId": 137,
//         "address": "0x0000000000000000000000000000000000001010",
//         "decimals": 18,
//         "symbol": "MATIC",
//         "name": "Matic Token"
//       },
//       "assetPrice": "0.6172",
//       "borrowCollateralFactor": "0.65",
//       "liquidateCollateralFactor": "0.7",
//       "collateralBalance": "41600",
//       "collateralUSD": "25675.52",
//       "borrowCapacity": "16689.822352",
//       "borrowCapacityUSD": "16689.09"
//     },
//     {
//       "asset": {
//         "chainId": 137,
//         "address": "0xfa68FB4628DFF1028CFEc22b4162FCcd0d45efb6",
//         "decimals": 18,
//         "symbol": "MaticX",
//         "name": "Liquid Staking Matic (PoS)"
//       },
//       "assetPrice": "0.66438874",
//       "borrowCollateralFactor": "0.55",
//       "liquidateCollateralFactor": "0.6",
//       "collateralBalance": "0",
//       "collateralUSD": "0",
//       "borrowCapacity": "0",
//       "borrowCapacityUSD": "0"
//     }
//   ]
// }

4. Select an use case

Depending on the selected use cases, users will need to input different parameters, and the SDK will generate the expected outcome. 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 own agent within Protocolink - for further details, please visit Smart Contract).

: achieve the desired collateral exposure in a single step using a flash loan.

: reduce the collateral exposure in a single step using a flash loan to repay the borrowed asset.

: replace one collateral asset with another in a single step using a flash loan.

: swap any token to add as base or collateral token in one transaction.

: withdraw base or collateral token, then swap to any token in one transaction.

: swap any token to repay as base token in one transaction.

: borrow the base token, then swap to any token in one transaction.

✳️
https://github.com/dinngo/compound-kit-js-sdk
Leverage
Deleverage
Collateral swap
Zap Supply
Zap Withdraw
Zap Repay
Zap Borrow