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: allow reward authority to sign for first stake account declaration #521

Merged
merged 3 commits into from
Sep 9, 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
58 changes: 57 additions & 1 deletion staking/integration-tests/tests/set_publisher_stake_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fn test_set_publisher_stake_account() {
None,
stake_account_positions,
),
IntegrityPoolError::PublisherNeedsToSign,
IntegrityPoolError::PublisherOrRewardAuthorityNeedsToSign,
0
);

Expand Down Expand Up @@ -371,3 +371,59 @@ fn test_set_publisher_stake_account() {
assert_eq!(pool_data.self_del_state[i], DelegationState::default());
}
}


#[test]
fn test_set_publisher_stake_account_reward_authority() {
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,
init_mint: true,
init_pool_data: true,
init_publishers: true,
reward_amount_override: None,
});
let publisher_index = maybe_publisher_index.unwrap();

let stake_account_positions =
initialize_new_stake_account(&mut svm, &payer, &pyth_token_mint, true, true);

set_publisher_stake_account(
&mut svm,
&payer,
&reward_program_authority,
publisher_keypair.pubkey(),
None,
stake_account_positions,
)
.unwrap();

let pool_data: PoolData = fetch_account_data_bytemuck(&mut svm, &pool_data_pubkey);

assert_eq!(
pool_data.publisher_stake_accounts[publisher_index],
stake_account_positions,
);

// can't set it once it's set
assert_anchor_program_error!(
set_publisher_stake_account(
&mut svm,
&payer,
&reward_program_authority,
publisher_keypair.pubkey(),
Some(stake_account_positions),
stake_account_positions,
),
IntegrityPoolError::StakeAccountOwnerNeedsToSign,
0
);
}
2 changes: 1 addition & 1 deletion staking/programs/integrity-pool/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use anchor_lang::error_code;
#[error_code]
pub enum IntegrityPoolError {
PublisherNotFound,
PublisherNeedsToSign,
PublisherOrRewardAuthorityNeedsToSign,
StakeAccountOwnerNeedsToSign,
OutdatedPublisherAccounting,
TooManyPublishers,
Expand Down
9 changes: 5 additions & 4 deletions staking/programs/integrity-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ pub mod integrity_pool {
let signer = &ctx.accounts.signer;
let publisher = &ctx.accounts.publisher;
let pool_data = &mut ctx.accounts.pool_data.load_mut()?;
let pool_config = &ctx.accounts.pool_config;
let new_stake_account =
DynamicPositionArray::load(&ctx.accounts.new_stake_account_positions)?;

Expand All @@ -236,10 +237,10 @@ pub mod integrity_pool {
let publisher_index = pool_data.get_publisher_index(publisher.key)?;

if pool_data.publisher_stake_accounts[publisher_index] == Pubkey::default() {
require_eq!(
signer.key(),
publisher.key(),
IntegrityPoolError::PublisherNeedsToSign
require!(
signer.key() == publisher.key()
|| signer.key() == pool_config.reward_program_authority,
IntegrityPoolError::PublisherOrRewardAuthorityNeedsToSign
);
} else if let Some(current_stake_account_positions) =
&ctx.accounts.current_stake_account_positions_option
Expand Down
Loading