diff --git a/api/src/sdk.rs b/api/src/sdk.rs index 2445e67..492d6b1 100644 --- a/api/src/sdk.rs +++ b/api/src/sdk.rs @@ -307,6 +307,28 @@ pub fn reset( data: Reset {}.to_bytes(), } } +// let [signer_info, automation_info, board_info, miner_info, round_info, treasury_info, system_program] = + +pub fn checkpoint(signer: Pubkey, authority: Pubkey, round_id: u64) -> Instruction { + let miner_address = miner_pda(authority).0; + let automation_address = automation_pda(authority).0; + let board_address = board_pda().0; + let round_address = round_pda(round_id).0; + let treasury_address = TREASURY_ADDRESS; + Instruction { + program_id: crate::ID, + accounts: vec![ + AccountMeta::new(signer, true), + AccountMeta::new(automation_address, false), + AccountMeta::new(board_address, false), + AccountMeta::new(miner_address, false), + AccountMeta::new(round_address, false), + AccountMeta::new(treasury_address, false), + AccountMeta::new_readonly(system_program::ID, false), + ], + data: Checkpoint {}.to_bytes(), + } +} pub fn set_admin(signer: Pubkey, admin: Pubkey) -> Instruction { let config_address = config_pda().0; diff --git a/api/src/state/miner.rs b/api/src/state/miner.rs index 60f5d53..95ff8c0 100644 --- a/api/src/state/miner.rs +++ b/api/src/state/miner.rs @@ -22,10 +22,6 @@ pub struct Miner { /// The last round that this miner checkpointed. pub checkpoint_id: u64, - /// The amount of SOL this miner has had refunded and may claim. - #[deprecated] - pub refund_sol: u64, - /// The amount of SOL this miner can claim. pub rewards_sol: u64, diff --git a/program/src/checkpoint.rs b/program/src/checkpoint.rs index 3c39666..44a7f50 100644 --- a/program/src/checkpoint.rs +++ b/program/src/checkpoint.rs @@ -13,13 +13,15 @@ pub fn process_checkpoint(accounts: &[AccountInfo<'_>], _data: &[u8]) -> Program }; signer_info.is_signer()?; let board = board_info.as_account::(&ore_api::ID)?; - let miner = miner_info - .as_account_mut::(&ore_api::ID)? - .assert_mut(|m| m.checkpoint_id < m.round_id)?; // Ensure miner has not already checkpointed this round. + let miner = miner_info.as_account_mut::(&ore_api::ID)?; + // If miner has already checkpointed this round, return. + if miner.checkpoint_id == miner.round_id { + return Ok(()); + } if round_info.data_is_empty() { // If round account is empty, ensure the correct account was provided. // This can happen if the miner attempted to checkpoint after the round expired and the account was closed. - // In this case, the miner forfeits any potential rewards and their checkpoint is recorded. + // In this case, the miner forfeits any potential rewards. round_info.has_seeds(&[ROUND, &miner.round_id.to_le_bytes()], &ore_api::ID)?; miner.checkpoint_id = miner.round_id; return Ok(()); @@ -33,7 +35,7 @@ pub fn process_checkpoint(accounts: &[AccountInfo<'_>], _data: &[u8]) -> Program // Ensure round is not expired. if clock.slot >= round.expires_at { - // In this case, the miner forfeits any potential rewards and their checkpoint is recorded. + // In this case, the miner forfeits any potential rewards. miner.checkpoint_id = miner.round_id; return Ok(()); } diff --git a/program/src/claim_sol.rs b/program/src/claim_sol.rs index 8345348..d8cced4 100644 --- a/program/src/claim_sol.rs +++ b/program/src/claim_sol.rs @@ -19,16 +19,12 @@ pub fn process_claim_sol(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRe system_program.is_program(&system_program::ID)?; // Normalize amount. - let total_claimable = miner.rewards_sol + miner.refund_sol; - let amount = total_claimable.min(amount); + let amount = miner.rewards_sol.min(amount); sol_log(&format!("Claiming {} SOL", lamports_to_sol(amount)).as_str()); - // Update miner. Deduct from refund first, then from rewards. - let from_refund = amount.min(miner.refund_sol); - miner.refund_sol -= from_refund; - let from_rewards = amount - from_refund; - miner.rewards_sol -= from_rewards; + // Update miner. + miner.rewards_sol -= amount; // Transfer reward to recipient. miner_info.send(amount, signer_info); diff --git a/program/src/deploy.rs b/program/src/deploy.rs index 77070e9..3d3a59e 100644 --- a/program/src/deploy.rs +++ b/program/src/deploy.rs @@ -92,7 +92,6 @@ pub fn process_deploy(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul miner.authority = *signer_info.key; miner.deployed = [0; 25]; miner.cumulative = [0; 25]; - miner.refund_sol = 0; miner.rewards_sol = 0; miner.rewards_ore = 0; miner.round_id = round.id; diff --git a/program/src/lib.rs b/program/src/lib.rs index 78fe999..459236d 100644 --- a/program/src/lib.rs +++ b/program/src/lib.rs @@ -9,6 +9,8 @@ mod claim_yield; mod close; mod deploy; mod deposit; +mod migrate_board; +mod migrate_miner; // mod initialize; mod log; mod reset; @@ -29,6 +31,8 @@ use claim_yield::*; use close::*; use deploy::*; use deposit::*; +use migrate_board::*; +use migrate_miner::*; // use initialize::*; use log::*; use reset::*; diff --git a/program/src/migrate_board.rs b/program/src/migrate_board.rs new file mode 100644 index 0000000..eb189ef --- /dev/null +++ b/program/src/migrate_board.rs @@ -0,0 +1,19 @@ +use ore_api::prelude::*; +use solana_program::slot_hashes::SlotHashes; +use steel::*; + +/// Pays out the winners and block reward. +pub fn process_migrate_board(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult { + // Load accounts. + let clock = Clock::get()?; + let [signer_info, board_info, system_program] = accounts else { + return Err(ProgramError::NotEnoughAccountKeys); + }; + signer_info.is_signer()?; + let board = board_info.as_account_mut::(&ore_api::ID)?; + system_program.is_program(&system_program::ID)?; + + // TODO Migrate miner account. + + Ok(()) +} diff --git a/program/src/migrate_miner.rs b/program/src/migrate_miner.rs new file mode 100644 index 0000000..e83189b --- /dev/null +++ b/program/src/migrate_miner.rs @@ -0,0 +1,20 @@ +use ore_api::prelude::*; +use solana_program::slot_hashes::SlotHashes; +use steel::*; + +/// Pays out the winners and block reward. +pub fn process_migrate_miner(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult { + // Load accounts. + let clock = Clock::get()?; + let [signer_info, miner_info, system_program] = accounts else { + return Err(ProgramError::NotEnoughAccountKeys); + }; + signer_info.is_signer()?; + let miner = miner_info.as_account_mut::(&ore_api::ID)?; + system_program.is_program(&system_program::ID)?; + + // TODO Migrate miner account. + // TODO Move refund_sol into rewards_sol. + + Ok(()) +}