Skip to content

Commit d0bfddb

Browse files
committed
XXX ixn introspection
1 parent 95decf7 commit d0bfddb

4 files changed

Lines changed: 44 additions & 43 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

program/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ solana-borsh = "3.0"
2323
solana-clock = "3.0"
2424
solana-cpi = "3.1"
2525
solana-instruction = "3.0"
26+
solana-instructions-sysvar = "3.0"
2627
solana-msg = "3.1"
2728
solana-native-token = "3.0"
2829
solana-program-entrypoint = "3.1"

program/src/instruction.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ pub enum SinglePoolInstruction {
166166
/// 5. `[]` Stake program
167167
InitializePoolOnRamp,
168168

169+
/// HANA fix if we do this
169170
/// Deposit liquid sol into the pool. The output is a "pool" token
170171
/// representing fractional ownership of the pool stake. Inputs are
171172
/// converted to the current ratio, less a fee of `DEPOSIT_SOL_FEE_BPS`.
@@ -386,6 +387,7 @@ pub fn deposit_liquid(
386387
user_token_account,
387388
lamports,
388389
),
390+
replenish_pool(program_id, vote_account_address),
389391
]
390392
}
391393

@@ -399,33 +401,25 @@ pub fn deposit_sol(
399401
user_token_account: &Pubkey,
400402
lamports: u64,
401403
) -> Instruction {
404+
// HANA pass pool directly
402405
let pool_address = find_pool_address(program_id, vote_account_address);
403406

404407
let data = borsh::to_vec(&SinglePoolInstruction::DepositSol { lamports }).unwrap();
405408
let accounts = vec![
406-
AccountMeta::new_readonly(*vote_account_address, false),
407409
AccountMeta::new_readonly(pool_address, false),
408-
AccountMeta::new(find_pool_stake_address(program_id, &pool_address), false),
410+
AccountMeta::new_readonly(find_pool_stake_address(program_id, &pool_address), false),
409411
AccountMeta::new(find_pool_onramp_address(program_id, &pool_address), false),
410412
AccountMeta::new(find_pool_mint_address(program_id, &pool_address), false),
411-
AccountMeta::new_readonly(
412-
find_pool_stake_authority_address(program_id, &pool_address),
413-
false,
414-
),
415413
AccountMeta::new_readonly(
416414
find_pool_mint_authority_address(program_id, &pool_address),
417415
false,
418416
),
419417
AccountMeta::new(*user_deposit_account, true),
420418
AccountMeta::new(*user_token_account, false),
421-
AccountMeta::new_readonly(sysvar::clock::id(), false),
422-
AccountMeta::new_readonly(stake_history::id(), false),
423-
#[allow(deprecated)]
424-
AccountMeta::new_readonly(stake::config::id(), false),
425419
AccountMeta::new_readonly(system_program::id(), false),
426420
AccountMeta::new_readonly(spl_token::id(), false),
427421
AccountMeta::new_readonly(stake::program::id(), false),
428-
AccountMeta::new_readonly(*program_id, false),
422+
AccountMeta::new_readonly(solana_instructions_sysvar::id(), false),
429423
];
430424

431425
Instruction {

program/src/processor.rs

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)