mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-13 15:09:57 +00:00
cleanup
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# ORE
|
# ORE
|
||||||
|
|
||||||
ORE is a crypto mining game.
|
ORE is a crypto mining protocol.
|
||||||
|
|
||||||
|
|
||||||
## API
|
## API
|
||||||
@@ -13,6 +13,7 @@ ORE is a crypto mining game.
|
|||||||
|
|
||||||
#### Mining
|
#### Mining
|
||||||
- [`Automate`](program/src/automate.rs) - Configures a new automation.
|
- [`Automate`](program/src/automate.rs) - Configures a new automation.
|
||||||
|
- [`Checkpoint`](program/src/checkpoint.rs) - Checkpoints rewards from an prior round.
|
||||||
- [`ClaimORE`](program/src/claim_ore.rs) - Claims ORE mining rewards.
|
- [`ClaimORE`](program/src/claim_ore.rs) - Claims ORE mining rewards.
|
||||||
- [`ClaimSOL`](program/src/claim_sol.rs) - Claims SOL mining rewards.
|
- [`ClaimSOL`](program/src/claim_sol.rs) - Claims SOL mining rewards.
|
||||||
- [`Deploy`](program/src/deploy.rs) – Deploys SOL to claim space on the board.
|
- [`Deploy`](program/src/deploy.rs) – Deploys SOL to claim space on the board.
|
||||||
@@ -36,11 +37,11 @@ ORE is a crypto mining game.
|
|||||||
|
|
||||||
## State
|
## State
|
||||||
- [`Automation`](api/src/state/automation.rs) - Tracks automation configs.
|
- [`Automation`](api/src/state/automation.rs) - Tracks automation configs.
|
||||||
- [`Board`](api/src/state/board.rs) - Holds current game state.
|
- [`Board`](api/src/state/board.rs) - Tracks the current round number and timestamps.
|
||||||
- [`Config`](api/src/state/config.rs) - Global program configs.
|
- [`Config`](api/src/state/config.rs) - Global program configs.
|
||||||
- [`Miner`](api/src/state/miner.rs) - Tracks a miner's game state.
|
- [`Miner`](api/src/state/miner.rs) - Tracks a miner's game state.
|
||||||
|
- [`Round`](api/src/state/round.rs) - Tracks the game state of a given round.
|
||||||
- [`Seeker`](api/src/state/seeker.rs) - Tracks whether a Seeker token has been claimed.
|
- [`Seeker`](api/src/state/seeker.rs) - Tracks whether a Seeker token has been claimed.
|
||||||
- [`Square`](api/src/state/square.rs) - The blockspace state and claims.
|
|
||||||
- [`Stake`](api/src/state/stake.rs) - Manages a user's staking activity.
|
- [`Stake`](api/src/state/stake.rs) - Manages a user's staking activity.
|
||||||
- [`Treasury`](api/src/state/treasury.rs) - Mints, burns, and escrows ORE tokens.
|
- [`Treasury`](api/src/state/treasury.rs) - Mints, burns, and escrows ORE tokens.
|
||||||
|
|
||||||
|
|||||||
@@ -13,52 +13,48 @@ pub fn process_checkpoint(accounts: &[AccountInfo<'_>], _data: &[u8]) -> Program
|
|||||||
signer_info.is_signer()?;
|
signer_info.is_signer()?;
|
||||||
let board = board_info.as_account::<Board>(&ore_api::ID)?;
|
let board = board_info.as_account::<Board>(&ore_api::ID)?;
|
||||||
let miner = miner_info.as_account_mut::<Miner>(&ore_api::ID)?;
|
let miner = miner_info.as_account_mut::<Miner>(&ore_api::ID)?;
|
||||||
|
|
||||||
// If miner has already checkpointed this round, return.
|
// If miner has already checkpointed this round, return.
|
||||||
if miner.checkpoint_id == miner.round_id {
|
if miner.checkpoint_id == miner.round_id {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If round account is empty, verify the correct account was provided.
|
||||||
|
// This can happen if the miner attempted to checkpoint after the round expired and the account was closed.
|
||||||
|
// In this case, the miner forfeits any potential rewards.
|
||||||
if round_info.data_is_empty() {
|
if round_info.data_is_empty() {
|
||||||
// If round account is empty, ensure the correct account was provided.
|
|
||||||
// This can happen if the miner attempted to checkpoint after the round expired and the account was closed.
|
|
||||||
// In this case, the miner forfeits any potential rewards.
|
|
||||||
round_info.has_seeds(&[ROUND, &miner.round_id.to_le_bytes()], &ore_api::ID)?;
|
round_info.has_seeds(&[ROUND, &miner.round_id.to_le_bytes()], &ore_api::ID)?;
|
||||||
miner.checkpoint_id = miner.round_id;
|
miner.checkpoint_id = miner.round_id;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let round = round_info.as_account_mut::<Round>(&ore_api::ID)?;
|
let round = round_info.as_account_mut::<Round>(&ore_api::ID)?;
|
||||||
|
|
||||||
// Ensure miner round ID matches the provided round.
|
|
||||||
if round.id != miner.round_id {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
treasury_info.as_account::<Treasury>(&ore_api::ID)?;
|
treasury_info.as_account::<Treasury>(&ore_api::ID)?;
|
||||||
system_program.is_program(&system_program::ID)?;
|
system_program.is_program(&system_program::ID)?;
|
||||||
|
|
||||||
// If round is current round, return.
|
// If round is current round, or the miner round ID does not match the provided round, return.
|
||||||
if round.id == board.round_id {
|
if round.id == board.round_id || round.id != miner.round_id {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure round is not expired.
|
// Ensure round is not expired.
|
||||||
|
// In this case, the miner forfeits any potential rewards.
|
||||||
if clock.slot >= round.expires_at {
|
if clock.slot >= round.expires_at {
|
||||||
// In this case, the miner forfeits any potential rewards.
|
|
||||||
miner.checkpoint_id = miner.round_id;
|
miner.checkpoint_id = miner.round_id;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the RNG.
|
// Get the RNG.
|
||||||
|
// If the round has no RNG, no one wins.
|
||||||
let Some(r) = round.rng() else {
|
let Some(r) = round.rng() else {
|
||||||
// If the round has no RNG, no one wins.
|
|
||||||
miner.checkpoint_id = miner.round_id;
|
miner.checkpoint_id = miner.round_id;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
|
|
||||||
// Calculate bot fee.
|
// Calculate bot fee.
|
||||||
|
// If the round expires in less than 12h, anyone may checkpoint this account and collect the bot fee.
|
||||||
let mut bot_fee = 0;
|
let mut bot_fee = 0;
|
||||||
if clock.slot >= round.expires_at - TWELVE_HOURS_SLOTS {
|
if clock.slot >= round.expires_at - TWELVE_HOURS_SLOTS {
|
||||||
// The round expires in less than 12h.
|
|
||||||
// Anyone may checkpoint this account and collect the bot fee.
|
|
||||||
bot_fee = miner.checkpoint_fee;
|
bot_fee = miner.checkpoint_fee;
|
||||||
miner.checkpoint_fee = 0;
|
miner.checkpoint_fee = 0;
|
||||||
}
|
}
|
||||||
@@ -112,14 +108,6 @@ pub fn process_checkpoint(accounts: &[AccountInfo<'_>], _data: &[u8]) -> Program
|
|||||||
miner_info.send(bot_fee, &signer_info);
|
miner_info.send(bot_fee, &signer_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assert round has sufficient funds for rent.
|
|
||||||
let account_size = 8 + std::mem::size_of::<Round>();
|
|
||||||
let required_rent = Rent::get()?.minimum_balance(account_size);
|
|
||||||
assert!(
|
|
||||||
round_info.lamports() >= required_rent,
|
|
||||||
"Round does not have sufficient funds for rent"
|
|
||||||
);
|
|
||||||
|
|
||||||
let account_size = 8 + std::mem::size_of::<Miner>();
|
let account_size = 8 + std::mem::size_of::<Miner>();
|
||||||
let required_rent = Rent::get()?.minimum_balance(account_size);
|
let required_rent = Rent::get()?.minimum_balance(account_size);
|
||||||
assert!(
|
assert!(
|
||||||
|
|||||||
Reference in New Issue
Block a user