@streamflow/stream 10.0.0-alpha.p313.18b7be3 → 10.0.0-alpha.p313.4046054

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.
package/README.md CHANGED
@@ -99,7 +99,7 @@ const solanaInteractParams = {
99
99
 
100
100
  ## Create a Vesting Stream
101
101
 
102
- Vesting Streams are a type of Stream used to linearly unlock a given amount of tokens over a period of time. You can specify the amount, cliff, start time and releasePeriod along with other configuration that controls who can transfer or cancel the contract. For a Stream to be considered Vesting in the Streamflow App it has to match the criteria from the `isVesting` helper function (or `buildStreamType` returns `StreamType.Vesting`). The stream must not allow top-ups, the cliff amount must not be too close to the total amount and it must not be a Dynamic token lock.
102
+ Vesting Streams are a type of Stream used to linearly unlock a given amount of tokens over a period of time. You can specify the amount, cliff, start time and releasePeriod along with other configuration that controls who can transfer or cancel the contract. For a Stream to be considered Vesting in the Streamflow App it has to match the criteria from the `isVesting` helper function (or `buildStreamType` returns `StreamType.Vesting`). The cliff amount must not be too close to the total amount and it must not be a Dynamic token lock.
103
103
 
104
104
  For more details creating a Stream with arbitrary configuration see [General Stream creation](#general-stream-creation).
105
105
  For creating multiple Streams at once see [Create Multiple Streams](#create-multiple-streams-at-once).
@@ -426,7 +426,7 @@ console.log(remaining);
426
426
  ```javascript
427
427
  const data: IGetAllData = {
428
428
  address: "99h00075bKjVg000000tLdk4w42NyG3Mv0000dc0M99",
429
- type: StreamType.All, // StreamType.Vesting, StreamType.Lock, StreamType.Payment
429
+ type: StreamType.All, // StreamType.Vesting, StreamType.Lock
430
430
  direction: StreamDirection.All, // StreamDirection.Outgoing, StreamDirection.Incoming
431
431
  };
432
432
 
@@ -59,11 +59,8 @@ var calculateUnlockedAmount = ({
59
59
  var isCliffCloseToDepositedAmount = (streamData) => {
60
60
  return streamData.cliffAmount.gte(streamData.depositedAmount.sub(new BN3__default.default(1)));
61
61
  };
62
- var isPayment = (streamData) => {
63
- return streamData.canTopup;
64
- };
65
62
  var isVesting = (streamData) => {
66
- return !streamData.canTopup && !isCliffCloseToDepositedAmount(streamData) && !isDynamicLock(streamData.minPrice, streamData.maxPrice, streamData.minPercentage, streamData.maxPercentage);
63
+ return !isCliffCloseToDepositedAmount(streamData) && !isDynamicLock(streamData.minPrice, streamData.maxPrice, streamData.minPercentage, streamData.maxPercentage);
67
64
  };
68
65
  var isAligned = (stream) => {
69
66
  return "minPrice" in stream && "maxPrice" in stream && "minPercentage" in stream && "maxPercentage" in stream;
@@ -78,13 +75,10 @@ var isTokenLock = (streamData) => {
78
75
  return !streamData.canTopup && !streamData.automaticWithdrawal && !streamData.cancelableBySender && !streamData.cancelableByRecipient && !streamData.transferableBySender && (isCliffCloseToDepositedAmount(streamData) || isDynamicLock(streamData.minPrice, streamData.maxPrice, streamData.minPercentage, streamData.maxPercentage));
79
76
  };
80
77
  var buildStreamType = (streamData) => {
81
- if (isVesting(streamData)) {
82
- return "vesting" /* Vesting */;
83
- }
84
78
  if (isTokenLock(streamData)) {
85
79
  return "lock" /* Lock */;
86
80
  }
87
- return "payment" /* Payment */;
81
+ return "vesting" /* Vesting */;
88
82
  };
89
83
  var decodeEndTime = (endTime) => {
90
84
  if (endTime.gt(new BN3__default.default(MAX_SAFE_UNIX_TIME_VALUE))) {
@@ -101,7 +95,6 @@ var StreamDirection = /* @__PURE__ */ ((StreamDirection2) => {
101
95
  })(StreamDirection || {});
102
96
  var StreamType = /* @__PURE__ */ ((StreamType2) => {
103
97
  StreamType2["All"] = "all";
104
- StreamType2["Payment"] = "payment";
105
98
  StreamType2["Vesting"] = "vesting";
106
99
  StreamType2["Lock"] = "lock";
107
100
  return StreamType2;
@@ -912,7 +905,7 @@ var streamflow_aligned_unlocks_default = {
912
905
  address: "aSTRM2NKoKxNnkmLWk9sz3k74gKBk9t7bpPrTGxMszH",
913
906
  metadata: {
914
907
  name: "streamflow_aligned_unlocks",
915
- version: "1.3.0",
908
+ version: "1.4.0",
916
909
  spec: "0.1.0",
917
910
  description: "Proxy to update unlock amount within Streamflow vesting protocol according to Token performance and other metrics"
918
911
  },
@@ -1786,6 +1779,80 @@ var streamflow_aligned_unlocks_default = {
1786
1779
  ],
1787
1780
  args: []
1788
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
+ },
1789
1856
  {
1790
1857
  name: "update_test_oracle",
1791
1858
  discriminator: [
@@ -2381,6 +2448,32 @@ var streamflow_aligned_unlocks_default = {
2381
2448
  ]
2382
2449
  }
2383
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
+ },
2384
2477
  {
2385
2478
  name: "UpdateTestOracleParams",
2386
2479
  type: {
@@ -2605,7 +2698,10 @@ var SolanaStreamClient = class {
2605
2698
  floorPrice
2606
2699
  } = streamParams;
2607
2700
  const { isNative, sender, computeLimit, computePrice, metadataPubKeys } = extParams;
2608
- 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
+ );
2609
2705
  common.assertHasPublicKey(sender, "Sender's PublicKey is not available, check passed wallet adapter!");
2610
2706
  const recipientPublicKey = new web3_js.PublicKey(recipient);
2611
2707
  const mintPublicKey = isNative ? splToken.NATIVE_MINT : new web3_js.PublicKey(mint);
@@ -2780,10 +2876,7 @@ var SolanaStreamClient = class {
2780
2876
  * @returns Create result
2781
2877
  */
2782
2878
  async createUnchecked(data, extParams) {
2783
- const { ixs, metadata, metadataPubKey } = await this.prepareCreateUncheckedInstructions(
2784
- data,
2785
- extParams
2786
- );
2879
+ const { ixs, metadata, metadataPubKey } = await this.prepareCreateUncheckedInstructions(data, extParams);
2787
2880
  const { tx, hash, context } = await common.prepareTransaction(
2788
2881
  this.connection,
2789
2882
  ixs,
@@ -2935,19 +3028,10 @@ var SolanaStreamClient = class {
2935
3028
  recipient: recipientData.recipient
2936
3029
  });
2937
3030
  }
2938
- const prepareInstructions = await this.getCreateATAInstructions(
2939
- [partnerPublicKey],
2940
- mintPublicKey,
2941
- sender,
2942
- true
2943
- );
3031
+ const prepareInstructions = await this.getCreateATAInstructions([partnerPublicKey], mintPublicKey, sender, true);
2944
3032
  if (isNative) {
2945
3033
  const totalDepositedAmount = recipients.reduce((acc, recipient) => recipient.amount.add(acc), new BN3__default.default(0));
2946
- const nativeInstructions = await common.prepareWrappedAccount(
2947
- this.connection,
2948
- sender.publicKey,
2949
- totalDepositedAmount
2950
- );
3034
+ const nativeInstructions = await common.prepareWrappedAccount(this.connection, sender.publicKey, totalDepositedAmount);
2951
3035
  prepareInstructions.push(...nativeInstructions);
2952
3036
  }
2953
3037
  return {
@@ -3145,10 +3229,7 @@ var SolanaStreamClient = class {
3145
3229
  async withdraw({ id, amount = WITHDRAW_AVAILABLE_AMOUNT }, extParams) {
3146
3230
  const { invoker, customInstructions } = extParams;
3147
3231
  common.assertHasPublicKey(invoker, "Invoker's PublicKey is not available, check passed wallet adapter!");
3148
- const ixs = await this.prepareWithdrawInstructions(
3149
- { id, amount },
3150
- extParams
3151
- );
3232
+ const ixs = await this.prepareWithdrawInstructions({ id, amount }, extParams);
3152
3233
  const metadata = new web3_js.PublicKey(id);
3153
3234
  await this.applyCustomAfterInstructions(ixs, customInstructions, metadata);
3154
3235
  const { tx, hash, context } = await common.prepareTransaction(this.connection, ixs, invoker.publicKey);
@@ -3652,17 +3733,26 @@ var SolanaStreamClient = class {
3652
3733
  const streamPublicKey = new web3_js.PublicKey(data.id);
3653
3734
  const escrow = await this.connection.getAccountInfo(streamPublicKey);
3654
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
+ }
3655
3741
  const ixs = common.prepareBaseInstructions(this.connection, {
3656
3742
  computePrice,
3657
3743
  computeLimit
3658
3744
  });
3659
3745
  ixs.push(
3660
- 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, {
3661
3751
  authority: invoker.publicKey,
3662
3752
  metadata: streamPublicKey,
3663
3753
  withdrawor: WITHDRAWOR_PUBLIC_KEY,
3664
3754
  systemProgram: web3_js.SystemProgram.programId
3665
- })
3755
+ }))
3666
3756
  );
3667
3757
  return ixs;
3668
3758
  }
@@ -3721,8 +3811,8 @@ var SolanaStreamClient = class {
3721
3811
  return extractSolanaErrorCode(err.toString() ?? "Unknown error!", logs);
3722
3812
  }
3723
3813
  /**
3724
- * Utility function that checks whether the associated stream address is an aligned unlock contract, indicated by whether the sender/creator is a PDA
3725
- */
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
+ */
3726
3816
  isAlignedUnlock(streamPublicKey, senderPublicKey) {
3727
3817
  const pda = deriveContractPDA(this.alignedProxyProgram.programId, streamPublicKey);
3728
3818
  return senderPublicKey.equals(pda);
@@ -4257,7 +4347,6 @@ exports.isAligned = isAligned;
4257
4347
  exports.isCliffCloseToDepositedAmount = isCliffCloseToDepositedAmount;
4258
4348
  exports.isCreateAlignedStreamData = isCreateAlignedStreamData;
4259
4349
  exports.isDynamicLock = isDynamicLock;
4260
- exports.isPayment = isPayment;
4261
4350
  exports.isTokenLock = isTokenLock;
4262
4351
  exports.isVesting = isVesting;
4263
4352
  exports.sendAndConfirmStreamRawTransaction = sendAndConfirmStreamRawTransaction;