mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-20 07:26:50 +00:00
delegate
This commit is contained in:
2
ore-delegate/api/src/consts.rs
Normal file
2
ore-delegate/api/src/consts.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
/// The seed of the delegate account PDA.
|
||||
pub const DELEGATE: &[u8] = b"delegate";
|
||||
10
ore-delegate/api/src/error.rs
Normal file
10
ore-delegate/api/src/error.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
use steel::*;
|
||||
|
||||
#[derive(Debug, Error, Clone, Copy, PartialEq, Eq, IntoPrimitive)]
|
||||
#[repr(u32)]
|
||||
pub enum OreError {
|
||||
#[error("Placeholder error")]
|
||||
Dummy = 0,
|
||||
}
|
||||
|
||||
error!(OreError);
|
||||
1
ore-delegate/api/src/event.rs
Normal file
1
ore-delegate/api/src/event.rs
Normal file
@@ -0,0 +1 @@
|
||||
use steel::*;
|
||||
37
ore-delegate/api/src/instruction.rs
Normal file
37
ore-delegate/api/src/instruction.rs
Normal file
@@ -0,0 +1,37 @@
|
||||
use steel::*;
|
||||
|
||||
#[repr(u8)]
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
|
||||
pub enum OreDelegateInstruction {
|
||||
Deposit = 0,
|
||||
Withdraw = 1,
|
||||
Crank = 2,
|
||||
Payout = 3,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
||||
pub struct Deposit {
|
||||
pub amount: [u8; 8],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
||||
pub struct Withdraw {
|
||||
pub amount: [u8; 8],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
||||
pub struct Crank {
|
||||
pub amount: [u8; 8],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
||||
pub struct Payout {}
|
||||
|
||||
instruction!(OreDelegateInstruction, Deposit);
|
||||
instruction!(OreDelegateInstruction, Withdraw);
|
||||
instruction!(OreDelegateInstruction, Crank);
|
||||
instruction!(OreDelegateInstruction, Payout);
|
||||
18
ore-delegate/api/src/lib.rs
Normal file
18
ore-delegate/api/src/lib.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
pub mod consts;
|
||||
pub mod error;
|
||||
pub mod event;
|
||||
pub mod instruction;
|
||||
pub mod sdk;
|
||||
pub mod state;
|
||||
|
||||
pub mod prelude {
|
||||
pub use crate::consts::*;
|
||||
pub use crate::error::*;
|
||||
pub use crate::event::*;
|
||||
pub use crate::instruction::*;
|
||||
pub use crate::state::*;
|
||||
}
|
||||
|
||||
use steel::*;
|
||||
|
||||
declare_id!("oreV2ZymfyeXgNgBdqMkumTqqAprVqgBWQfoYkrtKWQ");
|
||||
3
ore-delegate/api/src/sdk.rs
Normal file
3
ore-delegate/api/src/sdk.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
use steel::*;
|
||||
|
||||
use crate::{instruction::*, state::*};
|
||||
21
ore-delegate/api/src/state/delegate.rs
Normal file
21
ore-delegate/api/src/state/delegate.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
use steel::*;
|
||||
|
||||
use super::OreDelegateAccount;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
||||
pub struct Delegate {
|
||||
/// The authority of the delegate.
|
||||
pub authority: Pubkey,
|
||||
|
||||
/// The number of hash tokens deposited for mining.
|
||||
pub balance: u64,
|
||||
|
||||
/// The block these hash tokens are associated with.
|
||||
pub block_id: u64,
|
||||
|
||||
/// The fee to payout per crank (lamports).
|
||||
pub fee: u64,
|
||||
}
|
||||
|
||||
account!(OreDelegateAccount, Delegate);
|
||||
20
ore-delegate/api/src/state/mod.rs
Normal file
20
ore-delegate/api/src/state/mod.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
mod delegate;
|
||||
|
||||
pub use delegate::*;
|
||||
|
||||
use crate::consts::*;
|
||||
|
||||
use steel::*;
|
||||
|
||||
#[repr(u8)]
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
|
||||
pub enum OreDelegateAccount {
|
||||
Delegate = 100,
|
||||
}
|
||||
|
||||
pub fn delegate_pda(authority: Pubkey, block_id: u64) -> (Pubkey, u8) {
|
||||
Pubkey::find_program_address(
|
||||
&[DELEGATE, &authority.to_bytes(), &block_id.to_le_bytes()],
|
||||
&crate::ID,
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user