Shyft
Start BuildingSupportWebsite
  • Welcome
    • 👋Introducing Shyft
    • 🏗️Start Building
  • Solana Infrastructure
    • 🚁Shyft RPCs
  • Yellowstone gRPC Network
    • Decoding gRPC Latency
    • ⚡gRPC Docs
      • Introduction
      • Authentication
      • Subscribe Requests
      • FAQ
      • Getting Started
        • Initializing the Yellowstone Client
        • Making a gRPC connection
        • Adding a Reconnection Mechanism
        • Modifying your Subscribe Request
        • Closing a gRPC Connection
      • Subscribing to Transactions
        • All Transactions of an address
        • Subscribing to all transactions of a Liquidity Pool
        • Subscribing to all transactions of multiple addresses
        • Subscribing to all transactions of a Token
      • Subscribing to Accounts
        • Account Updates for a Program
        • Account Updates for an Address
        • Account updates using memcmp
      • Streaming Blocks & BlocksMeta
        • Streaming Block Updates
        • Subscribing to BlocksMeta
      • Modifying & Unsubscribing
  • Solana defi data
    • DeFI APIs
      • Get Pool By Address
      • Get Pools By Token Pair
      • Get All Pools for a Token
      • Get Liquidity Details of a Pool
  • Callbacks
    • ☎️What are Callbacks?
      • Transaction Callbacks
      • Account Callbacks
    • 📔Callback APIs
      • Response Structure
      • List Callbacks
      • Register callback
      • Remove callback
      • 🔥Pause a callback
      • 🔥Resume a callback
      • Update Callbacks
      • Add Addresses
      • Remove addresses
  • Solana Super Indexers
    • 🌩️GraphQL APIs
      • Getting Started
      • Building Queries
      • Paginating Response
      • Applying Filters
      • Ordering and Sorting Data
    • 📀Case Studies
      • Tensor
        • Get Active Listings of a Wallet
        • Get Active Bids of a Wallet
        • Get Active Listings of a Collection
        • Get all Bids of a Collection
        • Get all Pools of a Margin Account
        • Get all Pools by Owner
      • Raydium
        • Get Pool By Address
        • Get Pools By Token Address
        • Get Pools Created Between Time
        • Get Pool Burn Percentage
        • Get Liquidity Details of a Pool
        • Get Pool and OpenBook Market Info
        • Get Token Supply Percentage In Pool
      • Orca Whirlpool
        • Get Pool by Address
        • Get Pool by Token Address
        • Get Positions for a Pool
        • Get Positions for a Wallet
        • Get Liquidity Details of a Pool
      • Kamino
        • Get Borrow Details of a Wallet
        • Get Deposit Details of a Wallet
        • Get Reserve Details
      • Cross Marketplace Queries
        • Get active listings across marketplaces for a wallet
        • Get listings for a collection across marketplaces
        • Get floor price of a collection
      • Cross Defi Queries
        • Fetch Liquidity Pools for Token
      • Native Staking
        • Get Stakes for a Wallet
        • Get Stakes For Validator
      • Governance/Realms
        • Get DAO Token Owners
        • Get Proposals For Governing Mint
        • Get All Proposals For DAO
        • Get DAO Treasury Info
        • Get All Active Proposals For Wallet
      • Meteora
        • Get All LB Position Pairs
        • Get Position of a User Wallet
        • Get Pool by Token Addresses
        • Get All Deposits for a User
        • Get All Withdraws for a User
        • Get All Fees Claimed by a User
        • Get All User Positions and Deposits for a Pool
        • Get All User Positions and Withdrawals for a Pool
      • Fluxbeam
        • Get Pool by Address
        • Get Pool by Token Addresses
      • Drift
        • Get User account for Delegate
        • Get User accounts based on authority
        • Get User details based on Referrer
        • Get Borrow/Deposit Amount for an User
        • Get PrepPositions for an User Account
        • Getting OrderId and userOrderId
        • Get OpenOrders for a User Account
      • 🔥Pumpswap
        • 🔥Get Pool by Address
        • 🔥Get Pool by Creator Address
        • 🔥Get Pools by Token Addresses
      • 🔥Raydium Launchpad
        • 🔥Get Bonding Curve Details by Pool Address
        • 🔥Get All Pools for a Creator
        • 🔥Get Pools by Token Addresses
        • 🔥Get Migration details of a Pool
  • Solana APIs
    • API Reference
    • Transactions
      • Parsed Transaction Structure
      • Transaction APIs
        • History
        • Parse Signature
        • Parse Multiple Signatures
        • Send
        • Send Multiple
    • NFT
      • 🔥Create Gasless
      • Create
      • Read All
      • Burn
      • 🔥Burn Multiple NFTs V2
      • Update
      • 🔥Create NFT from Metadata
      • 🔥Read Wallet Nfts
      • 🔥Read Selected NFTs
      • 🔥Get NFT Owners
      • 🔥Update NFT Metadata Uri
      • 🔥Update V2
      • Search
      • Transfer
      • Transfer Multiple NFTs
      • Mint
      • Read
    • Wallet
      • Get Balance
      • Get Token Balance
      • Get All Tokens Balance
      • Get Portfolio
      • Resolve Address
      • Get All Domains
      • Get Stake Accounts
    • Fungible Tokens
      • Create
      • Mint
      • Burn
      • 🔥Update
      • Get Token Info
      • Transfer
      • Airdrop
Powered by GitBook
On this page

Was this helpful?

  1. Solana Super Indexers
  2. Case Studies
  3. Kamino

Get Borrow Details of a Wallet

Fetch details of all borrows by a wallet.

There are two Kamino account types that we are interested in. They are

  • Obligation, which stores a wallet's borrowed and deposited assets.

  • Reserve, which stores detail about the actual asset that is being borrowed or deposited.

We can get all lending details for a particular wallet, by querying the Obligation account from the Kamino Lending program. You can directly copy paste this code on replit and see it in action. The owner field refers to the wallet which is being queried, and we can filter this field to get the desired result.

const SHYFT_API_KEY = "YOUR_API_KEY"; //enter your SHYFT API Key
async function fetchObligationLendings(ownerAddress: string) {
  //more relevant fields can be cherry picked
  const operationsDoc = `
      query MyQuery {
        kamino_lending_Obligation(
          where: {owner: {_eq: ${JSON.stringify(ownerAddress)}}}
        ) {
          owner
          borrows
          borrowedAssetsMarketValueSf
          borrowFactorAdjustedDebtValueSf
        }
      }
    `; //graphQl query
  const result = await fetch(
    `https://programs.shyft.to/v0/graphql/accounts?api_key=${SHYFT_API_KEY}&network=mainnet-beta`,
    {
      method: "POST",
      body: JSON.stringify({
        query: operationsDoc,
        variables: {},
        operationName: "MyQuery",
      }),
    }
  );

  return await result.json();
}

async function getData(address: string) {
  const { errors, data } = await fetchObligationLendings(address);
  
  if (errors) {
    console.error(errors);
  }
  
  console.log(JSON.stringify(data));
}

getData("FgPehj68tvGcGDkHp2LwjVz8WaJdJCtkW1wYwzo3j8i3");
//wallet for which lendings are being fetched
{
  "data": {
    "kamino_lending_Obligation": [
      {
        "owner": "FgPehj68tvGcGDkHp2LwjVz8WaJdJCtkW1wYwzo3j8i3",
        "borrows": [
          {
            "padding": "0",
            "padding2": ["0","0","0","0","0","0","0","0"],
            "borrowReserve": "EVbyPKrHG6WBfm4dLxLMJpUDY43cCAcHSpV3KYjKsktW",
            "marketValueSf": "6025906178204981648",
            "borrowedAmountSf": "35134630221936101800853625",
            "cumulativeBorrowRateBsf": {
              "value": [
                "1156067927245241416","0", "0", "0"
              ],
              "padding": [
                "0",
                "0"
              ]
            },
            "borrowFactorAdjustedMarketValueSf": "7532382722756227060"
          },
          {
            "padding": "0",
            "padding2": ["0","0","0","0","0","0","0","0"],
            "borrowReserve": "11111111111111111111111111111111",
            "marketValueSf": "0",
            "borrowedAmountSf": "0",
            "cumulativeBorrowRateBsf": {
              "value": [
                "0",
                "0",
                "0",
                "0"
              ],
              "padding": [
                "0",
                "0"
              ]
            },
            "borrowFactorAdjustedMarketValueSf": "0"
          },
          {
            "padding": "0",
            "padding2": ["0","0","0","0","0","0","0","0"],
            "borrowReserve": "11111111111111111111111111111111",
            "marketValueSf": "0",
            "borrowedAmountSf": "0",
            "cumulativeBorrowRateBsf": {
              "value": [
                "0",
                "0",
                "0",
                "0"
              ],
              "padding": [
                "0",
                "0"
              ]
            },
            "borrowFactorAdjustedMarketValueSf": "0"
          },
          {
            "padding": "0",
            "padding2": ["0","0","0","0","0","0","0","0"],
            "borrowReserve": "11111111111111111111111111111111",
            "marketValueSf": "0",
            "borrowedAmountSf": "0",
            "cumulativeBorrowRateBsf": {
              "value": [
                "0",
                "0",
                "0",
                "0"
              ],
              "padding": [
                "0",
                "0"
              ]
            },
            "borrowFactorAdjustedMarketValueSf": "0"
          },
          {
            "padding": "0",
            "padding2": ["0","0","0","0","0","0","0","0"],
            "borrowReserve": "11111111111111111111111111111111",
            "marketValueSf": "0",
            "borrowedAmountSf": "0",
            "cumulativeBorrowRateBsf": {
              "value": [
                "0",
                "0",
                "0",
                "0"
              ],
              "padding": [
                "0",
                "0"
              ]
            },
            "borrowFactorAdjustedMarketValueSf": "0"
          }
        ],
        "borrowedAssetsMarketValueSf": 6025906178204981000,
        "borrowFactorAdjustedDebtValueSf": 7532382722756227000
      }
    ]
  }
}

The response returned contains a borrows field, which is an array of borrow details for the user. Each item in that array contains the following:

  • borrowReserve: The address of the reserve from which the asset is borrowed. The asset details can be retrieved by querying the Reserve account. Get Reserve Details.

  • cumulativeBorrowRateBsf: The borrow rate used for calculating interest.

  • borrowedAmountSf: The amount of liquidity borrowed plus interest.

  • marketValueSf: The liquidity market value in quote currency.

An Example to get Borrow details for a wallet

Consider the example, if we are trying to get all borrows for the wallet HNqJtqudHDWiWHWg3RH7FPamf8dyXjFwJVPmfRDMDyjE. The steps are as follows:

  • We query the Kamino Lending Obligation account using the where filter on the owner field, as illustrated in the above example. The query looks somewhat like this.

query MyQuery {
  kamino_lending_Obligation(where: {owner: {_eq: "HNqJtqudHDWiWHWg3RH7FPamf8dyXjFwJVPmfRDMDyjE"}}) {
    borrows
    pubkey
    tag
  }
}
  • Once successful, we get all the Obligation details for the wallet, which contains the borrow details. Each Item in the borrows array contains the borrowedAmountSf, which is the amount borrowed (in Scaled fraction) and borrowReserve, which contains the liquidity details.

{
  "data": {
    "kamino_lending_Obligation": [
      {
        "borrows": [
          {
            "padding": "0",
            "padding2": ["0","0","0","0","0","0","0"],
            "borrowReserve": "Ga4rZytCpq1unD4DbEJ5bkHeUz9g3oh9AAFEi6vSauXp",//reserve address
            "marketValueSf": "115840195581198642917",
            "borrowedAmountSf": "115869161712935259635828580", //borrowed amount plus interest
            "cumulativeBorrowRateBsf": {
              "value": ["1177132707471237533","0","0","0"],
              "padding": ["0","0"]
            },
            "borrowFactorAdjustedMarketValueSf": "115840195581198642917"
          }
        ]
      }
     ]
  }
}
  • The borrowReserve returned in the previous step is the pubkey of a reserve account, which keeps track of the liquidity. We query the reserve details from the Kamino Lending Reserves account.

query MyQuery {
  kamino_lending_Reserve(
    where: {pubkey: {_eq: "Ga4rZytCpq1unD4DbEJ5bkHeUz9g3oh9AAFEi6vSauXp"}}
  ) {
    liquidity
    pubkey
  }
}
  • Once successfully executed, this returns the mintPubkey which is the token address of the liquidity in this reserve. We can further user SHYFT’s SDK to get the token name, symbol and decimals.

{
  "data": {
    "kamino_lending_Reserve": [
      {
        "liquidity": {
          "feeVault": "rywFxeqHfCWL5iGq9cDxutwiiR2TabZgzv8aRM1Lceq", 
          "mintPubkey": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", //token address
          "supplyVault": "GENey8es3EgGiNTM8H8gzA3vf98haQF8LHiYFyErjgrv",
          "mintDecimals": "6", //decimals
          "marketPriceSf": "1152864008411412232",
          "availableAmount": "14304198739155",
          "borrowedAmountSf": "46874931934370590975849021213088",
          "pendingReferrerFeesSf": "0",
          "absoluteReferralRateSf": "0",
          "borrowLimitCrossedSlot": "0",
          "cumulativeBorrowRateBsf": {
            "value": [
              "1179082184865788199",
              "0",
              "0",
              "0"
            ]
          },
          "depositLimitCrossedSlot": "0",
          "marketPriceLastUpdatedTs": "1710439495",
          "accumulatedProtocolFeesSf": "59297420613860366241481245022",
          "accumulatedReferrerFeesSf": "0"
        },
        "pubkey": "Ga4rZytCpq1unD4DbEJ5bkHeUz9g3oh9AAFEi6vSauXp"
      }
    ]
  }
}
PreviousKaminoNextGet Deposit Details of a Wallet

Last updated 1 year ago

Was this helpful?

You can try out a sample project that gets all deposits and borrows of a wallet, .

📀
here