|
| 1 | +use generic_array_struct::generic_array_struct; |
| 2 | + |
| 3 | +use crate::{ |
| 4 | + LIDO_STATE_ADDR, RESERVE_PDA, STSOL_MINT_ADDR, SYSTEM_PROGRAM, SYSVAR_CLOCK, SYSVAR_RENT, |
| 5 | + VALIDATOR_LIST_ADDR, |
| 6 | +}; |
| 7 | + |
| 8 | +#[generic_array_struct(pub)] |
| 9 | +#[repr(transparent)] |
| 10 | +#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)] |
| 11 | +pub struct UpdateExchangeRateV2IxAccs<T> { |
| 12 | + pub lido_state: T, |
| 13 | + pub reserve: T, |
| 14 | + pub stsol_mint: T, |
| 15 | + pub validator_list: T, |
| 16 | + pub sysvar_clock: T, |
| 17 | + pub sysvar_rent: T, |
| 18 | +} |
| 19 | + |
| 20 | +pub type UpdateExchangeRateV2IxKeysOwned = UpdateExchangeRateV2IxAccs<[u8; 32]>; |
| 21 | +pub type UpdateExchangeRateV2IxKeys<'a> = UpdateExchangeRateV2IxAccs<&'a [u8; 32]>; |
| 22 | +pub type UpdateExchangeRateV2IxAccsFlag = UpdateExchangeRateV2IxAccs<bool>; |
| 23 | + |
| 24 | +pub const UPDATE_EXCHANGE_RATE_V2_IX_IS_WRITER: UpdateExchangeRateV2IxAccsFlag = |
| 25 | + UpdateExchangeRateV2IxAccsFlag::new([false; UPDATE_EXCHANGE_RATE_V2_IX_ACCS_LEN]) |
| 26 | + .const_with_lido_state(true); |
| 27 | + |
| 28 | +pub const UPDATE_EXCHANGE_RATE_V2_IX_IS_SIGNER: UpdateExchangeRateV2IxAccsFlag = |
| 29 | + UpdateExchangeRateV2IxAccsFlag::new([false; UPDATE_EXCHANGE_RATE_V2_IX_ACCS_LEN]); |
| 30 | + |
| 31 | +impl<T> UpdateExchangeRateV2IxAccs<T> { |
| 32 | + #[inline] |
| 33 | + pub const fn new(arr: [T; UPDATE_EXCHANGE_RATE_V2_IX_ACCS_LEN]) -> Self { |
| 34 | + Self(arr) |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +impl UpdateExchangeRateV2IxKeysOwned { |
| 39 | + #[inline] |
| 40 | + pub fn as_borrowed(&self) -> UpdateExchangeRateV2IxKeys<'_> { |
| 41 | + UpdateExchangeRateV2IxKeys::new(self.0.each_ref()) |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +impl UpdateExchangeRateV2IxKeys<'_> { |
| 46 | + #[inline] |
| 47 | + pub fn into_owned(self) -> UpdateExchangeRateV2IxKeysOwned { |
| 48 | + UpdateExchangeRateV2IxKeysOwned::new(self.0.map(|pk| *pk)) |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +impl UpdateExchangeRateV2IxKeys<'_> { |
| 53 | + /// The account keys input to this ix should never change |
| 54 | + pub const CONST: Self = Self::new([&SYSTEM_PROGRAM; UPDATE_EXCHANGE_RATE_V2_IX_ACCS_LEN]) |
| 55 | + .with_lido_consts() |
| 56 | + .with_sol_consts(); |
| 57 | + |
| 58 | + #[inline] |
| 59 | + pub const fn with_lido_consts(self) -> Self { |
| 60 | + self.const_with_lido_state(&LIDO_STATE_ADDR) |
| 61 | + .const_with_stsol_mint(&STSOL_MINT_ADDR) |
| 62 | + .const_with_validator_list(&VALIDATOR_LIST_ADDR) |
| 63 | + .const_with_reserve(&RESERVE_PDA) |
| 64 | + } |
| 65 | + |
| 66 | + #[inline] |
| 67 | + pub const fn with_sol_consts(self) -> Self { |
| 68 | + self.const_with_sysvar_clock(&SYSVAR_CLOCK) |
| 69 | + .const_with_sysvar_rent(&SYSVAR_RENT) |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +pub const UPDATE_EXCHANGE_RATE_V2_IX_DISCM: u8 = 22; |
| 74 | + |
| 75 | +pub const UPDATE_EXCHANGE_RATE_V2_IX_DATA_LEN: usize = 1; |
| 76 | + |
| 77 | +#[repr(transparent)] |
| 78 | +#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)] |
| 79 | +pub struct UpdateExchangeRateV2IxData([u8; UPDATE_EXCHANGE_RATE_V2_IX_DATA_LEN]); |
| 80 | + |
| 81 | +impl UpdateExchangeRateV2IxData { |
| 82 | + pub const CONST: Self = Self([UPDATE_EXCHANGE_RATE_V2_IX_DISCM]); |
| 83 | + |
| 84 | + #[inline] |
| 85 | + pub const fn new() -> Self { |
| 86 | + Self::CONST |
| 87 | + } |
| 88 | + |
| 89 | + #[inline] |
| 90 | + pub const fn to_buf(self) -> [u8; UPDATE_EXCHANGE_RATE_V2_IX_DATA_LEN] { |
| 91 | + self.0 |
| 92 | + } |
| 93 | +} |
0 commit comments