@streamflow/stream 10.0.0-alpha.p313.4470e29 → 10.0.0-alpha.p313.85091cd

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,
@@ -2928,19 +3028,10 @@ var SolanaStreamClient = class {
2928
3028
  recipient: recipientData.recipient
2929
3029
  });
2930
3030
  }
2931
- const prepareInstructions = await this.getCreateATAInstructions(
2932
- [partnerPublicKey],
2933
- mintPublicKey,
2934
- sender,
2935
- true
2936
- );
3031
+ const prepareInstructions = await this.getCreateATAInstructions([partnerPublicKey], mintPublicKey, sender, true);
2937
3032
  if (isNative) {
2938
3033
  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
- );
3034
+ const nativeInstructions = await common.prepareWrappedAccount(this.connection, sender.publicKey, totalDepositedAmount);
2944
3035
  prepareInstructions.push(...nativeInstructions);
2945
3036
  }
2946
3037
  return {
@@ -3009,7 +3100,7 @@ var SolanaStreamClient = class {
3009
3100
  if (!sender.publicKey) {
3010
3101
  throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
3011
3102
  }
3012
- const { instructionsBatch, metadatas, metadataToRecipient, prepareInstructions } = await this.buildCreateMultipleTransactionInstructions(data, extParams);
3103
+ const { instructionsBatch, metadatas, prepareInstructions, metadataToRecipient } = await this.flatBuildCreateMultipleTransactionInstructions(data, extParams);
3013
3104
  const errors = [];
3014
3105
  const signatures = [];
3015
3106
  const metadataPubKeys = metadataPubKeysExt || [];
@@ -3074,7 +3165,7 @@ var SolanaStreamClient = class {
3074
3165
  if (!sender.publicKey) {
3075
3166
  throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
3076
3167
  }
3077
- const { instructionsBatch, metadatas, metadataToRecipient, prepareInstructions } = await this.buildCreateMultipleTransactionInstructions(data, extParams);
3168
+ const { instructionsBatch, metadatas, prepareInstructions, metadataToRecipient } = await this.flatBuildCreateMultipleTransactionInstructions(data, extParams);
3078
3169
  const errors = [];
3079
3170
  const signatures = [];
3080
3171
  const batch = [];
@@ -3138,10 +3229,7 @@ var SolanaStreamClient = class {
3138
3229
  async withdraw({ id, amount = WITHDRAW_AVAILABLE_AMOUNT }, extParams) {
3139
3230
  const { invoker, customInstructions } = extParams;
3140
3231
  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
- );
3232
+ const ixs = await this.prepareWithdrawInstructions({ id, amount }, extParams);
3145
3233
  const metadata = new web3_js.PublicKey(id);
3146
3234
  await this.applyCustomAfterInstructions(ixs, customInstructions, metadata);
3147
3235
  const { tx, hash, context } = await common.prepareTransaction(this.connection, ixs, invoker.publicKey);
@@ -3239,7 +3327,7 @@ var SolanaStreamClient = class {
3239
3327
  }
3240
3328
  const { sender: senderPublicKey } = decodeStream(account.data);
3241
3329
  const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, senderPublicKey);
3242
- const ixs = isAlignedUnlock ? await this.prepareCancelAlignedUnlockInstructions(cancelData, extParams) : await this.prepareCancelStreamInstructions(cancelData, extParams);
3330
+ const ixs = isAlignedUnlock ? await this.prepareCancelAlignedUnlockInstructions(cancelData, extParams) : await this.prepareCancelLinearStream(cancelData, extParams);
3243
3331
  return ixs;
3244
3332
  }
3245
3333
  /**
@@ -3287,7 +3375,7 @@ var SolanaStreamClient = class {
3287
3375
  * @param {IPrepareStreamExt} extParams - Transaction configuration including invoker wallet, token account validation, and compute settings
3288
3376
  * @returns Transaction instructions
3289
3377
  */
3290
- async prepareCancelStreamInstructions({ id }, { invoker, checkTokenAccounts, computePrice, computeLimit }) {
3378
+ async prepareCancelLinearStream({ id }, { invoker, checkTokenAccounts, computePrice, computeLimit }) {
3291
3379
  common.assertHasPublicKey(invoker, "Invoker's PublicKey is not available, check passed wallet adapter!");
3292
3380
  const streamPublicKey = new web3_js.PublicKey(id);
3293
3381
  const escrowAcc = await this.connection.getAccountInfo(streamPublicKey);
@@ -3645,17 +3733,26 @@ var SolanaStreamClient = class {
3645
3733
  const streamPublicKey = new web3_js.PublicKey(data.id);
3646
3734
  const escrow = await this.connection.getAccountInfo(streamPublicKey);
3647
3735
  common.invariant(escrow, "Couldn't get account info");
3736
+ const { sender: senderPublicKey } = decodeStream(escrow.data);
3737
+ const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, senderPublicKey);
3738
+ if (isAlignedUnlock && (data.enableAutomaticWithdrawal !== void 0 || data.amountPerPeriod !== void 0)) {
3739
+ throw new Error("Automatic withdrawal and rate update are not possible in price-based vesting!");
3740
+ }
3648
3741
  const ixs = common.prepareBaseInstructions(this.connection, {
3649
3742
  computePrice,
3650
3743
  computeLimit
3651
3744
  });
3652
3745
  ixs.push(
3653
- await updateStreamInstruction(data, this.programId, {
3746
+ await (isAlignedUnlock ? this.alignedProxyProgram.methods.updateContract({
3747
+ transferableBySender: data.transferableBySender ?? null,
3748
+ transferableByRecipient: data.transferableByRecipient ?? null,
3749
+ cancelableBySender: data.cancelableBySender ?? null
3750
+ }).accounts({ sender: invoker.publicKey, streamMetadata: streamPublicKey, withdrawor: WITHDRAWOR_PUBLIC_KEY }).accountsPartial({ streamflowProgram: this.programId }).instruction() : updateStreamInstruction(data, this.programId, {
3654
3751
  authority: invoker.publicKey,
3655
3752
  metadata: streamPublicKey,
3656
3753
  withdrawor: WITHDRAWOR_PUBLIC_KEY,
3657
3754
  systemProgram: web3_js.SystemProgram.programId
3658
- })
3755
+ }))
3659
3756
  );
3660
3757
  return ixs;
3661
3758
  }
@@ -3691,11 +3788,11 @@ var SolanaStreamClient = class {
3691
3788
  return DEFAULT_STREAMFLOW_FEE;
3692
3789
  }
3693
3790
  /**
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
- */
3791
+ * Returns total fee percent, streamflow fees + partner fees
3792
+ * @param getFeesData structure with address for which we need to derive fee, either sender or partner usually
3793
+ * @param chainSpecificParams additional parameters required by chain client
3794
+ * @returns fee as floating number, so if fee is 0.99%, it will return 0.99
3795
+ */
3699
3796
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
3700
3797
  async getTotalFee(getFeesData) {
3701
3798
  const fees = await this.getFees(getFeesData);
@@ -3714,12 +3811,27 @@ var SolanaStreamClient = class {
3714
3811
  return extractSolanaErrorCode(err.toString() ?? "Unknown error!", logs);
3715
3812
  }
3716
3813
  /**
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
- */
3814
+ * Utility function that checks whether the associated stream address is an aligned unlock contract, indicated by whether the sender/creator is a PDA
3815
+ */
3719
3816
  isAlignedUnlock(streamPublicKey, senderPublicKey) {
3720
3817
  const pda = deriveContractPDA(this.alignedProxyProgram.programId, streamPublicKey);
3721
3818
  return senderPublicKey.equals(pda);
3722
3819
  }
3820
+ async flatBuildCreateMultipleTransactionInstructions(data, extParams) {
3821
+ const dataArray = Array.isArray(data) ? data : [data];
3822
+ const results = await Promise.all(
3823
+ dataArray.map((item) => this.buildCreateMultipleTransactionInstructions(item, extParams))
3824
+ );
3825
+ return {
3826
+ instructionsBatch: results.flatMap((r) => r.instructionsBatch),
3827
+ metadatas: results.flatMap((r) => r.metadatas),
3828
+ prepareInstructions: results.flatMap((r) => r.prepareInstructions),
3829
+ metadataToRecipient: results.reduce(
3830
+ (acc, r) => Object.assign(acc, r.metadataToRecipient),
3831
+ {}
3832
+ )
3833
+ };
3834
+ }
3723
3835
  /**
3724
3836
  * Utility function to generate metadata for a Contract or return existing Pubkey
3725
3837
  */