Skip to content

Commit 777fc36

Browse files
committed
Fix IDL and stake pool client refactor, lints
1 parent 410d94a commit 777fc36

File tree

7 files changed

+78
-938
lines changed

7 files changed

+78
-938
lines changed

core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub mod instruction;
1414
pub mod loaders;
1515
pub mod ncn_fee_group;
1616
pub mod ncn_reward_router;
17+
pub mod spl_stake_pool;
1718
pub mod stake_weight;
1819
pub mod utils;
1920
pub mod vault_registry;

core/src/spl_stake_pool.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//! Minimal SPL Stake Pool utilities
2+
//!
3+
//! This module contains only the minimal code needed to interact with the SPL Stake Pool program,
4+
//! specifically for depositing SOL. This avoids depending on the full spl-stake-pool crate.
5+
6+
use borsh::{BorshDeserialize, BorshSerialize};
7+
use solana_program::pubkey::Pubkey;
8+
9+
/// Seed for withdraw authority seed
10+
const AUTHORITY_WITHDRAW: &[u8] = b"withdraw";
11+
12+
/// Generates the withdraw authority program address for the stake pool
13+
pub fn find_withdraw_authority_program_address(
14+
program_id: &Pubkey,
15+
stake_pool_address: &Pubkey,
16+
) -> (Pubkey, u8) {
17+
Pubkey::find_program_address(
18+
&[stake_pool_address.as_ref(), AUTHORITY_WITHDRAW],
19+
program_id,
20+
)
21+
}
22+
23+
/// Minimal subset of SPL Stake Pool instructions needed for this program.
24+
///
25+
/// IMPORTANT: These variants have explicit discriminants to match the actual SPL Stake Pool program.
26+
/// DepositSol is variant #19 and DepositSolWithSlippage is variant #30 in the real enum.
27+
/// See: <https://github.com/solana-program/stake-pool/blob/main/program/src/instruction.rs>
28+
///
29+
/// Note: This appears in the IDL because it's used in public functions, but only with 2 variants.
30+
#[repr(u8)]
31+
#[derive(Clone, Debug, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
32+
#[borsh(use_discriminant = true)]
33+
pub enum StakePoolInstruction {
34+
/// Deposit SOL into the stake pool (variant #19)
35+
DepositSol(u64) = 19,
36+
/// Deposit SOL into the stake pool with slippage protection (variant #30)
37+
DepositSolWithSlippage {
38+
lamports_in: u64,
39+
minimum_pool_tokens_out: u64,
40+
} = 30,
41+
}

idl/jito_tip_router.json

Lines changed: 27 additions & 251 deletions
Original file line numberDiff line numberDiff line change
@@ -2855,257 +2855,6 @@
28552855
}
28562856
],
28572857
"types": [
2858-
{
2859-
"name": "StakePoolInstruction",
2860-
"type": {
2861-
"kind": "enum",
2862-
"variants": [
2863-
{
2864-
"name": "Initialize"
2865-
},
2866-
{
2867-
"name": "AddValidatorToPool",
2868-
"fields": [
2869-
"u32"
2870-
]
2871-
},
2872-
{
2873-
"name": "RemoveValidatorFromPool"
2874-
},
2875-
{
2876-
"name": "DecreaseValidatorStake",
2877-
"fields": [
2878-
{
2879-
"name": "lamports",
2880-
"type": "u64"
2881-
},
2882-
{
2883-
"name": "transient_stake_seed",
2884-
"type": "u64"
2885-
}
2886-
]
2887-
},
2888-
{
2889-
"name": "IncreaseValidatorStake",
2890-
"fields": [
2891-
{
2892-
"name": "lamports",
2893-
"type": "u64"
2894-
},
2895-
{
2896-
"name": "transient_stake_seed",
2897-
"type": "u64"
2898-
}
2899-
]
2900-
},
2901-
{
2902-
"name": "SetPreferredValidator"
2903-
},
2904-
{
2905-
"name": "UpdateValidatorListBalance",
2906-
"fields": [
2907-
{
2908-
"name": "start_index",
2909-
"type": "u32"
2910-
},
2911-
{
2912-
"name": "no_merge",
2913-
"type": "bool"
2914-
}
2915-
]
2916-
},
2917-
{
2918-
"name": "UpdateStakePoolBalance"
2919-
},
2920-
{
2921-
"name": "CleanupRemovedValidatorEntries"
2922-
},
2923-
{
2924-
"name": "DepositStake"
2925-
},
2926-
{
2927-
"name": "WithdrawStake",
2928-
"fields": [
2929-
"u64"
2930-
]
2931-
},
2932-
{
2933-
"name": "SetManager"
2934-
},
2935-
{
2936-
"name": "SetFee"
2937-
},
2938-
{
2939-
"name": "SetStaker"
2940-
},
2941-
{
2942-
"name": "DepositSol",
2943-
"fields": [
2944-
"u64"
2945-
]
2946-
},
2947-
{
2948-
"name": "SetFundingAuthority"
2949-
},
2950-
{
2951-
"name": "WithdrawSol",
2952-
"fields": [
2953-
"u64"
2954-
]
2955-
},
2956-
{
2957-
"name": "CreateTokenMetadata",
2958-
"fields": [
2959-
{
2960-
"name": "name",
2961-
"type": "string"
2962-
},
2963-
{
2964-
"name": "symbol",
2965-
"type": "string"
2966-
},
2967-
{
2968-
"name": "uri",
2969-
"type": "string"
2970-
}
2971-
]
2972-
},
2973-
{
2974-
"name": "UpdateTokenMetadata",
2975-
"fields": [
2976-
{
2977-
"name": "name",
2978-
"type": "string"
2979-
},
2980-
{
2981-
"name": "symbol",
2982-
"type": "string"
2983-
},
2984-
{
2985-
"name": "uri",
2986-
"type": "string"
2987-
}
2988-
]
2989-
},
2990-
{
2991-
"name": "IncreaseAdditionalValidatorStake",
2992-
"fields": [
2993-
{
2994-
"name": "lamports",
2995-
"type": "u64"
2996-
},
2997-
{
2998-
"name": "transient_stake_seed",
2999-
"type": "u64"
3000-
},
3001-
{
3002-
"name": "ephemeral_stake_seed",
3003-
"type": "u64"
3004-
}
3005-
]
3006-
},
3007-
{
3008-
"name": "DecreaseAdditionalValidatorStake",
3009-
"fields": [
3010-
{
3011-
"name": "lamports",
3012-
"type": "u64"
3013-
},
3014-
{
3015-
"name": "transient_stake_seed",
3016-
"type": "u64"
3017-
},
3018-
{
3019-
"name": "ephemeral_stake_seed",
3020-
"type": "u64"
3021-
}
3022-
]
3023-
},
3024-
{
3025-
"name": "DecreaseValidatorStakeWithReserve",
3026-
"fields": [
3027-
{
3028-
"name": "lamports",
3029-
"type": "u64"
3030-
},
3031-
{
3032-
"name": "transient_stake_seed",
3033-
"type": "u64"
3034-
}
3035-
]
3036-
},
3037-
{
3038-
"name": "Redelegate",
3039-
"fields": [
3040-
{
3041-
"name": "lamports",
3042-
"type": "u64"
3043-
},
3044-
{
3045-
"name": "source_transient_stake_seed",
3046-
"type": "u64"
3047-
},
3048-
{
3049-
"name": "ephemeral_stake_seed",
3050-
"type": "u64"
3051-
},
3052-
{
3053-
"name": "destination_transient_stake_seed",
3054-
"type": "u64"
3055-
}
3056-
]
3057-
},
3058-
{
3059-
"name": "DepositStakeWithSlippage",
3060-
"fields": [
3061-
{
3062-
"name": "minimum_pool_tokens_out",
3063-
"type": "u64"
3064-
}
3065-
]
3066-
},
3067-
{
3068-
"name": "WithdrawStakeWithSlippage",
3069-
"fields": [
3070-
{
3071-
"name": "pool_tokens_in",
3072-
"type": "u64"
3073-
},
3074-
{
3075-
"name": "minimum_lamports_out",
3076-
"type": "u64"
3077-
}
3078-
]
3079-
},
3080-
{
3081-
"name": "DepositSolWithSlippage",
3082-
"fields": [
3083-
{
3084-
"name": "lamports_in",
3085-
"type": "u64"
3086-
},
3087-
{
3088-
"name": "minimum_pool_tokens_out",
3089-
"type": "u64"
3090-
}
3091-
]
3092-
},
3093-
{
3094-
"name": "WithdrawSolWithSlippage",
3095-
"fields": [
3096-
{
3097-
"name": "pool_tokens_in",
3098-
"type": "u64"
3099-
},
3100-
{
3101-
"name": "minimum_lamports_out",
3102-
"type": "u64"
3103-
}
3104-
]
3105-
}
3106-
]
3107-
}
3108-
},
31092858
{
31102859
"name": "Ballot",
31112860
"type": {
@@ -3684,6 +3433,33 @@
36843433
}
36853434
]
36863435
}
3436+
},
3437+
{
3438+
"name": "StakePoolInstruction",
3439+
"type": {
3440+
"kind": "enum",
3441+
"variants": [
3442+
{
3443+
"name": "DepositSol",
3444+
"fields": [
3445+
"u64"
3446+
]
3447+
},
3448+
{
3449+
"name": "DepositSolWithSlippage",
3450+
"fields": [
3451+
{
3452+
"name": "lamports_in",
3453+
"type": "u64"
3454+
},
3455+
{
3456+
"name": "minimum_pool_tokens_out",
3457+
"type": "u64"
3458+
}
3459+
]
3460+
}
3461+
]
3462+
}
36873463
}
36883464
],
36893465
"errors": [

integration_tests/tests/fixtures/test_builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ use jito_tip_router_core::{
1414
epoch_state::EpochState,
1515
ncn_fee_group::NcnFeeGroup,
1616
ncn_reward_router::{NcnRewardReceiver, NcnRewardRouter},
17+
spl_stake_pool::find_withdraw_authority_program_address,
1718
weight_table::WeightTable,
1819
};
19-
use jito_tip_router_program::find_withdraw_authority_program_address;
2020
use solana_commitment_config::CommitmentLevel;
2121
use solana_program::{
2222
clock::Clock, native_token::sol_str_to_lamports, program_pack::Pack, pubkey::Pubkey,

integration_tests/tests/fixtures/tip_router_client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ use jito_tip_router_core::{
3535
error::TipRouterError,
3636
ncn_fee_group::NcnFeeGroup,
3737
ncn_reward_router::{NcnRewardReceiver, NcnRewardRouter},
38+
spl_stake_pool::find_withdraw_authority_program_address,
3839
vault_registry::VaultRegistry,
3940
weight_table::WeightTable,
4041
};
41-
use jito_tip_router_program::find_withdraw_authority_program_address;
4242
use jito_vault_core::{
4343
vault_ncn_ticket::VaultNcnTicket, vault_operator_delegation::VaultOperatorDelegation,
4444
};

0 commit comments

Comments
 (0)