|
| 1 | +use num_enum::TryFromPrimitive; |
| 2 | +use pinocchio::{error::ProgramError, ProgramResult}; |
| 3 | +use strum::IntoStaticStr; |
| 4 | + |
| 5 | +#[repr(u8)] |
| 6 | +#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive, IntoStaticStr)] |
| 7 | +#[rustfmt::skip] |
| 8 | +pub enum DlpInstruction { |
| 9 | + /// |
| 10 | + /// Delegate group: [101, 110] => 10 slots |
| 11 | + /// |
| 12 | + Delegate = 101, |
| 13 | + DelegateWithAnyValidator = 102, |
| 14 | + |
| 15 | + /// |
| 16 | + /// Commit group: [111, 120] => 10 slots |
| 17 | + /// |
| 18 | + Commit = 111, |
| 19 | + CommitFromBuffer = 112, |
| 20 | + CommitFinalize = 113, |
| 21 | + CommitFinalizeFromBuffer = 114, |
| 22 | + |
| 23 | + /// |
| 24 | + /// Finalize group: [121, 130] => 10 slots |
| 25 | + /// |
| 26 | + Finalize = 121, |
| 27 | + |
| 28 | + /// |
| 29 | + /// Undelegate group: [131, 140] => 10 slots |
| 30 | + /// |
| 31 | + Undelegate = 131, |
| 32 | + UndelegateConfinedAccount = 132, |
| 33 | + |
| 34 | + /// |
| 35 | + /// User group: [141, 150] => 10 slots |
| 36 | + /// |
| 37 | + CallHandler = 141, |
| 38 | + |
| 39 | + /// |
| 40 | + /// Vaults group: [151, 160] => 10 slots |
| 41 | + /// |
| 42 | + InitProtocolFeesVault = 151, |
| 43 | + ProtocolClaimFees = 152, |
| 44 | + InitValidatorFeesVault = 153, |
| 45 | + ValidatorClaimFees = 154, |
| 46 | + CloseValidatorFeesVault = 155, |
| 47 | + |
| 48 | + /// |
| 49 | + /// Misc group: [161, 180] => 20 slots |
| 50 | + /// |
| 51 | + WhitelistValidatorForProgram = 161, |
| 52 | + TopUpEphemeralBalance = 162, |
| 53 | + DelegateEphemeralBalance = 163, |
| 54 | + CloseEphemeralBalance = 164, |
| 55 | +} |
| 56 | + |
| 57 | +impl DlpInstruction { |
| 58 | + pub fn to_vec(self) -> Vec<u8> { |
| 59 | + let num = self as u64; |
| 60 | + num.to_le_bytes().to_vec() |
| 61 | + } |
| 62 | + |
| 63 | + pub fn name(&self) -> &'static str { |
| 64 | + self.into() |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +pub fn v2_process_instruction( |
| 69 | + accounts: &[pinocchio::AccountView], |
| 70 | + data: &[u8], |
| 71 | +) -> ProgramResult { |
| 72 | + let (ix, data) = data.split_at(8); |
| 73 | + |
| 74 | + let ix = match DlpInstruction::try_from(ix[0]) { |
| 75 | + Ok(discriminator) => discriminator, |
| 76 | + Err(_) => { |
| 77 | + pinocchio_log::log!("Failed to read and parse discriminator"); |
| 78 | + return Err(pinocchio::error::ProgramError::InvalidInstructionData); |
| 79 | + } |
| 80 | + }; |
| 81 | + |
| 82 | + use super::processor::*; |
| 83 | + |
| 84 | + let coming_soon = || { |
| 85 | + solana_program::msg!("Instruction {:#?} not yet implemented", ix); |
| 86 | + return Err(ProgramError::InvalidInstructionData); |
| 87 | + }; |
| 88 | + |
| 89 | + match ix { |
| 90 | + DlpInstruction::Delegate => process_delegate(accounts, data), |
| 91 | + DlpInstruction::DelegateWithAnyValidator => { |
| 92 | + process_delegate_with_any_validator(accounts, data) |
| 93 | + } |
| 94 | + DlpInstruction::Commit => coming_soon(), |
| 95 | + DlpInstruction::CommitFromBuffer => coming_soon(), |
| 96 | + DlpInstruction::CommitFinalize => coming_soon(), |
| 97 | + DlpInstruction::CommitFinalizeFromBuffer => coming_soon(), |
| 98 | + DlpInstruction::Finalize => coming_soon(), |
| 99 | + DlpInstruction::Undelegate => coming_soon(), |
| 100 | + DlpInstruction::UndelegateConfinedAccount => coming_soon(), |
| 101 | + DlpInstruction::CallHandler => coming_soon(), |
| 102 | + DlpInstruction::InitProtocolFeesVault => coming_soon(), |
| 103 | + DlpInstruction::ProtocolClaimFees => coming_soon(), |
| 104 | + DlpInstruction::InitValidatorFeesVault => coming_soon(), |
| 105 | + DlpInstruction::ValidatorClaimFees => coming_soon(), |
| 106 | + DlpInstruction::CloseValidatorFeesVault => coming_soon(), |
| 107 | + DlpInstruction::WhitelistValidatorForProgram => coming_soon(), |
| 108 | + DlpInstruction::TopUpEphemeralBalance => coming_soon(), |
| 109 | + DlpInstruction::DelegateEphemeralBalance => coming_soon(), |
| 110 | + DlpInstruction::CloseEphemeralBalance => coming_soon(), |
| 111 | + } |
| 112 | +} |
0 commit comments