mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-14 15:10:13 +00:00
reward event
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user