-
Notifications
You must be signed in to change notification settings - Fork 2
feat(wasm-solana): add transaction building support #113
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
02904b6 to
5bff3d8
Compare
OttoAllmendinger
left a comment
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.
make sure we use bigint instead of string when dealing with amounts
packages/wasm-solana/js/builder.ts
Outdated
| /** Lamports to transfer (as string) */ | ||
| lamports: string; |
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.
bigint
packages/wasm-solana/js/builder.ts
Outdated
| /** Amount in lamports to withdraw (as string) */ | ||
| lamports: string; |
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.
bigint
| use solana_system_interface::instruction::{self as system_ix, SystemInstruction}; | ||
| use spl_stake_pool::instruction::StakePoolInstruction; | ||
|
|
||
| /// Well-known program IDs and sysvars |
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.
where are these defined?
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.
added links
6a37e03 to
3ea21e0
Compare
… support This commit adds comprehensive transaction building capabilities to wasm-solana, enabling the construction of both legacy and versioned (MessageV0) Solana transactions without requiring @solana/web3.js dependency. ## Transaction Building ### Core Builder (Rust) - `src/builder/build.rs` - Main transaction building logic from TransactionIntent - `src/builder/types.rs` - Type definitions (TransactionIntent, Instruction, Nonce, etc.) - `src/builder/versioned.rs` - MessageV0/versioned transaction building from raw data ### Supported Instructions - Transfer (SOL and SPL tokens) - CreateAssociatedTokenAccount - StakingActivate, StakingDeactivate, StakingWithdraw - StakingAuthorize, StakingAuthorizeRaw - StakingPartialDeactivate (split + deactivate) - StakingSplit - AdvanceNonceAccount (durable nonce support) - Memo - SetComputeUnitLimit, SetComputeUnitPrice - TokenTransfer (SPL Token Program transfers) - CustomInstruction (raw instruction support) ### TypeScript API (`js/builder.ts`) - `buildTransaction()` - Build transactions from high-level intents - Type definitions for all instruction kinds and nonce sources - Support for Address Lookup Tables in versioned transactions ## Versioned Transaction Support ### Parsing (`js/versioned.ts`, `src/versioned.rs`) - `VersionedTransaction` class for parsing both legacy and MessageV0 transactions - `isVersionedTransaction()` utility to detect transaction format - Extract Address Lookup Tables, static account keys, and instructions - Support for adding signatures to parsed transactions ### Building from Raw Data - `buildFromRawVersionedData()` - Build MessageV0 from pre-compiled instruction data - Preserves account indexes, ALT references, and message header from source - Enables rebuilding transactions with different blockhash/nonce ## WASM Exports ### Constants (`src/wasm/constants.rs`) - Program IDs: systemProgramId, tokenProgramId, token2022ProgramId, etc. - Sysvar addresses: sysvarClockAddress, sysvarRecentBlockhashes, etc. - Well-known addresses: memoV1ProgramId, associatedTokenProgramId, etc. ### Builder Functions (`src/wasm/builder.rs`) - `buildTransaction()` - WASM entry point for transaction building - `buildFromRawVersionedData()` - WASM entry point for versioned building ### Transaction Methods - `serializeMessage()` - Returns message bytes for web3.js API compatibility - Property-based API (feePayer, recentBlockhash, signatures) - `CustomInstruction` type for passing raw instructions to builder ## Additional Changes ### CreateATA Fix - Fixed `programId` return value for CreateAssociatedTokenAccount instructions - Now correctly returns Token Program ID instead of ATA Program ID ### Stake Split Support - Added `StakeSplitIntent` for stake account splitting - Proper handling of split instruction in both building and parsing ### Test Coverage - `test/builder.ts` - Comprehensive builder tests (693 lines) - `test/versioned.ts` - Versioned transaction tests - `test/transaction.ts` - Extended transaction tests with building ## Architecture The builder follows an intent-based architecture: 1. Caller creates a `TransactionIntent` with fee payer, nonce, and instructions 2. Builder converts intents to native Solana instructions 3. Transaction is serialized as legacy or versioned based on ALT presence 4. Returns raw transaction bytes for signing This design eliminates @solana/web3.js dependency while maintaining full compatibility with the Solana transaction format.
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.
if we already expose a Transaction type, maybe we should return that here instead of the serialized for of it? The caller can serialize if they need
This commit adds comprehensive transaction building capabilities to wasm-solana,
enabling the construction of both legacy and versioned (MessageV0) Solana
transactions without requiring @solana/web3.js dependency.
Transaction Building
Core Builder (Rust)
src/builder/build.rs- Main transaction building logic from TransactionIntentsrc/builder/types.rs- Type definitions (TransactionIntent, Instruction, Nonce, etc.)src/builder/versioned.rs- MessageV0/versioned transaction building from raw dataSupported Instructions
TypeScript API (
js/builder.ts)buildTransaction()- Build transactions from high-level intentsVersioned Transaction Support
Parsing (
js/versioned.ts,src/versioned.rs)VersionedTransactionclass for parsing both legacy and MessageV0 transactionsisVersionedTransaction()utility to detect transaction formatBuilding from Raw Data
buildFromRawVersionedData()- Build MessageV0 from pre-compiled instruction dataWASM Exports
Constants (
src/wasm/constants.rs)Builder Functions (
src/wasm/builder.rs)buildTransaction()- WASM entry point for transaction buildingbuildFromRawVersionedData()- WASM entry point for versioned buildingTransaction Methods
serializeMessage()- Returns message bytes for web3.js API compatibilityCustomInstructiontype for passing raw instructions to builderAdditional Changes
CreateATA Fix
programIdreturn value for CreateAssociatedTokenAccount instructionsStake Split Support
StakeSplitIntentfor stake account splittingTest Coverage
test/builder.ts- Comprehensive builder tests (693 lines)test/versioned.ts- Versioned transaction teststest/transaction.ts- Extended transaction tests with buildingArchitecture
The builder follows an intent-based architecture:
TransactionIntentwith fee payer, nonce, and instructionsThis design eliminates @solana/web3.js dependency while maintaining full
compatibility with the Solana transaction format.