Skip to main content

klend_interface/
util.rs

1use solana_instruction::AccountMeta;
2use solana_pubkey::Pubkey;
3
4/// Build an `AccountMeta` for an optional account. When `opt` is `None`, the program ID is
5/// substituted (Anchor 0.29 convention for optional accounts).
6pub fn optional_account(
7    program_id: &Pubkey,
8    opt: Option<Pubkey>,
9    is_writable: bool,
10) -> AccountMeta {
11    match opt {
12        Some(key) => AccountMeta {
13            pubkey: key,
14            is_signer: false,
15            is_writable,
16        },
17        None => AccountMeta {
18            pubkey: *program_id,
19            is_signer: false,
20            is_writable: false,
21        },
22    }
23}
24
25pub fn readonly(pubkey: Pubkey) -> AccountMeta {
26    AccountMeta {
27        pubkey,
28        is_signer: false,
29        is_writable: false,
30    }
31}
32
33pub fn writable(pubkey: Pubkey) -> AccountMeta {
34    AccountMeta {
35        pubkey,
36        is_signer: false,
37        is_writable: true,
38    }
39}
40
41pub fn signer(pubkey: Pubkey) -> AccountMeta {
42    AccountMeta {
43        pubkey,
44        is_signer: true,
45        is_writable: false,
46    }
47}
48
49pub fn signer_writable(pubkey: Pubkey) -> AccountMeta {
50    AccountMeta {
51        pubkey,
52        is_signer: true,
53        is_writable: true,
54    }
55}