This repository was archived by the owner on Oct 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathinitObligation.ts
More file actions
45 lines (42 loc) · 1.49 KB
/
initObligation.ts
File metadata and controls
45 lines (42 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
import {
PublicKey,
SYSVAR_CLOCK_PUBKEY,
SYSVAR_RENT_PUBKEY,
TransactionInstruction,
} from "@solana/web3.js";
import * as BufferLayout from "buffer-layout";
import { LendingInstruction } from "./instruction";
/// Initializes a new lending market obligation.
///
/// Accounts expected by this instruction:
///
/// 0. `[writable]` Obligation account - uninitialized.
/// 1. `[]` Lending market account.
/// 2. `[signer]` Obligation owner.
/// 3. `[]` Clock sysvar.
/// 4. `[]` Rent sysvar.
/// 5. `[]` Token program id.
export const initObligationInstruction = (
obligation: PublicKey,
lendingMarket: PublicKey,
obligationOwner: PublicKey,
solendProgramAddress: PublicKey
): TransactionInstruction => {
const dataLayout = BufferLayout.struct([BufferLayout.u8("instruction")]);
const data = Buffer.alloc(dataLayout.span);
dataLayout.encode({ instruction: LendingInstruction.InitObligation }, data);
const keys = [
{ pubkey: obligation, isSigner: false, isWritable: true },
{ pubkey: lendingMarket, isSigner: false, isWritable: false },
{ pubkey: obligationOwner, isSigner: true, isWritable: false },
{ pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false },
{ pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false },
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
];
return new TransactionInstruction({
keys,
programId: solendProgramAddress,
data,
});
};