mirror of
https://github.com/d0zingcat/ore.git
synced 2026-06-06 15:11:30 +00:00
rebased
This commit is contained in:
18
Cargo.lock
generated
18
Cargo.lock
generated
@@ -1294,7 +1294,7 @@ dependencies = [
|
|||||||
"drillx",
|
"drillx",
|
||||||
"mpl-token-metadata",
|
"mpl-token-metadata",
|
||||||
"num_enum",
|
"num_enum",
|
||||||
"ore-utils",
|
"ore-utils 2.1.9",
|
||||||
"solana-program",
|
"solana-program",
|
||||||
"spl-associated-token-account",
|
"spl-associated-token-account",
|
||||||
"spl-token",
|
"spl-token",
|
||||||
@@ -1310,7 +1310,7 @@ dependencies = [
|
|||||||
"bytemuck",
|
"bytemuck",
|
||||||
"const-crypto",
|
"const-crypto",
|
||||||
"num_enum",
|
"num_enum",
|
||||||
"ore-utils",
|
"ore-utils 2.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"solana-program",
|
"solana-program",
|
||||||
"spl-associated-token-account",
|
"spl-associated-token-account",
|
||||||
"spl-token",
|
"spl-token",
|
||||||
@@ -1326,7 +1326,7 @@ dependencies = [
|
|||||||
"mpl-token-metadata",
|
"mpl-token-metadata",
|
||||||
"ore-api",
|
"ore-api",
|
||||||
"ore-boost-api",
|
"ore-boost-api",
|
||||||
"ore-utils",
|
"ore-utils 2.1.9",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
"solana-program",
|
"solana-program",
|
||||||
"spl-associated-token-account",
|
"spl-associated-token-account",
|
||||||
@@ -1343,6 +1343,18 @@ dependencies = [
|
|||||||
"spl-token",
|
"spl-token",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ore-utils"
|
||||||
|
version = "2.1.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7a2d6933b14c84fb91ad7ab2e8fccff589884a81507c1a198dea4f03f3180ef4"
|
||||||
|
dependencies = [
|
||||||
|
"bytemuck",
|
||||||
|
"solana-program",
|
||||||
|
"spl-associated-token-account",
|
||||||
|
"spl-token",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parking_lot"
|
name = "parking_lot"
|
||||||
version = "0.12.3"
|
version = "0.12.3"
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ use ore_boost_api::{
|
|||||||
loaders::{load_any_boost, load_stake},
|
loaders::{load_any_boost, load_stake},
|
||||||
state::{Boost, Stake},
|
state::{Boost, Stake},
|
||||||
};
|
};
|
||||||
use ore_utils::*;
|
use ore_utils::{load_signer, load_sysvar};
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
use solana_program::{
|
use solana_program::{
|
||||||
account_info::AccountInfo,
|
account_info::AccountInfo,
|
||||||
@@ -56,7 +56,10 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
|||||||
|
|
||||||
// Validate epoch is active.
|
// Validate epoch is active.
|
||||||
let config_data = config_info.data.borrow();
|
let config_data = config_info.data.borrow();
|
||||||
let config = Config::try_from_bytes(&config_data)?;
|
let config = {
|
||||||
|
use ore_utils::AccountDeserialize;
|
||||||
|
Config::try_from_bytes(&config_data)?
|
||||||
|
};
|
||||||
let clock = Clock::get().or(Err(ProgramError::InvalidAccountData))?;
|
let clock = Clock::get().or(Err(ProgramError::InvalidAccountData))?;
|
||||||
if config
|
if config
|
||||||
.last_reset_at
|
.last_reset_at
|
||||||
@@ -71,7 +74,10 @@ 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.
|
// Here we use drillx to validate the provided solution is a valid hash of the challenge.
|
||||||
// If invalid, we return an error.
|
// If invalid, we return an error.
|
||||||
let mut proof_data = proof_info.data.borrow_mut();
|
let mut proof_data = proof_info.data.borrow_mut();
|
||||||
let proof = Proof::try_from_bytes_mut(&mut proof_data)?;
|
let proof = {
|
||||||
|
use ore_utils::AccountDeserialize;
|
||||||
|
Proof::try_from_bytes_mut(&mut proof_data)?
|
||||||
|
};
|
||||||
let solution = Solution::new(args.digest, args.nonce);
|
let solution = Solution::new(args.digest, args.nonce);
|
||||||
if !solution.is_valid(&proof.challenge) {
|
if !solution.is_valid(&proof.challenge) {
|
||||||
return Err(OreError::HashInvalid.into());
|
return Err(OreError::HashInvalid.into());
|
||||||
@@ -116,7 +122,10 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
|||||||
// Any stake less than this will receives between 1x and 2x multipler. The multipler is only active
|
// 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.
|
// 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 mut bus_data = bus_info.data.borrow_mut();
|
||||||
let bus = Bus::try_from_bytes_mut(&mut bus_data)?;
|
let bus = {
|
||||||
|
use ore_utils::AccountDeserialize;
|
||||||
|
Bus::try_from_bytes_mut(&mut bus_data)?
|
||||||
|
};
|
||||||
if proof.balance.gt(&0) && proof.last_stake_at.saturating_add(ONE_MINUTE).lt(&t) {
|
if proof.balance.gt(&0) && proof.last_stake_at.saturating_add(ONE_MINUTE).lt(&t) {
|
||||||
// Calculate staking reward.
|
// Calculate staking reward.
|
||||||
if config.top_balance.gt(&0) {
|
if config.top_balance.gt(&0) {
|
||||||
@@ -158,9 +167,15 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
|||||||
|
|
||||||
// Parse account data.
|
// Parse account data.
|
||||||
let boost_data = boost_info.data.borrow();
|
let boost_data = boost_info.data.borrow();
|
||||||
let boost = Boost::try_from_bytes(&boost_data)?;
|
let boost = {
|
||||||
|
use ore_boost_api::ore_utils::AccountDeserialize;
|
||||||
|
Boost::try_from_bytes(&boost_data)?
|
||||||
|
};
|
||||||
let stake_data = stake_info.data.borrow();
|
let stake_data = stake_info.data.borrow();
|
||||||
let stake = Stake::try_from_bytes(&stake_data)?;
|
let stake = {
|
||||||
|
use ore_boost_api::ore_utils::AccountDeserialize;
|
||||||
|
Stake::try_from_bytes(&stake_data)?
|
||||||
|
};
|
||||||
|
|
||||||
// Apply multiplier if boost is not expired and last stake at was more than one minute ago.
|
// Apply multiplier if boost is not expired and last stake at was more than one minute ago.
|
||||||
if boost.expires_at.gt(&t) && stake.last_stake_at.saturating_add(ONE_MINUTE).le(&t) {
|
if boost.expires_at.gt(&t) && stake.last_stake_at.saturating_add(ONE_MINUTE).le(&t) {
|
||||||
|
|||||||
Reference in New Issue
Block a user