mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-13 23:16:52 +00:00
mine event
This commit is contained in:
@@ -3,13 +3,14 @@ use steel::*;
|
||||
use crate::state::{RewardConfig, SwapDirection};
|
||||
|
||||
pub enum OreEvent {
|
||||
Swap = 0,
|
||||
Reward = 1,
|
||||
Open = 2,
|
||||
Commit = 3,
|
||||
Deposit = 4,
|
||||
Withdraw = 5,
|
||||
Commit = 0,
|
||||
Deposit = 1,
|
||||
Mine = 2,
|
||||
Open = 3,
|
||||
Reward = 4,
|
||||
Swap = 5,
|
||||
Uncommit = 6,
|
||||
Withdraw = 7,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
@@ -80,6 +81,28 @@ pub struct RewardEvent {
|
||||
pub ts: i64,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)]
|
||||
pub struct MineEvent {
|
||||
/// The event discriminator.
|
||||
pub disc: u64,
|
||||
|
||||
/// The authority who mined.
|
||||
pub authority: Pubkey,
|
||||
|
||||
/// The block id.
|
||||
pub block_id: u64,
|
||||
|
||||
/// The amount of hashes deployed.
|
||||
pub deployed: u64,
|
||||
|
||||
/// The total amount of hashes deployed in the block.
|
||||
pub total_deployed: u64,
|
||||
|
||||
/// The timestamp of the event.
|
||||
pub ts: i64,
|
||||
}
|
||||
|
||||
#[repr(u8)]
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
|
||||
pub enum RewardsType {
|
||||
@@ -236,4 +259,5 @@ event!(CommitEvent);
|
||||
event!(DepositEvent);
|
||||
event!(WithdrawEvent);
|
||||
event!(UncommitEvent);
|
||||
event!(MineEvent);
|
||||
event!(CloseEvent);
|
||||
|
||||
@@ -93,8 +93,6 @@ pub fn mine(signer: Pubkey, id: u64, amount: u64) -> Instruction {
|
||||
}
|
||||
}
|
||||
|
||||
// let [signer_info, block_info, commitment_info, market_info, miner_info, mint_info, permit_info, sender_info, system_program, token_program, slot_hashes_sysvar] =
|
||||
|
||||
pub fn commit(
|
||||
signer: Pubkey,
|
||||
amount: u64,
|
||||
@@ -187,10 +185,6 @@ pub fn deposit(signer: Pubkey, id: u64, amount: u64) -> Instruction {
|
||||
}
|
||||
}
|
||||
|
||||
// let [signer_info, block_info, collateral_info, mint_ore_info, sender_info, stake_info, system_program, token_program] =
|
||||
|
||||
// let [signer_info, block_info, collateral_info, market_info, mint_base_info, mint_quote_info, stake_info, tokens_base_info, tokens_quote_info, vault_base_info, vault_quote_info, system_program, token_program, associated_token_program] =
|
||||
|
||||
pub fn swap(
|
||||
signer: Pubkey,
|
||||
id: u64,
|
||||
|
||||
@@ -11,7 +11,7 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
|
||||
// Load accounts.
|
||||
let clock = Clock::get()?;
|
||||
let [signer_info, authority_info, block_info, commitment_info, market_info, miner_info, mint_hash_info, mint_ore_info, permit_info, recipient_info, treasury_info, treasury_tokens_info, system_program, token_program, slot_hashes_sysvar] =
|
||||
let [signer_info, authority_info, block_info, commitment_info, market_info, miner_info, mint_hash_info, mint_ore_info, permit_info, recipient_info, treasury_info, system_program, token_program, slot_hashes_sysvar] =
|
||||
accounts
|
||||
else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
@@ -42,9 +42,6 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
.is_writable()?
|
||||
.as_associated_token_account(&miner.authority, &MINT_ADDRESS)?;
|
||||
treasury_info.has_address(&TREASURY_ADDRESS)?;
|
||||
let treasury_tokens = treasury_tokens_info
|
||||
.is_writable()?
|
||||
.as_associated_token_account(&treasury_info.key, &mint_ore_info.key)?;
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
token_program.is_program(&spl_token::ID)?;
|
||||
slot_hashes_sysvar.is_sysvar(&sysvar::slot_hashes::ID)?;
|
||||
@@ -147,6 +144,17 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
.log();
|
||||
}
|
||||
|
||||
// Emit event.
|
||||
MineEvent {
|
||||
disc: OreEvent::Mine as u64,
|
||||
authority: miner.authority,
|
||||
block_id: block.id,
|
||||
deployed: amount,
|
||||
total_deployed: block.total_deployed,
|
||||
ts: clock.unix_timestamp,
|
||||
}
|
||||
.log_return();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user