continue migration

This commit is contained in:
Hardhat Chad
2024-09-27 00:22:32 +00:00
parent 609349a5aa
commit be20034e57
20 changed files with 175 additions and 363 deletions

View File

@@ -1,7 +1,5 @@
use steel::*;
use crate::consts::BUS;
use super::OreAccount;
/// Bus accounts are responsible for distributing mining rewards. There are 8 busses total
@@ -23,30 +21,4 @@ pub struct Bus {
pub top_balance: u64,
}
/// Fetch the PDA of a bus account.
pub fn bus_pda(id: u8) -> (Pubkey, u8) {
Pubkey::find_program_address(&[BUS, &[id]], &crate::id())
}
impl<'a> From<&'a [u8]> for &'a Bus {
fn from(value: &'a [u8]) -> &'a Bus {
Bus::try_from_bytes(value).unwrap()
}
}
impl<'a> From<*const u8> for &'a Bus {
fn from(value: *const u8) -> &'a Bus {
unsafe {
if Bus::discriminator().ne(&value.add(0).read()) {
panic!("");
}
bytemuck::try_from_bytes::<Bus>(std::slice::from_raw_parts(
value.add(8),
std::mem::size_of::<Bus>(),
))
.expect("")
}
}
}
account!(OreAccount, Bus);

View File

@@ -1,7 +1,5 @@
use steel::*;
use crate::consts::CONFIG;
use super::OreAccount;
/// Config is a singleton account which manages program global variables.
@@ -21,9 +19,4 @@ pub struct Config {
pub top_balance: u64,
}
/// Derive the PDA of the config account.
pub fn config_pda() -> (Pubkey, u8) {
Pubkey::find_program_address(&[CONFIG], &crate::id())
}
account!(OreAccount, Config);

View File

@@ -8,7 +8,9 @@ pub use config::*;
pub use proof::*;
pub use treasury::*;
use num_enum::{IntoPrimitive, TryFromPrimitive};
use steel::*;
use crate::consts::*;
#[repr(u8)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
@@ -18,3 +20,23 @@ pub enum OreAccount {
Proof = 102,
Treasury = 103,
}
/// Fetch the PDA of a bus account.
pub fn bus_pda(id: u8) -> (Pubkey, u8) {
Pubkey::find_program_address(&[BUS, &[id]], &crate::id())
}
/// Derive the PDA of the config account.
pub fn config_pda() -> (Pubkey, u8) {
Pubkey::find_program_address(&[CONFIG], &crate::id())
}
/// Derive the PDA of a proof account.
pub fn proof_pda(authority: Pubkey) -> (Pubkey, u8) {
Pubkey::find_program_address(&[PROOF, authority.as_ref()], &crate::id())
}
/// Derive the PDA of the treasury account.
pub fn treasury_pda() -> (Pubkey, u8) {
Pubkey::find_program_address(&[TREASURY], &crate::id())
}

View File

@@ -1,9 +1,5 @@
use bytemuck::{Pod, Zeroable};
use solana_program::pubkey::Pubkey;
use steel::*;
use crate::consts::PROOF;
use super::OreAccount;
/// Proof accounts track a miner's current hash, claimable rewards, and lifetime stats.
@@ -39,9 +35,4 @@ pub struct Proof {
pub total_rewards: u64,
}
/// Derive the PDA of a proof account.
pub fn proof_pda(authority: Pubkey) -> (Pubkey, u8) {
Pubkey::find_program_address(&[PROOF, authority.as_ref()], &crate::id())
}
account!(OreAccount, Proof);

View File

@@ -1,9 +1,5 @@
use bytemuck::{Pod, Zeroable};
use solana_program::pubkey::Pubkey;
use steel::*;
use crate::consts::TREASURY;
use super::OreAccount;
/// Treasury is a singleton account which is the mint authority for the ORE token and the authority of
@@ -12,9 +8,4 @@ use super::OreAccount;
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
pub struct Treasury {}
/// Derive the PDA of the treasury account.
pub fn treasury_pda() -> (Pubkey, u8) {
Pubkey::find_program_address(&[TREASURY], &crate::id())
}
account!(OreAccount, Treasury);