mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-13 23:16:52 +00:00
seeker
This commit is contained in:
@@ -100,6 +100,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.deployed = [0; 25];
|
||||
miner.is_seeker = 0;
|
||||
miner.refund_sol = 0;
|
||||
miner.rewards_sol = 0;
|
||||
miner.rewards_ore = 0;
|
||||
|
||||
@@ -7,6 +7,7 @@ mod claim_sol;
|
||||
mod deploy;
|
||||
mod initialize;
|
||||
mod log;
|
||||
mod migrate_miner;
|
||||
mod reset;
|
||||
mod set_admin;
|
||||
mod set_fee_collector;
|
||||
@@ -22,6 +23,7 @@ use claim_sol::*;
|
||||
use deploy::*;
|
||||
use initialize::*;
|
||||
use log::*;
|
||||
use migrate_miner::*;
|
||||
use reset::*;
|
||||
use set_admin::*;
|
||||
use set_fee_collector::*;
|
||||
@@ -56,6 +58,7 @@ pub fn process_instruction(
|
||||
|
||||
// Seeker
|
||||
OreInstruction::ClaimSeeker => process_claim_seeker(accounts, data)?,
|
||||
OreInstruction::MigrateMiner => process_migrate_miner(accounts, data)?,
|
||||
// _ => return Err(ProgramError::InvalidInstructionData),
|
||||
}
|
||||
|
||||
|
||||
28
program/src/migrate_miner.rs
Normal file
28
program/src/migrate_miner.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
use ore_api::prelude::*;
|
||||
use steel::*;
|
||||
|
||||
/// Sets the admin.
|
||||
pub fn process_migrate_miner(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
|
||||
// Load accounts.
|
||||
let [signer_info, config_info, miner_info, system_program] = accounts else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
};
|
||||
signer_info.is_signer()?;
|
||||
let miner = miner_info.as_account_mut::<Miner>(&ore_api::ID)?;
|
||||
let config = config_info
|
||||
.as_account_mut::<Config>(&ore_api::ID)?
|
||||
.assert_mut_err(
|
||||
|c| c.admin == *signer_info.key,
|
||||
OreError::NotAuthorized.into(),
|
||||
)?;
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
|
||||
// Set seeker activation flag.
|
||||
config.is_seeker_activation_enabled = 0;
|
||||
|
||||
// Set seeker flag.
|
||||
miner.is_seeker = 0;
|
||||
miner.buffer = [0; 24];
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -102,6 +102,8 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
|
||||
let motherlode_activated = is_motherlode_activated(r);
|
||||
|
||||
// Record miner rewards.
|
||||
let mut total_seeker_deployed = 0;
|
||||
let mut is_seeker = [false; 16];
|
||||
let mut miner_deployments = [0; 16];
|
||||
let mut rewards_sol = [0; 16];
|
||||
let mut checksum = 0;
|
||||
@@ -122,6 +124,12 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
|
||||
miner.lifetime_rewards_sol += rewards;
|
||||
rewards_sol[i] = rewards;
|
||||
miner_deployments[i] = miner_deployed;
|
||||
is_seeker[i] = miner.is_seeker == 1;
|
||||
|
||||
// Record Seeker deployed balance.
|
||||
if is_seeker[i] {
|
||||
total_seeker_deployed += miner_deployed;
|
||||
}
|
||||
|
||||
// Record ORE motherlode winnings.
|
||||
if motherlode_activated {
|
||||
@@ -175,6 +183,34 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
|
||||
treasury.motherlode = 0;
|
||||
}
|
||||
|
||||
// If activation is enabled, pay out 1 ORE to all Seeker miners, proportional to their deployment.
|
||||
let mint = mint_info.as_mint()?;
|
||||
let seeker_mint_amount = ONE_ORE.min(MAX_SUPPLY - mint.supply());
|
||||
if config.is_seeker_activation_enabled == 1
|
||||
&& total_seeker_deployed > 0
|
||||
&& seeker_mint_amount > 0
|
||||
{
|
||||
// Record Seeker rewards.
|
||||
for (i, is_seeker) in is_seeker.iter().enumerate() {
|
||||
if *is_seeker {
|
||||
let miner = miner_accounts[i].as_account_mut::<Miner>(&ore_api::ID)?;
|
||||
let reward = seeker_mint_amount * miner_deployments[i] / total_seeker_deployed;
|
||||
miner.rewards_ore += reward;
|
||||
miner.lifetime_rewards_ore += reward;
|
||||
}
|
||||
}
|
||||
|
||||
// Mint 1 ORE to Seeker miners.
|
||||
mint_to_signed(
|
||||
mint_info,
|
||||
treasury_tokens_info,
|
||||
treasury_info,
|
||||
token_program,
|
||||
seeker_mint_amount,
|
||||
&[TREASURY],
|
||||
)?;
|
||||
}
|
||||
|
||||
// Top up the motherlode rewards pool.
|
||||
let mint = mint_info.as_mint()?;
|
||||
let motherlode_mint_amount = (ONE_ORE / 5).min(MAX_SUPPLY - mint.supply());
|
||||
@@ -207,7 +243,7 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
|
||||
total_deployed: board.total_deployed,
|
||||
total_vaulted: board.total_vaulted,
|
||||
total_winnings: board.total_winnings,
|
||||
total_minted: mint_amount + motherlode_mint_amount,
|
||||
total_minted: mint_amount + motherlode_mint_amount + seeker_mint_amount,
|
||||
ts: clock.unix_timestamp,
|
||||
}
|
||||
.to_bytes(),
|
||||
|
||||
Reference in New Issue
Block a user