Skip to content
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
83a6135
StartRebalance and EndRebalance ixs jiminy implementation
Johnnycus Oct 30, 2025
cb1efa4
cargo fmt
Johnnycus Oct 30, 2025
b5dc901
fix warning
Johnnycus Oct 30, 2025
836ea0b
remove system_program from end_rebalance and use SYS_PROG_ID const
Johnnycus Oct 31, 2025
46989c4
use csba to parse start_rebalance args
Johnnycus Oct 31, 2025
fccbb75
remove redundant validation checks
Johnnycus Nov 2, 2025
1d48e33
combine two verify_pks in start_rebalnce ix into one array based call
Johnnycus Nov 2, 2025
681eef8
realloc after assign and transfer in start_rebalance ix
Johnnycus Nov 2, 2025
b648c0f
move get_token_account_amount to a util file
Johnnycus Nov 2, 2025
df2154d
simplify verify_end_rebalance_exists fn
Johnnycus Nov 2, 2025
8a78892
use jiminy-sysvar-instructions to verify endrebalance exists after st…
Johnnycus Nov 2, 2025
7f72308
cargo fmt
Johnnycus Nov 2, 2025
06f836c
use .close() at the end of end_rebalance ix
Johnnycus Nov 2, 2025
85ecfda
simplify verify_end_rebalance_exists()
Johnnycus Nov 2, 2025
d67faf0
write tests for startrebalance and endrebalance instructions
Johnnycus Nov 3, 2025
335d545
ci
Johnnycus Nov 3, 2025
009637a
ci
Johnnycus Nov 3, 2025
6635954
use iinpt instead of dst and imports when possible
Johnnycus Nov 4, 2025
d718a5b
Merge branch 'master' into lst-343-inf1-jiminy-reimpl-startrebalance-…
Johnnycus Nov 4, 2025
d065bbe
read pool state using pool_state_checked()
Johnnycus Nov 4, 2025
aa34443
refactor start_rebalance test fns and arguments
Johnnycus Nov 4, 2025
5eec945
remove start/end err to programerr mapping
Johnnycus Nov 4, 2025
6c48dc2
review fixes
Johnnycus Nov 5, 2025
2aaa4e3
create rebalance_transaction test that tests rebalance ixs chain
Johnnycus Nov 5, 2025
93a95f2
reorg rebalance ixs and tests
Johnnycus Nov 5, 2025
23fafda
assert lamports are balanced properly
Johnnycus Nov 5, 2025
3b99c0c
Merge branch 'master' into lst-343-inf1-jiminy-reimpl-startrebalance-…
Johnnycus Nov 5, 2025
7e2661f
reduce clutter
Johnnycus Nov 5, 2025
bd20f20
better tests for rebalance chain
Johnnycus Nov 6, 2025
f8db979
Merge branch 'master' into lst-343-inf1-jiminy-reimpl-startrebalance-…
Johnnycus Nov 6, 2025
ddb899f
Merge branch 'master' into lst-343-inf1-jiminy-reimpl-startrebalance-…
Johnnycus Nov 7, 2025
12afd90
cleanup pdasigners for rebalance record and fix endrebalanceixdata use
Johnnycus Nov 7, 2025
15cc924
remove isolated start/end rebalance tests
Johnnycus Nov 7, 2025
4335c4c
add already rebalancing and unauthorized auth rebalance test cases
Johnnycus Nov 7, 2025
c5befa5
cleanup
Johnnycus Nov 7, 2025
e56a402
restore _POOL_STATE_ALIGN_CHECK
Johnnycus Nov 7, 2025
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
35 changes: 25 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ mollusk-svm-programs-token = { version = "^0.5", default-features = false }
solana-account = { version = "^2.2.1", default-features = false } # vers constraint based on solana-sdk subdep
solana-account-decoder-client-types = { version = "^2", default-features = false }
solana-instruction = { version = "^2.3.0", default-features = false } # vers constraint based on solana-sdk subdep
solana-instructions-sysvar = { version = "^2.2.1", default-features = false }
solana-logger = { version = "^2.3", default-features = false }
solana-program-error = { version = "^2.2", default-features = false }
solana-pubkey = { version = "^2.2.1", default-features = false } # vers constraint based on solana-sdk subdep
Expand All @@ -87,6 +88,7 @@ jiminy-log = { git = "https://github.com/igneous-labs/jiminy.git", branch = "mas
jiminy-pda = { git = "https://github.com/igneous-labs/jiminy.git", branch = "master", default-features = false }
jiminy-program-error = { git = "https://github.com/igneous-labs/jiminy.git", branch = "master", default-features = false }
jiminy-return-data = { git = "https://github.com/igneous-labs/jiminy.git", branch = "master", default-features = false }
jiminy-sysvar-instructions = { git = "https://github.com/igneous-labs/jiminy.git", branch = "master", default-features = false }
jiminy-sysvar-rent = { git = "https://github.com/igneous-labs/jiminy.git", branch = "master", default-features = false }
sanctum-ata-jiminy = { git = "https://github.com/igneous-labs/sanctum-ata-sdk.git", branch = "master", default-features = false }
sanctum-spl-token-core = { git = "https://github.com/igneous-labs/sanctum-spl-token-sdk.git", branch = "master", default-features = false }
Expand Down
1 change: 1 addition & 0 deletions controller/core/src/accounts/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod lst_state_list;
pub mod packed_list;
pub mod pool_state;
pub mod rebalance_record;
58 changes: 58 additions & 0 deletions controller/core/src/accounts/rebalance_record.rs
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>());
23 changes: 22 additions & 1 deletion controller/core/src/instructions/rebalance/start.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use generic_array_struct::generic_array_struct;

use crate::instructions::internal_utils::caba;
use crate::instructions::internal_utils::{caba, csba};

// Accounts

Expand Down Expand Up @@ -104,4 +104,25 @@ impl StartRebalanceIxData {
pub const fn as_buf(&self) -> &[u8; START_REBALANCE_IX_DATA_LEN] {
&self.0
}

#[inline]
pub const fn parse_no_discm(
data: &[u8; START_REBALANCE_IX_DATA_LEN - 1],
) -> StartRebalanceIxArgs {
let (out_lst_value_calc_accs, rest) = csba::<33, 1, 32>(data);
let (out_lst_index, rest) = csba::<32, 4, 28>(rest);
let (inp_lst_index, rest) = csba::<28, 4, 24>(rest);
let (amount, rest) = csba::<24, 8, 16>(rest);
let (min_starting_out_lst, rest) = csba::<16, 8, 8>(rest);
let (max_starting_inp_lst, _) = csba::<8, 8, 0>(rest);

StartRebalanceIxArgs {
out_lst_value_calc_accs: out_lst_value_calc_accs[0],
out_lst_index: u32::from_le_bytes(*out_lst_index),
inp_lst_index: u32::from_le_bytes(*inp_lst_index),
amount: u64::from_le_bytes(*amount),
min_starting_out_lst: u64::from_le_bytes(*min_starting_out_lst),
max_starting_inp_lst: u64::from_le_bytes(*max_starting_inp_lst),
}
}
}
13 changes: 12 additions & 1 deletion controller/jiminy/src/cpi.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use core::ops::RangeInclusive;
use inf1_ctl_core::instructions::{
admin::set_sol_value_calculator::SetSolValueCalculatorIxPreAccs,
liquidity::add::AddLiquidityIxPreAccs, swap::IxPreAccs as SwapIxPreAccs,
liquidity::add::AddLiquidityIxPreAccs,
rebalance::{end::EndRebalanceIxPreAccs, start::StartRebalanceIxPreAccs},
swap::IxPreAccs as SwapIxPreAccs,
sync_sol_value::SyncSolValueIxPreAccs,
};

Expand All @@ -27,6 +29,15 @@ pub type AddLiquidityPreAccountHandles<'account> = AddLiquidityIxPreAccs<Account
pub type SetSolValueCalculatorIxPreAccountHandles<'account> =
SetSolValueCalculatorIxPreAccs<AccountHandle<'account>>;

/// `S: AsRef<[AccountHandle]>`
/// -> use [`IxAccountHandles::seq`] with [`jiminy_cpi::Cpi::invoke_fwd`]
pub type StartRebalanceIxPreAccountHandles<'account> =
StartRebalanceIxPreAccs<AccountHandle<'account>>;

/// `S: AsRef<[AccountHandle]>`
/// -> use [`IxAccountHandles::seq`] with [`jiminy_cpi::Cpi::invoke_fwd`]
pub type EndRebalanceIxPreAccountHandles<'account> = EndRebalanceIxPreAccs<AccountHandle<'account>>;

pub type SwapIxPreAccountHandles<'account> = SwapIxPreAccs<AccountHandle<'account>>;

// TODO: make invoke() helpers for client programs
Expand Down
2 changes: 2 additions & 0 deletions controller/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jiminy-cpi = { workspace = true }
jiminy-entrypoint = { workspace = true, features = ["allocator", "panic"] }
jiminy-log = { workspace = true }
jiminy-pda = { workspace = true }
jiminy-sysvar-instructions = { workspace = true }
jiminy-sysvar-rent = { workspace = true }
sanctum-ata-jiminy = { workspace = true }
sanctum-spl-token-jiminy = { workspace = true }
Expand All @@ -40,4 +41,5 @@ mollusk-svm = { workspace = true }
proptest = { workspace = true, features = ["std"] }
solana-account = { workspace = true }
solana-instruction = { workspace = true }
solana-instructions-sysvar = { workspace = true }
solana-pubkey = { workspace = true }
1 change: 1 addition & 0 deletions controller/program/src/instructions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod admin;
pub mod liquidity;
pub mod protocol_fee;
pub mod rebalance;
pub mod swap;
pub mod sync_sol_value;
Loading
Loading