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 2 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
38 changes: 35 additions & 3 deletions staking/integration-tests/src/integrity_pool/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,39 @@ pub fn update_y(
svm.latest_blockhash(),
);

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

pub fn update_pyth_token_mint(
svm: &mut litesvm::LiteSVM,
payer: &Keypair,
reward_program_authority: &Keypair,
pyth_token_mint: Pubkey,
) -> TransactionResult {
let pool_config_pubkey = get_pool_config_address();

let instruction_data = integrity_pool::instruction::UpdatePythTokenMint { pyth_token_mint };

let instruction_accs = integrity_pool::accounts::UpdatePythTokenMint {
pool_config: pool_config_pubkey,
reward_program_authority: reward_program_authority.pubkey(),
system_program: system_program::ID,
};

let instruction = Instruction::new_with_bytes(
integrity_pool::ID,
&instruction_data.data(),
instruction_accs.to_account_metas(None),
);

let transaction = Transaction::new_signed_with_payer(
&[instruction],
Some(&payer.pubkey()),
&[payer, reward_program_authority],
svm.latest_blockhash(),
);

svm.send_transaction(transaction)
}

pub fn update_delegation_fee(
Expand Down Expand Up @@ -199,7 +231,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
39 changes: 39 additions & 0 deletions staking/integration-tests/tests/initialize_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use {
integrity_pool::{
instructions::{
create_pool_data_account,
update_pyth_token_mint,
update_y,
},
pda::get_pool_config_address,
Expand Down Expand Up @@ -116,3 +117,41 @@ fn test_update_y() {
0
);
}

#[test]
fn test_update_pyth_token_mint() {
let SetupResult {
mut svm,
payer,
pyth_token_mint,
reward_program_authority,
..
} = setup(SetupProps {
init_config: true,
init_target: true,
init_mint: true,
init_pool_data: true,
init_publishers: true,
reward_amount_override: None,
});

let pool_config_pubkey = get_pool_config_address();
let pool_config: PoolConfig = fetch_account_data(&mut svm, &pool_config_pubkey);

assert!(pool_config.pyth_token_mint == pyth_token_mint.pubkey());

let new_mint = Pubkey::new_unique();
update_pyth_token_mint(&mut svm, &payer, &reward_program_authority, new_mint).unwrap();

let pool_config: PoolConfig = fetch_account_data(&mut svm, &pool_config_pubkey);
assert!(pool_config.pyth_token_mint == new_mint);

// Trying to update the pyth token mint without the correct authority should fail
let wrong_authority = Keypair::new();

assert_anchor_program_error!(
update_pyth_token_mint(&mut svm, &payer, &wrong_authority, new_mint),
IntegrityPoolError::InvalidRewardProgramAuthority,
0
);
}
15 changes: 15 additions & 0 deletions staking/programs/integrity-pool/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ pub struct UpdateY<'info> {
pub system_program: Program<'info, System>,
}

#[derive(Accounts)]
pub struct UpdatePythTokenMint<'info> {
pub reward_program_authority: Signer<'info>,

#[account(
mut,
seeds = [POOL_CONFIG.as_bytes()],
bump,
has_one = reward_program_authority @ IntegrityPoolError::InvalidRewardProgramAuthority,
)]
pub pool_config: Account<'info, PoolConfig>,

pub system_program: Program<'info, System>,
}

#[derive(Accounts)]
pub struct UpdateDelegationFee<'info> {
pub reward_program_authority: Signer<'info>,
Expand Down
8 changes: 8 additions & 0 deletions staking/programs/integrity-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ pub mod integrity_pool {
Ok(())
}

pub fn update_pyth_token_mint(
ctx: Context<UpdatePythTokenMint>,
pyth_token_mint: Pubkey,
) -> Result<()> {
ctx.accounts.pool_config.pyth_token_mint = pyth_token_mint;
Ok(())
}

pub fn update_delegation_fee(
ctx: Context<UpdateDelegationFee>,
delegation_fee: frac64,
Expand Down
Loading