burn if no payout

This commit is contained in:
Hardhat Chad
2025-05-26 15:38:49 -07:00
parent e072b70e37
commit f022ada917
2 changed files with 22 additions and 1 deletions

View File

@@ -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();