mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-14 07:26:51 +00:00
boost event
This commit is contained in:
25
Cargo.lock
generated
25
Cargo.lock
generated
@@ -246,6 +246,12 @@ version = "0.21.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.22.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
|
||||
|
||||
[[package]]
|
||||
name = "bincode"
|
||||
version = "1.3.3"
|
||||
@@ -1294,7 +1300,7 @@ dependencies = [
|
||||
"drillx",
|
||||
"mpl-token-metadata",
|
||||
"num_enum",
|
||||
"ore-utils 2.1.9",
|
||||
"ore-utils",
|
||||
"solana-program",
|
||||
"spl-associated-token-account",
|
||||
"spl-token",
|
||||
@@ -1310,7 +1316,7 @@ dependencies = [
|
||||
"bytemuck",
|
||||
"const-crypto",
|
||||
"num_enum",
|
||||
"ore-utils 2.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ore-utils",
|
||||
"solana-program",
|
||||
"spl-associated-token-account",
|
||||
"spl-token",
|
||||
@@ -1322,11 +1328,12 @@ dependencies = [
|
||||
name = "ore-program"
|
||||
version = "2.1.9"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"drillx",
|
||||
"mpl-token-metadata",
|
||||
"ore-api",
|
||||
"ore-boost-api",
|
||||
"ore-utils 2.1.9",
|
||||
"ore-utils",
|
||||
"rand 0.8.5",
|
||||
"solana-program",
|
||||
"spl-associated-token-account",
|
||||
@@ -1343,18 +1350,6 @@ dependencies = [
|
||||
"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]]
|
||||
name = "parking_lot"
|
||||
version = "0.12.3"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
use ore_utils::*;
|
||||
use solana_program::pubkey::Pubkey;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
||||
@@ -9,4 +10,11 @@ pub struct MineEvent {
|
||||
pub timing: i64,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
||||
pub struct BoostEvent {
|
||||
pub mint: Pubkey,
|
||||
pub reward: u64,
|
||||
}
|
||||
event!(MineEvent);
|
||||
event!(BoostEvent);
|
||||
|
||||
@@ -59,18 +59,30 @@ pub fn close(signer: Pubkey) -> Instruction {
|
||||
}
|
||||
|
||||
/// Builds a mine instruction.
|
||||
pub fn mine(signer: Pubkey, authority: Pubkey, bus: Pubkey, solution: Solution) -> Instruction {
|
||||
pub fn mine(
|
||||
signer: Pubkey,
|
||||
authority: Pubkey,
|
||||
bus: Pubkey,
|
||||
solution: Solution,
|
||||
boost_accounts: Vec<Pubkey>,
|
||||
) -> Instruction {
|
||||
let proof = proof_pda(authority).0;
|
||||
let accounts = vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(bus, false),
|
||||
AccountMeta::new_readonly(CONFIG_ADDRESS, false),
|
||||
AccountMeta::new(proof, false),
|
||||
AccountMeta::new_readonly(sysvar::instructions::id(), false),
|
||||
AccountMeta::new_readonly(sysvar::slot_hashes::id(), false),
|
||||
];
|
||||
let boost_accounts = boost_accounts
|
||||
.into_iter()
|
||||
.map(|pk| AccountMeta::new_readonly(pk, false))
|
||||
.collect();
|
||||
let accounts = [accounts, boost_accounts].concat();
|
||||
Instruction {
|
||||
program_id: crate::id(),
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(bus, false),
|
||||
AccountMeta::new_readonly(CONFIG_ADDRESS, false),
|
||||
AccountMeta::new(proof, false),
|
||||
AccountMeta::new_readonly(sysvar::instructions::id(), false),
|
||||
AccountMeta::new_readonly(sysvar::slot_hashes::id(), false),
|
||||
],
|
||||
accounts,
|
||||
data: Mine {
|
||||
digest: solution.d,
|
||||
nonce: solution.n,
|
||||
|
||||
@@ -26,6 +26,7 @@ ore-utils.workspace = true
|
||||
solana-program.workspace = true
|
||||
spl-token.workspace = true
|
||||
spl-associated-token-account.workspace = true
|
||||
base64 = "0.22.1"
|
||||
|
||||
[dev-dependencies]
|
||||
rand = "0.8.5"
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
use std::mem::size_of;
|
||||
|
||||
use base64::{prelude::BASE64_STANDARD, Engine};
|
||||
use drillx::Solution;
|
||||
use ore_api::{
|
||||
consts::*,
|
||||
error::OreError,
|
||||
event::MineEvent,
|
||||
event::{BoostEvent, MineEvent},
|
||||
instruction::Mine,
|
||||
loaders::*,
|
||||
state::{Bus, Config, Proof},
|
||||
@@ -27,7 +28,10 @@ use solana_program::{
|
||||
slot_hashes::SlotHash,
|
||||
sysvar::{self, Sysvar},
|
||||
};
|
||||
use solana_program::{log, program::set_return_data};
|
||||
use solana_program::{
|
||||
log::{self, sol_log},
|
||||
program::set_return_data,
|
||||
};
|
||||
|
||||
/// Mine validates hashes and increments a miner's collectable balance.
|
||||
pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult {
|
||||
@@ -149,8 +153,11 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
// Up to 3 boosts can be applied on any given mine operation.
|
||||
log::sol_log(&format!("Base: {}", reward));
|
||||
let mut applied_boosts = [Pubkey::new_from_array([0; 32]); 3];
|
||||
sol_log(optional_accounts.len().to_string().as_str());
|
||||
for i in 0..3 {
|
||||
sol_log(i.to_string().as_str());
|
||||
if optional_accounts.len().gt(&(i * 2)) {
|
||||
sol_log("booooost");
|
||||
// Load optional accounts.
|
||||
let boost_info = optional_accounts[i * 2].clone();
|
||||
let stake_info = optional_accounts[i * 2 + 1].clone();
|
||||
@@ -177,6 +184,8 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
Stake::try_from_bytes(&stake_data)?
|
||||
};
|
||||
|
||||
sol_log(format!("expires at: {}", boost.expires_at).as_str());
|
||||
sol_log(format!("t: {}", t).as_str());
|
||||
// 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) {
|
||||
let multiplier = boost.multiplier.checked_sub(1).unwrap();
|
||||
@@ -187,8 +196,14 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
.unwrap()
|
||||
.checked_div(boost.total_stake as u128)
|
||||
.unwrap() as u64;
|
||||
log::sol_log(&format!("Boost: {}", boost_reward));
|
||||
reward = reward.checked_add(boost_reward).unwrap();
|
||||
let boost_event = BoostEvent {
|
||||
mint: boost.mint,
|
||||
reward: boost_reward,
|
||||
};
|
||||
let boost_event = boost_event.to_bytes();
|
||||
let boost_event = BASE64_STANDARD.encode(boost_event);
|
||||
sol_log(format!("Boost event: {:}", boost_event).as_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user