From 2fafa6358763f3fbeb8d513be68369f51273820b Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Mon, 29 Apr 2024 20:19:30 +0000 Subject: [PATCH] const noise --- Cargo.lock | 1 - Cargo.toml | 2 +- src/consts.rs | 7 ---- src/error.rs | 2 ++ src/instruction.rs | 38 +++++++++++--------- src/loaders.rs | 26 +------------- src/processor/initialize.rs | 69 +++++++++++++++++++------------------ src/processor/mine.rs | 7 ++-- 8 files changed, 62 insertions(+), 90 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 79e32c0..d3b15f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1242,7 +1242,6 @@ checksum = "1435fa1053d8b2fbbe9be7e97eca7f33d37b28409959813daefc1446a14247f1" [[package]] name = "drillx" version = "0.1.0" -source = "git+https://github.com/hardhatchad/drillx?branch=master#9fa59d964a23618b04f6f4f96ceb58f6638f9257" dependencies = [ "enum_dispatch", "num-traits", diff --git a/Cargo.toml b/Cargo.toml index 5de42fb..be2a6ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ array-const-fn-init = "0.1.1" bs58 = "0.5.0" bytemuck = "1.14.3" const-crypto = "0.1.0" -drillx = { git = "https://github.com/hardhatchad/drillx", branch = "master" } +drillx = { path = "../drillx/drillx" } mpl-token-metadata = "4.1.2" num_enum = "0.7.2" shank = "0.3.0" diff --git a/src/consts.rs b/src/consts.rs index 9ca222d..48448a7 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -51,9 +51,6 @@ pub const METADATA: &[u8] = b"metadata"; /// The seed of the mint account PDA. pub const MINT: &[u8] = b"mint"; -/// The seed of the noise account PDA. -pub const NOISE: &[u8] = b"noise"; - /// The seed of proof account PDAs. pub const PROOF: &[u8] = b"proof"; @@ -109,10 +106,6 @@ pub const MINT_ADDRESS: Pubkey = /// The address of the v1 mint account. pub const MINT_V1_ADDRESS: Pubkey = pubkey!("oreoN2tQbHXVaZsr3pf66A48miqcBXCDJozganhEJgz"); -/// The address of the mint metadata account. -pub const NOISE_ADDRESS: Pubkey = - Pubkey::new_from_array(ed25519::derive_program_address(&[NOISE], &PROGRAM_ID).0); - /// The address of the treasury account. pub const TREASURY_ADDRESS: Pubkey = Pubkey::new_from_array(ed25519::derive_program_address(&[TREASURY], &PROGRAM_ID).0); diff --git a/src/error.rs b/src/error.rs index 2dc6684..8880788 100644 --- a/src/error.rs +++ b/src/error.rs @@ -19,6 +19,8 @@ pub enum OreError { StakeTooLarge = 5, #[error("The clock time is invalid")] ClockInvalid = 6, + #[error("The noise account is as large as it can get")] + NoiseSizeExceeded = 7, } impl From for ProgramError { diff --git a/src/instruction.rs b/src/instruction.rs index 6674f6c..ce4465c 100644 --- a/src/instruction.rs +++ b/src/instruction.rs @@ -26,10 +26,11 @@ pub enum OreInstruction { #[account(7, name = "bus_5", desc = "Ore bus account 5", writable)] #[account(8, name = "bus_6", desc = "Ore bus account 6", writable)] #[account(9, name = "bus_7", desc = "Ore bus account 7", writable)] - #[account(10, name = "mint", desc = "Ore token mint account", writable)] - #[account(11, name = "treasury", desc = "Ore treasury account", writable)] - #[account(12, name = "treasury_tokens", desc = "Ore treasury token account", writable)] - #[account(13, name = "token_program", desc = "SPL token program")] + #[account(10, name = "config", desc = "Ore config account")] + #[account(11, name = "mint", desc = "Ore token mint account", writable)] + #[account(12, name = "treasury", desc = "Ore treasury account", writable)] + #[account(13, name = "treasury_tokens", desc = "Ore treasury token account", writable)] + #[account(14, name = "token_program", desc = "SPL token program")] Reset = 0, #[account(0, name = "ore_program", desc = "Ore program")] @@ -41,9 +42,10 @@ pub enum OreInstruction { #[account(0, name = "ore_program", desc = "Ore program")] #[account(1, name = "signer", desc = "Signer", signer)] #[account(2, name = "bus", desc = "Ore bus account", writable)] - #[account(3, name = "proof", desc = "Ore proof account", writable)] - #[account(4, name = "treasury", desc = "Ore treasury account")] - #[account(5, name = "slot_hashes", desc = "Solana slot hashes sysvar")] + #[account(3, name = "config", desc = "Ore config account")] + #[account(4, name = "noise", desc = "Ore noise account")] + #[account(5, name = "proof", desc = "Ore proof account", writable)] + #[account(6, name = "slot_hashes", desc = "Solana slot hashes sysvar")] Mine = 2, #[account(0, name = "ore_program", desc = "Ore program")] @@ -85,23 +87,24 @@ pub enum OreInstruction { #[account(9, name = "bus_7", desc = "Ore bus account 7", writable)] #[account(10, name = "metadata", desc = "Ore mint metadata account", writable)] #[account(11, name = "mint", desc = "Ore mint account", writable)] - #[account(12, name = "treasury", desc = "Ore treasury account", writable)] - #[account(13, name = "treasury_tokens", desc = "Ore treasury token account", writable)] - #[account(14, name = "system_program", desc = "Solana system program")] - #[account(15, name = "token_program", desc = "SPL token program")] - #[account(16, name = "associated_token_program", desc = "SPL associated token program")] - #[account(17, name = "mpl_metadata_program", desc = "Metaplex metadata program")] - #[account(18, name = "rent", desc = "Solana rent sysvar")] + #[account(12, name = "noise", desc = "Ore noise account", writable)] + #[account(13, name = "treasury", desc = "Ore treasury account", writable)] + #[account(14, name = "treasury_tokens", desc = "Ore treasury token account", writable)] + #[account(15, name = "system_program", desc = "Solana system program")] + #[account(16, name = "token_program", desc = "SPL token program")] + #[account(17, name = "associated_token_program", desc = "SPL associated token program")] + #[account(18, name = "mpl_metadata_program", desc = "Metaplex metadata program")] + #[account(19, name = "rent", desc = "Solana rent sysvar")] Initialize = 100, #[account(0, name = "ore_program", desc = "Ore program")] #[account(1, name = "signer", desc = "Admin signer", signer)] - #[account(2, name = "config", desc = "Ore config account")] + #[account(2, name = "config", desc = "Ore config account", writable)] UpdateAdmin = 101, #[account(0, name = "ore_program", desc = "Ore program")] #[account(1, name = "signer", desc = "Admin signer", signer)] - #[account(2, name = "config", desc = "Ore config account")] + #[account(2, name = "config", desc = "Ore config account", writable)] Pause = 102, } @@ -206,6 +209,7 @@ pub fn reset(signer: Pubkey) -> Instruction { AccountMeta::new(BUS_ADDRESSES[5], false), AccountMeta::new(BUS_ADDRESSES[6], false), AccountMeta::new(BUS_ADDRESSES[7], false), + AccountMeta::new(CONFIG_ADDRESS, false), AccountMeta::new(MINT_ADDRESS, false), AccountMeta::new(TREASURY_ADDRESS, false), AccountMeta::new(treasury_tokens, false), @@ -360,7 +364,7 @@ pub fn initialize(signer: Pubkey) -> Instruction { AccountMeta::new_readonly(system_program::id(), false), AccountMeta::new_readonly(spl_token::id(), false), AccountMeta::new_readonly(spl_associated_token_account::id(), false), - AccountMeta::new_readonly(mpl_token_metadata::ID, false), + // AccountMeta::new_readonly(mpl_token_metadata::ID, false), AccountMeta::new_readonly(sysvar::rent::id(), false), ], data: [ diff --git a/src/loaders.rs b/src/loaders.rs index 81f0a6d..eaddb54 100644 --- a/src/loaders.rs +++ b/src/loaders.rs @@ -7,7 +7,7 @@ use spl_token::state::Mint; use crate::{ state::{Bus, Config, Proof, Treasury}, utils::{AccountDeserialize, Discriminator}, - BUS_ADDRESSES, CONFIG_ADDRESS, NOISE_ADDRESS, TREASURY_ADDRESS, + BUS_ADDRESSES, CONFIG_ADDRESS, TREASURY_ADDRESS, }; /// Errors if: @@ -125,30 +125,6 @@ pub fn load_config<'a, 'info>( Ok(()) } -/// asdf -pub fn load_noise<'a, 'info>( - info: &'a AccountInfo<'info>, - is_writable: bool, -) -> Result<(), ProgramError> { - if info.owner.ne(&crate::id()) { - return Err(ProgramError::InvalidAccountOwner); - } - - if info.key.ne(&NOISE_ADDRESS) { - return Err(ProgramError::InvalidSeeds); - } - - if info.data_is_empty() { - return Err(ProgramError::UninitializedAccount); - } - - if is_writable && !info.is_writable { - return Err(ProgramError::InvalidAccountData); - } - - Ok(()) -} - /// Errors if: /// - Owner is not Ore program. /// - Data is empty. diff --git a/src/processor/initialize.rs b/src/processor/initialize.rs index 2c90ea3..be483fe 100644 --- a/src/processor/initialize.rs +++ b/src/processor/initialize.rs @@ -17,8 +17,8 @@ use crate::{ utils::create_pda, utils::AccountDeserialize, utils::Discriminator, - BUS, BUS_COUNT, CONFIG, METADATA, METADATA_NAME, METADATA_SYMBOL, METADATA_URI, MINT, - MINT_ADDRESS, MINT_NOISE, TOKEN_DECIMALS, TREASURY, + BUS, BUS_COUNT, CONFIG, INITIAL_BASE_REWARD_RATE, METADATA, METADATA_NAME, METADATA_SYMBOL, + METADATA_URI, MINT, MINT_ADDRESS, MINT_NOISE, TOKEN_DECIMALS, TREASURY, }; /// Initialize sets up the Ore program. Its responsibilities include: @@ -48,7 +48,8 @@ pub fn process_initialize<'a, 'info>( let args = InitializeArgs::try_from_bytes(data)?; // Load accounts - let [signer, bus_0_info, bus_1_info, bus_2_info, bus_3_info, bus_4_info, bus_5_info, bus_6_info, bus_7_info, config_info, metadata_info, mint_info, treasury_info, treasury_tokens_info, system_program, token_program, associated_token_program, metadata_program, rent_sysvar] = + // let [signer, bus_0_info, bus_1_info, bus_2_info, bus_3_info, bus_4_info, bus_5_info, bus_6_info, bus_7_info, config_info, metadata_info, mint_info, treasury_info, treasury_tokens_info, system_program, token_program, associated_token_program, metadata_program, rent_sysvar] = + let [signer, bus_0_info, bus_1_info, bus_2_info, bus_3_info, bus_4_info, bus_5_info, bus_6_info, bus_7_info, config_info, metadata_info, mint_info, treasury_info, treasury_tokens_info, system_program, token_program, associated_token_program, rent_sysvar] = accounts else { return Err(ProgramError::NotEnoughAccountKeys); @@ -84,7 +85,7 @@ pub fn process_initialize<'a, 'info>( load_program(system_program, system_program::id())?; load_program(token_program, spl_token::id())?; load_program(associated_token_program, spl_associated_token_account::id())?; - load_program(metadata_program, mpl_token_metadata::ID)?; + // load_program(metadata_program, mpl_token_metadata::ID)?; load_sysvar(rent_sysvar, sysvar::rent::id())?; // Initialize bus accounts @@ -118,7 +119,7 @@ pub fn process_initialize<'a, 'info>( bus.rewards = 0; } - // TODO Initialize config + // Initialize config create_pda( config_info, &crate::id(), @@ -131,9 +132,12 @@ pub fn process_initialize<'a, 'info>( config_data[0] = Config::discriminator() as u8; let config = Config::try_from_bytes_mut(&mut config_data)?; config.admin = *signer.key; - // config.difficulty = INITIAL_DIFFICULTY.into(); + config.base_reward_rate = INITIAL_BASE_REWARD_RATE; + config.last_reset_at = 0; + config.min_difficulty = 8; + config.paused = 0; - // TODO Initialize treasury + // Initialize treasury create_pda( treasury_info, &crate::id(), @@ -146,9 +150,6 @@ pub fn process_initialize<'a, 'info>( treasury_data[0] = Treasury::discriminator() as u8; let treasury = Treasury::try_from_bytes_mut(&mut treasury_data)?; treasury.bump = args.treasury_bump as u64; - // treasury.last_reset_at = 0; - // treasury.reward_rate = INITIAL_REWARD_RATE; - // treasury.total_claimed_rewards = 0; drop(treasury_data); // Initialize mint @@ -178,30 +179,30 @@ pub fn process_initialize<'a, 'info>( )?; // Initialize mint metadata - mpl_token_metadata::instructions::CreateMetadataAccountV3Cpi { - __program: metadata_program, - metadata: metadata_info, - mint: mint_info, - mint_authority: treasury_info, - payer: signer, - update_authority: (signer, true), - system_program, - rent: Some(rent_sysvar), - __args: mpl_token_metadata::instructions::CreateMetadataAccountV3InstructionArgs { - data: mpl_token_metadata::types::DataV2 { - name: METADATA_NAME.to_string(), - symbol: METADATA_SYMBOL.to_string(), - uri: METADATA_URI.to_string(), - seller_fee_basis_points: 0, - creators: None, - collection: None, - uses: None, - }, - is_mutable: true, - collection_details: None, - }, - } - .invoke_signed(&[&[TREASURY, &[args.treasury_bump]]])?; + // mpl_token_metadata::instructions::CreateMetadataAccountV3Cpi { + // __program: metadata_program, + // metadata: metadata_info, + // mint: mint_info, + // mint_authority: treasury_info, + // payer: signer, + // update_authority: (signer, true), + // system_program, + // rent: Some(rent_sysvar), + // __args: mpl_token_metadata::instructions::CreateMetadataAccountV3InstructionArgs { + // data: mpl_token_metadata::types::DataV2 { + // name: METADATA_NAME.to_string(), + // symbol: METADATA_SYMBOL.to_string(), + // uri: METADATA_URI.to_string(), + // seller_fee_basis_points: 0, + // creators: None, + // collection: None, + // uses: None, + // }, + // is_mutable: true, + // collection_details: None, + // }, + // } + // .invoke_signed(&[&[TREASURY, &[args.treasury_bump]]])?; // Initialize treasury token account solana_program::program::invoke( diff --git a/src/processor/mine.rs b/src/processor/mine.rs index efc036f..031baff 100644 --- a/src/processor/mine.rs +++ b/src/processor/mine.rs @@ -44,13 +44,12 @@ pub fn process_mine<'a, 'info>( let args = MineArgs::try_from_bytes(data)?; // Load accounts - let [signer, bus_info, config_info, noise_info, proof_info, slot_hashes_info] = accounts else { + let [signer, bus_info, config_info, proof_info, slot_hashes_info] = accounts else { return Err(ProgramError::NotEnoughAccountKeys); }; load_signer(signer)?; load_any_bus(bus_info, true)?; load_config(config_info, false)?; - load_noise(noise_info, false)?; load_proof(proof_info, signer.key, true)?; load_sysvar(slot_hashes_info, sysvar::slot_hashes::id())?; @@ -78,9 +77,7 @@ pub fn process_mine<'a, 'info>( // } // Calculate the hash from the provided nonce - let noise_data = noise_info.data.borrow(); - let hx = drillx::hash(&proof.challenge, &args.nonce, &noise_data); - drop(noise_data); + let hx = drillx::hash(&proof.challenge, &args.nonce); // Validate hash satisfies the minimnum difficulty let difficulty = drillx::difficulty(hx);