Get Deposit Details of a Wallet

Fetch details of all deposits by a wallet.

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

  • Obligation, which stores details about a wallet's borrows and deposits.

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

We can get all deposit 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 required deposit details.

const SHYFT_API_KEY = "YOUR_API_KEY"; //enter your SHYFT API Key
async function fetchObligationDeposits(ownerAddress: string) {
  //more relevant fields can be cherry picked as per requirement
  const operationsDoc = `
      query MyQuery {
        kamino_lending_Obligation(
          where: {owner: {_eq: ${JSON.stringify(ownerAddress)}}}
        ) {
          owner
          deposits
	  depositsAssetTiers
          depositedValueSf
        }
      }
    `; //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 fetchObligationDeposits(address);
  
  if (errors) {
    console.error(errors);
  }
  
  console.log(JSON.stringify(data));
}

getData("FgPehj68tvGcGDkHp2LwjVz8WaJdJCtkW1wYwzo3j8i3");
//wallet for which deposits are being fetched

To query reserves data, please check Get Reserve Details.

The response returned contains a deposits field, which is an array of deposit details for that particular user (owner) . Each item in that array contains

  • depositReserve: The address of the reserve to which collaterals are deposited to. The reserve details can be retrieved by querying the Reserve account, here Get Reserve Details. The mintPubkey of liquidty field is available here.

  • depositedAmount: The amount of the collaterals deposited in the reserve.

  • marketValueSf: The collateral market value in quote currency.

An Example to get Deposit details for a wallet

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

Consider the example, if we are trying to get all deposits 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"}}) {
    deposits
    pubkey
    tag
  }
}
  • Once successful, we get all the Obligation details for the wallet, which contains the deposit details. Each Item in the deposit array contains the depositedAmount, which is the amount deposited and depositReserve, which is the address of the reserve (pubkey) contains the liquidity details.

{
  "data": {
    "kamino_lending_Obligation": [
      {
        "deposits": [
          {
            "padding": ["0","0","0","0","0","0","0"],
            "marketValueSf": "178247987198691496876",
            "depositReserve": "DdTmCCjv7zHRD1hJv3E8bpnSEQBzdKkzB1j9ApXX5QoP",
            "depositedAmount": "96263860"
          }
        ]
      }
    ]
  }
}
  • The depositReserve 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 Reserve account.

query MyQuery {
  kamino_lending_Reserve(
    where: {pubkey: {_eq: "DdTmCCjv7zHRD1hJv3E8bpnSEQBzdKkzB1j9ApXX5QoP"}}
  ) {
    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": "Cb9y9VPv2J4DPWK5LwjSx5rvRQh7khoreuG2c1N12hwy", 
          "mintPubkey": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4", //token address
          "supplyVault": "CHcHknV6KujiUVqVsQfJrqUcsifgJmWBzhUWyYibt1ss",
          "mintDecimals": "6", //decimals
          "marketPriceSf": "2756993160450872368",
          "availableAmount": "14304198739155",
          "borrowedAmountSf": "468124421934370590975849021213088",
          "pendingReferrerFeesSf": "0",
          "absoluteReferralRateSf": "0",
          "borrowLimitCrossedSlot": "0",
          "cumulativeBorrowRateBsf": {
            "value": [
              "1179082124265788199",
              "0",
              "0",
              "0"
            ]
          },
          "depositLimitCrossedSlot": "0",
          "marketPriceLastUpdatedTs": "1234439495",
          "accumulatedProtocolFeesSf": "143597420613860366241481245022",
          "accumulatedReferrerFeesSf": "0"
        },
        "pubkey": "DdTmCCjv7zHRD1hJv3E8bpnSEQBzdKkzB1j9ApXX5QoP"
      }
    ]
  }
}

Last updated