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
53
54
55
56
57
58
59
60
61
62
63
64
use {
    super::*,
    spl_token_2022::{
        extension::interest_bearing_mint::{
            instruction::{InitializeInstructionData, InterestBearingMintInstruction},
            BasisPoints,
        },
        instruction::{decode_instruction_data, decode_instruction_type},
    },
};

pub(in crate::parse_token) fn parse_interest_bearing_mint_instruction(
    instruction_data: &[u8],
    account_indexes: &[u8],
    account_keys: &AccountKeys,
) -> Result<ParsedInstructionEnum, ParseInstructionError> {
    match decode_instruction_type(instruction_data)
        .map_err(|_| ParseInstructionError::InstructionNotParsable(ParsableProgram::SplToken))?
    {
        InterestBearingMintInstruction::Initialize => {
            check_num_token_accounts(account_indexes, 1)?;
            let InitializeInstructionData {
                rate_authority,
                rate,
            } = *decode_instruction_data(instruction_data).map_err(|_| {
                ParseInstructionError::InstructionNotParsable(ParsableProgram::SplToken)
            })?;
            let rate_authority = rate_authority;
            let rate_authority: Option<Pubkey> = rate_authority.into();
            Ok(ParsedInstructionEnum {
                instruction_type: "initializeInterestBearingConfig".to_string(),
                info: json!({
                    "mint": account_keys[account_indexes[0] as usize].to_string(),
                    "rateAuthority": rate_authority.map(|pubkey| pubkey.to_string()),
                    "rate": i16::from(rate),
                }),
            })
        }
        InterestBearingMintInstruction::UpdateRate => {
            check_num_token_accounts(account_indexes, 2)?;
            let new_rate: BasisPoints =
                *decode_instruction_data(instruction_data).map_err(|_| {
                    ParseInstructionError::InstructionNotParsable(ParsableProgram::SplToken)
                })?;
            let mut value = json!({
                "mint": account_keys[account_indexes[0] as usize].to_string(),
                "newRate": i16::from(new_rate),
            });
            let map = value.as_object_mut().unwrap();
            parse_signers(
                map,
                1,
                account_keys,
                account_indexes,
                "rateAuthority",
                "multisigRateAuthority",
            );
            Ok(ParsedInstructionEnum {
                instruction_type: "updateInterestBearingConfigRate".to_string(),
                info: value,
            })
        }
    }
}