Skip to content

program: Add delegate support to unwrap_lamports#1061

Merged
febo merged 3 commits into
mainfrom
febo/unwrap-lamports-delegate
Mar 25, 2026
Merged

program: Add delegate support to unwrap_lamports#1061
febo merged 3 commits into
mainfrom
febo/unwrap-lamports-delegate

Conversation

@febo
Copy link
Copy Markdown
Contributor

@febo febo commented Mar 25, 2026

Problem

Currently it is not possible to use a delegate to unwrap_lamports.

Solution

Add delegate support to unwrap_lamports. The delegate implementation works similarly to how it works on transfer:

  • delegates can only unwrap up to the amount delegated
  • when the delegated amount reaches 0, the delegate is cleared

This brings the implementation in-line with p-token (solana-program/token#120).

@febo febo requested a review from joncinque March 25, 2026 02:47
@joncinque joncinque changed the title Add delegate support to unwrap_lamports program: Add delegate support to unwrap_lamports Mar 25, 2026
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.

Just a nit, looks great overall!

/// * Single owner/delegate
/// 0. `[writable]` The source account.
/// 1. `[writable]` The destination account.
/// 2. `[signer]` The source account's owner/delegate.
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.

Haha I didn't realize we even advertised it here

Comment thread program/src/processor.rs Outdated
Comment on lines +1786 to +1788
if delegated_amount < amount {
return Err(TokenError::InsufficientFunds.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.

nit: Do we need this check? we're doing a checked_sub anyway, so may as well just change the error to TokenError::InsufficientFunds on the checked math and remove this check

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 great!

@febo febo merged commit 2e1d650 into main Mar 25, 2026
40 checks passed
@febo febo deleted the febo/unwrap-lamports-delegate branch March 27, 2026 10:46
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.

2 participants