mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-13 23:16:52 +00:00
burn if no payout
This commit is contained in:
@@ -114,6 +114,7 @@ pub fn payout(signer: Pubkey, wager: Pubkey, recipient: Pubkey) -> Instruction {
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(block, false),
|
||||
AccountMeta::new(MINT_ADDRESS, false),
|
||||
AccountMeta::new(wager, false),
|
||||
AccountMeta::new(recipient, false),
|
||||
AccountMeta::new(TREASURY_ADDRESS, false),
|
||||
|
||||
@@ -7,7 +7,7 @@ use sysvar::slot_hashes::SlotHashes;
|
||||
pub fn process_payout(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
|
||||
// Load accounts.
|
||||
let clock = Clock::get()?;
|
||||
let [signer_info, block_info, wager_info, recipient_info, treasury_info, treasury_tokens_info, system_program, token_program, slot_hashes_sysvar] =
|
||||
let [signer_info, block_info, mint_info, wager_info, recipient_info, treasury_info, treasury_tokens_info, system_program, token_program, slot_hashes_sysvar] =
|
||||
accounts
|
||||
else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
@@ -17,6 +17,10 @@ pub fn process_payout(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResu
|
||||
.as_account_mut::<Block>(&ore_api::ID)?
|
||||
.assert_mut(|b| b.ends_at <= clock.slot)?
|
||||
.assert_mut(|b| b.paid == 0)?;
|
||||
mint_info
|
||||
.is_writable()?
|
||||
.has_address(&MINT_ADDRESS)?
|
||||
.as_mint()?;
|
||||
treasury_info.has_address(&TREASURY_ADDRESS)?;
|
||||
treasury_tokens_info
|
||||
.has_address(&TREASURY_TOKENS_ADDRESS)?
|
||||
@@ -30,6 +34,14 @@ pub fn process_payout(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResu
|
||||
|
||||
// Skip payout if no bets were placed.
|
||||
if block.cumulative_sum == 0 || block.reward == 0 {
|
||||
burn_signed(
|
||||
&treasury_tokens_info,
|
||||
&mint_info,
|
||||
&treasury_info,
|
||||
&token_program,
|
||||
block.reward,
|
||||
&[TREASURY],
|
||||
)?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -39,6 +51,14 @@ pub fn process_payout(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResu
|
||||
let Some(slot_hash) = slot_hashes.get(&block.ends_at) else {
|
||||
// If payout is not called within 2.5 minutes of the block ending,
|
||||
// then the slot hash will be unavailable and the winning wager cannot be determined.
|
||||
burn_signed(
|
||||
&treasury_tokens_info,
|
||||
&mint_info,
|
||||
&treasury_info,
|
||||
&token_program,
|
||||
block.reward,
|
||||
&[TREASURY],
|
||||
)?;
|
||||
return Ok(());
|
||||
};
|
||||
block.noise = hashv(&[&block.noise, slot_hash.as_ref()]).to_bytes();
|
||||
|
||||
Reference in New Issue
Block a user