Skip to content

Commit 476b654

Browse files
Merge pull request #304 from streamflow-finance/dujo/feat/expose-solana-tx-builders
Fix: expose solana tx builders
2 parents e776841 + 6732440 commit 476b654

File tree

8 files changed

+44
-15
lines changed

8 files changed

+44
-15
lines changed

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"packages": ["packages/*"],
3-
"version": "8.7.0-alpha.0",
3+
"version": "8.7.0",
44
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
55
"command": {
66
"run": {

packages/common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@streamflow/common",
3-
"version": "8.7.0-alpha.0",
3+
"version": "8.7.0",
44
"description": "Common utilities and types used by streamflow packages.",
55
"homepage": "https://github.com/streamflow-finance/js-sdk/",
66
"type": "module",

packages/distributor/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@streamflow/distributor",
3-
"version": "8.7.0-alpha.0",
3+
"version": "8.7.0",
44
"description": "JavaScript SDK to interact with Streamflow Airdrop protocol.",
55
"homepage": "https://github.com/streamflow-finance/js-sdk/",
66
"main": "./dist/cjs/index.cjs",

packages/eslint-config/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@streamflow/eslint-config",
3-
"version": "8.7.0-alpha.0",
3+
"version": "8.7.0",
44
"description": "ESLint configuration for Streamflow protocol.",
55
"homepage": "https://github.com/streamflow-finance/js-sdk/",
66
"engines": {

packages/launchpad/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@streamflow/launchpad",
3-
"version": "8.7.0-alpha.0",
3+
"version": "8.7.0",
44
"description": "JavaScript SDK to interact with Streamflow Launchpad protocol.",
55
"homepage": "https://github.com/streamflow-finance/js-sdk/",
66
"main": "./dist/cjs/index.cjs",

packages/staking/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@streamflow/staking",
3-
"version": "8.7.0-alpha.0",
3+
"version": "8.7.0",
44
"description": "JavaScript SDK to interact with Streamflow Staking protocol.",
55
"homepage": "https://github.com/streamflow-finance/js-sdk/",
66
"main": "./dist/cjs/index.cjs",

packages/stream/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@streamflow/stream",
3-
"version": "8.7.0-alpha.0",
3+
"version": "8.7.0",
44
"description": "JavaScript SDK to interact with Streamflow protocol.",
55
"homepage": "https://github.com/streamflow-finance/js-sdk/",
66
"main": "./dist/cjs/index.cjs",

packages/stream/solana/StreamClient.ts

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ export class SolanaStreamClient extends BaseStreamClient {
221221
/**
222222
* Builds transaction instructions for creating a new stream/vesting contract without creating a transaction.
223223
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
224+
*
225+
* For native SOL (isNative: true), SOL wrapping instructions are automatically included in the correct order
226+
* (before stream creation) to ensure the WSOL account exists when the stream creation instruction executes.
227+
*
224228
* @param {ICreateStreamData} data - Stream parameters including recipient, token, amount, schedule, and permissions
225229
* @param {Omit<ICreateStreamSolanaExt, "sender"> & { senderPublicKey: PublicKey }} extParams - Transaction configuration including sender public key, native token handling, and custom instructions
226230
* @returns Transaction instructions and metadata ID
@@ -250,6 +254,16 @@ export class SolanaStreamClient extends BaseStreamClient {
250254
tokenProgramId ? new PublicKey(tokenProgramId) : undefined,
251255
);
252256

257+
// CRITICAL: SOL wrapping must happen BEFORE stream creation instructions
258+
// This ensures the WSOL account exists and has sufficient balance when stream creation executes
259+
if (isNative) {
260+
const totalFee = await this.getTotalFee({
261+
address: partnerPublicKey.toString(),
262+
});
263+
const totalAmount = calculateTotalAmountToDeposit(amount, totalFee);
264+
ixs.push(...(await prepareWrappedAccount(this.connection, tempSender.publicKey!, totalAmount)));
265+
}
266+
253267
const {
254268
ixs: createIxs,
255269
metadata,
@@ -261,14 +275,6 @@ export class SolanaStreamClient extends BaseStreamClient {
261275

262276
ixs.push(...createIxs);
263277

264-
if (isNative) {
265-
const totalFee = await this.getTotalFee({
266-
address: partnerPublicKey.toString(),
267-
});
268-
const totalAmount = calculateTotalAmountToDeposit(amount, totalFee);
269-
ixs.push(...(await prepareWrappedAccount(this.connection, tempSender.publicKey!, totalAmount)));
270-
}
271-
272278
await this.applyCustomAfterInstructions(ixs, customInstructions, metadataPubKey);
273279

274280
return {
@@ -281,6 +287,10 @@ export class SolanaStreamClient extends BaseStreamClient {
281287
/**
282288
* Builds a transaction for creating a new stream/vesting contract without signing or executing it.
283289
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
290+
*
291+
* For native SOL (isNative: true), SOL wrapping instructions are automatically included in the correct order
292+
* (before stream creation) to ensure the WSOL account exists when the stream creation instruction executes.
293+
*
284294
* @param {ICreateStreamData} data - Stream parameters including recipient, token, amount, schedule, and permissions
285295
* @param {Omit<ICreateStreamSolanaExt, "sender"> & { senderPublicKey: PublicKey }} extParams - Transaction configuration including sender public key, native token handling, and custom instructions
286296
* @returns Transaction and metadata information
@@ -841,6 +851,25 @@ export class SolanaStreamClient extends BaseStreamClient {
841851
/**
842852
* Builds multiple transactions for creating stream/vesting contracts without signing or executing them.
843853
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
854+
*
855+
* IMPORTANT: When using native SOL (isNative: true), you MUST execute the prepareTx FIRST and wait for confirmation
856+
* before executing the stream creation transactions. Otherwise, stream creation will fail with "InvalidAccountData".
857+
*
858+
* @example
859+
* ```typescript
860+
* const result = await streamClient.buildCreateMultipleTransactions(data, { isNative: true, senderPublicKey });
861+
*
862+
* // CRITICAL: Execute prepareTx first if it exists
863+
* if (result.prepareTx) {
864+
* await connection.sendAndConfirmTransaction(result.prepareTx, [signer]);
865+
* }
866+
*
867+
* // Only then execute stream creation transactions
868+
* for (const item of result.transactions) {
869+
* await connection.sendAndConfirmTransaction(item.tx, [signer]);
870+
* }
871+
* ```
872+
*
844873
* @param {ICreateMultipleStreamData} data - Stream base parameters and array of recipients with individual amounts and settings
845874
* @param {Omit<ICreateStreamSolanaExt, "sender"> & { senderPublicKey: PublicKey }} extParams - Transaction configuration including sender public key, native token handling, and custom instructions
846875
* @returns Multiple transaction information

0 commit comments

Comments
 (0)