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 pathrefreshReserve.ts
More file actions
52 lines (47 loc) · 1.44 KB
/
refreshReserve.ts
File metadata and controls
52 lines (47 loc) · 1.44 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
46
47
48
49
50
51
52
import {
PublicKey,
SYSVAR_CLOCK_PUBKEY,
TransactionInstruction,
} from "@solana/web3.js";
import * as BufferLayout from "buffer-layout";
import { LendingInstruction } from "./instruction";
/// Accrue interest and update market price of liquidity on a reserve.
///
/// Accounts expected by this instruction:
///
/// 0. `[writable]` Reserve account.
/// 1. `[]` Clock sysvar.
/// 2. `[optional]` Reserve liquidity oracle account.
/// Required if the reserve currency is not the lending market quote
/// currency.
export const refreshReserveInstruction = (
reserve: PublicKey,
solendProgramAddress: PublicKey,
oracle?: PublicKey,
switchboardFeedAddress?: PublicKey
): TransactionInstruction => {
const dataLayout = BufferLayout.struct([BufferLayout.u8("instruction")]);
const data = Buffer.alloc(dataLayout.span);
dataLayout.encode({ instruction: LendingInstruction.RefreshReserve }, data);
const keys = [{ pubkey: reserve, isSigner: false, isWritable: true }];
if (oracle) {
keys.push({ pubkey: oracle, isSigner: false, isWritable: false });
}
if (switchboardFeedAddress) {
keys.push({
pubkey: switchboardFeedAddress,
isSigner: false,
isWritable: false,
});
}
keys.push({
pubkey: SYSVAR_CLOCK_PUBKEY,
isSigner: false,
isWritable: false,
});
return new TransactionInstruction({
keys,
programId: solendProgramAddress,
data,
});
};