feat: accrue interest, resolves #38

This commit is contained in:
bartosz-lipinski 2021-01-22 23:04:23 -06:00
parent 7a7250ea62
commit 01bae0f1c8
6 changed files with 39 additions and 8 deletions

View File

@ -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(

View File

@ -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(

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -205,7 +205,7 @@ export const initReserveInstruction = (
};
export const accrueInterestInstruction = (
reserveAccount: PublicKey[],
...reserveAccount: PublicKey[]
): TransactionInstruction => {
const dataLayout = BufferLayout.struct([
BufferLayout.u8('instruction'),