- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.8k
          feat(solana): Add SolanaTransaction.insertTransferInstruction()
          #4523
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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_payerfield toSigningInputproto for optional SOL transfers to fee payers
- Implemented insert_transfer_instructionmethod inSolanaTransactionfor 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_payerfield toSigningInputmessage | 
| 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_instructionmethod with address parsing and instruction insertion | 
| rust/chains/tw_solana/src/modules/message_builder.rs | Added transfer_to_fee_payermethod and integrated sponsored transfers into all transaction builders | 
| rust/chains/tw_solana/src/modules/instruction_builder/mod.rs | Added maybe_add_instructionmethod 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_numberdependency for U256 parsing | 
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| Hi @10gic, thank you so much for the  | 
| 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 | 
There was a problem hiding this 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?
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:
transfer_to_fee_payerfield to transaction inputs, and implemented thetransfer_to_fee_payermethod inMessageBuilderto conditionally create and append a sponsored transfer instruction when requested. TheInstructionBuildernow includes a newmaybe_add_instructionmethod to facilitate optional instruction addition. [1] [2]MessageBuilder(e.g., token transfer, deposit, withdraw, deactivate, etc.) to callmaybe_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:
insert_transfer_instructiontoSolanaTransaction, enabling insertion of a transfer instruction at a specified index in an encoded transaction. This is also exposed via FFI astw_solana_transaction_insert_transfer_instruction. [1] [2]tw_numberfor U256 parsing andSystemInstructionBuilderfor transfer construction. [1] [2]Account permission validation improvements:
InsertInstructionto 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:
test_solana_sign_sponsored_transfer), verifying correct encoding and behavior.These changes collectively enable more flexible transaction construction in Solana, especially for scenarios involving external fee payers or custom transaction flows.