From 609349a5aa297e5f2187fd3a251dda45de3a2e1b Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Thu, 26 Sep 2024 03:50:36 +0000 Subject: [PATCH 01/18] upgrade to new version of steel --- Cargo.lock | 6 ++-- Cargo.toml | 2 ++ api/src/loaders.rs | 39 ++++++++-------------- api/src/state/bus.rs | 23 +++++++++++-- api/src/state/config.rs | 2 -- program/src/claim.rs | 6 ++-- program/src/close.rs | 10 +++--- program/src/initialize.rs | 70 +++++++++++++++------------------------ program/src/mine.rs | 12 +++---- program/src/open.rs | 27 +++++++-------- program/src/reset.rs | 10 +++--- program/src/stake.rs | 13 ++++---- program/src/update.rs | 4 +-- program/src/upgrade.rs | 21 +++++++----- 14 files changed, 120 insertions(+), 125 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3ffc70d..8758d26 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2211,14 +2211,14 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "steel" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b09eae425248a8afcef3cf3300dfa548791194fa9fe519dadd5c57d7964dbc" +version = "0.1.5" dependencies = [ "bytemuck", + "num_enum", "solana-program", "spl-associated-token-account", "spl-token", + "thiserror", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 3bb3b18..134951f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,3 +28,5 @@ steel = { features = ["spl"], version = "0.1.0" } thiserror = "1.0.57" +[patch.crates-io] +steel = { path = "../steel/lib" } diff --git a/api/src/loaders.rs b/api/src/loaders.rs index 925335d..77fa46a 100644 --- a/api/src/loaders.rs +++ b/api/src/loaders.rs @@ -192,34 +192,23 @@ pub fn load_any_proof(info: &AccountInfo<'_>, is_writable: bool) -> Result<(), P Ok(()) } -/// Errors if: -/// - Owner is not Ore program. -/// - Address does not match the expected address. -/// - Data is empty. -/// - Data cannot deserialize into a treasury account. -/// - Expected to be writable, but is not. -pub fn load_treasury(info: &AccountInfo<'_>, is_writable: bool) -> Result<(), ProgramError> { - if info.owner.ne(&crate::id()) { - return Err(ProgramError::InvalidAccountOwner); +pub trait OreAccountInfoValidation { + fn is_config(&self) -> Result<&Self, ProgramError>; + fn is_treasury(&self) -> Result<&Self, ProgramError>; +} + +impl<'a> OreAccountInfoValidation for AccountInfo<'a> { + fn is_config(&self) -> Result<&Self, ProgramError> { + self.has_address(&CONFIG_ADDRESS)? + .has_owner(&crate::ID)? + .is_type::() } - if info.key.ne(&TREASURY_ADDRESS) { - return Err(ProgramError::InvalidSeeds); + fn is_treasury(&self) -> Result<&Self, ProgramError> { + self.has_address(&TREASURY_ADDRESS)? + .has_owner(&crate::ID)? + .is_type::() } - - if info.data_is_empty() { - return Err(ProgramError::UninitializedAccount); - } - - if info.data.borrow()[0].ne(&(Treasury::discriminator() as u8)) { - return Err(solana_program::program_error::ProgramError::InvalidAccountData); - } - - if is_writable && !info.is_writable { - return Err(ProgramError::InvalidAccountData); - } - - Ok(()) } /// Errors if: diff --git a/api/src/state/bus.rs b/api/src/state/bus.rs index 2c12776..f92f715 100644 --- a/api/src/state/bus.rs +++ b/api/src/state/bus.rs @@ -1,5 +1,3 @@ -use bytemuck::{Pod, Zeroable}; -use solana_program::pubkey::Pubkey; use steel::*; use crate::consts::BUS; @@ -30,4 +28,25 @@ pub fn bus_pda(id: u8) -> (Pubkey, u8) { Pubkey::find_program_address(&[BUS, &[id]], &crate::id()) } +impl<'a> From<&'a [u8]> for &'a Bus { + fn from(value: &'a [u8]) -> &'a Bus { + Bus::try_from_bytes(value).unwrap() + } +} + +impl<'a> From<*const u8> for &'a Bus { + fn from(value: *const u8) -> &'a Bus { + unsafe { + if Bus::discriminator().ne(&value.add(0).read()) { + panic!(""); + } + bytemuck::try_from_bytes::(std::slice::from_raw_parts( + value.add(8), + std::mem::size_of::(), + )) + .expect("") + } + } +} + account!(OreAccount, Bus); diff --git a/api/src/state/config.rs b/api/src/state/config.rs index e35216c..64bbf8c 100644 --- a/api/src/state/config.rs +++ b/api/src/state/config.rs @@ -1,5 +1,3 @@ -use bytemuck::{Pod, Zeroable}; -use solana_program::pubkey::Pubkey; use steel::*; use crate::consts::CONFIG; diff --git a/program/src/claim.rs b/program/src/claim.rs index 7cf33cc..9f564b8 100644 --- a/program/src/claim.rs +++ b/program/src/claim.rs @@ -16,12 +16,12 @@ pub fn process_claim(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult else { return Err(ProgramError::NotEnoughAccountKeys); }; - load_signer(signer)?; + signer.is_signer()?; load_token_account(beneficiary_info, None, &MINT_ADDRESS, true)?; load_proof(proof_info, signer.key, true)?; - load_treasury(treasury_info, false)?; + treasury_info.is_treasury()?; load_treasury_tokens(treasury_tokens_info, true)?; - load_program(token_program, spl_token::id())?; + token_program.has_address(&spl_token::ID)?; // Update miner balance. let mut proof_data = proof_info.data.borrow_mut(); diff --git a/program/src/close.rs b/program/src/close.rs index 4529e39..4201b5f 100644 --- a/program/src/close.rs +++ b/program/src/close.rs @@ -8,12 +8,12 @@ use steel::*; /// Close closes a proof account and returns the rent to the owner. pub fn process_close(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult { // Load accounts. - let [signer, proof_info, system_program] = accounts else { + let [signer_info, proof_info, system_program] = accounts else { return Err(ProgramError::NotEnoughAccountKeys); }; - load_signer(signer)?; - load_proof(proof_info, signer.key, true)?; - load_program(system_program, system_program::id())?; + signer_info.is_signer()?; + load_proof(proof_info, signer_info.key, true)?; + system_program.is_program(&system_program::ID)?; // Validate balance is zero. let proof_data = proof_info.data.borrow(); @@ -27,7 +27,7 @@ pub fn process_close(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul proof_info.realloc(0, true)?; // Send remaining lamports to signer. - **signer.lamports.borrow_mut() += proof_info.lamports(); + **signer_info.lamports.borrow_mut() += proof_info.lamports(); **proof_info.lamports.borrow_mut() = 0; Ok(()) diff --git a/program/src/initialize.rs b/program/src/initialize.rs index b4255d0..16bd2d0 100644 --- a/program/src/initialize.rs +++ b/program/src/initialize.rs @@ -18,23 +18,22 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramR let args = Initialize::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_info, 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] = accounts else { return Err(ProgramError::NotEnoughAccountKeys); }; - load_signer(signer)?; - load_uninitialized_pda(bus_0_info, &[BUS, &[0]], args.bus_0_bump, &ore_api::id())?; - load_uninitialized_pda(bus_1_info, &[BUS, &[1]], args.bus_1_bump, &ore_api::id())?; - load_uninitialized_pda(bus_2_info, &[BUS, &[2]], args.bus_2_bump, &ore_api::id())?; - load_uninitialized_pda(bus_3_info, &[BUS, &[3]], args.bus_3_bump, &ore_api::id())?; - load_uninitialized_pda(bus_4_info, &[BUS, &[4]], args.bus_4_bump, &ore_api::id())?; - load_uninitialized_pda(bus_5_info, &[BUS, &[5]], args.bus_5_bump, &ore_api::id())?; - load_uninitialized_pda(bus_6_info, &[BUS, &[6]], args.bus_6_bump, &ore_api::id())?; - load_uninitialized_pda(bus_7_info, &[BUS, &[7]], args.bus_7_bump, &ore_api::id())?; - load_uninitialized_pda(config_info, &[CONFIG], args.config_bump, &ore_api::id())?; - load_uninitialized_pda( - metadata_info, + signer_info.is_signer()?.has_address(&INITIALIZER_ADDRESS)?; + bus_0_info.is_empty_pda(&[BUS, &[0]], args.bus_0_bump, &ore_api::ID)?; + bus_1_info.is_empty_pda(&[BUS, &[1]], args.bus_1_bump, &ore_api::ID)?; + bus_2_info.is_empty_pda(&[BUS, &[2]], args.bus_2_bump, &ore_api::ID)?; + bus_3_info.is_empty_pda(&[BUS, &[3]], args.bus_3_bump, &ore_api::ID)?; + bus_4_info.is_empty_pda(&[BUS, &[4]], args.bus_4_bump, &ore_api::ID)?; + bus_5_info.is_empty_pda(&[BUS, &[5]], args.bus_5_bump, &ore_api::ID)?; + bus_6_info.is_empty_pda(&[BUS, &[6]], args.bus_6_bump, &ore_api::ID)?; + bus_7_info.is_empty_pda(&[BUS, &[7]], args.bus_7_bump, &ore_api::ID)?; + config_info.is_empty_pda(&[CONFIG], args.config_bump, &ore_api::id())?; + metadata_info.is_empty_pda( &[ METADATA, mpl_token_metadata::ID.as_ref(), @@ -43,29 +42,14 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramR args.metadata_bump, &mpl_token_metadata::ID, )?; - load_uninitialized_pda( - mint_info, - &[MINT, MINT_NOISE.as_slice()], - args.mint_bump, - &ore_api::id(), - )?; - load_uninitialized_pda( - treasury_info, - &[TREASURY], - args.treasury_bump, - &ore_api::id(), - )?; - load_system_account(treasury_tokens_info, true)?; - 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_sysvar(rent_sysvar, sysvar::rent::id())?; - - // Check signer. - if signer.key.ne(&INITIALIZER_ADDRESS) { - return Err(ProgramError::MissingRequiredSignature); - } + mint_info.is_empty_pda(&[MINT, MINT_NOISE.as_slice()], args.mint_bump, &ore_api::ID)?; + treasury_info.is_empty_pda(&[TREASURY], args.treasury_bump, &ore_api::ID)?; + treasury_tokens_info.is_empty()?; + system_program.is_program(&system_program::ID)?; + token_program.is_program(&spl_token::ID)?; + associated_token_program.is_program(&spl_associated_token_account::ID)?; + metadata_program.is_program(&mpl_token_metadata::ID)?; + rent_sysvar.is_sysvar(&sysvar::rent::ID)?; // Initialize bus accounts. let bus_infos = [ @@ -89,7 +73,7 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramR 8 + size_of::(), &[BUS, &[i as u8], &[bus_bumps[i]]], system_program, - signer, + signer_info, )?; let mut bus_data = bus_infos[i].try_borrow_mut_data()?; bus_data[0] = Bus::discriminator() as u8; @@ -107,7 +91,7 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramR 8 + size_of::(), &[CONFIG, &[args.config_bump]], system_program, - signer, + signer_info, )?; let mut config_data = config_info.data.borrow_mut(); config_data[0] = Config::discriminator() as u8; @@ -124,7 +108,7 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramR 8 + size_of::(), &[TREASURY, &[args.treasury_bump]], system_program, - signer, + signer_info, )?; let mut treasury_data = treasury_info.data.borrow_mut(); treasury_data[0] = Treasury::discriminator() as u8; @@ -137,7 +121,7 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramR Mint::LEN, &[MINT, MINT_NOISE.as_slice(), &[args.mint_bump]], system_program, - signer, + signer_info, )?; solana_program::program::invoke_signed( &spl_token::instruction::initialize_mint( @@ -162,8 +146,8 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramR metadata: metadata_info, mint: mint_info, mint_authority: treasury_info, - payer: signer, - update_authority: (signer, true), + payer: signer_info, + update_authority: (signer_info, true), system_program, rent: Some(rent_sysvar), __args: mpl_token_metadata::instructions::CreateMetadataAccountV3InstructionArgs { @@ -184,7 +168,7 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramR // Initialize treasury token account. create_ata( - signer, + signer_info, treasury_info, treasury_tokens_info, mint_info, diff --git a/program/src/mine.rs b/program/src/mine.rs index 40aa1ee..cf5cf2d 100644 --- a/program/src/mine.rs +++ b/program/src/mine.rs @@ -26,7 +26,7 @@ use solana_program::{ use steel::*; /// Mine validates hashes and increments a miner's collectable balance. -pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult { +pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult { // Parse args. let args = Mine::try_from_bytes(data)?; @@ -36,12 +36,12 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult else { return Err(ProgramError::NotEnoughAccountKeys); }; - load_signer(signer)?; - load_any_bus(bus_info, true)?; - load_config(config_info, false)?; + signer.is_signer()?; + bus_info.is_type::()?.is_writable()?; + config_info.is_config()?; load_proof_with_miner(proof_info, signer.key, true)?; - load_sysvar(instructions_sysvar, sysvar::instructions::id())?; - load_sysvar(slot_hashes_sysvar, sysvar::slot_hashes::id())?; + instructions_sysvar.is_sysvar(&sysvar::instructions::ID)?; + slot_hashes_sysvar.is_sysvar(&sysvar::slot_hashes::ID)?; // Authenticate the proof account. // diff --git a/program/src/open.rs b/program/src/open.rs index f914af8..e2c99e3 100644 --- a/program/src/open.rs +++ b/program/src/open.rs @@ -19,28 +19,25 @@ pub fn process_open(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult let args = Open::try_from_bytes(data)?; // Load accounts. - let [signer, miner_info, payer_info, proof_info, system_program, slot_hashes_info] = accounts + let [signer_info, miner_info, payer_info, proof_info, system_program, slot_hashes_info] = + accounts else { return Err(ProgramError::NotEnoughAccountKeys); }; - load_signer(signer)?; - load_any(miner_info, false)?; - load_signer(payer_info)?; - load_uninitialized_pda( - proof_info, - &[PROOF, signer.key.as_ref()], - args.bump, - &ore_api::id(), - )?; - load_program(system_program, system_program::id())?; - load_sysvar(slot_hashes_info, sysvar::slot_hashes::id())?; + signer_info.is_signer()?; + payer_info.is_signer()?; + proof_info + .is_empty_pda(&[PROOF, signer_info.key.as_ref()], args.bump, &ore_api::ID)? + .is_writable()?; + system_program.is_program(&system_program::ID)?; + slot_hashes_info.is_sysvar(&sysvar::slot_hashes::ID)?; // Initialize proof. create_pda( proof_info, &ore_api::id(), 8 + size_of::(), - &[PROOF, signer.key.as_ref(), &[args.bump]], + &[PROOF, signer_info.key.as_ref(), &[args.bump]], system_program, payer_info, )?; @@ -48,10 +45,10 @@ pub fn process_open(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult let mut proof_data = proof_info.data.borrow_mut(); proof_data[0] = Proof::discriminator() as u8; let proof = Proof::try_from_bytes_mut(&mut proof_data)?; - proof.authority = *signer.key; + proof.authority = *signer_info.key; proof.balance = 0; proof.challenge = hashv(&[ - signer.key.as_ref(), + signer_info.key.as_ref(), &slot_hashes_info.data.borrow()[0..size_of::()], ]) .0; diff --git a/program/src/reset.rs b/program/src/reset.rs index a3abcfa..ffb282c 100644 --- a/program/src/reset.rs +++ b/program/src/reset.rs @@ -14,12 +14,12 @@ use steel::*; /// Reset tops up the bus balances, updates the base reward rate, and sets up the ORE program for the next epoch. pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult { // 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, mint_info, treasury_info, treasury_tokens_info, token_program] = + let [signer_info, 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, mint_info, treasury_info, treasury_tokens_info, token_program] = accounts else { return Err(ProgramError::NotEnoughAccountKeys); }; - load_signer(signer)?; + signer_info.is_signer()?; load_bus(bus_0_info, 0, true)?; load_bus(bus_1_info, 1, true)?; load_bus(bus_2_info, 2, true)?; @@ -28,11 +28,11 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul load_bus(bus_5_info, 5, true)?; load_bus(bus_6_info, 6, true)?; load_bus(bus_7_info, 7, true)?; - load_config(config_info, true)?; + config_info.is_config()?.is_writable()?; load_mint(mint_info, MINT_ADDRESS, true)?; - load_treasury(treasury_info, true)?; + treasury_info.is_treasury()?.is_writable()?; load_treasury_tokens(treasury_tokens_info, true)?; - load_program(token_program, spl_token::id())?; + token_program.is_program(&spl_token::ID)?; let busses: [&AccountInfo; BUS_COUNT] = [ bus_0_info, bus_1_info, bus_2_info, bus_3_info, bus_4_info, bus_5_info, bus_6_info, bus_7_info, diff --git a/program/src/stake.rs b/program/src/stake.rs index 08f33b5..94fef15 100644 --- a/program/src/stake.rs +++ b/program/src/stake.rs @@ -12,14 +12,15 @@ pub fn process_stake(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult let amount = u64::from_le_bytes(args.amount); // Load accounts. - let [signer, proof_info, sender_info, treasury_tokens_info, token_program] = accounts else { + let [signer_info, proof_info, sender_info, treasury_tokens_info, token_program] = accounts + else { return Err(ProgramError::NotEnoughAccountKeys); }; - load_signer(signer)?; - load_proof(proof_info, signer.key, true)?; - load_token_account(sender_info, Some(signer.key), &MINT_ADDRESS, true)?; + signer_info.is_signer()?; + load_proof(proof_info, signer_info.key, true)?; + load_token_account(sender_info, Some(signer_info.key), &MINT_ADDRESS, true)?; load_treasury_tokens(treasury_tokens_info, true)?; - load_program(token_program, spl_token::id())?; + token_program.is_program(&spl_token::ID)?; // Update the proof balance. let mut proof_data = proof_info.data.borrow_mut(); @@ -32,7 +33,7 @@ pub fn process_stake(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult // Transfer tokens from signer to treasury. transfer( - signer, + signer_info, sender_info, treasury_tokens_info, token_program, diff --git a/program/src/update.rs b/program/src/update.rs index 6ffdf3b..849eb1a 100644 --- a/program/src/update.rs +++ b/program/src/update.rs @@ -10,8 +10,8 @@ pub fn process_update(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResu let [signer, miner_info, proof_info] = accounts else { return Err(ProgramError::NotEnoughAccountKeys); }; - load_signer(signer)?; - load_any(miner_info, false)?; + signer.is_signer()?; + // load_any(miner_info, false)?; load_proof(proof_info, signer.key, true)?; // Update the proof's miner authority. diff --git a/program/src/upgrade.rs b/program/src/upgrade.rs index 7530117..d3b2220 100644 --- a/program/src/upgrade.rs +++ b/program/src/upgrade.rs @@ -13,17 +13,22 @@ pub fn process_upgrade(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResu let amount = u64::from_le_bytes(args.amount); // Load accounts - let [signer, beneficiary_info, mint_info, mint_v1_info, sender_info, treasury_info, token_program] = + let [signer_info, beneficiary_info, mint_info, mint_v1_info, sender_info, treasury_info, token_program] = accounts else { return Err(ProgramError::NotEnoughAccountKeys); }; - load_signer(signer)?; - load_token_account(beneficiary_info, Some(&signer.key), &MINT_ADDRESS, true)?; + signer_info.is_signer()?; + load_token_account( + beneficiary_info, + Some(&signer_info.key), + &MINT_ADDRESS, + true, + )?; load_mint(mint_info, MINT_ADDRESS, true)?; load_mint(mint_v1_info, MINT_V1_ADDRESS, true)?; - load_token_account(sender_info, Some(signer.key), &MINT_V1_ADDRESS, true)?; - load_program(token_program, spl_token::id())?; + load_token_account(sender_info, Some(signer_info.key), &MINT_V1_ADDRESS, true)?; + token_program.is_program(&spl_token::ID)?; // Burn v1 tokens solana_program::program::invoke( @@ -31,15 +36,15 @@ pub fn process_upgrade(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResu &spl_token::id(), sender_info.key, mint_v1_info.key, - signer.key, - &[signer.key], + signer_info.key, + &[signer_info.key], amount, )?, &[ token_program.clone(), sender_info.clone(), mint_v1_info.clone(), - signer.clone(), + signer_info.clone(), ], )?; From be20034e576ceae074576ec1a8eb41fd617a28e4 Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Fri, 27 Sep 2024 00:22:32 +0000 Subject: [PATCH 02/18] continue migration --- Cargo.lock | 2 +- Cargo.toml | 2 +- api/src/error.rs | 2 - api/src/event.rs | 1 - api/src/loaders.rs | 211 ++------------------------------------ api/src/sdk.rs | 7 +- api/src/state/bus.rs | 28 ----- api/src/state/config.rs | 7 -- api/src/state/mod.rs | 24 ++++- api/src/state/proof.rs | 9 -- api/src/state/treasury.rs | 9 -- program/src/claim.rs | 15 +-- program/src/close.rs | 16 ++- program/src/initialize.rs | 64 ++++++++---- program/src/mine.rs | 21 ++-- program/src/open.rs | 3 +- program/src/reset.rs | 63 +++++++----- program/src/stake.rs | 14 ++- program/src/update.rs | 13 ++- program/src/upgrade.rs | 27 +++-- 20 files changed, 175 insertions(+), 363 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8758d26..19d48f8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2211,7 +2211,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "steel" -version = "0.1.5" +version = "1.0.0" dependencies = [ "bytemuck", "num_enum", diff --git a/Cargo.toml b/Cargo.toml index 134951f..7ea337d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ solana-program = "^1.18" spl-token = { version = "^4", features = ["no-entrypoint"] } spl-associated-token-account = { version = "^2.3", features = [ "no-entrypoint" ] } static_assertions = "1.1.0" -steel = { features = ["spl"], version = "0.1.0" } +steel = { features = ["spl"], version = "1.0" } thiserror = "1.0.57" diff --git a/api/src/error.rs b/api/src/error.rs index 408681d..33fdb75 100644 --- a/api/src/error.rs +++ b/api/src/error.rs @@ -1,6 +1,4 @@ -use num_enum::IntoPrimitive; use steel::*; -use thiserror::Error; #[derive(Debug, Error, Clone, Copy, PartialEq, Eq, IntoPrimitive)] #[repr(u32)] diff --git a/api/src/event.rs b/api/src/event.rs index b7068b3..28b266d 100644 --- a/api/src/event.rs +++ b/api/src/event.rs @@ -1,4 +1,3 @@ -use bytemuck::{Pod, Zeroable}; use steel::*; #[repr(C)] diff --git a/api/src/loaders.rs b/api/src/loaders.rs index 77fa46a..ebc7383 100644 --- a/api/src/loaders.rs +++ b/api/src/loaders.rs @@ -1,223 +1,28 @@ -use solana_program::{account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey}; use steel::*; use crate::{ consts::*, - state::{Bus, Config, Proof, Treasury}, + state::{Config, Treasury}, }; -/// Errors if: -/// - Owner is not Ore program. -/// - Address does not match the expected bus address. -/// - Data is empty. -/// - Data cannot deserialize into a bus account. -/// - Bus ID does not match the expected ID. -/// - Expected to be writable, but is not. -pub fn load_bus(info: &AccountInfo<'_>, id: u64, is_writable: bool) -> Result<(), ProgramError> { - if info.owner.ne(&crate::id()) { - return Err(ProgramError::InvalidAccountOwner); - } - - if info.key.ne(&BUS_ADDRESSES[id as usize]) { - return Err(ProgramError::InvalidSeeds); - } - - if info.data_is_empty() { - return Err(ProgramError::UninitializedAccount); - } - - let bus_data = info.data.borrow(); - let bus = Bus::try_from_bytes(&bus_data)?; - - if bus.id.ne(&id) { - return Err(ProgramError::InvalidAccountData); - } - - if is_writable && !info.is_writable { - return Err(ProgramError::InvalidAccountData); - } - - Ok(()) -} - -/// Errors if: -/// - Owner is not Ore program. -/// - Data is empty. -/// - Data cannot deserialize into a bus account. -/// - Bus ID is not in the expected range. -/// - Address is not in set of valid bus address. -/// - Expected to be writable, but is not. -pub fn load_any_bus(info: &AccountInfo<'_>, is_writable: bool) -> Result<(), ProgramError> { - if info.owner.ne(&crate::id()) { - return Err(ProgramError::InvalidAccountOwner); - } - - if info.data_is_empty() { - return Err(ProgramError::UninitializedAccount); - } - - if info.data.borrow()[0].ne(&(Bus::discriminator() as u8)) { - return Err(solana_program::program_error::ProgramError::InvalidAccountData); - } - - if !BUS_ADDRESSES.contains(info.key) { - return Err(ProgramError::InvalidSeeds); - } - - if is_writable && !info.is_writable { - return Err(ProgramError::InvalidAccountData); - } - - Ok(()) -} - -/// Errors if: -/// - Owner is not Ore program. -/// - Address does not match the expected address. -/// - Data is empty. -/// - Data cannot deserialize into a config account. -/// - Expected to be writable, but is not. -pub fn load_config(info: &AccountInfo<'_>, is_writable: bool) -> Result<(), ProgramError> { - if info.owner.ne(&crate::id()) { - return Err(ProgramError::InvalidAccountOwner); - } - - if info.key.ne(&CONFIG_ADDRESS) { - return Err(ProgramError::InvalidSeeds); - } - - if info.data_is_empty() { - return Err(ProgramError::UninitializedAccount); - } - - if info.data.borrow()[0].ne(&(Config::discriminator() as u8)) { - return Err(solana_program::program_error::ProgramError::InvalidAccountData); - } - - if is_writable && !info.is_writable { - return Err(ProgramError::InvalidAccountData); - } - - Ok(()) -} - -/// Errors if: -/// - Owner is not Ore program. -/// - Data is empty. -/// - Data cannot deserialize into a proof account. -/// - Proof authority does not match the expected address. -/// - Expected to be writable, but is not. -pub fn load_proof( - info: &AccountInfo<'_>, - authority: &Pubkey, - is_writable: bool, -) -> Result<(), ProgramError> { - if info.owner.ne(&crate::id()) { - return Err(ProgramError::InvalidAccountOwner); - } - - if info.data_is_empty() { - return Err(ProgramError::UninitializedAccount); - } - - let proof_data = info.data.borrow(); - let proof = Proof::try_from_bytes(&proof_data)?; - - if proof.authority.ne(&authority) { - return Err(ProgramError::InvalidAccountData); - } - - if is_writable && !info.is_writable { - return Err(ProgramError::InvalidAccountData); - } - - Ok(()) -} - -/// Errors if: -/// - Owner is not Ore program. -/// - Data is empty. -/// - Data cannot deserialize into a proof account. -/// - Proof miner does not match the expected address. -/// - Expected to be writable, but is not. -pub fn load_proof_with_miner( - info: &AccountInfo<'_>, - miner: &Pubkey, - is_writable: bool, -) -> Result<(), ProgramError> { - if info.owner.ne(&crate::id()) { - return Err(ProgramError::InvalidAccountOwner); - } - - if info.data_is_empty() { - return Err(ProgramError::UninitializedAccount); - } - - let proof_data = info.data.borrow(); - let proof = Proof::try_from_bytes(&proof_data)?; - - if proof.miner.ne(&miner) { - return Err(ProgramError::InvalidAccountData); - } - - if is_writable && !info.is_writable { - return Err(ProgramError::InvalidAccountData); - } - - Ok(()) -} - -/// Errors if: -/// - Owner is not Ore program. -/// - Data is empty. -/// - Data cannot deserialize into a proof account. -/// - Expected to be writable, but is not. -pub fn load_any_proof(info: &AccountInfo<'_>, is_writable: bool) -> Result<(), ProgramError> { - if info.owner.ne(&crate::id()) { - return Err(ProgramError::InvalidAccountOwner); - } - - if info.data_is_empty() { - return Err(ProgramError::UninitializedAccount); - } - - if info.data.borrow()[0].ne(&(Proof::discriminator() as u8)) { - return Err(solana_program::program_error::ProgramError::InvalidAccountData); - } - - if is_writable && !info.is_writable { - return Err(ProgramError::InvalidAccountData); - } - - Ok(()) -} - pub trait OreAccountInfoValidation { fn is_config(&self) -> Result<&Self, ProgramError>; fn is_treasury(&self) -> Result<&Self, ProgramError>; + fn is_treasury_tokens(&self) -> Result<&Self, ProgramError>; } -impl<'a> OreAccountInfoValidation for AccountInfo<'a> { +impl OreAccountInfoValidation for AccountInfo<'_> { fn is_config(&self) -> Result<&Self, ProgramError> { self.has_address(&CONFIG_ADDRESS)? - .has_owner(&crate::ID)? - .is_type::() + .is_type::(&crate::ID) } fn is_treasury(&self) -> Result<&Self, ProgramError> { self.has_address(&TREASURY_ADDRESS)? - .has_owner(&crate::ID)? - .is_type::() - } -} - -/// Errors if: -/// - Address does not match the expected treasury tokens address. -/// - Cannot load as a token account -pub fn load_treasury_tokens(info: &AccountInfo<'_>, is_writable: bool) -> Result<(), ProgramError> { - if info.key.ne(&TREASURY_TOKENS_ADDRESS) { - return Err(ProgramError::InvalidSeeds); + .is_type::(&crate::ID) } - load_token_account(info, Some(&TREASURY_ADDRESS), &MINT_ADDRESS, is_writable) + fn is_treasury_tokens(&self) -> Result<&Self, ProgramError> { + self.has_address(&TREASURY_TOKENS_ADDRESS) + } } diff --git a/api/src/sdk.rs b/api/src/sdk.rs index 67793dc..602a4f6 100644 --- a/api/src/sdk.rs +++ b/api/src/sdk.rs @@ -1,9 +1,6 @@ use drillx::Solution; -use solana_program::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - system_program, sysvar, -}; +use solana_program::{system_program, sysvar}; +use steel::*; use crate::{ consts::*, diff --git a/api/src/state/bus.rs b/api/src/state/bus.rs index f92f715..bf32edc 100644 --- a/api/src/state/bus.rs +++ b/api/src/state/bus.rs @@ -1,7 +1,5 @@ use steel::*; -use crate::consts::BUS; - use super::OreAccount; /// Bus accounts are responsible for distributing mining rewards. There are 8 busses total @@ -23,30 +21,4 @@ pub struct Bus { pub top_balance: u64, } -/// Fetch the PDA of a bus account. -pub fn bus_pda(id: u8) -> (Pubkey, u8) { - Pubkey::find_program_address(&[BUS, &[id]], &crate::id()) -} - -impl<'a> From<&'a [u8]> for &'a Bus { - fn from(value: &'a [u8]) -> &'a Bus { - Bus::try_from_bytes(value).unwrap() - } -} - -impl<'a> From<*const u8> for &'a Bus { - fn from(value: *const u8) -> &'a Bus { - unsafe { - if Bus::discriminator().ne(&value.add(0).read()) { - panic!(""); - } - bytemuck::try_from_bytes::(std::slice::from_raw_parts( - value.add(8), - std::mem::size_of::(), - )) - .expect("") - } - } -} - account!(OreAccount, Bus); diff --git a/api/src/state/config.rs b/api/src/state/config.rs index 64bbf8c..52b21cc 100644 --- a/api/src/state/config.rs +++ b/api/src/state/config.rs @@ -1,7 +1,5 @@ use steel::*; -use crate::consts::CONFIG; - use super::OreAccount; /// Config is a singleton account which manages program global variables. @@ -21,9 +19,4 @@ pub struct Config { pub top_balance: u64, } -/// Derive the PDA of the config account. -pub fn config_pda() -> (Pubkey, u8) { - Pubkey::find_program_address(&[CONFIG], &crate::id()) -} - account!(OreAccount, Config); diff --git a/api/src/state/mod.rs b/api/src/state/mod.rs index 6803553..20baa13 100644 --- a/api/src/state/mod.rs +++ b/api/src/state/mod.rs @@ -8,7 +8,9 @@ pub use config::*; pub use proof::*; pub use treasury::*; -use num_enum::{IntoPrimitive, TryFromPrimitive}; +use steel::*; + +use crate::consts::*; #[repr(u8)] #[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)] @@ -18,3 +20,23 @@ pub enum OreAccount { Proof = 102, Treasury = 103, } + +/// Fetch the PDA of a bus account. +pub fn bus_pda(id: u8) -> (Pubkey, u8) { + Pubkey::find_program_address(&[BUS, &[id]], &crate::id()) +} + +/// Derive the PDA of the config account. +pub fn config_pda() -> (Pubkey, u8) { + Pubkey::find_program_address(&[CONFIG], &crate::id()) +} + +/// Derive the PDA of a proof account. +pub fn proof_pda(authority: Pubkey) -> (Pubkey, u8) { + Pubkey::find_program_address(&[PROOF, authority.as_ref()], &crate::id()) +} + +/// Derive the PDA of the treasury account. +pub fn treasury_pda() -> (Pubkey, u8) { + Pubkey::find_program_address(&[TREASURY], &crate::id()) +} diff --git a/api/src/state/proof.rs b/api/src/state/proof.rs index 33c0f4a..733e115 100644 --- a/api/src/state/proof.rs +++ b/api/src/state/proof.rs @@ -1,9 +1,5 @@ -use bytemuck::{Pod, Zeroable}; -use solana_program::pubkey::Pubkey; use steel::*; -use crate::consts::PROOF; - use super::OreAccount; /// Proof accounts track a miner's current hash, claimable rewards, and lifetime stats. @@ -39,9 +35,4 @@ pub struct Proof { pub total_rewards: u64, } -/// Derive the PDA of a proof account. -pub fn proof_pda(authority: Pubkey) -> (Pubkey, u8) { - Pubkey::find_program_address(&[PROOF, authority.as_ref()], &crate::id()) -} - account!(OreAccount, Proof); diff --git a/api/src/state/treasury.rs b/api/src/state/treasury.rs index 289fc35..2268ae0 100644 --- a/api/src/state/treasury.rs +++ b/api/src/state/treasury.rs @@ -1,9 +1,5 @@ -use bytemuck::{Pod, Zeroable}; -use solana_program::pubkey::Pubkey; use steel::*; -use crate::consts::TREASURY; - use super::OreAccount; /// Treasury is a singleton account which is the mint authority for the ORE token and the authority of @@ -12,9 +8,4 @@ use super::OreAccount; #[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)] pub struct Treasury {} -/// Derive the PDA of the treasury account. -pub fn treasury_pda() -> (Pubkey, u8) { - Pubkey::find_program_address(&[TREASURY], &crate::id()) -} - account!(OreAccount, Treasury); diff --git a/program/src/claim.rs b/program/src/claim.rs index 9f564b8..6e594fb 100644 --- a/program/src/claim.rs +++ b/program/src/claim.rs @@ -17,15 +17,18 @@ pub fn process_claim(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult return Err(ProgramError::NotEnoughAccountKeys); }; signer.is_signer()?; - load_token_account(beneficiary_info, None, &MINT_ADDRESS, true)?; - load_proof(proof_info, signer.key, true)?; + beneficiary_info + .is_writable()? + .to_token_account()? + .check(|t| t.mint.eq(&MINT_ADDRESS))?; + let proof = proof_info + .to_account_mut::(&ore_api::ID)? + .check_mut(|p| p.authority == *signer.key)?; treasury_info.is_treasury()?; - load_treasury_tokens(treasury_tokens_info, true)?; - token_program.has_address(&spl_token::ID)?; + treasury_tokens_info.is_writable()?.is_treasury_tokens()?; + token_program.is_program(&spl_token::ID)?; // Update miner balance. - let mut proof_data = proof_info.data.borrow_mut(); - let proof = Proof::try_from_bytes_mut(&mut proof_data)?; proof.balance = proof .balance .checked_sub(amount) diff --git a/program/src/close.rs b/program/src/close.rs index 4201b5f..94e63e4 100644 --- a/program/src/close.rs +++ b/program/src/close.rs @@ -1,4 +1,4 @@ -use ore_api::{loaders::*, state::Proof}; +use ore_api::state::Proof; use solana_program::{ account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError, system_program, @@ -12,17 +12,13 @@ pub fn process_close(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul return Err(ProgramError::NotEnoughAccountKeys); }; signer_info.is_signer()?; - load_proof(proof_info, signer_info.key, true)?; + proof_info + .is_writable()? + .to_account::(&ore_api::ID)? + .check(|p| p.authority == *signer_info.key)? + .check(|p| p.balance > 0)?; system_program.is_program(&system_program::ID)?; - // Validate balance is zero. - let proof_data = proof_info.data.borrow(); - let proof = Proof::try_from_bytes(&proof_data)?; - if proof.balance.gt(&0) { - return Err(ProgramError::InvalidAccountData); - } - drop(proof_data); - // Realloc data to zero. proof_info.realloc(0, true)?; diff --git a/program/src/initialize.rs b/program/src/initialize.rs index 16bd2d0..d331c14 100644 --- a/program/src/initialize.rs +++ b/program/src/initialize.rs @@ -24,26 +24,50 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramR return Err(ProgramError::NotEnoughAccountKeys); }; signer_info.is_signer()?.has_address(&INITIALIZER_ADDRESS)?; - bus_0_info.is_empty_pda(&[BUS, &[0]], args.bus_0_bump, &ore_api::ID)?; - bus_1_info.is_empty_pda(&[BUS, &[1]], args.bus_1_bump, &ore_api::ID)?; - bus_2_info.is_empty_pda(&[BUS, &[2]], args.bus_2_bump, &ore_api::ID)?; - bus_3_info.is_empty_pda(&[BUS, &[3]], args.bus_3_bump, &ore_api::ID)?; - bus_4_info.is_empty_pda(&[BUS, &[4]], args.bus_4_bump, &ore_api::ID)?; - bus_5_info.is_empty_pda(&[BUS, &[5]], args.bus_5_bump, &ore_api::ID)?; - bus_6_info.is_empty_pda(&[BUS, &[6]], args.bus_6_bump, &ore_api::ID)?; - bus_7_info.is_empty_pda(&[BUS, &[7]], args.bus_7_bump, &ore_api::ID)?; - config_info.is_empty_pda(&[CONFIG], args.config_bump, &ore_api::id())?; - metadata_info.is_empty_pda( - &[ - METADATA, - mpl_token_metadata::ID.as_ref(), - MINT_ADDRESS.as_ref(), - ], - args.metadata_bump, - &mpl_token_metadata::ID, - )?; - mint_info.is_empty_pda(&[MINT, MINT_NOISE.as_slice()], args.mint_bump, &ore_api::ID)?; - treasury_info.is_empty_pda(&[TREASURY], args.treasury_bump, &ore_api::ID)?; + bus_0_info + .has_seeds(&[BUS, &[0]], args.bus_0_bump, &ore_api::ID)? + .is_empty()?; + bus_1_info + .has_seeds(&[BUS, &[1]], args.bus_1_bump, &ore_api::ID)? + .is_empty()?; + bus_2_info + .has_seeds(&[BUS, &[2]], args.bus_2_bump, &ore_api::ID)? + .is_empty()?; + bus_3_info + .has_seeds(&[BUS, &[3]], args.bus_3_bump, &ore_api::ID)? + .is_empty()?; + bus_4_info + .has_seeds(&[BUS, &[4]], args.bus_4_bump, &ore_api::ID)? + .is_empty()?; + bus_5_info + .has_seeds(&[BUS, &[5]], args.bus_5_bump, &ore_api::ID)? + .is_empty()?; + bus_6_info + .has_seeds(&[BUS, &[6]], args.bus_6_bump, &ore_api::ID)? + .is_empty()?; + bus_7_info + .has_seeds(&[BUS, &[7]], args.bus_7_bump, &ore_api::ID)? + .is_empty()?; + config_info + .has_seeds(&[CONFIG], args.config_bump, &ore_api::ID)? + .is_empty()?; + metadata_info + .has_seeds( + &[ + METADATA, + mpl_token_metadata::ID.as_ref(), + MINT_ADDRESS.as_ref(), + ], + args.metadata_bump, + &mpl_token_metadata::ID, + )? + .is_empty()?; + mint_info + .has_seeds(&[MINT, MINT_NOISE.as_slice()], args.mint_bump, &ore_api::ID)? + .is_empty()?; + treasury_info + .has_seeds(&[TREASURY], args.treasury_bump, &ore_api::ID)? + .is_empty()?; treasury_tokens_info.is_empty()?; system_program.is_program(&system_program::ID)?; token_program.is_program(&spl_token::ID)?; diff --git a/program/src/mine.rs b/program/src/mine.rs index cf5cf2d..b5af8db 100644 --- a/program/src/mine.rs +++ b/program/src/mine.rs @@ -6,7 +6,6 @@ use ore_api::{ error::OreError, event::MineEvent, instruction::Mine, - loaders::*, state::{Bus, Config, Proof}, }; use solana_program::program::set_return_data; @@ -37,9 +36,11 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult { return Err(ProgramError::NotEnoughAccountKeys); }; signer.is_signer()?; - bus_info.is_type::()?.is_writable()?; - config_info.is_config()?; - load_proof_with_miner(proof_info, signer.key, true)?; + let bus = bus_info.to_account_mut::(&ore_api::ID)?; + let config = config_info.to_account::(&ore_api::ID)?; + let proof = proof_info + .to_account_mut::(&ore_api::ID)? + .check_mut(|p| p.authority.eq(signer.key))?; instructions_sysvar.is_sysvar(&sysvar::instructions::ID)?; slot_hashes_sysvar.is_sysvar(&sysvar::slot_hashes::ID)?; @@ -50,8 +51,8 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult { authenticate(&instructions_sysvar.data.borrow(), proof_info.key)?; // Validate epoch is active. - let config_data = config_info.data.borrow(); - let config = Config::try_from_bytes(&config_data)?; + // let config_data = config_info.data.borrow(); + // let config = Config::try_from_bytes(&config_data)?; let clock = Clock::get().or(Err(ProgramError::InvalidAccountData))?; if config .last_reset_at @@ -65,8 +66,8 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult { // // Here we use drillx to validate the provided solution is a valid hash of the challenge. // If invalid, we return an error. - let mut proof_data = proof_info.data.borrow_mut(); - let proof = Proof::try_from_bytes_mut(&mut proof_data)?; + // let mut proof_data = proof_info.data.borrow_mut(); + // let proof = Proof::try_from_bytes_mut(&mut proof_data)?; let solution = Solution::new(args.digest, args.nonce); if !solution.is_valid(&proof.challenge) { return Err(OreError::HashInvalid.into()); @@ -110,8 +111,8 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult { // If user has greater than or equal to the max stake on the network, they receive 2x multiplier. // Any stake less than this will receives between 1x and 2x multipler. The multipler is only active // if the miner's last stake deposit was more than one minute ago to protect against flash loan attacks. - let mut bus_data = bus_info.data.borrow_mut(); - let bus = Bus::try_from_bytes_mut(&mut bus_data)?; + // let mut bus_data = bus_info.data.borrow_mut(); + // let bus = Bus::try_from_bytes_mut(&mut bus_data)?; if proof.balance.gt(&0) && proof.last_stake_at.saturating_add(ONE_MINUTE).lt(&t) { // Calculate staking reward. if config.top_balance.gt(&0) { diff --git a/program/src/open.rs b/program/src/open.rs index e2c99e3..a89dbea 100644 --- a/program/src/open.rs +++ b/program/src/open.rs @@ -27,7 +27,8 @@ pub fn process_open(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult signer_info.is_signer()?; payer_info.is_signer()?; proof_info - .is_empty_pda(&[PROOF, signer_info.key.as_ref()], args.bump, &ore_api::ID)? + .has_seeds(&[PROOF, signer_info.key.as_ref()], args.bump, &ore_api::ID)? + .is_empty()? .is_writable()?; system_program.is_program(&system_program::ID)?; slot_hashes_info.is_sysvar(&sysvar::slot_hashes::ID)?; diff --git a/program/src/reset.rs b/program/src/reset.rs index ffb282c..fccb2f3 100644 --- a/program/src/reset.rs +++ b/program/src/reset.rs @@ -4,11 +4,7 @@ use ore_api::{ loaders::*, state::{Bus, Config}, }; -use solana_program::{ - account_info::AccountInfo, clock::Clock, entrypoint::ProgramResult, - program_error::ProgramError, program_pack::Pack, sysvar::Sysvar, -}; -use spl_token::state::Mint; +use solana_program::clock::Clock; use steel::*; /// Reset tops up the bus balances, updates the base reward rate, and sets up the ORE program for the next epoch. @@ -20,27 +16,42 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul return Err(ProgramError::NotEnoughAccountKeys); }; signer_info.is_signer()?; - load_bus(bus_0_info, 0, true)?; - load_bus(bus_1_info, 1, true)?; - load_bus(bus_2_info, 2, true)?; - load_bus(bus_3_info, 3, true)?; - load_bus(bus_4_info, 4, true)?; - load_bus(bus_5_info, 5, true)?; - load_bus(bus_6_info, 6, true)?; - load_bus(bus_7_info, 7, true)?; - config_info.is_config()?.is_writable()?; - load_mint(mint_info, MINT_ADDRESS, true)?; + let bus_0 = bus_0_info + .to_account_mut::(&ore_api::ID)? + .check_mut(|b| b.id == 0)?; + let bus_1 = bus_1_info + .to_account_mut::(&ore_api::ID)? + .check_mut(|b| b.id == 1)?; + let bus_2 = bus_2_info + .to_account_mut::(&ore_api::ID)? + .check_mut(|b| b.id == 2)?; + let bus_3 = bus_3_info + .to_account_mut::(&ore_api::ID)? + .check_mut(|b| b.id == 3)?; + let bus_4 = bus_4_info + .to_account_mut::(&ore_api::ID)? + .check_mut(|b| b.id == 4)?; + let bus_5 = bus_5_info + .to_account_mut::(&ore_api::ID)? + .check_mut(|b| b.id == 5)?; + let bus_6 = bus_6_info + .to_account_mut::(&ore_api::ID)? + .check_mut(|b| b.id == 6)?; + let bus_7 = bus_7_info + .to_account_mut::(&ore_api::ID)? + .check_mut(|b| b.id == 7)?; + let config = config_info.to_account_mut::(&ore_api::ID)?; + let mint = mint_info + .has_address(&MINT_ADDRESS)? + .is_writable()? + .to_mint()?; treasury_info.is_treasury()?.is_writable()?; - load_treasury_tokens(treasury_tokens_info, true)?; + treasury_tokens_info.is_treasury_tokens()?.is_writable()?; token_program.is_program(&spl_token::ID)?; - let busses: [&AccountInfo; BUS_COUNT] = [ - bus_0_info, bus_1_info, bus_2_info, bus_3_info, bus_4_info, bus_5_info, bus_6_info, - bus_7_info, - ]; // Validate enough time has passed since the last reset. - let mut config_data = config_info.data.borrow_mut(); - let config = Config::try_from_bytes_mut(&mut config_data)?; + // let mut config_data = config_info.data.borrow_mut(); + // let config = Config::try_from_bytes_mut(&mut config_data)?; let clock = Clock::get().or(Err(ProgramError::InvalidAccountData))?; if config .last_reset_at @@ -54,14 +65,11 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul config.last_reset_at = clock.unix_timestamp; // Reset bus accounts and calculate actual rewards mined since last reset. + let busses = [bus_0, bus_1, bus_2, bus_3, bus_4, bus_5, bus_6, bus_7]; let mut total_remaining_rewards = 0u64; let mut total_theoretical_rewards = 0u64; let mut top_balance = 0u64; - for i in 0..BUS_COUNT { - // Parse bus account. - let mut bus_data = busses[i].data.borrow_mut(); - let bus = Bus::try_from_bytes_mut(&mut bus_data)?; - + for bus in busses { // Track top balance. if bus.top_balance.gt(&top_balance) { top_balance = bus.top_balance; @@ -99,7 +107,6 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul } // Max supply check. - let mint = Mint::unpack(&mint_info.data.borrow()).expect("Failed to parse mint"); if mint.supply.ge(&MAX_SUPPLY) { return Err(OreError::MaxSupply.into()); } diff --git a/program/src/stake.rs b/program/src/stake.rs index 94fef15..9a4ac41 100644 --- a/program/src/stake.rs +++ b/program/src/stake.rs @@ -17,14 +17,18 @@ pub fn process_stake(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult return Err(ProgramError::NotEnoughAccountKeys); }; signer_info.is_signer()?; - load_proof(proof_info, signer_info.key, true)?; - load_token_account(sender_info, Some(signer_info.key), &MINT_ADDRESS, true)?; - load_treasury_tokens(treasury_tokens_info, true)?; + let proof = proof_info + .to_account_mut::(&ore_api::ID)? + .check_mut(|p| p.authority == *signer_info.key)?; + sender_info + .is_writable()? + .to_token_account()? + .check(|t| t.owner.eq(signer_info.key))? + .check(|t| t.mint.eq(&MINT_ADDRESS))?; + treasury_tokens_info.is_writable()?.is_treasury_tokens()?; token_program.is_program(&spl_token::ID)?; // Update the proof balance. - let mut proof_data = proof_info.data.borrow_mut(); - let proof = Proof::try_from_bytes_mut(&mut proof_data)?; proof.balance = proof.balance.checked_add(amount).unwrap(); // Update deposit timestamp. diff --git a/program/src/update.rs b/program/src/update.rs index 849eb1a..b101a3e 100644 --- a/program/src/update.rs +++ b/program/src/update.rs @@ -1,4 +1,4 @@ -use ore_api::{loaders::*, state::Proof}; +use ore_api::state::Proof; use solana_program::{ account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError, }; @@ -7,16 +7,15 @@ use steel::*; /// Update changes the miner authority on a proof account. pub fn process_update(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult { // Load accounts. - let [signer, miner_info, proof_info] = accounts else { + let [signer_info, miner_info, proof_info] = accounts else { return Err(ProgramError::NotEnoughAccountKeys); }; - signer.is_signer()?; - // load_any(miner_info, false)?; - load_proof(proof_info, signer.key, true)?; + signer_info.is_signer()?; + let proof = proof_info + .to_account_mut::(&ore_api::ID)? + .check_mut(|p| p.authority == *signer_info.key)?; // Update the proof's miner authority. - let mut proof_data = proof_info.data.borrow_mut(); - let proof = Proof::try_from_bytes_mut(&mut proof_data)?; proof.miner = *miner_info.key; Ok(()) diff --git a/program/src/upgrade.rs b/program/src/upgrade.rs index d3b2220..f530d2b 100644 --- a/program/src/upgrade.rs +++ b/program/src/upgrade.rs @@ -19,15 +19,24 @@ pub fn process_upgrade(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResu return Err(ProgramError::NotEnoughAccountKeys); }; signer_info.is_signer()?; - load_token_account( - beneficiary_info, - Some(&signer_info.key), - &MINT_ADDRESS, - true, - )?; - load_mint(mint_info, MINT_ADDRESS, true)?; - load_mint(mint_v1_info, MINT_V1_ADDRESS, true)?; - load_token_account(sender_info, Some(signer_info.key), &MINT_V1_ADDRESS, true)?; + beneficiary_info + .is_writable()? + .to_token_account()? + .check(|t| t.owner.eq(signer_info.key))? + .check(|t| t.mint.eq(&MINT_ADDRESS))?; + mint_info + .is_writable()? + .has_address(&MINT_ADDRESS)? + .to_mint()?; + mint_v1_info + .is_writable()? + .has_address(&MINT_V1_ADDRESS)? + .to_mint()?; + sender_info + .is_writable()? + .to_token_account()? + .check(|t| t.owner.eq(signer_info.key))? + .check(|t| t.mint.eq(&MINT_V1_ADDRESS))?; token_program.is_program(&spl_token::ID)?; // Burn v1 tokens From 4db7f970b226dffa5268b6b0a3c787f39b495555 Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Fri, 27 Sep 2024 01:26:26 +0000 Subject: [PATCH 03/18] cleanup --- Cargo.lock | 2 +- program/src/claim.rs | 8 ++++---- program/src/mine.rs | 6 +++--- program/src/upgrade.rs | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 19d48f8..06734de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2211,7 +2211,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "steel" -version = "1.0.0" +version = "1.1.0" dependencies = [ "bytemuck", "num_enum", diff --git a/program/src/claim.rs b/program/src/claim.rs index 6e594fb..8668190 100644 --- a/program/src/claim.rs +++ b/program/src/claim.rs @@ -11,19 +11,19 @@ pub fn process_claim(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult let amount = u64::from_le_bytes(args.amount); // Load accounts. - let [signer, beneficiary_info, proof_info, treasury_info, treasury_tokens_info, token_program] = + let [signer_info, beneficiary_info, proof_info, treasury_info, treasury_tokens_info, token_program] = accounts else { return Err(ProgramError::NotEnoughAccountKeys); }; - signer.is_signer()?; + signer_info.is_signer()?; beneficiary_info .is_writable()? .to_token_account()? - .check(|t| t.mint.eq(&MINT_ADDRESS))?; + .check(|t| t.mint == MINT_ADDRESS)?; let proof = proof_info .to_account_mut::(&ore_api::ID)? - .check_mut(|p| p.authority == *signer.key)?; + .check_mut(|p| p.authority == *signer_info.key)?; treasury_info.is_treasury()?; treasury_tokens_info.is_writable()?.is_treasury_tokens()?; token_program.is_program(&spl_token::ID)?; diff --git a/program/src/mine.rs b/program/src/mine.rs index b5af8db..1fb35e6 100644 --- a/program/src/mine.rs +++ b/program/src/mine.rs @@ -30,17 +30,17 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult { let args = Mine::try_from_bytes(data)?; // Load accounts. - let [signer, bus_info, config_info, proof_info, instructions_sysvar, slot_hashes_sysvar] = + let [signer_info, bus_info, config_info, proof_info, instructions_sysvar, slot_hashes_sysvar] = accounts else { return Err(ProgramError::NotEnoughAccountKeys); }; - signer.is_signer()?; + signer_info.is_signer()?; let bus = bus_info.to_account_mut::(&ore_api::ID)?; let config = config_info.to_account::(&ore_api::ID)?; let proof = proof_info .to_account_mut::(&ore_api::ID)? - .check_mut(|p| p.authority.eq(signer.key))?; + .check_mut(|p| p.miner == *signer_info.key)?; instructions_sysvar.is_sysvar(&sysvar::instructions::ID)?; slot_hashes_sysvar.is_sysvar(&sysvar::slot_hashes::ID)?; diff --git a/program/src/upgrade.rs b/program/src/upgrade.rs index f530d2b..202eb53 100644 --- a/program/src/upgrade.rs +++ b/program/src/upgrade.rs @@ -22,8 +22,8 @@ pub fn process_upgrade(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResu beneficiary_info .is_writable()? .to_token_account()? - .check(|t| t.owner.eq(signer_info.key))? - .check(|t| t.mint.eq(&MINT_ADDRESS))?; + .check(|t| t.owner == *signer_info.key)? + .check(|t| t.mint == MINT_ADDRESS)?; mint_info .is_writable()? .has_address(&MINT_ADDRESS)? @@ -35,8 +35,8 @@ pub fn process_upgrade(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResu sender_info .is_writable()? .to_token_account()? - .check(|t| t.owner.eq(signer_info.key))? - .check(|t| t.mint.eq(&MINT_V1_ADDRESS))?; + .check(|t| t.owner == *signer_info.key)? + .check(|t| t.mint == MINT_V1_ADDRESS)?; token_program.is_program(&spl_token::ID)?; // Burn v1 tokens From a9e445ad36f28de520199a803656d91c9b78bc59 Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Fri, 27 Sep 2024 02:40:50 +0000 Subject: [PATCH 04/18] use const pubkey --- api/src/sdk.rs | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/api/src/sdk.rs b/api/src/sdk.rs index 602a4f6..e6ccd5d 100644 --- a/api/src/sdk.rs +++ b/api/src/sdk.rs @@ -20,10 +20,6 @@ pub fn auth(proof: Pubkey) -> Instruction { /// Builds a claim instruction. pub fn claim(signer: Pubkey, beneficiary: Pubkey, amount: u64) -> Instruction { let proof = proof_pda(signer).0; - let treasury_tokens = spl_associated_token_account::get_associated_token_address( - &TREASURY_ADDRESS, - &MINT_ADDRESS, - ); Instruction { program_id: crate::id(), accounts: vec![ @@ -31,7 +27,7 @@ pub fn claim(signer: Pubkey, beneficiary: Pubkey, amount: u64) -> Instruction { AccountMeta::new(beneficiary, false), AccountMeta::new(proof, false), AccountMeta::new_readonly(TREASURY_ADDRESS, false), - AccountMeta::new(treasury_tokens, false), + AccountMeta::new(TREASURY_TOKENS_ADDRESS, false), AccountMeta::new_readonly(spl_token::id(), false), ], data: Claim { @@ -95,10 +91,6 @@ pub fn open(signer: Pubkey, miner: Pubkey, payer: Pubkey) -> Instruction { /// Builds a reset instruction. pub fn reset(signer: Pubkey) -> Instruction { - let treasury_tokens = spl_associated_token_account::get_associated_token_address( - &TREASURY_ADDRESS, - &MINT_ADDRESS, - ); Instruction { program_id: crate::id(), accounts: vec![ @@ -114,7 +106,7 @@ pub fn reset(signer: Pubkey) -> Instruction { AccountMeta::new(CONFIG_ADDRESS, false), AccountMeta::new(MINT_ADDRESS, false), AccountMeta::new(TREASURY_ADDRESS, false), - AccountMeta::new(treasury_tokens, false), + AccountMeta::new(TREASURY_TOKENS_ADDRESS, false), AccountMeta::new_readonly(spl_token::id(), false), ], data: Reset {}.to_bytes(), @@ -124,17 +116,13 @@ pub fn reset(signer: Pubkey) -> Instruction { /// Build a stake instruction. pub fn stake(signer: Pubkey, sender: Pubkey, amount: u64) -> Instruction { let proof = proof_pda(signer).0; - let treasury_tokens = spl_associated_token_account::get_associated_token_address( - &TREASURY_ADDRESS, - &MINT_ADDRESS, - ); Instruction { program_id: crate::id(), accounts: vec![ AccountMeta::new(signer, true), AccountMeta::new(proof, false), AccountMeta::new(sender, false), - AccountMeta::new(treasury_tokens, false), + AccountMeta::new(TREASURY_TOKENS_ADDRESS, false), AccountMeta::new_readonly(spl_token::id(), false), ], data: Stake { @@ -193,8 +181,6 @@ pub fn initialize(signer: Pubkey) -> Instruction { let config_pda = config_pda(); let mint_pda = Pubkey::find_program_address(&[MINT, MINT_NOISE.as_slice()], &crate::id()); let treasury_pda = treasury_pda(); - let treasury_tokens = - spl_associated_token_account::get_associated_token_address(&treasury_pda.0, &mint_pda.0); let metadata_pda = Pubkey::find_program_address( &[ METADATA, @@ -219,7 +205,7 @@ pub fn initialize(signer: Pubkey) -> Instruction { AccountMeta::new(metadata_pda.0, false), AccountMeta::new(mint_pda.0, false), AccountMeta::new(treasury_pda.0, false), - AccountMeta::new(treasury_tokens, false), + AccountMeta::new(TREASURY_TOKENS_ADDRESS, false), AccountMeta::new_readonly(system_program::id(), false), AccountMeta::new_readonly(spl_token::id(), false), AccountMeta::new_readonly(spl_associated_token_account::id(), false), From 799676863b631fb688fefe469450744bf405833f Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Fri, 27 Sep 2024 04:42:00 +0000 Subject: [PATCH 05/18] bump steel verison --- Cargo.lock | 2 +- program/src/initialize.rs | 26 +++++++------------------- program/src/open.rs | 9 +++------ 3 files changed, 11 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 06734de..5ee7aae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2211,7 +2211,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "steel" -version = "1.1.0" +version = "1.2.0" dependencies = [ "bytemuck", "num_enum", diff --git a/program/src/initialize.rs b/program/src/initialize.rs index d331c14..b17a8eb 100644 --- a/program/src/initialize.rs +++ b/program/src/initialize.rs @@ -1,5 +1,3 @@ -use std::mem::size_of; - use ore_api::{ consts::*, instruction::*, @@ -91,17 +89,14 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramR args.bus_7_bump, ]; for i in 0..BUS_COUNT { - create_pda( + create_account::( bus_infos[i], &ore_api::id(), - 8 + size_of::(), &[BUS, &[i as u8], &[bus_bumps[i]]], system_program, signer_info, )?; - let mut bus_data = bus_infos[i].try_borrow_mut_data()?; - bus_data[0] = Bus::discriminator() as u8; - let bus = Bus::try_from_bytes_mut(&mut bus_data)?; + let bus = bus_infos[i].to_account_mut::(&ore_api::ID)?; bus.id = i as u64; bus.rewards = 0; bus.theoretical_rewards = 0; @@ -109,37 +104,30 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramR } // Initialize config. - create_pda( + create_account::( config_info, &ore_api::id(), - 8 + size_of::(), &[CONFIG, &[args.config_bump]], system_program, signer_info, )?; - let mut config_data = config_info.data.borrow_mut(); - config_data[0] = Config::discriminator() as u8; - let config = Config::try_from_bytes_mut(&mut config_data)?; + let config = config_info.to_account_mut::(&ore_api::ID)?; config.base_reward_rate = INITIAL_BASE_REWARD_RATE; config.last_reset_at = 0; config.min_difficulty = INITIAL_MIN_DIFFICULTY as u64; config.top_balance = 0; // Initialize treasury. - create_pda( + create_account::( treasury_info, &ore_api::id(), - 8 + size_of::(), &[TREASURY, &[args.treasury_bump]], system_program, signer_info, )?; - let mut treasury_data = treasury_info.data.borrow_mut(); - treasury_data[0] = Treasury::discriminator() as u8; - drop(treasury_data); // Initialize mint. - create_pda( + allocate_account( mint_info, &spl_token::id(), Mint::LEN, @@ -191,7 +179,7 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramR .invoke_signed(&[&[TREASURY, &[args.treasury_bump]]])?; // Initialize treasury token account. - create_ata( + create_associated_token_account( signer_info, treasury_info, treasury_tokens_info, diff --git a/program/src/open.rs b/program/src/open.rs index a89dbea..ceee168 100644 --- a/program/src/open.rs +++ b/program/src/open.rs @@ -34,18 +34,15 @@ pub fn process_open(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult slot_hashes_info.is_sysvar(&sysvar::slot_hashes::ID)?; // Initialize proof. - create_pda( + create_account::( proof_info, - &ore_api::id(), - 8 + size_of::(), + &ore_api::ID, &[PROOF, signer_info.key.as_ref(), &[args.bump]], system_program, payer_info, )?; let clock = Clock::get().or(Err(ProgramError::InvalidAccountData))?; - let mut proof_data = proof_info.data.borrow_mut(); - proof_data[0] = Proof::discriminator() as u8; - let proof = Proof::try_from_bytes_mut(&mut proof_data)?; + let proof = proof_info.to_account_mut::(&ore_api::ID)?; proof.authority = *signer_info.key; proof.balance = 0; proof.challenge = hashv(&[ From 5bd4a467d69330454cdf3626817a151b320e4529 Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Fri, 27 Sep 2024 07:04:29 +0000 Subject: [PATCH 06/18] cleanup imports --- program/src/claim.rs | 3 --- program/src/close.rs | 5 +---- program/src/mine.rs | 5 ----- program/src/open.rs | 4 ---- program/src/reset.rs | 1 - program/src/stake.rs | 4 ---- program/src/update.rs | 3 --- program/src/upgrade.rs | 10 +--------- 8 files changed, 2 insertions(+), 33 deletions(-) diff --git a/program/src/claim.rs b/program/src/claim.rs index 8668190..7fa8c48 100644 --- a/program/src/claim.rs +++ b/program/src/claim.rs @@ -1,7 +1,4 @@ use ore_api::{consts::*, error::OreError, instruction::*, loaders::*, state::Proof}; -use solana_program::{ - account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError, -}; use steel::*; /// Claim distributes claimable ORE from the treasury to a miner. diff --git a/program/src/close.rs b/program/src/close.rs index 94e63e4..6737ade 100644 --- a/program/src/close.rs +++ b/program/src/close.rs @@ -1,8 +1,5 @@ use ore_api::state::Proof; -use solana_program::{ - account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError, - system_program, -}; +use solana_program::system_program; use steel::*; /// Close closes a proof account and returns the rent to the owner. diff --git a/program/src/mine.rs b/program/src/mine.rs index 1fb35e6..1cdadb7 100644 --- a/program/src/mine.rs +++ b/program/src/mine.rs @@ -11,12 +11,7 @@ use ore_api::{ use solana_program::program::set_return_data; #[allow(deprecated)] use solana_program::{ - account_info::AccountInfo, - clock::Clock, - entrypoint::ProgramResult, keccak::hashv, - program_error::ProgramError, - pubkey::Pubkey, sanitize::SanitizeError, serialize_utils::{read_pubkey, read_u16}, slot_hashes::SlotHash, diff --git a/program/src/open.rs b/program/src/open.rs index ceee168..94c7dec 100644 --- a/program/src/open.rs +++ b/program/src/open.rs @@ -2,11 +2,7 @@ use std::mem::size_of; use ore_api::{consts::*, instruction::Open, state::Proof}; use solana_program::{ - account_info::AccountInfo, - clock::Clock, - entrypoint::ProgramResult, keccak::hashv, - program_error::ProgramError, slot_hashes::SlotHash, system_program, sysvar::{self, Sysvar}, diff --git a/program/src/reset.rs b/program/src/reset.rs index fccb2f3..2800139 100644 --- a/program/src/reset.rs +++ b/program/src/reset.rs @@ -4,7 +4,6 @@ use ore_api::{ loaders::*, state::{Bus, Config}, }; -use solana_program::clock::Clock; use steel::*; /// Reset tops up the bus balances, updates the base reward rate, and sets up the ORE program for the next epoch. diff --git a/program/src/stake.rs b/program/src/stake.rs index 9a4ac41..1e495dd 100644 --- a/program/src/stake.rs +++ b/program/src/stake.rs @@ -1,8 +1,4 @@ use ore_api::{consts::*, instruction::Stake, loaders::*, state::Proof}; -use solana_program::{ - account_info::AccountInfo, clock::Clock, entrypoint::ProgramResult, - program_error::ProgramError, sysvar::Sysvar, -}; use steel::*; /// Stake deposits ORE into a proof account to earn multiplier. diff --git a/program/src/update.rs b/program/src/update.rs index b101a3e..6bf6f74 100644 --- a/program/src/update.rs +++ b/program/src/update.rs @@ -1,7 +1,4 @@ use ore_api::state::Proof; -use solana_program::{ - account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError, -}; use steel::*; /// Update changes the miner authority on a proof account. diff --git a/program/src/upgrade.rs b/program/src/upgrade.rs index 202eb53..058c400 100644 --- a/program/src/upgrade.rs +++ b/program/src/upgrade.rs @@ -1,9 +1,4 @@ use ore_api::{consts::*, error::OreError, instruction::Stake}; -use solana_program::{ - account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError, - program_pack::Pack, -}; -use spl_token::state::Mint; use steel::*; /// Upgrade allows a user to migrate a v1 token to a v2 token at a 1:1 exchange rate. @@ -24,7 +19,7 @@ pub fn process_upgrade(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResu .to_token_account()? .check(|t| t.owner == *signer_info.key)? .check(|t| t.mint == MINT_ADDRESS)?; - mint_info + let mint = mint_info .is_writable()? .has_address(&MINT_ADDRESS)? .to_mint()?; @@ -62,14 +57,11 @@ pub fn process_upgrade(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResu let amount_to_mint = amount.saturating_mul(100); // Cap at max supply. - let mint_data = mint_info.data.borrow(); - let mint = Mint::unpack(&mint_data)?; if mint.supply.saturating_add(amount_to_mint).gt(&MAX_SUPPLY) { return Err(OreError::MaxSupply.into()); } // Mint to the beneficiary account - drop(mint_data); mint_to_signed( mint_info, beneficiary_info, From d41c07c999f9d7081e4021b5d3c33066e8895b66 Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Fri, 27 Sep 2024 07:07:21 +0000 Subject: [PATCH 07/18] close condition --- program/src/close.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/program/src/close.rs b/program/src/close.rs index 6737ade..4be47c0 100644 --- a/program/src/close.rs +++ b/program/src/close.rs @@ -13,7 +13,7 @@ pub fn process_close(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul .is_writable()? .to_account::(&ore_api::ID)? .check(|p| p.authority == *signer_info.key)? - .check(|p| p.balance > 0)?; + .check(|p| p.balance == 0)?; system_program.is_program(&system_program::ID)?; // Realloc data to zero. From dc401ed86c9d6e09e77a46fb87a8a0efd4aa5d36 Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Fri, 27 Sep 2024 07:09:28 +0000 Subject: [PATCH 08/18] clenaup --- program/src/initialize.rs | 68 +++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/program/src/initialize.rs b/program/src/initialize.rs index b17a8eb..99bc7d1 100644 --- a/program/src/initialize.rs +++ b/program/src/initialize.rs @@ -23,49 +23,49 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramR }; signer_info.is_signer()?.has_address(&INITIALIZER_ADDRESS)?; bus_0_info - .has_seeds(&[BUS, &[0]], args.bus_0_bump, &ore_api::ID)? - .is_empty()?; + .is_empty()? + .has_seeds(&[BUS, &[0]], args.bus_0_bump, &ore_api::ID)?; bus_1_info - .has_seeds(&[BUS, &[1]], args.bus_1_bump, &ore_api::ID)? - .is_empty()?; + .is_empty()? + .has_seeds(&[BUS, &[1]], args.bus_1_bump, &ore_api::ID)?; bus_2_info - .has_seeds(&[BUS, &[2]], args.bus_2_bump, &ore_api::ID)? - .is_empty()?; + .is_empty()? + .has_seeds(&[BUS, &[2]], args.bus_2_bump, &ore_api::ID)?; bus_3_info - .has_seeds(&[BUS, &[3]], args.bus_3_bump, &ore_api::ID)? - .is_empty()?; + .is_empty()? + .has_seeds(&[BUS, &[3]], args.bus_3_bump, &ore_api::ID)?; bus_4_info - .has_seeds(&[BUS, &[4]], args.bus_4_bump, &ore_api::ID)? - .is_empty()?; + .is_empty()? + .has_seeds(&[BUS, &[4]], args.bus_4_bump, &ore_api::ID)?; bus_5_info - .has_seeds(&[BUS, &[5]], args.bus_5_bump, &ore_api::ID)? - .is_empty()?; + .is_empty()? + .has_seeds(&[BUS, &[5]], args.bus_5_bump, &ore_api::ID)?; bus_6_info - .has_seeds(&[BUS, &[6]], args.bus_6_bump, &ore_api::ID)? - .is_empty()?; + .is_empty()? + .has_seeds(&[BUS, &[6]], args.bus_6_bump, &ore_api::ID)?; bus_7_info - .has_seeds(&[BUS, &[7]], args.bus_7_bump, &ore_api::ID)? - .is_empty()?; + .is_empty()? + .has_seeds(&[BUS, &[7]], args.bus_7_bump, &ore_api::ID)?; config_info - .has_seeds(&[CONFIG], args.config_bump, &ore_api::ID)? - .is_empty()?; - metadata_info - .has_seeds( - &[ - METADATA, - mpl_token_metadata::ID.as_ref(), - MINT_ADDRESS.as_ref(), - ], - args.metadata_bump, - &mpl_token_metadata::ID, - )? - .is_empty()?; - mint_info - .has_seeds(&[MINT, MINT_NOISE.as_slice()], args.mint_bump, &ore_api::ID)? - .is_empty()?; + .is_empty()? + .has_seeds(&[CONFIG], args.config_bump, &ore_api::ID)?; + metadata_info.is_empty()?.has_seeds( + &[ + METADATA, + mpl_token_metadata::ID.as_ref(), + MINT_ADDRESS.as_ref(), + ], + args.metadata_bump, + &mpl_token_metadata::ID, + )?; + mint_info.is_empty()?.has_seeds( + &[MINT, MINT_NOISE.as_slice()], + args.mint_bump, + &ore_api::ID, + )?; treasury_info - .has_seeds(&[TREASURY], args.treasury_bump, &ore_api::ID)? - .is_empty()?; + .is_empty()? + .has_seeds(&[TREASURY], args.treasury_bump, &ore_api::ID)?; treasury_tokens_info.is_empty()?; system_program.is_program(&system_program::ID)?; token_program.is_program(&spl_token::ID)?; From 1448e2b793033229131003047f74fca8febd474b Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Fri, 27 Sep 2024 07:14:23 +0000 Subject: [PATCH 09/18] cleanup --- program/src/initialize.rs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/program/src/initialize.rs b/program/src/initialize.rs index 99bc7d1..48ed85f 100644 --- a/program/src/initialize.rs +++ b/program/src/initialize.rs @@ -24,32 +24,41 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramR signer_info.is_signer()?.has_address(&INITIALIZER_ADDRESS)?; bus_0_info .is_empty()? + .is_writable()? .has_seeds(&[BUS, &[0]], args.bus_0_bump, &ore_api::ID)?; bus_1_info .is_empty()? + .is_writable()? .has_seeds(&[BUS, &[1]], args.bus_1_bump, &ore_api::ID)?; bus_2_info .is_empty()? + .is_writable()? .has_seeds(&[BUS, &[2]], args.bus_2_bump, &ore_api::ID)?; bus_3_info .is_empty()? + .is_writable()? .has_seeds(&[BUS, &[3]], args.bus_3_bump, &ore_api::ID)?; bus_4_info .is_empty()? + .is_writable()? .has_seeds(&[BUS, &[4]], args.bus_4_bump, &ore_api::ID)?; bus_5_info .is_empty()? + .is_writable()? .has_seeds(&[BUS, &[5]], args.bus_5_bump, &ore_api::ID)?; bus_6_info .is_empty()? + .is_writable()? .has_seeds(&[BUS, &[6]], args.bus_6_bump, &ore_api::ID)?; bus_7_info .is_empty()? + .is_writable()? .has_seeds(&[BUS, &[7]], args.bus_7_bump, &ore_api::ID)?; config_info .is_empty()? + .is_writable()? .has_seeds(&[CONFIG], args.config_bump, &ore_api::ID)?; - metadata_info.is_empty()?.has_seeds( + metadata_info.is_empty()?.is_writable()?.has_seeds( &[ METADATA, mpl_token_metadata::ID.as_ref(), @@ -58,15 +67,17 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramR args.metadata_bump, &mpl_token_metadata::ID, )?; - mint_info.is_empty()?.has_seeds( + mint_info.is_empty()?.is_writable()?.has_seeds( &[MINT, MINT_NOISE.as_slice()], args.mint_bump, &ore_api::ID, )?; - treasury_info - .is_empty()? - .has_seeds(&[TREASURY], args.treasury_bump, &ore_api::ID)?; - treasury_tokens_info.is_empty()?; + treasury_info.is_empty()?.is_writable()?.has_seeds( + &[TREASURY], + args.treasury_bump, + &ore_api::ID, + )?; + treasury_tokens_info.is_empty()?.is_writable()?; system_program.is_program(&system_program::ID)?; token_program.is_program(&spl_token::ID)?; associated_token_program.is_program(&spl_associated_token_account::ID)?; From 79e1c5fbdbb851fe2c2599cfcfad13975407d479 Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Fri, 27 Sep 2024 07:25:46 +0000 Subject: [PATCH 10/18] cleanup entrypoint --- program/src/lib.rs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/program/src/lib.rs b/program/src/lib.rs index 0bb046f..1523004 100644 --- a/program/src/lib.rs +++ b/program/src/lib.rs @@ -19,27 +19,16 @@ use update::*; use upgrade::*; use ore_api::instruction::*; -use solana_program::{ - self, account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError, - pubkey::Pubkey, -}; - -solana_program::entrypoint!(process_instruction); +use steel::*; pub fn process_instruction( program_id: &Pubkey, accounts: &[AccountInfo], data: &[u8], ) -> ProgramResult { - if program_id.ne(&ore_api::id()) { - return Err(ProgramError::IncorrectProgramId); - } + let (ix, data) = parse_instruction(&ore_api::ID, program_id, data)?; - let (tag, data) = data - .split_first() - .ok_or(ProgramError::InvalidInstructionData)?; - - match OreInstruction::try_from(*tag).or(Err(ProgramError::InvalidInstructionData))? { + match ix { OreInstruction::Claim => process_claim(accounts, data)?, OreInstruction::Close => process_close(accounts, data)?, OreInstruction::Mine => process_mine(accounts, data)?, @@ -53,3 +42,5 @@ pub fn process_instruction( Ok(()) } + +entrypoint!(process_instruction); From 4f35fb23c6fcba5f387a30ed990cef23c24f4e32 Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Fri, 27 Sep 2024 07:31:51 +0000 Subject: [PATCH 11/18] cleanup loaders --- program/src/open.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/program/src/open.rs b/program/src/open.rs index 94c7dec..93df2ad 100644 --- a/program/src/open.rs +++ b/program/src/open.rs @@ -22,10 +22,11 @@ pub fn process_open(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult }; signer_info.is_signer()?; payer_info.is_signer()?; - proof_info - .has_seeds(&[PROOF, signer_info.key.as_ref()], args.bump, &ore_api::ID)? - .is_empty()? - .is_writable()?; + proof_info.is_empty()?.is_writable()?.has_seeds( + &[PROOF, signer_info.key.as_ref()], + args.bump, + &ore_api::ID, + )?; system_program.is_program(&system_program::ID)?; slot_hashes_info.is_sysvar(&sysvar::slot_hashes::ID)?; From 8b095c23363b0b9bf7a4158e7926cf897883e55d Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Fri, 27 Sep 2024 07:41:48 +0000 Subject: [PATCH 12/18] account validation checks --- program/src/mine.rs | 5 ++++- program/src/reset.rs | 4 +++- program/src/upgrade.rs | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/program/src/mine.rs b/program/src/mine.rs index 1cdadb7..14683a1 100644 --- a/program/src/mine.rs +++ b/program/src/mine.rs @@ -6,6 +6,7 @@ use ore_api::{ error::OreError, event::MineEvent, instruction::Mine, + loaders::OreAccountInfoValidation, state::{Bus, Config, Proof}, }; use solana_program::program::set_return_data; @@ -32,7 +33,9 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult { }; signer_info.is_signer()?; let bus = bus_info.to_account_mut::(&ore_api::ID)?; - let config = config_info.to_account::(&ore_api::ID)?; + let config = config_info + .is_config()? + .to_account::(&ore_api::ID)?; let proof = proof_info .to_account_mut::(&ore_api::ID)? .check_mut(|p| p.miner == *signer_info.key)?; diff --git a/program/src/reset.rs b/program/src/reset.rs index 2800139..6625f6d 100644 --- a/program/src/reset.rs +++ b/program/src/reset.rs @@ -39,7 +39,9 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul let bus_7 = bus_7_info .to_account_mut::(&ore_api::ID)? .check_mut(|b| b.id == 7)?; - let config = config_info.to_account_mut::(&ore_api::ID)?; + let config = config_info + .is_config()? + .to_account_mut::(&ore_api::ID)?; let mint = mint_info .has_address(&MINT_ADDRESS)? .is_writable()? diff --git a/program/src/upgrade.rs b/program/src/upgrade.rs index 058c400..140a499 100644 --- a/program/src/upgrade.rs +++ b/program/src/upgrade.rs @@ -1,4 +1,4 @@ -use ore_api::{consts::*, error::OreError, instruction::Stake}; +use ore_api::{consts::*, error::OreError, instruction::Stake, loaders::OreAccountInfoValidation}; use steel::*; /// Upgrade allows a user to migrate a v1 token to a v2 token at a 1:1 exchange rate. @@ -32,6 +32,7 @@ pub fn process_upgrade(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResu .to_token_account()? .check(|t| t.owner == *signer_info.key)? .check(|t| t.mint == MINT_V1_ADDRESS)?; + treasury_info.is_treasury()?; token_program.is_program(&spl_token::ID)?; // Burn v1 tokens From 466d69676597847e4fa3ec1b4e5d37bc90f5f2a7 Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Fri, 27 Sep 2024 07:45:00 +0000 Subject: [PATCH 13/18] account checks --- program/src/stake.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/program/src/stake.rs b/program/src/stake.rs index 1e495dd..ecddd0c 100644 --- a/program/src/stake.rs +++ b/program/src/stake.rs @@ -19,8 +19,8 @@ pub fn process_stake(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult sender_info .is_writable()? .to_token_account()? - .check(|t| t.owner.eq(signer_info.key))? - .check(|t| t.mint.eq(&MINT_ADDRESS))?; + .check(|t| t.owner == *signer_info.key)? + .check(|t| t.mint == MINT_ADDRESS)?; treasury_tokens_info.is_writable()?.is_treasury_tokens()?; token_program.is_program(&spl_token::ID)?; From ec505541b1280cfa0d02e42a329a42a1adae30f8 Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Fri, 27 Sep 2024 07:59:17 +0000 Subject: [PATCH 14/18] cleanup --- program/src/close.rs | 1 - program/src/initialize.rs | 5 +---- program/src/mine.rs | 3 +-- program/src/open.rs | 9 ++------- program/src/reset.rs | 2 +- program/src/stake.rs | 2 +- 6 files changed, 6 insertions(+), 16 deletions(-) diff --git a/program/src/close.rs b/program/src/close.rs index 4be47c0..8e7b85d 100644 --- a/program/src/close.rs +++ b/program/src/close.rs @@ -1,5 +1,4 @@ use ore_api::state::Proof; -use solana_program::system_program; use steel::*; /// Close closes a proof account and returns the rent to the owner. diff --git a/program/src/initialize.rs b/program/src/initialize.rs index 48ed85f..298e5c0 100644 --- a/program/src/initialize.rs +++ b/program/src/initialize.rs @@ -3,10 +3,7 @@ use ore_api::{ instruction::*, state::{Bus, Config, Treasury}, }; -use solana_program::{ - self, account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError, - program_pack::Pack, system_program, sysvar, -}; +use solana_program::program_pack::Pack; use spl_token::state::Mint; use steel::*; diff --git a/program/src/mine.rs b/program/src/mine.rs index 14683a1..655bb2d 100644 --- a/program/src/mine.rs +++ b/program/src/mine.rs @@ -16,7 +16,6 @@ use solana_program::{ sanitize::SanitizeError, serialize_utils::{read_pubkey, read_u16}, slot_hashes::SlotHash, - sysvar::{self, Sysvar}, }; use steel::*; @@ -51,7 +50,7 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult { // Validate epoch is active. // let config_data = config_info.data.borrow(); // let config = Config::try_from_bytes(&config_data)?; - let clock = Clock::get().or(Err(ProgramError::InvalidAccountData))?; + let clock = Clock::get()?; if config .last_reset_at .saturating_add(EPOCH_DURATION) diff --git a/program/src/open.rs b/program/src/open.rs index 93df2ad..2e82bd0 100644 --- a/program/src/open.rs +++ b/program/src/open.rs @@ -1,12 +1,7 @@ use std::mem::size_of; use ore_api::{consts::*, instruction::Open, state::Proof}; -use solana_program::{ - keccak::hashv, - slot_hashes::SlotHash, - system_program, - sysvar::{self, Sysvar}, -}; +use solana_program::{keccak::hashv, slot_hashes::SlotHash}; use steel::*; /// Open creates a new proof account to track a miner's state. @@ -38,7 +33,7 @@ pub fn process_open(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult system_program, payer_info, )?; - let clock = Clock::get().or(Err(ProgramError::InvalidAccountData))?; + let clock = Clock::get()?; let proof = proof_info.to_account_mut::(&ore_api::ID)?; proof.authority = *signer_info.key; proof.balance = 0; diff --git a/program/src/reset.rs b/program/src/reset.rs index 6625f6d..e59d7f3 100644 --- a/program/src/reset.rs +++ b/program/src/reset.rs @@ -53,7 +53,7 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul // Validate enough time has passed since the last reset. // let mut config_data = config_info.data.borrow_mut(); // let config = Config::try_from_bytes_mut(&mut config_data)?; - let clock = Clock::get().or(Err(ProgramError::InvalidAccountData))?; + let clock = Clock::get()?; if config .last_reset_at .saturating_add(EPOCH_DURATION) diff --git a/program/src/stake.rs b/program/src/stake.rs index ecddd0c..48ba171 100644 --- a/program/src/stake.rs +++ b/program/src/stake.rs @@ -28,7 +28,7 @@ pub fn process_stake(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult proof.balance = proof.balance.checked_add(amount).unwrap(); // Update deposit timestamp. - let clock = Clock::get().or(Err(ProgramError::InvalidAccountData))?; + let clock = Clock::get()?; proof.last_stake_at = clock.unix_timestamp; // Transfer tokens from signer to treasury. From 6cb5f18628ca837803d112cce41b22c825ab27d5 Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Fri, 27 Sep 2024 08:05:48 +0000 Subject: [PATCH 15/18] cleanup imports --- api/src/instruction.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/api/src/instruction.rs b/api/src/instruction.rs index 923b2c5..141df9a 100644 --- a/api/src/instruction.rs +++ b/api/src/instruction.rs @@ -1,5 +1,3 @@ -use bytemuck::{Pod, Zeroable}; -use num_enum::TryFromPrimitive; use steel::*; #[repr(u8)] From f0b0274372fa75624ef1f2a383094c219a66b842 Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Fri, 27 Sep 2024 08:10:46 +0000 Subject: [PATCH 16/18] cleanup imports --- api/src/sdk.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/api/src/sdk.rs b/api/src/sdk.rs index e6ccd5d..0c5d797 100644 --- a/api/src/sdk.rs +++ b/api/src/sdk.rs @@ -1,5 +1,4 @@ use drillx::Solution; -use solana_program::{system_program, sysvar}; use steel::*; use crate::{ From 13bd94df90181d918513779caa5a58d6fb095cfb Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Fri, 27 Sep 2024 08:15:05 +0000 Subject: [PATCH 17/18] ore_api prelude module --- api/src/lib.rs | 12 +++++++++++- program/src/claim.rs | 2 +- program/src/close.rs | 2 +- program/src/initialize.rs | 6 +----- program/src/mine.rs | 9 +-------- program/src/open.rs | 2 +- program/src/reset.rs | 7 +------ program/src/stake.rs | 2 +- program/src/update.rs | 2 +- program/src/upgrade.rs | 2 +- 10 files changed, 20 insertions(+), 26 deletions(-) diff --git a/api/src/lib.rs b/api/src/lib.rs index 75b6aba..c0e78a6 100644 --- a/api/src/lib.rs +++ b/api/src/lib.rs @@ -6,6 +6,16 @@ pub mod loaders; pub mod sdk; pub mod state; -use solana_program::declare_id; +pub mod prelude { + pub use crate::consts::*; + pub use crate::error::*; + pub use crate::event::*; + pub use crate::instruction::*; + pub use crate::loaders::*; + pub use crate::sdk::*; + pub use crate::state::*; +} + +use steel::*; declare_id!("oreV2ZymfyeXgNgBdqMkumTqqAprVqgBWQfoYkrtKWQ"); diff --git a/program/src/claim.rs b/program/src/claim.rs index 7fa8c48..c4a9201 100644 --- a/program/src/claim.rs +++ b/program/src/claim.rs @@ -1,4 +1,4 @@ -use ore_api::{consts::*, error::OreError, instruction::*, loaders::*, state::Proof}; +use ore_api::prelude::*; use steel::*; /// Claim distributes claimable ORE from the treasury to a miner. diff --git a/program/src/close.rs b/program/src/close.rs index 8e7b85d..dd58ead 100644 --- a/program/src/close.rs +++ b/program/src/close.rs @@ -1,4 +1,4 @@ -use ore_api::state::Proof; +use ore_api::prelude::*; use steel::*; /// Close closes a proof account and returns the rent to the owner. diff --git a/program/src/initialize.rs b/program/src/initialize.rs index 298e5c0..23cc57e 100644 --- a/program/src/initialize.rs +++ b/program/src/initialize.rs @@ -1,8 +1,4 @@ -use ore_api::{ - consts::*, - instruction::*, - state::{Bus, Config, Treasury}, -}; +use ore_api::prelude::*; use solana_program::program_pack::Pack; use spl_token::state::Mint; use steel::*; diff --git a/program/src/mine.rs b/program/src/mine.rs index 655bb2d..eb8e37b 100644 --- a/program/src/mine.rs +++ b/program/src/mine.rs @@ -1,14 +1,7 @@ use std::mem::size_of; use drillx::Solution; -use ore_api::{ - consts::*, - error::OreError, - event::MineEvent, - instruction::Mine, - loaders::OreAccountInfoValidation, - state::{Bus, Config, Proof}, -}; +use ore_api::prelude::*; use solana_program::program::set_return_data; #[allow(deprecated)] use solana_program::{ diff --git a/program/src/open.rs b/program/src/open.rs index 2e82bd0..bc9c9f3 100644 --- a/program/src/open.rs +++ b/program/src/open.rs @@ -1,6 +1,6 @@ use std::mem::size_of; -use ore_api::{consts::*, instruction::Open, state::Proof}; +use ore_api::prelude::*; use solana_program::{keccak::hashv, slot_hashes::SlotHash}; use steel::*; diff --git a/program/src/reset.rs b/program/src/reset.rs index e59d7f3..b00a6ba 100644 --- a/program/src/reset.rs +++ b/program/src/reset.rs @@ -1,9 +1,4 @@ -use ore_api::{ - consts::*, - error::OreError, - loaders::*, - state::{Bus, Config}, -}; +use ore_api::prelude::*; use steel::*; /// Reset tops up the bus balances, updates the base reward rate, and sets up the ORE program for the next epoch. diff --git a/program/src/stake.rs b/program/src/stake.rs index 48ba171..7a42d80 100644 --- a/program/src/stake.rs +++ b/program/src/stake.rs @@ -1,4 +1,4 @@ -use ore_api::{consts::*, instruction::Stake, loaders::*, state::Proof}; +use ore_api::prelude::*; use steel::*; /// Stake deposits ORE into a proof account to earn multiplier. diff --git a/program/src/update.rs b/program/src/update.rs index 6bf6f74..4f153a6 100644 --- a/program/src/update.rs +++ b/program/src/update.rs @@ -1,4 +1,4 @@ -use ore_api::state::Proof; +use ore_api::prelude::*; use steel::*; /// Update changes the miner authority on a proof account. diff --git a/program/src/upgrade.rs b/program/src/upgrade.rs index 140a499..74090d0 100644 --- a/program/src/upgrade.rs +++ b/program/src/upgrade.rs @@ -1,4 +1,4 @@ -use ore_api::{consts::*, error::OreError, instruction::Stake, loaders::OreAccountInfoValidation}; +use ore_api::prelude::*; use steel::*; /// Upgrade allows a user to migrate a v1 token to a v2 token at a 1:1 exchange rate. From 21862a31425e2a09b6b32325f135c1c559fda50e Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Sun, 29 Sep 2024 08:40:41 +0000 Subject: [PATCH 18/18] id style --- Cargo.lock | 2 +- program/src/initialize.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5ee7aae..e81be82 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2211,7 +2211,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "steel" -version = "1.2.0" +version = "1.3.0" dependencies = [ "bytemuck", "num_enum", diff --git a/program/src/initialize.rs b/program/src/initialize.rs index 23cc57e..4d7d8b3 100644 --- a/program/src/initialize.rs +++ b/program/src/initialize.rs @@ -95,7 +95,7 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramR for i in 0..BUS_COUNT { create_account::( bus_infos[i], - &ore_api::id(), + &ore_api::ID, &[BUS, &[i as u8], &[bus_bumps[i]]], system_program, signer_info, @@ -110,7 +110,7 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramR // Initialize config. create_account::( config_info, - &ore_api::id(), + &ore_api::ID, &[CONFIG, &[args.config_bump]], system_program, signer_info, @@ -124,7 +124,7 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramR // Initialize treasury. create_account::( treasury_info, - &ore_api::id(), + &ore_api::ID, &[TREASURY, &[args.treasury_bump]], system_program, signer_info, @@ -133,7 +133,7 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramR // Initialize mint. allocate_account( mint_info, - &spl_token::id(), + &spl_token::ID, Mint::LEN, &[MINT, MINT_NOISE.as_slice(), &[args.mint_bump]], system_program, @@ -141,7 +141,7 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramR )?; solana_program::program::invoke_signed( &spl_token::instruction::initialize_mint( - &spl_token::id(), + &spl_token::ID, mint_info.key, treasury_info.key, None,