-
Notifications
You must be signed in to change notification settings - Fork 2
[LST-408] setRps
#146
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
Merged
Merged
[LST-408] setRps
#146
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a12f586
feat: add setrps impl
jereldlimjy 4776c91
feat: add rebal and disabled check
jereldlimjy 09c9a21
feat: add basic test
jereldlimjy f8b2d4c
feat: add proptests
jereldlimjy 4a30c39
chore: refactor lookahead
jereldlimjy ad96439
fix: review comments
jereldlimjy e8707ba
fix: update withdrawprotocolfee
jereldlimjy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| pub mod set_rps; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| use generic_array_struct::generic_array_struct; | ||
|
|
||
| use crate::instructions::internal_utils::caba; | ||
|
|
||
| // Accounts | ||
|
|
||
| #[generic_array_struct(builder pub)] | ||
| #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)] | ||
| #[repr(transparent)] | ||
| pub struct SetRpsIxAccs<T> { | ||
| /// The pool's state singleton PDA | ||
| pub pool_state: T, | ||
|
|
||
| /// The pool's RPS authority | ||
| pub rps_auth: T, | ||
| } | ||
|
|
||
| impl<T: Copy> SetRpsIxAccs<T> { | ||
| #[inline] | ||
| pub const fn memset(val: T) -> Self { | ||
| Self([val; SET_RPS_IX_ACCS_LEN]) | ||
| } | ||
| } | ||
|
|
||
| pub type SetRpsIxKeys<'a> = SetRpsIxAccs<&'a [u8; 32]>; | ||
|
|
||
| pub type SetRpsIxKeysOwned = SetRpsIxAccs<[u8; 32]>; | ||
|
|
||
| pub type SetRpsIxAccFlags = SetRpsIxAccs<bool>; | ||
|
|
||
| pub const SET_RPS_IX_IS_WRITER: SetRpsIxAccFlags = | ||
| SetRpsIxAccFlags::memset(false).const_with_pool_state(true); | ||
|
|
||
| pub const SET_RPS_IX_IS_SIGNER: SetRpsIxAccFlags = | ||
| SetRpsIxAccFlags::memset(false).const_with_rps_auth(true); | ||
|
|
||
| // Data | ||
|
|
||
| pub const SET_RPS_IX_DISCM: u8 = 26; | ||
|
|
||
| pub const SET_RPS_IX_DATA_LEN: usize = 9; | ||
|
|
||
| #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
| #[repr(transparent)] | ||
| pub struct SetRpsIxData([u8; SET_RPS_IX_DATA_LEN]); | ||
|
|
||
| impl SetRpsIxData { | ||
| #[inline] | ||
| pub const fn new(rps: u64) -> Self { | ||
| const A: usize = SET_RPS_IX_DATA_LEN; | ||
|
|
||
| let mut d = [0u8; A]; | ||
|
|
||
| d = caba::<A, 0, 1>(d, &[SET_RPS_IX_DISCM]); | ||
| d = caba::<A, 1, 8>(d, &rps.to_le_bytes()); | ||
|
|
||
| Self(d) | ||
| } | ||
|
|
||
| #[inline] | ||
| pub const fn as_buf(&self) -> &[u8; SET_RPS_IX_DATA_LEN] { | ||
| &self.0 | ||
| } | ||
|
|
||
| /// Returns `rps` arg, the new RPS to set to | ||
| #[inline] | ||
| pub const fn parse_no_discm(data: &[u8; 8]) -> u64 { | ||
| u64::from_le_bytes(*data) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| pub mod set_rps; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| use inf1_ctl_jiminy::{ | ||
| account_utils::{pool_state_v2_checked, pool_state_v2_checked_mut}, | ||
| instructions::rps::set_rps::{ | ||
| NewSetRpsIxAccsBuilder, SetRpsIxAccs, SetRpsIxData, SET_RPS_IX_IS_SIGNER, | ||
| }, | ||
| keys::POOL_STATE_ID, | ||
| program_err::Inf1CtlCustomProgErr, | ||
| typedefs::{rps::Rps, uq0f63::UQ0F63}, | ||
| }; | ||
| use jiminy_cpi::{ | ||
| account::{Abr, AccountHandle}, | ||
| program_error::{ProgramError, INVALID_INSTRUCTION_DATA, NOT_ENOUGH_ACCOUNT_KEYS}, | ||
| }; | ||
| use jiminy_sysvar_clock::Clock; | ||
|
|
||
| use crate::verify::{verify_not_rebalancing_and_not_disabled, verify_pks, verify_signers}; | ||
|
|
||
| type SetRpsIxAccounts<'acc> = SetRpsIxAccs<AccountHandle<'acc>>; | ||
|
|
||
| #[inline] | ||
| pub fn set_rps_checked<'acc>( | ||
| abr: &mut Abr, | ||
| accs: &[AccountHandle<'acc>], | ||
| ix_data_no_discm: &[u8], | ||
| ) -> Result<(SetRpsIxAccounts<'acc>, u64), ProgramError> { | ||
| let accs = accs.first_chunk().ok_or(NOT_ENOUGH_ACCOUNT_KEYS)?; | ||
| let accs = SetRpsIxAccs(*accs); | ||
|
|
||
| let data: &[u8; 8] = ix_data_no_discm | ||
| .try_into() | ||
| .map_err(|_| INVALID_INSTRUCTION_DATA)?; | ||
| let new_rps_raw = SetRpsIxData::parse_no_discm(data); | ||
|
|
||
| // Validate raw RPS value | ||
| let uq = UQ0F63::new(new_rps_raw).map_err(|_| INVALID_INSTRUCTION_DATA)?; | ||
| let _new_rps = Rps::new(uq).map_err(|_| INVALID_INSTRUCTION_DATA)?; | ||
jereldlimjy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| let pool = pool_state_v2_checked(abr.get(*accs.pool_state()))?; | ||
|
|
||
| let expected_pks = NewSetRpsIxAccsBuilder::start() | ||
| .with_pool_state(&POOL_STATE_ID) | ||
| .with_rps_auth(&pool.rps_authority) | ||
| .build(); | ||
| verify_pks(abr, &accs.0, &expected_pks.0)?; | ||
|
|
||
| verify_signers(abr, &accs.0, &SET_RPS_IX_IS_SIGNER.0)?; | ||
|
|
||
| verify_not_rebalancing_and_not_disabled(pool)?; | ||
|
|
||
| Ok((accs, new_rps_raw)) | ||
| } | ||
|
|
||
| #[inline] | ||
| pub fn process_set_rps( | ||
| abr: &mut Abr, | ||
| accs: &SetRpsIxAccounts, | ||
| new_rps: u64, | ||
| clock: &Clock, | ||
| ) -> Result<(), ProgramError> { | ||
| let pool = pool_state_v2_checked_mut(abr.get_mut(*accs.pool_state()))?; | ||
| pool.release_yield(clock.slot) | ||
| .map_err(Inf1CtlCustomProgErr)?; | ||
|
|
||
| pool.rps = new_rps; | ||
|
|
||
| Ok(()) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| pub mod set_rps; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.