mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-14 07:26:51 +00:00
cleanup
This commit is contained in:
@@ -35,9 +35,6 @@ pub const MINER: &[u8] = b"miner";
|
||||
/// The seed of the mint account PDA.
|
||||
pub const MINT: &[u8] = b"mint";
|
||||
|
||||
/// The seed of the log authority PDA.
|
||||
// pub const LOG: &[u8] = b"log";
|
||||
|
||||
/// The seed of the permit account PDA.
|
||||
pub const PERMIT: &[u8] = b"permit";
|
||||
|
||||
@@ -84,6 +81,3 @@ pub const NUGGET_DIFFICULTY: u64 = 10;
|
||||
|
||||
// The fee to open a block.
|
||||
// pub const OPEN_FEE: u64 = ONE_ORE / 100;
|
||||
|
||||
// The reward rate per satisfying hash (0.002048 ORE).
|
||||
// pub const REWARD_RATE: u64 = 204_800_000;
|
||||
|
||||
193
api/src/event.rs
193
api/src/event.rs
@@ -1,16 +1,11 @@
|
||||
use steel::*;
|
||||
|
||||
use crate::state::{RewardConfig, SwapDirection};
|
||||
use crate::state::SwapDirection;
|
||||
|
||||
pub enum OreEvent {
|
||||
Commit = 0,
|
||||
Deposit = 1,
|
||||
Mine = 2,
|
||||
Open = 3,
|
||||
Reward = 4,
|
||||
Swap = 5,
|
||||
Uncommit = 6,
|
||||
Withdraw = 7,
|
||||
Mine = 1,
|
||||
Reward = 2,
|
||||
Swap = 3,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
@@ -112,186 +107,6 @@ pub struct MineEvent {
|
||||
pub ts: i64,
|
||||
}
|
||||
|
||||
#[repr(u8)]
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
|
||||
pub enum RewardsType {
|
||||
Nugget = 0,
|
||||
Lode = 1,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)]
|
||||
pub struct OpenEvent {
|
||||
/// The event discriminator.
|
||||
pub disc: u64,
|
||||
|
||||
/// The signer of the open transaction.
|
||||
pub signer: Pubkey,
|
||||
|
||||
/// The id of the block.
|
||||
pub id: u64,
|
||||
|
||||
/// The start slot of the block.
|
||||
pub start_slot: u64,
|
||||
|
||||
/// The base liquidity in the market.
|
||||
pub liquidity_base: u64,
|
||||
|
||||
/// The quote liquidity in the market.
|
||||
pub liquidity_quote: u64,
|
||||
|
||||
/// The reward configuration.
|
||||
pub reward_config: RewardConfig,
|
||||
|
||||
/// The timestamp of the event.
|
||||
pub ts: i64,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)]
|
||||
pub struct CloseEvent {
|
||||
/// The authority of the close transaction.
|
||||
pub authority: Pubkey,
|
||||
|
||||
/// The id of the block.
|
||||
pub id: u64,
|
||||
|
||||
/// The amount of base (hashpower) liquidity burned.
|
||||
pub burned_base: u64,
|
||||
|
||||
/// The amount of quote (ORE) liquidity burned.
|
||||
pub burned_quote: u64,
|
||||
|
||||
/// The timestamp of the event.
|
||||
pub ts: i64,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)]
|
||||
pub struct CommitEvent {
|
||||
/// The event discriminator.
|
||||
pub disc: u64,
|
||||
|
||||
/// The amount of hashpower committed.
|
||||
pub amount: u64,
|
||||
|
||||
/// The authority of the commit transaction.
|
||||
pub authority: Pubkey,
|
||||
|
||||
/// The id of the block.
|
||||
pub block_id: u64,
|
||||
|
||||
/// The total amount of hashpower committed to the block.
|
||||
pub block_commitment: u64,
|
||||
|
||||
/// The total amount of hashpower this miner has committed to the block.
|
||||
pub permit_commitment: u64,
|
||||
|
||||
/// The fee paid per hash.
|
||||
pub fee: u64,
|
||||
|
||||
/// The timestamp of the event.
|
||||
pub ts: i64,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)]
|
||||
pub struct UncommitEvent {
|
||||
/// The event discriminator.
|
||||
pub disc: u64,
|
||||
|
||||
/// The amount of hashpower committed.
|
||||
pub amount: u64,
|
||||
|
||||
/// The authority of the commit transaction.
|
||||
pub authority: Pubkey,
|
||||
|
||||
/// The id of the block.
|
||||
pub block_id: u64,
|
||||
|
||||
/// The total amount of hashpower committed to the block.
|
||||
pub block_commitment: u64,
|
||||
|
||||
/// The total amount of hashpower this miner has committed to the block.
|
||||
pub permit_commitment: u64,
|
||||
|
||||
/// The fee paid per hash.
|
||||
pub fee: u64,
|
||||
|
||||
/// The timestamp of the event.
|
||||
pub ts: i64,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)]
|
||||
pub struct DepositEvent {
|
||||
/// The event discriminator.
|
||||
pub disc: u64,
|
||||
|
||||
/// The amount of ORE collateral deposited.
|
||||
pub amount: u64,
|
||||
|
||||
/// The authority of the commit transaction.
|
||||
pub authority: Pubkey,
|
||||
|
||||
/// The id of the block.
|
||||
pub block_id: u64,
|
||||
|
||||
/// The total amount of ORE this user has deposited as collateral.
|
||||
pub collateral: u64,
|
||||
|
||||
/// The timestamp of the event.
|
||||
pub ts: i64,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)]
|
||||
pub struct WithdrawEvent {
|
||||
/// The event discriminator.
|
||||
pub disc: u64,
|
||||
|
||||
/// The amount of ORE collateral withdrawn.
|
||||
pub amount: u64,
|
||||
|
||||
/// The authority of the commit transaction.
|
||||
pub authority: Pubkey,
|
||||
|
||||
/// The id of the block.
|
||||
pub block_id: u64,
|
||||
|
||||
/// The total amount of ORE this user has deposited as collateral.
|
||||
pub collateral: u64,
|
||||
|
||||
/// The timestamp of the event.
|
||||
pub ts: i64,
|
||||
}
|
||||
|
||||
event!(SwapEvent);
|
||||
event!(RewardEvent);
|
||||
event!(OpenEvent);
|
||||
event!(CommitEvent);
|
||||
event!(DepositEvent);
|
||||
event!(WithdrawEvent);
|
||||
event!(UncommitEvent);
|
||||
event!(MineEvent);
|
||||
event!(CloseEvent);
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use base64::{prelude::BASE64_STANDARD, Engine};
|
||||
|
||||
#[test]
|
||||
fn test_parse_commit_event() {
|
||||
// Create sample return data
|
||||
let data = "BQAAAAAAAAB9607Qp9I2VxNo2rSPHAz/tR2pJzGu9om7qHP71TpKqciMAwAAAAAAAAAAAAAAAAA2CwUAAAAAAADodkgXAAAAAAAAAAAAAAAAAAAAAAAAADYLBQAAAAAAAB7cDBcAAAAAypo7AAAAAMMQW2gAAAAA";
|
||||
let bytes = BASE64_STANDARD.decode(data).unwrap();
|
||||
|
||||
// Parse into CommitEvent
|
||||
let event: &SwapEvent = bytemuck::try_from_bytes(&bytes).unwrap();
|
||||
|
||||
// Verify fields
|
||||
println!("{:?}", event);
|
||||
assert!(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,21 +4,15 @@ use steel::*;
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
|
||||
pub enum OreInstruction {
|
||||
// User
|
||||
Open = 0,
|
||||
Close = 1,
|
||||
Commit = 2,
|
||||
Deposit = 3,
|
||||
Log = 4,
|
||||
Mine = 5,
|
||||
Swap = 6,
|
||||
Uncommit = 7,
|
||||
Withdraw = 8,
|
||||
Log = 1,
|
||||
Mine = 2,
|
||||
Swap = 3,
|
||||
Initialize = 4,
|
||||
|
||||
// Admin
|
||||
SetAdmin = 9,
|
||||
SetBlockLimit = 10,
|
||||
SetFeeCollector = 11,
|
||||
SetFeeRate = 12,
|
||||
SetFeeCollector = 10,
|
||||
SetFeeRate = 11,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
@@ -42,9 +36,7 @@ pub struct Commit {
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
||||
pub struct Deposit {
|
||||
pub amount: [u8; 8],
|
||||
}
|
||||
pub struct Initialize {}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
||||
@@ -72,24 +64,12 @@ pub struct Uncommit {
|
||||
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 SetAdmin {
|
||||
pub admin: [u8; 32],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
||||
pub struct SetBlockLimit {
|
||||
pub block_limit: [u8; 8],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
||||
pub struct SetFeeCollector {
|
||||
@@ -102,16 +82,10 @@ pub struct SetFeeRate {
|
||||
pub fee_rate: [u8; 8],
|
||||
}
|
||||
|
||||
instruction!(OreInstruction, Open);
|
||||
instruction!(OreInstruction, Close);
|
||||
instruction!(OreInstruction, Commit);
|
||||
instruction!(OreInstruction, Deposit);
|
||||
instruction!(OreInstruction, Log);
|
||||
instruction!(OreInstruction, Mine);
|
||||
instruction!(OreInstruction, Swap);
|
||||
instruction!(OreInstruction, Uncommit);
|
||||
instruction!(OreInstruction, Withdraw);
|
||||
instruction!(OreInstruction, Initialize);
|
||||
instruction!(OreInstruction, SetAdmin);
|
||||
instruction!(OreInstruction, SetBlockLimit);
|
||||
instruction!(OreInstruction, SetFeeCollector);
|
||||
instruction!(OreInstruction, SetFeeRate);
|
||||
|
||||
243
api/src/sdk.rs
243
api/src/sdk.rs
@@ -7,90 +7,6 @@ use crate::{
|
||||
state::*,
|
||||
};
|
||||
|
||||
pub fn open(signer: Pubkey, id: u64) -> Instruction {
|
||||
let block_adddress = block_pda(id).0;
|
||||
let config_address = config_pda().0;
|
||||
let market_address = market_pda(id).0;
|
||||
let base_mint_address = mint_pda(id).0;
|
||||
let collateral_address = collateral_pda(id).0;
|
||||
let commitment_address = commitment_pda(id).0;
|
||||
let sender_address = get_associated_token_address(&signer, &MINT_ADDRESS);
|
||||
let vault_base_address = vault_base_pda(id).0;
|
||||
let vault_quote_address = vault_quote_pda(id).0;
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(block_adddress, false),
|
||||
AccountMeta::new(config_address, false),
|
||||
AccountMeta::new(collateral_address, false),
|
||||
AccountMeta::new(commitment_address, false),
|
||||
AccountMeta::new(market_address, false),
|
||||
AccountMeta::new(base_mint_address, false),
|
||||
AccountMeta::new(MINT_ADDRESS, false),
|
||||
AccountMeta::new(sender_address, false),
|
||||
AccountMeta::new(TREASURY_ADDRESS, false),
|
||||
AccountMeta::new(vault_base_address, false),
|
||||
AccountMeta::new(vault_quote_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),
|
||||
AccountMeta::new_readonly(crate::ID, false),
|
||||
AccountMeta::new_readonly(sysvar::rent::ID, false),
|
||||
],
|
||||
data: Open {
|
||||
id: id.to_le_bytes(),
|
||||
}
|
||||
.to_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
// let [signer_info, block_info, config_info, collateral_info, commitment_info, fee_collector_info, market_info, miner_info, mint_base_info, mint_quote_info, opener_info, recipient_info, treasury_info, vault_base_info, vault_quote_info, system_program, token_program, ore_program] =
|
||||
|
||||
pub fn close(
|
||||
signer: Pubkey,
|
||||
fee_collector: Pubkey,
|
||||
opener: Pubkey,
|
||||
load_authority: Pubkey,
|
||||
id: u64,
|
||||
) -> Instruction {
|
||||
let block_adddress = block_pda(id).0;
|
||||
let config_address = config_pda().0;
|
||||
let collateral_address = collateral_pda(id).0;
|
||||
let commitment_address = commitment_pda(id).0;
|
||||
let fee_collector_address = get_associated_token_address(&fee_collector, &MINT_ADDRESS);
|
||||
let market_address = market_pda(id).0;
|
||||
let base_mint_address = mint_pda(id).0;
|
||||
let vault_base = vault_base_pda(id).0;
|
||||
let vault_quote = vault_quote_pda(id).0;
|
||||
let miner_address = miner_pda(load_authority).0;
|
||||
let recipient = get_associated_token_address(&load_authority, &MINT_ADDRESS);
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(block_adddress, false),
|
||||
AccountMeta::new(config_address, false),
|
||||
AccountMeta::new(collateral_address, false),
|
||||
AccountMeta::new(commitment_address, false),
|
||||
AccountMeta::new(fee_collector_address, false),
|
||||
AccountMeta::new(market_address, false),
|
||||
AccountMeta::new(miner_address, false),
|
||||
AccountMeta::new(base_mint_address, false),
|
||||
AccountMeta::new(MINT_ADDRESS, false),
|
||||
AccountMeta::new(opener, false),
|
||||
AccountMeta::new(recipient, false),
|
||||
AccountMeta::new(TREASURY_ADDRESS, false),
|
||||
AccountMeta::new(vault_base, false),
|
||||
AccountMeta::new(vault_quote, false),
|
||||
AccountMeta::new_readonly(system_program::ID, false),
|
||||
AccountMeta::new_readonly(spl_token::ID, false),
|
||||
AccountMeta::new_readonly(crate::ID, false),
|
||||
],
|
||||
data: Close {}.to_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn log(signer: Pubkey, block_id: u64, msg: &[u8]) -> Instruction {
|
||||
let mut data = Log {
|
||||
block_id: block_id.to_le_bytes(),
|
||||
@@ -119,11 +35,8 @@ pub fn program_log(
|
||||
|
||||
pub fn mine(signer: Pubkey, authority: Pubkey, id: u64, amount: u64) -> Instruction {
|
||||
let block_adddress = block_pda(id).0;
|
||||
let commitment_address = commitment_pda(id).0;
|
||||
let market_address = market_pda(id).0;
|
||||
let base_mint_address = mint_pda(id).0;
|
||||
let market_address = market_pda().0;
|
||||
let miner_address = miner_pda(authority).0;
|
||||
let permit_address = permit_pda(authority, id).0;
|
||||
let recipient = get_associated_token_address(&authority, &MINT_ADDRESS);
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
@@ -131,12 +44,9 @@ pub fn mine(signer: Pubkey, authority: Pubkey, id: u64, amount: u64) -> Instruct
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(authority, false),
|
||||
AccountMeta::new(block_adddress, false),
|
||||
AccountMeta::new(commitment_address, false),
|
||||
AccountMeta::new(market_address, false),
|
||||
AccountMeta::new(miner_address, false),
|
||||
AccountMeta::new(base_mint_address, false),
|
||||
AccountMeta::new(MINT_ADDRESS, false),
|
||||
AccountMeta::new(permit_address, false),
|
||||
AccountMeta::new(recipient, false),
|
||||
AccountMeta::new(TREASURY_ADDRESS, false),
|
||||
AccountMeta::new_readonly(system_program::ID, false),
|
||||
@@ -151,126 +61,6 @@ pub fn mine(signer: Pubkey, authority: Pubkey, id: u64, amount: u64) -> Instruct
|
||||
}
|
||||
}
|
||||
|
||||
pub fn commit(
|
||||
signer: Pubkey,
|
||||
amount: u64,
|
||||
executor: Pubkey,
|
||||
fee: u64,
|
||||
id: u64,
|
||||
seed: [u8; 32],
|
||||
) -> Instruction {
|
||||
let block_adddress = block_pda(id).0;
|
||||
let market_address = market_pda(id).0;
|
||||
let base_mint_address = mint_pda(id).0;
|
||||
let miner_address = miner_pda(signer).0;
|
||||
let permit_address = permit_pda(signer, id).0;
|
||||
let commitment_address = commitment_pda(id).0;
|
||||
let sender_address = get_associated_token_address(&signer, &base_mint_address);
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(block_adddress, false),
|
||||
AccountMeta::new(commitment_address, false),
|
||||
AccountMeta::new(market_address, false),
|
||||
AccountMeta::new(miner_address, false),
|
||||
AccountMeta::new(base_mint_address, false),
|
||||
AccountMeta::new(permit_address, false),
|
||||
AccountMeta::new(sender_address, false),
|
||||
AccountMeta::new_readonly(system_program::ID, false),
|
||||
AccountMeta::new_readonly(spl_token::ID, false),
|
||||
AccountMeta::new_readonly(crate::ID, false),
|
||||
],
|
||||
data: Commit {
|
||||
amount: amount.to_le_bytes(),
|
||||
executor: executor.to_bytes(),
|
||||
fee: fee.to_le_bytes(),
|
||||
seed: seed,
|
||||
}
|
||||
.to_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn uncommit(signer: Pubkey, amount: u64, id: u64) -> Instruction {
|
||||
let block_adddress = block_pda(id).0;
|
||||
let market_address = market_pda(id).0;
|
||||
let base_mint_address = mint_pda(id).0;
|
||||
let miner_address = miner_pda(signer).0;
|
||||
let permit_address = permit_pda(signer, id).0;
|
||||
let commitment_address = commitment_pda(id).0;
|
||||
let recipient_address = get_associated_token_address(&signer, &MINT_ADDRESS);
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(block_adddress, false),
|
||||
AccountMeta::new(commitment_address, false),
|
||||
AccountMeta::new(market_address, false),
|
||||
AccountMeta::new(miner_address, false),
|
||||
AccountMeta::new(base_mint_address, false),
|
||||
AccountMeta::new(permit_address, false),
|
||||
AccountMeta::new(recipient_address, false),
|
||||
AccountMeta::new_readonly(system_program::ID, false),
|
||||
AccountMeta::new_readonly(spl_token::ID, false),
|
||||
AccountMeta::new_readonly(crate::ID, false),
|
||||
],
|
||||
data: Uncommit {
|
||||
amount: amount.to_le_bytes(),
|
||||
}
|
||||
.to_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deposit(signer: Pubkey, id: u64, amount: u64) -> Instruction {
|
||||
let block_adddress = block_pda(id).0;
|
||||
let collateral_address = collateral_pda(id).0;
|
||||
let stake_address = stake_pda(signer, id).0;
|
||||
let sender = get_associated_token_address(&signer, &MINT_ADDRESS);
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(block_adddress, false),
|
||||
AccountMeta::new(collateral_address, false),
|
||||
AccountMeta::new(MINT_ADDRESS, false),
|
||||
AccountMeta::new(sender, false),
|
||||
AccountMeta::new(stake_address, false),
|
||||
AccountMeta::new_readonly(system_program::ID, false),
|
||||
AccountMeta::new_readonly(spl_token::ID, false),
|
||||
AccountMeta::new_readonly(crate::ID, false),
|
||||
],
|
||||
data: Deposit {
|
||||
amount: amount.to_le_bytes(),
|
||||
}
|
||||
.to_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn withdraw(signer: Pubkey, id: u64, amount: u64) -> Instruction {
|
||||
let block_adddress = block_pda(id).0;
|
||||
let collateral_address = collateral_pda(id).0;
|
||||
let stake_address = stake_pda(signer, id).0;
|
||||
let recipient_address = get_associated_token_address(&signer, &MINT_ADDRESS);
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(block_adddress, false),
|
||||
AccountMeta::new(collateral_address, false),
|
||||
AccountMeta::new(MINT_ADDRESS, false),
|
||||
AccountMeta::new(recipient_address, false),
|
||||
AccountMeta::new(stake_address, false),
|
||||
AccountMeta::new_readonly(system_program::ID, false),
|
||||
AccountMeta::new_readonly(spl_token::ID, false),
|
||||
AccountMeta::new_readonly(crate::ID, false),
|
||||
],
|
||||
data: Withdraw {
|
||||
amount: amount.to_le_bytes(),
|
||||
}
|
||||
.to_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn swap(
|
||||
signer: Pubkey,
|
||||
id: u64,
|
||||
@@ -279,27 +69,18 @@ pub fn swap(
|
||||
precision: SwapPrecision,
|
||||
) -> Instruction {
|
||||
let block_adddress = block_pda(id).0;
|
||||
let market_address = market_pda(id).0;
|
||||
let base_mint_address = mint_pda(id).0;
|
||||
let stake_address = stake_pda(signer, id).0;
|
||||
let tokens_base_address = get_associated_token_address(&signer, &base_mint_address);
|
||||
let market_address = market_pda().0;
|
||||
let tokens_quote_address = get_associated_token_address(&signer, &MINT_ADDRESS);
|
||||
let vault_base_address = vault_base_pda(id).0;
|
||||
let vault_quote_address = vault_quote_pda(id).0;
|
||||
let vault_address = vault_pda().0;
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(block_adddress, false),
|
||||
// AccountMeta::new(collateral_address, false),
|
||||
AccountMeta::new(market_address, false),
|
||||
AccountMeta::new(base_mint_address, false),
|
||||
AccountMeta::new(MINT_ADDRESS, false),
|
||||
AccountMeta::new(stake_address, false),
|
||||
AccountMeta::new(tokens_base_address, false),
|
||||
AccountMeta::new(tokens_quote_address, false),
|
||||
AccountMeta::new(vault_base_address, false),
|
||||
AccountMeta::new(vault_quote_address, false),
|
||||
AccountMeta::new(vault_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),
|
||||
@@ -330,22 +111,6 @@ pub fn set_admin(signer: Pubkey, admin: Pubkey) -> Instruction {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_block_limit(signer: Pubkey, block_limit: u64) -> 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_readonly(system_program::ID, false),
|
||||
],
|
||||
data: SetBlockLimit {
|
||||
block_limit: block_limit.to_le_bytes(),
|
||||
}
|
||||
.to_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_fee_collector(signer: Pubkey, fee_collector: Pubkey) -> Instruction {
|
||||
let config_address = config_pda().0;
|
||||
Instruction {
|
||||
|
||||
@@ -4,12 +4,6 @@ use crate::state::block_pda;
|
||||
|
||||
use super::OreAccount;
|
||||
|
||||
// What could be variable?
|
||||
// - Payout style (winner take all / difficulty / both)
|
||||
// - Payout skew (larger / neutral / smaller)
|
||||
// - Jackpot possiblity (yes / no)
|
||||
// - Known / unknown
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
||||
pub struct Block {
|
||||
@@ -20,42 +14,19 @@ pub struct Block {
|
||||
pub opener: Pubkey,
|
||||
|
||||
/// The reward configuration.
|
||||
pub reward: RewardConfig,
|
||||
pub reward: u64,
|
||||
|
||||
/// The hash of the starting slot.
|
||||
pub slot_hash: [u8; 32],
|
||||
|
||||
/// The starting slot of the block.
|
||||
pub start_slot: u64,
|
||||
|
||||
/// The total number of hashes submitted to the block.
|
||||
pub total_committed: u64,
|
||||
|
||||
/// The total number of hashes deployed to the block.
|
||||
pub total_deployed: u64,
|
||||
|
||||
/// The total amount of rewards paid out to miners.
|
||||
pub total_rewards: u64,
|
||||
}
|
||||
|
||||
/// Configuration specifying how rewards are paid out.
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)]
|
||||
pub struct RewardConfig {
|
||||
/// The reward paid to the submitter of the best hash.
|
||||
pub lode_reward: u64,
|
||||
/// The best hash submitted to the block.
|
||||
pub best_hash: [u8; 32],
|
||||
|
||||
/// The authority of the miner who submitted the best hash.
|
||||
pub lode_authority: Pubkey,
|
||||
pub best_hash_miner: Pubkey,
|
||||
|
||||
/// The best hash.
|
||||
pub lode_hash: [u8; 32],
|
||||
/// The hash of the starting slot, used for random number generation.
|
||||
pub slot_hash: [u8; 32],
|
||||
|
||||
/// The reward rate paid to hashes satisfying the difficulty threshold.
|
||||
pub nugget_reward: u64,
|
||||
|
||||
/// The minimum difficulty required for payout.
|
||||
pub nugget_threshold: u64,
|
||||
/// The total amount of hashpower bought in the block.
|
||||
pub total_hashpower: u64,
|
||||
}
|
||||
|
||||
impl Block {
|
||||
|
||||
@@ -10,9 +10,6 @@ pub struct Config {
|
||||
// The address that can set the admin.
|
||||
pub admin: Pubkey,
|
||||
|
||||
/// Number of blocks that can be open for trading at one time.
|
||||
pub block_limit: u64,
|
||||
|
||||
// The address that receives fees.
|
||||
pub fee_collector: Pubkey,
|
||||
|
||||
|
||||
@@ -20,13 +20,13 @@ pub struct Market {
|
||||
/// Snapshot of the market state at the time of the last swap.
|
||||
pub snapshot: Snapshot,
|
||||
|
||||
/// The id of the block this market is associated with.
|
||||
pub id: u64,
|
||||
/// The id of the current block.
|
||||
pub block_id: u64,
|
||||
}
|
||||
|
||||
impl Market {
|
||||
pub fn pda(&self) -> (Pubkey, u8) {
|
||||
market_pda(self.id)
|
||||
market_pda()
|
||||
}
|
||||
|
||||
pub fn base_vault(&self) -> Pubkey {
|
||||
@@ -449,7 +449,7 @@ mod tests {
|
||||
quote_balance: 0,
|
||||
slot: 0,
|
||||
},
|
||||
id: 0,
|
||||
block_id: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,11 +16,14 @@ pub struct Miner {
|
||||
/// The hash of the last block this miner mined in.
|
||||
pub hash: [u8; 32],
|
||||
|
||||
/// The total number of hashes this miner has committed to the block.
|
||||
pub total_committed: u64,
|
||||
/// The amount of hashpower this miner has committed to the current block.
|
||||
pub hashpower: u64,
|
||||
|
||||
/// The total number of hashes this miner has deployed to the block.
|
||||
pub total_deployed: 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,
|
||||
|
||||
@@ -2,16 +2,12 @@ mod block;
|
||||
mod config;
|
||||
mod market;
|
||||
mod miner;
|
||||
mod permit;
|
||||
mod stake;
|
||||
mod treasury;
|
||||
|
||||
pub use block::*;
|
||||
pub use config::*;
|
||||
pub use market::*;
|
||||
pub use miner::*;
|
||||
pub use permit::*;
|
||||
pub use stake::*;
|
||||
pub use treasury::*;
|
||||
|
||||
use crate::consts::*;
|
||||
@@ -25,9 +21,7 @@ pub enum OreAccount {
|
||||
Config = 101,
|
||||
Market = 102,
|
||||
Miner = 103,
|
||||
Permit = 104,
|
||||
Stake = 105,
|
||||
Treasury = 106,
|
||||
Treasury = 104,
|
||||
}
|
||||
|
||||
pub fn block_pda(id: u64) -> (Pubkey, u8) {
|
||||
@@ -38,58 +32,16 @@ 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 market_pda() -> (Pubkey, u8) {
|
||||
Pubkey::find_program_address(&[MARKET], &crate::ID)
|
||||
}
|
||||
|
||||
pub fn miner_pda(authority: Pubkey) -> (Pubkey, u8) {
|
||||
Pubkey::find_program_address(&[MINER, &authority.to_bytes()], &crate::ID)
|
||||
}
|
||||
|
||||
pub fn mint_pda(id: u64) -> (Pubkey, u8) {
|
||||
Pubkey::find_program_address(&[MINT, &id.to_le_bytes()], &crate::ID)
|
||||
}
|
||||
|
||||
pub fn collateral_pda(block_id: u64) -> (Pubkey, u8) {
|
||||
let block_address = block_pda(block_id).0;
|
||||
Pubkey::find_program_address(
|
||||
&[
|
||||
&block_address.to_bytes(),
|
||||
&spl_token::ID.to_bytes(),
|
||||
&MINT_ADDRESS.to_bytes(),
|
||||
],
|
||||
&crate::ID,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn commitment_pda(block_id: u64) -> (Pubkey, u8) {
|
||||
let block_address = block_pda(block_id).0;
|
||||
let mint_address = mint_pda(block_id).0;
|
||||
Pubkey::find_program_address(
|
||||
&[
|
||||
&block_address.to_bytes(),
|
||||
&spl_token::ID.to_bytes(),
|
||||
&mint_address.to_bytes(),
|
||||
],
|
||||
&crate::ID,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn vault_base_pda(block_id: u64) -> (Pubkey, u8) {
|
||||
let market_address = market_pda(block_id).0;
|
||||
let mint_address = mint_pda(block_id).0;
|
||||
Pubkey::find_program_address(
|
||||
&[
|
||||
&market_address.to_bytes(),
|
||||
&spl_token::ID.to_bytes(),
|
||||
&mint_address.to_bytes(),
|
||||
],
|
||||
&crate::ID,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn vault_quote_pda(block_id: u64) -> (Pubkey, u8) {
|
||||
let market_address = market_pda(block_id).0;
|
||||
pub fn vault_pda() -> (Pubkey, u8) {
|
||||
let market_address = market_pda().0;
|
||||
Pubkey::find_program_address(
|
||||
&[
|
||||
&market_address.to_bytes(),
|
||||
@@ -100,20 +52,6 @@ pub fn vault_quote_pda(block_id: u64) -> (Pubkey, u8) {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn permit_pda(authority: Pubkey, block_id: u64) -> (Pubkey, u8) {
|
||||
Pubkey::find_program_address(
|
||||
&[PERMIT, &authority.to_bytes(), &block_id.to_le_bytes()],
|
||||
&crate::ID,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn stake_pda(authority: Pubkey, block_id: u64) -> (Pubkey, u8) {
|
||||
Pubkey::find_program_address(
|
||||
&[STAKE, &authority.to_bytes(), &block_id.to_le_bytes()],
|
||||
&crate::ID,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn treasury_pda() -> (Pubkey, u8) {
|
||||
Pubkey::find_program_address(&[TREASURY], &crate::ID)
|
||||
}
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
use steel::*;
|
||||
|
||||
use crate::state::permit_pda;
|
||||
|
||||
use super::OreAccount;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
||||
pub struct Permit {
|
||||
/// The authority of the miner account.
|
||||
pub authority: Pubkey,
|
||||
|
||||
/// The ID of the block this permit is for.
|
||||
pub block_id: u64,
|
||||
|
||||
/// The amount of hash tokens this miner has committed to the block.
|
||||
pub commitment: u64,
|
||||
|
||||
/// The executor of the permit.
|
||||
pub executor: Pubkey,
|
||||
|
||||
/// The fee paid to the executor.
|
||||
pub fee: u64,
|
||||
|
||||
/// A user-supplied seed for random number generation.
|
||||
pub seed: [u8; 32],
|
||||
}
|
||||
|
||||
impl Permit {
|
||||
pub fn pda(&self) -> (Pubkey, u8) {
|
||||
permit_pda(self.authority, self.block_id)
|
||||
}
|
||||
}
|
||||
|
||||
account!(OreAccount, Permit);
|
||||
@@ -1,29 +0,0 @@
|
||||
use steel::*;
|
||||
|
||||
use crate::state::stake_pda;
|
||||
|
||||
use super::OreAccount;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
||||
pub struct Stake {
|
||||
/// The authority of the miner account.
|
||||
pub authority: Pubkey,
|
||||
|
||||
/// The ID of the block this collateral is associated with.
|
||||
pub block_id: u64,
|
||||
|
||||
/// The amount of ORE this miner has deposited as collateral for trading.
|
||||
pub collateral: u64,
|
||||
|
||||
/// The amount of ORE this miner has spent on hashpower in this market.
|
||||
pub spend: u64,
|
||||
}
|
||||
|
||||
impl Stake {
|
||||
pub fn pda(&self) -> (Pubkey, u8) {
|
||||
stake_pda(self.authority, self.block_id)
|
||||
}
|
||||
}
|
||||
|
||||
account!(OreAccount, Stake);
|
||||
Reference in New Issue
Block a user