mirror of
https://github.com/d0zingcat/ore.git
synced 2026-06-04 23:26:47 +00:00
sdk
This commit is contained in:
@@ -307,6 +307,28 @@ pub fn reset(
|
|||||||
data: Reset {}.to_bytes(),
|
data: Reset {}.to_bytes(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// let [signer_info, automation_info, board_info, miner_info, round_info, treasury_info, system_program] =
|
||||||
|
|
||||||
|
pub fn checkpoint(signer: Pubkey, authority: Pubkey, round_id: u64) -> Instruction {
|
||||||
|
let miner_address = miner_pda(authority).0;
|
||||||
|
let automation_address = automation_pda(authority).0;
|
||||||
|
let board_address = board_pda().0;
|
||||||
|
let round_address = round_pda(round_id).0;
|
||||||
|
let treasury_address = TREASURY_ADDRESS;
|
||||||
|
Instruction {
|
||||||
|
program_id: crate::ID,
|
||||||
|
accounts: vec![
|
||||||
|
AccountMeta::new(signer, true),
|
||||||
|
AccountMeta::new(automation_address, false),
|
||||||
|
AccountMeta::new(board_address, false),
|
||||||
|
AccountMeta::new(miner_address, false),
|
||||||
|
AccountMeta::new(round_address, false),
|
||||||
|
AccountMeta::new(treasury_address, false),
|
||||||
|
AccountMeta::new_readonly(system_program::ID, false),
|
||||||
|
],
|
||||||
|
data: Checkpoint {}.to_bytes(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_admin(signer: Pubkey, admin: Pubkey) -> Instruction {
|
pub fn set_admin(signer: Pubkey, admin: Pubkey) -> Instruction {
|
||||||
let config_address = config_pda().0;
|
let config_address = config_pda().0;
|
||||||
|
|||||||
@@ -22,10 +22,6 @@ pub struct Miner {
|
|||||||
/// The last round that this miner checkpointed.
|
/// The last round that this miner checkpointed.
|
||||||
pub checkpoint_id: u64,
|
pub checkpoint_id: u64,
|
||||||
|
|
||||||
/// The amount of SOL this miner has had refunded and may claim.
|
|
||||||
#[deprecated]
|
|
||||||
pub refund_sol: u64,
|
|
||||||
|
|
||||||
/// The amount of SOL this miner can claim.
|
/// The amount of SOL this miner can claim.
|
||||||
pub rewards_sol: u64,
|
pub rewards_sol: u64,
|
||||||
|
|
||||||
|
|||||||
@@ -13,13 +13,15 @@ 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
|
let miner = miner_info.as_account_mut::<Miner>(&ore_api::ID)?;
|
||||||
.as_account_mut::<Miner>(&ore_api::ID)?
|
// If miner has already checkpointed this round, return.
|
||||||
.assert_mut(|m| m.checkpoint_id < m.round_id)?; // Ensure miner has not already checkpointed this round.
|
if miner.checkpoint_id == miner.round_id {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
if round_info.data_is_empty() {
|
if round_info.data_is_empty() {
|
||||||
// If round account is empty, ensure the correct account was provided.
|
// 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.
|
// 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 and their checkpoint is recorded.
|
// 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(());
|
||||||
@@ -33,7 +35,7 @@ pub fn process_checkpoint(accounts: &[AccountInfo<'_>], _data: &[u8]) -> Program
|
|||||||
|
|
||||||
// Ensure round is not expired.
|
// Ensure round is not expired.
|
||||||
if clock.slot >= round.expires_at {
|
if clock.slot >= round.expires_at {
|
||||||
// In this case, the miner forfeits any potential rewards and their checkpoint is recorded.
|
// 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(());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,16 +19,12 @@ pub fn process_claim_sol(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRe
|
|||||||
system_program.is_program(&system_program::ID)?;
|
system_program.is_program(&system_program::ID)?;
|
||||||
|
|
||||||
// Normalize amount.
|
// Normalize amount.
|
||||||
let total_claimable = miner.rewards_sol + miner.refund_sol;
|
let amount = miner.rewards_sol.min(amount);
|
||||||
let amount = total_claimable.min(amount);
|
|
||||||
|
|
||||||
sol_log(&format!("Claiming {} SOL", lamports_to_sol(amount)).as_str());
|
sol_log(&format!("Claiming {} SOL", lamports_to_sol(amount)).as_str());
|
||||||
|
|
||||||
// Update miner. Deduct from refund first, then from rewards.
|
// Update miner.
|
||||||
let from_refund = amount.min(miner.refund_sol);
|
miner.rewards_sol -= amount;
|
||||||
miner.refund_sol -= from_refund;
|
|
||||||
let from_rewards = amount - from_refund;
|
|
||||||
miner.rewards_sol -= from_rewards;
|
|
||||||
|
|
||||||
// Transfer reward to recipient.
|
// Transfer reward to recipient.
|
||||||
miner_info.send(amount, signer_info);
|
miner_info.send(amount, signer_info);
|
||||||
|
|||||||
@@ -92,7 +92,6 @@ pub fn process_deploy(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul
|
|||||||
miner.authority = *signer_info.key;
|
miner.authority = *signer_info.key;
|
||||||
miner.deployed = [0; 25];
|
miner.deployed = [0; 25];
|
||||||
miner.cumulative = [0; 25];
|
miner.cumulative = [0; 25];
|
||||||
miner.refund_sol = 0;
|
|
||||||
miner.rewards_sol = 0;
|
miner.rewards_sol = 0;
|
||||||
miner.rewards_ore = 0;
|
miner.rewards_ore = 0;
|
||||||
miner.round_id = round.id;
|
miner.round_id = round.id;
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ mod claim_yield;
|
|||||||
mod close;
|
mod close;
|
||||||
mod deploy;
|
mod deploy;
|
||||||
mod deposit;
|
mod deposit;
|
||||||
|
mod migrate_board;
|
||||||
|
mod migrate_miner;
|
||||||
// mod initialize;
|
// mod initialize;
|
||||||
mod log;
|
mod log;
|
||||||
mod reset;
|
mod reset;
|
||||||
@@ -29,6 +31,8 @@ use claim_yield::*;
|
|||||||
use close::*;
|
use close::*;
|
||||||
use deploy::*;
|
use deploy::*;
|
||||||
use deposit::*;
|
use deposit::*;
|
||||||
|
use migrate_board::*;
|
||||||
|
use migrate_miner::*;
|
||||||
// use initialize::*;
|
// use initialize::*;
|
||||||
use log::*;
|
use log::*;
|
||||||
use reset::*;
|
use reset::*;
|
||||||
|
|||||||
19
program/src/migrate_board.rs
Normal file
19
program/src/migrate_board.rs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
use ore_api::prelude::*;
|
||||||
|
use solana_program::slot_hashes::SlotHashes;
|
||||||
|
use steel::*;
|
||||||
|
|
||||||
|
/// Pays out the winners and block reward.
|
||||||
|
pub fn process_migrate_board(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
|
||||||
|
// Load accounts.
|
||||||
|
let clock = Clock::get()?;
|
||||||
|
let [signer_info, board_info, system_program] = accounts else {
|
||||||
|
return Err(ProgramError::NotEnoughAccountKeys);
|
||||||
|
};
|
||||||
|
signer_info.is_signer()?;
|
||||||
|
let board = board_info.as_account_mut::<Board>(&ore_api::ID)?;
|
||||||
|
system_program.is_program(&system_program::ID)?;
|
||||||
|
|
||||||
|
// TODO Migrate miner account.
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
20
program/src/migrate_miner.rs
Normal file
20
program/src/migrate_miner.rs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
use ore_api::prelude::*;
|
||||||
|
use solana_program::slot_hashes::SlotHashes;
|
||||||
|
use steel::*;
|
||||||
|
|
||||||
|
/// Pays out the winners and block reward.
|
||||||
|
pub fn process_migrate_miner(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
|
||||||
|
// Load accounts.
|
||||||
|
let clock = Clock::get()?;
|
||||||
|
let [signer_info, miner_info, system_program] = accounts else {
|
||||||
|
return Err(ProgramError::NotEnoughAccountKeys);
|
||||||
|
};
|
||||||
|
signer_info.is_signer()?;
|
||||||
|
let miner = miner_info.as_account_mut::<Miner>(&ore_api::ID)?;
|
||||||
|
system_program.is_program(&system_program::ID)?;
|
||||||
|
|
||||||
|
// TODO Migrate miner account.
|
||||||
|
// TODO Move refund_sol into rewards_sol.
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user