Skip to content

Commit

Permalink
Jupiter changes for jupiter-core compat
Browse files Browse the repository at this point in the history
  • Loading branch information
Arrowana committed Feb 11, 2024
1 parent e2ac26c commit d31df7c
Show file tree
Hide file tree
Showing 9 changed files with 259 additions and 192 deletions.
270 changes: 194 additions & 76 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 3 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
[workspace]
resolver = "2"

members = [
"stakedex_sdk",
"common",
"libs/*",
"interfaces/*"
]
members = ["stakedex_sdk", "common", "libs/*", "interfaces/*"]

[workspace.dependencies]
anyhow = "^1.0"
Expand All @@ -16,8 +11,8 @@ itertools = ">=0.1"
jupiter-amm-interface = "~0.3.2"
lazy_static = "^1.0"
# set git dependencies to branch instead of locking to rev so that consumers can upgrade easily
lido = { git = "https://github.com/jup-ag/solido", branch = "jupiter", features = ["no-entrypoint"] } # rev = "ec25a9b"
marinade_finance_interface = { git = "https://github.com/igneous-labs/marinade_finance_interface", branch = "master" } # rev = "4d1895b"
lido = { git = "https://github.com/jup-ag/solido", rev = "2c85ddf7b50d8162d2b81d79d7fcbfd5e05dc967", features = ["no-entrypoint"] }
marinade_finance_interface = { git = "https://github.com/jup-ag/marinade_finance_interface", rev = "5747b5350c5505fc2ea597c3f8ae1f8cf71c363d" } # rev = "4d1895b"
num-derive = ">=0.1"
num-traits = ">=0.1"
rust_decimal = ">=1.0,<=1.32.0" # anything >1.32 uses borsh ^1
Expand Down
102 changes: 17 additions & 85 deletions interfaces/stakedex_interface/src/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,56 +158,16 @@ impl From<StakeWrappedSolAccounts<'_, '_>> for StakeWrappedSolKeys {
impl From<StakeWrappedSolKeys> for [AccountMeta; STAKE_WRAPPED_SOL_IX_ACCOUNTS_LEN] {
fn from(keys: StakeWrappedSolKeys) -> Self {
[
AccountMeta {
pubkey: keys.user,
is_signer: true,
is_writable: false,
},
AccountMeta {
pubkey: keys.wsol_from,
is_signer: false,
is_writable: true,
},
AccountMeta {
pubkey: keys.dest_token_to,
is_signer: false,
is_writable: true,
},
AccountMeta {
pubkey: keys.wsol_bridge_in,
is_signer: false,
is_writable: true,
},
AccountMeta {
pubkey: keys.sol_bridge_out,
is_signer: false,
is_writable: true,
},
AccountMeta {
pubkey: keys.dest_token_fee_token_account,
is_signer: false,
is_writable: true,
},
AccountMeta {
pubkey: keys.dest_token_mint,
is_signer: false,
is_writable: true,
},
AccountMeta {
pubkey: keys.wsol_mint,
is_signer: false,
is_writable: false,
},
AccountMeta {
pubkey: keys.token_program,
is_signer: false,
is_writable: false,
},
AccountMeta {
pubkey: keys.system_program,
is_signer: false,
is_writable: false,
},
AccountMeta::new_readonly(keys.user, false),
AccountMeta::new(keys.wsol_from, false),
AccountMeta::new(keys.dest_token_to, false),
AccountMeta::new(keys.wsol_bridge_in, false),
AccountMeta::new(keys.sol_bridge_out, false),
AccountMeta::new(keys.dest_token_fee_token_account, false),
AccountMeta::new(keys.dest_token_mint, false),
AccountMeta::new_readonly(keys.wsol_mint, false),
AccountMeta::new_readonly(keys.token_program, false),
AccountMeta::new_readonly(keys.system_program, false),
]
}
}
Expand Down Expand Up @@ -464,41 +424,13 @@ impl From<SwapViaStakeAccounts<'_, '_>> for SwapViaStakeKeys {
impl From<SwapViaStakeKeys> for [AccountMeta; SWAP_VIA_STAKE_IX_ACCOUNTS_LEN] {
fn from(keys: SwapViaStakeKeys) -> Self {
[
AccountMeta {
pubkey: keys.user,
is_signer: true,
is_writable: true,
},
AccountMeta {
pubkey: keys.src_token_from,
is_signer: false,
is_writable: true,
},
AccountMeta {
pubkey: keys.dest_token_to,
is_signer: false,
is_writable: true,
},
AccountMeta {
pubkey: keys.bridge_stake,
is_signer: false,
is_writable: true,
},
AccountMeta {
pubkey: keys.dest_token_fee_token_account,
is_signer: false,
is_writable: true,
},
AccountMeta {
pubkey: keys.src_token_mint,
is_signer: false,
is_writable: true,
},
AccountMeta {
pubkey: keys.dest_token_mint,
is_signer: false,
is_writable: true,
},
AccountMeta::new(keys.user, false),
AccountMeta::new(keys.src_token_from, false),
AccountMeta::new(keys.dest_token_to, false),
AccountMeta::new(keys.bridge_stake, false),
AccountMeta::new(keys.dest_token_fee_token_account, false),
AccountMeta::new(keys.src_token_mint, false),
AccountMeta::new(keys.dest_token_mint, false),
]
}
}
Expand Down
26 changes: 14 additions & 12 deletions libs/marinade/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use anyhow::{anyhow, Result};
use borsh::BorshDeserialize;
use consts::VALIDATOR_RECORD_BYTE_LENGTH;
use marinade_finance_interface::{
Fee, FeeCents, LiqPool, List, StakeSystem, State, ValidatorRecord, ValidatorSystem,
Fee, LiqPool, List, StakeSystem, State, ValidatorRecord, ValidatorSystem,
};
use solana_program::{borsh0_10::try_from_slice_unchecked, pubkey::Pubkey};

Expand All @@ -28,11 +28,13 @@ impl Default for MarinadeStakedex {
account: Pubkey::default(),
item_size: 0,
count: 0,
reserved1: Pubkey::default(),
reserved2: 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 };
// let zero_fee_cents = FeeCents { bp_cents: 0 };
Self {
state: State {
msol_mint: Pubkey::default(),
Expand Down Expand Up @@ -84,14 +86,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,
// 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
7 changes: 5 additions & 2 deletions libs/spl_stake_pool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ anyhow = { workspace = true }
bincode = { workspace = true }
borsh = { workspace = true }
solana-program = { workspace = true }
spl-stake-pool = { workspace = true }
spl-stake-pool = { git = "https://github.com/solana-labs/solana-program-library.git", rev = "a3996814cb44eab2834f72113b742c875ac7b1b9", features = [
"no-entrypoint",
] }
# spl-stake-pool = "^0.6.4"
spl-token = { workspace = true }
stakedex_deposit_sol_interface = { workspace = true }
stakedex_deposit_stake_interface = { workspace = true }
stakedex_sdk_common = { workspace = true }
stakedex_withdraw_stake_interface = { workspace = true }
stakedex_withdraw_stake_interface = { workspace = true }
1 change: 1 addition & 0 deletions libs/spl_stake_pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use spl_stake_pool::{
use stakedex_sdk_common::{WithdrawStakeQuote, STAKE_ACCOUNT_RENT_EXEMPT_LAMPORTS};

mod stakedex_traits;
pub use spl_stake_pool::ID;
pub use stakedex_traits::*;

/// A SPL stake pool with possibly custom program ID
Expand Down
3 changes: 1 addition & 2 deletions libs/unstake_it/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use anyhow::Result;
use solana_program::{borsh0_10::try_from_slice_unchecked, pubkey::Pubkey};
use solana_program::{borsh0_9::try_from_slice_unchecked, pubkey::Pubkey};
use unstake_interface::{Fee, FeeEnum, Pool, ProtocolFee, Rational};

mod pda;
mod stakedex_traits;

pub use pda::*;
pub use stakedex_traits::*;

pub const UNSTAKE_IT_LABEL: &str = "Unstake.it";

Expand Down
1 change: 1 addition & 0 deletions stakedex_sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ stakedex_unstake_it = { workspace = true }

[dev-dependencies]
solana-client = { workspace = true }
lazy_static = { workspace = true }
30 changes: 23 additions & 7 deletions stakedex_sdk/tests/test_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,25 @@ fn fetch_accounts(accounts_pubkeys: &[Pubkey]) -> HashMap<Pubkey, Account> {
}

#[test]
fn test_swap_via_stake_unknown_token() {
fn test_quote_swap_via_stake_jitosol_bsol() {
STAKEDEX
.quote_swap_via_stake(&QuoteParams {
amount: 1_000_000_000,
input_mint: jitosol::ID,
output_mint: bsol::ID,
swap_mode: jupiter_amm_interface::SwapMode::ExactIn,
})
.unwrap();
}

#[test]
fn test_quote_swap_via_stake_unknown_token() {
let unknown_token = Pubkey::new_unique();
let res = STAKEDEX.quote_swap_via_stake(&QuoteParams {
amount: 1_000_000_000,
input_mint: unknown_token,
output_mint: bsol::ID,
swap_mode: SwapMode::default(),
swap_mode: jupiter_amm_interface::SwapMode::ExactIn,
});
assert!(res.is_err());
}
Expand Down Expand Up @@ -247,13 +259,17 @@ fn test_jsol_drain_vsa_edge_case() {
.validator_list
.validators
.iter()
.max_by_key(|v| v.active_stake_lamports)
.max_by_key(|v| u64::from(v.active_stake_lamports))
.unwrap();
let max_withdraw_lamports = largest_active_stake_vsi.active_stake_lamports;
let parts_after_fees = (STAKEDEX.jpool.stake_pool.stake_withdrawal_fee.denominator
- STAKEDEX.jpool.stake_pool.stake_withdrawal_fee.numerator)
as u128;
<<<<<<< HEAD
let max_withdraw_lamports_bef_fees = u128::from(max_withdraw_lamports)
=======
let max_withdraw_lamports_bef_fees = (u128::from(u64::from(max_withdraw_lamports))
>>>>>>> 6314bd6 (Jupiter changes for jupiter-core compat)
* (STAKEDEX.jpool.stake_pool.stake_withdrawal_fee.denominator as u128)
+ parts_after_fees
- 1)
Expand All @@ -265,17 +281,17 @@ fn test_jsol_drain_vsa_edge_case() {
.unwrap();
let max_possible_quote = STAKEDEX
.quote_swap_via_stake(&QuoteParams {
amount: max_withdraw_jsol,
input_mint: jsol::ID,
amount: 100_000_000_000,
input_mint: stsol::ID,
output_mint: msol::ID,
swap_mode: SwapMode::default(),
swap_mode: jupiter_amm_interface::SwapMode::ExactIn,
})
.unwrap();
let should_fail = STAKEDEX.quote_swap_via_stake(&QuoteParams {
amount: max_withdraw_jsol + 1,
input_mint: jsol::ID,
output_mint: msol::ID,
swap_mode: SwapMode::default(),
swap_mode: SwapMode::ExactIn,
});
assert!(should_fail.is_err());
Expand Down

0 comments on commit d31df7c

Please sign in to comment.