mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-16 07:26:51 +00:00
cleanup
This commit is contained in:
@@ -2,7 +2,7 @@ use ore_api::prelude::*;
|
||||
use solana_program::keccak::hashv;
|
||||
use steel::*;
|
||||
|
||||
/// Places a bet.
|
||||
/// Open a wager.
|
||||
pub fn process_bet(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult {
|
||||
// Parse data.
|
||||
let args = Bet::try_from_bytes(data)?;
|
||||
@@ -46,14 +46,14 @@ pub fn process_bet(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult {
|
||||
let wager = wager_info.as_account_mut::<Wager>(&ore_api::ID)?;
|
||||
wager.amount = amount;
|
||||
wager.authority = *signer_info.key;
|
||||
wager.cumulative_bets = block.total_bets;
|
||||
wager.cumulative_sum = block.cumulative_sum;
|
||||
wager.round = block.current_round;
|
||||
wager.seed = seed;
|
||||
wager.timestamp = clock.unix_timestamp as u64;
|
||||
|
||||
// Update block stats.
|
||||
block.bet_count += 1;
|
||||
block.total_bets += amount;
|
||||
block.cumulative_sum += amount;
|
||||
block.total_wagers += 1;
|
||||
|
||||
// Hash client seed into block noise for provably fair randomness.
|
||||
block.noise = hashv(&[&block.noise, &seed]).to_bytes();
|
||||
|
||||
@@ -2,7 +2,7 @@ use meteora_pools_sdk::instructions::{SwapCpi, SwapCpiAccounts, SwapInstructionA
|
||||
use ore_api::prelude::*;
|
||||
use steel::*;
|
||||
|
||||
/// Swaps bets into ORE and buries the ORE.
|
||||
/// Swap wagers into ORE and bury the ORE.
|
||||
pub fn process_bury(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
|
||||
// Load accounts.
|
||||
let clock = Clock::get()?;
|
||||
@@ -61,19 +61,20 @@ pub fn process_bury(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult
|
||||
|
||||
// Burn (bury) the purchased ORE.
|
||||
let block_ore = block_ore_info.as_associated_token_account(block_info.key, &MINT_ADDRESS)?;
|
||||
let burn_amount = block_ore.amount();
|
||||
burn_signed_with_bump(
|
||||
block_ore_info,
|
||||
ore_mint_info,
|
||||
block_info,
|
||||
token_program_info,
|
||||
block_ore.amount(),
|
||||
burn_amount,
|
||||
&[BLOCK],
|
||||
block_bump,
|
||||
)?;
|
||||
|
||||
// Emit an event.
|
||||
BuryEvent {
|
||||
amount: block_ore.amount(),
|
||||
amount: burn_amount,
|
||||
ts: clock.unix_timestamp as u64,
|
||||
}
|
||||
.log();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use ore_api::prelude::*;
|
||||
use steel::*;
|
||||
|
||||
/// Closes a wager account.
|
||||
/// Close a wager account.
|
||||
pub fn process_close(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
|
||||
// Load accounts.
|
||||
let [signer_info, block_info, wager_info, system_program] = accounts else {
|
||||
|
||||
@@ -31,7 +31,7 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], _data: &[u8]) -> Program
|
||||
&[BLOCK],
|
||||
)?;
|
||||
let block = block_info.as_account_mut::<Block>(&ore_api::ID)?;
|
||||
block.bet_count = 0;
|
||||
block.cumulative_sum = 0;
|
||||
block.current_round = 0;
|
||||
block.ends_at = 0;
|
||||
block.mint = spl_token::native_mint::ID;
|
||||
@@ -39,7 +39,7 @@ pub fn process_initialize(accounts: &[AccountInfo<'_>], _data: &[u8]) -> Program
|
||||
block.payed_out = 0;
|
||||
block.reward = 0;
|
||||
block.started_at = 0;
|
||||
block.total_bets = 0;
|
||||
block.total_wagers = 0;
|
||||
|
||||
// Initialize block token accounts.
|
||||
create_associated_token_account(
|
||||
|
||||
@@ -3,7 +3,7 @@ use solana_program::keccak::hashv;
|
||||
use steel::*;
|
||||
use sysvar::slot_hashes::SlotHashes;
|
||||
|
||||
/// Pays out a block reward to the winning.
|
||||
/// Payout block reward to the winning wager.
|
||||
pub fn process_payout(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
|
||||
// Load accounts.
|
||||
let clock = Clock::get()?;
|
||||
@@ -29,7 +29,7 @@ pub fn process_payout(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResu
|
||||
block.payed_out = 1;
|
||||
|
||||
// Skip payout if no bets were placed.
|
||||
if block.total_bets == 0 || block.reward == 0 {
|
||||
if block.cumulative_sum == 0 || block.reward == 0 {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -44,13 +44,13 @@ pub fn process_payout(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResu
|
||||
let y = u64::from_le_bytes(block.noise[8..16].try_into().unwrap());
|
||||
let z = u64::from_le_bytes(block.noise[16..24].try_into().unwrap());
|
||||
let w = u64::from_le_bytes(block.noise[24..32].try_into().unwrap());
|
||||
let roll = (x ^ y ^ z ^ w) % block.total_bets;
|
||||
let roll = (x ^ y ^ z ^ w) % block.cumulative_sum;
|
||||
|
||||
// Validate the wager account.
|
||||
let wager = wager_info
|
||||
.as_account_mut::<Wager>(&ore_api::ID)?
|
||||
.assert_mut(|w| roll >= w.cumulative_bets)?
|
||||
.assert_mut(|w| roll < w.cumulative_bets + w.amount)?;
|
||||
.assert_mut(|w| roll >= w.cumulative_sum)?
|
||||
.assert_mut(|w| roll < w.cumulative_sum + w.amount)?;
|
||||
recipient_info.as_associated_token_account(&wager.authority, &MINT_ADDRESS)?;
|
||||
|
||||
// Transfer the winnings to the recipient.
|
||||
|
||||
@@ -2,7 +2,7 @@ use ore_api::prelude::*;
|
||||
use ore_boost_api::{consts::DENOMINATOR_BPS, prelude::Config as BoostConfig};
|
||||
use steel::*;
|
||||
|
||||
/// Reset tops up the bus balances and updates the emissions and reward rates.
|
||||
/// Start the next block.
|
||||
pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
|
||||
// Load accounts.
|
||||
let clock = Clock::get()?;
|
||||
@@ -42,14 +42,14 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
|
||||
boost_proof.total_rewards += boost_reward;
|
||||
|
||||
// Reset the block.
|
||||
block.bet_count = 0;
|
||||
block.cumulative_sum = 0;
|
||||
block.current_round += 1;
|
||||
block.ends_at = clock.slot + 150; // 60 seconds
|
||||
block.noise = [0; 32];
|
||||
block.payed_out = 0;
|
||||
block.reward = net_emissions - boost_reward;
|
||||
block.started_at = clock.slot;
|
||||
block.total_bets = 0;
|
||||
block.total_wagers = 0;
|
||||
|
||||
// Fund the treasury.
|
||||
mint_to_signed(
|
||||
|
||||
Reference in New Issue
Block a user