@streamflow/stream 11.1.0 → 11.2.0-alpha.p342.ccd18cf

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- export { AIRDROP_AMOUNT, AIRDROP_TEST_TOKEN, ALIGNED_COMPUTE_LIMIT, ALIGNED_PRECISION_FACTOR_POW, ALIGNED_UNLOCKS_PROGRAM_ID, Account, AlignedContract, AlignedProxyErrorCode, AlignedStream, AlignedStreamData, AlignedUnlocksContract, ApiClient, ApiClientOptions, BatchItem, BatchItemError, BatchItemResult, BatchItemSuccess, CONTRACT_DISCRIMINATOR, CONTRACT_SEED, CREATE_PARAMS_PADDING, Chain, ChangeOracleParams, ClientCreationOptions, Contract, ContractErrorCode, ContractSchema, ContractType, CreateParams, CreateTestOracleParams, DEFAULT_AUTO_CLAIM_FEE_SOL, DEFAULT_CREATION_FEE_SOL, DEFAULT_STREAMFLOW_FEE, DecodedStream, DynamicContractSchema, ESCROW_SEED, FEES_METADATA_SEED, FEE_ORACLE_PUBLIC_KEY, GetContractsOptions, IAlignedStreamConfig, IBaseStreamConfig, ICancelData, ICreateAlignedStreamData, ICreateExt, ICreateLinearStreamData, ICreateMultiError, ICreateMultipleAlignedStreamData, ICreateMultipleLinearStreamData, ICreateMultipleStreamData, ICreateResult, ICreateStreamData, ICreateStreamExt, ICreateStreamInstructions, IFees, IGetAllData, IGetFeesData, IGetOneData, IInteractData, IInteractStreamExt, IMultiTransactionResult, IPrepareCreateStreamExt, IPrepareStreamExt, IRecipient, ISearchStreams, ITopUpData, ITopUpStreamExt, ITransactionExtWithInstructions, ITransactionResult, ITransferData, IUpdateData, IWithdrawData, InstructionGenerator, LinearStream, MAX_SAFE_UNIX_TIME_VALUE, MetadataRecipientHashMap, ORIGINAL_CONTRACT_SENDER_OFFSET, OracleType, OracleTypeName, PARTNERS_SCHEMA, PARTNER_ORACLE_PROGRAM_ID, PARTNER_SCHEMA, PROGRAM_ID, PriceOracleType, REPOPULATED_METADATA_SEED, SOLANA_ERROR_MAP, SOLANA_ERROR_MATCH_REGEX, STREAMFLOW_TREASURY_PUBLIC_KEY, STREAM_STRUCT_OFFSETS, STREAM_STRUCT_OFFSET_CLOSED, STREAM_STRUCT_OFFSET_MINT, STREAM_STRUCT_OFFSET_OLD_METADATA_KEY, STREAM_STRUCT_OFFSET_RECIPIENT, STREAM_STRUCT_OFFSET_SENDER, SolanaStreamClient, Stream, StreamClientOptions, StreamDirection, StreamType, TEST_ORACLE_DISCRIMINATOR, TEST_ORACLE_SEED, TX_FINALITY_CONFIRMED, TabulariumContract, TestOracle, TransactionSchedulingOptions, UpdateTestOracleParams, WITHDRAWOR, WITHDRAWOR_PUBLIC_KEY, WITHDRAW_AVAILABLE_AMOUNT, buildStreamType, calculateTotalAmountToDeposit, calculateUnlockedAmount, cancelStreamInstruction, createClient, createStreamInstruction, createUncheckedStreamInstruction, decodeEndTime, decodeStream, deriveContractPDA, deriveEscrowPDA, deriveRepopulatedMetadataPDA, deriveTestOraclePDA, extractSolanaErrorCode, getMetadataKey, handleContractError, isAligned, isCliffCloseToDepositedAmount, isCreateAlignedStreamData, isDynamicLock, isTokenLock, isVesting, sendAndConfirmStreamRawTransaction, signAllTransactionWithRecipients, timelockIDL, topupStreamInstruction, transferStreamInstruction, transformContract, updateStreamInstruction, withdrawStreamInstruction } from './solana/index.cjs';
1
+ export { AIRDROP_AMOUNT, AIRDROP_TEST_TOKEN, ALIGNED_COMPUTE_LIMIT, ALIGNED_PRECISION_FACTOR_POW, ALIGNED_UNLOCKS_PROGRAM_ID, Account, AlignedContract, AlignedProxyErrorCode, AlignedStream, AlignedStreamData, AlignedUnlocksContract, ApiClient, ApiClientOptions, BatchItem, BatchItemError, BatchItemResult, BatchItemSuccess, CONTRACT_DISCRIMINATOR, CONTRACT_SEED, CREATE_PARAMS_PADDING, Chain, ChangeOracleParams, ClientCreationOptions, Contract, ContractErrorCode, ContractSchema, ContractType, CreateParams, CreateTestOracleParams, DEFAULT_AUTO_CLAIM_FEE_SOL, DEFAULT_CREATION_FEE_SOL, DEFAULT_STREAMFLOW_FEE, DecodedStream, DynamicContractSchema, ESCROW_SEED, FEES_METADATA_SEED, FEE_ORACLE_PUBLIC_KEY, GetContractsOptions, IAlignedStreamConfig, IBaseStreamConfig, ICancelData, ICreateAlignedStreamData, ICreateExt, ICreateLinearStreamData, ICreateMultiError, ICreateMultipleAlignedStreamData, ICreateMultipleLinearStreamData, ICreateMultipleStreamData, ICreateResult, ICreateStreamData, ICreateStreamExt, ICreateStreamInstructions, IFees, IGetAllData, IGetFeesData, IGetOneData, IInteractData, IInteractStreamExt, IMultiTransactionResult, IPrepareCreateStreamExt, IPrepareStreamExt, IRecipient, ISearchStreams, ITopUpData, ITopUpStreamExt, ITransactionExtWithInstructions, ITransactionResult, ITransferData, IUpdateData, IWithdrawData, InstructionGenerator, LinearStream, MAX_SAFE_UNIX_TIME_VALUE, METADATA_SEED, MetadataRecipientHashMap, ORIGINAL_CONTRACT_SENDER_OFFSET, OracleType, OracleTypeName, PARTNERS_SCHEMA, PARTNER_ORACLE_PROGRAM_ID, PARTNER_SCHEMA, PROGRAM_ID, PriceOracleType, REPOPULATED_METADATA_SEED, SOLANA_ERROR_MAP, SOLANA_ERROR_MATCH_REGEX, STREAMFLOW_TREASURY_PUBLIC_KEY, STREAM_STRUCT_OFFSETS, STREAM_STRUCT_OFFSET_CLOSED, STREAM_STRUCT_OFFSET_MINT, STREAM_STRUCT_OFFSET_OLD_METADATA_KEY, STREAM_STRUCT_OFFSET_RECIPIENT, STREAM_STRUCT_OFFSET_SENDER, SolanaStreamClient, Stream, StreamClientOptions, StreamDirection, StreamType, TEST_ORACLE_DISCRIMINATOR, TEST_ORACLE_SEED, TX_FINALITY_CONFIRMED, TabulariumContract, TestOracle, TransactionSchedulingOptions, UpdateTestOracleParams, WITHDRAWOR, WITHDRAWOR_PUBLIC_KEY, WITHDRAW_AVAILABLE_AMOUNT, buildStreamType, calculateTotalAmountToDeposit, calculateUnlockedAmount, cancelStreamInstruction, createClient, createStreamInstruction, createStreamV2Instruction, createUncheckedStreamInstruction, createUncheckedStreamV2Instruction, decodeEndTime, decodeStream, deriveContractPDA, deriveEscrowPDA, deriveRepopulatedMetadataPDA, deriveStreamMetadataPDA, deriveTestOraclePDA, extractSolanaErrorCode, getMetadataKey, handleContractError, isAligned, isCliffCloseToDepositedAmount, isCreateAlignedStreamData, isDynamicLock, isTokenLock, isVesting, sendAndConfirmStreamRawTransaction, signAllTransactionWithRecipients, timelockIDL, topupStreamInstruction, transferStreamInstruction, transformContract, updateStreamInstruction, withdrawStreamInstruction } from './solana/index.cjs';
2
2
  export { ContractError, ICluster, getBN, getNumberFromBN } from '@streamflow/common';
3
3
  import 'p-queue';
4
4
  import '@solana/web3.js';
@@ -180,12 +180,16 @@ var Contract = class {
180
180
  this.canTopup = stream.canTopup;
181
181
  this.name = stream.name;
182
182
  this.withdrawalFrequency = stream.withdrawFrequency.toNumber();
183
+ this.isPda = stream.isPda;
184
+ this.nonce = stream.nonce;
183
185
  this.closed = stream.closed;
184
186
  this.currentPauseStart = stream.currentPauseStart.toNumber();
185
187
  this.pauseCumulative = stream.pauseCumulative;
186
188
  this.lastRateChangeTime = stream.lastRateChangeTime.toNumber();
187
189
  this.fundsUnlockedAtLastRateChange = stream.fundsUnlockedAtLastRateChange;
188
190
  this.oldMetadata = stream.oldMetadata;
191
+ this.payer = stream.payer.toBase58();
192
+ this.bump = stream.bump;
189
193
  this.type = buildStreamType(this);
190
194
  this.isAligned = false;
191
195
  }
@@ -240,7 +244,7 @@ var STREAM_STRUCT_OFFSETS = {
240
244
  sender: STREAM_STRUCT_OFFSET_SENDER,
241
245
  closed: STREAM_STRUCT_OFFSET_CLOSED
242
246
  };
243
- var CREATE_PARAMS_PADDING = 126;
247
+ var CREATE_PARAMS_PADDING = 121;
244
248
  var PROGRAM_ID = {
245
249
  [common.ICluster.Devnet]: "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ",
246
250
  [common.ICluster.Mainnet]: "strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m",
@@ -271,6 +275,7 @@ var TEST_ORACLE_DISCRIMINATOR = [198, 49, 63, 134, 232, 251, 168, 28];
271
275
  var CONTRACT_SEED = buffer.Buffer.from("contract", "utf-8");
272
276
  var ESCROW_SEED = buffer.Buffer.from("strm", "utf-8");
273
277
  var TEST_ORACLE_SEED = buffer.Buffer.from("test-oracle", "utf-8");
278
+ var METADATA_SEED = buffer.Buffer.from("strm-met", "utf-8");
274
279
  var REPOPULATED_METADATA_SEED = buffer.Buffer.from("strm-rep", "utf-8");
275
280
  var STREAMFLOW_TREASURY_PUBLIC_KEY = new web3_js.PublicKey("5SEpbdjFK5FxwTvfsGMXVQTD2v4M2c5tyRTxhdsPkgDw");
276
281
  var WITHDRAWOR = "wdrwhnCv4pzW8beKsbPa4S2UDZrXenjg16KJdKSpb5u";
@@ -374,7 +379,9 @@ var streamLayout = BufferLayout__namespace.struct([
374
379
  BufferLayout__namespace.blob(4, "ghost"),
375
380
  BufferLayout__namespace.u8("pausable"),
376
381
  BufferLayout__namespace.u8("can_update_rate"),
377
- BufferLayout__namespace.blob(4, "create_stream_params_padding_length"),
382
+ BufferLayout__namespace.blob(4, "ghost2"),
383
+ BufferLayout__namespace.u8("is_pda"),
384
+ BufferLayout__namespace.u32("nonce"),
378
385
  BufferLayout__namespace.seq(BufferLayout__namespace.u8(), CREATE_PARAMS_PADDING, "create_params_padding"),
379
386
  BufferLayout__namespace.u8("closed"),
380
387
  BufferLayout__namespace.blob(8, "current_pause_start"),
@@ -385,7 +392,9 @@ var streamLayout = BufferLayout__namespace.struct([
385
392
  BufferLayout__namespace.u8("creation_fee_claimed"),
386
393
  BufferLayout__namespace.u32("auto_claim_fee"),
387
394
  BufferLayout__namespace.u8("auto_claim_fee_claimed"),
388
- BufferLayout__namespace.blob(32, "old_metadata")
395
+ BufferLayout__namespace.blob(32, "old_metadata"),
396
+ BufferLayout__namespace.blob(32, "payer"),
397
+ BufferLayout__namespace.u8("bump")
389
398
  ]);
390
399
  BufferLayout__namespace.struct([
391
400
  BufferLayout__namespace.blob(32, "pubkey"),
@@ -414,6 +423,25 @@ var createStreamLayout = BufferLayout__namespace.struct([
414
423
  BufferLayout__namespace.u8("_can_update_rate_discriminator"),
415
424
  BufferLayout__namespace.u8("can_update_rate")
416
425
  ]);
426
+ var createStreamV2Layout = BufferLayout__namespace.struct([
427
+ BufferLayout__namespace.blob(8, "start_time"),
428
+ BufferLayout__namespace.blob(8, "net_amount_deposited"),
429
+ BufferLayout__namespace.blob(8, "period"),
430
+ BufferLayout__namespace.blob(8, "amount_per_period"),
431
+ BufferLayout__namespace.blob(8, "cliff"),
432
+ BufferLayout__namespace.blob(8, "cliff_amount"),
433
+ BufferLayout__namespace.u8("cancelable_by_sender"),
434
+ BufferLayout__namespace.u8("cancelable_by_recipient"),
435
+ BufferLayout__namespace.u8("automatic_withdrawal"),
436
+ BufferLayout__namespace.u8("transferable_by_sender"),
437
+ BufferLayout__namespace.u8("transferable_by_recipient"),
438
+ BufferLayout__namespace.u8("can_topup"),
439
+ BufferLayout__namespace.blob(64, "stream_name"),
440
+ BufferLayout__namespace.blob(8, "withdraw_frequency"),
441
+ BufferLayout__namespace.u8("pausable"),
442
+ BufferLayout__namespace.u8("can_update_rate"),
443
+ BufferLayout__namespace.blob(4, "nonce")
444
+ ]);
417
445
  var createUncheckedStreamLayout = BufferLayout__namespace.struct([
418
446
  BufferLayout__namespace.blob(8, "start_time"),
419
447
  BufferLayout__namespace.blob(8, "net_amount_deposited"),
@@ -434,6 +462,27 @@ var createUncheckedStreamLayout = BufferLayout__namespace.struct([
434
462
  BufferLayout__namespace.u8("pausable"),
435
463
  BufferLayout__namespace.u8("can_update_rate")
436
464
  ]);
465
+ var createUncheckedStreamV2Layout = BufferLayout__namespace.struct([
466
+ BufferLayout__namespace.blob(8, "start_time"),
467
+ BufferLayout__namespace.blob(8, "net_amount_deposited"),
468
+ BufferLayout__namespace.blob(8, "period"),
469
+ BufferLayout__namespace.blob(8, "amount_per_period"),
470
+ BufferLayout__namespace.blob(8, "cliff"),
471
+ BufferLayout__namespace.blob(8, "cliff_amount"),
472
+ BufferLayout__namespace.u8("cancelable_by_sender"),
473
+ BufferLayout__namespace.u8("cancelable_by_recipient"),
474
+ BufferLayout__namespace.u8("automatic_withdrawal"),
475
+ BufferLayout__namespace.u8("transferable_by_sender"),
476
+ BufferLayout__namespace.u8("transferable_by_recipient"),
477
+ BufferLayout__namespace.u8("can_topup"),
478
+ BufferLayout__namespace.blob(64, "stream_name"),
479
+ BufferLayout__namespace.blob(8, "withdraw_frequency"),
480
+ BufferLayout__namespace.blob(32, "recipient"),
481
+ BufferLayout__namespace.blob(32, "partner"),
482
+ BufferLayout__namespace.u8("pausable"),
483
+ BufferLayout__namespace.u8("can_update_rate"),
484
+ BufferLayout__namespace.blob(4, "nonce")
485
+ ]);
437
486
  var withdrawStreamLayout = BufferLayout__namespace.struct([
438
487
  BufferLayout__namespace.blob(8, "amount")
439
488
  ]);
@@ -551,12 +600,16 @@ var decodeStream = (buf) => {
551
600
  canTopup: Boolean(raw.can_topup),
552
601
  name: decoder.decode(raw.stream_name),
553
602
  withdrawFrequency: new BN3__default.default(raw.withdraw_frequency, LE),
603
+ isPda: Boolean(raw.is_pda),
604
+ nonce: raw.nonce,
554
605
  closed: Boolean(raw.closed),
555
606
  currentPauseStart: new BN3__default.default(raw.current_pause_start, LE),
556
607
  pauseCumulative: new BN3__default.default(raw.pause_cumulative, LE),
557
608
  lastRateChangeTime: new BN3__default.default(raw.last_rate_change_time, LE),
558
609
  fundsUnlockedAtLastRateChange: new BN3__default.default(raw.funds_unlocked_at_last_rate_change, LE),
559
- oldMetadata: new web3_js.PublicKey(raw.old_metadata)
610
+ oldMetadata: new web3_js.PublicKey(raw.old_metadata),
611
+ payer: new web3_js.PublicKey(raw.payer),
612
+ bump: raw.bump
560
613
  };
561
614
  };
562
615
  async function signAllTransactionWithRecipients(sender, items) {
@@ -747,6 +800,133 @@ var createUncheckedStreamInstruction = async (data, programId, accounts) => {
747
800
  data: bufferData
748
801
  });
749
802
  };
803
+ var createStreamV2Instruction = async (data, programId, accounts) => {
804
+ const keys = [
805
+ { pubkey: accounts.sender, isSigner: true, isWritable: true },
806
+ { pubkey: accounts.senderTokens, isSigner: false, isWritable: true },
807
+ { pubkey: accounts.recipient, isSigner: false, isWritable: true },
808
+ { pubkey: accounts.metadata, isSigner: false, isWritable: true },
809
+ { pubkey: accounts.escrowTokens, isSigner: false, isWritable: true },
810
+ { pubkey: accounts.recipientTokens, isSigner: false, isWritable: true },
811
+ {
812
+ pubkey: accounts.streamflowTreasury,
813
+ isSigner: false,
814
+ isWritable: true
815
+ },
816
+ {
817
+ pubkey: accounts.streamflowTreasuryTokens,
818
+ isSigner: false,
819
+ isWritable: true
820
+ },
821
+ { pubkey: accounts.withdrawor, isSigner: false, isWritable: true },
822
+ { pubkey: accounts.partner, isSigner: false, isWritable: true },
823
+ { pubkey: accounts.partnerTokens, isSigner: false, isWritable: true },
824
+ { pubkey: accounts.mint, isSigner: false, isWritable: false },
825
+ { pubkey: accounts.feeOracle, isSigner: false, isWritable: false },
826
+ { pubkey: accounts.rent, isSigner: false, isWritable: false },
827
+ { pubkey: accounts.timelockProgram, isSigner: false, isWritable: false },
828
+ { pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
829
+ {
830
+ pubkey: accounts.associatedTokenProgram,
831
+ isSigner: false,
832
+ isWritable: false
833
+ },
834
+ { pubkey: accounts.systemProgram, isSigner: false, isWritable: false }
835
+ ];
836
+ let bufferData = buffer.Buffer.alloc(createStreamV2Layout.span);
837
+ const encodedUIntArray = new TextEncoder().encode(data.name);
838
+ const streamNameBuffer = buffer.Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
839
+ const nonceBuffer = buffer.Buffer.alloc(4);
840
+ nonceBuffer.writeUInt32LE(data.nonce);
841
+ const decodedData = {
842
+ start_time: data.start.toArrayLike(buffer.Buffer, "le", 8),
843
+ net_amount_deposited: data.depositedAmount.toArrayLike(buffer.Buffer, "le", 8),
844
+ period: data.period.toArrayLike(buffer.Buffer, "le", 8),
845
+ amount_per_period: data.amountPerPeriod.toArrayLike(buffer.Buffer, "le", 8),
846
+ cliff: data.cliff.toArrayLike(buffer.Buffer, "le", 8),
847
+ cliff_amount: data.cliffAmount.toArrayLike(buffer.Buffer, "le", 8),
848
+ cancelable_by_sender: Number(data.cancelableBySender),
849
+ cancelable_by_recipient: Number(data.cancelableByRecipient),
850
+ automatic_withdrawal: Number(data.automaticWithdrawal),
851
+ transferable_by_sender: Number(data.transferableBySender),
852
+ transferable_by_recipient: Number(data.transferableByRecipient),
853
+ can_topup: Number(data.canTopup),
854
+ stream_name: streamNameBuffer,
855
+ withdraw_frequency: data.withdrawFrequency.toArrayLike(buffer.Buffer, "le", 8),
856
+ pausable: Number(data.canPause),
857
+ can_update_rate: Number(data.canUpdateRate),
858
+ nonce: nonceBuffer
859
+ };
860
+ const encodeLength = createStreamV2Layout.encode(decodedData, bufferData);
861
+ bufferData = bufferData.slice(0, encodeLength);
862
+ bufferData = buffer.Buffer.concat([
863
+ buffer.Buffer.from(await sha256.digest("global:create_v2")).slice(0, 8),
864
+ bufferData,
865
+ buffer.Buffer.alloc(10)
866
+ ]);
867
+ return new web3_js.TransactionInstruction({
868
+ keys,
869
+ programId,
870
+ data: bufferData
871
+ });
872
+ };
873
+ var createUncheckedStreamV2Instruction = async (data, programId, accounts) => {
874
+ const keys = [
875
+ { pubkey: accounts.sender, isSigner: true, isWritable: true },
876
+ { pubkey: accounts.senderTokens, isSigner: false, isWritable: true },
877
+ { pubkey: accounts.metadata, isSigner: false, isWritable: true },
878
+ { pubkey: accounts.escrowTokens, isSigner: false, isWritable: true },
879
+ { pubkey: accounts.withdrawor, isSigner: false, isWritable: true },
880
+ { pubkey: accounts.mint, isSigner: false, isWritable: false },
881
+ { pubkey: accounts.feeOracle, isSigner: false, isWritable: false },
882
+ { pubkey: accounts.rent, isSigner: false, isWritable: false },
883
+ { pubkey: accounts.timelockProgram, isSigner: false, isWritable: false },
884
+ { pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
885
+ { pubkey: accounts.systemProgram, isSigner: false, isWritable: false }
886
+ ];
887
+ if (accounts.payer) {
888
+ keys.unshift({
889
+ pubkey: accounts.payer,
890
+ isSigner: true,
891
+ isWritable: true
892
+ });
893
+ }
894
+ let bufferData = buffer.Buffer.alloc(createUncheckedStreamV2Layout.span);
895
+ const encodedUIntArray = new TextEncoder().encode(data.name);
896
+ const streamNameBuffer = buffer.Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
897
+ const nonceBuffer = buffer.Buffer.alloc(4);
898
+ nonceBuffer.writeUInt32LE(data.nonce);
899
+ const decodedData = {
900
+ start_time: data.start.toArrayLike(buffer.Buffer, "le", 8),
901
+ net_amount_deposited: data.depositedAmount.toArrayLike(buffer.Buffer, "le", 8),
902
+ period: data.period.toArrayLike(buffer.Buffer, "le", 8),
903
+ amount_per_period: data.amountPerPeriod.toArrayLike(buffer.Buffer, "le", 8),
904
+ cliff: data.cliff.toArrayLike(buffer.Buffer, "le", 8),
905
+ cliff_amount: data.cliffAmount.toArrayLike(buffer.Buffer, "le", 8),
906
+ cancelable_by_sender: Number(data.cancelableBySender),
907
+ cancelable_by_recipient: Number(data.cancelableByRecipient),
908
+ automatic_withdrawal: Number(data.automaticWithdrawal),
909
+ transferable_by_sender: Number(data.transferableBySender),
910
+ transferable_by_recipient: Number(data.transferableByRecipient),
911
+ can_topup: Number(data.canTopup),
912
+ stream_name: streamNameBuffer,
913
+ withdraw_frequency: data.withdrawFrequency.toArrayLike(buffer.Buffer, "le", 8),
914
+ recipient: data.recipient.toBuffer(),
915
+ partner: data.partner.toBuffer(),
916
+ pausable: Number(data.canPause),
917
+ can_update_rate: Number(data.canUpdateRate),
918
+ nonce: nonceBuffer
919
+ };
920
+ const encodeLength = createUncheckedStreamV2Layout.encode(decodedData, bufferData);
921
+ bufferData = bufferData.slice(0, encodeLength);
922
+ const digest = accounts.payer ? await sha256.digest("global:create_unchecked_with_payer_v2") : await sha256.digest("global:create_unchecked_v2");
923
+ bufferData = buffer.Buffer.concat([buffer.Buffer.from(digest).slice(0, 8), bufferData, buffer.Buffer.alloc(10)]);
924
+ return new web3_js.TransactionInstruction({
925
+ keys,
926
+ programId,
927
+ data: bufferData
928
+ });
929
+ };
750
930
  var withdrawStreamInstruction = async (amount, programId, {
751
931
  authority,
752
932
  recipient,
@@ -2539,6 +2719,14 @@ var deriveEscrowPDA = (programId, streamMetadata) => {
2539
2719
  var deriveTestOraclePDA = (programId, mint, creator) => {
2540
2720
  return web3_js.PublicKey.findProgramAddressSync([TEST_ORACLE_SEED, mint.toBuffer(), creator.toBuffer()], programId)[0];
2541
2721
  };
2722
+ var deriveStreamMetadataPDA = (programId, mint, sender, nonce) => {
2723
+ const nonceBuffer = buffer.Buffer.alloc(4);
2724
+ nonceBuffer.writeUInt32BE(nonce);
2725
+ return web3_js.PublicKey.findProgramAddressSync(
2726
+ [METADATA_SEED, mint.toBuffer(), sender.toBuffer(), nonceBuffer],
2727
+ programId
2728
+ );
2729
+ };
2542
2730
  var deriveRepopulatedMetadataPDA = (programId, streamMetadata) => {
2543
2731
  return web3_js.PublicKey.findProgramAddressSync([REPOPULATED_METADATA_SEED, streamMetadata.toBuffer()], programId)[0];
2544
2732
  };
@@ -2597,6 +2785,7 @@ async function toDecodedStream(schema) {
2597
2785
  const sender = common.pk(schema.sender);
2598
2786
  const recipient = common.pk(schema.recipient);
2599
2787
  const partner = schema.partner ? common.pk(schema.partner) : sender;
2788
+ const payer = schema.payer ? common.pk(schema.payer) : web3_js.PublicKey.default;
2600
2789
  const [senderTokens, recipientTokens, partnerTokens, streamflowTreasuryTokens] = await Promise.all([
2601
2790
  common.ata(mint, sender),
2602
2791
  common.ata(mint, recipient),
@@ -2641,12 +2830,16 @@ async function toDecodedStream(schema) {
2641
2830
  canTopup: schema.canTopup,
2642
2831
  name: schema.name,
2643
2832
  withdrawFrequency: toBN(schema.autoClaimPeriod),
2833
+ isPda: schema.isPda,
2834
+ nonce: schema.nonce ? schema.nonce : 0,
2644
2835
  closed: schema.isClosed,
2645
2836
  currentPauseStart: toBN(0),
2646
2837
  pauseCumulative: toBN(schema.pauseCumulative),
2647
2838
  lastRateChangeTime: toBN(isoToUnix(schema.lastRateUpdateDt)),
2648
2839
  fundsUnlockedAtLastRateChange: toBN(schema.amountUnlockedAtLastRateUpdate),
2649
- oldMetadata: web3_js.PublicKey.default
2840
+ oldMetadata: web3_js.PublicKey.default,
2841
+ payer,
2842
+ bump: schema.bump ? schema.bump : 0
2650
2843
  };
2651
2844
  }
2652
2845
  function toPrecisionBN(value, precision = ALIGNED_PRECISION_FACTOR_POW2) {
@@ -2974,7 +3167,8 @@ var SolanaStreamClient = class {
2974
3167
  automaticWithdrawal = false,
2975
3168
  withdrawalFrequency = 0,
2976
3169
  partner,
2977
- tokenProgramId: streamTokenProgramId
3170
+ tokenProgramId: streamTokenProgramId,
3171
+ nonce
2978
3172
  }, { sender, metadataPubKeys, isNative = false, computePrice, computeLimit }) {
2979
3173
  common.assertHasPublicKey(sender, "Sender's PublicKey is not available, check passed wallet adapter!");
2980
3174
  const ixs = common.prepareBaseInstructions(this.connection, {
@@ -2983,7 +3177,13 @@ var SolanaStreamClient = class {
2983
3177
  });
2984
3178
  const mintPublicKey = isNative ? splToken.NATIVE_MINT : new web3_js.PublicKey(mint);
2985
3179
  const recipientPublicKey = new web3_js.PublicKey(recipient);
2986
- const { metadata, metadataPubKey } = this.getOrCreateStreamMetadata(metadataPubKeys);
3180
+ let metadata;
3181
+ let metadataPubKey;
3182
+ if (nonce != null) {
3183
+ [metadataPubKey] = deriveStreamMetadataPDA(this.programId, mintPublicKey, sender.publicKey, nonce);
3184
+ } else {
3185
+ ({ metadata, metadataPubKey } = this.getOrCreateStreamMetadata(metadataPubKeys));
3186
+ }
2987
3187
  const [escrowTokens] = web3_js.PublicKey.findProgramAddressSync(
2988
3188
  [buffer.Buffer.from("strm"), metadataPubKey.toBuffer()],
2989
3189
  this.programId
@@ -2997,49 +3197,49 @@ var SolanaStreamClient = class {
2997
3197
  const streamflowTreasuryTokens = await common.ata(mintPublicKey, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
2998
3198
  const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : sender.publicKey;
2999
3199
  const partnerTokens = await common.ata(mintPublicKey, partnerPublicKey, tokenProgramId);
3000
- ixs.push(
3001
- await createStreamInstruction(
3002
- {
3003
- start: new BN3__default.default(start),
3004
- depositedAmount,
3005
- period: new BN3__default.default(period),
3006
- amountPerPeriod,
3007
- cliff: new BN3__default.default(cliff),
3008
- cliffAmount: new BN3__default.default(cliffAmount),
3009
- cancelableBySender,
3010
- cancelableByRecipient,
3011
- automaticWithdrawal,
3012
- transferableBySender,
3013
- transferableByRecipient,
3014
- canTopup,
3015
- canUpdateRate: !!canUpdateRate,
3016
- canPause: !!canPause,
3017
- name,
3018
- withdrawFrequency: new BN3__default.default(automaticWithdrawal ? withdrawalFrequency : period)
3019
- },
3020
- this.programId,
3021
- {
3022
- sender: sender.publicKey,
3023
- senderTokens,
3024
- recipient: new web3_js.PublicKey(recipient),
3025
- metadata: metadataPubKey,
3026
- escrowTokens,
3027
- recipientTokens,
3028
- streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
3029
- streamflowTreasuryTokens,
3030
- partner: partnerPublicKey,
3031
- partnerTokens,
3032
- mint: new web3_js.PublicKey(mint),
3033
- feeOracle: this.feeOraclePublicKey,
3034
- rent: web3_js.SYSVAR_RENT_PUBKEY,
3035
- timelockProgram: this.programId,
3036
- tokenProgram: tokenProgramId,
3037
- associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
3038
- withdrawor: WITHDRAWOR_PUBLIC_KEY,
3039
- systemProgram: web3_js.SystemProgram.programId
3040
- }
3041
- )
3042
- );
3200
+ const accounts = {
3201
+ sender: sender.publicKey,
3202
+ senderTokens,
3203
+ recipient: new web3_js.PublicKey(recipient),
3204
+ metadata: metadataPubKey,
3205
+ escrowTokens,
3206
+ recipientTokens,
3207
+ streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
3208
+ streamflowTreasuryTokens,
3209
+ partner: partnerPublicKey,
3210
+ partnerTokens,
3211
+ mint: new web3_js.PublicKey(mint),
3212
+ feeOracle: this.feeOraclePublicKey,
3213
+ rent: web3_js.SYSVAR_RENT_PUBKEY,
3214
+ timelockProgram: this.programId,
3215
+ tokenProgram: tokenProgramId,
3216
+ associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
3217
+ withdrawor: WITHDRAWOR_PUBLIC_KEY,
3218
+ systemProgram: web3_js.SystemProgram.programId
3219
+ };
3220
+ const baseData = {
3221
+ start: new BN3__default.default(start),
3222
+ depositedAmount,
3223
+ period: new BN3__default.default(period),
3224
+ amountPerPeriod,
3225
+ cliff: new BN3__default.default(cliff),
3226
+ cliffAmount: new BN3__default.default(cliffAmount),
3227
+ cancelableBySender,
3228
+ cancelableByRecipient,
3229
+ automaticWithdrawal,
3230
+ transferableBySender,
3231
+ transferableByRecipient,
3232
+ canTopup,
3233
+ canUpdateRate: !!canUpdateRate,
3234
+ canPause: !!canPause,
3235
+ name,
3236
+ withdrawFrequency: new BN3__default.default(automaticWithdrawal ? withdrawalFrequency : period)
3237
+ };
3238
+ if (nonce != null) {
3239
+ ixs.push(await createStreamV2Instruction({ ...baseData, nonce }, this.programId, accounts));
3240
+ } else {
3241
+ ixs.push(await createStreamInstruction(baseData, this.programId, accounts));
3242
+ }
3043
3243
  return { ixs, metadata, metadataPubKey };
3044
3244
  }
3045
3245
  /**
@@ -3099,20 +3299,19 @@ var SolanaStreamClient = class {
3099
3299
  transferableByRecipient,
3100
3300
  automaticWithdrawal = false,
3101
3301
  withdrawalFrequency = 0,
3102
- partner
3302
+ partner,
3303
+ nonce
3103
3304
  }, { sender, metadataPubKeys, isNative = false, computePrice, computeLimit }) {
3104
3305
  common.assertHasPublicKey(sender, "Sender's PublicKey is not available, check passed wallet adapter!");
3105
3306
  const mintPublicKey = new web3_js.PublicKey(mint);
3106
3307
  const recipientPublicKey = new web3_js.PublicKey(recipient);
3107
- const { metadata, metadataPubKey } = this.getOrCreateStreamMetadata(metadataPubKeys);
3108
- const rentToExempt = await this.connection.getMinimumBalanceForRentExemption(METADATA_ACC_SIZE);
3109
- const createMetadataInstruction = web3_js.SystemProgram.createAccount({
3110
- programId: this.programId,
3111
- space: METADATA_ACC_SIZE,
3112
- lamports: rentToExempt,
3113
- fromPubkey: sender.publicKey,
3114
- newAccountPubkey: metadataPubKey
3115
- });
3308
+ let metadata;
3309
+ let metadataPubKey;
3310
+ if (nonce != null) {
3311
+ [metadataPubKey] = deriveStreamMetadataPDA(this.programId, mintPublicKey, sender.publicKey, nonce);
3312
+ } else {
3313
+ ({ metadata, metadataPubKey } = this.getOrCreateStreamMetadata(metadataPubKeys));
3314
+ }
3116
3315
  const [escrowTokens] = web3_js.PublicKey.findProgramAddressSync(
3117
3316
  [buffer.Buffer.from("strm"), metadataPubKey.toBuffer()],
3118
3317
  this.programId
@@ -3129,43 +3328,58 @@ var SolanaStreamClient = class {
3129
3328
  const totalAmount = calculateTotalAmountToDeposit(depositedAmount, totalFee);
3130
3329
  ixs.push(...await common.prepareWrappedAccount(this.connection, sender.publicKey, totalAmount));
3131
3330
  }
3132
- const createInstruction = await createUncheckedStreamInstruction(
3133
- {
3134
- start: new BN3__default.default(start),
3135
- depositedAmount,
3136
- period: new BN3__default.default(period),
3137
- amountPerPeriod,
3138
- cliff: new BN3__default.default(cliff),
3139
- cliffAmount: new BN3__default.default(cliffAmount),
3140
- cancelableBySender,
3141
- cancelableByRecipient,
3142
- automaticWithdrawal,
3143
- transferableBySender,
3144
- transferableByRecipient,
3145
- canTopup,
3146
- canUpdateRate: !!canUpdateRate,
3147
- canPause: !!canPause,
3148
- name,
3149
- withdrawFrequency: new BN3__default.default(automaticWithdrawal ? withdrawalFrequency : period),
3150
- recipient: recipientPublicKey,
3151
- partner: partnerPublicKey
3152
- },
3153
- this.programId,
3154
- {
3155
- sender: sender.publicKey,
3156
- senderTokens,
3157
- metadata: metadataPubKey,
3158
- escrowTokens,
3159
- mint: new web3_js.PublicKey(mint),
3160
- feeOracle: this.feeOraclePublicKey,
3161
- rent: web3_js.SYSVAR_RENT_PUBKEY,
3162
- timelockProgram: this.programId,
3163
- tokenProgram: tokenProgramId,
3164
- withdrawor: WITHDRAWOR_PUBLIC_KEY,
3165
- systemProgram: web3_js.SystemProgram.programId
3166
- }
3167
- );
3168
- ixs.push(createMetadataInstruction, createInstruction);
3331
+ const accounts = {
3332
+ sender: sender.publicKey,
3333
+ senderTokens,
3334
+ metadata: metadataPubKey,
3335
+ escrowTokens,
3336
+ mint: new web3_js.PublicKey(mint),
3337
+ feeOracle: this.feeOraclePublicKey,
3338
+ rent: web3_js.SYSVAR_RENT_PUBKEY,
3339
+ timelockProgram: this.programId,
3340
+ tokenProgram: tokenProgramId,
3341
+ withdrawor: WITHDRAWOR_PUBLIC_KEY,
3342
+ systemProgram: web3_js.SystemProgram.programId
3343
+ };
3344
+ const baseData = {
3345
+ start: new BN3__default.default(start),
3346
+ depositedAmount,
3347
+ period: new BN3__default.default(period),
3348
+ amountPerPeriod,
3349
+ cliff: new BN3__default.default(cliff),
3350
+ cliffAmount: new BN3__default.default(cliffAmount),
3351
+ cancelableBySender,
3352
+ cancelableByRecipient,
3353
+ automaticWithdrawal,
3354
+ transferableBySender,
3355
+ transferableByRecipient,
3356
+ canTopup,
3357
+ canUpdateRate: !!canUpdateRate,
3358
+ canPause: !!canPause,
3359
+ name,
3360
+ withdrawFrequency: new BN3__default.default(automaticWithdrawal ? withdrawalFrequency : period),
3361
+ recipient: recipientPublicKey,
3362
+ partner: partnerPublicKey
3363
+ };
3364
+ if (nonce != null) {
3365
+ const createInstruction = await createUncheckedStreamV2Instruction(
3366
+ { ...baseData, nonce },
3367
+ this.programId,
3368
+ accounts
3369
+ );
3370
+ ixs.push(createInstruction);
3371
+ } else {
3372
+ const rentToExempt = await this.connection.getMinimumBalanceForRentExemption(METADATA_ACC_SIZE);
3373
+ const createMetadataInstruction = web3_js.SystemProgram.createAccount({
3374
+ programId: this.programId,
3375
+ space: METADATA_ACC_SIZE,
3376
+ lamports: rentToExempt,
3377
+ fromPubkey: sender.publicKey,
3378
+ newAccountPubkey: metadataPubKey
3379
+ });
3380
+ const createInstruction = await createUncheckedStreamInstruction(baseData, this.programId, accounts);
3381
+ ixs.push(createMetadataInstruction, createInstruction);
3382
+ }
3169
3383
  return { ixs, metadata, metadataPubKey };
3170
3384
  }
3171
3385
  /**
@@ -4604,6 +4818,7 @@ exports.ESCROW_SEED = ESCROW_SEED;
4604
4818
  exports.FEES_METADATA_SEED = FEES_METADATA_SEED;
4605
4819
  exports.FEE_ORACLE_PUBLIC_KEY = FEE_ORACLE_PUBLIC_KEY;
4606
4820
  exports.MAX_SAFE_UNIX_TIME_VALUE = MAX_SAFE_UNIX_TIME_VALUE2;
4821
+ exports.METADATA_SEED = METADATA_SEED;
4607
4822
  exports.ORIGINAL_CONTRACT_SENDER_OFFSET = ORIGINAL_CONTRACT_SENDER_OFFSET;
4608
4823
  exports.PARTNERS_SCHEMA = PARTNERS_SCHEMA;
4609
4824
  exports.PARTNER_ORACLE_PROGRAM_ID = PARTNER_ORACLE_PROGRAM_ID;
@@ -4634,12 +4849,15 @@ exports.calculateUnlockedAmount = calculateUnlockedAmount;
4634
4849
  exports.cancelStreamInstruction = cancelStreamInstruction;
4635
4850
  exports.createClient = createClient;
4636
4851
  exports.createStreamInstruction = createStreamInstruction;
4852
+ exports.createStreamV2Instruction = createStreamV2Instruction;
4637
4853
  exports.createUncheckedStreamInstruction = createUncheckedStreamInstruction;
4854
+ exports.createUncheckedStreamV2Instruction = createUncheckedStreamV2Instruction;
4638
4855
  exports.decodeEndTime = decodeEndTime;
4639
4856
  exports.decodeStream = decodeStream;
4640
4857
  exports.deriveContractPDA = deriveContractPDA;
4641
4858
  exports.deriveEscrowPDA = deriveEscrowPDA;
4642
4859
  exports.deriveRepopulatedMetadataPDA = deriveRepopulatedMetadataPDA;
4860
+ exports.deriveStreamMetadataPDA = deriveStreamMetadataPDA;
4643
4861
  exports.deriveTestOraclePDA = deriveTestOraclePDA;
4644
4862
  exports.extractSolanaErrorCode = extractSolanaErrorCode;
4645
4863
  exports.getMetadataKey = getMetadataKey;