mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-29 15:11:03 +00:00
set executor
This commit is contained in:
@@ -11,12 +11,12 @@ pub enum OreInstruction {
|
|||||||
Initialize = 4,
|
Initialize = 4,
|
||||||
Log = 5,
|
Log = 5,
|
||||||
Reset = 7,
|
Reset = 7,
|
||||||
Reimburse = 8,
|
SetExecutor = 9,
|
||||||
|
|
||||||
// Admin
|
// Admin
|
||||||
Bury = 9,
|
Bury = 10,
|
||||||
SetAdmin = 10,
|
SetAdmin = 11,
|
||||||
SetFeeCollector = 11,
|
SetFeeCollector = 12,
|
||||||
|
|
||||||
// Seeker
|
// Seeker
|
||||||
ClaimSeeker = 14,
|
ClaimSeeker = 14,
|
||||||
@@ -78,6 +78,12 @@ pub struct Uncommit {
|
|||||||
pub amount: [u8; 8],
|
pub amount: [u8; 8],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
||||||
|
pub struct SetExecutor {
|
||||||
|
pub executor: [u8; 32],
|
||||||
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
||||||
pub struct SetAdmin {
|
pub struct SetAdmin {
|
||||||
@@ -106,12 +112,6 @@ pub struct Bury {
|
|||||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
||||||
pub struct ClaimSeeker {}
|
pub struct ClaimSeeker {}
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
|
||||||
pub struct Reimburse {
|
|
||||||
pub amount: [u8; 8],
|
|
||||||
}
|
|
||||||
|
|
||||||
instruction!(OreInstruction, Boost);
|
instruction!(OreInstruction, Boost);
|
||||||
instruction!(OreInstruction, ClaimSOL);
|
instruction!(OreInstruction, ClaimSOL);
|
||||||
instruction!(OreInstruction, ClaimORE);
|
instruction!(OreInstruction, ClaimORE);
|
||||||
@@ -120,7 +120,7 @@ instruction!(OreInstruction, Initialize);
|
|||||||
instruction!(OreInstruction, Log);
|
instruction!(OreInstruction, Log);
|
||||||
instruction!(OreInstruction, Bury);
|
instruction!(OreInstruction, Bury);
|
||||||
instruction!(OreInstruction, Reset);
|
instruction!(OreInstruction, Reset);
|
||||||
instruction!(OreInstruction, Reimburse);
|
instruction!(OreInstruction, SetExecutor);
|
||||||
instruction!(OreInstruction, SetAdmin);
|
instruction!(OreInstruction, SetAdmin);
|
||||||
instruction!(OreInstruction, SetFeeCollector);
|
instruction!(OreInstruction, SetFeeCollector);
|
||||||
instruction!(OreInstruction, ClaimSeeker);
|
instruction!(OreInstruction, ClaimSeeker);
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ mod claim_sol;
|
|||||||
mod deploy;
|
mod deploy;
|
||||||
mod initialize;
|
mod initialize;
|
||||||
mod log;
|
mod log;
|
||||||
mod reimburse;
|
|
||||||
mod reset;
|
mod reset;
|
||||||
mod set_admin;
|
mod set_admin;
|
||||||
|
mod set_executor;
|
||||||
mod set_fee_collector;
|
mod set_fee_collector;
|
||||||
mod whitelist;
|
mod whitelist;
|
||||||
|
|
||||||
@@ -20,9 +20,9 @@ use claim_sol::*;
|
|||||||
use deploy::*;
|
use deploy::*;
|
||||||
use initialize::*;
|
use initialize::*;
|
||||||
use log::*;
|
use log::*;
|
||||||
use reimburse::*;
|
|
||||||
use reset::*;
|
use reset::*;
|
||||||
use set_admin::*;
|
use set_admin::*;
|
||||||
|
use set_executor::*;
|
||||||
use set_fee_collector::*;
|
use set_fee_collector::*;
|
||||||
|
|
||||||
use ore_api::instruction::*;
|
use ore_api::instruction::*;
|
||||||
@@ -44,7 +44,7 @@ pub fn process_instruction(
|
|||||||
OreInstruction::Log => process_log(accounts, data)?,
|
OreInstruction::Log => process_log(accounts, data)?,
|
||||||
OreInstruction::Initialize => process_initialize(accounts, data)?,
|
OreInstruction::Initialize => process_initialize(accounts, data)?,
|
||||||
OreInstruction::Reset => process_reset(accounts, data)?,
|
OreInstruction::Reset => process_reset(accounts, data)?,
|
||||||
OreInstruction::Reimburse => process_reimburse(accounts, data)?,
|
OreInstruction::SetExecutor => process_set_executor(accounts, data)?,
|
||||||
|
|
||||||
// Admin
|
// Admin
|
||||||
OreInstruction::SetAdmin => process_set_admin(accounts, data)?,
|
OreInstruction::SetAdmin => process_set_admin(accounts, data)?,
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
use ore_api::prelude::*;
|
|
||||||
use solana_program::rent::Rent;
|
|
||||||
use steel::*;
|
|
||||||
|
|
||||||
/// Reimburses an executor keypair for their tx fee expenses.
|
|
||||||
pub fn process_reimburse(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult {
|
|
||||||
// Parse data.
|
|
||||||
let args = Reimburse::try_from_bytes(data)?;
|
|
||||||
let amount = u64::from_le_bytes(args.amount);
|
|
||||||
|
|
||||||
// Load accounts.
|
|
||||||
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)?
|
|
||||||
.assert_mut(|m| m.executor == *signer_info.key)?;
|
|
||||||
system_program.is_program(&system_program::ID)?;
|
|
||||||
|
|
||||||
// Check if miner can charge.// Check total amount.
|
|
||||||
let account_size = 8 + std::mem::size_of::<Miner>();
|
|
||||||
let min_rent = Rent::get()?.minimum_balance(account_size);
|
|
||||||
let claimable_sol = miner.rewards_sol;
|
|
||||||
let obligations = min_rent + claimable_sol;
|
|
||||||
let new_lamports = miner_info.lamports().saturating_sub(amount);
|
|
||||||
if new_lamports < obligations {
|
|
||||||
return Err(trace(
|
|
||||||
"Miner account has insufficient SOL",
|
|
||||||
ProgramError::InsufficientFunds,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send reimbursement.
|
|
||||||
miner_info.send(amount, signer_info);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
27
program/src/set_executor.rs
Normal file
27
program/src/set_executor.rs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
use ore_api::prelude::*;
|
||||||
|
use steel::*;
|
||||||
|
|
||||||
|
/// Sets the executor.
|
||||||
|
pub fn process_set_executor(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult {
|
||||||
|
// Parse data.
|
||||||
|
let args = SetExecutor::try_from_bytes(data)?;
|
||||||
|
let new_executor = Pubkey::new_from_array(args.executor);
|
||||||
|
|
||||||
|
// Load accounts.
|
||||||
|
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)?
|
||||||
|
.assert_mut_err(
|
||||||
|
|m| m.authority == *signer_info.key,
|
||||||
|
OreError::NotAuthorized.into(),
|
||||||
|
)?;
|
||||||
|
system_program.is_program(&system_program::ID)?;
|
||||||
|
|
||||||
|
// Set executor.
|
||||||
|
miner.executor = new_executor;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user