mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-13 15:09:57 +00:00
close
This commit is contained in:
@@ -34,7 +34,7 @@ pub fn process_checkpoint(accounts: &[AccountInfo<'_>], _data: &[u8]) -> Program
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
|
||||
// Ensure round is not expired.
|
||||
if clock.unix_timestamp >= round.expires_at {
|
||||
if clock.slot >= round.expires_at {
|
||||
// In this case, the miner forfeits any potential rewards and their checkpoint is recorded.
|
||||
miner.checkpoint_id = round.id;
|
||||
return Ok(());
|
||||
@@ -42,13 +42,14 @@ pub fn process_checkpoint(accounts: &[AccountInfo<'_>], _data: &[u8]) -> Program
|
||||
|
||||
// Calculate bot fee permissions.
|
||||
let mut bot_fee = 0;
|
||||
if clock.unix_timestamp > round.expires_at - ONE_DAY {
|
||||
// We are in the last day before the round expires.
|
||||
// Anyone is allowed to checkpoint and may collect the bot fee.
|
||||
if clock.slot >= round.expires_at - ONE_DAY_SLOTS {
|
||||
// The round expires in less than 24h.
|
||||
// Anyone is allowed to checkpoint this account and may collect the bot fee.
|
||||
bot_fee = miner.checkpoint_fee;
|
||||
miner.checkpoint_fee = 0;
|
||||
} else {
|
||||
// There is still time before the round expires. Bots may not yet checkpoint this account.
|
||||
// There is still time remaining before the round expires.
|
||||
// Bots may not yet checkpoint this account.
|
||||
automation_info.has_seeds(&[AUTOMATION, &miner.authority.to_bytes()], &ore_api::ID)?;
|
||||
if !automation_info.data_is_empty() {
|
||||
let automation = automation_info
|
||||
|
||||
23
program/src/close.rs
Normal file
23
program/src/close.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
use ore_api::prelude::*;
|
||||
use steel::*;
|
||||
|
||||
/// Closes a round accound, and returns the rent to the rent payer.
|
||||
pub fn process_close(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
|
||||
// Load accounts.
|
||||
let clock = Clock::get()?;
|
||||
let [signer_info, rent_payer_info, round_info, system_program] = accounts else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
};
|
||||
signer_info.is_signer()?;
|
||||
rent_payer_info.is_writable()?;
|
||||
round_info
|
||||
.as_account_mut::<Round>(&ore_api::ID)?
|
||||
.assert_mut(|r| r.expires_at >= clock.slot)? // Ensure round has ended.
|
||||
.assert_mut(|r| r.rent_payer == *rent_payer_info.key)?; // Ensure the rent payer is the correct one.
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
|
||||
// Close the account.
|
||||
round_info.close(rent_payer_info)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -11,7 +11,7 @@ pub fn process_deploy(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul
|
||||
|
||||
// Load accounts.
|
||||
let clock = Clock::get()?;
|
||||
let [signer_info, authority_info, automation_info, board_info, miner_info, round_info, round_prev_info, system_program] =
|
||||
let [signer_info, authority_info, automation_info, board_info, miner_info, round_info, system_program] =
|
||||
accounts
|
||||
else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
|
||||
@@ -6,6 +6,7 @@ mod claim_ore;
|
||||
mod claim_seeker;
|
||||
mod claim_sol;
|
||||
mod claim_yield;
|
||||
mod close;
|
||||
mod deploy;
|
||||
mod deposit;
|
||||
// mod initialize;
|
||||
@@ -25,6 +26,7 @@ use claim_ore::*;
|
||||
use claim_seeker::*;
|
||||
use claim_sol::*;
|
||||
use claim_yield::*;
|
||||
use close::*;
|
||||
use deploy::*;
|
||||
use deposit::*;
|
||||
// use initialize::*;
|
||||
@@ -55,6 +57,7 @@ pub fn process_instruction(
|
||||
OreInstruction::ClaimORE => process_claim_ore(accounts, data)?,
|
||||
OreInstruction::Deploy => process_deploy(accounts, data)?,
|
||||
OreInstruction::Log => process_log(accounts, data)?,
|
||||
OreInstruction::Close => process_close(accounts, data)?,
|
||||
// OreInstruction::Initialize => process_initialize(accounts, data)?,
|
||||
OreInstruction::Reset => process_reset(accounts, data)?,
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use ore_api::prelude::*;
|
||||
use solana_program::{log::sol_log, slot_hashes::SlotHashes};
|
||||
use solana_program::slot_hashes::SlotHashes;
|
||||
use steel::*;
|
||||
|
||||
/// Pays out the winners and block reward.
|
||||
@@ -14,7 +14,7 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
|
||||
signer_info.is_signer()?;
|
||||
let board = board_info
|
||||
.as_account_mut::<Board>(&ore_api::ID)?
|
||||
.assert_mut(|b| clock.slot > b.end_slot)?;
|
||||
.assert_mut(|b| clock.slot >= b.end_slot + INTERMISSION_SLOTS)?;
|
||||
let config = config_info.as_account::<Config>(&ore_api::ID)?;
|
||||
fee_collector_info
|
||||
.is_writable()?
|
||||
@@ -160,8 +160,8 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
|
||||
start_slot: board.start_slot,
|
||||
end_slot: board.end_slot,
|
||||
winning_square: winning_square as u64,
|
||||
top_miner: Pubkey::default(), // board.top_miner,
|
||||
num_winners: 0, // square.count[winning_square],
|
||||
top_miner: Pubkey::default(), // Unknown
|
||||
num_winners: 0, // Unknown
|
||||
total_deployed: round.total_deployed,
|
||||
total_vaulted: round.total_vaulted,
|
||||
total_winnings: round.total_winnings,
|
||||
@@ -171,6 +171,32 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
|
||||
.to_bytes(),
|
||||
)?;
|
||||
|
||||
// Reset board.
|
||||
board.round_id += 1;
|
||||
board.start_slot = clock.slot + 1;
|
||||
board.end_slot = board.start_slot + 150;
|
||||
|
||||
// Open next round account.
|
||||
create_program_account::<Round>(
|
||||
round_next_info,
|
||||
ore_program,
|
||||
signer_info,
|
||||
&ore_api::ID,
|
||||
&[ROUND, &(board.round_id + 1).to_le_bytes()],
|
||||
)?;
|
||||
let round_next = round_next_info.as_account_mut::<Round>(&ore_api::ID)?;
|
||||
round_next.id = board.round_id + 1;
|
||||
round_next.deployed = [0; 25];
|
||||
round_next.slot_hash = [0; 32];
|
||||
round_next.expires_at = board.end_slot + ONE_WEEK_SLOTS;
|
||||
round_next.rent_payer = *signer_info.key;
|
||||
round_next.motherlode = 0;
|
||||
round_next.top_miner = Pubkey::default();
|
||||
round_next.top_miner_reward = round.top_miner_reward;
|
||||
round_next.total_deployed = 0;
|
||||
round_next.total_vaulted = 0;
|
||||
round_next.total_winnings = 0;
|
||||
|
||||
// Do SOL transfers.
|
||||
round_info.send(total_admin_fee, &fee_collector_info);
|
||||
round_info.send(vault_amount, &treasury_info);
|
||||
|
||||
Reference in New Issue
Block a user