migration

This commit is contained in:
Hardhat Chad
2025-09-18 09:00:49 -07:00
parent 7c94459df0
commit ffaa93d947
9 changed files with 410 additions and 244 deletions

View File

@@ -29,6 +29,47 @@ pub fn boost(signer: Pubkey) -> Instruction {
}
}
// let [signer_info, authority_info, miner_info, miner_tokens_info, mint_info, recipient_info, system_program, token_program, associated_token_program] =
pub fn migrate_miner(signer: Pubkey, authority: Pubkey) -> Instruction {
let miner_address = miner_pda(authority).0;
let miner_tokens_address = get_associated_token_address(&miner_address, &MINT_ADDRESS);
let recipient_address = get_associated_token_address(&authority, &MINT_ADDRESS);
let mint_address = MINT_ADDRESS;
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(authority, false),
AccountMeta::new(miner_address, false),
AccountMeta::new(miner_tokens_address, false),
AccountMeta::new(mint_address, false),
AccountMeta::new(recipient_address, false),
AccountMeta::new_readonly(system_program::ID, false),
AccountMeta::new_readonly(spl_token::ID, false),
AccountMeta::new_readonly(spl_associated_token_account::ID, false),
],
data: MigrateMiner {}.to_bytes(),
}
}
// let [signer_info, config_info, treasury_info, system_program] = accounts else {
pub fn migrate_treasury(signer: Pubkey) -> Instruction {
let config_address = config_pda().0;
let treasury_address = treasury_pda().0;
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(config_address, false),
AccountMeta::new(treasury_address, false),
AccountMeta::new_readonly(system_program::ID, false),
],
data: MigrateTreasury {}.to_bytes(),
}
}
// let [signer_info, board_info, config_info, mint_info, treasury_info, vault_info, system_program, token_program, associated_token_program] =
pub fn initialize(signer: Pubkey) -> Instruction {

View File

@@ -1,6 +1,6 @@
use steel::*;
use crate::state::config_pda;
use crate::state::{config_pda, OreAccountOLD};
use super::OreAccount;
@@ -25,6 +25,25 @@ pub struct Config {
pub fee_rate: u64,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct ConfigOLD {
// The address that can set the admin.
pub admin: Pubkey,
// The block duration in slots.
pub block_duration: u64,
// The duration in slots for which the sniper fee is applied.
pub sniper_fee_duration: u64,
// The address that receives fees.
pub fee_collector: Pubkey,
// The fee rate taken for each swap.
pub fee_rate: u64,
}
impl Config {
pub fn pda() -> (Pubkey, u8) {
config_pda()
@@ -32,3 +51,4 @@ impl Config {
}
account!(OreAccount, Config);
account!(OreAccountOLD, ConfigOLD);

View File

@@ -1,6 +1,6 @@
use steel::*;
use crate::state::miner_pda;
use crate::state::{miner_pda, OreAccountOLD};
use super::OreAccount;
@@ -29,6 +29,31 @@ pub struct Miner {
pub lifetime_rewards_ore: u64,
}
#[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,
/// 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,
/// 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,
}
impl Miner {
pub fn pda(&self) -> (Pubkey, u8) {
miner_pda(self.authority)
@@ -36,3 +61,4 @@ impl Miner {
}
account!(OreAccount, Miner);
account!(OreAccountOLD, MinerOLD);

View File

@@ -26,6 +26,14 @@ pub enum OreAccount {
Square = 106,
}
#[repr(u8)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
pub enum OreAccountOLD {
ConfigOLD = 101,
MinerOLD = 103,
TreasuryOLD = 104,
}
pub fn board_pda() -> (Pubkey, u8) {
Pubkey::find_program_address(&[BOARD], &crate::ID)
}
@@ -42,11 +50,6 @@ pub fn square_pda(id: u64) -> (Pubkey, u8) {
Pubkey::find_program_address(&[SQUARE, &id.to_le_bytes()], &crate::ID)
}
// pub fn vault_address() -> Pubkey {
// let board_address = board_pda().0;
// spl_associated_token_account::get_associated_token_address(&board_address, &MINT_ADDRESS)
// }
pub fn treasury_pda() -> (Pubkey, u8) {
Pubkey::find_program_address(&[TREASURY], &crate::ID)
}

View File

@@ -1,6 +1,6 @@
use steel::*;
use crate::state::treasury_pda;
use crate::state::{treasury_pda, OreAccountOLD};
use super::OreAccount;
@@ -12,6 +12,12 @@ pub struct Treasury {
pub balance: u64,
}
/// Treasury is a singleton account which is the mint authority for the ORE token and the authority of
/// the program's global token account.
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct TreasuryOLD {}
impl Treasury {
pub fn pda() -> (Pubkey, u8) {
treasury_pda()
@@ -19,3 +25,4 @@ impl Treasury {
}
account!(OreAccount, Treasury);
account!(OreAccountOLD, TreasuryOLD);