Skip to content

Conversation

@abelmarnk
Copy link

Background

This PR adds the unwrap_lamports instruction originally proposed here to the Token-2022 program. It also addresses and closes issue #773.

Problem

In order to transfer out lamports from native SOL accounts, currently it is necessary to create and close ATAs or token accounts all the time.

Solution

This PR adds a new unwrap_lamports instruction that allows transferring out lamports directly to any destination account. This eliminates the need for creating temporary native token accounts for the recipient.

The new instruction uses the discriminator 45, which is currently unused in Token-2022.

The amount to unwrap is specified as an Option<u64>:

None: the entire token balance is unwrap
Some(amount): the specified amount is unwrap

Scope

  • Add instruction builder and associated tests
  • Add the POD type and helpers with tests
  • Add instruction processor associated tests
  • Update the Rust legacy test helpers
  • Update the Rust legacy tests
  • Update JS & JS legacy implementations
  • Update auto-generated code
  • Update CLI functionality and CLI tests

@abelmarnk
Copy link
Author

@joncinque 🙏 Could I get a high level review of this before I mark it ready for review?

Copy link
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.

This was in such good shape that I gave it a full review. Thanks for your contribution, and for making it so complete!

Most of the comments are pretty minor, so we should be able to land this pretty quickly.

cc @febo to also give it a look since he wrote the p-token implementation

@joncinque joncinque requested a review from febo November 26, 2025 21:51
@abelmarnk
Copy link
Author

abelmarnk commented Nov 27, 2025

I've made the changes, i'll resolve the conversation with the commit references after the last comment(the one about the p-token implementation) has been resolved since it would affect most of the code.

@abelmarnk abelmarnk marked this pull request as ready for review December 2, 2025 14:07
Copy link
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 couple of last bits, then this is good to on my side!

@joncinque
Copy link
Contributor

Can you re-run client generation and commit the results? Looks like there's a failure on that job. pnpm i && make generate-clients should do it.

Otherwise, the rust legacy tests are failing at the end due to running out of space, so that shouldn't be your problem 😄

Let's get final approval from @febo too before merging.

@abelmarnk
Copy link
Author

The commits have gotten quite large, would it be better to squash them?

joncinque
joncinque previously approved these changes Dec 3, 2025
Copy link
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, thanks for all your work! We squash on merging, but that leaves one line per commit in the final commit message, so feel free to rewrite history if you like.

Once @febo approves too, we'll merge

Copy link
Contributor

@febo febo left a comment

Choose a reason for hiding this comment

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

Looks very good – left few small nits.

Co-authored-by: Fernando Otero <[email protected]>
@abelmarnk
Copy link
Author

Looks very good – left few small nits.

The fixes have been made, thanks for the review!

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.

3 participants