Skip to content

chore: improved error logs + docs and naming #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Mar 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bcc9d3f
feat: include account labels in error messages
thlorenz Mar 6, 2025
f6f3de1
feat: add msgs to inline errors
thlorenz Mar 6, 2025
48b944c
feat: documenting delegate instruction
thlorenz Mar 6, 2025
ff8b183
docs: commit state
thlorenz Mar 6, 2025
17b86dc
chore: minor cosmetics
thlorenz Mar 6, 2025
35b894c
docs: commit args and finalize
thlorenz Mar 6, 2025
e686b4a
docs: undelegate
thlorenz Mar 6, 2025
242d5c0
chore: consistent naming of protocol fees vault ixs + methods
thlorenz Mar 7, 2025
5db5765
docs: initialize protocol fees vault
thlorenz Mar 7, 2025
d3c0b3e
docs: init validator fees vault
thlorenz Mar 7, 2025
aebda73
chore: load protocol fees full method name
thlorenz Mar 7, 2025
1c6cc96
docs: validator claim fees
thlorenz Mar 7, 2025
1a8d2b8
docs: whitelist validator
thlorenz Mar 7, 2025
5975d28
chore: fill in docs for args I missed earlier
thlorenz Mar 7, 2025
94b4bc4
docs: ephemeral balance top up
thlorenz Mar 7, 2025
af912fc
docs: delegate ephemeral balance
thlorenz Mar 7, 2025
c8ea8fc
docs: normalize all account docs to be numbered
thlorenz Mar 7, 2025
696e862
docs: close ephemeral balance account
thlorenz Mar 7, 2025
c38cffe
docs: protocol claim fees
thlorenz Mar 7, 2025
f4aca70
docs: commit state from buffer
thlorenz Mar 7, 2025
2eaa16b
chore: remove question markers
thlorenz Mar 7, 2025
7f5a48d
fix: typo
thlorenz Mar 7, 2025
24f12a5
fix: comment typo
thlorenz Mar 7, 2025
a8fa376
fix: comment typo
thlorenz Mar 7, 2025
9c7abbd
fix: greptile issues
thlorenz Mar 7, 2025
b5081dd
fix: writable account not documented as such
thlorenz Mar 7, 2025
cbb16e1
chore: pointing out accounts that don't need to be writable
thlorenz Mar 7, 2025
03ad7e0
chore: address account optimizations
thlorenz Mar 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/args/commit_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@ use borsh::{BorshDeserialize, BorshSerialize};

#[derive(Default, Debug, BorshSerialize, BorshDeserialize)]
pub struct CommitStateArgs {
/// The ephemeral slot at which the account data is committed
pub slot: u64,
/// The lamports that the account holds in the ephemeral validator
pub lamports: u64,
/// Whether the account can be undelegated after the commit completes
pub allow_undelegation: bool,
/// The account data
pub data: Vec<u8>,
}

#[derive(Default, Debug, BorshSerialize, BorshDeserialize)]
pub struct CommitStateFromBufferArgs {
/// The ephemeral slot at which the account data is committed
pub slot: u64,
/// The lamports that the account holds in the ephemeral validator
pub lamports: u64,
/// Whether the account can be undelegated after the commit completes
pub allow_undelegation: bool,
}
4 changes: 4 additions & 0 deletions src/args/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ use solana_program::pubkey::Pubkey;

#[derive(Default, Debug, BorshSerialize, BorshDeserialize)]
pub struct DelegateArgs {
/// The frequency at which the validator should commit the account data
/// if no commit is triggered by the owning program
pub commit_frequency_ms: u32,
/// The seeds used to derive the PDA of the delegated account
pub seeds: Vec<Vec<u8>>,
/// The validator authority that is added to the delegation record
pub validator: Option<Pubkey>,
}
3 changes: 3 additions & 0 deletions src/args/top_up_ephemeral_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ use borsh::{BorshDeserialize, BorshSerialize};

#[derive(Debug, BorshSerialize, BorshDeserialize)]
pub struct TopUpEphemeralBalanceArgs {
/// The amount to add to the ephemeral balance.
pub amount: u64,
/// The index of the ephemeral balance account to top up which allows
/// one payer to have multiple ephemeral balance accounts.
pub index: u8,
}
3 changes: 3 additions & 0 deletions src/args/validator_claim_fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ use borsh::{BorshDeserialize, BorshSerialize};

#[derive(Default, Debug, BorshSerialize, BorshDeserialize)]
pub struct ValidatorClaimFeesArgs {
/// The amount to claim from the fees vault.
/// If `None`, almost the entire amount is claimed. The remaining amount
/// is needed to keep the fees vault rent-exempt.
pub amount: Option<u64>,
}
2 changes: 2 additions & 0 deletions src/args/whitelist_validator_for_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ use borsh::{BorshDeserialize, BorshSerialize};

#[derive(Debug, BorshSerialize, BorshDeserialize)]
pub struct WhitelistValidatorForProgramArgs {
/// If `true`, insert the validator identity into the program whitelist,
/// otherwise remove it.
pub insert: bool,
}
17 changes: 15 additions & 2 deletions src/discriminator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,31 @@ use solana_program::program_error::ProgramError;
#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
#[rustfmt::skip]
pub enum DlpDiscriminator {
/// See [crate::processor::process_delegate] for docs.
Delegate = 0,
/// See [crate::processor::process_commit_state] for docs.
CommitState = 1,
/// See [crate::processor::process_finalize] for docs.
Finalize = 2,
/// See [crate::processor::process_undelegate] for docs.
Undelegate = 3,
InitFeesVault = 5,
/// See [crate::processor::process_init_protocol_fees_vault] for docs.
InitProtocolFeesVault = 5,
/// See [crate::processor::process_init_validator_fees_vault] for docs.
InitValidatorFeesVault = 6,
/// See [crate::processor::process_validator_claim_fees] for docs.
ValidatorClaimFees = 7,
/// See [crate::processor::process_whitelist_validator_for_program] for docs.
WhitelistValidatorForProgram = 8,
/// See [crate::processor::process_top_up_ephemeral_balance] for docs.
TopUpEphemeralBalance = 9,
/// See [crate::processor::process_delegate_ephemeral_balance] for docs.
DelegateEphemeralBalance = 10,
/// See [crate::processor::process_close_ephemeral_balance] for docs.
CloseEphemeralBalance = 11,
/// See [crate::processor::process_protocol_claim_fees] for docs.
ProtocolClaimFees = 12,
/// See [crate::processor::process_commit_state_from_buffer] for docs.
CommitStateFromBuffer = 13,
}

Expand All @@ -35,7 +48,7 @@ impl TryFrom<[u8; 8]> for DlpDiscriminator {
0x1 => Ok(DlpDiscriminator::CommitState),
0x2 => Ok(DlpDiscriminator::Finalize),
0x3 => Ok(DlpDiscriminator::Undelegate),
0x5 => Ok(DlpDiscriminator::InitFeesVault),
0x5 => Ok(DlpDiscriminator::InitProtocolFeesVault),
0x6 => Ok(DlpDiscriminator::InitValidatorFeesVault),
0x7 => Ok(DlpDiscriminator::ValidatorClaimFees),
0x8 => Ok(DlpDiscriminator::WhitelistValidatorForProgram),
Expand Down
4 changes: 2 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use thiserror::Error;
pub enum DlpError {
#[error("Invalid Authority")]
InvalidAuthority = 0,
#[error("Account cannot be undelegated, is_delegatable is false")]
Undelegatable = 1,
#[error("Account cannot be undelegated, is_undelegatable is false")]
NotUndelegatable = 1,
#[error("Unauthorized Operation")]
Unauthorized = 2,
#[error("Invalid Authority for the current target program")]
Expand Down
2 changes: 2 additions & 0 deletions src/instruction_builder/close_ephemeral_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use solana_program::{instruction::AccountMeta, pubkey::Pubkey};
use crate::discriminator::DlpDiscriminator;
use crate::pda::ephemeral_balance_pda_from_payer;

/// Creates instruction to close an ephemeral balance account
/// See [crate::processor::process_close_ephemeral_balance] for docs.
pub fn close_ephemeral_balance(payer: Pubkey, index: u8) -> Instruction {
let ephemeral_balance_pda = ephemeral_balance_pda_from_payer(&payer, index);
Instruction {
Expand Down
1 change: 1 addition & 0 deletions src/instruction_builder/commit_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::pda::{
};

/// Builds a commit state instruction.
/// See [crate::processor::process_commit_state] for docs.
pub fn commit_state(
validator: Pubkey,
delegated_account: Pubkey,
Expand Down
1 change: 1 addition & 0 deletions src/instruction_builder/commit_state_from_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::pda::{
};

/// Builds a commit state from buffer instruction.
/// See [crate::processor::process_commit_state_from_buffer] for docs.
pub fn commit_state_from_buffer(
validator: Pubkey,
delegated_account: Pubkey,
Expand Down
1 change: 1 addition & 0 deletions src/instruction_builder/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::pda::{
};

/// Builds a delegate instruction
/// See [crate::processor::process_delegate] for docs.
pub fn delegate(
payer: Pubkey,
delegated_account: Pubkey,
Expand Down
1 change: 1 addition & 0 deletions src/instruction_builder/delegate_ephemeral_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::pda::{
};

/// Delegate ephemeral balance
/// See [crate::processor::process_delegate_ephemeral_balance] for docs.
pub fn delegate_ephemeral_balance(
payer: Pubkey,
pubkey: Pubkey,
Expand Down
1 change: 1 addition & 0 deletions src/instruction_builder/finalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::pda::{
};

/// Builds a finalize state instruction.
/// See [crate::processor::process_finalize] for docs.
pub fn finalize(validator: Pubkey, delegated_account: Pubkey) -> Instruction {
let commit_state_pda = commit_state_pda_from_delegated_account(&delegated_account);
let commit_record_pda = commit_record_pda_from_delegated_account(&delegated_account);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use crate::discriminator::DlpDiscriminator;
use crate::pda::fees_vault_pda;

/// Initialize the fees vault PDA.
pub fn init_fees_vault(payer: Pubkey) -> Instruction {
/// See [crate::processor::process_init_protocol_fees_vault] for docs.
pub fn init_protocol_fees_vault(payer: Pubkey) -> Instruction {
let fees_vault_pda = fees_vault_pda();
Instruction {
program_id: crate::id(),
Expand All @@ -15,6 +16,6 @@ pub fn init_fees_vault(payer: Pubkey) -> Instruction {
AccountMeta::new(fees_vault_pda, false),
AccountMeta::new_readonly(system_program::id(), false),
],
data: DlpDiscriminator::InitFeesVault.to_vec(),
data: DlpDiscriminator::InitProtocolFeesVault.to_vec(),
}
}
1 change: 1 addition & 0 deletions src/instruction_builder/init_validator_fees_vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::discriminator::DlpDiscriminator;
use crate::pda::validator_fees_vault_pda_from_validator;

/// Initialize a validator fees vault PDA.
/// See [crate::processor::process_init_validator_fees_vault] for docs.
pub fn init_validator_fees_vault(
payer: Pubkey,
admin: Pubkey,
Expand Down
4 changes: 2 additions & 2 deletions src/instruction_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod commit_state_from_buffer;
mod delegate;
mod delegate_ephemeral_balance;
mod finalize;
mod init_fees_vault;
mod init_protocol_fees_vault;
mod init_validator_fees_vault;
mod protocol_claim_fees;
mod top_up_ephemeral_balance;
Expand All @@ -19,7 +19,7 @@ pub use commit_state_from_buffer::*;
pub use delegate::*;
pub use delegate_ephemeral_balance::*;
pub use finalize::*;
pub use init_fees_vault::*;
pub use init_protocol_fees_vault::*;
pub use init_validator_fees_vault::*;
pub use protocol_claim_fees::*;
pub use top_up_ephemeral_balance::*;
Expand Down
1 change: 1 addition & 0 deletions src/instruction_builder/protocol_claim_fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::discriminator::DlpDiscriminator;
use crate::pda::fees_vault_pda;

/// Claim the accrued fees from the protocol fees vault.
/// See [crate::processor::process_protocol_claim_fees] for docs.
pub fn protocol_claim_fees(admin: Pubkey) -> Instruction {
let fees_vault_pda = fees_vault_pda();
Instruction {
Expand Down
1 change: 1 addition & 0 deletions src/instruction_builder/top_up_ephemeral_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::discriminator::DlpDiscriminator;
use crate::pda::ephemeral_balance_pda_from_payer;

/// Builds a top-up ephemeral balance instruction.
/// See [crate::processor::process_top_up_ephemeral_balance] for docs.
pub fn top_up_ephemeral_balance(
payer: Pubkey,
pubkey: Pubkey,
Expand Down
1 change: 1 addition & 0 deletions src/instruction_builder/undelegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::pda::{
};

/// Builds an undelegate instruction.
/// See [crate::processor::process_undelegate] for docs.
#[allow(clippy::too_many_arguments)]
pub fn undelegate(
validator: Pubkey,
Expand Down
1 change: 1 addition & 0 deletions src/instruction_builder/validator_claim_fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::discriminator::DlpDiscriminator;
use crate::pda::{fees_vault_pda, validator_fees_vault_pda_from_validator};

/// Claim the accrued fees from the fees vault.
/// See [crate::processor::process_validator_claim_fees] for docs.
pub fn validator_claim_fees(validator: Pubkey, amount: Option<u64>) -> Instruction {
let args = ValidatorClaimFeesArgs { amount };
let fees_vault_pda = fees_vault_pda();
Expand Down
4 changes: 3 additions & 1 deletion src/instruction_builder/whitelist_validator_for_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use crate::discriminator::DlpDiscriminator;
use crate::pda::program_config_from_program_id;

/// Whitelist validator for program
///
/// See [crate::processor::process_whitelist_validator_for_program] for docs.
pub fn whitelist_validator_for_program(
authority: Pubkey,
validator_identity: Pubkey,
Expand All @@ -23,7 +25,7 @@ pub fn whitelist_validator_for_program(
program_id: crate::id(),
accounts: vec![
AccountMeta::new(authority, true),
AccountMeta::new(validator_identity, false),
AccountMeta::new_readonly(validator_identity, false),
AccountMeta::new_readonly(program, false),
AccountMeta::new_readonly(program_data, false),
AccountMeta::new(program_config_pda, false),
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub fn process_instruction(
discriminator::DlpDiscriminator::InitValidatorFeesVault => {
processor::process_init_validator_fees_vault(program_id, accounts, data)?
}
discriminator::DlpDiscriminator::InitFeesVault => {
discriminator::DlpDiscriminator::InitProtocolFeesVault => {
processor::process_init_protocol_fees_vault(program_id, accounts, data)?
}
discriminator::DlpDiscriminator::ValidatorClaimFees => {
Expand Down
18 changes: 17 additions & 1 deletion src/processor/close_ephemeral_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ use crate::processor::utils::pda::close_pda;
use solana_program::program_error::ProgramError;
use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey};

/// Process the closing of an ephemeral balance account
///
/// Accounts:
///
/// 0: `[signer]` payer to pay for the transaction and receive the refund
/// 1: `[writable]` ephemeral balance account we are closing
///
/// Requirements:
///
/// - ephemeral balance account is initialized
///
/// Steps:
///
/// 1. Closes the ephemeral balance account and refunds the payer with the
/// escrowed lamports
pub fn process_close_ephemeral_balance(
_program_id: &Pubkey,
accounts: &[AccountInfo],
Expand All @@ -16,13 +31,14 @@ pub fn process_close_ephemeral_balance(
return Err(ProgramError::NotEnoughAccountKeys);
};

load_signer(payer)?;
load_signer(payer, "payer")?;

load_initialized_pda(
ephemeral_balance_account,
ephemeral_balance_seeds_from_payer!(payer.key, index),
&crate::id(),
true,
"ephemeral balance",
)?;

close_pda(ephemeral_balance_account, payer)?;
Expand Down
Loading