@@ -46,6 +46,7 @@ import {
4646 ICreateStreamSolanaExt ,
4747 IInteractStreamSolanaExt ,
4848 ITopUpStreamSolanaExt ,
49+ ITransactionSolanaExtWithInstructions ,
4950 ISearchStreams ,
5051 ICreateStreamInstructions ,
5152 AlignedContract ,
@@ -111,7 +112,7 @@ import { BaseStreamClient } from "../common/BaseStreamClient.js";
111112import { IPartnerLayout } from "./instructionTypes.js" ;
112113import { calculateTotalAmountToDeposit } from "../common/utils.js" ;
113114import { WITHDRAW_AVAILABLE_AMOUNT } from "../common/constants.js" ;
114- import { StreamflowAlignedUnlocks as AlignedUnlocksProgramType } from "./descriptor/streamflow_aligned_unlocks" ;
115+ import { StreamflowAlignedUnlocks as AlignedUnlocksProgramType } from "./descriptor/streamflow_aligned_unlocks.js " ;
115116import StreamflowAlignedUnlocksIDL from "./descriptor/idl/streamflow_aligned_unlocks.json" ;
116117import { deriveContractPDA , deriveEscrowPDA , deriveTestOraclePDA } from "./lib/derive-accounts.js" ;
117118import { isCreateAlignedStreamData } from "../common/contractUtils.js" ;
@@ -220,7 +221,7 @@ export class SolanaStreamClient extends BaseStreamClient {
220221 */
221222 public async create ( data : ICreateStreamData , extParams : ICreateStreamSolanaExt ) : Promise < ICreateResult > {
222223 const { partner, amount, tokenProgramId } = data ;
223- const { isNative, sender } = extParams ;
224+ const { isNative, sender, customInstructions } = extParams ;
224225
225226 const partnerPublicKey = partner ? new PublicKey ( partner ) : WITHDRAWOR_PUBLIC_KEY ;
226227 const mintPublicKey = new PublicKey ( data . tokenId ) ;
@@ -229,7 +230,7 @@ export class SolanaStreamClient extends BaseStreamClient {
229230 throw new Error ( "Sender's PublicKey is not available, check passed wallet adapter!" ) ;
230231 }
231232
232- const ixs = await this . getCreateATAInstructions (
233+ const ixs : TransactionInstruction [ ] = await this . getCreateATAInstructions (
233234 [ STREAMFLOW_TREASURY_PUBLIC_KEY , partnerPublicKey ] ,
234235 mintPublicKey ,
235236 sender ,
@@ -249,13 +250,9 @@ export class SolanaStreamClient extends BaseStreamClient {
249250 ixs . push ( ...( await prepareWrappedAccount ( this . connection , sender . publicKey , totalAmount ) ) ) ;
250251 }
251252
252- const { tx, hash, context } = await prepareTransaction (
253- this . connection ,
254- ixs ,
255- extParams . sender . publicKey ,
256- undefined ,
257- metadata ,
258- ) ;
253+ await this . applyCustomAfterInstructions ( ixs , customInstructions , metadataPubKey ) ;
254+
255+ const { tx, hash, context } = await prepareTransaction ( this . connection , ixs , sender . publicKey , undefined , metadata ) ;
259256 const signature = await signAndExecuteTransaction (
260257 this . connection ,
261258 extParams . sender ,
@@ -653,7 +650,14 @@ export class SolanaStreamClient extends BaseStreamClient {
653650 ) : Promise < IMultiTransactionResult > {
654651 const { recipients, ...streamParams } = data ;
655652
656- const { sender, metadataPubKeys : metadataPubKeysExt , isNative, computePrice, computeLimit } = extParams ;
653+ const {
654+ sender,
655+ metadataPubKeys : metadataPubKeysExt ,
656+ isNative,
657+ computePrice,
658+ computeLimit,
659+ customInstructions,
660+ } = extParams ;
657661
658662 const metadatas : string [ ] = [ ] ;
659663 const metadataToRecipient : MetadataRecipientHashMap = { } ;
@@ -686,13 +690,15 @@ export class SolanaStreamClient extends BaseStreamClient {
686690 metadataPubKeys : metadataPubKeys [ i ] ? [ metadataPubKeys [ i ] ] : undefined ,
687691 computePrice,
688692 computeLimit,
693+ customInstructions,
689694 } ;
690695
691696 const { ixs, metadata, metadataPubKey } = await this . prepareCreateInstructions (
692697 createStreamData ,
693698 createStreamExtParams ,
694699 ) ;
695700
701+ await this . applyCustomAfterInstructions ( ixs , customInstructions , metadataPubKey ) ;
696702 metadataToRecipient [ metadataPubKey . toBase58 ( ) ] = recipientData ;
697703
698704 metadatas . push ( metadataPubKey . toBase58 ( ) ) ;
@@ -803,7 +809,14 @@ export class SolanaStreamClient extends BaseStreamClient {
803809 ) : Promise < IMultiTransactionResult > {
804810 const { recipients, ...streamParams } = data ;
805811
806- const { sender, metadataPubKeys : metadataPubKeysExt , isNative, computePrice, computeLimit } = extParams ;
812+ const {
813+ sender,
814+ metadataPubKeys : metadataPubKeysExt ,
815+ isNative,
816+ computePrice,
817+ computeLimit,
818+ customInstructions,
819+ } = extParams ;
807820
808821 const metadatas : string [ ] = [ ] ;
809822 const metadataToRecipient : MetadataRecipientHashMap = { } ;
@@ -836,13 +849,15 @@ export class SolanaStreamClient extends BaseStreamClient {
836849 metadataPubKeys : metadataPubKeys [ i ] ? [ metadataPubKeys [ i ] ] : undefined ,
837850 computePrice,
838851 computeLimit,
852+ customInstructions,
839853 } ;
840854
841855 const { ixs, metadata, metadataPubKey } = await this . prepareCreateInstructions (
842856 createStreamData ,
843857 createStreamExtParams ,
844858 ) ;
845859
860+ await this . applyCustomAfterInstructions ( ixs , customInstructions , metadataPubKey ) ;
846861 metadataToRecipient [ metadataPubKey . toBase58 ( ) ] = recipientData ;
847862
848863 metadatas . push ( metadataPubKey . toBase58 ( ) ) ;
@@ -934,8 +949,18 @@ export class SolanaStreamClient extends BaseStreamClient {
934949 { id, amount = WITHDRAW_AVAILABLE_AMOUNT } : IWithdrawData ,
935950 extParams : IInteractStreamSolanaExt ,
936951 ) : Promise < ITransactionResult > {
952+ const { invoker, customInstructions } = extParams ;
953+
954+ if ( ! invoker . publicKey ) {
955+ throw new Error ( "Invoker's PublicKey is not available, check passed wallet adapter!" ) ;
956+ }
957+
937958 const ixs : TransactionInstruction [ ] = await this . prepareWithdrawInstructions ( { id, amount } , extParams ) ;
938- const { tx, hash, context } = await prepareTransaction ( this . connection , ixs , extParams . invoker . publicKey ) ;
959+
960+ const metadata = new PublicKey ( id ) ;
961+ await this . applyCustomAfterInstructions ( ixs , customInstructions , metadata ) ;
962+
963+ const { tx, hash, context } = await prepareTransaction ( this . connection , ixs , invoker . publicKey ) ;
939964 const signature = await signAndExecuteTransaction (
940965 this . connection ,
941966 extParams . invoker ,
@@ -1574,4 +1599,21 @@ export class SolanaStreamClient extends BaseStreamClient {
15741599 ) ;
15751600 return checkOrCreateAtaBatch ( this . connection , uniqueOwners , mint , invoker , programId ) ;
15761601 }
1602+
1603+ private async applyCustomAfterInstructions (
1604+ ixs : TransactionInstruction [ ] ,
1605+ customInstructions : ITransactionSolanaExtWithInstructions [ "customInstructions" ] ,
1606+ metadata ?: PublicKey ,
1607+ ) : Promise < void > {
1608+ if ( customInstructions ?. after ) {
1609+ const afterInstructions =
1610+ typeof customInstructions . after === "function"
1611+ ? await customInstructions . after ( {
1612+ instructions : ixs ,
1613+ metadata,
1614+ } )
1615+ : customInstructions . after ;
1616+ ixs . push ( ...afterInstructions ) ;
1617+ }
1618+ }
15771619}
0 commit comments