diff --git a/cli/src/processor/config.rs b/cli/src/processor/config.rs index 5356cfd50..cf0d9733d 100644 --- a/cli/src/processor/config.rs +++ b/cli/src/processor/config.rs @@ -1,7 +1,8 @@ use { crate::errors::CliError, clockwork_client::{ - crank::state::Config as CrankConfig, network::state::Config as NetworkConfig, Client, + crank::state::Config as CrankConfig, network::state::Config as NetworkConfig, + pool::state::Config as PoolConfig, Client, }, solana_sdk::pubkey::Pubkey, }; @@ -19,9 +20,16 @@ pub fn get(client: &Client) -> Result<(), CliError> { .get::(&network_config_pubkey) .map_err(|_err| CliError::AccountNotFound(network_config_pubkey.to_string()))?; + // Get pool config + let pool_config_pubkey = PoolConfig::pubkey(); + let pool_config = client + .get::(&pool_config_pubkey) + .map_err(|_err| CliError::AccountNotFound(pool_config_pubkey.to_string()))?; + // Print configs println!("Crank {:#?}", crank_config); println!("Network {:#?}", network_config); + println!("Pool {:#?}", pool_config); Ok(()) } diff --git a/cli/src/processor/initialize.rs b/cli/src/processor/initialize.rs index b87ed6dbd..f13971c80 100644 --- a/cli/src/processor/initialize.rs +++ b/cli/src/processor/initialize.rs @@ -1,8 +1,6 @@ -use clockwork_client::pool::state::Pool; - use { crate::errors::CliError, - clockwork_client::Client, + clockwork_client::{pool::state::Pool, Client}, solana_sdk::{native_token::LAMPORTS_PER_SOL, pubkey::Pubkey}, }; @@ -16,11 +14,12 @@ pub fn initialize(client: &Client, mint: Pubkey) -> Result<(), CliError> { let ix_a = clockwork_client::crank::instruction::initialize(admin, pool); let ix_b = clockwork_client::http::instruction::initialize(admin); let ix_c = clockwork_client::network::instruction::initialize(admin, mint); - let ix_d = clockwork_client::network::instruction::pool_create(admin, pool_name.into(), 1); + let ix_d = clockwork_client::pool::instruction::initialize(admin); + let ix_e = clockwork_client::network::instruction::pool_create(admin, pool_name.into(), 1); // Submit tx client - .send_and_confirm(&[ix_a, ix_b, ix_c, ix_d], &[client.payer()]) + .send_and_confirm(&[ix_a, ix_b, ix_c, ix_d, ix_e], &[client.payer()]) .unwrap(); // Airdrop some lamports to the network's snapshot queue diff --git a/client/src/network/instruction/pool_create.rs b/client/src/network/instruction/pool_create.rs index deb6f92a0..e02eedc1b 100644 --- a/client/src/network/instruction/pool_create.rs +++ b/client/src/network/instruction/pool_create.rs @@ -14,6 +14,7 @@ pub fn pool_create(admin: Pubkey, name: String, size: usize) -> Instruction { AccountMeta::new_readonly(clockwork_network::state::Config::pubkey(), false), AccountMeta::new(clockwork_pool::state::Pool::pubkey(name.clone()), false), AccountMeta::new_readonly(clockwork_pool::ID, false), + AccountMeta::new_readonly(clockwork_pool::state::Config::pubkey(), false), AccountMeta::new(clockwork_network::state::Rotator::pubkey(), false), AccountMeta::new_readonly(system_program::ID, false), ], diff --git a/client/src/network/instruction/pools_rotate.rs b/client/src/network/instruction/pools_rotate.rs index 1c8d62afa..4fb7a30c8 100644 --- a/client/src/network/instruction/pools_rotate.rs +++ b/client/src/network/instruction/pools_rotate.rs @@ -22,6 +22,7 @@ pub fn pools_rotate( AccountMeta::new_readonly(entry, false), AccountMeta::new_readonly(node, false), AccountMeta::new_readonly(clockwork_pool::ID, false), + AccountMeta::new_readonly(clockwork_pool::state::Config::pubkey(), false), AccountMeta::new(clockwork_network::state::Rotator::pubkey(), false), AccountMeta::new(signer, true), AccountMeta::new_readonly(snapshot, false), diff --git a/client/src/pool/instruction/initialize.rs b/client/src/pool/instruction/initialize.rs new file mode 100644 index 000000000..e2b74eba4 --- /dev/null +++ b/client/src/pool/instruction/initialize.rs @@ -0,0 +1,23 @@ +use anchor_lang::{ + solana_program::{ + instruction::{AccountMeta, Instruction}, + pubkey::Pubkey, + system_program, + }, + InstructionData, +}; + +pub fn initialize(admin: Pubkey) -> Instruction { + let config_pubkey = clockwork_pool::state::Config::pubkey(); + let pool_authority = clockwork_network::state::Rotator::pubkey(); + + Instruction { + program_id: clockwork_pool::ID, + accounts: vec![ + AccountMeta::new(admin, true), + AccountMeta::new(config_pubkey, false), + AccountMeta::new_readonly(system_program::ID, false), + ], + data: clockwork_pool::instruction::Initialize { pool_authority }.data(), + } +} diff --git a/client/src/pool/instruction/mod.rs b/client/src/pool/instruction/mod.rs new file mode 100644 index 000000000..52d32669b --- /dev/null +++ b/client/src/pool/instruction/mod.rs @@ -0,0 +1,3 @@ +mod initialize; + +pub use initialize::*; diff --git a/client/src/pool/mod.rs b/client/src/pool/mod.rs index d4ae1fedf..dffff321d 100644 --- a/client/src/pool/mod.rs +++ b/client/src/pool/mod.rs @@ -1,2 +1,4 @@ +pub mod instruction; + pub use clockwork_pool::state; pub use clockwork_pool::ID; diff --git a/programs/crank/src/instructions/config_update.rs b/programs/crank/src/instructions/config_update.rs index 23393a08e..a145ff0f1 100644 --- a/programs/crank/src/instructions/config_update.rs +++ b/programs/crank/src/instructions/config_update.rs @@ -3,10 +3,10 @@ use {crate::state::*, anchor_lang::prelude::*}; #[derive(Accounts)] #[instruction(settings: ConfigSettings)] pub struct ConfigUpdate<'info> { - #[account(mut, address = config.admin)] + #[account(mut)] pub admin: Signer<'info>, - #[account(mut, seeds = [SEED_CONFIG], bump)] + #[account(mut, seeds = [SEED_CONFIG], bump, has_one = admin)] pub config: Account<'info, Config>, } diff --git a/programs/network/src/errors.rs b/programs/network/src/errors.rs index d55fb89e2..292786fdf 100644 --- a/programs/network/src/errors.rs +++ b/programs/network/src/errors.rs @@ -5,9 +5,6 @@ pub enum ClockworkError { #[msg("This account has already been initialized")] AccountAlreadyInitialized, - #[msg("This instruction requires admin authority")] - AdminAuthorityInvalid, - #[msg("The provided node is cannot be used for this operation")] InvalidNode, diff --git a/programs/network/src/instructions/config_update.rs b/programs/network/src/instructions/config_update.rs new file mode 100644 index 000000000..a145ff0f1 --- /dev/null +++ b/programs/network/src/instructions/config_update.rs @@ -0,0 +1,16 @@ +use {crate::state::*, anchor_lang::prelude::*}; + +#[derive(Accounts)] +#[instruction(settings: ConfigSettings)] +pub struct ConfigUpdate<'info> { + #[account(mut)] + pub admin: Signer<'info>, + + #[account(mut, seeds = [SEED_CONFIG], bump, has_one = admin)] + pub config: Account<'info, Config>, +} + +pub fn handler(ctx: Context, settings: ConfigSettings) -> Result<()> { + let config = &mut ctx.accounts.config; + config.update(settings) +} diff --git a/programs/network/src/instructions/mod.rs b/programs/network/src/instructions/mod.rs index 0fe9cb9f7..e0c817722 100644 --- a/programs/network/src/instructions/mod.rs +++ b/programs/network/src/instructions/mod.rs @@ -1,3 +1,4 @@ +pub mod config_update; pub mod entry_close; pub mod entry_create; pub mod initialize; @@ -14,6 +15,7 @@ pub mod snapshot_pause; pub mod snapshot_resume; pub mod snapshot_rotate; +pub use config_update::*; pub use entry_close::*; pub use entry_create::*; pub use initialize::*; diff --git a/programs/network/src/instructions/pool_create.rs b/programs/network/src/instructions/pool_create.rs index 896d88ccf..b0e15aa6b 100644 --- a/programs/network/src/instructions/pool_create.rs +++ b/programs/network/src/instructions/pool_create.rs @@ -1,7 +1,11 @@ use { crate::state::*, - anchor_lang::{prelude::*, solana_program::system_program, system_program::{transfer, Transfer}}, - clockwork_pool::{program::ClockworkPool, state::SEED_POOL} + anchor_lang::{ + prelude::*, + solana_program::system_program, + system_program::{transfer, Transfer}, + }, + clockwork_pool::{program::ClockworkPool, state::SEED_POOL}, }; #[derive(Accounts)] @@ -13,16 +17,15 @@ pub struct PoolCreate<'info> { #[account(seeds = [SEED_CONFIG], bump, has_one = admin)] pub config: Account<'info, Config>, - #[account( - seeds = [SEED_POOL, name.as_bytes()], - seeds::program = clockwork_pool::ID, - bump, - )] + #[account(seeds = [SEED_POOL, name.as_bytes()], seeds::program = clockwork_pool::ID, bump)] pub pool: SystemAccount<'info>, #[account(address = clockwork_pool::ID)] pub pool_program: Program<'info, ClockworkPool>, + #[account(seeds = [SEED_CONFIG], seeds::program = clockwork_pool::ID, bump)] + pub pool_program_config: Account<'info, clockwork_pool::state::Config>, + #[account(mut, seeds = [SEED_ROTATOR], bump)] pub rotator: Account<'info, Rotator>, @@ -35,6 +38,7 @@ pub fn handler(ctx: Context, name: String, size: usize) -> Result<() let admin = &ctx.accounts.admin; let pool = &ctx.accounts.pool; let pool_program = &ctx.accounts.pool_program; + let pool_program_config = &ctx.accounts.pool_program_config; let rotator = &mut ctx.accounts.rotator; let system_program = &ctx.accounts.system_program; @@ -44,9 +48,10 @@ pub fn handler(ctx: Context, name: String, size: usize) -> Result<() CpiContext::new_with_signer( pool_program.to_account_info(), clockwork_pool::cpi::accounts::PoolCreate { - authority: rotator.to_account_info(), + config: pool_program_config.to_account_info(), payer: admin.to_account_info(), pool: pool.to_account_info(), + pool_authority: rotator.to_account_info(), system_program: system_program.to_account_info(), }, &[&[SEED_ROTATOR, &[rotator_bump]]], diff --git a/programs/network/src/instructions/pools_rotate.rs b/programs/network/src/instructions/pools_rotate.rs index b14fbaabb..ed79276d4 100644 --- a/programs/network/src/instructions/pools_rotate.rs +++ b/programs/network/src/instructions/pools_rotate.rs @@ -25,23 +25,17 @@ pub struct PoolsRotate<'info> { )] pub entry: Account<'info, SnapshotEntry>, - #[account( - seeds = [ - SEED_NODE, - node.id.to_be_bytes().as_ref() - ], - bump, - constraint = node.id == entry.id - )] + #[account(seeds = [SEED_NODE, node.id.to_be_bytes().as_ref()], bump, constraint = node.id == entry.id)] pub node: Account<'info, Node>, #[account(address = clockwork_pool::ID)] pub pool_program: Program<'info, clockwork_pool::program::ClockworkPool>, + #[account(seeds = [SEED_CONFIG], bump, seeds::program = clockwork_pool::ID)] + pub pool_program_config: Account<'info, clockwork_pool::state::Config>, + #[account( - mut, - seeds = [SEED_ROTATOR], - bump, + mut, seeds = [SEED_ROTATOR], bump, constraint = Clock::get().unwrap().slot >= rotator.last_rotation_at.checked_add(config.slots_per_rotation).unwrap() )] pub rotator: Account<'info, Rotator>, @@ -50,11 +44,7 @@ pub struct PoolsRotate<'info> { pub signer: Signer<'info>, #[account( - seeds = [ - SEED_SNAPSHOT, - snapshot.id.to_be_bytes().as_ref() - ], - bump, + seeds = [SEED_SNAPSHOT, snapshot.id.to_be_bytes().as_ref()], bump, constraint = snapshot.status == SnapshotStatus::Current @ ClockworkError::SnapshotNotCurrent )] pub snapshot: Account<'info, Snapshot>, @@ -67,6 +57,7 @@ pub fn handler<'info>(ctx: Context<'_, '_, '_, 'info, PoolsRotate<'info>>) -> Re // Get accounts let node = &ctx.accounts.node; let pool_program = &ctx.accounts.pool_program; + let pool_program_config = &ctx.accounts.pool_program_config; let rotator = &mut ctx.accounts.rotator; let worker = &ctx.accounts.worker; @@ -89,8 +80,9 @@ pub fn handler<'info>(ctx: Context<'_, '_, '_, 'info, PoolsRotate<'info>>) -> Re CpiContext::new_with_signer( pool_program.to_account_info(), PoolRotate { - authority: rotator.to_account_info(), + config: pool_program_config.to_account_info(), pool: pool_acc_info.clone(), + pool_authority: rotator.to_account_info(), worker: worker.to_account_info(), }, &[&[SEED_ROTATOR, &[rotator_bump]]], diff --git a/programs/network/src/lib.rs b/programs/network/src/lib.rs index 66679aba2..cf30c6fbb 100644 --- a/programs/network/src/lib.rs +++ b/programs/network/src/lib.rs @@ -15,6 +15,10 @@ use state::*; pub mod clockwork_network { use super::*; + pub fn config_update(ctx: Context, settings: ConfigSettings) -> Result<()> { + config_update::handler(ctx, settings) + } + pub fn entry_close(ctx: Context) -> Result { entry_close::handler(ctx) } diff --git a/programs/network/src/state/config.rs b/programs/network/src/state/config.rs index 1f3991240..01710a7cb 100644 --- a/programs/network/src/state/config.rs +++ b/programs/network/src/state/config.rs @@ -1,5 +1,4 @@ use { - crate::errors::ClockworkError, anchor_lang::{prelude::*, AnchorDeserialize}, std::convert::TryFrom, }; @@ -51,7 +50,7 @@ pub struct ConfigSettings { pub trait ConfigAccount { fn init(&mut self, admin: Pubkey, mint: Pubkey) -> Result<()>; - fn update(&mut self, admin: &Signer, settings: ConfigSettings) -> Result<()>; + fn update(&mut self, settings: ConfigSettings) -> Result<()>; } impl ConfigAccount for Account<'_, Config> { @@ -62,12 +61,10 @@ impl ConfigAccount for Account<'_, Config> { Ok(()) } - fn update(&mut self, admin: &Signer, settings: ConfigSettings) -> Result<()> { - require!( - self.admin == admin.key(), - ClockworkError::AdminAuthorityInvalid - ); + fn update(&mut self, settings: ConfigSettings) -> Result<()> { self.admin = settings.admin; + self.mint = settings.mint; + self.slots_per_rotation = settings.slots_per_rotation; Ok(()) } } diff --git a/programs/pool/src/instructions/config_update.rs b/programs/pool/src/instructions/config_update.rs new file mode 100644 index 000000000..a145ff0f1 --- /dev/null +++ b/programs/pool/src/instructions/config_update.rs @@ -0,0 +1,16 @@ +use {crate::state::*, anchor_lang::prelude::*}; + +#[derive(Accounts)] +#[instruction(settings: ConfigSettings)] +pub struct ConfigUpdate<'info> { + #[account(mut)] + pub admin: Signer<'info>, + + #[account(mut, seeds = [SEED_CONFIG], bump, has_one = admin)] + pub config: Account<'info, Config>, +} + +pub fn handler(ctx: Context, settings: ConfigSettings) -> Result<()> { + let config = &mut ctx.accounts.config; + config.update(settings) +} diff --git a/programs/pool/src/instructions/initialize.rs b/programs/pool/src/instructions/initialize.rs new file mode 100644 index 000000000..77fb7be54 --- /dev/null +++ b/programs/pool/src/instructions/initialize.rs @@ -0,0 +1,33 @@ +use { + crate::state::*, + anchor_lang::{prelude::*, solana_program::system_program}, + std::mem::size_of, +}; + +#[derive(Accounts)] +#[instruction(pool_authority: Pubkey)] +pub struct Initialize<'info> { + #[account(mut)] + pub admin: Signer<'info>, + + #[account( + init, + seeds = [SEED_CONFIG], + bump, + payer = admin, + space = 8 + size_of::(), + )] + pub config: Account<'info, Config>, + + #[account(address = system_program::ID)] + pub system_program: Program<'info, System>, +} + +pub fn handler(ctx: Context, pool_authority: Pubkey) -> Result<()> { + let admin = &ctx.accounts.admin; + let config = &mut ctx.accounts.config; + + config.init(admin.key(), pool_authority)?; + + Ok(()) +} diff --git a/programs/pool/src/instructions/mod.rs b/programs/pool/src/instructions/mod.rs index 0cf51549f..7c17964ac 100644 --- a/programs/pool/src/instructions/mod.rs +++ b/programs/pool/src/instructions/mod.rs @@ -1,7 +1,11 @@ +pub mod config_update; +pub mod initialize; pub mod pool_create; pub mod pool_rotate; pub mod pool_update; +pub use config_update::*; +pub use initialize::*; pub use pool_create::*; pub use pool_rotate::*; pub use pool_update::*; diff --git a/programs/pool/src/instructions/pool_create.rs b/programs/pool/src/instructions/pool_create.rs index d63a5906e..fa0053a8e 100644 --- a/programs/pool/src/instructions/pool_create.rs +++ b/programs/pool/src/instructions/pool_create.rs @@ -7,9 +7,8 @@ use { #[derive(Accounts)] #[instruction(name: String, size: usize)] pub struct PoolCreate<'info> { - // TODO Verify this signer is a Clockwork network program PDA - #[account()] - pub authority: Signer<'info>, + #[account(seeds = [SEED_CONFIG], bump, has_one = pool_authority)] + pub config: Account<'info, Config>, #[account(mut)] pub payer: Signer<'info>, @@ -23,17 +22,19 @@ pub struct PoolCreate<'info> { )] pub pool: Account<'info, Pool>, + #[account()] + pub pool_authority: Signer<'info>, + #[account(address = system_program::ID)] pub system_program: Program<'info, System>, } pub fn handler(ctx: Context, name: String, size: usize) -> Result<()> { // Get accounts - let authority = &ctx.accounts.authority; let pool = &mut ctx.accounts.pool; // Initialize the pool - pool.init(authority.key(), name, size)?; + pool.init(name, size)?; Ok(()) } diff --git a/programs/pool/src/instructions/pool_rotate.rs b/programs/pool/src/instructions/pool_rotate.rs index 601e94c3d..157a70fdf 100644 --- a/programs/pool/src/instructions/pool_rotate.rs +++ b/programs/pool/src/instructions/pool_rotate.rs @@ -2,12 +2,15 @@ use {crate::state::*, anchor_lang::prelude::*}; #[derive(Accounts)] pub struct PoolRotate<'info> { - #[account(address = pool.authority)] - pub authority: Signer<'info>, + #[account(seeds = [SEED_CONFIG], bump, has_one = pool_authority)] + pub config: Account<'info, Config>, #[account(mut, seeds = [SEED_POOL, pool.name.as_bytes()], bump)] pub pool: Account<'info, Pool>, + #[account()] + pub pool_authority: Signer<'info>, + #[account()] pub worker: SystemAccount<'info>, } diff --git a/programs/pool/src/instructions/pool_update.rs b/programs/pool/src/instructions/pool_update.rs index bbff948eb..03df6dd0c 100644 --- a/programs/pool/src/instructions/pool_update.rs +++ b/programs/pool/src/instructions/pool_update.rs @@ -1,30 +1,35 @@ use { crate::state::*, - anchor_lang::{prelude::*, system_program::{transfer, Transfer}, solana_program::system_program}, - std::mem::size_of + anchor_lang::{ + prelude::*, + solana_program::system_program, + system_program::{transfer, Transfer}, + }, + std::mem::size_of, }; #[derive(Accounts)] #[instruction(settings: PoolSettings)] pub struct PoolUpdate<'info> { + #[account(seeds = [SEED_CONFIG], bump, has_one = pool_authority)] + pub config: Account<'info, Config>, + #[account(mut)] - pub authority: Signer<'info>, - - #[account( - mut, - seeds = [SEED_POOL, pool.name.as_bytes()], - bump, - has_one = authority - )] + pub payer: Signer<'info>, + + #[account(mut, seeds = [SEED_POOL, pool.name.as_bytes()], bump)] pub pool: Account<'info, Pool>, + #[account()] + pub pool_authority: Signer<'info>, + #[account(address = system_program::ID)] pub system_program: Program<'info, System>, } pub fn handler(ctx: Context, settings: PoolSettings) -> Result<()> { // Get accounts - let authority = &ctx.accounts.authority; + let payer = &ctx.accounts.payer; let pool = &mut ctx.accounts.pool; let system_program = &ctx.accounts.system_program; @@ -32,25 +37,25 @@ pub fn handler(ctx: Context, settings: PoolSettings) -> Result<()> { pool.update(&settings)?; // Reallocate memory for the pool account - let data_len = 8 + size_of::() + settings.size.checked_mul(size_of::()).unwrap(); + let data_len = 8 + size_of::() + settings.size.checked_mul(size_of::()).unwrap(); pool.to_account_info().realloc(data_len, false)?; - // If lamports are required to maintain rent-exemption, pay them - let minimum_rent = Rent::get().unwrap().minimum_balance(data_len); - if minimum_rent > pool.to_account_info().lamports() { - transfer( - CpiContext::new( - system_program.to_account_info(), - Transfer { - from: authority.to_account_info(), - to: pool.to_account_info(), - }, - ), - minimum_rent - .checked_sub(pool.to_account_info().lamports()) - .unwrap(), - )?; - } + // If lamports are required to maintain rent-exemption, pay them + let minimum_rent = Rent::get().unwrap().minimum_balance(data_len); + if minimum_rent > pool.to_account_info().lamports() { + transfer( + CpiContext::new( + system_program.to_account_info(), + Transfer { + from: payer.to_account_info(), + to: pool.to_account_info(), + }, + ), + minimum_rent + .checked_sub(pool.to_account_info().lamports()) + .unwrap(), + )?; + } Ok(()) } diff --git a/programs/pool/src/lib.rs b/programs/pool/src/lib.rs index c9fce9ccb..0ed1057e9 100644 --- a/programs/pool/src/lib.rs +++ b/programs/pool/src/lib.rs @@ -10,12 +10,18 @@ use anchor_lang::prelude::*; use instructions::*; use state::*; -// TODO Create config to hold onto network program ID (make configurable in case we need to cutover to new network program) - #[program] pub mod clockwork_pool { use super::*; + pub fn config_update(ctx: Context, settings: ConfigSettings) -> Result<()> { + config_update::handler(ctx, settings) + } + + pub fn initialize(ctx: Context, pool_authority: Pubkey) -> Result<()> { + initialize::handler(ctx, pool_authority) + } + pub fn pool_create(ctx: Context, name: String, size: usize) -> Result<()> { pool_create::handler(ctx, name, size) } diff --git a/programs/pool/src/state/config.rs b/programs/pool/src/state/config.rs new file mode 100644 index 000000000..6905b4861 --- /dev/null +++ b/programs/pool/src/state/config.rs @@ -0,0 +1,61 @@ +use anchor_lang::{prelude::*, AnchorDeserialize}; + +pub const SEED_CONFIG: &[u8] = b"config"; + +/** + * Config + */ + +#[account] +#[derive(Debug)] +pub struct Config { + pub admin: Pubkey, + pub pool_authority: Pubkey, +} + +impl Config { + pub fn pubkey() -> Pubkey { + Pubkey::find_program_address(&[SEED_CONFIG], &crate::ID).0 + } +} + +impl TryFrom> for Config { + type Error = Error; + fn try_from(data: Vec) -> std::result::Result { + Config::try_deserialize(&mut data.as_slice()) + } +} + +/** + * ConfigSettings + */ + +#[derive(AnchorSerialize, AnchorDeserialize)] +pub struct ConfigSettings { + pub admin: Pubkey, + pub pool_authority: Pubkey, +} + +/** + * ConfigAccount + */ + +pub trait ConfigAccount { + fn init(&mut self, admin: Pubkey, pool_authority: Pubkey) -> Result<()>; + + fn update(&mut self, settings: ConfigSettings) -> Result<()>; +} + +impl ConfigAccount for Account<'_, Config> { + fn init(&mut self, admin: Pubkey, pool_authority: Pubkey) -> Result<()> { + self.admin = admin; + self.pool_authority = pool_authority; + Ok(()) + } + + fn update(&mut self, settings: ConfigSettings) -> Result<()> { + self.admin = settings.admin; + self.pool_authority = settings.pool_authority; + Ok(()) + } +} diff --git a/programs/pool/src/state/mod.rs b/programs/pool/src/state/mod.rs index cb76c244c..8f86e1e2f 100644 --- a/programs/pool/src/state/mod.rs +++ b/programs/pool/src/state/mod.rs @@ -1,3 +1,5 @@ +mod config; mod pool; +pub use config::*; pub use pool::*; diff --git a/programs/pool/src/state/pool.rs b/programs/pool/src/state/pool.rs index 28fda8394..edfb3ea8f 100644 --- a/programs/pool/src/state/pool.rs +++ b/programs/pool/src/state/pool.rs @@ -12,7 +12,6 @@ pub const SEED_POOL: &[u8] = b"pool"; #[account] #[derive(Debug)] pub struct Pool { - pub authority: Pubkey, pub name: String, pub size: usize, pub workers: VecDeque, @@ -37,7 +36,6 @@ impl TryFrom> for Pool { #[derive(AnchorSerialize, AnchorDeserialize)] pub struct PoolSettings { - pub authority: Pubkey, pub size: usize, } @@ -46,7 +44,7 @@ pub struct PoolSettings { */ pub trait PoolAccount { - fn init(&mut self, authority: Pubkey, name: String, size: usize) -> Result<()>; + fn init(&mut self, name: String, size: usize) -> Result<()>; fn rotate(&mut self, worker: Pubkey) -> Result<()>; @@ -54,8 +52,7 @@ pub trait PoolAccount { } impl PoolAccount for Account<'_, Pool> { - fn init(&mut self, authority: Pubkey, name: String, size: usize) -> Result<()> { - self.authority = authority; + fn init(&mut self, name: String, size: usize) -> Result<()> { self.name = name; self.size = size; self.workers = VecDeque::new(); @@ -78,7 +75,6 @@ impl PoolAccount for Account<'_, Pool> { } fn update(&mut self, settings: &PoolSettings) -> Result<()> { - self.authority = settings.authority; self.size = settings.size; Ok(()) }