mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-13 15:09:57 +00:00
deploy
This commit is contained in:
@@ -29,7 +29,7 @@ pub struct ResetEvent {
|
||||
pub num_winners: u64,
|
||||
|
||||
/// The total amount of SOL prospected in the round.
|
||||
pub total_prospects: u64,
|
||||
pub total_deployed: u64,
|
||||
|
||||
/// The total amount of SOL put in the ORE vault.
|
||||
pub total_vaulted: u64,
|
||||
|
||||
@@ -10,8 +10,8 @@ pub struct Board {
|
||||
/// The round number.
|
||||
pub id: u64,
|
||||
|
||||
/// The prospects for the round.
|
||||
pub prospects: [u64; 25],
|
||||
/// The deployed SOL for the round.
|
||||
pub deployed: [u64; 25],
|
||||
|
||||
/// The timestamp at which the block starts mining.
|
||||
pub start_at: i64,
|
||||
@@ -28,8 +28,8 @@ pub struct Board {
|
||||
/// The top miner of the round.
|
||||
pub top_miner: Pubkey,
|
||||
|
||||
/// The total amount of SOL prospected in the round.
|
||||
pub total_prospects: u64,
|
||||
/// The total amount of SOL deployed in the round.
|
||||
pub total_deployed: u64,
|
||||
|
||||
/// The total amount of SOL put in the ORE vault.
|
||||
pub total_vaulted: u64,
|
||||
|
||||
@@ -11,7 +11,7 @@ pub struct Miner {
|
||||
pub authority: Pubkey,
|
||||
|
||||
/// The miner's prospects in the current round.
|
||||
pub prospects: [u64; 25],
|
||||
pub deployed: [u64; 25],
|
||||
|
||||
/// The amount of SOL this miner can claim.
|
||||
pub rewards_sol: u64,
|
||||
|
||||
@@ -284,7 +284,7 @@ async fn log_miner(
|
||||
println!("Miner");
|
||||
println!(" address: {}", miner_address);
|
||||
println!(" authority: {}", authority);
|
||||
println!(" prospects: {:?}", miner.prospects);
|
||||
println!(" deployed: {:?}", miner.deployed);
|
||||
println!(" rewards_sol: {}", miner.rewards_sol);
|
||||
println!(" rewards_ore: {}", miner.rewards_ore);
|
||||
println!(" round_id: {}", miner.round_id);
|
||||
@@ -328,9 +328,9 @@ fn print_board(board: Board, clock: &Clock) {
|
||||
println!(" Slot hash: {:?}", board.slot_hash);
|
||||
println!(" Start slot: {}", board.start_slot);
|
||||
println!(" End slot: {}", board.end_slot);
|
||||
println!(" Prospects: {:?}", board.prospects);
|
||||
println!(" deployed: {:?}", board.deployed);
|
||||
println!(" Top miner: {:?}", board.top_miner);
|
||||
println!(" Total prospects: {}", board.total_prospects);
|
||||
println!(" Total deployed: {}", board.total_deployed);
|
||||
println!(" Total vaulted: {}", board.total_vaulted);
|
||||
println!(" Total winnings: {}", board.total_winnings);
|
||||
if board.slot_hash != [0; 32] {
|
||||
|
||||
@@ -53,7 +53,7 @@ pub fn process_deploy(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul
|
||||
)?;
|
||||
let miner = miner_info.as_account_mut::<Miner>(&ore_api::ID)?;
|
||||
miner.authority = *signer_info.key;
|
||||
miner.prospects = [0; 25];
|
||||
miner.deployed = [0; 25];
|
||||
miner.rewards_sol = 0;
|
||||
miner.rewards_ore = 0;
|
||||
miner.round_id = board.id;
|
||||
@@ -69,13 +69,13 @@ pub fn process_deploy(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul
|
||||
// Reset board.
|
||||
if board.slot_hash != [0; 32] {
|
||||
// Reset board
|
||||
board.prospects = [0; 25];
|
||||
board.deployed = [0; 25];
|
||||
board.id += 1;
|
||||
board.slot_hash = [0; 32];
|
||||
board.start_slot = clock.slot;
|
||||
board.end_slot = clock.slot + 150; // one minute
|
||||
board.top_miner = Pubkey::default();
|
||||
board.total_prospects = 0;
|
||||
board.total_deployed = 0;
|
||||
board.total_vaulted = 0;
|
||||
board.total_winnings = 0;
|
||||
|
||||
@@ -86,7 +86,7 @@ pub fn process_deploy(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul
|
||||
|
||||
// Reset miner
|
||||
if miner.round_id != board.id {
|
||||
miner.prospects = [0; 25];
|
||||
miner.deployed = [0; 25];
|
||||
miner.round_id = board.id;
|
||||
}
|
||||
|
||||
@@ -95,8 +95,8 @@ pub fn process_deploy(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul
|
||||
let amount = amount - fee;
|
||||
|
||||
// Update miner
|
||||
let is_first_move = miner.prospects[square_id] == 0;
|
||||
miner.prospects[square_id] += amount;
|
||||
let is_first_move = miner.deployed[square_id] == 0;
|
||||
miner.deployed[square_id] += amount;
|
||||
|
||||
// Update square
|
||||
if is_first_move {
|
||||
@@ -105,10 +105,10 @@ pub fn process_deploy(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul
|
||||
}
|
||||
|
||||
// Update board
|
||||
board.prospects[square_id] += amount;
|
||||
board.total_prospects += amount;
|
||||
board.deployed[square_id] += amount;
|
||||
board.total_deployed += amount;
|
||||
|
||||
// Transfer prospects.
|
||||
// Transfer deployed.
|
||||
board_info.collect(amount, &signer_info)?;
|
||||
fee_collector_info.collect(fee, &signer_info)?;
|
||||
|
||||
|
||||
@@ -29,14 +29,14 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], _data: &[u8]) -> Program
|
||||
&[BOARD],
|
||||
)?;
|
||||
let board = board_info.as_account_mut::<Board>(&ore_api::ID)?;
|
||||
board.prospects = [0; 25];
|
||||
board.deployed = [0; 25];
|
||||
board.id = 0;
|
||||
board.start_at = 0;
|
||||
board.start_slot = 0;
|
||||
board.end_slot = 0;
|
||||
board.slot_hash = [0; 32];
|
||||
board.top_miner = Pubkey::default();
|
||||
board.total_prospects = 0;
|
||||
board.total_deployed = 0;
|
||||
board.total_vaulted = 0;
|
||||
board.total_winnings = 0;
|
||||
} else {
|
||||
|
||||
@@ -32,7 +32,7 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
|
||||
if let Ok(slot_hash) = get_slot_hash(board.end_slot, slot_hashes_sysvar) {
|
||||
board.slot_hash = slot_hash;
|
||||
let winning_square = get_winning_square(&slot_hash);
|
||||
let square_prospects = board.prospects[winning_square];
|
||||
let square_prospects = board.deployed[winning_square];
|
||||
(winning_square, square_prospects)
|
||||
} else {
|
||||
// Cannot get slot hash. No one wins.
|
||||
@@ -40,11 +40,11 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
|
||||
(u64::MAX as usize, 0)
|
||||
};
|
||||
|
||||
// No one won. Vault all prospects.
|
||||
// No one won. Vault all deployed.
|
||||
if square_prospects == 0 {
|
||||
// Update board.
|
||||
board.total_vaulted = board.total_prospects;
|
||||
treasury.balance += board.total_prospects;
|
||||
board.total_vaulted = board.total_deployed;
|
||||
treasury.balance += board.total_deployed;
|
||||
|
||||
// Emit event.
|
||||
program_log(
|
||||
@@ -57,7 +57,7 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
|
||||
winning_square: winning_square as u64,
|
||||
top_miner: board.top_miner,
|
||||
num_winners: 0,
|
||||
total_prospects: board.total_prospects,
|
||||
total_deployed: board.total_deployed,
|
||||
total_vaulted: board.total_vaulted,
|
||||
total_winnings: board.total_winnings,
|
||||
total_minted: 0,
|
||||
@@ -67,16 +67,16 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
|
||||
)?;
|
||||
|
||||
// Do SOL transfers.
|
||||
board_info.send(board.total_prospects, &treasury_info);
|
||||
board_info.send(board.total_deployed, &treasury_info);
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Get winnings amount (prospects on all non-winning squares).
|
||||
// Get winnings amount (deployed on all non-winning squares).
|
||||
let mut winnings = 0;
|
||||
for (i, prospects) in board.prospects.iter().enumerate() {
|
||||
for (i, deployed) in board.deployed.iter().enumerate() {
|
||||
if i != winning_square {
|
||||
winnings += prospects;
|
||||
winnings += deployed;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
|
||||
let miner = miner_info
|
||||
.as_account_mut::<Miner>(&ore_api::ID)?
|
||||
.assert_mut(|m| m.round_id == board.id)?;
|
||||
let miner_prospects = miner.prospects[winning_square];
|
||||
let miner_prospects = miner.deployed[winning_square];
|
||||
let rewards = miner_prospects + (winnings * miner_prospects / square_prospects); // Winners get their own prospect back plus their share of the winnings.
|
||||
checksum += miner_prospects;
|
||||
miner.rewards_sol += rewards;
|
||||
@@ -172,7 +172,7 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
|
||||
winning_square: winning_square as u64,
|
||||
top_miner: board.top_miner,
|
||||
num_winners: square.count[winning_square],
|
||||
total_prospects: board.total_prospects,
|
||||
total_deployed: board.total_deployed,
|
||||
total_vaulted: board.total_vaulted,
|
||||
total_winnings: board.total_winnings,
|
||||
total_minted: mint_amount,
|
||||
|
||||
Reference in New Issue
Block a user