diff --git a/src/actions/account.ts b/src/actions/account.ts index f428008..7d80fd4 100644 --- a/src/actions/account.ts +++ b/src/actions/account.ts @@ -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, diff --git a/src/actions/borrow.tsx b/src/actions/borrow.tsx index 4d59073..a03d2e5 100644 --- a/src/actions/borrow.tsx +++ b/src/actions/borrow.tsx @@ -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(