diff --git a/Cargo.lock b/Cargo.lock index 0b8cf51..e99d408 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1287,7 +1287,7 @@ checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" [[package]] name = "ore-api" -version = "2.4.0" +version = "2.5.0" dependencies = [ "array-const-fn-init", "bytemuck", @@ -1305,9 +1305,9 @@ dependencies = [ [[package]] name = "ore-boost-api" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c97f55b9d1a40a6b3044444c457acd70b983d31b7edd5c8459b8c616b080fecd" +checksum = "1ce6c36c89d829a4b36debc127625513aaf668ed8f0eb4982493fdc3b6b004e9" dependencies = [ "array-const-fn-init", "bytemuck", @@ -1323,7 +1323,7 @@ dependencies = [ [[package]] name = "ore-program" -version = "2.4.0" +version = "2.5.0" dependencies = [ "drillx", "mpl-token-metadata", @@ -2237,9 +2237,9 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "steel" -version = "1.3.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d88c610ca9fd5e4e51bdb6e9964114133a42f006713fe38aff37266fac91e1be" +checksum = "7a2ca3cc310b7b71ce7944af64fb4fdaa5d0c2848ac79616d75e401913b6f781" dependencies = [ "bytemuck", "num_enum", diff --git a/Cargo.toml b/Cargo.toml index 8df27c6..983efd3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ resolver = "2" members = ["api", "program"] [workspace.package] -version = "2.4.0" +version = "2.5.0" edition = "2021" license = "Apache-2.0" homepage = "https://ore.supply" @@ -20,10 +20,10 @@ drillx = { version = "2.0.0", features = ["solana"] } mpl-token-metadata = "4.1.2" num_enum = "0.7.2" ore-api = { path = "api", version = "2.1.9" } -ore-boost-api = "0.2" +ore-boost-api = "0.3" 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 = "1.0" } +steel = { features = ["spl"], version = "2.0" } thiserror = "1.0.57" diff --git a/api/src/consts.rs b/api/src/consts.rs index 20ba668..51b3784 100644 --- a/api/src/consts.rs +++ b/api/src/consts.rs @@ -128,6 +128,9 @@ pub const METADATA_ADDRESS: Pubkey = Pubkey::new_from_array( pub const MINT_ADDRESS: Pubkey = Pubkey::new_from_array(ed25519::derive_program_address(&[MINT, &MINT_NOISE], &PROGRAM_ID).0); +/// The bump of the mint account. +pub const MINT_BUMP: u8 = ed25519::derive_program_address(&[MINT, &MINT_NOISE], &PROGRAM_ID).1; + /// The address of the v1 mint account. pub const MINT_V1_ADDRESS: Pubkey = pubkey!("oreoN2tQbHXVaZsr3pf66A48miqcBXCDJozganhEJgz"); diff --git a/api/src/instruction.rs b/api/src/instruction.rs index f29b3b7..4427d88 100644 --- a/api/src/instruction.rs +++ b/api/src/instruction.rs @@ -38,6 +38,7 @@ pub struct Mine { #[repr(C)] #[derive(Clone, Copy, Debug, Pod, Zeroable)] pub struct Open { + #[deprecated(since = "2.5.0", note = "Bump no longer used")] pub bump: u8, } @@ -65,17 +66,29 @@ pub struct Upgrade { #[repr(C)] #[derive(Clone, Copy, Debug, Pod, Zeroable)] pub struct Initialize { + #[deprecated(since = "2.5.0", note = "Bump no longer used")] pub bus_0_bump: u8, + #[deprecated(since = "2.5.0", note = "Bump no longer used")] pub bus_1_bump: u8, + #[deprecated(since = "2.5.0", note = "Bump no longer used")] pub bus_2_bump: u8, + #[deprecated(since = "2.5.0", note = "Bump no longer used")] pub bus_3_bump: u8, + #[deprecated(since = "2.5.0", note = "Bump no longer used")] pub bus_4_bump: u8, + #[deprecated(since = "2.5.0", note = "Bump no longer used")] pub bus_5_bump: u8, + #[deprecated(since = "2.5.0", note = "Bump no longer used")] pub bus_6_bump: u8, + #[deprecated(since = "2.5.0", note = "Bump no longer used")] pub bus_7_bump: u8, + #[deprecated(since = "2.5.0", note = "Bump no longer used")] pub config_bump: u8, + #[deprecated(since = "2.5.0", note = "Bump no longer used")] pub metadata_bump: u8, + #[deprecated(since = "2.5.0", note = "Bump no longer used")] pub mint_bump: u8, + #[deprecated(since = "2.5.0", note = "Bump no longer used")] pub treasury_bump: u8, } diff --git a/api/src/sdk.rs b/api/src/sdk.rs index 6bac98f..ee8d38b 100644 --- a/api/src/sdk.rs +++ b/api/src/sdk.rs @@ -83,6 +83,7 @@ pub fn mine( } /// Builds an open instruction. +#[allow(deprecated)] pub fn open(signer: Pubkey, miner: Pubkey, payer: Pubkey) -> Instruction { let proof_pda = proof_pda(signer); Instruction { @@ -179,6 +180,7 @@ pub fn upgrade(signer: Pubkey, beneficiary: Pubkey, sender: Pubkey, amount: u64) } /// Builds an initialize instruction. +#[allow(deprecated)] pub fn initialize(signer: Pubkey) -> Instruction { let bus_pdas = [ bus_pda(0), diff --git a/program/src/claim.rs b/program/src/claim.rs index c4a9201..34ebadd 100644 --- a/program/src/claim.rs +++ b/program/src/claim.rs @@ -16,11 +16,14 @@ pub fn process_claim(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult signer_info.is_signer()?; beneficiary_info .is_writable()? - .to_token_account()? - .check(|t| t.mint == MINT_ADDRESS)?; + .as_token_account()? + .assert(|t| t.mint == MINT_ADDRESS)?; let proof = proof_info - .to_account_mut::(&ore_api::ID)? - .check_mut(|p| p.authority == *signer_info.key)?; + .as_account_mut::(&ore_api::ID)? + .assert_mut_err( + |p| p.authority == *signer_info.key, + ProgramError::MissingRequiredSignature, + )?; treasury_info.is_treasury()?; treasury_tokens_info.is_writable()?.is_treasury_tokens()?; token_program.is_program(&spl_token::ID)?; @@ -38,7 +41,7 @@ pub fn process_claim(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult beneficiary_info, token_program, amount, - &[&[TREASURY, &[TREASURY_BUMP]]], + &[TREASURY], )?; Ok(()) diff --git a/program/src/close.rs b/program/src/close.rs index dd58ead..326aca3 100644 --- a/program/src/close.rs +++ b/program/src/close.rs @@ -10,17 +10,16 @@ pub fn process_close(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul signer_info.is_signer()?; proof_info .is_writable()? - .to_account::(&ore_api::ID)? - .check(|p| p.authority == *signer_info.key)? - .check(|p| p.balance == 0)?; + .as_account::(&ore_api::ID)? + .assert_err( + |p| p.authority == *signer_info.key, + ProgramError::MissingRequiredSignature, + )? + .assert(|p| p.balance == 0)?; system_program.is_program(&system_program::ID)?; - // Realloc data to zero. - proof_info.realloc(0, true)?; - - // Send remaining lamports to signer. - **signer_info.lamports.borrow_mut() += proof_info.lamports(); - **proof_info.lamports.borrow_mut() = 0; + // Return rent to signer. + proof_info.close(signer_info)?; Ok(()) } diff --git a/program/src/initialize.rs b/program/src/initialize.rs index 4d7d8b3..364a666 100644 --- a/program/src/initialize.rs +++ b/program/src/initialize.rs @@ -4,10 +4,7 @@ use spl_token::state::Mint; use steel::*; /// Initialize sets up the ORE program to begin mining. -pub fn process_initialize(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult { - // Parse args. - let args = Initialize::try_from_bytes(data)?; - +pub fn process_initialize(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult { // Load accounts. 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 @@ -18,58 +15,55 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramR bus_0_info .is_empty()? .is_writable()? - .has_seeds(&[BUS, &[0]], args.bus_0_bump, &ore_api::ID)?; + .has_seeds(&[BUS, &[0]], &ore_api::ID)?; bus_1_info .is_empty()? .is_writable()? - .has_seeds(&[BUS, &[1]], args.bus_1_bump, &ore_api::ID)?; + .has_seeds(&[BUS, &[1]], &ore_api::ID)?; bus_2_info .is_empty()? .is_writable()? - .has_seeds(&[BUS, &[2]], args.bus_2_bump, &ore_api::ID)?; + .has_seeds(&[BUS, &[2]], &ore_api::ID)?; bus_3_info .is_empty()? .is_writable()? - .has_seeds(&[BUS, &[3]], args.bus_3_bump, &ore_api::ID)?; + .has_seeds(&[BUS, &[3]], &ore_api::ID)?; bus_4_info .is_empty()? .is_writable()? - .has_seeds(&[BUS, &[4]], args.bus_4_bump, &ore_api::ID)?; + .has_seeds(&[BUS, &[4]], &ore_api::ID)?; bus_5_info .is_empty()? .is_writable()? - .has_seeds(&[BUS, &[5]], args.bus_5_bump, &ore_api::ID)?; + .has_seeds(&[BUS, &[5]], &ore_api::ID)?; bus_6_info .is_empty()? .is_writable()? - .has_seeds(&[BUS, &[6]], args.bus_6_bump, &ore_api::ID)?; + .has_seeds(&[BUS, &[6]], &ore_api::ID)?; bus_7_info .is_empty()? .is_writable()? - .has_seeds(&[BUS, &[7]], args.bus_7_bump, &ore_api::ID)?; + .has_seeds(&[BUS, &[7]], &ore_api::ID)?; config_info .is_empty()? .is_writable()? - .has_seeds(&[CONFIG], args.config_bump, &ore_api::ID)?; + .has_seeds(&[CONFIG], &ore_api::ID)?; metadata_info.is_empty()?.is_writable()?.has_seeds( &[ METADATA, mpl_token_metadata::ID.as_ref(), MINT_ADDRESS.as_ref(), ], - args.metadata_bump, &mpl_token_metadata::ID, )?; - mint_info.is_empty()?.is_writable()?.has_seeds( - &[MINT, MINT_NOISE.as_slice()], - args.mint_bump, - &ore_api::ID, - )?; - treasury_info.is_empty()?.is_writable()?.has_seeds( - &[TREASURY], - args.treasury_bump, - &ore_api::ID, - )?; + mint_info + .is_empty()? + .is_writable()? + .has_seeds(&[MINT, MINT_NOISE.as_slice()], &ore_api::ID)?; + treasury_info + .is_empty()? + .is_writable()? + .has_seeds(&[TREASURY], &ore_api::ID)?; treasury_tokens_info.is_empty()?.is_writable()?; system_program.is_program(&system_program::ID)?; token_program.is_program(&spl_token::ID)?; @@ -82,25 +76,15 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramR bus_0_info, bus_1_info, bus_2_info, bus_3_info, bus_4_info, bus_5_info, bus_6_info, bus_7_info, ]; - let bus_bumps = [ - args.bus_0_bump, - args.bus_1_bump, - args.bus_2_bump, - args.bus_3_bump, - args.bus_4_bump, - args.bus_5_bump, - args.bus_6_bump, - args.bus_7_bump, - ]; for i in 0..BUS_COUNT { create_account::( bus_infos[i], - &ore_api::ID, - &[BUS, &[i as u8], &[bus_bumps[i]]], system_program, signer_info, + &ore_api::ID, + &[BUS, &[i as u8]], )?; - let bus = bus_infos[i].to_account_mut::(&ore_api::ID)?; + let bus = bus_infos[i].as_account_mut::(&ore_api::ID)?; bus.id = i as u64; bus.rewards = 0; bus.theoretical_rewards = 0; @@ -110,12 +94,12 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramR // Initialize config. create_account::( config_info, - &ore_api::ID, - &[CONFIG, &[args.config_bump]], system_program, signer_info, + &ore_api::ID, + &[CONFIG], )?; - let config = config_info.to_account_mut::(&ore_api::ID)?; + let config = config_info.as_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; @@ -124,36 +108,31 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramR // Initialize treasury. create_account::( treasury_info, - &ore_api::ID, - &[TREASURY, &[args.treasury_bump]], system_program, signer_info, + &ore_api::ID, + &[TREASURY], )?; // Initialize mint. - allocate_account( + allocate_account_with_bump( mint_info, - &spl_token::ID, - Mint::LEN, - &[MINT, MINT_NOISE.as_slice(), &[args.mint_bump]], system_program, signer_info, + Mint::LEN, + &spl_token::ID, + &[MINT, MINT_NOISE.as_slice()], + MINT_BUMP, )?; - solana_program::program::invoke_signed( - &spl_token::instruction::initialize_mint( - &spl_token::ID, - mint_info.key, - treasury_info.key, - None, - TOKEN_DECIMALS, - )?, - &[ - token_program.clone(), - mint_info.clone(), - treasury_info.clone(), - rent_sysvar.clone(), - ], - &[&[MINT, MINT_NOISE.as_slice(), &[args.mint_bump]]], + initialize_mint_signed_with_bump( + mint_info, + treasury_info, + None, + token_program, + rent_sysvar, + TOKEN_DECIMALS, + &[MINT, MINT_NOISE.as_slice()], + MINT_BUMP, )?; // Initialize mint metadata. @@ -180,7 +159,7 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramR collection_details: None, }, } - .invoke_signed(&[&[TREASURY, &[args.treasury_bump]]])?; + .invoke_signed(&[&[TREASURY, &[TREASURY_BUMP]]])?; // Initialize treasury token account. create_associated_token_account( diff --git a/program/src/mine.rs b/program/src/mine.rs index adfe22d..5c932d2 100644 --- a/program/src/mine.rs +++ b/program/src/mine.rs @@ -6,7 +6,6 @@ use ore_boost_api::state::{Boost, Stake}; #[allow(deprecated)] use solana_program::{ keccak::hashv, - program::set_return_data, sanitize::SanitizeError, serialize_utils::{read_pubkey, read_u16}, slot_hashes::SlotHash, @@ -19,6 +18,8 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult { let args = Mine::try_from_bytes(data)?; // Load accounts. + let clock = Clock::get()?; + let t: i64 = clock.unix_timestamp; let (required_accounts, optional_accounts) = accounts.split_at(6); let [signer_info, bus_info, config_info, proof_info, instructions_sysvar, slot_hashes_sysvar] = required_accounts @@ -26,13 +27,20 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult { return Err(ProgramError::NotEnoughAccountKeys); }; signer_info.is_signer()?; - let bus = bus_info.is_bus()?.to_account_mut::(&ore_api::ID)?; + let bus = bus_info.is_bus()?.as_account_mut::(&ore_api::ID)?; let config = config_info .is_config()? - .to_account::(&ore_api::ID)?; + .as_account::(&ore_api::ID)? + .assert_err( + |c| c.last_reset_at.saturating_add(EPOCH_DURATION) > t, + OreError::NeedsReset.into(), + )?; let proof = proof_info - .to_account_mut::(&ore_api::ID)? - .check_mut(|p| p.miner == *signer_info.key)?; + .as_account_mut::(&ore_api::ID)? + .assert_mut_err( + |p| p.miner == *signer_info.key, + ProgramError::MissingRequiredSignature, + )?; instructions_sysvar.is_sysvar(&sysvar::instructions::ID)?; slot_hashes_sysvar.is_sysvar(&sysvar::slot_hashes::ID)?; @@ -42,21 +50,10 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult { // in the transaction must use the same proof account. authenticate(&instructions_sysvar.data.borrow(), proof_info.key)?; - // Validate epoch is active. - let clock = Clock::get()?; - if config - .last_reset_at - .saturating_add(EPOCH_DURATION) - .le(&clock.unix_timestamp) - { - return Err(OreError::NeedsReset.into()); - } - // Reject spam transactions. // // Miners are rate limited to approximately 1 hash per minute. If a miner attempts to submit // solutions more frequently than this, reject with an error. - let t: i64 = clock.unix_timestamp; let t_target = proof.last_hash_at.saturating_add(ONE_MINUTE); let t_spam = t_target.saturating_sub(TOLERANCE); if t.lt(&t_spam) { @@ -106,11 +103,11 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult { // Load optional accounts. let boost_info = optional_accounts[i * 2].clone(); let stake_info = optional_accounts[i * 2 + 1].clone(); - let boost = boost_info.to_account::(&ore_boost_api::ID)?; + let boost = boost_info.as_account::(&ore_boost_api::ID)?; let stake = stake_info - .to_account::(&ore_boost_api::ID)? - .check(|s| s.authority == proof.authority)? - .check(|s| s.boost == *boost_info.key)?; + .as_account::(&ore_boost_api::ID)? + .assert(|s| s.authority == proof.authority)? + .assert(|s| s.boost == *boost_info.key)?; // Skip if boost is applied twice. if applied_boosts.contains(boost_info.key) { @@ -209,19 +206,17 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult { .checked_div(reward_pre_penalty as u128) .unwrap() as u64; } - set_return_data( - MineEvent { - balance: proof.balance, - difficulty: difficulty as u64, - last_hash_at: prev_last_hash_at, - timing: t.saturating_sub(t_liveness), - reward: reward_actual, - boost_1: boost_rewards[0], - boost_2: boost_rewards[1], - boost_3: boost_rewards[2], - } - .to_bytes(), - ); + MineEvent { + balance: proof.balance, + difficulty: difficulty as u64, + last_hash_at: prev_last_hash_at, + timing: t.saturating_sub(t_liveness), + reward: reward_actual, + boost_1: boost_rewards[0], + boost_2: boost_rewards[1], + boost_3: boost_rewards[2], + } + .log_return(); Ok(()) } diff --git a/program/src/open.rs b/program/src/open.rs index bc9c9f3..4eec85a 100644 --- a/program/src/open.rs +++ b/program/src/open.rs @@ -5,10 +5,7 @@ use solana_program::{keccak::hashv, slot_hashes::SlotHash}; use steel::*; /// Open creates a new proof account to track a miner's state. -pub fn process_open(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult { - // Parse args. - let args = Open::try_from_bytes(data)?; - +pub fn process_open(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult { // Load accounts. let [signer_info, miner_info, payer_info, proof_info, system_program, slot_hashes_info] = accounts @@ -17,24 +14,23 @@ pub fn process_open(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult }; signer_info.is_signer()?; payer_info.is_signer()?; - proof_info.is_empty()?.is_writable()?.has_seeds( - &[PROOF, signer_info.key.as_ref()], - args.bump, - &ore_api::ID, - )?; + proof_info + .is_empty()? + .is_writable()? + .has_seeds(&[PROOF, signer_info.key.as_ref()], &ore_api::ID)?; system_program.is_program(&system_program::ID)?; slot_hashes_info.is_sysvar(&sysvar::slot_hashes::ID)?; // Initialize proof. create_account::( proof_info, - &ore_api::ID, - &[PROOF, signer_info.key.as_ref(), &[args.bump]], system_program, payer_info, + &ore_api::ID, + &[PROOF, signer_info.key.as_ref()], )?; let clock = Clock::get()?; - let proof = proof_info.to_account_mut::(&ore_api::ID)?; + let proof = proof_info.as_account_mut::(&ore_api::ID)?; proof.authority = *signer_info.key; proof.balance = 0; proof.challenge = hashv(&[ diff --git a/program/src/reset.rs b/program/src/reset.rs index 28a736c..5bcc317 100644 --- a/program/src/reset.rs +++ b/program/src/reset.rs @@ -11,36 +11,36 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul }; signer_info.is_signer()?; let bus_0 = bus_0_info - .to_account_mut::(&ore_api::ID)? - .check_mut(|b| b.id == 0)?; + .as_account_mut::(&ore_api::ID)? + .assert_mut(|b| b.id == 0)?; let bus_1 = bus_1_info - .to_account_mut::(&ore_api::ID)? - .check_mut(|b| b.id == 1)?; + .as_account_mut::(&ore_api::ID)? + .assert_mut(|b| b.id == 1)?; let bus_2 = bus_2_info - .to_account_mut::(&ore_api::ID)? - .check_mut(|b| b.id == 2)?; + .as_account_mut::(&ore_api::ID)? + .assert_mut(|b| b.id == 2)?; let bus_3 = bus_3_info - .to_account_mut::(&ore_api::ID)? - .check_mut(|b| b.id == 3)?; + .as_account_mut::(&ore_api::ID)? + .assert_mut(|b| b.id == 3)?; let bus_4 = bus_4_info - .to_account_mut::(&ore_api::ID)? - .check_mut(|b| b.id == 4)?; + .as_account_mut::(&ore_api::ID)? + .assert_mut(|b| b.id == 4)?; let bus_5 = bus_5_info - .to_account_mut::(&ore_api::ID)? - .check_mut(|b| b.id == 5)?; + .as_account_mut::(&ore_api::ID)? + .assert_mut(|b| b.id == 5)?; let bus_6 = bus_6_info - .to_account_mut::(&ore_api::ID)? - .check_mut(|b| b.id == 6)?; + .as_account_mut::(&ore_api::ID)? + .assert_mut(|b| b.id == 6)?; let bus_7 = bus_7_info - .to_account_mut::(&ore_api::ID)? - .check_mut(|b| b.id == 7)?; + .as_account_mut::(&ore_api::ID)? + .assert_mut(|b| b.id == 7)?; let config = config_info .is_config()? - .to_account_mut::(&ore_api::ID)?; + .as_account_mut::(&ore_api::ID)?; let mint = mint_info .has_address(&MINT_ADDRESS)? .is_writable()? - .to_mint()?; + .as_mint()?; treasury_info.is_treasury()?.is_writable()?; treasury_tokens_info.is_treasury_tokens()?.is_writable()?; token_program.is_program(&spl_token::ID)?; @@ -109,22 +109,13 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul let amount = MAX_SUPPLY .saturating_sub(mint.supply) .min(total_epoch_rewards); - solana_program::program::invoke_signed( - &spl_token::instruction::mint_to( - &spl_token::id(), - mint_info.key, - treasury_tokens_info.key, - treasury_info.key, - &[treasury_info.key], - amount, - )?, - &[ - token_program.clone(), - mint_info.clone(), - treasury_tokens_info.clone(), - treasury_info.clone(), - ], - &[&[TREASURY, &[TREASURY_BUMP]]], + mint_to_signed( + mint_info, + treasury_tokens_info, + treasury_info, + token_program, + amount, + &[TREASURY], )?; Ok(()) diff --git a/program/src/update.rs b/program/src/update.rs index 4f153a6..9001ff7 100644 --- a/program/src/update.rs +++ b/program/src/update.rs @@ -9,8 +9,11 @@ pub fn process_update(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResu }; signer_info.is_signer()?; let proof = proof_info - .to_account_mut::(&ore_api::ID)? - .check_mut(|p| p.authority == *signer_info.key)?; + .as_account_mut::(&ore_api::ID)? + .assert_mut_err( + |p| p.authority == *signer_info.key, + ProgramError::MissingRequiredSignature, + )?; // Update the proof's miner authority. proof.miner = *miner_info.key; diff --git a/program/src/upgrade.rs b/program/src/upgrade.rs index 19202a1..f7d692d 100644 --- a/program/src/upgrade.rs +++ b/program/src/upgrade.rs @@ -16,41 +16,32 @@ pub fn process_upgrade(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResu signer_info.is_signer()?; beneficiary_info .is_writable()? - .to_token_account()? - .check(|t| t.owner == *signer_info.key)? - .check(|t| t.mint == MINT_ADDRESS)?; + .as_token_account()? + .assert(|t| t.owner == *signer_info.key)? + .assert(|t| t.mint == MINT_ADDRESS)?; let mint = mint_info .is_writable()? .has_address(&MINT_ADDRESS)? - .to_mint()?; + .as_mint()?; mint_v1_info .is_writable()? .has_address(&MINT_V1_ADDRESS)? - .to_mint()?; + .as_mint()?; sender_info .is_writable()? - .to_token_account()? - .check(|t| t.owner == *signer_info.key)? - .check(|t| t.mint == MINT_V1_ADDRESS)?; + .as_token_account()? + .assert(|t| t.owner == *signer_info.key)? + .assert(|t| t.mint == MINT_V1_ADDRESS)?; treasury_info.is_treasury()?; token_program.is_program(&spl_token::ID)?; // Burn v1 tokens - solana_program::program::invoke( - &spl_token::instruction::burn( - &spl_token::id(), - sender_info.key, - mint_v1_info.key, - signer_info.key, - &[signer_info.key], - amount, - )?, - &[ - token_program.clone(), - sender_info.clone(), - mint_v1_info.clone(), - signer_info.clone(), - ], + burn( + sender_info, + mint_v1_info, + signer_info, + token_program, + amount, )?; // Account for decimals change. @@ -69,7 +60,7 @@ pub fn process_upgrade(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResu treasury_info, token_program, amount_to_mint, - &[&[TREASURY, &[TREASURY_BUMP]]], + &[TREASURY], )?; Ok(())