mirror of
https://github.com/d0zingcat/ore.git
synced 2026-06-11 15:11:54 +00:00
migrate
This commit is contained in:
@@ -19,12 +19,16 @@ 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 total_claimable = miner.rewards_sol + miner.refund_sol;
|
||||
let amount = total_claimable.min(amount);
|
||||
|
||||
sol_log(&format!("Claiming {} SOL", lamports_to_sol(amount)).as_str());
|
||||
|
||||
// Update miner.
|
||||
miner.rewards_sol -= amount;
|
||||
// Update miner. Deduct from refund first, then from rewards.
|
||||
let from_refund = amount.min(miner.refund_sol);
|
||||
miner.refund_sol -= from_refund;
|
||||
let from_rewards = amount - from_refund;
|
||||
miner.rewards_sol -= from_rewards;
|
||||
|
||||
// Transfer reward to recipient.
|
||||
miner_info.send(amount, signer_info);
|
||||
|
||||
@@ -7,6 +7,8 @@ mod claim_sol;
|
||||
mod deploy;
|
||||
mod initialize;
|
||||
mod log;
|
||||
mod migrate_miner;
|
||||
mod migrate_squares;
|
||||
mod reset;
|
||||
mod set_admin;
|
||||
mod set_fee_collector;
|
||||
@@ -22,6 +24,8 @@ use claim_sol::*;
|
||||
use deploy::*;
|
||||
use initialize::*;
|
||||
use log::*;
|
||||
use migrate_miner::*;
|
||||
use migrate_squares::*;
|
||||
use reset::*;
|
||||
use set_admin::*;
|
||||
use set_fee_collector::*;
|
||||
@@ -53,6 +57,8 @@ pub fn process_instruction(
|
||||
OreInstruction::Wrap => process_wrap(accounts, data)?,
|
||||
OreInstruction::SetAdmin => process_set_admin(accounts, data)?,
|
||||
OreInstruction::SetFeeCollector => process_set_fee_collector(accounts, data)?,
|
||||
OreInstruction::MigrateMiner => process_migrate_miner(accounts, data)?,
|
||||
OreInstruction::MigrateSquares => process_migrate_squares(accounts, data)?,
|
||||
|
||||
// Seeker
|
||||
OreInstruction::ClaimSeeker => process_claim_seeker(accounts, data)?,
|
||||
|
||||
55
program/src/migrate_miner.rs
Normal file
55
program/src/migrate_miner.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
use ore_api::prelude::*;
|
||||
use solana_program::rent::Rent;
|
||||
use steel::*;
|
||||
|
||||
/// Sets the admin.
|
||||
pub fn process_migrate_miner(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
|
||||
// Load accounts.
|
||||
let [signer_info, config_info, miner_info, system_program] = accounts else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
};
|
||||
signer_info.is_signer()?;
|
||||
let miner_old = miner_info
|
||||
.as_account_mut::<MinerOLD>(&ore_api::ID)?
|
||||
.assert_mut(|m| m.authority == *signer_info.key)?;
|
||||
config_info
|
||||
.as_account_mut::<Config>(&ore_api::ID)?
|
||||
.assert_mut_err(
|
||||
|c| c.admin == *signer_info.key,
|
||||
OreError::NotAuthorized.into(),
|
||||
)?;
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
|
||||
// Record old values.
|
||||
let authority = miner_old.authority;
|
||||
let deployed = miner_old.deployed;
|
||||
let executor = miner_old.executor;
|
||||
let rewards_sol = miner_old.rewards_sol;
|
||||
let rewards_ore = miner_old.rewards_ore;
|
||||
let round_id = miner_old.round_id;
|
||||
let lifetime_rewards_sol = miner_old.lifetime_rewards_sol;
|
||||
let lifetime_rewards_ore = miner_old.lifetime_rewards_ore;
|
||||
|
||||
// Realloc miner
|
||||
let new_size = 8 + std::mem::size_of::<Miner>();
|
||||
let old_size = 8 + std::mem::size_of::<MinerOLD>();
|
||||
let new_rent = Rent::get()?.minimum_balance(new_size);
|
||||
let old_rent = Rent::get()?.minimum_balance(old_size);
|
||||
let additional_rent = new_rent - old_rent;
|
||||
miner_info.realloc(new_size, false)?;
|
||||
miner_info.collect(additional_rent, &signer_info)?;
|
||||
|
||||
// Update miner.
|
||||
let miner = miner_info.as_account_mut::<Miner>(&ore_api::ID)?;
|
||||
miner.authority = authority;
|
||||
miner.deployed = deployed;
|
||||
miner.executor = executor;
|
||||
miner.refund_sol = 0;
|
||||
miner.rewards_sol = rewards_sol;
|
||||
miner.rewards_ore = rewards_ore;
|
||||
miner.round_id = round_id;
|
||||
miner.lifetime_rewards_sol = lifetime_rewards_sol;
|
||||
miner.lifetime_rewards_ore = lifetime_rewards_ore;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
59
program/src/migrate_squares.rs
Normal file
59
program/src/migrate_squares.rs
Normal file
@@ -0,0 +1,59 @@
|
||||
use ore_api::prelude::*;
|
||||
use solana_program::rent::Rent;
|
||||
use steel::*;
|
||||
|
||||
/// Sets the admin.
|
||||
pub fn process_migrate_squares(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
|
||||
// Load accounts.
|
||||
let [signer_info, config_info, squares_info, treasury_info, system_program] = accounts else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
};
|
||||
signer_info.is_signer()?;
|
||||
let squares_old = squares_info.as_account_mut::<SquareOLD>(&ore_api::ID)?;
|
||||
let treasury_old = treasury_info.as_account_mut::<TreasuryOLD>(&ore_api::ID)?;
|
||||
config_info
|
||||
.as_account_mut::<Config>(&ore_api::ID)?
|
||||
.assert_mut_err(
|
||||
|c| c.admin == *signer_info.key,
|
||||
OreError::NotAuthorized.into(),
|
||||
)?;
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
|
||||
// Record old values.
|
||||
let count = squares_old.count;
|
||||
let miners = squares_old.miners;
|
||||
|
||||
// Record old values.
|
||||
let balance = treasury_old.balance;
|
||||
|
||||
// Realloc squares
|
||||
let new_size = 8 + std::mem::size_of::<Square>();
|
||||
let old_size = 8 + std::mem::size_of::<SquareOLD>();
|
||||
let new_rent = Rent::get()?.minimum_balance(new_size);
|
||||
let old_rent = Rent::get()?.minimum_balance(old_size);
|
||||
let additional_rent = new_rent - old_rent;
|
||||
squares_info.realloc(new_size, false)?;
|
||||
squares_info.collect(additional_rent, &signer_info)?;
|
||||
|
||||
// Realloc treasury
|
||||
let new_size = 8 + std::mem::size_of::<Treasury>();
|
||||
let old_size = 8 + std::mem::size_of::<TreasuryOLD>();
|
||||
let new_rent = Rent::get()?.minimum_balance(new_size);
|
||||
let old_rent = Rent::get()?.minimum_balance(old_size);
|
||||
let additional_rent = new_rent - old_rent;
|
||||
treasury_info.realloc(new_size, false)?;
|
||||
treasury_info.collect(additional_rent, &signer_info)?;
|
||||
|
||||
// Update squares.
|
||||
let squares = squares_info.as_account_mut::<Square>(&ore_api::ID)?;
|
||||
squares.count = count;
|
||||
squares.miners = miners;
|
||||
squares.deployed = [[0; 16]; 25];
|
||||
|
||||
// Update treasury.
|
||||
let treasury = treasury_info.as_account_mut::<Treasury>(&ore_api::ID)?;
|
||||
treasury.balance = balance;
|
||||
treasury.motherlode = 0;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user