From fb285226fbd1fd9de7610a5e9b4f56578eea9c65 Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Tue, 10 Jun 2025 07:56:04 -0700 Subject: [PATCH] cleanup --- Cargo.toml | 5 +- README.md | 42 ++++++-- {ore/api => api}/Cargo.toml | 0 {ore/api => api}/src/consts.rs | 7 +- {ore/api => api}/src/error.rs | 0 {ore/api => api}/src/event.rs | 0 {ore/api => api}/src/instruction.rs | 0 {ore/api => api}/src/lib.rs | 0 {ore/api => api}/src/sdk.rs | 0 {ore/api => api}/src/state/block.rs | 0 {ore/api => api}/src/state/config.rs | 0 .../src/state/market/buy_exact_in.rs | 0 .../src/state/market/buy_exact_out.rs | 0 {ore/api => api}/src/state/market/curve.rs | 0 {ore/api => api}/src/state/market/fees.rs | 0 {ore/api => api}/src/state/market/market.rs | 0 {ore/api => api}/src/state/market/mod.rs | 0 .../src/state/market/sell_exact_in.rs | 0 .../src/state/market/sell_exact_out.rs | 0 {ore/api => api}/src/state/market/swap.rs | 0 {ore/api => api}/src/state/market/vaults.rs | 0 .../src/state/market/virtual_limit_order.rs | 0 {ore/api => api}/src/state/miner.rs | 0 {ore/api => api}/src/state/mod.rs | 0 {ore/api => api}/src/state/permit.rs | 0 {ore/api => api}/src/state/stake.rs | 0 {ore/api => api}/src/state/treasury.rs | 0 cli/Cargo.toml | 2 +- ore-delegate/README.md | 33 ------- ore-delegate/api/Cargo.toml | 21 ---- ore-delegate/api/src/consts.rs | 2 - ore-delegate/api/src/error.rs | 10 -- ore-delegate/api/src/event.rs | 1 - ore-delegate/api/src/instruction.rs | 37 ------- ore-delegate/api/src/lib.rs | 18 ---- ore-delegate/api/src/sdk.rs | 3 - ore-delegate/api/src/state/delegate.rs | 21 ---- ore-delegate/api/src/state/mod.rs | 20 ---- ore-delegate/program/Cargo.toml | 32 ------ ore-delegate/program/src/crank.rs | 52 ---------- ore-delegate/program/src/deposit.rs | 77 --------------- ore-delegate/program/src/lib.rs | 31 ------ ore-delegate/program/src/payout.rs | 99 ------------------- ore-delegate/program/src/withdraw.rs | 61 ------------ ore/README.md | 38 ------- {ore/program => program}/Cargo.toml | 0 {ore/program => program}/src/close.rs | 0 {ore/program => program}/src/commit.rs | 0 {ore/program => program}/src/decommit.rs | 0 {ore/program => program}/src/deposit.rs | 0 {ore/program => program}/src/lib.rs | 0 {ore/program => program}/src/mine.rs | 0 {ore/program => program}/src/open.rs | 2 +- {ore/program => program}/src/swap.rs | 0 {ore/program => program}/src/withdraw.rs | 0 55 files changed, 41 insertions(+), 573 deletions(-) rename {ore/api => api}/Cargo.toml (100%) rename {ore/api => api}/src/consts.rs (93%) rename {ore/api => api}/src/error.rs (100%) rename {ore/api => api}/src/event.rs (100%) rename {ore/api => api}/src/instruction.rs (100%) rename {ore/api => api}/src/lib.rs (100%) rename {ore/api => api}/src/sdk.rs (100%) rename {ore/api => api}/src/state/block.rs (100%) rename {ore/api => api}/src/state/config.rs (100%) rename {ore/api => api}/src/state/market/buy_exact_in.rs (100%) rename {ore/api => api}/src/state/market/buy_exact_out.rs (100%) rename {ore/api => api}/src/state/market/curve.rs (100%) rename {ore/api => api}/src/state/market/fees.rs (100%) rename {ore/api => api}/src/state/market/market.rs (100%) rename {ore/api => api}/src/state/market/mod.rs (100%) rename {ore/api => api}/src/state/market/sell_exact_in.rs (100%) rename {ore/api => api}/src/state/market/sell_exact_out.rs (100%) rename {ore/api => api}/src/state/market/swap.rs (100%) rename {ore/api => api}/src/state/market/vaults.rs (100%) rename {ore/api => api}/src/state/market/virtual_limit_order.rs (100%) rename {ore/api => api}/src/state/miner.rs (100%) rename {ore/api => api}/src/state/mod.rs (100%) rename {ore/api => api}/src/state/permit.rs (100%) rename {ore/api => api}/src/state/stake.rs (100%) rename {ore/api => api}/src/state/treasury.rs (100%) delete mode 100644 ore-delegate/README.md delete mode 100644 ore-delegate/api/Cargo.toml delete mode 100644 ore-delegate/api/src/consts.rs delete mode 100644 ore-delegate/api/src/error.rs delete mode 100644 ore-delegate/api/src/event.rs delete mode 100644 ore-delegate/api/src/instruction.rs delete mode 100644 ore-delegate/api/src/lib.rs delete mode 100644 ore-delegate/api/src/sdk.rs delete mode 100644 ore-delegate/api/src/state/delegate.rs delete mode 100644 ore-delegate/api/src/state/mod.rs delete mode 100644 ore-delegate/program/Cargo.toml delete mode 100644 ore-delegate/program/src/crank.rs delete mode 100644 ore-delegate/program/src/deposit.rs delete mode 100644 ore-delegate/program/src/lib.rs delete mode 100644 ore-delegate/program/src/payout.rs delete mode 100644 ore-delegate/program/src/withdraw.rs delete mode 100644 ore/README.md rename {ore/program => program}/Cargo.toml (100%) rename {ore/program => program}/src/close.rs (100%) rename {ore/program => program}/src/commit.rs (100%) rename {ore/program => program}/src/decommit.rs (100%) rename {ore/program => program}/src/deposit.rs (100%) rename {ore/program => program}/src/lib.rs (100%) rename {ore/program => program}/src/mine.rs (100%) rename {ore/program => program}/src/open.rs (99%) rename {ore/program => program}/src/swap.rs (100%) rename {ore/program => program}/src/withdraw.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index d94b336..f00581b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] resolver = "2" -members = ["ore/*", "cli"] +members = ["api", "program", "cli"] [workspace.package] version = "3.7.0" @@ -21,8 +21,7 @@ bytemuck_derive = "1.7.0" const-crypto = "0.1.0" mpl-token-metadata = "5.1" num_enum = "0.7.2" -ore-api = { path = "./ore/api" } -ore-delegate-api = { path = "./ore-delegate/api" } +ore-api = { path = "./api" } ore-boost-api = "4.0.0-alpha" solana-account-decoder = "^2.1" solana-nostd-keccak = "0.1.3" diff --git a/README.md b/README.md index 2bf4cac..c46aa61 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,40 @@ # ORE -**Mine blockspace. Trade hashpower. Win rewards.** +**Mine blockspace. Trade hashpower. Earn rewards.** -## Programs -- [`ore`](ore/) – ORE mining program. -- [`ore-delegate`](ore-delegate/) – Delegate mining to another party. +## API +- [`Consts`](api/src/consts.rs) – Program constants. +- [`Error`](api/src/error.rs) – Custom program errors. +- [`Event`](api/src/error.rs) – Custom program events. +- [`Instruction`](api/src/instruction.rs) – Declared instructions and arguments. + +## Instructions + +- [`Open`](program/src/open.rs) - Open a new block. +- [`Close`](program/src/close.rs) - Close a block and pay out the reward. +- [`Mine`](program/src/mine.rs) - Mine the current block. +- [`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) - Tracks a miner state and history. +- [`Permit`](api/src/state/permit.rs) - Tracks a miner's commitment to mine a block. +- [`Stake`](api/src/state/stake.rs) - Tracks a miner's collateral for trading in a market. +- [`Treasury`](api/src/state/treasury.rs) - The mint authority of the ORE token. -TODO -- [ ] Hash token metadata -- [ ] \ No newline at end of file +## Tests + +To run the test suite, use the Solana toolchain: + +``` +cargo test-sbf +``` + +For line coverage, use llvm-cov: + +``` +cargo llvm-cov +``` diff --git a/ore/api/Cargo.toml b/api/Cargo.toml similarity index 100% rename from ore/api/Cargo.toml rename to api/Cargo.toml diff --git a/ore/api/src/consts.rs b/api/src/consts.rs similarity index 93% rename from ore/api/src/consts.rs rename to api/src/consts.rs index c423d56..fa763e1 100644 --- a/ore/api/src/consts.rs +++ b/api/src/consts.rs @@ -67,11 +67,8 @@ pub const SLOT_WINDOW: u64 = 4; /// Amount of hash tokens to mint to market. pub const HASH_TOKEN_SUPPLY: u64 = 10_000_000; -/// The block reward. -// pub const BLOCK_REWARD: u64 = ONE_ORE * 10; - -/// The virtual ORE liquidity. -pub const VIRTUAL_ORE_LIQUIDITY: u64 = ONE_ORE * 5; +/// The virtual liquidity to seed the markets with (in ORE). +pub const VIRTUAL_LIQUIDITY: u64 = ONE_ORE * 5; /// The minimum difficulty required for payout. pub const MIN_DIFFICULTY: u64 = 10; diff --git a/ore/api/src/error.rs b/api/src/error.rs similarity index 100% rename from ore/api/src/error.rs rename to api/src/error.rs diff --git a/ore/api/src/event.rs b/api/src/event.rs similarity index 100% rename from ore/api/src/event.rs rename to api/src/event.rs diff --git a/ore/api/src/instruction.rs b/api/src/instruction.rs similarity index 100% rename from ore/api/src/instruction.rs rename to api/src/instruction.rs diff --git a/ore/api/src/lib.rs b/api/src/lib.rs similarity index 100% rename from ore/api/src/lib.rs rename to api/src/lib.rs diff --git a/ore/api/src/sdk.rs b/api/src/sdk.rs similarity index 100% rename from ore/api/src/sdk.rs rename to api/src/sdk.rs diff --git a/ore/api/src/state/block.rs b/api/src/state/block.rs similarity index 100% rename from ore/api/src/state/block.rs rename to api/src/state/block.rs diff --git a/ore/api/src/state/config.rs b/api/src/state/config.rs similarity index 100% rename from ore/api/src/state/config.rs rename to api/src/state/config.rs diff --git a/ore/api/src/state/market/buy_exact_in.rs b/api/src/state/market/buy_exact_in.rs similarity index 100% rename from ore/api/src/state/market/buy_exact_in.rs rename to api/src/state/market/buy_exact_in.rs diff --git a/ore/api/src/state/market/buy_exact_out.rs b/api/src/state/market/buy_exact_out.rs similarity index 100% rename from ore/api/src/state/market/buy_exact_out.rs rename to api/src/state/market/buy_exact_out.rs diff --git a/ore/api/src/state/market/curve.rs b/api/src/state/market/curve.rs similarity index 100% rename from ore/api/src/state/market/curve.rs rename to api/src/state/market/curve.rs diff --git a/ore/api/src/state/market/fees.rs b/api/src/state/market/fees.rs similarity index 100% rename from ore/api/src/state/market/fees.rs rename to api/src/state/market/fees.rs diff --git a/ore/api/src/state/market/market.rs b/api/src/state/market/market.rs similarity index 100% rename from ore/api/src/state/market/market.rs rename to api/src/state/market/market.rs diff --git a/ore/api/src/state/market/mod.rs b/api/src/state/market/mod.rs similarity index 100% rename from ore/api/src/state/market/mod.rs rename to api/src/state/market/mod.rs diff --git a/ore/api/src/state/market/sell_exact_in.rs b/api/src/state/market/sell_exact_in.rs similarity index 100% rename from ore/api/src/state/market/sell_exact_in.rs rename to api/src/state/market/sell_exact_in.rs diff --git a/ore/api/src/state/market/sell_exact_out.rs b/api/src/state/market/sell_exact_out.rs similarity index 100% rename from ore/api/src/state/market/sell_exact_out.rs rename to api/src/state/market/sell_exact_out.rs diff --git a/ore/api/src/state/market/swap.rs b/api/src/state/market/swap.rs similarity index 100% rename from ore/api/src/state/market/swap.rs rename to api/src/state/market/swap.rs diff --git a/ore/api/src/state/market/vaults.rs b/api/src/state/market/vaults.rs similarity index 100% rename from ore/api/src/state/market/vaults.rs rename to api/src/state/market/vaults.rs diff --git a/ore/api/src/state/market/virtual_limit_order.rs b/api/src/state/market/virtual_limit_order.rs similarity index 100% rename from ore/api/src/state/market/virtual_limit_order.rs rename to api/src/state/market/virtual_limit_order.rs diff --git a/ore/api/src/state/miner.rs b/api/src/state/miner.rs similarity index 100% rename from ore/api/src/state/miner.rs rename to api/src/state/miner.rs diff --git a/ore/api/src/state/mod.rs b/api/src/state/mod.rs similarity index 100% rename from ore/api/src/state/mod.rs rename to api/src/state/mod.rs diff --git a/ore/api/src/state/permit.rs b/api/src/state/permit.rs similarity index 100% rename from ore/api/src/state/permit.rs rename to api/src/state/permit.rs diff --git a/ore/api/src/state/stake.rs b/api/src/state/stake.rs similarity index 100% rename from ore/api/src/state/stake.rs rename to api/src/state/stake.rs diff --git a/ore/api/src/state/treasury.rs b/api/src/state/treasury.rs similarity index 100% rename from ore/api/src/state/treasury.rs rename to api/src/state/treasury.rs diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 1a189cd..285ab18 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -18,7 +18,7 @@ anyhow.workspace = true base64 = "0.22.1" bincode = "1.3.3" bytemuck.workspace = true -ore-api = { path = "../ore/api" } +ore-api = { path = "../api" } serde_json = "1.0.140" solana-account-decoder.workspace = true solana-client.workspace = true diff --git a/ore-delegate/README.md b/ore-delegate/README.md deleted file mode 100644 index 60493e5..0000000 --- a/ore-delegate/README.md +++ /dev/null @@ -1,33 +0,0 @@ -# ORE Delegate - -**Delegate mining to another party.** - -## API -- [`Consts`](api/src/consts.rs) – Program constants. -- [`Error`](api/src/error.rs) – Custom program errors. -- [`Event`](api/src/error.rs) – Custom program events. -- [`Instruction`](api/src/instruction.rs) – Declared instructions and arguments. - -## Instructions -- [`Deposit`](program/src/deposit.rs) - Deposit hash tokens. -- [`Withdraw`](program/src/withdraw.rs) - Withdraw hash tokens. -- [`Crank`](program/src/crank.rs) - Crank mine instructions. -- [`Payout`](program/src/payout.rs) - Payout mining rewards. - -## State -- [`Delegate`](api/src/state/delegate.rs) - Escrows hash tokens on behalf of a miner. - - -## Tests - -To run the test suite, use the Solana toolchain: - -``` -cargo test-sbf -``` - -For line coverage, use llvm-cov: - -``` -cargo llvm-cov -``` diff --git a/ore-delegate/api/Cargo.toml b/ore-delegate/api/Cargo.toml deleted file mode 100644 index ab83669..0000000 --- a/ore-delegate/api/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "ore-delegate-api" -description.workspace = true -version.workspace = true -edition.workspace = true -license.workspace = true -homepage.workspace = true -documentation.workspace = true -repository.workspace = true -keywords.workspace = true - -[dependencies] -bytemuck.workspace = true -const-crypto.workspace = true -mpl-token-metadata.workspace = true -num_enum.workspace = true -solana-program.workspace = true -spl-token.workspace = true -spl-associated-token-account.workspace = true -steel.workspace = true -thiserror.workspace = true diff --git a/ore-delegate/api/src/consts.rs b/ore-delegate/api/src/consts.rs deleted file mode 100644 index 045c6eb..0000000 --- a/ore-delegate/api/src/consts.rs +++ /dev/null @@ -1,2 +0,0 @@ -/// The seed of the delegate account PDA. -pub const DELEGATE: &[u8] = b"delegate"; diff --git a/ore-delegate/api/src/error.rs b/ore-delegate/api/src/error.rs deleted file mode 100644 index ace6867..0000000 --- a/ore-delegate/api/src/error.rs +++ /dev/null @@ -1,10 +0,0 @@ -use steel::*; - -#[derive(Debug, Error, Clone, Copy, PartialEq, Eq, IntoPrimitive)] -#[repr(u32)] -pub enum OreError { - #[error("Placeholder error")] - Dummy = 0, -} - -error!(OreError); diff --git a/ore-delegate/api/src/event.rs b/ore-delegate/api/src/event.rs deleted file mode 100644 index ee7f90d..0000000 --- a/ore-delegate/api/src/event.rs +++ /dev/null @@ -1 +0,0 @@ -use steel::*; diff --git a/ore-delegate/api/src/instruction.rs b/ore-delegate/api/src/instruction.rs deleted file mode 100644 index 9867b14..0000000 --- a/ore-delegate/api/src/instruction.rs +++ /dev/null @@ -1,37 +0,0 @@ -use steel::*; - -#[repr(u8)] -#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)] -pub enum OreDelegateInstruction { - Deposit = 0, - Withdraw = 1, - Crank = 2, - Payout = 3, -} - -#[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 Crank { - pub amount: [u8; 8], -} - -#[repr(C)] -#[derive(Clone, Copy, Debug, Pod, Zeroable)] -pub struct Payout {} - -instruction!(OreDelegateInstruction, Deposit); -instruction!(OreDelegateInstruction, Withdraw); -instruction!(OreDelegateInstruction, Crank); -instruction!(OreDelegateInstruction, Payout); diff --git a/ore-delegate/api/src/lib.rs b/ore-delegate/api/src/lib.rs deleted file mode 100644 index 7c83341..0000000 --- a/ore-delegate/api/src/lib.rs +++ /dev/null @@ -1,18 +0,0 @@ -pub mod consts; -pub mod error; -pub mod event; -pub mod instruction; -pub mod sdk; -pub mod state; - -pub mod prelude { - pub use crate::consts::*; - pub use crate::error::*; - pub use crate::event::*; - pub use crate::instruction::*; - pub use crate::state::*; -} - -use steel::*; - -declare_id!("oreV2ZymfyeXgNgBdqMkumTqqAprVqgBWQfoYkrtKWQ"); diff --git a/ore-delegate/api/src/sdk.rs b/ore-delegate/api/src/sdk.rs deleted file mode 100644 index c25624c..0000000 --- a/ore-delegate/api/src/sdk.rs +++ /dev/null @@ -1,3 +0,0 @@ -use steel::*; - -use crate::{instruction::*, state::*}; diff --git a/ore-delegate/api/src/state/delegate.rs b/ore-delegate/api/src/state/delegate.rs deleted file mode 100644 index b2c375a..0000000 --- a/ore-delegate/api/src/state/delegate.rs +++ /dev/null @@ -1,21 +0,0 @@ -use steel::*; - -use super::OreDelegateAccount; - -#[repr(C)] -#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)] -pub struct Delegate { - /// The authority of the delegate. - pub authority: Pubkey, - - /// The number of hash tokens deposited for mining. - pub balance: u64, - - /// The block these hash tokens are associated with. - pub block_id: u64, - - /// The fee to payout per crank (lamports). - pub fee: u64, -} - -account!(OreDelegateAccount, Delegate); diff --git a/ore-delegate/api/src/state/mod.rs b/ore-delegate/api/src/state/mod.rs deleted file mode 100644 index 5c2c8f2..0000000 --- a/ore-delegate/api/src/state/mod.rs +++ /dev/null @@ -1,20 +0,0 @@ -mod delegate; - -pub use delegate::*; - -use crate::consts::*; - -use steel::*; - -#[repr(u8)] -#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)] -pub enum OreDelegateAccount { - Delegate = 100, -} - -pub fn delegate_pda(authority: Pubkey, block_id: u64) -> (Pubkey, u8) { - Pubkey::find_program_address( - &[DELEGATE, &authority.to_bytes(), &block_id.to_le_bytes()], - &crate::ID, - ) -} diff --git a/ore-delegate/program/Cargo.toml b/ore-delegate/program/Cargo.toml deleted file mode 100644 index a3ffd4b..0000000 --- a/ore-delegate/program/Cargo.toml +++ /dev/null @@ -1,32 +0,0 @@ -[package] -name = "ore-delegate-program" -description.workspace = true -version.workspace = true -edition.workspace = true -license.workspace = true -homepage.workspace = true -documentation.workspace = true -repository.workspace = true -readme.workspace = true -keywords.workspace = true - -[lib] -crate-type = ["cdylib", "lib"] -name = "ore_delegate" - -[features] -default = [] - -[dependencies] -bincode.workspace = true -mpl-token-metadata.workspace = true -ore-api.workspace = true -ore-delegate-api.workspace = true -solana-program.workspace = true -spl-token.workspace = true -spl-token-2022.workspace = true -spl-associated-token-account.workspace = true -steel.workspace = true - -[dev-dependencies] -rand = "0.8.5" diff --git a/ore-delegate/program/src/crank.rs b/ore-delegate/program/src/crank.rs deleted file mode 100644 index 2f80046..0000000 --- a/ore-delegate/program/src/crank.rs +++ /dev/null @@ -1,52 +0,0 @@ -use ore_api::prelude::*; -use ore_delegate_api::prelude::*; -use steel::*; - -/// Cranks a mining transaction. -pub fn process_crank(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult { - // Parse data. - let args = Crank::try_from_bytes(data)?; - let amount = u64::from_le_bytes(args.amount); - - // Load accounts. - let [signer_info, block_info, delegate_info, escrow_info, market_info, miner_info, mint_info, system_program, token_program, slot_hashes_sysvar] = - accounts - else { - return Err(ProgramError::NotEnoughAccountKeys); - }; - signer_info.is_signer()?; - let block = block_info.as_account::(&ore_api::ID)?; - let delegate = delegate_info - .as_account_mut::(&ore_delegate_api::ID)? - .assert_mut(|d| d.block_id == block.id)?; - - // TODO Convert amount - - // Crank. - let ix = ore_api::sdk::mine(*signer_info.key, block.id, amount); - invoke_signed( - &ix, - &[ - delegate_info.clone(), - block_info.clone(), - market_info.clone(), - miner_info.clone(), - mint_info.clone(), - escrow_info.clone(), - system_program.clone(), - token_program.clone(), - slot_hashes_sysvar.clone(), - ], - &ore_delegate_api::ID, - &[ - DELEGATE, - &delegate.authority.to_bytes(), - &block.id.to_le_bytes(), - ], - )?; - - // Pay fee. - escrow_info.send(delegate.fee, &signer_info); - - Ok(()) -} diff --git a/ore-delegate/program/src/deposit.rs b/ore-delegate/program/src/deposit.rs deleted file mode 100644 index c6fe179..0000000 --- a/ore-delegate/program/src/deposit.rs +++ /dev/null @@ -1,77 +0,0 @@ -use ore_api::prelude::*; -use ore_delegate_api::prelude::*; -use steel::*; - -/// Deposits hash tokens for cranking. -pub fn process_deposit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult { - // Load data. - let args = Deposit::try_from_bytes(data)?; - let amount = u64::from_le_bytes(args.amount); - - // Load accounts. - let [signer_info, block_info, delegate_info, escrow_info, market_info, mint_info, sender_info, system_program, token_program, associated_token_program] = - accounts - else { - return Err(ProgramError::NotEnoughAccountKeys); - }; - signer_info.is_signer()?; - let block = block_info.as_account_mut::(&ore_api::ID)?; - let market = market_info - .as_account_mut::(&ore_api::ID)? - .assert_mut(|m| m.id == block.id)?; - mint_info.has_address(&market.base.mint)?.as_mint()?; - sender_info - .is_writable()? - .as_associated_token_account(signer_info.key, &market.base.mint)? - .assert_mut(|t| t.amount() >= amount)?; - system_program.is_program(&system_program::ID)?; - token_program.is_program(&spl_token::ID)?; - associated_token_program.is_program(&spl_associated_token_account::ID)?; - - // Initialize delegate. - let delegate = if delegate_info.data_is_empty() { - create_program_account::( - delegate_info, - system_program, - signer_info, - &ore_delegate_api::ID, - &[ - DELEGATE, - &signer_info.key.to_bytes(), - &block.id.to_le_bytes(), - ], - )?; - let delegate = delegate_info.as_account_mut::(&ore_delegate_api::ID)?; - delegate.authority = *signer_info.key; - delegate.block_id = block.id; - delegate.fee = 0; // TODO: Set fee. - delegate - } else { - delegate_info.as_account_mut::(&ore_delegate_api::ID)? - }; - - // Initialize escrow. - if escrow_info.data_is_empty() { - create_associated_token_account( - signer_info, - delegate_info, - escrow_info, - mint_info, - system_program, - token_program, - associated_token_program, - )?; - } else { - escrow_info - .is_writable()? - .as_associated_token_account(delegate_info.key, &mint_info.key)?; - } - - // Update delegate. - delegate.balance += amount; - - // Transfer tokens. - transfer(signer_info, sender_info, escrow_info, token_program, amount)?; - - Ok(()) -} diff --git a/ore-delegate/program/src/lib.rs b/ore-delegate/program/src/lib.rs deleted file mode 100644 index 05e5ea3..0000000 --- a/ore-delegate/program/src/lib.rs +++ /dev/null @@ -1,31 +0,0 @@ -mod crank; -mod deposit; -mod payout; -mod withdraw; - -use crank::*; -use deposit::*; -use payout::*; -use withdraw::*; - -use ore_delegate_api::instruction::*; -use steel::*; - -pub fn process_instruction( - program_id: &Pubkey, - accounts: &[AccountInfo], - data: &[u8], -) -> ProgramResult { - let (ix, data) = parse_instruction(&ore_delegate_api::ID, program_id, data)?; - - match ix { - OreDelegateInstruction::Deposit => process_deposit(accounts, data)?, - OreDelegateInstruction::Withdraw => process_withdraw(accounts, data)?, - OreDelegateInstruction::Crank => process_crank(accounts, data)?, - OreDelegateInstruction::Payout => process_payout(accounts, data)?, - } - - Ok(()) -} - -entrypoint!(process_instruction); diff --git a/ore-delegate/program/src/payout.rs b/ore-delegate/program/src/payout.rs deleted file mode 100644 index 482097b..0000000 --- a/ore-delegate/program/src/payout.rs +++ /dev/null @@ -1,99 +0,0 @@ -use ore_delegate_api::prelude::*; -use steel::*; - -/// Payouts a block reward. -pub fn process_payout(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult { - // Parse args. - // let args = Payout::try_from_bytes(data)?; - // let amount = u64::from_le_bytes(args.amount); - // let direction = PayoutDirection::try_from(args.direction).unwrap(); - // let precision = PayoutPrecision::try_from(args.precision).unwrap(); - - // // Load accounts. - // let clock = Clock::get()?; - // let [signer_info, block_info, market_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); - // }; - // signer_info.is_signer()?; - // let block = block_info - // .as_account_mut::(&ore_api::ID)? - // .assert_mut(|b| clock.slot >= b.start_slot + 1500)?; - // let market = market_info - // .as_account_mut::(&ore_api::ID)? - // .assert_mut(|m| m.id == block.id)? - // .assert_mut_err( - // |m| m.base.liquidity() > 0, - // OreError::InsufficientLiquidity.into(), - // )? - // .assert_mut_err( - // |m| m.quote.liquidity() > 0, - // OreError::InsufficientLiquidity.into(), - // )?; - // mint_base_info.has_address(&market.base.mint)?.as_mint()?; - // mint_quote_info.has_address(&market.quote.mint)?.as_mint()?; - // tokens_base_info - // .is_writable()? - // .as_associated_token_account(signer_info.key, mint_base_info.key)?; - // tokens_quote_info - // .is_writable()? - // .as_associated_token_account(signer_info.key, mint_quote_info.key)?; - // vault_base_info - // .is_writable()? - // .as_associated_token_account(market_info.key, mint_base_info.key)?; - // vault_quote_info - // .is_writable()? - // .as_associated_token_account(market_info.key, mint_quote_info.key)?; - // system_program.is_program(&system_program::ID)?; - // token_program.is_program(&spl_token::ID)?; - - // // Update market state. - // let swap_result = market.swap(amount, direction, precision, clock)?; - // swap_result.log_return(); - - // // Get transfer amounts and accounts. - // let (in_amount, in_from, in_to, out_amount, out_from, out_to) = match direction { - // SwapDirection::Buy => ( - // swap_result.quote_to_transfer, - // tokens_quote_info, - // vault_quote_info, - // swap_result.base_to_transfer, - // vault_base_info, - // tokens_base_info, - // ), - // SwapDirection::Sell => ( - // swap_result.base_to_transfer, - // tokens_base_info, - // vault_base_info, - // swap_result.quote_to_transfer, - // vault_quote_info, - // tokens_quote_info, - // ), - // }; - - // // Transfer tokens. - // transfer(signer_info, in_from, in_to, token_program, in_amount)?; - // transfer_signed( - // market_info, - // out_from, - // out_to, - // token_program, - // out_amount, - // &[ - // MARKET, - // market.base.mint.as_ref(), - // market.quote.mint.as_ref(), - // market.id.to_le_bytes().as_ref(), - // ], - // )?; - - // // Validate vault reserves. - // let vault_base = - // vault_base_info.as_associated_token_account(market_info.key, mint_base_info.key)?; - // let vault_quote = - // vault_quote_info.as_associated_token_account(market_info.key, mint_quote_info.key)?; - // market.check_vaults(&vault_base, &vault_quote)?; - - Ok(()) -} diff --git a/ore-delegate/program/src/withdraw.rs b/ore-delegate/program/src/withdraw.rs deleted file mode 100644 index ad3354e..0000000 --- a/ore-delegate/program/src/withdraw.rs +++ /dev/null @@ -1,61 +0,0 @@ -use ore_delegate_api::prelude::*; -use steel::*; - -/// Withdraws hash tokens from the delegate. -pub fn process_withdraw(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult { - // Load data. - let args = Withdraw::try_from_bytes(data)?; - let amount = u64::from_le_bytes(args.amount); - - // Load accounts. - let [signer_info, delegate_info, escrow_info, mint_info, recipient_info, system_program, token_program] = - accounts - else { - return Err(ProgramError::NotEnoughAccountKeys); - }; - signer_info.is_signer()?; - let delegate = delegate_info - .as_account_mut::(&ore_delegate_api::ID)? - .assert_mut(|d| d.authority == *signer_info.key)?; - let escrow = escrow_info.as_associated_token_account(delegate_info.key, &mint_info.key)?; - recipient_info - .is_writable()? - .as_associated_token_account(signer_info.key, &mint_info.key)?; - system_program.is_program(&system_program::ID)?; - token_program.is_program(&spl_token::ID)?; - - // Update delegate. - delegate.balance -= escrow.amount().min(amount); - - // Transfer tokens. - transfer_signed( - signer_info, - escrow_info, - recipient_info, - token_program, - amount, - &[ - DELEGATE, - &delegate.authority.to_bytes(), - &delegate.block_id.to_le_bytes(), - ], - )?; - - // Close accounts if empty. - if delegate.balance == 0 { - delegate_info.close(signer_info)?; - close_token_account_signed( - escrow_info, - signer_info, - delegate_info, - token_program, - &[ - DELEGATE, - &delegate.authority.to_bytes(), - &delegate.block_id.to_le_bytes(), - ], - )?; - } - - Ok(()) -} diff --git a/ore/README.md b/ore/README.md deleted file mode 100644 index da5d0b8..0000000 --- a/ore/README.md +++ /dev/null @@ -1,38 +0,0 @@ -# ORE - -**Mine blockspace. Trade hashpower. Earn rewards.** - -## API -- [`Consts`](api/src/consts.rs) – Program constants. -- [`Error`](api/src/error.rs) – Custom program errors. -- [`Event`](api/src/error.rs) – Custom program events. -- [`Instruction`](api/src/instruction.rs) – Declared instructions and arguments. - -## Instructions - -- [`Open`](program/src/open.rs) - Open a new block. -- [`Close`](program/src/close.rs) - Close a block and pay out the reward. -- [`Mine`](program/src/mine.rs) - Mine the current block. -- [`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) - Tracks a miner state and history. -- [`Treasury`](api/src/state/treasury.rs) - The mint authority of the ORE token. - - -## Tests - -To run the test suite, use the Solana toolchain: - -``` -cargo test-sbf -``` - -For line coverage, use llvm-cov: - -``` -cargo llvm-cov -``` diff --git a/ore/program/Cargo.toml b/program/Cargo.toml similarity index 100% rename from ore/program/Cargo.toml rename to program/Cargo.toml diff --git a/ore/program/src/close.rs b/program/src/close.rs similarity index 100% rename from ore/program/src/close.rs rename to program/src/close.rs diff --git a/ore/program/src/commit.rs b/program/src/commit.rs similarity index 100% rename from ore/program/src/commit.rs rename to program/src/commit.rs diff --git a/ore/program/src/decommit.rs b/program/src/decommit.rs similarity index 100% rename from ore/program/src/decommit.rs rename to program/src/decommit.rs diff --git a/ore/program/src/deposit.rs b/program/src/deposit.rs similarity index 100% rename from ore/program/src/deposit.rs rename to program/src/deposit.rs diff --git a/ore/program/src/lib.rs b/program/src/lib.rs similarity index 100% rename from ore/program/src/lib.rs rename to program/src/lib.rs diff --git a/ore/program/src/mine.rs b/program/src/mine.rs similarity index 100% rename from ore/program/src/mine.rs rename to program/src/mine.rs diff --git a/ore/program/src/open.rs b/program/src/open.rs similarity index 99% rename from ore/program/src/open.rs rename to program/src/open.rs index 8704d4e..7ac5645 100644 --- a/ore/program/src/open.rs +++ b/program/src/open.rs @@ -77,7 +77,7 @@ pub fn process_open(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult market.quote = TokenParams { mint: *mint_quote_info.key, balance: 0, - balance_virtual: VIRTUAL_ORE_LIQUIDITY, + balance_virtual: VIRTUAL_LIQUIDITY, }; market.fee = FeeParams { rate: FEE_RATE_BPS, diff --git a/ore/program/src/swap.rs b/program/src/swap.rs similarity index 100% rename from ore/program/src/swap.rs rename to program/src/swap.rs diff --git a/ore/program/src/withdraw.rs b/program/src/withdraw.rs similarity index 100% rename from ore/program/src/withdraw.rs rename to program/src/withdraw.rs