reward event

This commit is contained in:
Hardhat Chad
2025-06-13 15:37:20 -07:00
parent 2f1b99ceac
commit 1d9b0ebd42
3 changed files with 63 additions and 15 deletions

View File

@@ -45,14 +45,25 @@ impl SwapEvent {
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)]
pub struct RewardEvent {
/// The amount of ORE distributed as a reward.
pub amount: u64,
/// The authority who received the reward.
pub authority: Pubkey,
/// The block id.
pub block_id: u64,
/// The amount of ORE distributed as a reward.
pub amount: u64,
/// The type of reward.
pub rewards_type: u64,
}
#[repr(u8)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
pub enum RewardsType {
Nugget = 0,
Lode = 1,
Motherlode = 2,
}
event!(SwapEvent);

View File

@@ -57,7 +57,10 @@ pub fn process_close(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
// Payout block reward.
if block.reward.lode_reward > 0 && block.reward.lode_authority != Pubkey::default() {
// Load recipient.
recipient_info.as_associated_token_account(&block.reward.lode_authority, &MINT_ADDRESS)?;
// Mint reward to recipient.
mint_to_signed(
mint_quote_info,
recipient_info,
@@ -66,6 +69,15 @@ pub fn process_close(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
block.reward.lode_reward,
&[TREASURY],
)?;
// Emit event.
RewardEvent {
amount: block.reward.lode_reward,
authority: block.reward.lode_authority,
block_id: block.id,
rewards_type: RewardsType::Lode as u64,
}
.log();
}
// Burn base liquidity.

View File

@@ -97,7 +97,7 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
}
// Mine and accumulate rewards.
let mut miner_reward = 0;
let mut nugget_reward = 0;
for _ in 0..amount {
// Update stats
block.total_hashes += 1;
@@ -109,7 +109,7 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
// Score and increment rewards.
let score = difficulty(miner.hash) as u64;
if score >= block.reward.nugget_threshold {
miner_reward += block.reward.nugget_reward;
nugget_reward += block.reward.nugget_reward;
}
// If hash is best hash, update best hash.
@@ -120,28 +120,53 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
// If hash is motherlode hash, pay the motherlode reward.
if score >= block.reward.motherlode_threshold {
// Execute transfer.
let motherlode_amount = treasury_tokens.amount();
transfer_signed(
authority_info,
treasury_tokens_info,
recipient_info,
token_program,
treasury_tokens.amount(),
motherlode_amount,
&[TREASURY],
)?;
// Emit event.
RewardEvent {
amount: motherlode_amount,
authority: miner.authority,
block_id: block.id,
rewards_type: RewardsType::Motherlode as u64,
}
.log();
}
}
// Payout ORE.
block.total_rewards += miner_reward;
miner.total_rewards += miner_reward;
mint_to_signed(
mint_ore_info,
recipient_info,
treasury_info,
token_program,
miner_reward,
&[TREASURY],
)?;
if nugget_reward > 0 {
// Update stats.
block.total_rewards += nugget_reward;
miner.total_rewards += nugget_reward;
// Mint to recipient.
mint_to_signed(
mint_ore_info,
recipient_info,
treasury_info,
token_program,
nugget_reward,
&[TREASURY],
)?;
// Emit event.
RewardEvent {
amount: nugget_reward,
authority: miner.authority,
block_id: block.id,
rewards_type: RewardsType::Nugget as u64,
}
.log();
}
Ok(())
}