From d59b3a2f4d06882e1b23f1842615e5369df62ff5 Mon Sep 17 00:00:00 2001 From: Hardhat Chad <155858888+HardhatChad@users.noreply.github.com> Date: Thu, 24 Oct 2024 13:41:03 -0500 Subject: [PATCH] Deprecate legacy staking (#99) * add post balance to MineEvent log * log input hash * deprecate legacy staking * update error message * remove stake from readme * err msg * err msg * update logs and comments * consolidate logs * last hash at * bump version * deprecate legacy staking * update error message * remove stake from readme * err msg * err msg * bump version --------- Co-authored-by: tonton-sol <19677766+tonton-sol@users.noreply.github.com> Co-authored-by: alex --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- README.md | 1 - api/src/instruction.rs | 2 ++ api/src/lib.rs | 1 + api/src/sdk.rs | 2 ++ program/src/lib.rs | 1 + program/src/mine.rs | 22 ---------------------- program/src/stake.rs | 42 ++---------------------------------------- program/src/upgrade.rs | 2 +- 10 files changed, 12 insertions(+), 67 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 73f09e9..0b8cf51 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1287,7 +1287,7 @@ checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" [[package]] name = "ore-api" -version = "2.3.0" +version = "2.4.0" dependencies = [ "array-const-fn-init", "bytemuck", @@ -1323,7 +1323,7 @@ dependencies = [ [[package]] name = "ore-program" -version = "2.3.0" +version = "2.4.0" dependencies = [ "drillx", "mpl-token-metadata", diff --git a/Cargo.toml b/Cargo.toml index 2ec9c35..da556bb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ resolver = "2" members = ["api", "program"] [workspace.package] -version = "2.3.0" +version = "2.4.0" edition = "2021" license = "Apache-2.0" homepage = "https://ore.supply" diff --git a/README.md b/README.md index 9ec44a1..8c09602 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,6 @@ - [`Close`](program/src/close.rs) – Closes a proof account returns the rent to the owner. - [`Open`](program/src/open.rs) – Opens a new proof account for a miner. - [`Mine`](program/src/mine.rs) – Verifies a hash and increments a miner's claimable balance. -- [`Stake`](program/src/stake.rs) – Stakes ORE with a miner to increase their multiplier. - [`Reset`](program/src/reset.rs) – Resets the program for a new epoch. - [`Update`](program/src/update.rs) – Updates a proof account's miner authority. - [`Upgrade`](program/src/upgrade.rs) – Migrates ORE v1 tokens to ORE v2, one-for-one. diff --git a/api/src/instruction.rs b/api/src/instruction.rs index 141df9a..f29b3b7 100644 --- a/api/src/instruction.rs +++ b/api/src/instruction.rs @@ -9,6 +9,7 @@ pub enum OreInstruction { Mine = 2, Open = 3, Reset = 4, + #[deprecated(since = "2.4.0", note = "Please stake with the boost program")] Stake = 5, Update = 6, Upgrade = 7, @@ -44,6 +45,7 @@ pub struct Open { #[derive(Clone, Copy, Debug, Pod, Zeroable)] pub struct Reset {} +#[deprecated(since = "2.4.0", note = "Please stake with the boost program")] #[repr(C)] #[derive(Clone, Copy, Debug, Pod, Zeroable)] pub struct Stake { diff --git a/api/src/lib.rs b/api/src/lib.rs index c0e78a6..f65af45 100644 --- a/api/src/lib.rs +++ b/api/src/lib.rs @@ -1,6 +1,7 @@ pub mod consts; pub mod error; pub mod event; +#[allow(deprecated)] pub mod instruction; pub mod loaders; pub mod sdk; diff --git a/api/src/sdk.rs b/api/src/sdk.rs index e9d20eb..6bac98f 100644 --- a/api/src/sdk.rs +++ b/api/src/sdk.rs @@ -124,8 +124,10 @@ pub fn reset(signer: Pubkey) -> Instruction { } /// Build a stake instruction. +#[deprecated(since = "2.4.0", note = "Please stake with the boost program")] pub fn stake(signer: Pubkey, sender: Pubkey, amount: u64) -> Instruction { let proof = proof_pda(signer).0; + #[allow(deprecated)] Instruction { program_id: crate::ID, accounts: vec![ diff --git a/program/src/lib.rs b/program/src/lib.rs index 1523004..798b9f2 100644 --- a/program/src/lib.rs +++ b/program/src/lib.rs @@ -34,6 +34,7 @@ pub fn process_instruction( OreInstruction::Mine => process_mine(accounts, data)?, OreInstruction::Open => process_open(accounts, data)?, OreInstruction::Reset => process_reset(accounts, data)?, + #[allow(deprecated)] OreInstruction::Stake => process_stake(accounts, data)?, OreInstruction::Update => process_update(accounts, data)?, OreInstruction::Upgrade => process_upgrade(accounts, data)?, diff --git a/program/src/mine.rs b/program/src/mine.rs index b653d77..adfe22d 100644 --- a/program/src/mine.rs +++ b/program/src/mine.rs @@ -94,28 +94,6 @@ pub fn process_mine(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult { .checked_mul(2u64.checked_pow(normalized_difficulty).unwrap()) .unwrap(); - // Apply staking multiplier. - // - // 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. - if proof.balance.gt(&0) && proof.last_stake_at.saturating_add(ONE_MINUTE).lt(&t) { - // Calculate staking reward. - if config.top_balance.gt(&0) { - let staking_reward = (reward as u128) - .checked_mul(proof.balance.min(config.top_balance) as u128) - .unwrap() - .checked_div(config.top_balance as u128) - .unwrap() as u64; - reward = reward.checked_add(staking_reward).unwrap(); - } - - // Update bus stake tracker. - if proof.balance.gt(&bus.top_balance) { - bus.top_balance = proof.balance; - } - } - // Apply boosts. // // Boosts are staking incentives that can multiply a miner's rewards. Up to 3 boosts can be applied diff --git a/program/src/stake.rs b/program/src/stake.rs index 7a42d80..9eee05f 100644 --- a/program/src/stake.rs +++ b/program/src/stake.rs @@ -1,44 +1,6 @@ -use ore_api::prelude::*; use steel::*; /// Stake deposits ORE into a proof account to earn multiplier. -pub fn process_stake(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult { - // Parse args. - let args = Stake::try_from_bytes(data)?; - let amount = u64::from_le_bytes(args.amount); - - // Load accounts. - let [signer_info, proof_info, sender_info, treasury_tokens_info, token_program] = accounts - else { - return Err(ProgramError::NotEnoughAccountKeys); - }; - signer_info.is_signer()?; - let proof = proof_info - .to_account_mut::(&ore_api::ID)? - .check_mut(|p| p.authority == *signer_info.key)?; - sender_info - .is_writable()? - .to_token_account()? - .check(|t| t.owner == *signer_info.key)? - .check(|t| t.mint == MINT_ADDRESS)?; - treasury_tokens_info.is_writable()?.is_treasury_tokens()?; - token_program.is_program(&spl_token::ID)?; - - // Update the proof balance. - proof.balance = proof.balance.checked_add(amount).unwrap(); - - // Update deposit timestamp. - let clock = Clock::get()?; - proof.last_stake_at = clock.unix_timestamp; - - // Transfer tokens from signer to treasury. - transfer( - signer_info, - sender_info, - treasury_tokens_info, - token_program, - amount, - )?; - - Ok(()) +pub fn process_stake(_accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult { + panic!("This instruction has been deprecated. Please stake with the boost program instead."); } diff --git a/program/src/upgrade.rs b/program/src/upgrade.rs index 74090d0..19202a1 100644 --- a/program/src/upgrade.rs +++ b/program/src/upgrade.rs @@ -4,7 +4,7 @@ use steel::*; /// Upgrade allows a user to migrate a v1 token to a v2 token at a 1:1 exchange rate. pub fn process_upgrade(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult { // Parse args - let args = Stake::try_from_bytes(data)?; + let args = Upgrade::try_from_bytes(data)?; let amount = u64::from_le_bytes(args.amount); // Load accounts