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.
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:
You can try out a sample project that gets all deposits and borrows of a wallet, here.
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.
Once successful, we get all the Obligation details for the wallet, which contains the borrow details. Each Item in the
borrows
array contains theborrowedAmountSf
, which is the amount borrowed (in Scaled fraction) andborrowReserve
, which contains the liquidity details.
The
borrowReserve
returned in the previous step is thepubkey
of a reserve account, which keeps track of the liquidity. We query the reserve details from the Kamino Lending Reserves account.
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.
Last updated