mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-14 07:26:51 +00:00
scaffold
This commit is contained in:
@@ -26,15 +26,24 @@ pub const COMMIT: &[u8] = b"commit";
|
||||
/// The seed of the config account PDA.
|
||||
pub const CONFIG: &[u8] = b"config";
|
||||
|
||||
/// The seed of the market account PDA.
|
||||
pub const MARKET: &[u8] = b"market";
|
||||
|
||||
/// The seed of the miner account PDA.
|
||||
pub const MINER: &[u8] = b"miner";
|
||||
|
||||
/// The seed of the receipt account PDA.
|
||||
pub const RECEIPT: &[u8] = b"receipt";
|
||||
|
||||
/// The seed of the stake account PDA.
|
||||
pub const STAKE: &[u8] = b"stake";
|
||||
|
||||
/// The seed of the metadata account PDA.
|
||||
pub const METADATA: &[u8] = b"metadata";
|
||||
|
||||
/// The seed of the mint account PDA.
|
||||
pub const MINT: &[u8] = b"mint";
|
||||
|
||||
/// The seed of proof account PDAs.
|
||||
pub const PROOF: &[u8] = b"proof";
|
||||
|
||||
/// The seed of the treasury account PDA.
|
||||
pub const TREASURY: &[u8] = b"treasury";
|
||||
|
||||
|
||||
@@ -3,28 +3,25 @@ use steel::*;
|
||||
#[repr(u8)]
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
|
||||
pub enum OreInstruction {
|
||||
// User
|
||||
Claim = 0,
|
||||
Bury = 1,
|
||||
Close = 2,
|
||||
Deploy = 3,
|
||||
Payout = 4,
|
||||
Reset = 5,
|
||||
// Block
|
||||
Open = 0,
|
||||
Close = 1,
|
||||
Mine = 2,
|
||||
|
||||
// Admin
|
||||
Initialize = 100,
|
||||
// Market
|
||||
Buy = 3,
|
||||
Sell = 4,
|
||||
|
||||
// Stake
|
||||
Deposit = 5,
|
||||
Withdraw = 6,
|
||||
Free = 7,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
||||
pub struct Bury {
|
||||
pub amount: [u8; 8],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
||||
pub struct Claim {
|
||||
pub amount: [u8; 8],
|
||||
pub struct Open {
|
||||
pub id: [u8; 8],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
@@ -33,27 +30,35 @@ pub struct Close {}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
||||
pub struct Deploy {
|
||||
pub struct Mine {
|
||||
pub amount: [u8; 8],
|
||||
pub seed: [u8; 32],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
||||
pub struct Reset {}
|
||||
pub struct Buy {}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
||||
pub struct Payout {}
|
||||
pub struct Sell {}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
||||
pub struct Initialize {}
|
||||
pub struct Deposit {}
|
||||
|
||||
instruction!(OreInstruction, Claim);
|
||||
instruction!(OreInstruction, Bury);
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
||||
pub struct Withdraw {}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
||||
pub struct Free {}
|
||||
|
||||
instruction!(OreInstruction, Open);
|
||||
instruction!(OreInstruction, Close);
|
||||
instruction!(OreInstruction, Deploy);
|
||||
instruction!(OreInstruction, Payout);
|
||||
instruction!(OreInstruction, Reset);
|
||||
instruction!(OreInstruction, Initialize);
|
||||
instruction!(OreInstruction, Mine);
|
||||
instruction!(OreInstruction, Buy);
|
||||
instruction!(OreInstruction, Sell);
|
||||
instruction!(OreInstruction, Deposit);
|
||||
instruction!(OreInstruction, Withdraw);
|
||||
instruction!(OreInstruction, Free);
|
||||
|
||||
147
api/src/sdk.rs
147
api/src/sdk.rs
@@ -7,150 +7,3 @@ use crate::{
|
||||
instruction::*,
|
||||
state::*,
|
||||
};
|
||||
|
||||
pub fn deploy(
|
||||
signer: Pubkey,
|
||||
mint: Pubkey,
|
||||
amount: u64,
|
||||
round: u64,
|
||||
seed: [u8; 32],
|
||||
) -> Instruction {
|
||||
let sender = spl_associated_token_account::get_associated_token_address(&signer, &mint);
|
||||
let block = block_pda().0;
|
||||
let block_commits = spl_associated_token_account::get_associated_token_address(&block, &mint);
|
||||
let commit = commit_pda(round, seed).0;
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(block, false),
|
||||
AccountMeta::new(block_commits, false),
|
||||
AccountMeta::new(commit, false),
|
||||
AccountMeta::new(sender, false),
|
||||
AccountMeta::new_readonly(system_program::ID, false),
|
||||
AccountMeta::new_readonly(spl_token::ID, false),
|
||||
AccountMeta::new_readonly(sysvar::slot_hashes::ID, false),
|
||||
],
|
||||
data: Deploy {
|
||||
amount: amount.to_le_bytes(),
|
||||
seed,
|
||||
}
|
||||
.to_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bury(signer: Pubkey, swap: Swap, amount: u64) -> Instruction {
|
||||
let block = block_pda().0;
|
||||
let block_commits = spl_associated_token_account::get_associated_token_address(
|
||||
&block,
|
||||
&spl_token::native_mint::ID,
|
||||
);
|
||||
let block_ore =
|
||||
spl_associated_token_account::get_associated_token_address(&block, &MINT_ADDRESS);
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
// required accounts
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(block, false),
|
||||
AccountMeta::new(block_commits, false),
|
||||
AccountMeta::new(block_ore, false),
|
||||
AccountMeta::new(spl_token::native_mint::ID, false),
|
||||
AccountMeta::new(MINT_ADDRESS, false),
|
||||
// swap accounts
|
||||
AccountMeta::new(swap.pool, false),
|
||||
AccountMeta::new(swap.a_vault, false),
|
||||
AccountMeta::new(swap.b_vault, false),
|
||||
AccountMeta::new(swap.a_token_vault, false),
|
||||
AccountMeta::new(swap.b_token_vault, false),
|
||||
AccountMeta::new(swap.a_vault_lp_mint, false),
|
||||
AccountMeta::new(swap.b_vault_lp_mint, false),
|
||||
AccountMeta::new(swap.a_vault_lp, false),
|
||||
AccountMeta::new(swap.b_vault_lp, false),
|
||||
AccountMeta::new(swap.protocol_token_fee, false),
|
||||
AccountMeta::new_readonly(swap.vault_program, false),
|
||||
AccountMeta::new_readonly(spl_token::ID, false),
|
||||
AccountMeta::new_readonly(meteora_pools_sdk::programs::AMM_ID, false),
|
||||
],
|
||||
data: Bury {
|
||||
amount: amount.to_le_bytes(),
|
||||
}
|
||||
.to_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn close(signer: Pubkey, commit: Pubkey) -> Instruction {
|
||||
let block = block_pda().0;
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(block, false),
|
||||
AccountMeta::new(commit, false),
|
||||
AccountMeta::new_readonly(system_program::ID, false),
|
||||
],
|
||||
data: Close {}.to_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn initialize(signer: Pubkey) -> Instruction {
|
||||
let block = block_pda().0;
|
||||
let block_commits =
|
||||
spl_associated_token_account::get_associated_token_address(&block, &native_mint::ID);
|
||||
let block_ore =
|
||||
spl_associated_token_account::get_associated_token_address(&block, &MINT_ADDRESS);
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(block, false),
|
||||
AccountMeta::new(block_commits, false),
|
||||
AccountMeta::new(block_ore, false),
|
||||
AccountMeta::new_readonly(MINT_ADDRESS, false),
|
||||
AccountMeta::new_readonly(native_mint::ID, 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: Initialize {}.to_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn payout(signer: Pubkey, commit: Pubkey, recipient: Pubkey) -> Instruction {
|
||||
let block = block_pda().0;
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(block, false),
|
||||
AccountMeta::new(commit, false),
|
||||
AccountMeta::new(MINT_ADDRESS, false),
|
||||
AccountMeta::new(recipient, false),
|
||||
AccountMeta::new(TREASURY_ADDRESS, false),
|
||||
AccountMeta::new(TREASURY_TOKENS_ADDRESS, false),
|
||||
AccountMeta::new_readonly(system_program::ID, false),
|
||||
AccountMeta::new_readonly(spl_token::ID, false),
|
||||
AccountMeta::new_readonly(sysvar::slot_hashes::ID, false),
|
||||
],
|
||||
data: Payout {}.to_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn reset(signer: Pubkey, boost_config: Pubkey) -> Instruction {
|
||||
let block = block_pda().0;
|
||||
let boost_proof = proof_pda(boost_config).0;
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(block, false),
|
||||
AccountMeta::new(MINT_ADDRESS, false),
|
||||
AccountMeta::new(TREASURY_ADDRESS, false),
|
||||
AccountMeta::new(TREASURY_TOKENS_ADDRESS, false),
|
||||
AccountMeta::new_readonly(spl_token::ID, false),
|
||||
AccountMeta::new_readonly(boost_config, false),
|
||||
AccountMeta::new(boost_proof, false),
|
||||
],
|
||||
data: Reset {}.to_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,32 +5,23 @@ use super::OreAccount;
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
||||
pub struct Block {
|
||||
/// The cumulative amount deployed in the current round.
|
||||
pub cumulative_sum: u64,
|
||||
/// The best hash.
|
||||
pub best_hash: [u8; 32],
|
||||
|
||||
/// The current round.
|
||||
pub current_round: u64,
|
||||
/// The miner who submitted the best hash.
|
||||
pub best_miner: Pubkey,
|
||||
|
||||
/// The slot at which the current round ends.
|
||||
pub ends_at: u64,
|
||||
/// The block number.
|
||||
pub id: u64,
|
||||
|
||||
/// The mint used for commits of the current round.
|
||||
pub mint: Pubkey,
|
||||
|
||||
/// The noise used for the current round for provably fair randomness.
|
||||
pub noise: [u8; 32],
|
||||
|
||||
/// Whether or not the current round has paid out.
|
||||
pub paid: u64,
|
||||
|
||||
/// The amount of ORE to distribute to the winner.
|
||||
/// The amount of ORE to payout to the miner who submitted the best hash.
|
||||
pub reward: u64,
|
||||
|
||||
/// The time the current round started at.
|
||||
pub started_at: u64,
|
||||
/// The hash of the starting slot.
|
||||
pub slot_hash: [u8; 32],
|
||||
|
||||
/// The number of commits made in the current round.
|
||||
pub total_commits: u64,
|
||||
/// The starting slot of the block.
|
||||
pub start_slot: u64,
|
||||
}
|
||||
|
||||
account!(OreAccount, Block);
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
use steel::*;
|
||||
|
||||
use super::OreAccount;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
||||
pub struct Commit {
|
||||
/// The amount deployed in this commit.
|
||||
pub amount: u64,
|
||||
|
||||
/// The signer authorized to use this commit.
|
||||
pub authority: Pubkey,
|
||||
|
||||
/// The cumulative amount deployed in the current round prior to this commit.
|
||||
pub cumulative_sum: u64,
|
||||
|
||||
/// The current round this commit is for.
|
||||
pub round: u64,
|
||||
|
||||
/// The ID of the commit, used for provably fair randomness.
|
||||
pub seed: [u8; 32],
|
||||
|
||||
/// The timestamp of the commit.
|
||||
pub timestamp: u64,
|
||||
}
|
||||
|
||||
account!(OreAccount, Commit);
|
||||
11
api/src/state/config.rs
Normal file
11
api/src/state/config.rs
Normal file
@@ -0,0 +1,11 @@
|
||||
use steel::*;
|
||||
|
||||
use super::OreAccount;
|
||||
|
||||
// TODO Config stuff
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
||||
pub struct Config {}
|
||||
|
||||
account!(OreAccount, Config);
|
||||
14
api/src/state/market.rs
Normal file
14
api/src/state/market.rs
Normal file
@@ -0,0 +1,14 @@
|
||||
use steel::*;
|
||||
|
||||
use super::OreAccount;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
||||
pub struct Market {
|
||||
/// The id of the block this market is associated with.
|
||||
pub block_id: u64,
|
||||
}
|
||||
|
||||
// TODO Bonding curve stuff
|
||||
|
||||
account!(OreAccount, Market);
|
||||
30
api/src/state/miner.rs
Normal file
30
api/src/state/miner.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
use steel::*;
|
||||
|
||||
use super::OreAccount;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
||||
pub struct Miner {
|
||||
/// 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 ORE this miner can deploy into hashpower markets.
|
||||
pub capacity: u64,
|
||||
|
||||
/// The hash of the last block this miner mined in.
|
||||
pub hash: [u8; 32],
|
||||
|
||||
/// The amount of ORE this miner has staked.
|
||||
pub stake: u64,
|
||||
|
||||
/// The total number of hashes this miner has submitted.
|
||||
pub total_hashes: u64,
|
||||
|
||||
/// The amount of ORE this miner has mined.
|
||||
pub total_rewards: u64,
|
||||
}
|
||||
|
||||
account!(OreAccount, Miner);
|
||||
@@ -1,38 +1,55 @@
|
||||
mod block;
|
||||
mod commit;
|
||||
mod proof;
|
||||
mod config;
|
||||
mod market;
|
||||
mod miner;
|
||||
mod receipt;
|
||||
mod treasury;
|
||||
|
||||
pub use block::*;
|
||||
pub use commit::*;
|
||||
pub use proof::*;
|
||||
pub use config::*;
|
||||
pub use market::*;
|
||||
pub use miner::*;
|
||||
pub use receipt::*;
|
||||
pub use treasury::*;
|
||||
|
||||
use steel::*;
|
||||
|
||||
use crate::consts::*;
|
||||
|
||||
use steel::*;
|
||||
|
||||
#[repr(u8)]
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
|
||||
pub enum OreAccount {
|
||||
Proof = 102,
|
||||
Treasury = 103,
|
||||
Block = 104,
|
||||
Commit = 105,
|
||||
Block = 100,
|
||||
Config = 101,
|
||||
Market = 102,
|
||||
Miner = 103,
|
||||
Receipt = 104,
|
||||
Treasury = 105,
|
||||
}
|
||||
|
||||
pub fn block_pda() -> (Pubkey, u8) {
|
||||
Pubkey::find_program_address(&[BLOCK], &crate::ID)
|
||||
pub fn block_pda(id: u64) -> (Pubkey, u8) {
|
||||
Pubkey::find_program_address(&[BLOCK, &id.to_le_bytes()], &crate::ID)
|
||||
}
|
||||
|
||||
pub fn proof_pda(authority: Pubkey) -> (Pubkey, u8) {
|
||||
Pubkey::find_program_address(&[PROOF, authority.as_ref()], &crate::id())
|
||||
pub fn config_pda() -> (Pubkey, u8) {
|
||||
Pubkey::find_program_address(&[CONFIG], &crate::ID)
|
||||
}
|
||||
|
||||
pub fn market_pda(id: u64) -> (Pubkey, u8) {
|
||||
Pubkey::find_program_address(&[MARKET, &id.to_le_bytes()], &crate::ID)
|
||||
}
|
||||
|
||||
pub fn miner_pda(authority: Pubkey) -> (Pubkey, u8) {
|
||||
Pubkey::find_program_address(&[MINER, &authority.to_bytes()], &crate::ID)
|
||||
}
|
||||
|
||||
pub fn receipt_pda(authority: Pubkey, id: u64) -> (Pubkey, u8) {
|
||||
Pubkey::find_program_address(
|
||||
&[RECEIPT, &authority.to_bytes(), &id.to_le_bytes()],
|
||||
&crate::ID,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn treasury_pda() -> (Pubkey, u8) {
|
||||
Pubkey::find_program_address(&[TREASURY], &crate::ID)
|
||||
}
|
||||
|
||||
pub fn commit_pda(round: u64, seed: [u8; 32]) -> (Pubkey, u8) {
|
||||
Pubkey::find_program_address(&[COMMIT, &round.to_le_bytes(), &seed], &crate::ID)
|
||||
}
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
use steel::*;
|
||||
|
||||
use super::OreAccount;
|
||||
|
||||
/// Proof accounts track a miner's current hash, claimable rewards, and lifetime stats.
|
||||
/// Every miner is allowed one proof account which is required by the program to mine or claim rewards.
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
||||
pub struct Proof {
|
||||
/// The signer authorized to use this proof.
|
||||
pub authority: Pubkey,
|
||||
|
||||
/// The quantity of tokens this miner has staked or earned.
|
||||
pub balance: u64,
|
||||
|
||||
/// The current mining challenge.
|
||||
pub challenge: [u8; 32],
|
||||
|
||||
/// The last hash the miner provided.
|
||||
pub last_hash: [u8; 32],
|
||||
|
||||
/// Timestamp of the last time this account provided a hash.
|
||||
pub last_hash_at: i64,
|
||||
|
||||
/// Timestamp of the last claim.
|
||||
pub last_claim_at: i64,
|
||||
|
||||
/// The keypair which has permission to submit hashes for mining.
|
||||
pub miner: Pubkey,
|
||||
|
||||
/// The total lifetime hashes provided by this miner.
|
||||
pub total_hashes: u64,
|
||||
|
||||
/// The total lifetime rewards distributed to this miner.
|
||||
pub total_rewards: u64,
|
||||
}
|
||||
|
||||
account!(OreAccount, Proof);
|
||||
18
api/src/state/receipt.rs
Normal file
18
api/src/state/receipt.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
use steel::*;
|
||||
|
||||
use super::OreAccount;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
||||
pub struct Receipt {
|
||||
/// The authority of this receipt account.
|
||||
pub authority: Pubkey,
|
||||
|
||||
/// The amount of ORE this miner has deployed in the hashpower market corresponding to the block id.
|
||||
pub amount: u64,
|
||||
|
||||
/// The id of the block this receipt is associated with.
|
||||
pub block_id: u64,
|
||||
}
|
||||
|
||||
account!(OreAccount, Receipt);
|
||||
Reference in New Issue
Block a user