Skip to content

Conversation

grod220
Copy link
Member

@grod220 grod220 commented Apr 1, 2025

Final CLI helper: Unwrap instruction. Converts wrapped tokens back into the original unwrapped version.

Walkthrough for testing locally:

  1. Build program and binary
cargo build-sbf && cargo build
  1. Start solana test validator
solana-test-validator \
  --bpf-program TwRapQCDhWkZRrDaHfZGuHxkZ91gHDRkyuzNqeU5MgR target/deploy/spl_token_wrap.so \
  --reset
  1. Create a new mint & token account
spl-token create-token
# mint addr -> 8XFsJ3v6zycqQaxhmgLQtYrYNCxL52q8ERWeZHNh3EDv
spl-token create-account 8XFsJ3v6zycqQaxhmgLQtYrYNCxL52q8ERWeZHNh3EDv 
# token account -> J3enKxioWoZqJP8CpZGmJhq2YwTvzopuiWYu4Rb97rst
spl-token mint 8XFsJ3v6zycqQaxhmgLQtYrYNCxL52q8ERWeZHNh3EDv 100000
  1. Run CreateMint token-wrap command
cargo run --bin spl-token-wrap create-mint \
    8XFsJ3v6zycqQaxhmgLQtYrYNCxL52q8ERWeZHNh3EDv \
    TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA \
    TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb

# Keep note of console output
# Wrapped mint address: 3KdPWyHmyVDThDjf4jE6m4sxmgYev9sSG74GW9BcFyK9
  1. Find PDAs
cargo run --bin spl-token-wrap find-pdas 8XFsJ3v6zycqQaxhmgLQtYrYNCxL52q8ERWeZHNh3EDv TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb

# note wrapped mint authority
# Wrapped mint authority: 4WGS8PTY9fetLDY9nn3wBUWSGm92ysX5TaR3svKCPneQ
  1. Create an escrow token account and set its owner to the mint_authority
spl-token create-account 8XFsJ3v6zycqQaxhmgLQtYrYNCxL52q8ERWeZHNh3EDv --owner 4WGS8PTY9fetLDY9nn3wBUWSGm92ysX5TaR3svKCPneQ --fee-payer /Users/gabe/.config/solana/id.json

# Escrow: 5GcUo7Dk2kdoZc1MD5gwXrbpufm3VoXZj7qLda62g6Qe
  1. Create a recipient token account of that new wrapped mint
spl-token create-account 3KdPWyHmyVDThDjf4jE6m4sxmgYev9sSG74GW9BcFyK9 --program-id TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb

# recipient account: EJPFBmkU7gnV2KmaQwQsm3sgY3BqMqknRQYGeJ4Ac7Bx
  1. Issue Wrap command
spl-token-wrap wrap <UNWRAPPED_TOKEN_ACCOUNT> <ESCROW_ACCOUNT> <WRAPPED_TOKEN_PROGRAM> <AMOUNT>

cargo run --bin spl-token-wrap wrap J3enKxioWoZqJP8CpZGmJhq2YwTvzopuiWYu4Rb97rst 5GcUo7Dk2kdoZc1MD5gwXrbpufm3VoXZj7qLda62g6Qe TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb 55
  1. Issue Unwrap command
spl-token-wrap wrap <WRAPPED_TOKEN_ACCOUNT> <ESCROW_ACCOUNT> <UNWRAPPED_TOKEN_RECIPIENT> <AMOUNT>

cargo run --bin spl-token-wrap unwrap EJPFBmkU7gnV2KmaQwQsm3sgY3BqMqknRQYGeJ4Ac7Bx 5GcUo7Dk2kdoZc1MD5gwXrbpufm3VoXZj7qLda62g6Qe J3enKxioWoZqJP8CpZGmJhq2YwTvzopuiWYu4Rb97rst 25

@grod220 grod220 force-pushed the cli-wrap-multisig branch from 59b308c to 4db885c Compare April 3, 2025 14:36
Base automatically changed from cli-wrap-multisig to main April 4, 2025 06:21
@grod220 grod220 marked this pull request as ready for review April 4, 2025 07:48
@grod220 grod220 requested review from joncinque and buffalojoec April 4, 2025 07:48
Copy link

@buffalojoec buffalojoec left a comment

Choose a reason for hiding this comment

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

Nice!! I think this looks great.

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 really good! Mostly small things

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 few last things, looking really close!

Comment on lines 40 to 42
/// The address of the token account to receive the unwrapped tokens
#[clap(value_parser = parse_pubkey)]
pub unwrapped_token_recipient: Pubkey,
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be done in a separate command, but it would be good to have a way to find out: "Given a mint address, is this a wrapped token mint? If so, what's it wrapping?"

@grod220 grod220 requested review from joncinque and buffalojoec and removed request for buffalojoec April 9, 2025 13:48
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 good to me!

@grod220 grod220 merged commit 4bc5de9 into main Apr 9, 2025
10 checks passed
@grod220 grod220 deleted the cli-unwrap branch April 9, 2025 14:15
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