From 2b9c917bf4673ab31c7cca1dc60ab2e4572d33f4 Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Fri, 6 Jun 2025 07:51:29 -0700 Subject: [PATCH] remove staking --- README.md | 12 +---------- api/src/instruction.rs | 29 +------------------------ api/src/state/mod.rs | 12 +---------- api/src/state/receipt.rs | 18 ---------------- program/src/close.rs | 4 ++-- program/src/deposit.rs | 39 ---------------------------------- program/src/free.rs | 31 --------------------------- program/src/lib.rs | 14 ------------ program/src/swap.rs | 4 +--- program/src/withdraw.rs | 46 ---------------------------------------- 10 files changed, 6 insertions(+), 203 deletions(-) delete mode 100644 api/src/state/receipt.rs delete mode 100644 program/src/deposit.rs delete mode 100644 program/src/free.rs delete mode 100644 program/src/withdraw.rs diff --git a/README.md b/README.md index f94cda5..e6f893c 100644 --- a/README.md +++ b/README.md @@ -10,26 +10,16 @@ ## Instructions -#### Mine - [`Open`](program/src/open.rs) - Opens a new block for mining. - [`Close`](program/src/close.rs) - Closes a block and pays out rewards. - [`Mine`](program/src/mine.rs) - Mines the current block by computing hashes. - -#### Stake -- [`Deposit`](program/src/deposit.rs) - Deposits stake into a miner account. -- [`Withdraw`](program/src/withdraw.rs) - Withdraws stake from a miner account. -- [`Free`](program/src/free.rs) - Frees up miner capacity after block ends. - -#### Trade -- [`Buy`](program/src/buy.rs) - Buys hash tokens from the market. -- [`Sell`](program/src/sell.rs) - Sells hash tokens to the market. +- [`Swap`](program/src/swap.rs) - Trade in a hashpower market. ## State - [`Block`](api/src/state/block.rs) - A period of time for mining. - [`Config`](api/src/state/config.rs) - Global program configuration. - [`Market`](api/src/state/market.rs) - Hashpower market for a given block. - [`Miner`](api/src/state/miner.rs) - A user's mining and staking state. -- [`Receipt`](api/src/state/receipt.rs) - Tracks a miner's deployed capital. - [`Treasury`](api/src/state/treasury.rs) - The mint authority on the ORE token. diff --git a/api/src/instruction.rs b/api/src/instruction.rs index 1e3528d..000718e 100644 --- a/api/src/instruction.rs +++ b/api/src/instruction.rs @@ -3,18 +3,10 @@ use steel::*; #[repr(u8)] #[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)] pub enum OreInstruction { - // Mine Open = 0, Close = 1, Mine = 2, - - // Stake - Deposit = 3, - Withdraw = 4, - - // Trade - Free = 5, - Swap = 6, + Swap = 3, } #[repr(C)] @@ -33,22 +25,6 @@ pub struct Mine { pub amount: [u8; 8], } -#[repr(C)] -#[derive(Clone, Copy, Debug, Pod, Zeroable)] -pub struct Deposit { - pub amount: [u8; 8], -} - -#[repr(C)] -#[derive(Clone, Copy, Debug, Pod, Zeroable)] -pub struct Withdraw { - pub amount: [u8; 8], -} - -#[repr(C)] -#[derive(Clone, Copy, Debug, Pod, Zeroable)] -pub struct Free {} - #[repr(C)] #[derive(Clone, Copy, Debug, Pod, Zeroable)] pub struct Swap { @@ -60,7 +36,4 @@ pub struct Swap { instruction!(OreInstruction, Open); instruction!(OreInstruction, Close); instruction!(OreInstruction, Mine); -instruction!(OreInstruction, Deposit); -instruction!(OreInstruction, Withdraw); -instruction!(OreInstruction, Free); instruction!(OreInstruction, Swap); diff --git a/api/src/state/mod.rs b/api/src/state/mod.rs index 28c9ec9..69e03d6 100644 --- a/api/src/state/mod.rs +++ b/api/src/state/mod.rs @@ -2,14 +2,12 @@ mod block; mod config; mod market; mod miner; -mod receipt; mod treasury; pub use block::*; pub use config::*; pub use market::*; pub use miner::*; -pub use receipt::*; pub use treasury::*; use crate::consts::*; @@ -23,8 +21,7 @@ pub enum OreAccount { Config = 101, Market = 102, Miner = 103, - Receipt = 104, - Treasury = 105, + Treasury = 104, } pub fn block_pda(id: u64) -> (Pubkey, u8) { @@ -43,13 +40,6 @@ pub fn miner_pda(authority: Pubkey) -> (Pubkey, u8) { Pubkey::find_program_address(&[MINER, &authority.to_bytes()], &crate::ID) } -pub fn receipt_pda(authority: Pubkey, id: u64) -> (Pubkey, u8) { - Pubkey::find_program_address( - &[RECEIPT, &authority.to_bytes(), &id.to_le_bytes()], - &crate::ID, - ) -} - pub fn treasury_pda() -> (Pubkey, u8) { Pubkey::find_program_address(&[TREASURY], &crate::ID) } diff --git a/api/src/state/receipt.rs b/api/src/state/receipt.rs deleted file mode 100644 index 7095ba6..0000000 --- a/api/src/state/receipt.rs +++ /dev/null @@ -1,18 +0,0 @@ -use steel::*; - -use super::OreAccount; - -#[repr(C)] -#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)] -pub struct Receipt { - /// The authority of this receipt account. - pub authority: Pubkey, - - /// The amount of ORE this miner has deployed in the hashpower market corresponding to the block id. - pub amount: u64, - - /// The id of the block this receipt is associated with. - pub block_id: u64, -} - -account!(OreAccount, Receipt); diff --git a/program/src/close.rs b/program/src/close.rs index f6f64d6..d10dfd9 100644 --- a/program/src/close.rs +++ b/program/src/close.rs @@ -21,8 +21,8 @@ pub fn process_close(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul market_hash_info.as_associated_token_account(market_info.key, mint_hash_info.key)?; let market_ore = market_ore_info.as_associated_token_account(market_info.key, mint_ore_info.key)?; - mint_hash_info.has_address(&market.base.mint)?.as_mint(); - mint_ore_info.has_address(&market.quote.mint)?.as_mint(); + mint_hash_info.has_address(&market.base.mint)?.as_mint()?; + mint_ore_info.has_address(&market.quote.mint)?.as_mint()?; system_program.is_program(&system_program::ID)?; token_program.is_program(&spl_token::ID)?; diff --git a/program/src/deposit.rs b/program/src/deposit.rs deleted file mode 100644 index 76cf0fc..0000000 --- a/program/src/deposit.rs +++ /dev/null @@ -1,39 +0,0 @@ -use ore_api::prelude::*; -use steel::*; - -/// Deposits stake. -pub fn process_deposit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult { - // Parse data. - let args = Deposit::try_from_bytes(data)?; - let amount = u64::from_le_bytes(args.amount); - - // Load accounts. - let [signer_info, miner_info, sender_info, treasury_info, treasury_tokens_info, token_program] = - accounts - else { - return Err(ProgramError::NotEnoughAccountKeys); - }; - signer_info.is_signer()?; - let miner = miner_info - .as_account_mut::(&ore_api::ID)? - .assert_mut(|m| m.authority == *signer_info.key)?; - sender_info.as_associated_token_account(&signer_info.key, &MINT_ADDRESS)?; - let treasury = treasury_info.as_account_mut::(&ore_api::ID)?; - treasury_tokens_info.as_associated_token_account(&treasury_info.key, &MINT_ADDRESS)?; - token_program.is_program(&spl_token::ID)?; - - // Update account state. - miner.stake += amount; - treasury.total_stake += amount; - - // Execute transfer. - transfer( - signer_info, - sender_info, - treasury_tokens_info, - token_program, - amount, - )?; - - Ok(()) -} diff --git a/program/src/free.rs b/program/src/free.rs deleted file mode 100644 index f19e026..0000000 --- a/program/src/free.rs +++ /dev/null @@ -1,31 +0,0 @@ -use ore_api::prelude::*; -use steel::*; - -/// Free up capacity. -pub fn process_free(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult { - // Load accounts. - let clock = Clock::get()?; - let [signer_info, miner_info, receipt_info] = accounts else { - return Err(ProgramError::NotEnoughAccountKeys); - }; - signer_info.is_signer()?; - let miner = miner_info - .as_account_mut::(&ore_api::ID)? - .assert_mut(|m| m.authority == *signer_info.key)?; - let receipt = receipt_info - .as_account_mut::(&ore_api::ID)? - .assert_mut(|r| r.authority == *signer_info.key)?; - - // Asset that block has ended. - let start_slot = 1500 * receipt.block_id; - let end_slot = start_slot + 1500; - assert!(clock.slot >= end_slot, "Block has not yet closed."); - - // Free up miner capacity. - miner.deployed -= receipt.amount; - - // Close the receipt. - receipt_info.close(signer_info)?; - - Ok(()) -} diff --git a/program/src/lib.rs b/program/src/lib.rs index b1ebbb9..bf709ea 100644 --- a/program/src/lib.rs +++ b/program/src/lib.rs @@ -1,18 +1,12 @@ mod close; -mod deposit; -mod free; mod mine; mod open; mod swap; -mod withdraw; use close::*; -use deposit::*; -use free::*; use mine::*; use open::*; use swap::*; -use withdraw::*; use ore_api::instruction::*; use steel::*; @@ -25,17 +19,9 @@ pub fn process_instruction( let (ix, data) = parse_instruction(&ore_api::ID, program_id, data)?; match ix { - // Mine OreInstruction::Open => process_open(accounts, data)?, OreInstruction::Close => process_close(accounts, data)?, OreInstruction::Mine => process_mine(accounts, data)?, - - // Stake - OreInstruction::Deposit => process_deposit(accounts, data)?, - OreInstruction::Withdraw => process_withdraw(accounts, data)?, - - // Trade - OreInstruction::Free => process_free(accounts, data)?, OreInstruction::Swap => process_swap(accounts, data)?, } diff --git a/program/src/swap.rs b/program/src/swap.rs index 6a59d3b..5cfc754 100644 --- a/program/src/swap.rs +++ b/program/src/swap.rs @@ -11,7 +11,7 @@ pub fn process_swap(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult // Load accounts. let clock = Clock::get()?; - let [signer_info, block_info, market_info, miner_info, mint_base_info, mint_quote_info, receipt_info, tokens_base_info, tokens_quote_info, vault_base_info, vault_quote_info, system_program, token_program] = + let [signer_info, block_info, market_info, miner_info, mint_base_info, mint_quote_info, tokens_base_info, tokens_quote_info, vault_base_info, vault_quote_info, system_program, token_program] = accounts else { return Err(ProgramError::NotEnoughAccountKeys); @@ -51,8 +51,6 @@ pub fn process_swap(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult system_program.is_program(&system_program::ID)?; token_program.is_program(&spl_token::ID)?; - // TODO Buy hash tokens - // Update market state. let swap_result = market.swap(amount, direction, precision, clock)?; swap_result.log_return(); diff --git a/program/src/withdraw.rs b/program/src/withdraw.rs deleted file mode 100644 index d4215f0..0000000 --- a/program/src/withdraw.rs +++ /dev/null @@ -1,46 +0,0 @@ -use ore_api::prelude::*; -use steel::*; - -/// Withdraws stake. -pub fn process_withdraw(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult { - // Parse data. - let args = Withdraw::try_from_bytes(data)?; - let amount = u64::from_le_bytes(args.amount); - - // Load accounts. - let [signer_info, miner_info, recipient_info, treasury_info, treasury_tokens_info, token_program] = - accounts - else { - return Err(ProgramError::NotEnoughAccountKeys); - }; - signer_info.is_signer()?; - let miner = miner_info - .as_account_mut::(&ore_api::ID)? - .assert_mut(|m| m.authority == *signer_info.key)?; - recipient_info.as_associated_token_account(&signer_info.key, &MINT_ADDRESS)?; - let treasury = treasury_info.as_account_mut::(&ore_api::ID)?; - treasury_tokens_info.as_associated_token_account(&treasury_info.key, &MINT_ADDRESS)?; - token_program.is_program(&spl_token::ID)?; - - // Update account state. - miner.stake -= amount; - treasury.total_stake -= amount; - - // Asset miner has enough stake to cover the withdrawal. - assert!( - miner.stake >= miner.deployed, - "Withdrawal cannot reduce capacity below deployment levels." - ); - - // Execute transfer. - transfer_signed( - signer_info, - treasury_tokens_info, - recipient_info, - token_program, - amount, - &[TREASURY], - )?; - - Ok(()) -}