mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-14 07:26:51 +00:00
cleanup
This commit is contained in:
@@ -8,7 +8,7 @@ pub fn process_claim(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
let amount = u64::from_le_bytes(args.amount);
|
||||
|
||||
// Load accounts.
|
||||
let [signer_info, miner_info, miner_rewards_info, recipient_info, mint_info, system_program, token_program, associated_token_program] =
|
||||
let [signer_info, miner_info, miner_tokens_info, recipient_info, mint_info, system_program, token_program, associated_token_program] =
|
||||
accounts
|
||||
else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
@@ -17,8 +17,8 @@ pub fn process_claim(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
let miner = miner_info
|
||||
.as_account::<Miner>(&ore_api::ID)?
|
||||
.assert(|m| m.authority == *signer_info.key)?;
|
||||
let miner_rewards =
|
||||
miner_rewards_info.as_associated_token_account(&miner_info.key, &mint_info.key)?;
|
||||
let miner_tokens =
|
||||
miner_tokens_info.as_associated_token_account(&miner_info.key, &mint_info.key)?;
|
||||
mint_info.has_address(&MINT_ADDRESS)?.as_mint()?;
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
token_program.is_program(&spl_token::ID)?;
|
||||
@@ -40,13 +40,13 @@ pub fn process_claim(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
}
|
||||
|
||||
// Load amount.
|
||||
let amount = miner_rewards.amount().min(amount);
|
||||
let amount = miner_tokens.amount().min(amount);
|
||||
|
||||
// Transfer reward to recipient.
|
||||
transfer_signed(
|
||||
miner_info,
|
||||
miner_rewards_info,
|
||||
mint_info,
|
||||
miner_tokens_info,
|
||||
recipient_info,
|
||||
token_program,
|
||||
amount,
|
||||
&[MINER, miner.authority.as_ref()],
|
||||
|
||||
@@ -5,7 +5,7 @@ use steel::*;
|
||||
pub fn process_close(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
|
||||
// Load accounts.
|
||||
let clock = Clock::get()?;
|
||||
let [signer_info, block_info, miner_info, miner_rewards_info, mint_info, opener_info, recipient_info, treasury_info, treasury_tokens_info, system_program, token_program, associated_token_program] =
|
||||
let [signer_info, block_info, miner_info, miner_tokens_info, mint_info, opener_info, recipient_info, treasury_info, treasury_tokens_info, system_program, token_program, associated_token_program] =
|
||||
accounts
|
||||
else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
@@ -25,18 +25,18 @@ pub fn process_close(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
|
||||
associated_token_program.is_program(&spl_associated_token_account::ID)?;
|
||||
|
||||
// Load miner rewards.
|
||||
if miner_rewards_info.data_is_empty() {
|
||||
if miner_tokens_info.data_is_empty() {
|
||||
create_associated_token_account(
|
||||
signer_info,
|
||||
miner_info,
|
||||
miner_rewards_info,
|
||||
miner_tokens_info,
|
||||
mint_info,
|
||||
system_program,
|
||||
token_program,
|
||||
associated_token_program,
|
||||
)?;
|
||||
} else {
|
||||
miner_rewards_info.as_associated_token_account(&miner_info.key, &mint_info.key)?;
|
||||
miner_tokens_info.as_associated_token_account(&miner_info.key, &mint_info.key)?;
|
||||
}
|
||||
|
||||
// Payout block reward to winning miner.
|
||||
@@ -54,7 +54,17 @@ pub fn process_close(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
|
||||
transfer_signed(
|
||||
treasury_info,
|
||||
treasury_tokens_info,
|
||||
miner_rewards_info,
|
||||
miner_tokens_info,
|
||||
token_program,
|
||||
block.reward,
|
||||
&[TREASURY],
|
||||
)?;
|
||||
} else {
|
||||
// If no one won, burn the block reward.
|
||||
burn_signed(
|
||||
treasury_tokens_info,
|
||||
mint_info,
|
||||
treasury_info,
|
||||
token_program,
|
||||
block.reward,
|
||||
&[TREASURY],
|
||||
|
||||
@@ -22,12 +22,12 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
|
||||
let market = market_info
|
||||
.as_account_mut::<Market>(&ore_api::ID)?
|
||||
.assert_mut(|m| m.block_id == block_next.id - 1)?;
|
||||
mint_info.has_address(&MINT_ADDRESS)?.as_mint()?;
|
||||
let ore_mint = mint_info.has_address(&MINT_ADDRESS)?.as_mint()?;
|
||||
treasury_info.as_account::<Treasury>(&ore_api::ID)?;
|
||||
treasury_tokens_info
|
||||
.is_writable()?
|
||||
.as_associated_token_account(treasury_info.key, mint_info.key)?;
|
||||
let vault = vault_info.as_associated_token_account(&mint_info.key, &mint_info.key)?;
|
||||
let vault = vault_info.as_associated_token_account(&market_info.key, &mint_info.key)?;
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
token_program.is_program(&spl_token::ID)?;
|
||||
ore_program.is_program(&ore_api::ID)?;
|
||||
@@ -49,7 +49,6 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
|
||||
let block_reward = calculate_block_reward(&block_prev.slot_hash);
|
||||
|
||||
// Limit the block reward to supply cap.
|
||||
let ore_mint = mint_info.as_mint()?;
|
||||
let max_reward = MAX_SUPPLY.saturating_sub(ore_mint.supply());
|
||||
let block_reward = block_reward.min(max_reward);
|
||||
|
||||
@@ -94,7 +93,7 @@ pub fn process_reset(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
|
||||
market.fee.uncollected = 0;
|
||||
market.fee.cumulative = 0;
|
||||
|
||||
// Mark the block start and end slots.
|
||||
// Setup the next block start and end slots.
|
||||
block_next.start_slot = clock.slot;
|
||||
block_next.end_slot = clock.slot + config.block_duration;
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@ pub fn process_swap(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
signer_info.is_signer()?;
|
||||
let block: &mut Block = block_info
|
||||
.as_account_mut::<Block>(&ore_api::ID)?
|
||||
.assert_mut(|b| b.start_slot <= clock.slot)?
|
||||
.assert_mut(|b| b.end_slot > clock.slot)?;
|
||||
.assert_mut(|b| b.start_slot <= clock.slot)? // Block has started
|
||||
.assert_mut(|b| b.end_slot > clock.slot)?; // Block has not ended
|
||||
let config = config_info.as_account_mut::<Config>(&ore_api::ID)?;
|
||||
fee_collector_info
|
||||
.is_writable()?
|
||||
@@ -33,18 +33,25 @@ pub fn process_swap(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
let miner = miner_info
|
||||
.as_account_mut::<Miner>(&ore_api::ID)?
|
||||
.assert_mut(|m| m.authority == *signer_info.key)?;
|
||||
mint_info.has_address(&market.quote.mint)?.as_mint()?;
|
||||
mint_info
|
||||
.has_address(&market.quote.mint)?
|
||||
.has_address(&MINT_ADDRESS)?
|
||||
.as_mint()?;
|
||||
vault_info
|
||||
.is_writable()?
|
||||
.has_address(&vault_pda().0)?
|
||||
.as_token_account()?
|
||||
.assert(|t| t.mint() == *mint_info.key)?
|
||||
.assert(|t| t.owner() == *market_info.key)?;
|
||||
.as_associated_token_account(market_info.key, mint_info.key)?;
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
token_program.is_program(&spl_token::ID)?;
|
||||
associated_token_program.is_program(&spl_associated_token_account::ID)?;
|
||||
ore_program.is_program(&ore_api::ID)?;
|
||||
|
||||
// Reset miner.
|
||||
if miner.block_id != block.id {
|
||||
miner.block_id = block.id;
|
||||
miner.hashpower = 0;
|
||||
}
|
||||
|
||||
// Pay swap fee.
|
||||
if config.fee_rate > 0 {
|
||||
signer_info.send(config.fee_rate, fee_collector_info);
|
||||
@@ -76,12 +83,6 @@ pub fn process_swap(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
swap_event.authority = *signer_info.key;
|
||||
swap_event.block_id = block.id;
|
||||
|
||||
// Reset miner.
|
||||
if miner.block_id != block.id {
|
||||
miner.block_id = block.id;
|
||||
miner.hashpower = 0;
|
||||
}
|
||||
|
||||
// Transfer tokens
|
||||
match direction {
|
||||
SwapDirection::Buy => {
|
||||
|
||||
Reference in New Issue
Block a user