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

[WIP] add test fixtures, update deps #38

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2,747 changes: 2,142 additions & 605 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 13 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,29 @@ members = [
[workspace.dependencies]
anyhow = "^1.0"
bincode = "^1.0"
borsh = "^0.9"
borsh = ">=0.9,<1.0.0"
jupiter-amm-interface = "~0.3.2"
lazy_static = "^1.0"
lido = { git = "https://github.com/jup-ag/solido", rev = "ec25a9b", features = ["no-entrypoint"] }
marinade_finance_interface = { git = "https://github.com/igneous-labs/marinade_finance_interface", rev = "4d1895b" }
num-derive = ">=0.1"
num-traits = ">=0.1"
rust_decimal = "^1.0"
rust_decimal = ">=1.0,<=1.32.0" # anything > uses borsh ^1
sanctum-macros = "^1.2"
serde = "^1"
solana-client = "^1.9"
solana-program = "^1.9"
solana-program = "^1.17"
solana-program-test = "^1.9"
solana-sdk = "^1.9"
spl-stake-pool = { version = "^1", features = ["no-entrypoint"] }
spl-token = "^3.0"
thiserror = "^1.0"
tokio = "^1"
unstake_interface = { git = "https://github.com/igneous-labs/sanctum-unstake-program.git", rev = "069f941" }
unstake-lib = { git = "https://github.com/igneous-labs/sanctum-unstake-program.git", rev = "069f941" }

# sanctum-solana-utils
sanctum-solana-test-utils = { git = "https://github.com/igneous-labs/sanctum-solana-utils.git", rev = "46e5da1" }

# workspace members
stakedex_deposit_sol_interface = { path = "./interfaces/stakedex_deposit_sol_interface" }
Expand Down
6 changes: 3 additions & 3 deletions common/src/withdraw_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use solana_program::{
clock::Clock,
instruction::Instruction,
pubkey::Pubkey,
stake::state::{Delegation, Stake, StakeState},
stake::state::{Delegation, Stake, StakeStateV2},
};

use crate::{BaseStakePoolAmm, STAKE_ACCOUNT_RENT_EXEMPT_LAMPORTS};
Expand Down Expand Up @@ -67,11 +67,11 @@ impl WithdrawStakeQuote {
}

pub fn try_from_stake_acc(
s: &StakeState,
s: &StakeStateV2,
stake_acc_lamports: u64,
clock: &Clock,
) -> Result<Self> {
if let StakeState::Stake(meta, stake) = s {
if let StakeStateV2::Stake(meta, stake, _flags) = s {
if meta.lockup.is_in_force(clock, None) {
return Err(anyhow!("Stake acc lockup in force"));
}
Expand Down
4 changes: 2 additions & 2 deletions libs/lido/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ edition = "2021"
anyhow = { workspace = true }
bincode = { workspace = true }
borsh = { workspace = true }
lido = { git = "https://github.com/igneous-labs/solido", branch = "mod/2.0.0-loose-deps", features = ["no-entrypoint"] }
lido = { workspace = true }
solana-program = { workspace = true }
spl-token = { workspace = true }
stakedex_deposit_sol_interface = { workspace = true }
stakedex_withdraw_stake_interface = { workspace = true }
stakedex_sdk_common = { workspace = true }

[dev-dependencies]
solana-client = "^1.9"
solana-client = { workspace = true }
2 changes: 1 addition & 1 deletion libs/lido/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use lido::state::{AccountType, Lido, Validator};
mod stakedex_traits;

use solana_program::{
borsh::try_from_slice_unchecked, clock::Clock, program_pack::Pack, stake_history::Epoch,
borsh0_10::try_from_slice_unchecked, clock::Clock, program_pack::Pack, stake_history::Epoch,
};
pub use stakedex_traits::*;

Expand Down
2 changes: 1 addition & 1 deletion libs/marinade/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
[dependencies]
anyhow = { workspace = true }
borsh = { workspace = true }
marinade_finance_interface = { git = "https://github.com/igneous-labs/marinade_finance_interface", rev = "d625979" }
marinade_finance_interface = { workspace = true }
solana-program = { workspace = true }
spl-token = { workspace = true }
stakedex_deposit_sol_interface = { workspace = true }
Expand Down
19 changes: 14 additions & 5 deletions libs/marinade/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use anyhow::{anyhow, Result};
use borsh::BorshDeserialize;
use consts::VALIDATOR_RECORD_BYTE_LENGTH;
use marinade_finance_interface::{
Fee, LiqPool, List, StakeSystem, State, ValidatorRecord, ValidatorSystem,
Fee, FeeCents, LiqPool, List, StakeSystem, State, ValidatorRecord, ValidatorSystem,
};
use solana_program::{borsh::try_from_slice_unchecked, pubkey::Pubkey};
use solana_program::{borsh0_10::try_from_slice_unchecked, pubkey::Pubkey};

pub use stakedex_traits::*;

Expand All @@ -28,10 +28,11 @@ impl Default for MarinadeStakedex {
account: Pubkey::default(),
item_size: 0,
count: 0,
new_account: Pubkey::default(),
copied_count: 0,
reserved1: Pubkey::default(),
reserved2: 0,
};
let zero_fee = Fee { basis_points: 0 };
let zero_fee_cents = FeeCents { bp_cents: 0 };
Self {
state: State {
msol_mint: Pubkey::default(),
Expand Down Expand Up @@ -68,7 +69,7 @@ impl Default for MarinadeStakedex {
lp_liquidity_target: 0,
lp_max_fee: zero_fee.clone(),
lp_min_fee: zero_fee.clone(),
treasury_cut: zero_fee,
treasury_cut: zero_fee.clone(),
lp_supply: 0,
lent_from_sol_leg: 0,
liquidity_sol_cap: 0,
Expand All @@ -83,6 +84,14 @@ impl Default for MarinadeStakedex {
min_withdraw: 0,
staking_sol_cap: 0,
emergency_cooling_down: 0,
pause_authority: Pubkey::default(),
paused: false,
delayed_unstake_fee: zero_fee_cents.clone(),
withdraw_stake_account_fee: zero_fee_cents,
withdraw_stake_account_enabled: false,
last_stake_move_epoch: 0,
stake_moved: 0,
max_stake_moved_per_epoch: zero_fee,
},
validator_records: Vec::new(),
}
Expand Down
3 changes: 1 addition & 2 deletions libs/socean_stake_pool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ bincode = { workspace = true }
borsh = { workspace = true }
solana-program = { workspace = true }

spl-stake-pool = "^0.6.4"
# { git = "https://github.com/igneous-labs/solana-program-library", branch = "release/v0.1"} incompatible with solana-program ^1.9
spl-stake-pool = { workspace = true }

spl-token = { workspace = true }
stakedex_deposit_sol_interface = { workspace = true }
Expand Down
8 changes: 4 additions & 4 deletions libs/socean_stake_pool/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use solana_program::{borsh::try_from_slice_unchecked, pubkey::Pubkey, stake_history::Epoch};
use solana_program::{borsh0_10::try_from_slice_unchecked, pubkey::Pubkey, stake_history::Epoch};
use spl_stake_pool::{
error::StakePoolError,
find_stake_program_address, find_withdraw_authority_program_address,
Expand Down Expand Up @@ -38,7 +38,7 @@ impl SoceanStakePoolStakedex {

/// Find and return validator stake account
pub fn vsa(voter: &Pubkey) -> Pubkey {
find_stake_program_address(&socean_program::ID, voter, &socean_stake_pool::ID).0
find_stake_program_address(&socean_program::ID, voter, &socean_stake_pool::ID, None).0
}

pub fn is_updated_this_epoch(&self) -> bool {
Expand All @@ -53,7 +53,7 @@ impl SoceanStakePoolStakedex {
let validator_list_entry = self.validator_list.validators.get(validator_index).unwrap();
// only handle withdrawal from active stake accounts for simplicity.
// Likely other stake pools can't accept non active stake anyway
if validator_list_entry.status != StakeStatus::Active {
if validator_list_entry.status != StakeStatus::Active.into() {
return Err(StakePoolError::InvalidState);
}
let stake_pool = &self.stake_pool;
Expand Down Expand Up @@ -83,7 +83,7 @@ impl SoceanStakePoolStakedex {
// according to https://github.com/solana-labs/solana-program-library/blob/58c1226a513d3d8bb2de8ec67586a679be7fd2d4/stake-pool/program/src/state.rs#L536C1-L542
// `active_stake_lamports` = delegation.stake - MIN_ACTIVE_STAKE_LAMPORTS.
// Withdrawals must leave at least MIN_ACTIVE_STAKE_LAMPORTS active stake in vsa
if withdraw_lamports > validator_list_entry.active_stake_lamports {
if withdraw_lamports > u64::from(validator_list_entry.active_stake_lamports) {
return Err(StakePoolError::InvalidState);
}
let lamports_staked = withdraw_lamports
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl DepositStake for SoceanStakePoolStakedex {
Some(r) => r,
None => return DepositStakeQuote::default(),
};
if validator_list_entry.status != StakeStatus::Active {
if validator_list_entry.status != StakeStatus::Active.into() {
return DepositStakeQuote::default();
}
// Reference: https://github.com/solana-labs/solana-program-library/blob/stake-pool-v0.6.4/stake-pool/program/src/processor.rs#L1971
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl<'a> WithdrawStakeQuoteIter<'a> {
.enumerate()
.find(|(_, vsi)| vsi.vote_account_address == preferred_voter)?;
// preferred cant service withdrawals, fallback to normal
if vsi.active_stake_lamports <= MINIMUM_ACTIVE_STAKE {
if u64::from(vsi.active_stake_lamports) <= MINIMUM_ACTIVE_STAKE {
return Some((
WithdrawStakeQuote::default(),
WithdrawStakeQuoteIterState::Normal(0),
Expand Down
2 changes: 1 addition & 1 deletion libs/spl_stake_pool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ bincode = { workspace = true }
borsh = { workspace = true }
lazy_static = "^1.0"
solana-program = { workspace = true }
spl-stake-pool = "^0.6.4"
spl-stake-pool = { workspace = true }
spl-token = { workspace = true }
stakedex_deposit_sol_interface = { workspace = true }
stakedex_deposit_stake_interface = { workspace = true }
Expand Down
6 changes: 3 additions & 3 deletions libs/spl_stake_pool/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Result;
use lazy_static::lazy_static;
use solana_program::{borsh::try_from_slice_unchecked, pubkey::Pubkey, stake_history::Epoch};
use solana_program::{borsh0_10::try_from_slice_unchecked, pubkey::Pubkey, stake_history::Epoch};
use spl_stake_pool::{
error::StakePoolError,
state::{StakePool, StakeStatus, ValidatorList},
Expand Down Expand Up @@ -63,7 +63,7 @@ impl SplStakePoolStakedex {
let validator_list_entry = self.validator_list.validators.get(validator_index).unwrap();
// only handle withdrawal from active stake accounts for simplicity.
// Likely other stake pools can't accept non active stake anyway
if validator_list_entry.status != StakeStatus::Active {
if validator_list_entry.status != StakeStatus::Active.into() {
return Err(StakePoolError::InvalidState);
}
let stake_pool = &self.stake_pool;
Expand All @@ -90,7 +90,7 @@ impl SplStakePoolStakedex {
// according to https://github.com/solana-labs/solana-program-library/blob/58c1226a513d3d8bb2de8ec67586a679be7fd2d4/stake-pool/program/src/state.rs#L536C1-L542
// `active_stake_lamports` = delegation.stake - MIN_ACTIVE_STAKE_LAMPORTS.
// Withdrawals must leave at least MIN_ACTIVE_STAKE_LAMPORTS active stake in vsa
if withdraw_lamports > validator_list_entry.active_stake_lamports {
if withdraw_lamports > u64::from(validator_list_entry.active_stake_lamports) {
return Err(StakePoolError::InvalidState);
}
let lamports_staked = withdraw_lamports
Expand Down
11 changes: 8 additions & 3 deletions libs/spl_stake_pool/src/stakedex_traits/deposit_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl DepositStake for SplStakePoolStakedex {
Some(r) => r,
None => return DepositStakeQuote::default(),
};
if validator_list_entry.status != StakeStatus::Active {
if validator_list_entry.status != StakeStatus::Active.into() {
return DepositStakeQuote::default();
}
// Reference: https://github.com/solana-labs/solana-program-library/blob/stake-pool-v0.6.4/stake-pool/program/src/processor.rs#L1971
Expand Down Expand Up @@ -113,8 +113,13 @@ impl DepositStake for SplStakePoolStakedex {
quote: &DepositStakeQuote,
_deposit_stake_info: &DepositStakeInfo,
) -> Result<Instruction> {
let deposit_stake_validator_stake =
find_stake_program_address(&spl_stake_pool::ID, &quote.voter, &self.stake_pool_addr).0;
let deposit_stake_validator_stake = find_stake_program_address(
&spl_stake_pool::ID,
&quote.voter,
&self.stake_pool_addr,
None,
)
.0;
Ok(spl_stake_pool_deposit_stake_ix(
SplStakePoolDepositStakeKeys {
spl_stake_pool_program: spl_stake_pool::ID,
Expand Down
11 changes: 8 additions & 3 deletions libs/spl_stake_pool/src/stakedex_traits/withdraw_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl<'a> WithdrawStakeQuoteIter<'a> {
.enumerate()
.find(|(_, vsi)| vsi.vote_account_address == preferred_voter)?;
// preferred cant service withdrawals, fallback to normal
if vsi.active_stake_lamports <= MINIMUM_ACTIVE_STAKE {
if u64::from(vsi.active_stake_lamports) <= MINIMUM_ACTIVE_STAKE {
return Some((
WithdrawStakeQuote::default(),
WithdrawStakeQuoteIterState::Normal(0),
Expand Down Expand Up @@ -103,8 +103,13 @@ impl WithdrawStakeBase for SplStakePoolStakedex {
}

fn virtual_ix(&self, quote: &WithdrawStakeQuote) -> Result<Instruction> {
let withdraw_stake_stake_to_split =
find_stake_program_address(&spl_stake_pool::ID, &quote.voter, &self.stake_pool_addr).0;
let withdraw_stake_stake_to_split = find_stake_program_address(
&spl_stake_pool::ID,
&quote.voter,
&self.stake_pool_addr,
None,
)
.0;
Ok(spl_stake_pool_withdraw_stake_ix(
SplStakePoolWithdrawStakeKeys {
spl_stake_pool_program: spl_stake_pool::ID,
Expand Down
3 changes: 2 additions & 1 deletion libs/unstake_it/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ spl-math = { version = "0.1.0", features = ["no-entrypoint"]}
spl-token = { workspace = true }
stakedex_deposit_stake_interface = { workspace = true }
stakedex_sdk_common = { workspace = true }
unstake_it_interface = { git = "https://github.com/igneous-labs/unstake_it_interface", rev = "8819194" } # TODO: change to main program crate once we open source unstake.it
unstake_interface = { workspace = true }
unstake-lib = { workspace = true }
63 changes: 0 additions & 63 deletions libs/unstake_it/src/fee.rs

This file was deleted.

Loading