This commit is contained in:
Hardhat Chad
2025-09-25 12:36:20 -07:00
parent a9a2e87031
commit d7d3cb8463
6 changed files with 171 additions and 154 deletions

View File

@@ -13,8 +13,8 @@ pub fn process_deploy(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul
// Load accounts.
let clock = Clock::get()?;
let (required_accounts, miner_accounts) = accounts.split_at(9);
let [signer_info, authority_info, automation_info, board_info, config_info, fee_collector_info, miner_info, square_info, system_program] =
let (required_accounts, miner_accounts) = accounts.split_at(7);
let [signer_info, authority_info, automation_info, board_info, miner_info, square_info, system_program] =
required_accounts
else {
return Err(ProgramError::NotEnoughAccountKeys);
@@ -28,10 +28,6 @@ pub fn process_deploy(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul
(clock.slot >= b.start_slot && clock.slot < b.end_slot && b.slot_hash == [0; 32])
|| (clock.slot >= b.end_slot + INTERMISSION_SLOTS && b.slot_hash != [0; 32])
})?;
let config = config_info.as_account::<Config>(&ore_api::ID)?;
fee_collector_info
.has_address(&config.fee_collector)?
.is_writable()?;
miner_info.is_writable()?;
let square = square_info.as_account_mut::<Square>(&ore_api::ID)?;
system_program.is_program(&system_program::ID)?;
@@ -149,14 +145,9 @@ pub fn process_deploy(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul
miner.round_id = board.id;
}
// Normalize amount.
let fee = amount / 100;
let amount = amount - fee;
// Calculate all deployments.
let mut refund_amounts = [0; 25];
let mut refund_miner_infos = [None; 25];
let mut total_fee = 0;
let mut total_amount = 0;
'deploy: for (square_id, &should_deploy) in squares.iter().enumerate() {
// Skip if square index is out of bounds.
@@ -233,6 +224,14 @@ pub fn process_deploy(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul
square.deployed[square_id][idx] -= smallest_deployment;
square.miners[square_id][idx] = Pubkey::default();
square.count[square_id] -= 1;
sol_log(
&format!(
"Kicking miner {} from square {}. Refunding: {}",
smallest_miner.authority, square_id, smallest_deployment
)
.as_str(),
);
break 'refund;
}
}
@@ -245,6 +244,7 @@ pub fn process_deploy(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul
// Safety check.
// Skip if square count is still >= 16. This can only happen if the signer didn't provide a miner account to refund.
if square.count[square_id] >= 16 {
sol_log(&format!("Square {} is full. Skipping deployment.", square_id).as_str());
continue 'deploy;
}
@@ -264,23 +264,14 @@ pub fn process_deploy(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul
// Update square deployed
square.deployed[square_id][idx] += amount;
// Update total fee and amount
total_fee += fee;
// Update total amount
total_amount += amount;
}
// Transfer SOL refunds.
for (square_id, refund_amount) in refund_amounts.iter().enumerate() {
if let Some(refund_miner_info) = refund_miner_infos[square_id] {
board_info.send(*refund_amount, &refund_miner_info);
}
}
// Transfer SOL.
if let Some(automation) = automation {
automation.balance -= total_amount + total_fee + automation.fee;
automation.balance -= total_amount + automation.fee;
automation_info.send(total_amount, &board_info);
automation_info.send(total_fee, &fee_collector_info);
automation_info.send(automation.fee, &signer_info);
// Close automation if balance is 0.
@@ -289,7 +280,13 @@ pub fn process_deploy(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul
}
} else {
board_info.collect(total_amount, &signer_info)?;
fee_collector_info.collect(total_fee, &signer_info)?;
}
// Transfer SOL refunds.
for (square_id, refund_amount) in refund_amounts.iter().enumerate() {
if let Some(refund_miner_info) = refund_miner_infos[square_id] {
board_info.send(*refund_amount, &refund_miner_info);
}
}
Ok(())

View File

@@ -2,12 +2,12 @@ use ore_api::prelude::*;
use solana_program::slot_hashes::SlotHashes;
use steel::*;
/// Claims a block reward.
/// Pays out the winners and block reward.
pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
// Load accounts.
let clock = Clock::get()?;
let (required_accounts, miner_accounts) = accounts.split_at(11);
let [signer_info, board_info, config_info, mint_info, square_info, treasury_info, treasury_tokens_info, system_program, token_program, ore_program, slot_hashes_sysvar] =
let (required_accounts, miner_accounts) = accounts.split_at(12);
let [signer_info, board_info, config_info, fee_collector_info, mint_info, square_info, treasury_info, treasury_tokens_info, system_program, token_program, ore_program, slot_hashes_sysvar] =
required_accounts
else {
return Err(ProgramError::NotEnoughAccountKeys);
@@ -17,7 +17,10 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
.as_account_mut::<Board>(&ore_api::ID)?
.assert_mut(|b| b.slot_hash == [0; 32])?
.assert_mut(|b| clock.slot > b.end_slot)?;
config_info.as_account::<Config>(&ore_api::ID)?;
let config = config_info.as_account::<Config>(&ore_api::ID)?;
fee_collector_info
.is_writable()?
.has_address(&config.fee_collector)?;
let mint = mint_info.has_address(&MINT_ADDRESS)?.as_mint()?;
let square = square_info.as_account_mut::<Square>(&ore_api::ID)?;
let treasury = treasury_info.as_account_mut::<Treasury>(&ore_api::ID)?;
@@ -42,6 +45,9 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
(u64::MAX as usize, 0)
};
// Collect fees.
let fee = board.total_deployed / 100;
// No one won. Vault all deployed.
if square_deployed == 0 {
// Update board.
@@ -69,7 +75,8 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
)?;
// Do SOL transfers.
board_info.send(board.total_deployed, &treasury_info);
board_info.send(fee, &fee_collector_info);
board_info.send(board.total_deployed - fee, &treasury_info);
return Ok(());
}
@@ -77,7 +84,7 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
let mut winnings = 0;
for (i, deployed) in board.deployed.iter().enumerate() {
if i != winning_square {
winnings += deployed;
winnings += deployed - (deployed / 100);
}
}
@@ -87,6 +94,9 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
board.total_vaulted = vault_amount;
treasury.balance += vault_amount;
// Assert
assert!(board.total_deployed >= vault_amount + winnings + fee);
// Record miner rewards.
let mut miner_deployments = [0; 16];
let mut rewards_sol = [0; 16];
@@ -162,6 +172,7 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
)?;
// Do SOL transfers.
board_info.send(fee, &fee_collector_info);
board_info.send(vault_amount, &treasury_info);
for (i, miner_info) in miner_accounts.iter().enumerate() {
board_info.send(rewards_sol[i], &miner_info);

View File

@@ -1,8 +1,29 @@
use solana_program::pubkey;
use steel::*;
pub const AUTHORIZED_ACCOUNTS: [Pubkey; 1] = [
pub const AUTHORIZED_ACCOUNTS: [Pubkey; 21] = [
pubkey!("pqspJ298ryBjazPAr95J9sULCVpZe3HbZTWkbC1zrkS"),
// TESTERS
pubkey!("Dmy2fqxpkUocwvkALMDwfCRFeYfkdGqgB5PLfmZW5ASR"),
pubkey!("Az9Xia5f6EXU9MGHuuMCKyHMy3MfNnsoyTbh7HTuFw5G"),
pubkey!("5muLAbcjsAMcP8438KPfo2Jqw2vgAtuSDvMFNWb6Bexi"),
pubkey!("FRYaFLiE384yeqqjM9smbz17HrJAWGVmicmWYCEMAL16"),
pubkey!("9D3hfN4FJWVdCMZStAhJbx93m2WLYXVEbkwdehsjihSK"),
pubkey!("GNVEy8fcCwfDFHFXiKBrnmxDwQDFq9JfACgnjirWvzXa"),
pubkey!("7sBX4kPzB87tBw7xGsaLMyUjbPvoKRz2HA5kgxruUYfr"),
pubkey!("BeqD2wuermavKMivfRMw3eFaXpAosh5pCVotF89PLfZk"),
pubkey!("3xrxQD2DcxiTeBKQqu129aijrVt6iAJ9yiEAV83yd61a"),
pubkey!("GQA2EL4FJhFvKrQwLTUvq2kczS8t4MxpAzfbgroUX8oP"),
pubkey!("Ddh1CP9vA3kjizVsr2J18VetznQiaY3EjPs8uPLVDFSd"),
pubkey!("A21sYbqWbURRnUQEsVnyjEJq1hackmspp7RYaZFh4dw8"),
pubkey!("9fhLoSqzG9dfBja9mCHeYo4pG3jNyw47xqoZ9R3sihug"),
pubkey!("FuWRwcvKBs3EHq9eUNy3xUSYETwhoK4jCHq93rFRas1i"),
pubkey!("8N8xX3dX4QhYtsmkU1jH6qPhT46or8TU8gvk9sF7PKrA"),
pubkey!("Da6QdrpoSsZUffj7RBmVmnvP4HJZTBwcDv47YQErm45E"),
pubkey!("Fjyo6xK6KdfaejYdZnb46aEXxmKHgkb3JoAW41ydF6gA"),
pubkey!("EYuhVmfAG6WoKVkwnb1TEeXKek5J14YAkJn4VTEgu4ip"),
pubkey!("CJmSeXLA2LrX8qLehn1vaMHGj2pX3hXmnJstgU3uhNeM"),
pubkey!("34QyjRFFU2Vp7ZAxdNm3FRCChEMbStAh9Zf58W84q7Fh"),
// pubkey!("HNWhK5f8RMWBqcA7mXJPaxdTPGrha3rrqUrri7HSKb3T"),
// pubkey!("6B9PjpHfbhPcSakS5UQ7ZctgbPujfsryVRpDecskGLiz"),
// pubkey!("HBUh9g46wk2X89CvaNN15UmsznP59rh6od1h8JwYAopk"),