mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-14 15:10:13 +00:00
continue migration
This commit is contained in:
@@ -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::<Proof>(&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)
|
||||
|
||||
@@ -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::<Proof>(&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)?;
|
||||
|
||||
|
||||
@@ -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)?;
|
||||
|
||||
@@ -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::<Bus>()?.is_writable()?;
|
||||
config_info.is_config()?;
|
||||
load_proof_with_miner(proof_info, signer.key, true)?;
|
||||
let bus = bus_info.to_account_mut::<Bus>(&ore_api::ID)?;
|
||||
let config = config_info.to_account::<Config>(&ore_api::ID)?;
|
||||
let proof = proof_info
|
||||
.to_account_mut::<Proof>(&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) {
|
||||
|
||||
@@ -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)?;
|
||||
|
||||
@@ -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::<Bus>(&ore_api::ID)?
|
||||
.check_mut(|b| b.id == 0)?;
|
||||
let bus_1 = bus_1_info
|
||||
.to_account_mut::<Bus>(&ore_api::ID)?
|
||||
.check_mut(|b| b.id == 1)?;
|
||||
let bus_2 = bus_2_info
|
||||
.to_account_mut::<Bus>(&ore_api::ID)?
|
||||
.check_mut(|b| b.id == 2)?;
|
||||
let bus_3 = bus_3_info
|
||||
.to_account_mut::<Bus>(&ore_api::ID)?
|
||||
.check_mut(|b| b.id == 3)?;
|
||||
let bus_4 = bus_4_info
|
||||
.to_account_mut::<Bus>(&ore_api::ID)?
|
||||
.check_mut(|b| b.id == 4)?;
|
||||
let bus_5 = bus_5_info
|
||||
.to_account_mut::<Bus>(&ore_api::ID)?
|
||||
.check_mut(|b| b.id == 5)?;
|
||||
let bus_6 = bus_6_info
|
||||
.to_account_mut::<Bus>(&ore_api::ID)?
|
||||
.check_mut(|b| b.id == 6)?;
|
||||
let bus_7 = bus_7_info
|
||||
.to_account_mut::<Bus>(&ore_api::ID)?
|
||||
.check_mut(|b| b.id == 7)?;
|
||||
let config = config_info.to_account_mut::<Config>(&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());
|
||||
}
|
||||
|
||||
@@ -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::<Proof>(&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.
|
||||
|
||||
@@ -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::<Proof>(&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(())
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user