@streamflow/stream 9.0.3 → 9.1.0

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.
@@ -495,8 +495,8 @@ declare class SolanaStreamClient extends BaseStreamClient {
495
495
  */
496
496
  extractErrorCode(err: Error): string | null;
497
497
  /**
498
- * Utility function that checks whether the associated stream address is an aligned unlock contract, indicated by whether the sender/creator is a PDA
499
- */
498
+ * Utility function that checks whether the associated stream address is an aligned unlock contract, indicated by whether the sender/creator is a PDA
499
+ */
500
500
  isAlignedUnlock(streamPublicKey: PublicKey, senderPublicKey: PublicKey): boolean;
501
501
  /**
502
502
  * Utility function to generate metadata for a Contract or return existing Pubkey
@@ -3494,7 +3494,7 @@ var streamflow_aligned_unlocks_default = {
3494
3494
  address: "aSTRM2NKoKxNnkmLWk9sz3k74gKBk9t7bpPrTGxMszH",
3495
3495
  metadata: {
3496
3496
  name: "streamflow_aligned_unlocks",
3497
- version: "1.3.0",
3497
+ version: "1.4.0",
3498
3498
  spec: "0.1.0",
3499
3499
  description: "Proxy to update unlock amount within Streamflow vesting protocol according to Token performance and other metrics"
3500
3500
  },
@@ -4368,6 +4368,80 @@ var streamflow_aligned_unlocks_default = {
4368
4368
  ],
4369
4369
  args: []
4370
4370
  },
4371
+ {
4372
+ name: "update_contract",
4373
+ discriminator: [
4374
+ 78,
4375
+ 184,
4376
+ 162,
4377
+ 174,
4378
+ 233,
4379
+ 5,
4380
+ 40,
4381
+ 82
4382
+ ],
4383
+ accounts: [
4384
+ {
4385
+ name: "sender",
4386
+ writable: true,
4387
+ signer: true
4388
+ },
4389
+ {
4390
+ name: "proxy_metadata",
4391
+ docs: [
4392
+ "Proxy Contract"
4393
+ ],
4394
+ writable: true,
4395
+ pda: {
4396
+ seeds: [
4397
+ {
4398
+ kind: "const",
4399
+ value: [
4400
+ 99,
4401
+ 111,
4402
+ 110,
4403
+ 116,
4404
+ 114,
4405
+ 97,
4406
+ 99,
4407
+ 116
4408
+ ]
4409
+ },
4410
+ {
4411
+ kind: "account",
4412
+ path: "stream_metadata"
4413
+ }
4414
+ ]
4415
+ }
4416
+ },
4417
+ {
4418
+ name: "stream_metadata",
4419
+ writable: true
4420
+ },
4421
+ {
4422
+ name: "withdrawor",
4423
+ writable: true
4424
+ },
4425
+ {
4426
+ name: "streamflow_program",
4427
+ address: "strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m"
4428
+ },
4429
+ {
4430
+ name: "system_program",
4431
+ address: "11111111111111111111111111111111"
4432
+ }
4433
+ ],
4434
+ args: [
4435
+ {
4436
+ name: "params",
4437
+ type: {
4438
+ defined: {
4439
+ name: "UpdateContractParams"
4440
+ }
4441
+ }
4442
+ }
4443
+ ]
4444
+ },
4371
4445
  {
4372
4446
  name: "update_test_oracle",
4373
4447
  discriminator: [
@@ -4963,6 +5037,32 @@ var streamflow_aligned_unlocks_default = {
4963
5037
  ]
4964
5038
  }
4965
5039
  },
5040
+ {
5041
+ name: "UpdateContractParams",
5042
+ type: {
5043
+ kind: "struct",
5044
+ fields: [
5045
+ {
5046
+ name: "transferable_by_sender",
5047
+ type: {
5048
+ option: "bool"
5049
+ }
5050
+ },
5051
+ {
5052
+ name: "transferable_by_recipient",
5053
+ type: {
5054
+ option: "bool"
5055
+ }
5056
+ },
5057
+ {
5058
+ name: "cancelable_by_sender",
5059
+ type: {
5060
+ option: "bool"
5061
+ }
5062
+ }
5063
+ ]
5064
+ }
5065
+ },
4966
5066
  {
4967
5067
  name: "UpdateTestOracleParams",
4968
5068
  type: {
@@ -5188,7 +5288,10 @@ var SolanaStreamClient = class extends BaseStreamClient {
5188
5288
  floorPrice
5189
5289
  } = streamParams;
5190
5290
  const { isNative, sender, computeLimit, computePrice, metadataPubKeys } = extParams;
5191
- common.invariant(priceOracle || !oracleType || oracleType === "none", "Price oracle is required for the specified oracle type");
5291
+ common.invariant(
5292
+ priceOracle || !oracleType || oracleType === "none",
5293
+ "Price oracle is required for the specified oracle type"
5294
+ );
5192
5295
  common.assertHasPublicKey(sender, "Sender's PublicKey is not available, check passed wallet adapter!");
5193
5296
  const recipientPublicKey = new web3_js.PublicKey(recipient);
5194
5297
  const mintPublicKey = isNative ? splToken.NATIVE_MINT : new web3_js.PublicKey(mint);
@@ -5363,10 +5466,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
5363
5466
  * @returns Create result
5364
5467
  */
5365
5468
  async createUnchecked(data, extParams) {
5366
- const { ixs, metadata, metadataPubKey } = await this.prepareCreateUncheckedInstructions(
5367
- data,
5368
- extParams
5369
- );
5469
+ const { ixs, metadata, metadataPubKey } = await this.prepareCreateUncheckedInstructions(data, extParams);
5370
5470
  const { tx, hash, context } = await solana.prepareTransaction(
5371
5471
  this.connection,
5372
5472
  ixs,
@@ -5518,19 +5618,10 @@ var SolanaStreamClient = class extends BaseStreamClient {
5518
5618
  recipient: recipientData.recipient
5519
5619
  });
5520
5620
  }
5521
- const prepareInstructions = await this.getCreateATAInstructions(
5522
- [partnerPublicKey],
5523
- mintPublicKey,
5524
- sender,
5525
- true
5526
- );
5621
+ const prepareInstructions = await this.getCreateATAInstructions([partnerPublicKey], mintPublicKey, sender, true);
5527
5622
  if (isNative) {
5528
5623
  const totalDepositedAmount = recipients.reduce((acc, recipient) => recipient.amount.add(acc), new BN7__default.default(0));
5529
- const nativeInstructions = await solana.prepareWrappedAccount(
5530
- this.connection,
5531
- sender.publicKey,
5532
- totalDepositedAmount
5533
- );
5624
+ const nativeInstructions = await solana.prepareWrappedAccount(this.connection, sender.publicKey, totalDepositedAmount);
5534
5625
  prepareInstructions.push(...nativeInstructions);
5535
5626
  }
5536
5627
  return {
@@ -5728,10 +5819,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
5728
5819
  async withdraw({ id, amount = WITHDRAW_AVAILABLE_AMOUNT }, extParams) {
5729
5820
  const { invoker, customInstructions } = extParams;
5730
5821
  common.assertHasPublicKey(invoker, "Invoker's PublicKey is not available, check passed wallet adapter!");
5731
- const ixs = await this.prepareWithdrawInstructions(
5732
- { id, amount },
5733
- extParams
5734
- );
5822
+ const ixs = await this.prepareWithdrawInstructions({ id, amount }, extParams);
5735
5823
  const metadata = new web3_js.PublicKey(id);
5736
5824
  await this.applyCustomAfterInstructions(ixs, customInstructions, metadata);
5737
5825
  const { tx, hash, context } = await solana.prepareTransaction(this.connection, ixs, invoker.publicKey);
@@ -6181,10 +6269,20 @@ var SolanaStreamClient = class extends BaseStreamClient {
6181
6269
  const accounts = await this.connection.getProgramAccounts(this.programId, {
6182
6270
  filters
6183
6271
  });
6184
- return accounts.map(({ pubkey, account }) => ({
6185
- publicKey: pubkey,
6186
- account: new Contract2(decodeStream(account.data))
6187
- }));
6272
+ const mapped = await Promise.all(
6273
+ accounts.map(async ({ pubkey, account }) => {
6274
+ const stream = decodeStream(account.data);
6275
+ if (this.isAlignedUnlock(pubkey, stream.sender)) {
6276
+ const alignedProxy = await this.alignedProxyProgram.account.contract.fetch(
6277
+ deriveContractPDA(this.alignedProxyProgram.programId, pubkey)
6278
+ );
6279
+ common.invariant(alignedProxy, "Couldn't get aligned proxy account info");
6280
+ return { publicKey: pubkey, account: new AlignedContract(stream, alignedProxy) };
6281
+ }
6282
+ return { publicKey: pubkey, account: new Contract2(stream) };
6283
+ })
6284
+ );
6285
+ return mapped;
6188
6286
  }
6189
6287
  /**
6190
6288
  * Attempts updating the stream auto withdrawal params and amount per period
@@ -6225,17 +6323,26 @@ var SolanaStreamClient = class extends BaseStreamClient {
6225
6323
  const streamPublicKey = new web3_js.PublicKey(data.id);
6226
6324
  const escrow = await this.connection.getAccountInfo(streamPublicKey);
6227
6325
  common.invariant(escrow, "Couldn't get account info");
6326
+ const { sender: senderPublicKey } = decodeStream(escrow.data);
6327
+ const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, senderPublicKey);
6328
+ if (isAlignedUnlock && (data.enableAutomaticWithdrawal !== void 0 || data.amountPerPeriod !== void 0)) {
6329
+ throw new Error("Automatic withdrawal and rate update are not possible in price-based vesting!");
6330
+ }
6228
6331
  const ixs = solana.prepareBaseInstructions(this.connection, {
6229
6332
  computePrice,
6230
6333
  computeLimit
6231
6334
  });
6232
6335
  ixs.push(
6233
- await updateStreamInstruction(data, this.programId, {
6336
+ await (isAlignedUnlock ? this.alignedProxyProgram.methods.updateContract({
6337
+ transferableBySender: data.transferableBySender ?? null,
6338
+ transferableByRecipient: data.transferableByRecipient ?? null,
6339
+ cancelableBySender: data.cancelableBySender ?? null
6340
+ }).accounts({ sender: invoker.publicKey, streamMetadata: streamPublicKey, withdrawor: WITHDRAWOR_PUBLIC_KEY }).accountsPartial({ streamflowProgram: this.programId }).instruction() : updateStreamInstruction(data, this.programId, {
6234
6341
  authority: invoker.publicKey,
6235
6342
  metadata: streamPublicKey,
6236
6343
  withdrawor: WITHDRAWOR_PUBLIC_KEY,
6237
6344
  systemProgram: web3_js.SystemProgram.programId
6238
- })
6345
+ }))
6239
6346
  );
6240
6347
  return ixs;
6241
6348
  }
@@ -6280,8 +6387,8 @@ var SolanaStreamClient = class extends BaseStreamClient {
6280
6387
  return extractSolanaErrorCode(err.toString() ?? "Unknown error!", logs);
6281
6388
  }
6282
6389
  /**
6283
- * Utility function that checks whether the associated stream address is an aligned unlock contract, indicated by whether the sender/creator is a PDA
6284
- */
6390
+ * Utility function that checks whether the associated stream address is an aligned unlock contract, indicated by whether the sender/creator is a PDA
6391
+ */
6285
6392
  isAlignedUnlock(streamPublicKey, senderPublicKey) {
6286
6393
  const pda = deriveContractPDA(this.alignedProxyProgram.programId, streamPublicKey);
6287
6394
  return senderPublicKey.equals(pda);