Skip to content

Commit

Permalink
upgrade to steel v2
Browse files Browse the repository at this point in the history
  • Loading branch information
HardhatChad committed Oct 25, 2024
1 parent 1d6ea5f commit 62d6be1
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 77 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resolver = "2"
members = ["api", "cli", "program"]

[workspace.package]
version = "0.2.0"
version = "0.3.0"
edition = "2021"
license = "Apache-2.0"
homepage = "https://ore.supply"
Expand All @@ -22,7 +22,7 @@ const-crypto = "0.1.0"
log = "0.4"
futures = "0.3"
num_enum = "0.7.2"
ore-boost-api = { path = "api", version = "0.2" }
ore-boost-api = { path = "api", version = "0.3" }
solana-cli-config = "^1.18"
solana-client = "^1.18"
solana-program = "^1.18"
Expand All @@ -34,7 +34,7 @@ spl-associated-token-account = { version = "^2.3", features = [
"no-entrypoint",
] }
static_assertions = "1.1.0"
steel = { features = ["spl"], version = "1.2" }
steel = { features = ["spl"], version = "2.0" }
thiserror = "1.0.57"
tokio = "1.35"

3 changes: 3 additions & 0 deletions api/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ pub struct Deposit {
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Initialize {
#[deprecated(since = "0.3.0", note = "Bump no longer used")]
pub config_bump: u8,
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct New {
#[deprecated(since = "0.3.0", note = "Bump no longer used")]
pub bump: u8,
pub expires_at: [u8; 8],
pub multiplier: [u8; 8],
Expand All @@ -50,6 +52,7 @@ pub struct New {
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Open {
#[deprecated(since = "0.3.0", note = "Bump no longer used")]
pub stake_bump: u8,
}

Expand Down
3 changes: 3 additions & 0 deletions api/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub fn deposit(signer: Pubkey, mint: Pubkey, amount: u64) -> Instruction {
}

// Build initialize instruction.
#[allow(deprecated)]
pub fn initialize(signer: Pubkey) -> Instruction {
let config_pda = config_pda();
Instruction {
Expand All @@ -48,6 +49,7 @@ pub fn initialize(signer: Pubkey) -> Instruction {
}

// Build new instruction.
#[allow(deprecated)]
pub fn new(signer: Pubkey, mint: Pubkey, expires_at: i64, multiplier: u64) -> Instruction {
let boost_pda = boost_pda(mint);
let boost_tokens_address =
Expand All @@ -74,6 +76,7 @@ pub fn new(signer: Pubkey, mint: Pubkey, expires_at: i64, multiplier: u64) -> In
}

// Build open instruction.
#[allow(deprecated)]
pub fn open(signer: Pubkey, payer: Pubkey, mint: Pubkey) -> Instruction {
let boost_pda = boost_pda(mint);
let stake_pda = stake_pda(signer, boost_pda.0);
Expand Down
6 changes: 3 additions & 3 deletions program/src/close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ pub fn process_close(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
};
signer_info.is_signer()?;
stake_info
.to_account_mut::<Stake>(&ore_boost_api::ID)?
.check_mut(|s| s.authority == *signer_info.key)?
.check_mut(|s| s.balance == 0)?;
.as_account_mut::<Stake>(&ore_boost_api::ID)?
.assert_mut(|s| s.authority == *signer_info.key)?
.assert_mut(|s| s.balance == 0)?;
system_program.is_program(&system_program::ID)?;

// Realloc data to zero.
Expand Down
20 changes: 10 additions & 10 deletions program/src/deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ pub fn process_deposit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResu
};
signer_info.is_signer()?;
let boost = boost_info
.to_account_mut::<Boost>(&ore_boost_api::ID)?
.check_mut(|b| b.mint == *mint_info.key)?;
.as_account_mut::<Boost>(&ore_boost_api::ID)?
.assert_mut(|b| b.mint == *mint_info.key)?;
boost_tokens_info
.is_writable()?
.to_associated_token_account(boost_info.key, mint_info.key)?;
mint_info.to_mint()?;
.as_associated_token_account(boost_info.key, mint_info.key)?;
mint_info.as_mint()?;
sender_info
.is_writable()?
.to_token_account()?
.check(|t| t.owner == *signer_info.key)?
.check(|t| t.mint == *mint_info.key)?;
.as_token_account()?
.assert(|t| t.owner == *signer_info.key)?
.assert(|t| t.mint == *mint_info.key)?;
let stake = stake_info
.to_account_mut::<Stake>(&ore_boost_api::ID)?
.check_mut(|s| s.authority == *signer_info.key)?
.check_mut(|s| s.boost == *boost_info.key)?;
.as_account_mut::<Stake>(&ore_boost_api::ID)?
.assert_mut(|s| s.authority == *signer_info.key)?
.assert_mut(|s| s.boost == *boost_info.key)?;
token_program.is_program(&spl_token::ID)?;

// Update balances.
Expand Down
20 changes: 8 additions & 12 deletions program/src/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,27 @@ use ore_boost_api::prelude::*;
use steel::*;

/// Initialize sets up the boost program.
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, config_info, system_program] = accounts else {
return Err(ProgramError::NotEnoughAccountKeys);
};
signer_info.is_signer()?.has_address(&INITIALIZER_ADDRESS)?;
config_info.is_writable()?.is_empty()?.has_seeds(
&[CONFIG],
args.config_bump,
&ore_boost_api::ID,
)?;
config_info
.is_writable()?
.is_empty()?
.has_seeds(&[CONFIG], &ore_boost_api::ID)?;
system_program.is_program(&system_program::ID)?;

// Initialize config account.
create_account::<Config>(
config_info,
&ore_boost_api::id(),
&[CONFIG, &[args.config_bump]],
system_program,
signer_info,
&ore_boost_api::id(),
&[CONFIG],
)?;
let config = config_info.to_account_mut::<Config>(&ore_boost_api::ID)?;
let config = config_info.as_account_mut::<Config>(&ore_boost_api::ID)?;
config.authority = *signer_info.key;

Ok(())
Expand Down
22 changes: 10 additions & 12 deletions program/src/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,28 @@ pub fn process_new(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult {
return Err(ProgramError::NotEnoughAccountKeys);
};
signer_info.is_signer()?;
boost_info.is_writable()?.is_empty()?.has_seeds(
&[BOOST, mint_info.key.as_ref()],
args.bump,
&ore_boost_api::id(),
)?;
boost_info
.is_writable()?
.is_empty()?
.has_seeds(&[BOOST, mint_info.key.as_ref()], &ore_boost_api::id())?;
boost_tokens_info.is_writable()?.is_empty()?;
config_info
.to_account::<Config>(&ore_boost_api::ID)?
.check(|c| c.authority == *signer_info.key)?;
mint_info.to_mint()?;
.as_account::<Config>(&ore_boost_api::ID)?
.assert(|c| c.authority == *signer_info.key)?;
mint_info.as_mint()?;
system_program.is_program(&system_program::ID)?;
token_program.is_program(&spl_token::ID)?;
associated_token_program.is_program(&spl_associated_token_account::ID)?;

// Initialize the boost account.
create_account::<Boost>(
boost_info,
&ore_boost_api::id(),
&[BOOST, mint_info.key.as_ref(), &[args.bump]],
system_program,
signer_info,
&ore_boost_api::id(),
&[BOOST, mint_info.key.as_ref()],
)?;
let boost = boost_info.to_account_mut::<Boost>(&ore_boost_api::ID)?;
boost.bump = args.bump as u64;
let boost = boost_info.as_account_mut::<Boost>(&ore_boost_api::ID)?;
boost.mint = *mint_info.key;
boost.expires_at = expires_at;
boost.multiplier = multiplier;
Expand Down
24 changes: 7 additions & 17 deletions program/src/open.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
use ore_boost_api::{
consts::STAKE,
instruction::Open,
state::{Boost, Stake},
};
use solana_program::system_program;
use steel::*;

/// Open creates a new stake account.
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, payer_info, boost_info, mint_info, stake_info, system_program] = accounts
else {
Expand All @@ -19,31 +15,25 @@ pub fn process_open(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
signer_info.is_signer()?;
payer_info.is_signer()?;
boost_info
.to_account::<Boost>(&ore_boost_api::ID)?
.check(|b| b.mint == *mint_info.key)?;
mint_info.to_mint()?;
.as_account::<Boost>(&ore_boost_api::ID)?
.assert(|b| b.mint == *mint_info.key)?;
mint_info.as_mint()?;
stake_info.is_empty()?.is_writable()?.has_seeds(
&[STAKE, signer_info.key.as_ref(), boost_info.key.as_ref()],
args.stake_bump,
&ore_boost_api::ID,
)?;
system_program.is_program(&system_program::ID)?;

// Initialize the stake account.
create_account::<Stake>(
stake_info,
&ore_boost_api::ID,
&[
STAKE,
signer_info.key.as_ref(),
boost_info.key.as_ref(),
&[args.stake_bump],
],
system_program,
payer_info,
&ore_boost_api::ID,
&[STAKE, signer_info.key.as_ref(), boost_info.key.as_ref()],
)?;
let clock = Clock::get()?;
let stake = stake_info.to_account_mut::<Stake>(&ore_boost_api::ID)?;
let stake = stake_info.as_account_mut::<Stake>(&ore_boost_api::ID)?;
stake.authority = *signer_info.key;
stake.balance = 0;
stake.boost = *boost_info.key;
Expand Down
4 changes: 2 additions & 2 deletions program/src/update_admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ pub fn process_update_admin(accounts: &[AccountInfo<'_>], data: &[u8]) -> Progra
};
signer_info.is_signer()?;
let config = config_info
.to_account_mut::<Config>(&ore_boost_api::ID)?
.check_mut(|c| c.authority == *signer_info.key)?;
.as_account_mut::<Config>(&ore_boost_api::ID)?
.assert_mut(|c| c.authority == *signer_info.key)?;

// Update the admin.
config.authority = args.new_admin;
Expand Down
6 changes: 3 additions & 3 deletions program/src/update_boost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ pub fn process_update_boost(accounts: &[AccountInfo<'_>], data: &[u8]) -> Progra
return Err(ProgramError::NotEnoughAccountKeys);
};
signer_info.is_signer()?;
let boost = boost_info.to_account_mut::<Boost>(&ore_boost_api::ID)?;
let boost = boost_info.as_account_mut::<Boost>(&ore_boost_api::ID)?;
config_info
.to_account::<Config>(&ore_boost_api::ID)?
.check(|c| c.authority == *signer_info.key)?;
.as_account::<Config>(&ore_boost_api::ID)?
.assert(|c| c.authority == *signer_info.key)?;

// Update the boost multiplier.
boost.multiplier = multiplier;
Expand Down
20 changes: 10 additions & 10 deletions program/src/withdraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ pub fn process_withdraw(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRes
signer_info.is_signer()?;
beneficiary_info
.is_writable()?
.to_token_account()?
.check(|t| t.mint == *mint_info.key)?;
.as_token_account()?
.assert(|t| t.mint == *mint_info.key)?;
let boost = boost_info
.to_account_mut::<Boost>(&ore_boost_api::ID)?
.check_mut(|b| b.mint == *mint_info.key)?;
.as_account_mut::<Boost>(&ore_boost_api::ID)?
.assert_mut(|b| b.mint == *mint_info.key)?;
boost_tokens_info
.is_writable()?
.to_associated_token_account(boost_info.key, mint_info.key)?;
mint_info.to_mint()?;
.as_associated_token_account(boost_info.key, mint_info.key)?;
mint_info.as_mint()?;
let stake = stake_info
.to_account_mut::<Stake>(&ore_boost_api::ID)?
.check_mut(|s| s.authority == *signer_info.key)?
.check_mut(|s| s.boost == *boost_info.key)?;
.as_account_mut::<Stake>(&ore_boost_api::ID)?
.assert_mut(|s| s.authority == *signer_info.key)?
.assert_mut(|s| s.boost == *boost_info.key)?;
token_program.is_program(&spl_token::ID)?;

// Update the stake balance.
Expand All @@ -48,7 +48,7 @@ pub fn process_withdraw(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRes
beneficiary_info,
token_program,
amount,
&[&[BOOST, mint_info.key.as_ref(), &[boost.bump as u8]]],
&[BOOST, mint_info.key.as_ref()],
)?;

Ok(())
Expand Down

0 comments on commit 62d6be1

Please sign in to comment.