@streamflow/stream 10.0.0-alpha.p313.4470e29 → 10.0.0-alpha.p313.77ad1fe

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.
@@ -8,7 +8,7 @@ type StreamflowAlignedUnlocks = {
8
8
  "address": "aSTRM2NKoKxNnkmLWk9sz3k74gKBk9t7bpPrTGxMszH";
9
9
  "metadata": {
10
10
  "name": "streamflowAlignedUnlocks";
11
- "version": "1.3.0";
11
+ "version": "1.4.0";
12
12
  "spec": "0.1.0";
13
13
  "description": "Proxy to update unlock amount within Streamflow vesting protocol according to Token performance and other metrics";
14
14
  };
@@ -882,6 +882,80 @@ type StreamflowAlignedUnlocks = {
882
882
  ];
883
883
  "args": [];
884
884
  },
885
+ {
886
+ "name": "updateContract";
887
+ "discriminator": [
888
+ 78,
889
+ 184,
890
+ 162,
891
+ 174,
892
+ 233,
893
+ 5,
894
+ 40,
895
+ 82
896
+ ];
897
+ "accounts": [
898
+ {
899
+ "name": "sender";
900
+ "writable": true;
901
+ "signer": true;
902
+ },
903
+ {
904
+ "name": "proxyMetadata";
905
+ "docs": [
906
+ "Proxy Contract"
907
+ ];
908
+ "writable": true;
909
+ "pda": {
910
+ "seeds": [
911
+ {
912
+ "kind": "const";
913
+ "value": [
914
+ 99,
915
+ 111,
916
+ 110,
917
+ 116,
918
+ 114,
919
+ 97,
920
+ 99,
921
+ 116
922
+ ];
923
+ },
924
+ {
925
+ "kind": "account";
926
+ "path": "streamMetadata";
927
+ }
928
+ ];
929
+ };
930
+ },
931
+ {
932
+ "name": "streamMetadata";
933
+ "writable": true;
934
+ },
935
+ {
936
+ "name": "withdrawor";
937
+ "writable": true;
938
+ },
939
+ {
940
+ "name": "streamflowProgram";
941
+ "address": "strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m";
942
+ },
943
+ {
944
+ "name": "systemProgram";
945
+ "address": "11111111111111111111111111111111";
946
+ }
947
+ ];
948
+ "args": [
949
+ {
950
+ "name": "params";
951
+ "type": {
952
+ "defined": {
953
+ "name": "updateContractParams";
954
+ };
955
+ };
956
+ }
957
+ ];
958
+ },
885
959
  {
886
960
  "name": "updateTestOracle";
887
961
  "discriminator": [
@@ -1477,6 +1551,32 @@ type StreamflowAlignedUnlocks = {
1477
1551
  ];
1478
1552
  };
1479
1553
  },
1554
+ {
1555
+ "name": "updateContractParams";
1556
+ "type": {
1557
+ "kind": "struct";
1558
+ "fields": [
1559
+ {
1560
+ "name": "transferableBySender";
1561
+ "type": {
1562
+ "option": "bool";
1563
+ };
1564
+ },
1565
+ {
1566
+ "name": "transferableByRecipient";
1567
+ "type": {
1568
+ "option": "bool";
1569
+ };
1570
+ },
1571
+ {
1572
+ "name": "cancelableBySender";
1573
+ "type": {
1574
+ "option": "bool";
1575
+ };
1576
+ }
1577
+ ];
1578
+ };
1579
+ },
1480
1580
  {
1481
1581
  "name": "updateTestOracleParams";
1482
1582
  "type": {
@@ -905,7 +905,7 @@ var streamflow_aligned_unlocks_default = {
905
905
  address: "aSTRM2NKoKxNnkmLWk9sz3k74gKBk9t7bpPrTGxMszH",
906
906
  metadata: {
907
907
  name: "streamflow_aligned_unlocks",
908
- version: "1.3.0",
908
+ version: "1.4.0",
909
909
  spec: "0.1.0",
910
910
  description: "Proxy to update unlock amount within Streamflow vesting protocol according to Token performance and other metrics"
911
911
  },
@@ -1779,6 +1779,80 @@ var streamflow_aligned_unlocks_default = {
1779
1779
  ],
1780
1780
  args: []
1781
1781
  },
1782
+ {
1783
+ name: "update_contract",
1784
+ discriminator: [
1785
+ 78,
1786
+ 184,
1787
+ 162,
1788
+ 174,
1789
+ 233,
1790
+ 5,
1791
+ 40,
1792
+ 82
1793
+ ],
1794
+ accounts: [
1795
+ {
1796
+ name: "sender",
1797
+ writable: true,
1798
+ signer: true
1799
+ },
1800
+ {
1801
+ name: "proxy_metadata",
1802
+ docs: [
1803
+ "Proxy Contract"
1804
+ ],
1805
+ writable: true,
1806
+ pda: {
1807
+ seeds: [
1808
+ {
1809
+ kind: "const",
1810
+ value: [
1811
+ 99,
1812
+ 111,
1813
+ 110,
1814
+ 116,
1815
+ 114,
1816
+ 97,
1817
+ 99,
1818
+ 116
1819
+ ]
1820
+ },
1821
+ {
1822
+ kind: "account",
1823
+ path: "stream_metadata"
1824
+ }
1825
+ ]
1826
+ }
1827
+ },
1828
+ {
1829
+ name: "stream_metadata",
1830
+ writable: true
1831
+ },
1832
+ {
1833
+ name: "withdrawor",
1834
+ writable: true
1835
+ },
1836
+ {
1837
+ name: "streamflow_program",
1838
+ address: "strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m"
1839
+ },
1840
+ {
1841
+ name: "system_program",
1842
+ address: "11111111111111111111111111111111"
1843
+ }
1844
+ ],
1845
+ args: [
1846
+ {
1847
+ name: "params",
1848
+ type: {
1849
+ defined: {
1850
+ name: "UpdateContractParams"
1851
+ }
1852
+ }
1853
+ }
1854
+ ]
1855
+ },
1782
1856
  {
1783
1857
  name: "update_test_oracle",
1784
1858
  discriminator: [
@@ -2374,6 +2448,32 @@ var streamflow_aligned_unlocks_default = {
2374
2448
  ]
2375
2449
  }
2376
2450
  },
2451
+ {
2452
+ name: "UpdateContractParams",
2453
+ type: {
2454
+ kind: "struct",
2455
+ fields: [
2456
+ {
2457
+ name: "transferable_by_sender",
2458
+ type: {
2459
+ option: "bool"
2460
+ }
2461
+ },
2462
+ {
2463
+ name: "transferable_by_recipient",
2464
+ type: {
2465
+ option: "bool"
2466
+ }
2467
+ },
2468
+ {
2469
+ name: "cancelable_by_sender",
2470
+ type: {
2471
+ option: "bool"
2472
+ }
2473
+ }
2474
+ ]
2475
+ }
2476
+ },
2377
2477
  {
2378
2478
  name: "UpdateTestOracleParams",
2379
2479
  type: {
@@ -2564,7 +2664,7 @@ var SolanaStreamClient = class {
2564
2664
  return { ixs, txId: signature, metadataId };
2565
2665
  }
2566
2666
  async prepareCreateInstructions(streamParams, extParams) {
2567
- const { ixs, metadata, metadataPubKey } = isCreateAlignedStreamData(streamParams) ? await this.prepareCreateAlignedUnlockInstructions(streamParams, extParams) : await this.prepareCreateStreamInstructions(streamParams, extParams);
2667
+ const { ixs, metadata, metadataPubKey } = isCreateAlignedStreamData(streamParams) ? await this.prepareCreateAlignedUnlockInstructions(streamParams, extParams) : await this.prepareCreateLinearStreamInstructions(streamParams, extParams);
2568
2668
  return { ixs, metadata, metadataPubKey };
2569
2669
  }
2570
2670
  async prepareCreateAlignedUnlockInstructions(streamParams, extParams) {
@@ -2598,7 +2698,10 @@ var SolanaStreamClient = class {
2598
2698
  floorPrice
2599
2699
  } = streamParams;
2600
2700
  const { isNative, sender, computeLimit, computePrice, metadataPubKeys } = extParams;
2601
- common.invariant(priceOracle || !oracleType || oracleType === "none", "Price oracle is required for the specified oracle type");
2701
+ common.invariant(
2702
+ priceOracle || !oracleType || oracleType === "none",
2703
+ "Price oracle is required for the specified oracle type"
2704
+ );
2602
2705
  common.assertHasPublicKey(sender, "Sender's PublicKey is not available, check passed wallet adapter!");
2603
2706
  const recipientPublicKey = new web3_js.PublicKey(recipient);
2604
2707
  const mintPublicKey = isNative ? splToken.NATIVE_MINT : new web3_js.PublicKey(mint);
@@ -2671,7 +2774,7 @@ var SolanaStreamClient = class {
2671
2774
  * @param {IPrepareCreateStreamExt} extParams - Transaction configuration including sender wallet, metadata keys, and compute settings
2672
2775
  * @returns Create stream instructions
2673
2776
  */
2674
- async prepareCreateStreamInstructions({
2777
+ async prepareCreateLinearStreamInstructions({
2675
2778
  recipient,
2676
2779
  tokenId: mint,
2677
2780
  start,
@@ -2773,10 +2876,7 @@ var SolanaStreamClient = class {
2773
2876
  * @returns Create result
2774
2877
  */
2775
2878
  async createUnchecked(data, extParams) {
2776
- const { ixs, metadata, metadataPubKey } = await this.prepareCreateUncheckedInstructions(
2777
- data,
2778
- extParams
2779
- );
2879
+ const { ixs, metadata, metadataPubKey } = await this.prepareCreateUncheckedInstructions(data, extParams);
2780
2880
  const { tx, hash, context } = await common.prepareTransaction(
2781
2881
  this.connection,
2782
2882
  ixs,
@@ -2895,14 +2995,13 @@ var SolanaStreamClient = class {
2895
2995
  * @param {IPrepareCreateStreamExt} extParams - Transaction configuration including sender public key, native token handling, and custom instructions
2896
2996
  * @returns Create multiple transaction instructions
2897
2997
  */
2898
- async buildCreateMultipleTransactionInstructions(data, extParams) {
2998
+ async buildCreateMultipleTransactionInstructions(data, extParams, applyCustomAfterInstructions = true) {
2899
2999
  const { recipients, ...streamParams } = data;
2900
3000
  const { sender, metadataPubKeys: metadataPubKeysExt, isNative, customInstructions } = extParams;
2901
3001
  common.assertHasPublicKey(sender, "Sender's PublicKey is not available, check passed wallet adapter!");
2902
3002
  const metadatas = [];
2903
3003
  const metadataToRecipient = {};
2904
3004
  const instructionsBatch = [];
2905
- const metadataPubKeys = metadataPubKeysExt || [];
2906
3005
  const partnerPublicKey = data.partner ? new web3_js.PublicKey(data.partner) : WITHDRAWOR_PUBLIC_KEY;
2907
3006
  const mintPublicKey = new web3_js.PublicKey(data.tokenId);
2908
3007
  if (recipients.length === 0) {
@@ -2912,14 +3011,16 @@ var SolanaStreamClient = class {
2912
3011
  const recipientData = recipients[i];
2913
3012
  const createStreamData = { ...streamParams, ...recipientData };
2914
3013
  const createStreamExtParams = {
2915
- metadataPubKeys: metadataPubKeys[i] ? [metadataPubKeys[i]] : void 0,
2916
- ...extParams
3014
+ ...extParams,
3015
+ metadataPubKeys: metadataPubKeysExt?.[i] ? [metadataPubKeysExt[i]] : void 0
2917
3016
  };
2918
3017
  const { ixs, metadata, metadataPubKey } = await this.prepareCreateInstructions(
2919
3018
  createStreamData,
2920
3019
  createStreamExtParams
2921
3020
  );
2922
- await this.applyCustomAfterInstructions(ixs, customInstructions, metadataPubKey);
3021
+ if (applyCustomAfterInstructions) {
3022
+ await this.applyCustomAfterInstructions(ixs, customInstructions, metadataPubKey);
3023
+ }
2923
3024
  metadataToRecipient[metadataPubKey.toBase58()] = recipientData;
2924
3025
  metadatas.push(metadataPubKey.toBase58());
2925
3026
  instructionsBatch.push({
@@ -2928,19 +3029,10 @@ var SolanaStreamClient = class {
2928
3029
  recipient: recipientData.recipient
2929
3030
  });
2930
3031
  }
2931
- const prepareInstructions = await this.getCreateATAInstructions(
2932
- [partnerPublicKey],
2933
- mintPublicKey,
2934
- sender,
2935
- true
2936
- );
3032
+ const prepareInstructions = await this.getCreateATAInstructions([partnerPublicKey], mintPublicKey, sender, true);
2937
3033
  if (isNative) {
2938
3034
  const totalDepositedAmount = recipients.reduce((acc, recipient) => recipient.amount.add(acc), new BN3__default.default(0));
2939
- const nativeInstructions = await common.prepareWrappedAccount(
2940
- this.connection,
2941
- sender.publicKey,
2942
- totalDepositedAmount
2943
- );
3035
+ const nativeInstructions = await common.prepareWrappedAccount(this.connection, sender.publicKey, totalDepositedAmount);
2944
3036
  prepareInstructions.push(...nativeInstructions);
2945
3037
  }
2946
3038
  return {
@@ -2976,9 +3068,9 @@ var SolanaStreamClient = class {
2976
3068
  * @param {IPrepareCreateStreamExt} extParams - Transaction configuration including sender public key, native token handling, and custom instructions
2977
3069
  * @returns Multiple transaction information
2978
3070
  */
2979
- async buildCreateMultipleTransactions(data, extParams) {
3071
+ async buildCreateMultipleTransactions(data, extParams, applyCustomAfterInstructions = true) {
2980
3072
  const { sender } = extParams;
2981
- const { instructionsBatch, metadatas, metadataToRecipient, prepareInstructions } = await this.buildCreateMultipleTransactionInstructions(data, extParams);
3073
+ const { instructionsBatch, metadatas, metadataToRecipient, prepareInstructions } = await this.buildCreateMultipleTransactionInstructions(data, extParams, applyCustomAfterInstructions);
2982
3074
  const { value: hash, context } = await this.connection.getLatestBlockhashAndContext();
2983
3075
  const batch = [];
2984
3076
  for (const { ixs, metadata, recipient } of instructionsBatch) {
@@ -3009,7 +3101,7 @@ var SolanaStreamClient = class {
3009
3101
  if (!sender.publicKey) {
3010
3102
  throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
3011
3103
  }
3012
- const { instructionsBatch, metadatas, metadataToRecipient, prepareInstructions } = await this.buildCreateMultipleTransactionInstructions(data, extParams);
3104
+ const { instructionsBatch, metadatas, prepareInstructions, metadataToRecipient } = await this.flatBuildCreateMultipleTransactionInstructions(data, extParams);
3013
3105
  const errors = [];
3014
3106
  const signatures = [];
3015
3107
  const metadataPubKeys = metadataPubKeysExt || [];
@@ -3074,7 +3166,7 @@ var SolanaStreamClient = class {
3074
3166
  if (!sender.publicKey) {
3075
3167
  throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
3076
3168
  }
3077
- const { instructionsBatch, metadatas, metadataToRecipient, prepareInstructions } = await this.buildCreateMultipleTransactionInstructions(data, extParams);
3169
+ const { instructionsBatch, metadatas, prepareInstructions, metadataToRecipient } = await this.flatBuildCreateMultipleTransactionInstructions(data, extParams);
3078
3170
  const errors = [];
3079
3171
  const signatures = [];
3080
3172
  const batch = [];
@@ -3138,10 +3230,7 @@ var SolanaStreamClient = class {
3138
3230
  async withdraw({ id, amount = WITHDRAW_AVAILABLE_AMOUNT }, extParams) {
3139
3231
  const { invoker, customInstructions } = extParams;
3140
3232
  common.assertHasPublicKey(invoker, "Invoker's PublicKey is not available, check passed wallet adapter!");
3141
- const ixs = await this.prepareWithdrawInstructions(
3142
- { id, amount },
3143
- extParams
3144
- );
3233
+ const ixs = await this.prepareWithdrawInstructions({ id, amount }, extParams);
3145
3234
  const metadata = new web3_js.PublicKey(id);
3146
3235
  await this.applyCustomAfterInstructions(ixs, customInstructions, metadata);
3147
3236
  const { tx, hash, context } = await common.prepareTransaction(this.connection, ixs, invoker.publicKey);
@@ -3239,7 +3328,7 @@ var SolanaStreamClient = class {
3239
3328
  }
3240
3329
  const { sender: senderPublicKey } = decodeStream(account.data);
3241
3330
  const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, senderPublicKey);
3242
- const ixs = isAlignedUnlock ? await this.prepareCancelAlignedUnlockInstructions(cancelData, extParams) : await this.prepareCancelStreamInstructions(cancelData, extParams);
3331
+ const ixs = isAlignedUnlock ? await this.prepareCancelAlignedUnlockInstructions(cancelData, extParams) : await this.prepareCancelLinearStream(cancelData, extParams);
3243
3332
  return ixs;
3244
3333
  }
3245
3334
  /**
@@ -3287,7 +3376,7 @@ var SolanaStreamClient = class {
3287
3376
  * @param {IPrepareStreamExt} extParams - Transaction configuration including invoker wallet, token account validation, and compute settings
3288
3377
  * @returns Transaction instructions
3289
3378
  */
3290
- async prepareCancelStreamInstructions({ id }, { invoker, checkTokenAccounts, computePrice, computeLimit }) {
3379
+ async prepareCancelLinearStream({ id }, { invoker, checkTokenAccounts, computePrice, computeLimit }) {
3291
3380
  common.assertHasPublicKey(invoker, "Invoker's PublicKey is not available, check passed wallet adapter!");
3292
3381
  const streamPublicKey = new web3_js.PublicKey(id);
3293
3382
  const escrowAcc = await this.connection.getAccountInfo(streamPublicKey);
@@ -3645,17 +3734,26 @@ var SolanaStreamClient = class {
3645
3734
  const streamPublicKey = new web3_js.PublicKey(data.id);
3646
3735
  const escrow = await this.connection.getAccountInfo(streamPublicKey);
3647
3736
  common.invariant(escrow, "Couldn't get account info");
3737
+ const { sender: senderPublicKey } = decodeStream(escrow.data);
3738
+ const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, senderPublicKey);
3739
+ if (isAlignedUnlock && (data.enableAutomaticWithdrawal !== void 0 || data.amountPerPeriod !== void 0)) {
3740
+ throw new Error("Automatic withdrawal and rate update are not possible in price-based vesting!");
3741
+ }
3648
3742
  const ixs = common.prepareBaseInstructions(this.connection, {
3649
3743
  computePrice,
3650
3744
  computeLimit
3651
3745
  });
3652
3746
  ixs.push(
3653
- await updateStreamInstruction(data, this.programId, {
3747
+ await (isAlignedUnlock ? this.alignedProxyProgram.methods.updateContract({
3748
+ transferableBySender: data.transferableBySender ?? null,
3749
+ transferableByRecipient: data.transferableByRecipient ?? null,
3750
+ cancelableBySender: data.cancelableBySender ?? null
3751
+ }).accounts({ sender: invoker.publicKey, streamMetadata: streamPublicKey, withdrawor: WITHDRAWOR_PUBLIC_KEY }).accountsPartial({ streamflowProgram: this.programId }).instruction() : updateStreamInstruction(data, this.programId, {
3654
3752
  authority: invoker.publicKey,
3655
3753
  metadata: streamPublicKey,
3656
3754
  withdrawor: WITHDRAWOR_PUBLIC_KEY,
3657
3755
  systemProgram: web3_js.SystemProgram.programId
3658
- })
3756
+ }))
3659
3757
  );
3660
3758
  return ixs;
3661
3759
  }
@@ -3691,11 +3789,11 @@ var SolanaStreamClient = class {
3691
3789
  return DEFAULT_STREAMFLOW_FEE;
3692
3790
  }
3693
3791
  /**
3694
- * Returns total fee percent, streamflow fees + partner fees
3695
- * @param getFeesData structure with address for which we need to derive fee, either sender or partner usually
3696
- * @param chainSpecificParams additional parameters required by chain client
3697
- * @returns fee as floating number, so if fee is 0.99%, it will return 0.99
3698
- */
3792
+ * Returns total fee percent, streamflow fees + partner fees
3793
+ * @param getFeesData structure with address for which we need to derive fee, either sender or partner usually
3794
+ * @param chainSpecificParams additional parameters required by chain client
3795
+ * @returns fee as floating number, so if fee is 0.99%, it will return 0.99
3796
+ */
3699
3797
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
3700
3798
  async getTotalFee(getFeesData) {
3701
3799
  const fees = await this.getFees(getFeesData);
@@ -3714,12 +3812,27 @@ var SolanaStreamClient = class {
3714
3812
  return extractSolanaErrorCode(err.toString() ?? "Unknown error!", logs);
3715
3813
  }
3716
3814
  /**
3717
- * Utility function that checks whether the associated stream address is an aligned unlock contract, indicated by whether the sender/creator is a PDA
3718
- */
3815
+ * Utility function that checks whether the associated stream address is an aligned unlock contract, indicated by whether the sender/creator is a PDA
3816
+ */
3719
3817
  isAlignedUnlock(streamPublicKey, senderPublicKey) {
3720
3818
  const pda = deriveContractPDA(this.alignedProxyProgram.programId, streamPublicKey);
3721
3819
  return senderPublicKey.equals(pda);
3722
3820
  }
3821
+ async flatBuildCreateMultipleTransactionInstructions(data, extParams) {
3822
+ const dataArray = Array.isArray(data) ? data : [data];
3823
+ const results = await Promise.all(
3824
+ dataArray.map((item, index) => this.buildCreateMultipleTransactionInstructions(item, extParams, index === 0))
3825
+ );
3826
+ return {
3827
+ instructionsBatch: results.flatMap((r) => r.instructionsBatch),
3828
+ metadatas: results.flatMap((r) => r.metadatas),
3829
+ prepareInstructions: results.flatMap((r) => r.prepareInstructions),
3830
+ metadataToRecipient: results.reduce(
3831
+ (acc, r) => Object.assign(acc, r.metadataToRecipient),
3832
+ {}
3833
+ )
3834
+ };
3835
+ }
3723
3836
  /**
3724
3837
  * Utility function to generate metadata for a Contract or return existing Pubkey
3725
3838
  */