Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: read pyth token mint from staking program in initialize pool #518

Merged
merged 4 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions staking/integration-tests/src/integrity_pool/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ pub fn create_pool_data_account(
payer: &Keypair,
pool_data_keypair: &Keypair,
reward_program_authority: Pubkey,
pyth_token_mint: Pubkey,
) -> TransactionResult {
let pool_data_space: u64 = PoolData::LEN.try_into().unwrap();
let global_config = get_config_address();

let rent = svm.minimum_balance_for_rent_exemption(pool_data_space.try_into().unwrap());

Expand All @@ -107,7 +107,6 @@ pub fn create_pool_data_account(
let pool_config_pubkey = get_pool_config_address();

let initialize_pool_data = integrity_pool::instruction::InitializePool {
pyth_token_mint,
reward_program_authority,
y: YIELD,
};
Expand All @@ -116,6 +115,7 @@ pub fn create_pool_data_account(
payer: payer.pubkey(),
pool_data: pool_data_keypair.pubkey(),
pool_config: pool_config_pubkey,
config_account: global_config,
system_program: system_program::ID,
};

Expand All @@ -132,7 +132,7 @@ pub fn create_pool_data_account(
svm.latest_blockhash(),
);

svm.send_transaction(initialize_pool_tx.clone())
svm.send_transaction(initialize_pool_tx)
}

pub fn update_y(
Expand Down Expand Up @@ -164,7 +164,7 @@ pub fn update_y(
svm.latest_blockhash(),
);

svm.send_transaction(update_y_tx.clone())
svm.send_transaction(update_y_tx)
}

pub fn update_reward_program_authority(
Expand Down Expand Up @@ -233,7 +233,7 @@ pub fn update_delegation_fee(
svm.latest_blockhash(),
);

svm.send_transaction(update_delegation_fee_tx.clone())
svm.send_transaction(update_delegation_fee_tx)
}


Expand Down
1 change: 0 additions & 1 deletion staking/integration-tests/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ pub fn setup(props: SetupProps) -> SetupResult {
&payer,
&pool_data_keypair,
reward_program_authority.pubkey(),
pyth_token_mint.pubkey(),
)
.unwrap();
}
Expand Down
14 changes: 3 additions & 11 deletions staking/integration-tests/tests/initialize_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,8 @@ fn initialize_pool() {
let SetupResult {
mut svm,
payer,
pyth_token_mint,
publisher_keypair: _,
pool_data_pubkey,
reward_program_authority: _,
maybe_publisher_index: _,
..
} = setup(SetupProps {
init_config: true,
init_target: true,
Expand All @@ -58,13 +55,8 @@ fn initialize_pool() {

// Trying to initialize the pool again should fail
let pool_data2_keypair = Keypair::new();
let initialize_pool_2_res = create_pool_data_account(
&mut svm,
&payer,
&pool_data2_keypair,
Pubkey::new_unique(),
pyth_token_mint.pubkey(),
);
let initialize_pool_2_res =
create_pool_data_account(&mut svm, &payer, &pool_data2_keypair, Pubkey::new_unique());
assert_anchor_program_error!(initialize_pool_2_res, ProgramError::Custom(0), 1);
}

Expand Down
7 changes: 7 additions & 0 deletions staking/programs/integrity-pool/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ pub struct InitializePool<'info> {
#[account(mut)]
pub payer: Signer<'info>,

#[account(
seeds = [staking::context::CONFIG_SEED.as_bytes()],
bump,
seeds::program = staking::ID,
)]
pub config_account: Account<'info, staking::state::global_config::GlobalConfig>,

#[account(zero)]
pub pool_data: AccountLoader<'info, PoolData>,

Expand Down
7 changes: 4 additions & 3 deletions staking/programs/integrity-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@ pub mod integrity_pool {
pub fn initialize_pool(
ctx: Context<InitializePool>,
reward_program_authority: Pubkey,
pyth_token_mint: Pubkey,
y: frac64,
) -> Result<()> {
let global_config = &ctx.accounts.config_account;
let pool_config = &mut ctx.accounts.pool_config;

require_gte!(FRAC_64_MULTIPLIER / 100, y, IntegrityPoolError::InvalidY);

let pool_config = &mut ctx.accounts.pool_config;
pool_config.pool_data = ctx.accounts.pool_data.key();
pool_config.reward_program_authority = reward_program_authority;
pool_config.pyth_token_mint = pyth_token_mint;
pool_config.pyth_token_mint = global_config.pyth_token_mint;
pool_config.y = y;

let mut pool_data = ctx.accounts.pool_data.load_init()?;
Expand Down
Loading