Installation
# npm
npm install @hubbleprotocol/kamino-lending-sdk
# yarn
yarn add @hubbleprotocol/kamino-lending-sdk
Kamino Lending Typescript SDK
This is the Kamino Lending Typescript SDK to interact with the Kamino Lend smart contract
Basic usage
Reading data
// There are three levels of data you can request (and cache) about the lending market.
// 1. Initalize market with parameters and metadata
const market = await KaminoMarket.load(
connection,
new PublicKey("ABPeWVeRuvii6HuzTYcp1iH5a3ELfeVEviCtm3GfNnLV") // main market address. Defaults to 'Main' market
);
console.log(market.reserves.map((reserve) => reserve.config.loanToValueRatio));
// 2. Refresh on-chain accounts for reserve data and cache
await market.loadReserves();
const usdcReserve = market.getReserve("USDC");
console.log(usdcReserve?.stats.totalDepositsWads.toString());
// Read Kamino Lending liquidity mining stats
// await market.loadRewards();
// console.log(reserve.stats.totalSupplyAPY().rewards); // {apy: 0.07, rewardMint: "SLND...
// Refresh all cached data
market.refreshAll();
const obligation = market.fetchObligationByWallet("[WALLET_ID]");
console.log(obligation.stats.borrowLimit);
Perform lending action
// Create one or more (may contain setup accuont creation txns) to perform a Kamino action.
const kaminoAction = await KaminoAction.buildDepositTxns(
kaminoMarket,
amountBase,
symbol,
new VanillaObligation(PROGRAM_ID),
);
const env = await initEnv('mainnet-beta');
await sendTransactionFromAction(env, sendTransaction); // sendTransaction from wallet adapter or custom
Upcoming
- Better support for obligation based actions (Fully repay borrow, max borrow up to borrow limit, etc.)
- React hook API
FAQ
Interest rates do not match what's show on kamino.finance
The Kamino SDK pulls certain price data from cached sources from our backend api that might be different from the API used on front-end. Divergences should be very small and these price sources will soon be consolidated.
Multiple transactions being created for a lending action
Due to transaction size limits of Solana, a user with a high amount of positions might need their lending action to be broken into multiple transactions. Usually this involves creating or closing associated token accounts for up to 3 transactions.
Values are weird on devnet
Partner rewards and liquidity mining are not present on devnet.
Regenerate keys
anchor-client-gen ../kamino-lending/target/idl/kamino_lending.json ./src/ --program-id KLend2g3cP87fffoy8q1mQqGKjrxjC8boSyAYavgmjD
Client
- npx ts-node src/client.ts deposit --url --owner ./keypair.json --token USDH --amount 10
- npx ts-node src/client.ts deposit --url --owner ./keypair.json --token SOL --amount 10
Codegen
- Copy the new
idl
from the kamino-lending program tosrc/idl.json
yarn codegen
Setup localnet
- Ensure
deps
contains the correct.so
you want to test against. Either build it from the main repo or dump it from mainnet yarn start-validator
Run tests
yarn start-validator-and-test
- Or, if the local validator is already running,
yarn test
Deploy farms
-
npx ts-node src/client.ts init-farms-for-reserve --cluster mainnet --owner ../kamino-lending/keys/devnet/owner.json --farms-global-config 6UodrBjL2ZreDy7QdR4YV1oxqMBjVYSEyrFpctqqwGwL --reserve 9pX8uCeeGnGYYTEVdVfreqBa9RfhtRWHcez3sU6uinYr --kind Collateral
-
npx ts-node src/client.ts add-reward-to-farm --cluster mainnet --owner ../kamino-lending/keys/devnet/owner.json --farms-global-config 6UodrBjL2ZreDy7QdR4YV1oxqMBjVYSEyrFpctqqwGwL --reserve 9pX8uCeeGnGYYTEVdVfreqBa9RfhtRWHcez3sU6uinYr --kind Collateral --mint DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263
-
npx ts-node src/client.ts topup-reward-to-farm --cluster mainnet --owner ../kamino-lending/keys/devnet/owner.json --reserve 9pX8uCeeGnGYYTEVdVfreqBa9RfhtRWHcez3sU6uinYr --kind Collateral --mint DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263 --amount 100000000000
Kamino Program commit
f31d9e64c40623fea6043849991c982f5bce01e8