Skip to content

Conversation

@satoshiotomakan
Copy link
Collaborator

This pull request introduces support for sponsored transfers in Solana transactions, allowing an additional transfer to a fee payer to be included in various transaction types. It also adds a utility for programmatically inserting transfer instructions at arbitrary positions in a transaction, improves account permission validation logic, and updates the FFI interface to expose the new functionality.

Sponsored transfer support and builder enhancements:

  • Added the transfer_to_fee_payer field to transaction inputs, and implemented the transfer_to_fee_payer method in MessageBuilder to conditionally create and append a sponsored transfer instruction when requested. The InstructionBuilder now includes a new maybe_add_instruction method to facilitate optional instruction addition. [1] [2]
  • Updated all transaction builder flows in MessageBuilder (e.g., token transfer, deposit, withdraw, deactivate, etc.) to call maybe_add_instruction(self.transfer_to_fee_payer()?), ensuring the sponsored transfer is included when present. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12]

Transaction utility and FFI interface:

  • Added insert_transfer_instruction to SolanaTransaction, enabling insertion of a transfer instruction at a specified index in an encoded transaction. This is also exposed via FFI as tw_solana_transaction_insert_transfer_instruction. [1] [2]
  • Updated dependencies and imports to support new functionality, including tw_number for U256 parsing and SystemInstructionBuilder for transfer construction. [1] [2]

Account permission validation improvements:

  • Refactored logic in InsertInstruction to use pattern matching for signer/writable permission checks, and clarified error handling and comments for cases where stronger permissions would require account reordering (with a TODO for future implementation). [1] [2]

Testing:

  • Added a new test for sponsored token transfers (test_solana_sign_sponsored_transfer), verifying correct encoding and behavior.
  • Updated FFI transaction tests to cover the new sponsored transfer and instruction insertion functionality. [1] [2]

These changes collectively enable more flexible transaction construction in Solana, especially for scenarios involving external fee payers or custom transaction flows.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces sponsored transfer support for Solana transactions, allowing SOL transfers to fee payers to be included in various transaction types. The implementation adds a new transfer_to_fee_payer field to signing inputs and provides programmatic insertion of transfer instructions at arbitrary positions.

Key changes include:

  • Added transfer_to_fee_payer field to SigningInput proto for optional SOL transfers to fee payers
  • Implemented insert_transfer_instruction method in SolanaTransaction for programmatically inserting transfer instructions
  • Enhanced all transaction builder flows to conditionally include sponsored transfers when specified

Reviewed Changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/proto/Solana.proto Added transfer_to_fee_payer field to SigningInput message
rust/wallet_core_rs/src/ffi/solana/transaction.rs Added FFI function tw_solana_transaction_insert_transfer_instruction
rust/tw_tests/tests/chains/solana/solana_transaction_ffi.rs Added test for new transfer instruction insertion functionality
rust/tw_tests/tests/chains/solana/solana_sign.rs Added test for sponsored transfer transaction signing
rust/chains/tw_solana/src/modules/utils.rs Implemented insert_transfer_instruction method with address parsing and instruction insertion
rust/chains/tw_solana/src/modules/message_builder.rs Added transfer_to_fee_payer method and integrated sponsored transfers into all transaction builders
rust/chains/tw_solana/src/modules/instruction_builder/mod.rs Added maybe_add_instruction method for conditional instruction addition
rust/chains/tw_solana/src/modules/insert_instruction.rs Refactored account permission validation using pattern matching
rust/chains/tw_solana/Cargo.toml Added tw_number dependency for U256 parsing

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@satoshiotomakan
Copy link
Collaborator Author

Hi @10gic, thank you so much for the SolanaTransaction.insertInstruction() FFI, it's very useful!
I made a minor change, please take a look when you have time

@github-actions
Copy link

github-actions bot commented Oct 9, 2025

Binary size comparison

➡️ aarch64-apple-ios:

- 14.15 MB
+ 14.16 MB 	 +10 KB

➡️ aarch64-apple-ios-sim:

- 14.16 MB
+ 14.17 MB 	 +10 KB

➡️ aarch64-linux-android:

- 18.64 MB
+ 18.65 MB 	 +14 KB

➡️ armv7-linux-androideabi:

- 15.59 MB
+ 15.60 MB 	 +9 KB

➡️ wasm32-unknown-emscripten:

- 13.29 MB
+ 13.30 MB 	 +12 KB

Copy link
Collaborator

@gupnik gupnik left a comment

Choose a reason for hiding this comment

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

@satoshiotomakan Added a comment about compute limit/price instructions. Could you please take a look?

@satoshiotomakan satoshiotomakan merged commit bb49d06 into master Oct 10, 2025
15 checks passed
@satoshiotomakan satoshiotomakan deleted the feat/solana-sponsorable-transaction branch October 10, 2025 07:44
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