miner migration

This commit is contained in:
Hardhat Chad
2025-08-28 13:29:57 -07:00
parent e17a90db4a
commit 53b340268d
8 changed files with 155 additions and 5 deletions

View File

@@ -19,6 +19,9 @@ pub enum OreInstruction {
SetFeeCollector = 10,
SetFeeRate = 11,
SetSniperFeeDuration = 12,
// Migration
MigrateMinerAccount = 13,
}
#[repr(C)]
@@ -100,6 +103,12 @@ pub struct SetSniperFeeDuration {
pub sniper_fee_duration: [u8; 8],
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct MigrateMinerAccount {
pub authority: [u8; 32],
}
instruction!(OreInstruction, Claim);
instruction!(OreInstruction, Open);
instruction!(OreInstruction, Close);
@@ -113,3 +122,4 @@ instruction!(OreInstruction, SetBlockDuration);
instruction!(OreInstruction, SetFeeCollector);
instruction!(OreInstruction, SetFeeRate);
instruction!(OreInstruction, SetSniperFeeDuration);
instruction!(OreInstruction, MigrateMinerAccount);

View File

@@ -287,3 +287,20 @@ pub fn set_sniper_fee_duration(signer: Pubkey, sniper_fee_duration: u64) -> Inst
.to_bytes(),
}
}
pub fn migrate_miner_account(signer: Pubkey, miner: Pubkey) -> Instruction {
let config_address = config_pda().0;
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(config_address, false),
AccountMeta::new(miner, false),
AccountMeta::new_readonly(system_program::ID, false),
],
data: MigrateMinerAccount {
authority: miner.to_bytes(),
}
.to_bytes(),
}
}

View File

@@ -1,9 +1,31 @@
use steel::*;
use crate::state::miner_pda;
use crate::state::{miner_pda, OreAccountOLD};
use super::OreAccount;
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct MinerOLD {
/// The authority of this miner account.
pub authority: Pubkey,
/// The ID of the last block this miner mined in.
pub block_id: u64,
/// The amount of hashpower this miner has committed to the current block.
pub hashpower: u64,
/// A user-supplied seed for random number generation.
pub seed: [u8; 32],
/// The total amount of hashpower this miner has committed across all blocks.
pub total_hashpower: u64,
/// The total amount of ORE this miner has mined across all blocks.
pub total_rewards: u64,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Miner {
@@ -13,6 +35,9 @@ pub struct Miner {
/// The ID of the last block this miner mined in.
pub block_id: u64,
/// An account authorized to execute actions on behalf of this miner.
pub executor: Pubkey,
/// The amount of hashpower this miner has committed to the current block.
pub hashpower: u64,
@@ -33,3 +58,4 @@ impl Miner {
}
account!(OreAccount, Miner);
account!(OreAccountOLD, MinerOLD);

View File

@@ -24,6 +24,12 @@ pub enum OreAccount {
Treasury = 104,
}
#[repr(u8)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
pub enum OreAccountOLD {
MinerOLD = 103,
}
pub fn block_pda(id: u64) -> (Pubkey, u8) {
Pubkey::find_program_address(&[BLOCK, &id.to_le_bytes()], &crate::ID)
}