From dc84a347e7b73cb84feb7407229882c341fb91cc Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Thu, 2 May 2024 15:03:56 +0000 Subject: [PATCH] comments --- src/lib.rs | 2 -- src/processor/claim.rs | 8 ++++---- src/processor/deregister.rs | 9 +++++++++ src/processor/pause.rs | 10 ++++++++++ src/processor/register.rs | 2 +- src/processor/stake.rs | 8 ++++++++ src/processor/update_tolerance.rs | 8 ++++++++ src/processor/upgrade.rs | 7 +++++++ 8 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ee46608..3bcda6e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,8 +14,6 @@ use solana_program::{ program_error::ProgramError, pubkey::Pubkey, }; -// TODO Is downgrade necessary? - declare_id!("mineRHF5r6S7HyD9SppBfVMXMavDkJsxwGesEvxZr2A"); #[cfg(not(feature = "no-entrypoint"))] diff --git a/src/processor/claim.rs b/src/processor/claim.rs index 69ae1fe..4875e65 100644 --- a/src/processor/claim.rs +++ b/src/processor/claim.rs @@ -8,14 +8,14 @@ use crate::{ MINT_ADDRESS, TREASURY, TREASURY_BUMP, }; -/// Claim distributes owed token rewards from the treasury to the miner. Its responsibilies include: -/// 1. Decrement the miner's claimable rewards counter. +/// Claim distributes Ore from the treasury to a miner. Its responsibilies include: +/// 1. Decrement the miner's claimable balance. /// 2. Transfer tokens from the treasury to the miner. /// /// Safety requirements: -/// - Claim is a permissionless instruction and can be called by any miner. +/// - Claim is a permissionless instruction and can be called by any user. /// - Can only succeed if the claimed amount is less than or equal to the miner's claimable rewards. -/// - The provided beneficiary token account, treasury, treasury token account, and token program must be valid. +/// - The provided beneficiary, token account, treasury, treasury token account, and token program must be valid. pub fn process_claim<'a, 'info>( _program_id: &Pubkey, accounts: &'a [AccountInfo<'info>], diff --git a/src/processor/deregister.rs b/src/processor/deregister.rs index 0640e6c..8ec8d4a 100644 --- a/src/processor/deregister.rs +++ b/src/processor/deregister.rs @@ -5,6 +5,15 @@ use solana_program::{ use crate::{loaders::*, state::Proof, utils::AccountDeserialize, PROOF}; +/// Deregister closes a proof account and returns the rent to the owner. Its responsibilities include: +/// 1. Realloc proof account size to 0. +/// 2. Transfer lamports to the owner. +/// 3. Reassign the account owner back to the system program. +/// +/// Safety requirements: +/// - Deregister is a permissionless instruction and can be invoked by any singer. +/// - Can only succeed if the provided proof acount PDA is valid (associated with the signer). +/// - The provided system program must be valid. pub fn process_deregister<'a, 'info>( _program_id: &Pubkey, accounts: &'a [AccountInfo<'info>], diff --git a/src/processor/pause.rs b/src/processor/pause.rs index 4970c6e..29e4d17 100644 --- a/src/processor/pause.rs +++ b/src/processor/pause.rs @@ -5,6 +5,16 @@ use solana_program::{ use crate::{instruction::PauseArgs, loaders::*, state::Config, utils::AccountDeserialize}; +/// Pause updates the program's pause flag. Its responsibilities include: +/// 1. Update the pause flag. +/// +/// Safety requirements: +/// - Can only succeed if the signer is the program admin. +/// - Can only succeed if the provided config is valid. +/// +/// Discussion: +/// - This should only be used to address critical contract risks and force migration to a new +/// verison (hardfork). pub fn process_pause<'a, 'info>( _program_id: &Pubkey, accounts: &'a [AccountInfo<'info>], diff --git a/src/processor/register.rs b/src/processor/register.rs index 6b100ca..550ee24 100644 --- a/src/processor/register.rs +++ b/src/processor/register.rs @@ -21,7 +21,7 @@ use crate::{ /// Safety requirements: /// - Register is a permissionless instruction and can be invoked by any singer. /// - Can only succeed if the provided proof acount PDA is valid (associated with the signer). -/// - Can only succeed once per signer. +/// - Can only succeed if the user does not already have a proof account. /// - The provided system program must be valid. pub fn process_register<'a, 'info>( _program_id: &Pubkey, diff --git a/src/processor/stake.rs b/src/processor/stake.rs index dc18c61..bb3275b 100644 --- a/src/processor/stake.rs +++ b/src/processor/stake.rs @@ -8,6 +8,14 @@ use crate::{ TREASURY_ADDRESS, }; +/// Stake deposits Ore into a miner's proof account to earn multiplier. Its responsibilies include: +/// 1. Transfer tokens from the miner to the treasury account. +/// 2. Increment the miner's claimable balance. +/// +/// Safety requirements: +/// - Stake is a permissionless instruction and can be called by any user. +/// - Can only succeed if the amount is less than or equal to the miner's transferable tokens. +/// - The provided beneficiary, proof, sender, treasury token account, and token program must be valid. pub fn process_stake<'a, 'info>( _program_id: &Pubkey, accounts: &'a [AccountInfo<'info>], diff --git a/src/processor/update_tolerance.rs b/src/processor/update_tolerance.rs index 6dfbfe9..b7bd86b 100644 --- a/src/processor/update_tolerance.rs +++ b/src/processor/update_tolerance.rs @@ -8,6 +8,14 @@ use crate::{ utils::AccountDeserialize, ONE_MINUTE, }; +/// UpdateTolerance updates the program's tolerance settings. Its responsibilities include: +/// 1. Update the liveness tolerance. +/// 2. Update the spam tolerance. +/// +/// Safety requirements: +/// - Can only succeed if the signer is the program admin. +/// - Can only succeed if the provided config is valid. +/// - Can only succeed if the tolerances pass sanity tests. pub fn process_update_tolerance<'a, 'info>( _program_id: &Pubkey, accounts: &'a [AccountInfo<'info>], diff --git a/src/processor/upgrade.rs b/src/processor/upgrade.rs index b4ee4cf..f1f2bf5 100644 --- a/src/processor/upgrade.rs +++ b/src/processor/upgrade.rs @@ -7,6 +7,13 @@ use crate::{ instruction::StakeArgs, loaders::*, MINT_ADDRESS, MINT_V1_ADDRESS, TREASURY, TREASURY_BUMP, }; +/// Upgrade allows a user to migrate a v1 token to a v2 token one-for-one. Its responsibilies include: +/// 1. Burns the v1 tokens. +/// 2. Mints an equivalent number of v2 tokens to the user. +/// +/// Safety requirements: +/// - Upgrade is a permissionless instruction and can be called by any user. +/// - The provided beneficiary, mint, mint v1, sender, and token program must be valid. pub fn process_upgrade<'a, 'info>( _program_id: &Pubkey, accounts: &'a [AccountInfo<'info>],