mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-13 15:09:57 +00:00
Claim fee (#136)
* claim fee * migration * migrate * sdk * disable fee * disable claim fee * cleanup * cleanup * fix * cleanup * stake * cleanup * cleanup * cleanup * hour
This commit is contained in:
@@ -17,12 +17,6 @@ pub fn process_automate(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRes
|
||||
};
|
||||
signer_info.is_signer()?;
|
||||
automation_info.is_writable()?;
|
||||
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)?;
|
||||
|
||||
// // Check whitelist
|
||||
@@ -30,6 +24,36 @@ pub fn process_automate(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRes
|
||||
// return Err(trace("Not authorized", OreError::NotAuthorized.into()));
|
||||
// }
|
||||
|
||||
// Open miner account.
|
||||
let miner = if miner_info.data_is_empty() {
|
||||
create_program_account::<Miner>(
|
||||
miner_info,
|
||||
system_program,
|
||||
&signer_info,
|
||||
&ore_api::ID,
|
||||
&[MINER, &signer_info.key.to_bytes()],
|
||||
)?;
|
||||
let miner = miner_info.as_account_mut::<Miner>(&ore_api::ID)?;
|
||||
miner.authority = *signer_info.key;
|
||||
miner.deployed = [0; 25];
|
||||
miner.cumulative = [0; 25];
|
||||
miner.checkpoint_fee = 0;
|
||||
miner.checkpoint_id = 0;
|
||||
miner.rewards_sol = 0;
|
||||
miner.rewards_ore = 0;
|
||||
miner.round_id = 0;
|
||||
miner.lifetime_rewards_sol = 0;
|
||||
miner.lifetime_rewards_ore = 0;
|
||||
miner
|
||||
} else {
|
||||
miner_info
|
||||
.as_account_mut::<Miner>(&ore_api::ID)?
|
||||
.assert_mut_err(
|
||||
|m| m.authority == *signer_info.key,
|
||||
OreError::NotAuthorized.into(),
|
||||
)?
|
||||
};
|
||||
|
||||
// Close account if executor is Pubkey::default().
|
||||
if *executor_info.key == Pubkey::default() {
|
||||
automation_info
|
||||
|
||||
@@ -29,7 +29,7 @@ pub fn process_checkpoint(accounts: &[AccountInfo<'_>], _data: &[u8]) -> Program
|
||||
}
|
||||
|
||||
let round = round_info.as_account_mut::<Round>(&ore_api::ID)?; // Round has been closed.
|
||||
treasury_info.as_account::<Treasury>(&ore_api::ID)?;
|
||||
let treasury = treasury_info.as_account_mut::<Treasury>(&ore_api::ID)?;
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
|
||||
// If round is current round, or the miner round ID does not match the provided round, return.
|
||||
@@ -118,6 +118,9 @@ pub fn process_checkpoint(accounts: &[AccountInfo<'_>], _data: &[u8]) -> Program
|
||||
miner.rewards_sol += rewards_sol;
|
||||
miner.lifetime_rewards_sol += rewards_sol;
|
||||
|
||||
// Update treasury.
|
||||
treasury.total_unclaimed += rewards_ore;
|
||||
|
||||
// Do SOL transfers.
|
||||
if rewards_sol > 0 {
|
||||
round_info.send(rewards_sol, &miner_info);
|
||||
|
||||
@@ -21,7 +21,7 @@ pub fn process_claim_ore(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRe
|
||||
.assert_mut(|m| m.authority == *signer_info.key)?;
|
||||
mint_info.has_address(&MINT_ADDRESS)?.as_mint()?;
|
||||
recipient_info.is_writable()?;
|
||||
treasury_info.as_account_mut::<Treasury>(&ore_api::ID)?;
|
||||
let treasury = treasury_info.as_account_mut::<Treasury>(&ore_api::ID)?;
|
||||
treasury_tokens_info.as_associated_token_account(&treasury_info.key, &mint_info.key)?;
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
token_program.is_program(&spl_token::ID)?;
|
||||
@@ -43,7 +43,7 @@ pub fn process_claim_ore(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRe
|
||||
}
|
||||
|
||||
// Normalize amount.
|
||||
let amount = miner.rewards_ore.min(amount);
|
||||
let amount = miner.claim_ore(amount, treasury);
|
||||
|
||||
sol_log(
|
||||
&format!(
|
||||
@@ -53,9 +53,6 @@ pub fn process_claim_ore(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRe
|
||||
.as_str(),
|
||||
);
|
||||
|
||||
// Update miner.
|
||||
miner.rewards_ore -= amount;
|
||||
|
||||
// Transfer reward to recipient.
|
||||
transfer_signed(
|
||||
treasury_info,
|
||||
|
||||
@@ -19,13 +19,10 @@ pub fn process_claim_sol(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRe
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
|
||||
// Normalize amount.
|
||||
let amount = miner.rewards_sol.min(amount);
|
||||
let amount = miner.claim_sol(amount);
|
||||
|
||||
sol_log(&format!("Claiming {} SOL", lamports_to_sol(amount)).as_str());
|
||||
|
||||
// Update miner.
|
||||
miner.rewards_sol -= amount;
|
||||
|
||||
// Transfer reward to recipient.
|
||||
miner_info.send(amount, signer_info);
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ pub fn process_deposit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResu
|
||||
};
|
||||
|
||||
// Only allow deposits from seekers.
|
||||
assert!(stake.is_seeker == 1, "Only seekers can deposit stake");
|
||||
// assert!(stake.is_seeker == 1, "Only seekers can deposit stake");
|
||||
|
||||
// Deposit into stake account.
|
||||
let amount = stake.deposit(amount, &clock, treasury, &sender);
|
||||
|
||||
@@ -59,9 +59,9 @@ pub fn process_instruction(
|
||||
OreInstruction::Reset => process_reset(accounts, data)?,
|
||||
|
||||
// Staker
|
||||
OreInstruction::Deposit => process_deposit(accounts, data)?,
|
||||
OreInstruction::Withdraw => process_withdraw(accounts, data)?,
|
||||
OreInstruction::ClaimYield => process_claim_yield(accounts, data)?,
|
||||
// OreInstruction::Deposit => process_deposit(accounts, data)?,
|
||||
// OreInstruction::Withdraw => process_withdraw(accounts, data)?,
|
||||
// OreInstruction::ClaimYield => process_claim_yield(accounts, data)?,
|
||||
|
||||
// Admin
|
||||
OreInstruction::Bury => process_bury(accounts, data)?,
|
||||
|
||||
Reference in New Issue
Block a user