Skip to content

Commit 3ea21e0

Browse files
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

26 files changed

+6346
-144
lines changed

packages/wasm-solana/Cargo.lock

Lines changed: 964 additions & 74 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/wasm-solana/Cargo.toml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,30 @@ wasm-bindgen = "0.2"
1717
js-sys = "0.3"
1818
serde = { version = "1.0", features = ["derive"] }
1919
serde_json = "1.0"
20-
# Solana SDK crates
20+
# Solana 3.x crates (for transaction building)
21+
solana-sdk = { version = "3.0", default-features = false, features = ["full"] }
22+
solana-transaction = { version = "3.0", features = ["serde", "bincode"] }
23+
solana-message = { version = "3.0", features = ["serde", "bincode"] }
24+
solana-system-interface = { version = "3.0", features = ["bincode"] }
25+
solana-compute-budget-interface = { version = "3.0", features = ["borsh"] }
26+
# Solana 2.x crates (no 3.x available yet for these)
27+
solana-stake-interface = { version = "2.0", features = ["bincode"] }
2128
solana-pubkey = { version = "2.0", features = ["curve25519"] }
2229
solana-keypair = "2.0"
2330
solana-signer = "2.0"
24-
solana-transaction = { version = "3.0", features = ["serde", "bincode"] }
25-
# Instruction decoder interfaces (official Solana crates)
26-
solana-system-interface = { version = "2.0", features = ["bincode"] }
27-
solana-stake-interface = { version = "2.0", features = ["bincode"] }
28-
solana-compute-budget-interface = { version = "2.0", features = ["borsh"] }
31+
solana-signature = "3.0"
32+
solana-address = "1.0"
2933
# Serialization
3034
bincode = "1.3"
3135
borsh = "1.5"
3236
base64 = "0.22"
37+
hex = "0.4"
3338
serde-wasm-bindgen = "0.6"
39+
# SPL crates for token/ATA operations
3440
spl-stake-pool = { version = "2.0.3", features = ["no-entrypoint"] }
41+
spl-token = { version = "6.0", features = ["no-entrypoint"] }
42+
spl-associated-token-account = { version = "4.0", features = ["no-entrypoint"] }
43+
spl-memo = { version = "5.0", features = ["no-entrypoint"] }
3544

3645
[dev-dependencies]
3746
wasm-bindgen-test = "0.3"
253 KB
Binary file not shown.

0 commit comments

Comments
 (0)