mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-16 23:16:47 +00:00
commit
This commit is contained in:
@@ -20,8 +20,8 @@ pub const MAX_SUPPLY: u64 = ONE_ORE * 5_000_000;
|
||||
/// The seed of the block account PDA.
|
||||
pub const BLOCK: &[u8] = b"block";
|
||||
|
||||
/// The seed of the wager account PDA.
|
||||
pub const WAGER: &[u8] = b"wager";
|
||||
/// The seed of the commit account PDA.
|
||||
pub const COMMIT: &[u8] = b"commit";
|
||||
|
||||
/// The seed of the config account PDA.
|
||||
pub const CONFIG: &[u8] = b"config";
|
||||
|
||||
@@ -2,15 +2,15 @@ use steel::*;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
||||
pub struct BetEvent {
|
||||
pub authority: Pubkey,
|
||||
pub struct BuryEvent {
|
||||
pub amount: u64,
|
||||
pub ts: u64,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
||||
pub struct BuryEvent {
|
||||
pub struct DeployEvent {
|
||||
pub authority: Pubkey,
|
||||
pub amount: u64,
|
||||
pub ts: u64,
|
||||
}
|
||||
@@ -23,6 +23,6 @@ pub struct PayoutEvent {
|
||||
pub ts: u64,
|
||||
}
|
||||
|
||||
event!(BetEvent);
|
||||
event!(BuryEvent);
|
||||
event!(DeployEvent);
|
||||
event!(PayoutEvent);
|
||||
|
||||
@@ -5,9 +5,9 @@ use steel::*;
|
||||
pub enum OreInstruction {
|
||||
// User
|
||||
Claim = 0,
|
||||
Bet = 1,
|
||||
Bury = 2,
|
||||
Close = 3,
|
||||
Bury = 1,
|
||||
Close = 2,
|
||||
Deploy = 3,
|
||||
Payout = 4,
|
||||
Reset = 5,
|
||||
|
||||
@@ -17,15 +17,10 @@ pub enum OreInstruction {
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
||||
pub struct Bet {
|
||||
pub struct Bury {
|
||||
pub amount: [u8; 8],
|
||||
pub seed: [u8; 32],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
||||
pub struct Bury {}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
||||
pub struct Claim {
|
||||
@@ -36,6 +31,13 @@ pub struct Claim {
|
||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
||||
pub struct Close {}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
||||
pub struct Deploy {
|
||||
pub amount: [u8; 8],
|
||||
pub seed: [u8; 32],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
||||
pub struct Reset {}
|
||||
@@ -49,9 +51,9 @@ pub struct Payout {}
|
||||
pub struct Initialize {}
|
||||
|
||||
instruction!(OreInstruction, Claim);
|
||||
instruction!(OreInstruction, Bet);
|
||||
instruction!(OreInstruction, Bury);
|
||||
instruction!(OreInstruction, Close);
|
||||
instruction!(OreInstruction, Deploy);
|
||||
instruction!(OreInstruction, Payout);
|
||||
instruction!(OreInstruction, Reset);
|
||||
instruction!(OreInstruction, Initialize);
|
||||
|
||||
@@ -8,24 +8,30 @@ use crate::{
|
||||
state::*,
|
||||
};
|
||||
|
||||
pub fn bet(signer: Pubkey, mint: Pubkey, amount: u64, round: u64, seed: [u8; 32]) -> Instruction {
|
||||
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_bets = spl_associated_token_account::get_associated_token_address(&block, &mint);
|
||||
let wager = wager_pda(round, seed).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_bets, false),
|
||||
AccountMeta::new(block_commits, false),
|
||||
AccountMeta::new(commit, false),
|
||||
AccountMeta::new(sender, false),
|
||||
AccountMeta::new(wager, false),
|
||||
AccountMeta::new_readonly(system_program::ID, false),
|
||||
AccountMeta::new_readonly(spl_token::ID, false),
|
||||
AccountMeta::new_readonly(sysvar::slot_hashes::ID, false),
|
||||
],
|
||||
data: Bet {
|
||||
data: Deploy {
|
||||
amount: amount.to_le_bytes(),
|
||||
seed,
|
||||
}
|
||||
@@ -33,9 +39,9 @@ pub fn bet(signer: Pubkey, mint: Pubkey, amount: u64, round: u64, seed: [u8; 32]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bury(signer: Pubkey, swap: Swap) -> Instruction {
|
||||
pub fn bury(signer: Pubkey, swap: Swap, amount: u64) -> Instruction {
|
||||
let block = block_pda().0;
|
||||
let block_bets = spl_associated_token_account::get_associated_token_address(
|
||||
let block_commits = spl_associated_token_account::get_associated_token_address(
|
||||
&block,
|
||||
&spl_token::native_mint::ID,
|
||||
);
|
||||
@@ -47,7 +53,7 @@ pub fn bury(signer: Pubkey, swap: Swap) -> Instruction {
|
||||
// required accounts
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(block, false),
|
||||
AccountMeta::new(block_bets, false),
|
||||
AccountMeta::new(block_commits, false),
|
||||
AccountMeta::new(block_ore, false),
|
||||
AccountMeta::new(spl_token::native_mint::ID, false),
|
||||
AccountMeta::new(MINT_ADDRESS, false),
|
||||
@@ -66,18 +72,21 @@ pub fn bury(signer: Pubkey, swap: Swap) -> Instruction {
|
||||
AccountMeta::new_readonly(spl_token::ID, false),
|
||||
AccountMeta::new_readonly(meteora_pools_sdk::programs::AMM_ID, false),
|
||||
],
|
||||
data: Bury {}.to_bytes(),
|
||||
data: Bury {
|
||||
amount: amount.to_le_bytes(),
|
||||
}
|
||||
.to_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn close(signer: Pubkey, wager: Pubkey) -> Instruction {
|
||||
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(wager, false),
|
||||
AccountMeta::new(commit, false),
|
||||
AccountMeta::new_readonly(system_program::ID, false),
|
||||
],
|
||||
data: Close {}.to_bytes(),
|
||||
@@ -86,7 +95,7 @@ pub fn close(signer: Pubkey, wager: Pubkey) -> Instruction {
|
||||
|
||||
pub fn initialize(signer: Pubkey) -> Instruction {
|
||||
let block = block_pda().0;
|
||||
let block_bets =
|
||||
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);
|
||||
@@ -95,7 +104,7 @@ pub fn initialize(signer: Pubkey) -> Instruction {
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(block, false),
|
||||
AccountMeta::new(block_bets, false),
|
||||
AccountMeta::new(block_commits, false),
|
||||
AccountMeta::new(block_ore, false),
|
||||
AccountMeta::new_readonly(MINT_ADDRESS, false),
|
||||
AccountMeta::new_readonly(native_mint::ID, false),
|
||||
@@ -107,15 +116,15 @@ pub fn initialize(signer: Pubkey) -> Instruction {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn payout(signer: Pubkey, wager: Pubkey, recipient: Pubkey) -> Instruction {
|
||||
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(wager, false),
|
||||
AccountMeta::new(recipient, false),
|
||||
AccountMeta::new(TREASURY_ADDRESS, false),
|
||||
AccountMeta::new(TREASURY_TOKENS_ADDRESS, false),
|
||||
|
||||
@@ -5,7 +5,7 @@ use super::OreAccount;
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
||||
pub struct Block {
|
||||
/// The cumulative amount risked in the current round.
|
||||
/// The cumulative amount deployed in the current round.
|
||||
pub cumulative_sum: u64,
|
||||
|
||||
/// The current round.
|
||||
@@ -14,7 +14,7 @@ pub struct Block {
|
||||
/// The slot at which the current round ends.
|
||||
pub ends_at: u64,
|
||||
|
||||
/// The mint used for wagers of the current round.
|
||||
/// The mint used for commits of the current round.
|
||||
pub mint: Pubkey,
|
||||
|
||||
/// The noise used for the current round for provably fair randomness.
|
||||
@@ -29,8 +29,8 @@ pub struct Block {
|
||||
/// The time the current round started at.
|
||||
pub started_at: u64,
|
||||
|
||||
/// The number of wagers made in the current round.
|
||||
pub total_wagers: u64,
|
||||
/// The number of commits made in the current round.
|
||||
pub total_commits: u64,
|
||||
}
|
||||
|
||||
account!(OreAccount, Block);
|
||||
|
||||
27
api/src/state/commit.rs
Normal file
27
api/src/state/commit.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
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);
|
||||
@@ -1,12 +1,12 @@
|
||||
mod block;
|
||||
mod commit;
|
||||
mod proof;
|
||||
mod treasury;
|
||||
mod wager;
|
||||
|
||||
pub use block::*;
|
||||
pub use commit::*;
|
||||
pub use proof::*;
|
||||
pub use treasury::*;
|
||||
pub use wager::*;
|
||||
|
||||
use steel::*;
|
||||
|
||||
@@ -18,7 +18,7 @@ pub enum OreAccount {
|
||||
Proof = 102,
|
||||
Treasury = 103,
|
||||
Block = 104,
|
||||
Wager = 105,
|
||||
Commit = 105,
|
||||
}
|
||||
|
||||
pub fn block_pda() -> (Pubkey, u8) {
|
||||
@@ -33,6 +33,6 @@ pub fn treasury_pda() -> (Pubkey, u8) {
|
||||
Pubkey::find_program_address(&[TREASURY], &crate::ID)
|
||||
}
|
||||
|
||||
pub fn wager_pda(round: u64, seed: [u8; 32]) -> (Pubkey, u8) {
|
||||
Pubkey::find_program_address(&[WAGER, &round.to_le_bytes(), &seed], &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,27 +0,0 @@
|
||||
use steel::*;
|
||||
|
||||
use super::OreAccount;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
||||
pub struct Wager {
|
||||
/// The amount bet in this wager.
|
||||
pub amount: u64,
|
||||
|
||||
/// The signer authorized to use this wager.
|
||||
pub authority: Pubkey,
|
||||
|
||||
/// The cumulative amount bet in the current round prior to this wager.
|
||||
pub cumulative_sum: u64,
|
||||
|
||||
/// The current round this wager is for.
|
||||
pub round: u64,
|
||||
|
||||
/// The ID of the wager, used for provably fair randomness.
|
||||
pub seed: [u8; 32],
|
||||
|
||||
/// The timestamp of the wager.
|
||||
pub timestamp: u64,
|
||||
}
|
||||
|
||||
account!(OreAccount, Wager);
|
||||
Reference in New Issue
Block a user