mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-14 07:26:51 +00:00
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:
@@ -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::<Proof>(&ore_api::ID)?
|
||||
.check_mut(|p| p.authority == *signer_info.key)?;
|
||||
.as_account_mut::<Proof>(&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(())
|
||||
|
||||
@@ -10,17 +10,16 @@ pub fn process_close(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
|
||||
signer_info.is_signer()?;
|
||||
proof_info
|
||||
.is_writable()?
|
||||
.to_account::<Proof>(&ore_api::ID)?
|
||||
.check(|p| p.authority == *signer_info.key)?
|
||||
.check(|p| p.balance == 0)?;
|
||||
.as_account::<Proof>(&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(())
|
||||
}
|
||||
|
||||
@@ -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>(
|
||||
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::<Bus>(&ore_api::ID)?;
|
||||
let bus = bus_infos[i].as_account_mut::<Bus>(&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>(
|
||||
config_info,
|
||||
&ore_api::ID,
|
||||
&[CONFIG, &[args.config_bump]],
|
||||
system_program,
|
||||
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.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>(
|
||||
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(
|
||||
|
||||
@@ -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::<Bus>(&ore_api::ID)?;
|
||||
let bus = bus_info.is_bus()?.as_account_mut::<Bus>(&ore_api::ID)?;
|
||||
let config = config_info
|
||||
.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
|
||||
.to_account_mut::<Proof>(&ore_api::ID)?
|
||||
.check_mut(|p| p.miner == *signer_info.key)?;
|
||||
.as_account_mut::<Proof>(&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::<Boost>(&ore_boost_api::ID)?;
|
||||
let boost = boost_info.as_account::<Boost>(&ore_boost_api::ID)?;
|
||||
let stake = stake_info
|
||||
.to_account::<Stake>(&ore_boost_api::ID)?
|
||||
.check(|s| s.authority == proof.authority)?
|
||||
.check(|s| s.boost == *boost_info.key)?;
|
||||
.as_account::<Stake>(&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(())
|
||||
}
|
||||
|
||||
@@ -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>(
|
||||
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::<Proof>(&ore_api::ID)?;
|
||||
let proof = proof_info.as_account_mut::<Proof>(&ore_api::ID)?;
|
||||
proof.authority = *signer_info.key;
|
||||
proof.balance = 0;
|
||||
proof.challenge = hashv(&[
|
||||
|
||||
@@ -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::<Bus>(&ore_api::ID)?
|
||||
.check_mut(|b| b.id == 0)?;
|
||||
.as_account_mut::<Bus>(&ore_api::ID)?
|
||||
.assert_mut(|b| b.id == 0)?;
|
||||
let bus_1 = bus_1_info
|
||||
.to_account_mut::<Bus>(&ore_api::ID)?
|
||||
.check_mut(|b| b.id == 1)?;
|
||||
.as_account_mut::<Bus>(&ore_api::ID)?
|
||||
.assert_mut(|b| b.id == 1)?;
|
||||
let bus_2 = bus_2_info
|
||||
.to_account_mut::<Bus>(&ore_api::ID)?
|
||||
.check_mut(|b| b.id == 2)?;
|
||||
.as_account_mut::<Bus>(&ore_api::ID)?
|
||||
.assert_mut(|b| b.id == 2)?;
|
||||
let bus_3 = bus_3_info
|
||||
.to_account_mut::<Bus>(&ore_api::ID)?
|
||||
.check_mut(|b| b.id == 3)?;
|
||||
.as_account_mut::<Bus>(&ore_api::ID)?
|
||||
.assert_mut(|b| b.id == 3)?;
|
||||
let bus_4 = bus_4_info
|
||||
.to_account_mut::<Bus>(&ore_api::ID)?
|
||||
.check_mut(|b| b.id == 4)?;
|
||||
.as_account_mut::<Bus>(&ore_api::ID)?
|
||||
.assert_mut(|b| b.id == 4)?;
|
||||
let bus_5 = bus_5_info
|
||||
.to_account_mut::<Bus>(&ore_api::ID)?
|
||||
.check_mut(|b| b.id == 5)?;
|
||||
.as_account_mut::<Bus>(&ore_api::ID)?
|
||||
.assert_mut(|b| b.id == 5)?;
|
||||
let bus_6 = bus_6_info
|
||||
.to_account_mut::<Bus>(&ore_api::ID)?
|
||||
.check_mut(|b| b.id == 6)?;
|
||||
.as_account_mut::<Bus>(&ore_api::ID)?
|
||||
.assert_mut(|b| b.id == 6)?;
|
||||
let bus_7 = bus_7_info
|
||||
.to_account_mut::<Bus>(&ore_api::ID)?
|
||||
.check_mut(|b| b.id == 7)?;
|
||||
.as_account_mut::<Bus>(&ore_api::ID)?
|
||||
.assert_mut(|b| b.id == 7)?;
|
||||
let config = config_info
|
||||
.is_config()?
|
||||
.to_account_mut::<Config>(&ore_api::ID)?;
|
||||
.as_account_mut::<Config>(&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(())
|
||||
|
||||
@@ -9,8 +9,11 @@ pub fn process_update(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResu
|
||||
};
|
||||
signer_info.is_signer()?;
|
||||
let proof = proof_info
|
||||
.to_account_mut::<Proof>(&ore_api::ID)?
|
||||
.check_mut(|p| p.authority == *signer_info.key)?;
|
||||
.as_account_mut::<Proof>(&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;
|
||||
|
||||
@@ -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(())
|
||||
|
||||
Reference in New Issue
Block a user