This commit is contained in:
Hardhat Chad
2025-09-20 11:49:03 -07:00
parent 5d7c31d324
commit 44c87aa89c
11 changed files with 79 additions and 79 deletions

View File

@@ -3,17 +3,11 @@ use steel::*;
#[derive(Debug, Error, Clone, Copy, PartialEq, Eq, IntoPrimitive)]
#[repr(u32)]
pub enum OreError {
#[error("Placeholder error")]
Dummy = 0,
#[error("Amount too small")]
AmountTooSmall = 0,
#[error("Insufficient vault reserves")]
InsufficientVaultReserves = 1,
#[error("Invariant violation")]
InvariantViolation = 2,
#[error("Insufficient liquidity")]
InsufficientLiquidity = 3,
#[error("Not authorized")]
NotAuthorized = 1,
}
error!(OreError);

View File

@@ -7,9 +7,9 @@ pub enum OreInstruction {
Boost = 0,
ClaimSOL = 1,
ClaimORE = 2,
Initialize = 3,
Log = 4,
Prospect = 5,
Deploy = 3,
Initialize = 4,
Log = 5,
Redeem = 6,
Reset = 7,
@@ -37,6 +37,13 @@ pub struct ClaimORE {
pub amount: [u8; 8],
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Deploy {
pub amount: [u8; 8],
pub square_id: [u8; 8],
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Initialize {}
@@ -55,12 +62,6 @@ pub struct Redeem {
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Reset {}
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Prospect {
pub amount: [u8; 8],
pub square_id: [u8; 8],
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Mine {
@@ -119,9 +120,9 @@ pub struct ClaimSeeker {}
instruction!(OreInstruction, Boost);
instruction!(OreInstruction, ClaimSOL);
instruction!(OreInstruction, ClaimORE);
instruction!(OreInstruction, Deploy);
instruction!(OreInstruction, Initialize);
instruction!(OreInstruction, Log);
instruction!(OreInstruction, Prospect);
instruction!(OreInstruction, Redeem);
instruction!(OreInstruction, Reset);
instruction!(OreInstruction, SetAdmin);

View File

@@ -111,6 +111,32 @@ pub fn claim_ore(signer: Pubkey, amount: u64) -> Instruction {
}
}
// let [signer_info, board_info, config_info, fee_collector_info, miner_info, sender_info, square_info, system_program] =
pub fn deploy(signer: Pubkey, fee_collector: Pubkey, amount: u64, square_id: u64) -> Instruction {
let board_address = board_pda().0;
let config_address = config_pda().0;
let miner_address = miner_pda(signer).0;
let square_address = square_pda().0;
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(board_address, false),
AccountMeta::new(config_address, false),
AccountMeta::new(fee_collector, false),
AccountMeta::new(miner_address, false),
AccountMeta::new(square_address, false),
AccountMeta::new_readonly(system_program::ID, false),
],
data: Deploy {
amount: amount.to_le_bytes(),
square_id: square_id.to_le_bytes(),
}
.to_bytes(),
}
}
pub fn redeem(signer: Pubkey, amount: u64) -> Instruction {
let mint_address = MINT_ADDRESS;
let sender_address = get_associated_token_address(&signer, &MINT_ADDRESS);
@@ -166,32 +192,6 @@ pub fn reset(signer: Pubkey, miners: Vec<Pubkey>) -> Instruction {
}
}
// let [signer_info, board_info, config_info, fee_collector_info, miner_info, sender_info, square_info, system_program] =
pub fn prospect(signer: Pubkey, fee_collector: Pubkey, amount: u64, square_id: u64) -> Instruction {
let board_address = board_pda().0;
let config_address = config_pda().0;
let miner_address = miner_pda(signer).0;
let square_address = square_pda().0;
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(board_address, false),
AccountMeta::new(config_address, false),
AccountMeta::new(fee_collector, false),
AccountMeta::new(miner_address, false),
AccountMeta::new(square_address, false),
AccountMeta::new_readonly(system_program::ID, false),
],
data: Prospect {
amount: amount.to_le_bytes(),
square_id: square_id.to_le_bytes(),
}
.to_bytes(),
}
}
pub fn set_admin(signer: Pubkey, admin: Pubkey) -> Instruction {
let config_address = config_pda().0;
Instruction {

View File

@@ -13,8 +13,8 @@ pub struct Config {
// The last boost timestamp.
pub last_boost: i64,
// The minimum amount of SOL that can be prospect.
pub min_prospect_amount: u64,
// The minimum amount of SOL that can be deploy.
pub min_deploy_amount: u64,
// The address that receives fees.
pub fee_collector: Pubkey,

View File

@@ -64,11 +64,11 @@ async fn main() {
"miner" => {
log_miner(&rpc, &payer).await.unwrap();
}
"prospect" => {
prospect(&rpc, &payer).await.unwrap();
"deploy" => {
deploy(&rpc, &payer).await.unwrap();
}
"prospect_some" => {
prospect_some(&rpc, &payer).await.unwrap();
"deploy_some" => {
deploy_some(&rpc, &payer).await.unwrap();
}
"square" => {
log_square(&rpc).await.unwrap();
@@ -193,7 +193,7 @@ async fn reset(
Ok(())
}
async fn prospect(
async fn deploy(
rpc: &RpcClient,
payer: &solana_sdk::signer::keypair::Keypair,
) -> Result<(), anyhow::Error> {
@@ -202,12 +202,12 @@ async fn prospect(
let square_id = std::env::var("SQUARE").expect("Missing SQUARE env var");
let square_id = u64::from_str(&square_id).expect("Invalid SQUARE");
let config = get_config(rpc).await?;
let ix = ore_api::sdk::prospect(payer.pubkey(), config.fee_collector, amount, square_id);
let ix = ore_api::sdk::deploy(payer.pubkey(), config.fee_collector, amount, square_id);
submit_transaction(rpc, payer, &[ix]).await?;
Ok(())
}
async fn prospect_some(
async fn deploy_some(
rpc: &RpcClient,
payer: &solana_sdk::signer::keypair::Keypair,
) -> Result<(), anyhow::Error> {
@@ -216,7 +216,7 @@ async fn prospect_some(
let config = get_config(rpc).await?;
let mut ixs = vec![];
for i in 0..8 {
let ix = ore_api::sdk::prospect(payer.pubkey(), config.fee_collector, amount, i as u64);
let ix = ore_api::sdk::deploy(payer.pubkey(), config.fee_collector, amount, i as u64);
ixs.push(ix);
}
submit_transaction(rpc, payer, &ixs).await?;
@@ -309,7 +309,7 @@ async fn log_config(rpc: &RpcClient) -> Result<(), anyhow::Error> {
println!("Config");
println!(" admin: {}", config.admin);
println!(" last_boost: {}", config.last_boost);
println!(" min_prospect_amount: {}", config.min_prospect_amount);
println!(" min_deploy_amount: {}", config.min_deploy_amount);
println!(" fee_collector: {}", config.fee_collector);
Ok(())
}

View File

@@ -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.

View File

@@ -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

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.

View File

@@ -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"),