mirror of https://github.com/certusone/oyster.git
feat: accrue interest, resolves #38
This commit is contained in:
parent
7a7250ea62
commit
01bae0f1c8
|
@ -6,7 +6,7 @@ import {
|
||||||
} from "@solana/web3.js";
|
} from "@solana/web3.js";
|
||||||
import { sendTransaction } from "../contexts/connection";
|
import { sendTransaction } from "../contexts/connection";
|
||||||
import { notify } from "../utils/notifications";
|
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 { AccountLayout, MintInfo, MintLayout } from "@solana/spl-token";
|
||||||
import { LENDING_PROGRAM_ID, LEND_HOST_FEE_ADDRESS } from "../utils/ids";
|
import { LENDING_PROGRAM_ID, LEND_HOST_FEE_ADDRESS } from "../utils/ids";
|
||||||
import {
|
import {
|
||||||
|
@ -123,7 +123,6 @@ export const borrow = async (
|
||||||
)
|
)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
|
|
||||||
if (instructions.length > 0) {
|
if (instructions.length > 0) {
|
||||||
// create all accounts in one transaction
|
// create all accounts in one transaction
|
||||||
let tx = await sendTransaction(connection, wallet, instructions, [...signers]);
|
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);
|
const memory = createTempMemoryAccount(instructions, wallet.publicKey, signers, LENDING_PROGRAM_ID);
|
||||||
|
|
||||||
|
instructions.push(
|
||||||
|
accrueInterestInstruction(
|
||||||
|
depositReserve.pubkey,
|
||||||
|
borrowReserve.pubkey,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
// borrow
|
// borrow
|
||||||
instructions.push(
|
instructions.push(
|
||||||
borrowInstruction(
|
borrowInstruction(
|
||||||
|
|
|
@ -7,6 +7,7 @@ import {
|
||||||
import { sendTransaction } from "../contexts/connection";
|
import { sendTransaction } from "../contexts/connection";
|
||||||
import { notify } from "../utils/notifications";
|
import { notify } from "../utils/notifications";
|
||||||
import {
|
import {
|
||||||
|
accrueInterestInstruction,
|
||||||
depositInstruction,
|
depositInstruction,
|
||||||
initReserveInstruction,
|
initReserveInstruction,
|
||||||
LendingReserve,
|
LendingReserve,
|
||||||
|
@ -85,6 +86,12 @@ export const deposit = async (
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isInitalized) {
|
if (isInitalized) {
|
||||||
|
instructions.push(
|
||||||
|
accrueInterestInstruction(
|
||||||
|
reserveAddress,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
// deposit
|
// deposit
|
||||||
instructions.push(
|
instructions.push(
|
||||||
depositInstruction(
|
depositInstruction(
|
||||||
|
|
|
@ -6,7 +6,7 @@ import {
|
||||||
} from "@solana/web3.js";
|
} from "@solana/web3.js";
|
||||||
import { sendTransaction } from "../contexts/connection";
|
import { sendTransaction } from "../contexts/connection";
|
||||||
import { notify } from "../utils/notifications";
|
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 { liquidateInstruction } from "./../models/lending/liquidate";
|
||||||
import { AccountLayout } from "@solana/spl-token";
|
import { AccountLayout } from "@solana/spl-token";
|
||||||
import { LENDING_PROGRAM_ID } from "../utils/ids";
|
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);
|
const memory = createTempMemoryAccount(instructions, wallet.publicKey, signers, LENDING_PROGRAM_ID);
|
||||||
|
|
||||||
|
instructions.push(
|
||||||
|
accrueInterestInstruction(
|
||||||
|
repayReserve.pubkey,
|
||||||
|
withdrawReserve.pubkey,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
instructions.push(
|
instructions.push(
|
||||||
liquidateInstruction(
|
liquidateInstruction(
|
||||||
amountLamports,
|
amountLamports,
|
||||||
|
|
|
@ -6,7 +6,7 @@ import {
|
||||||
} from "@solana/web3.js";
|
} from "@solana/web3.js";
|
||||||
import { sendTransaction } from "../contexts/connection";
|
import { sendTransaction } from "../contexts/connection";
|
||||||
import { notify } from "../utils/notifications";
|
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 { repayInstruction } from "./../models/lending/repay";
|
||||||
import { AccountLayout, Token, NATIVE_MINT } from "@solana/spl-token";
|
import { AccountLayout, Token, NATIVE_MINT } from "@solana/spl-token";
|
||||||
import { LENDING_PROGRAM_ID, TOKEN_PROGRAM_ID } from "../utils/ids";
|
import { LENDING_PROGRAM_ID, TOKEN_PROGRAM_ID } from "../utils/ids";
|
||||||
|
@ -87,7 +87,12 @@ export const repay = async (
|
||||||
transferAuthority.publicKey,
|
transferAuthority.publicKey,
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO: add obligation
|
instructions.push(
|
||||||
|
accrueInterestInstruction(
|
||||||
|
repayReserve.pubkey,
|
||||||
|
withdrawReserve.pubkey,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
instructions.push(
|
instructions.push(
|
||||||
repayInstruction(
|
repayInstruction(
|
||||||
|
|
|
@ -6,7 +6,7 @@ import {
|
||||||
} from "@solana/web3.js";
|
} from "@solana/web3.js";
|
||||||
import { sendTransaction } from "../contexts/connection";
|
import { sendTransaction } from "../contexts/connection";
|
||||||
import { notify } from "../utils/notifications";
|
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 { AccountLayout } from "@solana/spl-token";
|
||||||
import { LENDING_PROGRAM_ID } from "../utils/ids";
|
import { LENDING_PROGRAM_ID } from "../utils/ids";
|
||||||
import { findOrCreateAccountByMint } from "./account";
|
import { findOrCreateAccountByMint } from "./account";
|
||||||
|
@ -59,6 +59,12 @@ export const withdraw = async (
|
||||||
signers
|
signers
|
||||||
);
|
);
|
||||||
|
|
||||||
|
instructions.push(
|
||||||
|
accrueInterestInstruction(
|
||||||
|
reserveAddress
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
instructions.push(
|
instructions.push(
|
||||||
withdrawInstruction(
|
withdrawInstruction(
|
||||||
amountLamports,
|
amountLamports,
|
||||||
|
|
|
@ -205,7 +205,7 @@ export const initReserveInstruction = (
|
||||||
};
|
};
|
||||||
|
|
||||||
export const accrueInterestInstruction = (
|
export const accrueInterestInstruction = (
|
||||||
reserveAccount: PublicKey[],
|
...reserveAccount: PublicKey[]
|
||||||
): TransactionInstruction => {
|
): TransactionInstruction => {
|
||||||
const dataLayout = BufferLayout.struct([
|
const dataLayout = BufferLayout.struct([
|
||||||
BufferLayout.u8('instruction'),
|
BufferLayout.u8('instruction'),
|
||||||
|
|
Loading…
Reference in New Issue