Skip to content

program: deposit sol#631

Open
2501babe wants to merge 3 commits intosolana-program:mainfrom
2501babe:20260417_depositsol
Open

program: deposit sol#631
2501babe wants to merge 3 commits intosolana-program:mainfrom
2501babe:20260417_depositsol

Conversation

@2501babe
Copy link
Copy Markdown
Member

@2501babe 2501babe commented Apr 17, 2026

the latest. the greatest. it needs no further introduction. god knows ive talked about it too much already. deposit sol

closes #46

@2501babe 2501babe self-assigned this Apr 17, 2026
@2501babe 2501babe force-pushed the 20260417_depositsol branch 3 times, most recently from fa0b257 to 1e0b60b Compare April 18, 2026 08:01
@2501babe 2501babe force-pushed the 20260417_depositsol branch 5 times, most recently from 5ff8680 to 310dc5c Compare April 21, 2026 10:44
@2501babe 2501babe marked this pull request as ready for review April 21, 2026 10:45
@2501babe 2501babe requested a review from joncinque April 21, 2026 10:45
`DepositSol` is a new instruction that allows depositing liquid sol directly into the pool onramp for a fee, calculated by underminting tokens to spread the benefit to all existing holders
@2501babe 2501babe force-pushed the 20260417_depositsol branch from 310dc5c to 5542960 Compare April 22, 2026 14:51
Copy link
Copy Markdown
Contributor

@joncinque joncinque left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really great! Just a couple of small things

Comment thread clients/cli/src/cli.rs
/// Lamports to deposit into pool
pub lamports: u64,

/// The pool to withdraw from
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
/// The pool to withdraw from
/// The pool to deposit into

Comment thread clients/cli/src/cli.rs
#[clap(short, long = "pool", value_parser = |p: &str| parse_address(p, "pool_address"))]
pub pool_address: Option<Pubkey>,

/// The vote account corresponding to the pool to withdraw from
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
/// The vote account corresponding to the pool to withdraw from
/// The vote account corresponding to the pool to deposit into

Comment thread clients/cli/src/main.rs
.is_none()
{
return Err(format!(
"Pool {} onramp {} does not exist",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: is it worth telling people what to do? ie "Run spl-single-pool create-onramp ..."

Comment thread program/src/lib.rs
Comment on lines +18 to +19
/// Fee charged for the `DepositSol` instruction.
pub const DEPOSIT_SOL_FEE_BPS: u64 = 100;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me! I think we could get away with 50 bps, especially considering inflation going down over time, but that could also be done in another upgrade

}

interface DepositSolParams {
rpc: Rpc<GetAccountInfoApi & GetMinimumBalanceForRentExemptionApi & GetStakeMinimumDelegationApi>;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think this only needs GetAccountInfoApi

Suggested change
rpc: Rpc<GetAccountInfoApi & GetMinimumBalanceForRentExemptionApi & GetStakeMinimumDelegationApi>;
rpc: Rpc<GetAccountInfoApi>;

Comment thread program/src/processor.rs
Comment on lines +1651 to +1656
// we round division down and reject deposits too small to generate a fee
// this is to avoid pathological cases where eg someone deposits 2 lamps and pays 50%
let deposit_sol_fee = raw_tokens
.checked_mul(DEPOSIT_SOL_FEE_BPS)
.and_then(|n| n.checked_div(MAX_BPS))
.ok_or(SinglePoolError::UnexpectedMathError)?;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend a ceil_div on this calculation so that we always take a little bit more.

Because of the 0 check later, it's impossible for someone to deposit less than 100 lamports anyway, which is a slick touch

Comment thread program/src/processor.rs
Comment on lines +1682 to +1696
// replenish to delegate the deposit. this safely returns Ok if onramp doesnt meet minimum delegation
invoke(
&svsp_instruction::replenish_pool(program_id, vote_account_info.key),
&[
vote_account_info.clone(),
pool_info.clone(),
pool_stake_info.clone(),
pool_onramp_info.clone(),
pool_stake_authority_info.clone(),
clock_info.clone(),
stake_history_info.clone(),
stake_config_info.clone(),
stake_program_info.clone(),
],
)?;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't typically perform re-entrancy in our programs, so just flagging the behavior, but I can't see a reason why it would be a problem

Comment thread program/src/processor.rs
Comment on lines +1621 to +1627
// deposit source must be a system account for transfer to succeed
if !user_lamport_account_info.is_signer
|| user_lamport_account_info.owner != &system_program::id()
|| user_lamport_account_info.lamports() < deposit_amount
{
return Err(SinglePoolError::InvalidDepositSolSource.into());
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure about these checks, but it's probably good to make sure one of the program accounts isn't weirdly compromised through the operation

AccountMeta::new_readonly(system_program::id(), false),
AccountMeta::new_readonly(spl_token::id(), false),
AccountMeta::new_readonly(stake::program::id(), false),
AccountMeta::new_readonly(*program_id, false),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this actually needed for re-entrancy? Since the JS client seem ok without it, I'm going to guess not

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

program: allow sol deposit

2 participants