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: add a limit to y #509

Merged
merged 4 commits into from
Aug 29, 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
4 changes: 2 additions & 2 deletions staking/integration-tests/src/utils/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ use integrity_pool::utils::types::{
// 100 PYTH tokens
pub const STAKED_TOKENS: frac64 = 100 * FRAC_64_MULTIPLIER;

// 10% yield per epoch
pub const YIELD: frac64 = FRAC_64_MULTIPLIER / 10;
// 1% yield per epoch
pub const YIELD: frac64 = FRAC_64_MULTIPLIER / 100;
12 changes: 12 additions & 0 deletions staking/integration-tests/tests/initialize_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use {
integrity_pool::{
error::IntegrityPoolError,
state::pool::PoolConfig,
utils::types::FRAC_64_MULTIPLIER,
},
solana_sdk::{
program_error::ProgramError,
Expand Down Expand Up @@ -101,4 +102,15 @@ fn test_update_y() {
IntegrityPoolError::InvalidRewardProgramAuthority,
0
);

assert_anchor_program_error!(
update_y(
&mut svm,
&payer,
&reward_program_authority,
FRAC_64_MULTIPLIER / 100 + 1
),
IntegrityPoolError::InvalidY,
0
);
}
2 changes: 2 additions & 0 deletions staking/programs/integrity-pool/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ pub enum IntegrityPoolError {
#[msg("Delegation fee must not be greater than 100%")]
InvalidDelegationFee,
InvalidPublisher,
#[msg("Y should not be greater than 1%")]
InvalidY,
}
4 changes: 4 additions & 0 deletions staking/programs/integrity-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub mod integrity_pool {
pyth_token_mint: Pubkey,
y: frac64,
) -> Result<()> {
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;
Expand All @@ -49,6 +51,8 @@ pub mod integrity_pool {
}

pub fn update_y(ctx: Context<UpdateY>, y: frac64) -> Result<()> {
require_gte!(FRAC_64_MULTIPLIER / 100, y, IntegrityPoolError::InvalidY);

ctx.accounts.pool_config.y = y;
Ok(())
}
Expand Down
Loading