fix: obligation account

This commit is contained in:
Justin Starry 2020-11-21 15:15:14 +08:00
parent c9a87b3771
commit a87a8cfcdd
2 changed files with 26 additions and 3 deletions

View File

@ -5,8 +5,8 @@ import {
SystemProgram,
TransactionInstruction,
} from "@solana/web3.js";
import { TOKEN_PROGRAM_ID, WRAPPED_SOL_MINT } from "../constants/ids";
import { TokenAccount } from "../models";
import { LENDING_PROGRAM_ID, TOKEN_PROGRAM_ID, WRAPPED_SOL_MINT } from "../constants/ids";
import { LendingObligationLayout, TokenAccount } from "../models";
import { cache, TokenAccountParser } from "./../contexts/accounts";
export function ensureSplAccount(
@ -75,6 +75,28 @@ export function createTempMemoryAccount(
return account.publicKey;
}
export function createUninitializedObligation(
instructions: TransactionInstruction[],
payer: PublicKey,
amount: number,
signers: Account[]
) {
const account = new Account();
instructions.push(
SystemProgram.createAccount({
fromPubkey: payer,
newAccountPubkey: account.publicKey,
lamports: amount,
space: LendingObligationLayout.span,
programId: LENDING_PROGRAM_ID,
})
);
signers.push(account);
return account.publicKey;
}
export function createUninitializedMint(
instructions: TransactionInstruction[],
payer: PublicKey,

View File

@ -13,6 +13,7 @@ import {
createTempMemoryAccount,
createUninitializedAccount,
createUninitializedMint,
createUninitializedObligation,
ensureSplAccount,
findOrCreateAccountByMint,
} from "./account";
@ -52,7 +53,7 @@ export const borrow = async (
AccountLayout.span
);
const obligation = createUninitializedAccount(
const obligation = createUninitializedObligation(
instructions,
wallet.publicKey,
await connection.getMinimumBalanceForRentExemption(