Migrate to steel v2 (#102)

* migrate to steel v2

* migrate to steel v2

* assert with err

* args ordering

* new close

* logging

* bump deps

* bump ore-boost-api version

* deprecate bumps in sdk

* remove msg

* remove comment

* remove unused import

* bump version
This commit is contained in:
Hardhat Chad
2024-10-25 17:22:41 -05:00
committed by GitHub
parent ac31c75201
commit cb24b65133
13 changed files with 165 additions and 190 deletions

12
Cargo.lock generated
View File

@@ -1287,7 +1287,7 @@ checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381"
[[package]] [[package]]
name = "ore-api" name = "ore-api"
version = "2.4.0" version = "2.5.0"
dependencies = [ dependencies = [
"array-const-fn-init", "array-const-fn-init",
"bytemuck", "bytemuck",
@@ -1305,9 +1305,9 @@ dependencies = [
[[package]] [[package]]
name = "ore-boost-api" name = "ore-boost-api"
version = "0.2.0" version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c97f55b9d1a40a6b3044444c457acd70b983d31b7edd5c8459b8c616b080fecd" checksum = "1ce6c36c89d829a4b36debc127625513aaf668ed8f0eb4982493fdc3b6b004e9"
dependencies = [ dependencies = [
"array-const-fn-init", "array-const-fn-init",
"bytemuck", "bytemuck",
@@ -1323,7 +1323,7 @@ dependencies = [
[[package]] [[package]]
name = "ore-program" name = "ore-program"
version = "2.4.0" version = "2.5.0"
dependencies = [ dependencies = [
"drillx", "drillx",
"mpl-token-metadata", "mpl-token-metadata",
@@ -2237,9 +2237,9 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]] [[package]]
name = "steel" name = "steel"
version = "1.3.0" version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d88c610ca9fd5e4e51bdb6e9964114133a42f006713fe38aff37266fac91e1be" checksum = "7a2ca3cc310b7b71ce7944af64fb4fdaa5d0c2848ac79616d75e401913b6f781"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"num_enum", "num_enum",

View File

@@ -3,7 +3,7 @@ resolver = "2"
members = ["api", "program"] members = ["api", "program"]
[workspace.package] [workspace.package]
version = "2.4.0" version = "2.5.0"
edition = "2021" edition = "2021"
license = "Apache-2.0" license = "Apache-2.0"
homepage = "https://ore.supply" homepage = "https://ore.supply"
@@ -20,10 +20,10 @@ drillx = { version = "2.0.0", features = ["solana"] }
mpl-token-metadata = "4.1.2" mpl-token-metadata = "4.1.2"
num_enum = "0.7.2" num_enum = "0.7.2"
ore-api = { path = "api", version = "2.1.9" } ore-api = { path = "api", version = "2.1.9" }
ore-boost-api = "0.2" ore-boost-api = "0.3"
solana-program = "^1.18" solana-program = "^1.18"
spl-token = { version = "^4", features = ["no-entrypoint"] } spl-token = { version = "^4", features = ["no-entrypoint"] }
spl-associated-token-account = { version = "^2.3", features = [ "no-entrypoint" ] } spl-associated-token-account = { version = "^2.3", features = [ "no-entrypoint" ] }
static_assertions = "1.1.0" static_assertions = "1.1.0"
steel = { features = ["spl"], version = "1.0" } steel = { features = ["spl"], version = "2.0" }
thiserror = "1.0.57" thiserror = "1.0.57"

View File

@@ -128,6 +128,9 @@ pub const METADATA_ADDRESS: Pubkey = Pubkey::new_from_array(
pub const MINT_ADDRESS: Pubkey = pub const MINT_ADDRESS: Pubkey =
Pubkey::new_from_array(ed25519::derive_program_address(&[MINT, &MINT_NOISE], &PROGRAM_ID).0); 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. /// The address of the v1 mint account.
pub const MINT_V1_ADDRESS: Pubkey = pubkey!("oreoN2tQbHXVaZsr3pf66A48miqcBXCDJozganhEJgz"); pub const MINT_V1_ADDRESS: Pubkey = pubkey!("oreoN2tQbHXVaZsr3pf66A48miqcBXCDJozganhEJgz");

View File

@@ -38,6 +38,7 @@ pub struct Mine {
#[repr(C)] #[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)] #[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Open { pub struct Open {
#[deprecated(since = "2.5.0", note = "Bump no longer used")]
pub bump: u8, pub bump: u8,
} }
@@ -65,17 +66,29 @@ pub struct Upgrade {
#[repr(C)] #[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)] #[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Initialize { pub struct Initialize {
#[deprecated(since = "2.5.0", note = "Bump no longer used")]
pub bus_0_bump: u8, pub bus_0_bump: u8,
#[deprecated(since = "2.5.0", note = "Bump no longer used")]
pub bus_1_bump: u8, pub bus_1_bump: u8,
#[deprecated(since = "2.5.0", note = "Bump no longer used")]
pub bus_2_bump: u8, pub bus_2_bump: u8,
#[deprecated(since = "2.5.0", note = "Bump no longer used")]
pub bus_3_bump: u8, pub bus_3_bump: u8,
#[deprecated(since = "2.5.0", note = "Bump no longer used")]
pub bus_4_bump: u8, pub bus_4_bump: u8,
#[deprecated(since = "2.5.0", note = "Bump no longer used")]
pub bus_5_bump: u8, pub bus_5_bump: u8,
#[deprecated(since = "2.5.0", note = "Bump no longer used")]
pub bus_6_bump: u8, pub bus_6_bump: u8,
#[deprecated(since = "2.5.0", note = "Bump no longer used")]
pub bus_7_bump: u8, pub bus_7_bump: u8,
#[deprecated(since = "2.5.0", note = "Bump no longer used")]
pub config_bump: u8, pub config_bump: u8,
#[deprecated(since = "2.5.0", note = "Bump no longer used")]
pub metadata_bump: u8, pub metadata_bump: u8,
#[deprecated(since = "2.5.0", note = "Bump no longer used")]
pub mint_bump: u8, pub mint_bump: u8,
#[deprecated(since = "2.5.0", note = "Bump no longer used")]
pub treasury_bump: u8, pub treasury_bump: u8,
} }

View File

@@ -83,6 +83,7 @@ pub fn mine(
} }
/// Builds an open instruction. /// Builds an open instruction.
#[allow(deprecated)]
pub fn open(signer: Pubkey, miner: Pubkey, payer: Pubkey) -> Instruction { pub fn open(signer: Pubkey, miner: Pubkey, payer: Pubkey) -> Instruction {
let proof_pda = proof_pda(signer); let proof_pda = proof_pda(signer);
Instruction { Instruction {
@@ -179,6 +180,7 @@ pub fn upgrade(signer: Pubkey, beneficiary: Pubkey, sender: Pubkey, amount: u64)
} }
/// Builds an initialize instruction. /// Builds an initialize instruction.
#[allow(deprecated)]
pub fn initialize(signer: Pubkey) -> Instruction { pub fn initialize(signer: Pubkey) -> Instruction {
let bus_pdas = [ let bus_pdas = [
bus_pda(0), bus_pda(0),

View File

@@ -16,11 +16,14 @@ pub fn process_claim(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
signer_info.is_signer()?; signer_info.is_signer()?;
beneficiary_info beneficiary_info
.is_writable()? .is_writable()?
.to_token_account()? .as_token_account()?
.check(|t| t.mint == MINT_ADDRESS)?; .assert(|t| t.mint == MINT_ADDRESS)?;
let proof = proof_info let proof = proof_info
.to_account_mut::<Proof>(&ore_api::ID)? .as_account_mut::<Proof>(&ore_api::ID)?
.check_mut(|p| p.authority == *signer_info.key)?; .assert_mut_err(
|p| p.authority == *signer_info.key,
ProgramError::MissingRequiredSignature,
)?;
treasury_info.is_treasury()?; treasury_info.is_treasury()?;
treasury_tokens_info.is_writable()?.is_treasury_tokens()?; treasury_tokens_info.is_writable()?.is_treasury_tokens()?;
token_program.is_program(&spl_token::ID)?; token_program.is_program(&spl_token::ID)?;
@@ -38,7 +41,7 @@ pub fn process_claim(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
beneficiary_info, beneficiary_info,
token_program, token_program,
amount, amount,
&[&[TREASURY, &[TREASURY_BUMP]]], &[TREASURY],
)?; )?;
Ok(()) Ok(())

View File

@@ -10,17 +10,16 @@ pub fn process_close(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
signer_info.is_signer()?; signer_info.is_signer()?;
proof_info proof_info
.is_writable()? .is_writable()?
.to_account::<Proof>(&ore_api::ID)? .as_account::<Proof>(&ore_api::ID)?
.check(|p| p.authority == *signer_info.key)? .assert_err(
.check(|p| p.balance == 0)?; |p| p.authority == *signer_info.key,
ProgramError::MissingRequiredSignature,
)?
.assert(|p| p.balance == 0)?;
system_program.is_program(&system_program::ID)?; system_program.is_program(&system_program::ID)?;
// Realloc data to zero. // Return rent to signer.
proof_info.realloc(0, true)?; proof_info.close(signer_info)?;
// Send remaining lamports to signer.
**signer_info.lamports.borrow_mut() += proof_info.lamports();
**proof_info.lamports.borrow_mut() = 0;
Ok(()) Ok(())
} }

View File

@@ -4,10 +4,7 @@ use spl_token::state::Mint;
use steel::*; use steel::*;
/// Initialize sets up the ORE program to begin mining. /// Initialize sets up the ORE program to begin mining.
pub fn process_initialize(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult { pub fn process_initialize(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
// Parse args.
let args = Initialize::try_from_bytes(data)?;
// Load accounts. // 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] = 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 accounts
@@ -18,58 +15,55 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramR
bus_0_info bus_0_info
.is_empty()? .is_empty()?
.is_writable()? .is_writable()?
.has_seeds(&[BUS, &[0]], args.bus_0_bump, &ore_api::ID)?; .has_seeds(&[BUS, &[0]], &ore_api::ID)?;
bus_1_info bus_1_info
.is_empty()? .is_empty()?
.is_writable()? .is_writable()?
.has_seeds(&[BUS, &[1]], args.bus_1_bump, &ore_api::ID)?; .has_seeds(&[BUS, &[1]], &ore_api::ID)?;
bus_2_info bus_2_info
.is_empty()? .is_empty()?
.is_writable()? .is_writable()?
.has_seeds(&[BUS, &[2]], args.bus_2_bump, &ore_api::ID)?; .has_seeds(&[BUS, &[2]], &ore_api::ID)?;
bus_3_info bus_3_info
.is_empty()? .is_empty()?
.is_writable()? .is_writable()?
.has_seeds(&[BUS, &[3]], args.bus_3_bump, &ore_api::ID)?; .has_seeds(&[BUS, &[3]], &ore_api::ID)?;
bus_4_info bus_4_info
.is_empty()? .is_empty()?
.is_writable()? .is_writable()?
.has_seeds(&[BUS, &[4]], args.bus_4_bump, &ore_api::ID)?; .has_seeds(&[BUS, &[4]], &ore_api::ID)?;
bus_5_info bus_5_info
.is_empty()? .is_empty()?
.is_writable()? .is_writable()?
.has_seeds(&[BUS, &[5]], args.bus_5_bump, &ore_api::ID)?; .has_seeds(&[BUS, &[5]], &ore_api::ID)?;
bus_6_info bus_6_info
.is_empty()? .is_empty()?
.is_writable()? .is_writable()?
.has_seeds(&[BUS, &[6]], args.bus_6_bump, &ore_api::ID)?; .has_seeds(&[BUS, &[6]], &ore_api::ID)?;
bus_7_info bus_7_info
.is_empty()? .is_empty()?
.is_writable()? .is_writable()?
.has_seeds(&[BUS, &[7]], args.bus_7_bump, &ore_api::ID)?; .has_seeds(&[BUS, &[7]], &ore_api::ID)?;
config_info config_info
.is_empty()? .is_empty()?
.is_writable()? .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_info.is_empty()?.is_writable()?.has_seeds(
&[ &[
METADATA, METADATA,
mpl_token_metadata::ID.as_ref(), mpl_token_metadata::ID.as_ref(),
MINT_ADDRESS.as_ref(), MINT_ADDRESS.as_ref(),
], ],
args.metadata_bump,
&mpl_token_metadata::ID, &mpl_token_metadata::ID,
)?; )?;
mint_info.is_empty()?.is_writable()?.has_seeds( mint_info
&[MINT, MINT_NOISE.as_slice()], .is_empty()?
args.mint_bump, .is_writable()?
&ore_api::ID, .has_seeds(&[MINT, MINT_NOISE.as_slice()], &ore_api::ID)?;
)?; treasury_info
treasury_info.is_empty()?.is_writable()?.has_seeds( .is_empty()?
&[TREASURY], .is_writable()?
args.treasury_bump, .has_seeds(&[TREASURY], &ore_api::ID)?;
&ore_api::ID,
)?;
treasury_tokens_info.is_empty()?.is_writable()?; treasury_tokens_info.is_empty()?.is_writable()?;
system_program.is_program(&system_program::ID)?; system_program.is_program(&system_program::ID)?;
token_program.is_program(&spl_token::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_0_info, bus_1_info, bus_2_info, bus_3_info, bus_4_info, bus_5_info, bus_6_info,
bus_7_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 { for i in 0..BUS_COUNT {
create_account::<Bus>( create_account::<Bus>(
bus_infos[i], bus_infos[i],
&ore_api::ID,
&[BUS, &[i as u8], &[bus_bumps[i]]],
system_program, system_program,
signer_info, signer_info,
&ore_api::ID,
&[BUS, &[i as u8]],
)?; )?;
let bus = bus_infos[i].to_account_mut::<Bus>(&ore_api::ID)?; let bus = bus_infos[i].as_account_mut::<Bus>(&ore_api::ID)?;
bus.id = i as u64; bus.id = i as u64;
bus.rewards = 0; bus.rewards = 0;
bus.theoretical_rewards = 0; bus.theoretical_rewards = 0;
@@ -110,12 +94,12 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramR
// Initialize config. // Initialize config.
create_account::<Config>( create_account::<Config>(
config_info, config_info,
&ore_api::ID,
&[CONFIG, &[args.config_bump]],
system_program, system_program,
signer_info, signer_info,
&ore_api::ID,
&[CONFIG],
)?; )?;
let config = config_info.to_account_mut::<Config>(&ore_api::ID)?; let config = config_info.as_account_mut::<Config>(&ore_api::ID)?;
config.base_reward_rate = INITIAL_BASE_REWARD_RATE; config.base_reward_rate = INITIAL_BASE_REWARD_RATE;
config.last_reset_at = 0; config.last_reset_at = 0;
config.min_difficulty = INITIAL_MIN_DIFFICULTY as u64; config.min_difficulty = INITIAL_MIN_DIFFICULTY as u64;
@@ -124,36 +108,31 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramR
// Initialize treasury. // Initialize treasury.
create_account::<Treasury>( create_account::<Treasury>(
treasury_info, treasury_info,
&ore_api::ID,
&[TREASURY, &[args.treasury_bump]],
system_program, system_program,
signer_info, signer_info,
&ore_api::ID,
&[TREASURY],
)?; )?;
// Initialize mint. // Initialize mint.
allocate_account( allocate_account_with_bump(
mint_info, mint_info,
&spl_token::ID,
Mint::LEN,
&[MINT, MINT_NOISE.as_slice(), &[args.mint_bump]],
system_program, system_program,
signer_info, signer_info,
Mint::LEN,
&spl_token::ID,
&[MINT, MINT_NOISE.as_slice()],
MINT_BUMP,
)?; )?;
solana_program::program::invoke_signed( initialize_mint_signed_with_bump(
&spl_token::instruction::initialize_mint( mint_info,
&spl_token::ID, treasury_info,
mint_info.key, None,
treasury_info.key, token_program,
None, rent_sysvar,
TOKEN_DECIMALS, TOKEN_DECIMALS,
)?, &[MINT, MINT_NOISE.as_slice()],
&[ MINT_BUMP,
token_program.clone(),
mint_info.clone(),
treasury_info.clone(),
rent_sysvar.clone(),
],
&[&[MINT, MINT_NOISE.as_slice(), &[args.mint_bump]]],
)?; )?;
// Initialize mint metadata. // Initialize mint metadata.
@@ -180,7 +159,7 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramR
collection_details: None, collection_details: None,
}, },
} }
.invoke_signed(&[&[TREASURY, &[args.treasury_bump]]])?; .invoke_signed(&[&[TREASURY, &[TREASURY_BUMP]]])?;
// Initialize treasury token account. // Initialize treasury token account.
create_associated_token_account( create_associated_token_account(

View File

@@ -6,7 +6,6 @@ use ore_boost_api::state::{Boost, Stake};
#[allow(deprecated)] #[allow(deprecated)]
use solana_program::{ use solana_program::{
keccak::hashv, keccak::hashv,
program::set_return_data,
sanitize::SanitizeError, sanitize::SanitizeError,
serialize_utils::{read_pubkey, read_u16}, serialize_utils::{read_pubkey, read_u16},
slot_hashes::SlotHash, slot_hashes::SlotHash,
@@ -19,6 +18,8 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult {
let args = Mine::try_from_bytes(data)?; let args = Mine::try_from_bytes(data)?;
// Load accounts. // Load accounts.
let clock = Clock::get()?;
let t: i64 = clock.unix_timestamp;
let (required_accounts, optional_accounts) = accounts.split_at(6); let (required_accounts, optional_accounts) = accounts.split_at(6);
let [signer_info, 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] =
required_accounts required_accounts
@@ -26,13 +27,20 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult {
return Err(ProgramError::NotEnoughAccountKeys); return Err(ProgramError::NotEnoughAccountKeys);
}; };
signer_info.is_signer()?; signer_info.is_signer()?;
let bus = bus_info.is_bus()?.to_account_mut::<Bus>(&ore_api::ID)?; let bus = bus_info.is_bus()?.as_account_mut::<Bus>(&ore_api::ID)?;
let config = config_info let config = config_info
.is_config()? .is_config()?
.to_account::<Config>(&ore_api::ID)?; .as_account::<Config>(&ore_api::ID)?
.assert_err(
|c| c.last_reset_at.saturating_add(EPOCH_DURATION) > t,
OreError::NeedsReset.into(),
)?;
let proof = proof_info let proof = proof_info
.to_account_mut::<Proof>(&ore_api::ID)? .as_account_mut::<Proof>(&ore_api::ID)?
.check_mut(|p| p.miner == *signer_info.key)?; .assert_mut_err(
|p| p.miner == *signer_info.key,
ProgramError::MissingRequiredSignature,
)?;
instructions_sysvar.is_sysvar(&sysvar::instructions::ID)?; instructions_sysvar.is_sysvar(&sysvar::instructions::ID)?;
slot_hashes_sysvar.is_sysvar(&sysvar::slot_hashes::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. // in the transaction must use the same proof account.
authenticate(&instructions_sysvar.data.borrow(), proof_info.key)?; 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. // Reject spam transactions.
// //
// Miners are rate limited to approximately 1 hash per minute. If a miner attempts to submit // 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. // 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_target = proof.last_hash_at.saturating_add(ONE_MINUTE);
let t_spam = t_target.saturating_sub(TOLERANCE); let t_spam = t_target.saturating_sub(TOLERANCE);
if t.lt(&t_spam) { if t.lt(&t_spam) {
@@ -106,11 +103,11 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult {
// Load optional accounts. // Load optional accounts.
let boost_info = optional_accounts[i * 2].clone(); let boost_info = optional_accounts[i * 2].clone();
let stake_info = optional_accounts[i * 2 + 1].clone(); let stake_info = optional_accounts[i * 2 + 1].clone();
let boost = boost_info.to_account::<Boost>(&ore_boost_api::ID)?; let boost = boost_info.as_account::<Boost>(&ore_boost_api::ID)?;
let stake = stake_info let stake = stake_info
.to_account::<Stake>(&ore_boost_api::ID)? .as_account::<Stake>(&ore_boost_api::ID)?
.check(|s| s.authority == proof.authority)? .assert(|s| s.authority == proof.authority)?
.check(|s| s.boost == *boost_info.key)?; .assert(|s| s.boost == *boost_info.key)?;
// Skip if boost is applied twice. // Skip if boost is applied twice.
if applied_boosts.contains(boost_info.key) { 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) .checked_div(reward_pre_penalty as u128)
.unwrap() as u64; .unwrap() as u64;
} }
set_return_data( MineEvent {
MineEvent { balance: proof.balance,
balance: proof.balance, difficulty: difficulty as u64,
difficulty: difficulty as u64, last_hash_at: prev_last_hash_at,
last_hash_at: prev_last_hash_at, timing: t.saturating_sub(t_liveness),
timing: t.saturating_sub(t_liveness), reward: reward_actual,
reward: reward_actual, boost_1: boost_rewards[0],
boost_1: boost_rewards[0], boost_2: boost_rewards[1],
boost_2: boost_rewards[1], boost_3: boost_rewards[2],
boost_3: boost_rewards[2], }
} .log_return();
.to_bytes(),
);
Ok(()) Ok(())
} }

View File

@@ -5,10 +5,7 @@ use solana_program::{keccak::hashv, slot_hashes::SlotHash};
use steel::*; use steel::*;
/// Open creates a new proof account to track a miner's state. /// Open creates a new proof account to track a miner's state.
pub fn process_open(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult { pub fn process_open(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
// Parse args.
let args = Open::try_from_bytes(data)?;
// Load accounts. // Load accounts.
let [signer_info, miner_info, payer_info, proof_info, system_program, slot_hashes_info] = let [signer_info, miner_info, payer_info, proof_info, system_program, slot_hashes_info] =
accounts accounts
@@ -17,24 +14,23 @@ pub fn process_open(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
}; };
signer_info.is_signer()?; signer_info.is_signer()?;
payer_info.is_signer()?; payer_info.is_signer()?;
proof_info.is_empty()?.is_writable()?.has_seeds( proof_info
&[PROOF, signer_info.key.as_ref()], .is_empty()?
args.bump, .is_writable()?
&ore_api::ID, .has_seeds(&[PROOF, signer_info.key.as_ref()], &ore_api::ID)?;
)?;
system_program.is_program(&system_program::ID)?; system_program.is_program(&system_program::ID)?;
slot_hashes_info.is_sysvar(&sysvar::slot_hashes::ID)?; slot_hashes_info.is_sysvar(&sysvar::slot_hashes::ID)?;
// Initialize proof. // Initialize proof.
create_account::<Proof>( create_account::<Proof>(
proof_info, proof_info,
&ore_api::ID,
&[PROOF, signer_info.key.as_ref(), &[args.bump]],
system_program, system_program,
payer_info, payer_info,
&ore_api::ID,
&[PROOF, signer_info.key.as_ref()],
)?; )?;
let clock = Clock::get()?; let clock = Clock::get()?;
let proof = proof_info.to_account_mut::<Proof>(&ore_api::ID)?; let proof = proof_info.as_account_mut::<Proof>(&ore_api::ID)?;
proof.authority = *signer_info.key; proof.authority = *signer_info.key;
proof.balance = 0; proof.balance = 0;
proof.challenge = hashv(&[ proof.challenge = hashv(&[

View File

@@ -11,36 +11,36 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
}; };
signer_info.is_signer()?; signer_info.is_signer()?;
let bus_0 = bus_0_info let bus_0 = bus_0_info
.to_account_mut::<Bus>(&ore_api::ID)? .as_account_mut::<Bus>(&ore_api::ID)?
.check_mut(|b| b.id == 0)?; .assert_mut(|b| b.id == 0)?;
let bus_1 = bus_1_info let bus_1 = bus_1_info
.to_account_mut::<Bus>(&ore_api::ID)? .as_account_mut::<Bus>(&ore_api::ID)?
.check_mut(|b| b.id == 1)?; .assert_mut(|b| b.id == 1)?;
let bus_2 = bus_2_info let bus_2 = bus_2_info
.to_account_mut::<Bus>(&ore_api::ID)? .as_account_mut::<Bus>(&ore_api::ID)?
.check_mut(|b| b.id == 2)?; .assert_mut(|b| b.id == 2)?;
let bus_3 = bus_3_info let bus_3 = bus_3_info
.to_account_mut::<Bus>(&ore_api::ID)? .as_account_mut::<Bus>(&ore_api::ID)?
.check_mut(|b| b.id == 3)?; .assert_mut(|b| b.id == 3)?;
let bus_4 = bus_4_info let bus_4 = bus_4_info
.to_account_mut::<Bus>(&ore_api::ID)? .as_account_mut::<Bus>(&ore_api::ID)?
.check_mut(|b| b.id == 4)?; .assert_mut(|b| b.id == 4)?;
let bus_5 = bus_5_info let bus_5 = bus_5_info
.to_account_mut::<Bus>(&ore_api::ID)? .as_account_mut::<Bus>(&ore_api::ID)?
.check_mut(|b| b.id == 5)?; .assert_mut(|b| b.id == 5)?;
let bus_6 = bus_6_info let bus_6 = bus_6_info
.to_account_mut::<Bus>(&ore_api::ID)? .as_account_mut::<Bus>(&ore_api::ID)?
.check_mut(|b| b.id == 6)?; .assert_mut(|b| b.id == 6)?;
let bus_7 = bus_7_info let bus_7 = bus_7_info
.to_account_mut::<Bus>(&ore_api::ID)? .as_account_mut::<Bus>(&ore_api::ID)?
.check_mut(|b| b.id == 7)?; .assert_mut(|b| b.id == 7)?;
let config = config_info let config = config_info
.is_config()? .is_config()?
.to_account_mut::<Config>(&ore_api::ID)?; .as_account_mut::<Config>(&ore_api::ID)?;
let mint = mint_info let mint = mint_info
.has_address(&MINT_ADDRESS)? .has_address(&MINT_ADDRESS)?
.is_writable()? .is_writable()?
.to_mint()?; .as_mint()?;
treasury_info.is_treasury()?.is_writable()?; treasury_info.is_treasury()?.is_writable()?;
treasury_tokens_info.is_treasury_tokens()?.is_writable()?; treasury_tokens_info.is_treasury_tokens()?.is_writable()?;
token_program.is_program(&spl_token::ID)?; token_program.is_program(&spl_token::ID)?;
@@ -109,22 +109,13 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
let amount = MAX_SUPPLY let amount = MAX_SUPPLY
.saturating_sub(mint.supply) .saturating_sub(mint.supply)
.min(total_epoch_rewards); .min(total_epoch_rewards);
solana_program::program::invoke_signed( mint_to_signed(
&spl_token::instruction::mint_to( mint_info,
&spl_token::id(), treasury_tokens_info,
mint_info.key, treasury_info,
treasury_tokens_info.key, token_program,
treasury_info.key, amount,
&[treasury_info.key], &[TREASURY],
amount,
)?,
&[
token_program.clone(),
mint_info.clone(),
treasury_tokens_info.clone(),
treasury_info.clone(),
],
&[&[TREASURY, &[TREASURY_BUMP]]],
)?; )?;
Ok(()) Ok(())

View File

@@ -9,8 +9,11 @@ pub fn process_update(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResu
}; };
signer_info.is_signer()?; signer_info.is_signer()?;
let proof = proof_info let proof = proof_info
.to_account_mut::<Proof>(&ore_api::ID)? .as_account_mut::<Proof>(&ore_api::ID)?
.check_mut(|p| p.authority == *signer_info.key)?; .assert_mut_err(
|p| p.authority == *signer_info.key,
ProgramError::MissingRequiredSignature,
)?;
// Update the proof's miner authority. // Update the proof's miner authority.
proof.miner = *miner_info.key; proof.miner = *miner_info.key;

View File

@@ -16,41 +16,32 @@ pub fn process_upgrade(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResu
signer_info.is_signer()?; signer_info.is_signer()?;
beneficiary_info beneficiary_info
.is_writable()? .is_writable()?
.to_token_account()? .as_token_account()?
.check(|t| t.owner == *signer_info.key)? .assert(|t| t.owner == *signer_info.key)?
.check(|t| t.mint == MINT_ADDRESS)?; .assert(|t| t.mint == MINT_ADDRESS)?;
let mint = mint_info let mint = mint_info
.is_writable()? .is_writable()?
.has_address(&MINT_ADDRESS)? .has_address(&MINT_ADDRESS)?
.to_mint()?; .as_mint()?;
mint_v1_info mint_v1_info
.is_writable()? .is_writable()?
.has_address(&MINT_V1_ADDRESS)? .has_address(&MINT_V1_ADDRESS)?
.to_mint()?; .as_mint()?;
sender_info sender_info
.is_writable()? .is_writable()?
.to_token_account()? .as_token_account()?
.check(|t| t.owner == *signer_info.key)? .assert(|t| t.owner == *signer_info.key)?
.check(|t| t.mint == MINT_V1_ADDRESS)?; .assert(|t| t.mint == MINT_V1_ADDRESS)?;
treasury_info.is_treasury()?; treasury_info.is_treasury()?;
token_program.is_program(&spl_token::ID)?; token_program.is_program(&spl_token::ID)?;
// Burn v1 tokens // Burn v1 tokens
solana_program::program::invoke( burn(
&spl_token::instruction::burn( sender_info,
&spl_token::id(), mint_v1_info,
sender_info.key, signer_info,
mint_v1_info.key, token_program,
signer_info.key, amount,
&[signer_info.key],
amount,
)?,
&[
token_program.clone(),
sender_info.clone(),
mint_v1_info.clone(),
signer_info.clone(),
],
)?; )?;
// Account for decimals change. // Account for decimals change.
@@ -69,7 +60,7 @@ pub fn process_upgrade(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResu
treasury_info, treasury_info,
token_program, token_program,
amount_to_mint, amount_to_mint,
&[&[TREASURY, &[TREASURY_BUMP]]], &[TREASURY],
)?; )?;
Ok(()) Ok(())