mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-15 07:26:45 +00:00
deploy
This commit is contained in:
@@ -3,10 +3,10 @@ use steel::*;
|
||||
|
||||
use crate::whitelist::AUTHORIZED_ACCOUNTS;
|
||||
|
||||
/// Claims a block reward.
|
||||
pub fn process_prospect(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult {
|
||||
/// Deploys capital to prospect on a square.
|
||||
pub fn process_deploy(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult {
|
||||
// Parse data.
|
||||
let args = Prospect::try_from_bytes(data)?;
|
||||
let args = Deploy::try_from_bytes(data)?;
|
||||
let amount = u64::from_le_bytes(args.amount);
|
||||
let square_id = usize::from_le_bytes(args.square_id);
|
||||
|
||||
@@ -34,12 +34,12 @@ pub fn process_prospect(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRes
|
||||
|
||||
// Check whitelist
|
||||
if !AUTHORIZED_ACCOUNTS.contains(&signer_info.key) {
|
||||
return Err(ProgramError::InvalidAccountData);
|
||||
return Err(OreError::NotAuthorized.into());
|
||||
}
|
||||
|
||||
// Check minimum amount.
|
||||
if amount < config.min_prospect_amount {
|
||||
return Err(ProgramError::InvalidAccountData);
|
||||
if amount < config.min_deploy_amount {
|
||||
return Err(OreError::AmountTooSmall.into());
|
||||
}
|
||||
|
||||
// Create miner.
|
||||
@@ -2,10 +2,9 @@ mod boost;
|
||||
mod claim_ore;
|
||||
mod claim_seeker;
|
||||
mod claim_sol;
|
||||
mod deploy;
|
||||
mod initialize;
|
||||
mod log;
|
||||
mod prospect;
|
||||
mod redeem;
|
||||
mod reset;
|
||||
mod set_admin;
|
||||
mod set_fee_collector;
|
||||
@@ -15,10 +14,9 @@ use boost::*;
|
||||
use claim_ore::*;
|
||||
use claim_seeker::*;
|
||||
use claim_sol::*;
|
||||
use deploy::*;
|
||||
use initialize::*;
|
||||
use log::*;
|
||||
use prospect::*;
|
||||
use redeem::*;
|
||||
use reset::*;
|
||||
use set_admin::*;
|
||||
use set_fee_collector::*;
|
||||
@@ -38,9 +36,9 @@ pub fn process_instruction(
|
||||
OreInstruction::Boost => process_boost(accounts, data)?,
|
||||
OreInstruction::ClaimSOL => process_claim_sol(accounts, data)?,
|
||||
OreInstruction::ClaimORE => process_claim_ore(accounts, data)?,
|
||||
OreInstruction::Deploy => process_deploy(accounts, data)?,
|
||||
OreInstruction::Log => process_log(accounts, data)?,
|
||||
OreInstruction::Initialize => process_initialize(accounts, data)?,
|
||||
OreInstruction::Prospect => process_prospect(accounts, data)?,
|
||||
OreInstruction::Reset => process_reset(accounts, data)?,
|
||||
|
||||
// Admin
|
||||
|
||||
@@ -143,22 +143,22 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
|
||||
// Update board.
|
||||
board.total_winnings = winnings;
|
||||
|
||||
// Update min prospect amount.
|
||||
// Update min deploy amount.
|
||||
let capacity: u64 = 16 * 25;
|
||||
let limit = capacity / 4;
|
||||
let threshold = capacity / 4;
|
||||
let mut availability = 0;
|
||||
for i in 0..25 {
|
||||
availability += 16 - square.count[i];
|
||||
}
|
||||
if availability == 0 {
|
||||
// If board is full, double the minimum prospect amount.
|
||||
config.min_prospect_amount *= 2;
|
||||
} else if availability < limit {
|
||||
// If board is more than 75% full, reduce minimum prospect amount linearly.
|
||||
// If board is full, double the minimum deploy amount.
|
||||
config.min_deploy_amount *= 2;
|
||||
} else if availability < threshold {
|
||||
// If board is more than 75% full, reduce minimum deploy amount linearly.
|
||||
let pct = (availability * 100) / capacity;
|
||||
let chg = (25u64.saturating_sub(pct) * 100) / 75;
|
||||
let dif = (config.min_prospect_amount * chg) / 100;
|
||||
config.min_prospect_amount = config.min_prospect_amount.saturating_sub(dif);
|
||||
let dif = (config.min_deploy_amount * chg) / 100;
|
||||
config.min_deploy_amount = config.min_deploy_amount.saturating_sub(dif);
|
||||
}
|
||||
|
||||
// Emit event.
|
||||
|
||||
@@ -14,7 +14,10 @@ pub fn process_set_admin(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRe
|
||||
signer_info.is_signer()?;
|
||||
let config = config_info
|
||||
.as_account_mut::<Config>(&ore_api::ID)?
|
||||
.assert_mut(|c| c.admin == *signer_info.key)?;
|
||||
.assert_mut_err(
|
||||
|c| c.admin == *signer_info.key,
|
||||
OreError::NotAuthorized.into(),
|
||||
)?;
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
|
||||
// Set admin.
|
||||
|
||||
@@ -14,7 +14,10 @@ pub fn process_set_fee_collector(accounts: &[AccountInfo<'_>], data: &[u8]) -> P
|
||||
signer_info.is_signer()?;
|
||||
let config = config_info
|
||||
.as_account_mut::<Config>(&ore_api::ID)?
|
||||
.assert_mut(|c| c.admin == *signer_info.key)?;
|
||||
.assert_mut_err(
|
||||
|c| c.admin == *signer_info.key,
|
||||
OreError::NotAuthorized.into(),
|
||||
)?;
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
|
||||
// Set fee collector.
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
use solana_program::pubkey;
|
||||
use steel::*;
|
||||
|
||||
pub const AUTHORIZED_ACCOUNTS: [Pubkey; 3] = [
|
||||
pub const AUTHORIZED_ACCOUNTS: [Pubkey; 4] = [
|
||||
pubkey!("pqspJ298ryBjazPAr95J9sULCVpZe3HbZTWkbC1zrkS"),
|
||||
pubkey!("6B9PjpHfbhPcSakS5UQ7ZctgbPujfsryVRpDecskGLiz"),
|
||||
pubkey!("HBUh9g46wk2X89CvaNN15UmsznP59rh6od1h8JwYAopk"),
|
||||
pubkey!("By5JFFueXCqeqLk5MzR8ZSwFxASz3SKWX2TVfT1LTFbX"),
|
||||
// pubkey!("By5JFFueXCqeqLk5MzR8ZSwFxASz3SKWX2TVfT1LTFbX"),
|
||||
// pubkey!("J89R2jNKbfkFoJjvkjnwwepvJRE2M8VPQ67RhPeQfVY8"),
|
||||
// pubkey!("6Qaf8uCcYWkWb12FZYUhuqkae3np2WiaZCv7ic4PMf72"),
|
||||
|
||||
Reference in New Issue
Block a user