diff --git a/src/actions/borrow.tsx b/src/actions/borrow.tsx index 3fdb2d1..a48554e 100644 --- a/src/actions/borrow.tsx +++ b/src/actions/borrow.tsx @@ -6,7 +6,7 @@ import { } from "@solana/web3.js"; import { sendTransaction } from "../contexts/connection"; import { notify } from "../utils/notifications"; -import { LendingReserve } from "./../models/lending/reserve"; +import { accrueInterestInstruction, LendingReserve } from "./../models/lending/reserve"; import { AccountLayout, MintInfo, MintLayout } from "@solana/spl-token"; import { LENDING_PROGRAM_ID, LEND_HOST_FEE_ADDRESS } from "../utils/ids"; import { @@ -123,7 +123,6 @@ export const borrow = async ( ) : undefined; - if (instructions.length > 0) { // create all accounts in one transaction let tx = await sendTransaction(connection, wallet, instructions, [...signers]); @@ -202,6 +201,13 @@ export const borrow = async ( const memory = createTempMemoryAccount(instructions, wallet.publicKey, signers, LENDING_PROGRAM_ID); + instructions.push( + accrueInterestInstruction( + depositReserve.pubkey, + borrowReserve.pubkey, + ) + ); + // borrow instructions.push( borrowInstruction( diff --git a/src/actions/deposit.tsx b/src/actions/deposit.tsx index 454f3a2..f748fc4 100644 --- a/src/actions/deposit.tsx +++ b/src/actions/deposit.tsx @@ -7,6 +7,7 @@ import { import { sendTransaction } from "../contexts/connection"; import { notify } from "../utils/notifications"; import { + accrueInterestInstruction, depositInstruction, initReserveInstruction, LendingReserve, @@ -85,6 +86,12 @@ export const deposit = async ( } if (isInitalized) { + instructions.push( + accrueInterestInstruction( + reserveAddress, + ) + ); + // deposit instructions.push( depositInstruction( diff --git a/src/actions/liquidate.tsx b/src/actions/liquidate.tsx index d9f82c1..f76acff 100644 --- a/src/actions/liquidate.tsx +++ b/src/actions/liquidate.tsx @@ -6,7 +6,7 @@ import { } from "@solana/web3.js"; import { sendTransaction } from "../contexts/connection"; import { notify } from "../utils/notifications"; -import { LendingReserve } from "./../models/lending/reserve"; +import { accrueInterestInstruction, LendingReserve } from "./../models/lending/reserve"; import { liquidateInstruction } from "./../models/lending/liquidate"; import { AccountLayout } from "@solana/spl-token"; import { LENDING_PROGRAM_ID } from "../utils/ids"; @@ -92,6 +92,13 @@ export const liquidate = async ( const memory = createTempMemoryAccount(instructions, wallet.publicKey, signers, LENDING_PROGRAM_ID); + instructions.push( + accrueInterestInstruction( + repayReserve.pubkey, + withdrawReserve.pubkey, + ) + ); + instructions.push( liquidateInstruction( amountLamports, diff --git a/src/actions/repay.tsx b/src/actions/repay.tsx index e4365d6..9450715 100644 --- a/src/actions/repay.tsx +++ b/src/actions/repay.tsx @@ -6,7 +6,7 @@ import { } from "@solana/web3.js"; import { sendTransaction } from "../contexts/connection"; import { notify } from "../utils/notifications"; -import { LendingReserve } from "./../models/lending/reserve"; +import { accrueInterestInstruction, LendingReserve } from "./../models/lending/reserve"; import { repayInstruction } from "./../models/lending/repay"; import { AccountLayout, Token, NATIVE_MINT } from "@solana/spl-token"; import { LENDING_PROGRAM_ID, TOKEN_PROGRAM_ID } from "../utils/ids"; @@ -87,8 +87,13 @@ export const repay = async ( transferAuthority.publicKey, ); - // TODO: add obligation - + instructions.push( + accrueInterestInstruction( + repayReserve.pubkey, + withdrawReserve.pubkey, + ) + ); + instructions.push( repayInstruction( repayAmount, diff --git a/src/actions/withdraw.tsx b/src/actions/withdraw.tsx index 2e3455c..b9b1726 100644 --- a/src/actions/withdraw.tsx +++ b/src/actions/withdraw.tsx @@ -6,7 +6,7 @@ import { } from "@solana/web3.js"; import { sendTransaction } from "../contexts/connection"; import { notify } from "../utils/notifications"; -import { LendingReserve, withdrawInstruction } from "./../models/lending"; +import { accrueInterestInstruction, LendingReserve, withdrawInstruction } from "./../models/lending"; import { AccountLayout } from "@solana/spl-token"; import { LENDING_PROGRAM_ID } from "../utils/ids"; import { findOrCreateAccountByMint } from "./account"; @@ -59,6 +59,12 @@ export const withdraw = async ( signers ); + instructions.push( + accrueInterestInstruction( + reserveAddress + ) + ); + instructions.push( withdrawInstruction( amountLamports, diff --git a/src/models/lending/reserve.ts b/src/models/lending/reserve.ts index 4bf053e..eb4c66f 100644 --- a/src/models/lending/reserve.ts +++ b/src/models/lending/reserve.ts @@ -205,7 +205,7 @@ export const initReserveInstruction = ( }; export const accrueInterestInstruction = ( - reserveAccount: PublicKey[], + ...reserveAccount: PublicKey[] ): TransactionInstruction => { const dataLayout = BufferLayout.struct([ BufferLayout.u8('instruction'),