-
Notifications
You must be signed in to change notification settings - Fork 2
[LST-343] StartRebalance and EndRebalance instructions #89
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
Changes from 35 commits
83a6135
cb1efa4
b5dc901
836ea0b
46989c4
fccbb75
1d48e33
681eef8
b648c0f
df2154d
8a78892
7f72308
06f836c
85ecfda
d67faf0
335d545
009637a
6635954
d718a5b
d065bbe
aa34443
5eec945
6c48dc2
2aaa4e3
93a95f2
23fafda
3b99c0c
7e2661f
bd20f20
f8db979
ddb899f
12afd90
15cc924
4335c4c
c5befa5
e56a402
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| use core::mem::size_of; | ||
|
|
||
| use crate::internal_utils::{impl_cast_from_acc_data, impl_cast_to_acc_data}; | ||
|
|
||
| #[repr(C)] | ||
| #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | ||
| pub struct RebalanceRecord { | ||
| pub old_total_sol_value: u64, | ||
| pub inp_lst_index: u32, | ||
| pub padding: [u8; 4], | ||
| } | ||
| impl_cast_from_acc_data!(RebalanceRecord); | ||
| impl_cast_to_acc_data!(RebalanceRecord); | ||
|
|
||
| #[repr(C)] | ||
| #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | ||
| pub struct RebalanceRecordPacked { | ||
| old_total_sol_value: [u8; 8], | ||
| inp_lst_index: [u8; 4], | ||
| padding: [u8; 4], | ||
| } | ||
| impl_cast_from_acc_data!(RebalanceRecordPacked, packed); | ||
| impl_cast_to_acc_data!(RebalanceRecordPacked, packed); | ||
|
|
||
| impl RebalanceRecordPacked { | ||
| #[inline] | ||
| pub const fn into_rebalance_record(self) -> RebalanceRecord { | ||
| let Self { | ||
| old_total_sol_value, | ||
| inp_lst_index, | ||
| padding, | ||
| } = self; | ||
| RebalanceRecord { | ||
| old_total_sol_value: u64::from_le_bytes(old_total_sol_value), | ||
| inp_lst_index: u32::from_le_bytes(inp_lst_index), | ||
| padding, | ||
| } | ||
| } | ||
|
|
||
| /// # Safety | ||
| /// - `self` must be pointing to mem that has same align as `RebalanceRecord`. | ||
| /// This is true onchain for a RebalanceRecord account since account data | ||
| /// is always 8-byte aligned onchain. | ||
| #[inline] | ||
| pub const unsafe fn as_rebalance_record(&self) -> &RebalanceRecord { | ||
| &*(self as *const Self).cast() | ||
| } | ||
| } | ||
|
|
||
| impl From<RebalanceRecordPacked> for RebalanceRecord { | ||
| #[inline] | ||
| fn from(value: RebalanceRecordPacked) -> Self { | ||
| value.into_rebalance_record() | ||
| } | ||
| } | ||
|
|
||
| const _ASSERT_PACKED_UNPACKED_SIZES_EQ: () = | ||
| assert!(size_of::<RebalanceRecord>() == size_of::<RebalanceRecordPacked>()); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ use inf1_ctl_core::{ | |
| lst_state_list::{LstStateList, LstStateListMut}, | ||
| packed_list::{PackedList, PackedListMut}, | ||
| pool_state::PoolState, | ||
| rebalance_record::RebalanceRecord, | ||
| }, | ||
| err::Inf1CtlErr, | ||
| typedefs::lst_state::LstState, | ||
|
|
@@ -14,8 +15,6 @@ use crate::program_err::Inf1CtlCustomProgErr; | |
|
|
||
| const _ACC_DATA_ALIGN: usize = 8; | ||
|
|
||
| const _POOL_STATE_ALIGN_CHECK: () = assert!(core::mem::align_of::<PoolState>() <= _ACC_DATA_ALIGN); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. whyd you delete this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. happy little accident |
||
|
|
||
| #[inline] | ||
| pub fn pool_state_checked(acc: &Account) -> Result<&PoolState, Inf1CtlCustomProgErr> { | ||
| // safety: account data is 8-byte aligned | ||
|
|
@@ -105,6 +104,25 @@ pub fn disable_pool_auth_list_checked_mut( | |
| } | ||
| } | ||
|
|
||
| const _REBALANCE_RECORD_ALIGN_CHECK: () = | ||
| assert!(core::mem::align_of::<RebalanceRecord>() <= _ACC_DATA_ALIGN); | ||
|
|
||
| #[inline] | ||
| pub fn rebalance_record_checked(acc: &Account) -> Result<&RebalanceRecord, Inf1CtlCustomProgErr> { | ||
| // safety: account data is 8-byte aligned | ||
| unsafe { RebalanceRecord::of_acc_data(acc.data()) } | ||
| .ok_or(Inf1CtlCustomProgErr(Inf1CtlErr::InvalidRebalanceRecordData)) | ||
| } | ||
|
|
||
| #[inline] | ||
| pub fn rebalance_record_checked_mut( | ||
| acc: &mut Account, | ||
| ) -> Result<&mut RebalanceRecord, Inf1CtlCustomProgErr> { | ||
| // safety: account data is 8-byte aligned | ||
| unsafe { RebalanceRecord::of_acc_data_mut(acc.data_mut()) } | ||
| .ok_or(Inf1CtlCustomProgErr(Inf1CtlErr::InvalidRebalanceRecordData)) | ||
| } | ||
|
|
||
| // TODO: refactor to use this fn everywhere | ||
| #[inline] | ||
| pub fn lst_state_list_get( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.