Commit 3ea21e0
committed
feat(wasm-solana): add transaction building and versioned transaction 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.1 parent fbc7c4a commit 3ea21e0
File tree
26 files changed
+6346
-144
lines changed- packages/wasm-solana
- js
- src
- builder
- instructions
- wasm
- test
26 files changed
+6346
-144
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
21 | 28 | | |
22 | 29 | | |
23 | 30 | | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
| 31 | + | |
| 32 | + | |
29 | 33 | | |
30 | 34 | | |
31 | 35 | | |
32 | 36 | | |
| 37 | + | |
33 | 38 | | |
| 39 | + | |
34 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
35 | 44 | | |
36 | 45 | | |
37 | 46 | | |
| |||
Binary file not shown.
0 commit comments