mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-13 23:16:52 +00:00
config
This commit is contained in:
@@ -200,13 +200,13 @@ pub fn migrate_miner(signer: Pubkey, address: Pubkey) -> Instruction {
|
||||
|
||||
pub fn migrate_treasury(signer: Pubkey) -> Instruction {
|
||||
let config_address = config_pda().0;
|
||||
let treasury_address = treasury_pda().0;
|
||||
// let treasury_address = treasury_pda().0;
|
||||
Instruction {
|
||||
program_id: crate::ID,
|
||||
accounts: vec![
|
||||
AccountMeta::new(signer, true),
|
||||
AccountMeta::new(config_address, false),
|
||||
AccountMeta::new(treasury_address, false),
|
||||
// AccountMeta::new(treasury_address, false),
|
||||
AccountMeta::new_readonly(system_program::ID, false),
|
||||
],
|
||||
data: MigrateTreasury {}.to_bytes(),
|
||||
|
||||
@@ -1,22 +1,41 @@
|
||||
use steel::*;
|
||||
|
||||
use crate::state::config_pda;
|
||||
use crate::state::{config_pda, OreAccountOLD};
|
||||
|
||||
use super::OreAccount;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
||||
pub struct Config {
|
||||
// The address that can set the admin.
|
||||
/// The address that can update the config.
|
||||
pub admin: Pubkey,
|
||||
|
||||
// The last boost timestamp.
|
||||
/// The adress with authority to call bury.
|
||||
pub bury_authority: Pubkey,
|
||||
|
||||
/// The address that receives admin fees.
|
||||
pub fee_collector: Pubkey,
|
||||
|
||||
/// The last boost timestamp.
|
||||
pub last_boost: i64,
|
||||
|
||||
// Whether seeker activation is enabled.
|
||||
/// Whether seeker activation is enabled.
|
||||
pub is_seeker_activation_enabled: u64,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
||||
pub struct ConfigOLD {
|
||||
/// The address that can update the config.
|
||||
pub admin: Pubkey,
|
||||
|
||||
/// The last boost timestamp.
|
||||
pub last_boost: i64,
|
||||
|
||||
/// Whether seeker activation is enabled.
|
||||
pub is_seeker_activation_enabled: u64,
|
||||
|
||||
// The address that receives fees.
|
||||
/// The address that receives admin fees.
|
||||
pub fee_collector: Pubkey,
|
||||
|
||||
// The fee rate taken for each swap.
|
||||
@@ -31,3 +50,4 @@ impl Config {
|
||||
}
|
||||
|
||||
account!(OreAccount, Config);
|
||||
account!(OreAccountOLD, ConfigOLD);
|
||||
|
||||
@@ -38,6 +38,7 @@ pub enum OreAccount {
|
||||
#[repr(u8)]
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
|
||||
pub enum OreAccountOLD {
|
||||
ConfigOLD = 101,
|
||||
MinerOLD = 103,
|
||||
TreasuryOLD = 104,
|
||||
}
|
||||
|
||||
@@ -95,6 +95,9 @@ async fn main() {
|
||||
"ata" => {
|
||||
ata(&rpc, &payer).await.unwrap();
|
||||
}
|
||||
"checkpoint" => {
|
||||
checkpoint(&rpc, &payer).await.unwrap();
|
||||
}
|
||||
"checkpoint_all" => {
|
||||
checkpoint_all(&rpc, &payer).await.unwrap();
|
||||
}
|
||||
@@ -199,16 +202,16 @@ async fn ata(
|
||||
rpc: &RpcClient,
|
||||
payer: &solana_sdk::signer::keypair::Keypair,
|
||||
) -> Result<(), anyhow::Error> {
|
||||
let user = pubkey!("45db2FSR4mcXdSVVZbKbwojU6uYDpMyhpEi7cC8nHaWG");
|
||||
let token = pubkey!("So11111111111111111111111111111111111111112");
|
||||
let user = pubkey!("BQbXD9tqv3ysrvojSZao2RoW9ucR4RmiKbKEaVWJp4J3");
|
||||
let token = pubkey!("8H8rPiWW4iTFCfEkSnf7jpqeNpFfvdH9gLouAL3Fe2Zx");
|
||||
let ata = get_associated_token_address(&user, &token);
|
||||
let ix = spl_associated_token_account::instruction::create_associated_token_account(
|
||||
&payer.pubkey(),
|
||||
&user,
|
||||
&token,
|
||||
&spl_token::ID,
|
||||
);
|
||||
submit_transaction(rpc, payer, &[ix]).await?;
|
||||
// let ix = spl_associated_token_account::instruction::create_associated_token_account(
|
||||
// &payer.pubkey(),
|
||||
// &user,
|
||||
// &token,
|
||||
// &spl_token::ID,
|
||||
// );
|
||||
// submit_transaction(rpc, payer, &[ix]).await?;
|
||||
let account = rpc.get_account(&ata).await?;
|
||||
println!("ATA: {}", ata);
|
||||
println!("Account: {:?}", account);
|
||||
@@ -266,8 +269,8 @@ async fn bury(
|
||||
let amount_u64 = ui_amount_to_amount(amount_f64, TOKEN_DECIMALS);
|
||||
let wrap_ix = ore_api::sdk::wrap(payer.pubkey());
|
||||
let bury_ix = ore_api::sdk::bury(payer.pubkey(), amount_u64);
|
||||
// submit_transaction(rpc, payer, &[wrap_ix, bury_ix]).await?;
|
||||
simulate_transaction(rpc, payer, &[wrap_ix, bury_ix]).await;
|
||||
submit_transaction(rpc, payer, &[wrap_ix, bury_ix]).await?;
|
||||
// simulate_transaction(rpc, payer, &[wrap_ix, bury_ix]).await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -368,6 +371,18 @@ async fn set_fee_collector(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn checkpoint(
|
||||
rpc: &RpcClient,
|
||||
payer: &solana_sdk::signer::keypair::Keypair,
|
||||
) -> Result<(), anyhow::Error> {
|
||||
let authority = std::env::var("AUTHORITY").unwrap_or(payer.pubkey().to_string());
|
||||
let authority = Pubkey::from_str(&authority).expect("Invalid AUTHORITY");
|
||||
let miner = get_miner(rpc, authority).await?;
|
||||
let ix = ore_api::sdk::checkpoint(payer.pubkey(), authority, miner.round_id);
|
||||
submit_transaction(rpc, payer, &[ix]).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn checkpoint_all(
|
||||
rpc: &RpcClient,
|
||||
payer: &solana_sdk::signer::keypair::Keypair,
|
||||
@@ -626,8 +641,14 @@ async fn log_config(rpc: &RpcClient) -> Result<(), anyhow::Error> {
|
||||
let config = get_config(&rpc).await?;
|
||||
println!("Config");
|
||||
println!(" admin: {}", config.admin);
|
||||
println!(" last_boost: {}", config.last_boost);
|
||||
println!(" bury_authority: {}", config.bury_authority);
|
||||
println!(" fee_collector: {}", config.fee_collector);
|
||||
println!(" last_boost: {}", config.last_boost);
|
||||
println!(
|
||||
" is_seeker_activation_enabled: {}",
|
||||
config.is_seeker_activation_enabled
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ pub fn process_bury(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
board_info.as_account_mut::<Board>(&ore_api::ID)?;
|
||||
config_info
|
||||
.as_account::<Config>(&ore_api::ID)?
|
||||
.assert(|c| c.admin == *signer_info.key)?;
|
||||
.assert(|c| c.bury_authority == *signer_info.key)?;
|
||||
mint_info.has_address(&MINT_ADDRESS)?.as_mint()?;
|
||||
let treasury = treasury_info.as_account_mut::<Treasury>(&ore_api::ID)?;
|
||||
let treasury_ore =
|
||||
|
||||
@@ -11,7 +11,7 @@ mod deploy;
|
||||
mod deposit;
|
||||
mod log;
|
||||
// mod migrate_miner;
|
||||
// mod migrate_treasury;
|
||||
mod migrate_treasury;
|
||||
mod reset;
|
||||
mod set_admin;
|
||||
mod set_fee_collector;
|
||||
|
||||
@@ -1,49 +1,46 @@
|
||||
use ore_api::prelude::*;
|
||||
use solana_program::rent::Rent;
|
||||
use solana_program::{pubkey, rent::Rent};
|
||||
use steel::*;
|
||||
|
||||
/// Sets the admin.
|
||||
pub fn process_migrate_treasury(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult {
|
||||
// Load accounts.
|
||||
let [signer_info, config_info, treasury_info, system_program] = accounts else {
|
||||
let [signer_info, config_info, system_program] = accounts else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
};
|
||||
signer_info.is_signer()?;
|
||||
let config = config_info
|
||||
.as_account_mut::<Config>(&ore_api::ID)?
|
||||
.as_account_mut::<ConfigOLD>(&ore_api::ID)?
|
||||
.assert_mut_err(
|
||||
|c| c.admin == *signer_info.key,
|
||||
OreError::NotAuthorized.into(),
|
||||
)?;
|
||||
let treasury = treasury_info.as_account_mut::<TreasuryOLD>(&ore_api::ID)?;
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
|
||||
// Record old values.
|
||||
let balance = treasury.balance;
|
||||
let motherlode = treasury.motherlode;
|
||||
let stake_rewards_factor = treasury.stake_rewards_factor;
|
||||
let total_staked = treasury.total_staked;
|
||||
let total_unclaimed = treasury.total_unclaimed;
|
||||
let miner_rewards_factor = treasury.miner_rewards_factor;
|
||||
let admin = config.admin;
|
||||
let fee_collector = config.fee_collector;
|
||||
let last_boost = config.last_boost;
|
||||
let is_seeker_activation_enabled = config.is_seeker_activation_enabled;
|
||||
|
||||
// Realloc treasury.
|
||||
let new_size = 8 + std::mem::size_of::<Treasury>();
|
||||
let old_size = 8 + std::mem::size_of::<TreasuryOLD>();
|
||||
let new_size = 8 + std::mem::size_of::<Config>();
|
||||
let old_size = 8 + std::mem::size_of::<ConfigOLD>();
|
||||
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)?;
|
||||
config_info.realloc(new_size, false)?;
|
||||
if new_size > old_size {
|
||||
let additional_rent = new_rent.saturating_sub(old_rent);
|
||||
config_info.collect(additional_rent, &signer_info)?;
|
||||
}
|
||||
|
||||
// Update treasury.
|
||||
let treasury = treasury_info.as_account_mut::<Treasury>(&ore_api::ID)?;
|
||||
treasury.balance = balance;
|
||||
treasury.motherlode = motherlode;
|
||||
treasury.stake_rewards_factor = stake_rewards_factor;
|
||||
treasury.total_staked = total_staked;
|
||||
treasury.total_unclaimed = total_unclaimed;
|
||||
treasury.miner_rewards_factor = miner_rewards_factor;
|
||||
treasury.total_refined = 0;
|
||||
// Update config.
|
||||
let config = config_info.as_account_mut::<Config>(&ore_api::ID)?;
|
||||
config.admin = admin;
|
||||
config.fee_collector = fee_collector;
|
||||
config.bury_authority = pubkey!("HNWhK5f8RMWBqcA7mXJPaxdTPGrha3rrqUrri7HSKb3T");
|
||||
config.last_boost = last_boost;
|
||||
config.is_seeker_activation_enabled = is_seeker_activation_enabled;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user