You’ll also need the Kamino Lending IDL file to interact with the program. You can generate it from the source or obtain it from the Kamino Finance repository.
3
Configure your connection
Create a file config.ts to set up your connection to the Kamino Lending program:
import { Connection, PublicKey, clusterApiUrl } from '@solana/web3.js';import { AnchorProvider, Program } from '@coral-xyz/anchor';// Kamino Lending program ID on devnetexport const KLEND_PROGRAM_ID = new PublicKey( 'KLend2g3cP87fffoy8q1mQqGKjrxjC8boSyAYavgmjD');// Connect to devnetexport const connection = new Connection( clusterApiUrl('devnet'), 'confirmed');// Set up provider (you'll need to configure your wallet)export function getProvider(wallet: any) { return new AnchorProvider( connection, wallet, { commitment: 'confirmed' } );}
4
Initialize an obligation
An obligation tracks a user’s deposits and borrows. Here’s how to create one:
import { PublicKey, Keypair, SystemProgram } from '@solana/web3.js';import { Program } from '@coral-xyz/anchor';import { KLEND_PROGRAM_ID } from './config';async function initializeObligation( program: Program, lendingMarket: PublicKey, obligationOwner: Keypair, userMetadata: PublicKey) { // Generate a unique ID for this obligation const obligationId = 0; const tag = 0; // Tag 0 = no specific seed requirements // Derive the obligation PDA const [obligationPubkey] = PublicKey.findProgramAddressSync( [ Buffer.from([tag]), Buffer.from([obligationId]), obligationOwner.publicKey.toBuffer(), lendingMarket.toBuffer(), PublicKey.default.toBuffer(), // seed1_account for tag 0 PublicKey.default.toBuffer(), // seed2_account for tag 0 ], KLEND_PROGRAM_ID ); // Initialize the obligation const tx = await program.methods .initObligation({ tag, id: obligationId, }) .accounts({ obligationOwner: obligationOwner.publicKey, feePayer: obligationOwner.publicKey, obligation: obligationPubkey, lendingMarket, seed1Account: PublicKey.default, seed2Account: PublicKey.default, ownerUserMetadata: userMetadata, systemProgram: SystemProgram.programId, }) .signers([obligationOwner]) .rpc(); console.log('Obligation initialized:', obligationPubkey.toString()); console.log('Transaction signature:', tx); return obligationPubkey;}
The initObligation instruction is defined at src/lib.rs:135. It requires a UserMetadata account to track referrals.
5
Deposit liquidity to a reserve
Once you have an obligation, you can deposit assets into reserves: