@@ -1550,39 +1550,27 @@ impl Processor {
15501550 deposit_amount : u64 ,
15511551 ) -> ProgramResult {
15521552 let account_info_iter = & mut accounts. iter ( ) ;
1553- let vote_account_info = next_account_info ( account_info_iter) ?;
15541553 let pool_info = next_account_info ( account_info_iter) ?;
15551554 let pool_stake_info = next_account_info ( account_info_iter) ?;
15561555 let pool_onramp_info = next_account_info ( account_info_iter) ?;
15571556 let pool_mint_info = next_account_info ( account_info_iter) ?;
1558- let pool_stake_authority_info = next_account_info ( account_info_iter) ?;
15591557 let pool_mint_authority_info = next_account_info ( account_info_iter) ?;
15601558 let user_lamport_account_info = next_account_info ( account_info_iter) ?;
15611559 let user_token_account_info = next_account_info ( account_info_iter) ?;
1562- let clock_info = next_account_info ( account_info_iter) ?;
1563- let clock = & Clock :: from_account_info ( clock_info) ?;
1564- let stake_history_info = next_account_info ( account_info_iter) ?;
1565- let stake_config_info = next_account_info ( account_info_iter) ?;
15661560 let system_program_info = next_account_info ( account_info_iter) ?;
15671561 let token_program_info = next_account_info ( account_info_iter) ?;
15681562 let stake_program_info = next_account_info ( account_info_iter) ?;
1563+ let result_instructions_info = next_account_info ( account_info_iter) ;
15691564
15701565 let rent = Rent :: get ( ) ?;
1566+ let clock = Clock :: get ( ) ?;
15711567 let stake_history = & StakeHistorySysvar ( clock. epoch ) ;
15721568
1573- check_vote_account ( vote_account_info) ?;
1574- check_pool_address ( program_id, vote_account_info. key , pool_info. key ) ?;
1575-
15761569 SinglePool :: from_account_info ( pool_info, program_id) ?;
15771570
15781571 check_pool_stake_address ( program_id, pool_info. key , pool_stake_info. key ) ?;
15791572 check_pool_onramp_address ( program_id, pool_info. key , pool_onramp_info. key ) ?;
15801573 let token_supply = check_pool_mint_with_supply ( program_id, pool_info. key , pool_mint_info) ?;
1581- check_pool_stake_authority_address (
1582- program_id,
1583- pool_info. key ,
1584- pool_stake_authority_info. key ,
1585- ) ?;
15861574 let mint_authority_bump_seed = check_pool_mint_authority_address (
15871575 program_id,
15881576 pool_info. key ,
@@ -1592,6 +1580,9 @@ impl Processor {
15921580 check_token_program ( token_program_info. key ) ?;
15931581 check_stake_program ( stake_program_info. key ) ?;
15941582
1583+ let minimum_delegation = stake:: tools:: get_minimum_delegation ( ) ?;
1584+ let onramp_rent_exempt_reserve = rent. minimum_balance ( pool_onramp_info. data_len ( ) ) ;
1585+
15951586 if deposit_amount == 0 {
15961587 return Err ( SinglePoolError :: DepositTooSmall . into ( ) ) ;
15971588 }
@@ -1613,10 +1604,15 @@ impl Processor {
16131604 } ;
16141605
16151606 // we require onramp to exist, though we dont care what state its in
1616- match deserialize_stake ( pool_onramp_info) {
1617- Ok ( StakeStateV2 :: Initialized ( _) ) | Ok ( StakeStateV2 :: Stake ( _, _, _) ) => ( ) ,
1607+ let pre_onramp_stake = match deserialize_stake ( pool_onramp_info) {
1608+ Ok ( StakeStateV2 :: Stake ( _, Stake { delegation, .. } , _) )
1609+ if delegation. deactivation_epoch == u64:: MAX =>
1610+ {
1611+ delegation. stake
1612+ }
1613+ Ok ( StakeStateV2 :: Stake ( _, _, _) ) | Ok ( StakeStateV2 :: Initialized ( _) ) => 0 ,
16181614 _ => return Err ( SinglePoolError :: OnRampDoesntExist . into ( ) ) ,
1619- }
1615+ } ;
16201616
16211617 // deposit source must be a system account for transfer to succeed
16221618 if !user_lamport_account_info. is_signer
@@ -1679,21 +1675,30 @@ impl Processor {
16791675 new_pool_tokens,
16801676 ) ?;
16811677
1682- // replenish to delegate the deposit. this safely returns Ok if onramp doesnt meet minimum delegation
1683- invoke (
1684- & svsp_instruction:: replenish_pool ( program_id, vote_account_info. key ) ,
1685- & [
1686- vote_account_info. clone ( ) ,
1687- pool_info. clone ( ) ,
1688- pool_stake_info. clone ( ) ,
1689- pool_onramp_info. clone ( ) ,
1690- pool_stake_authority_info. clone ( ) ,
1691- clock_info. clone ( ) ,
1692- stake_history_info. clone ( ) ,
1693- stake_config_info. clone ( ) ,
1694- stake_program_info. clone ( ) ,
1695- ] ,
1696- ) ?;
1678+ // if there is at least minimum delegation idle, we require replenish
1679+ if pool_onramp_info
1680+ . lamports ( )
1681+ . saturating_sub ( pre_onramp_stake)
1682+ . saturating_sub ( onramp_rent_exempt_reserve)
1683+ >= minimum_delegation
1684+ {
1685+ let instructions_info = result_instructions_info?;
1686+
1687+ let current_index =
1688+ solana_instructions_sysvar:: load_current_index_checked ( & instructions_info) ?;
1689+
1690+ let replenish_instruction = solana_instructions_sysvar:: load_instruction_at_checked (
1691+ current_index. saturating_add ( 1 ) as usize ,
1692+ & instructions_info,
1693+ ) ?;
1694+
1695+ if & replenish_instruction. program_id != program_id
1696+ || replenish_instruction. data != [ 1 ]
1697+ || & replenish_instruction. accounts [ 1 ] . pubkey != pool_info. key
1698+ {
1699+ panic ! ( "HANA new err" ) ;
1700+ }
1701+ }
16971702
16981703 Ok ( ( ) )
16991704 }
0 commit comments