@streamflow/stream 12.1.1 → 12.2.1-alpha.p361.52afa92

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,9 +1,10 @@
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, IPrepareTopUpstreamExt, IRecipient, IRequestCancelData, ISearchStreams, ITopUpData, ITopUpStreamExt, ITransactionExtWithInstructions, ITransactionResult, ITransferData, IUpdateData, IWithdrawCancelRequestData, 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, requestCancelStreamInstruction, sendAndConfirmStreamRawTransaction, signAllTransactionWithRecipients, timelockIDL, topupStreamInstruction, transferStreamInstruction, transformContract, updateStreamInstruction, withdrawCancelRequestInstruction, withdrawStreamInstruction } from './solana/index.js';
1
+ export { f as Account, g as AlignedContract, h as AlignedProxyErrorCode, A as AlignedStream, i as AlignedStreamData, j as AlignedUnlocksContract, k as BatchCreationItem, l as BatchExecuteResult, m as BatchInstructionResult, B as BatchItem, n as BatchItemError, a as BatchItemResult, o as BatchItemSuccess, p as BuildTransactionFn, q as BuildTransactionOptions, r as BuiltTransaction, C as CancelFn, s as ChangeOracleParams, t as ClientCreationOptions, u as Contract, v as ContractErrorCode, w as CreateBatchFn, x as CreateFn, y as CreateInstructionResult, z as CreateParams, E as CreateTestOracleParams, D as DecodedStream, F as Env, G as ExecuteBatchFn, H as ExecuteBatchSequentialFn, J as ExecuteFn, K as ExecutionEnv, L as IAlignedStreamConfig, M as IBaseStreamConfig, N as ICancelData, d as ICreateAlignedStreamData, O as ICreateExt, P as ICreateLinearStreamData, Q as ICreateLockBatchParams, R as ICreateLockParams, T as ICreateMultiError, U as ICreateMultipleAlignedStreamData, V as ICreateMultipleLinearStreamData, W as ICreateMultipleStreamData, X as ICreateResult, c as ICreateStreamData, Y as ICreateStreamExt, Z as ICreateStreamInstructions, _ as ICreateVestingBatchParams, $ as ICreateVestingParams, a0 as IFees, a1 as IGetAllData, a2 as IGetFeesData, a3 as IGetOneData, a4 as IInteractData, a5 as IInteractStreamExt, a6 as ILockBatchRecipient, a7 as IMultiTransactionResult, a8 as IPrepareCreateStreamExt, a9 as IPrepareStreamExt, aa as IPrepareTopUpstreamExt, ab as IRecipient, ac as IRequestCancelData, e as ISearchStreams, ad as ITopUpData, ae as ITopUpStreamExt, af as ITransactionExtWithInstructions, ag as ITransactionResult, ah as ITransferData, I as IUpdateData, ai as IVestingBatchRecipient, aj as IWithdrawCancelRequestData, ak as IWithdrawData, al as InstructionGenerator, am as InstructionResult, an as Invoker, ao as LinearStream, ap as MetadataRecipientHashMap, aq as NativeOptions, ar as OracleType, as as OracleTypeName, at as SignFn, au as SolanaStreamClient, b as Stream, av as StreamClientOptions, aw as StreamClientOptionsWithConnection, ax as StreamDirection, S as StreamType, ay as TestOracle, az as TopupFn, aA as TransactionSchedulingOptions, aB as TransferFn, aC as UpdateFn, aD as UpdateTestOracleParams, aE as WithdrawFn, aF as buildLockBatchParams, aG as buildLockParams, aH as buildTransaction, aI as buildVestingBatchParams, aJ as buildVestingParams, aK as cancel, aL as computeAmountPerPeriod, aM as create, aN as createBatch, aO as createClientFromEnv, aP as createLock, aQ as createLockBatch, aR as createVesting, aS as createVestingBatch, aT as execute, aU as executeBatch, aV as executeBatchSequential, aW as resolveConnection, aX as resolveDuration, aY as sign, aZ as topup, a_ as transfer, a$ as update, b0 as withdraw } from './index-Cu0If4Dd.js';
2
+ export { AIRDROP_AMOUNT, AIRDROP_TEST_TOKEN, ALIGNED_COMPUTE_LIMIT, ALIGNED_PRECISION_FACTOR_POW, ALIGNED_UNLOCKS_PROGRAM_ID, ApiClient, ApiClientOptions, CONTRACT_DISCRIMINATOR, CONTRACT_SEED, CREATE_PARAMS_PADDING, Chain, ContractSchema, ContractType, DEFAULT_AUTO_CLAIM_FEE_SOL, DEFAULT_CREATION_FEE_SOL, DEFAULT_STREAMFLOW_FEE, DynamicContractSchema, ESCROW_SEED, FEES_METADATA_SEED, FEE_ORACLE_PUBLIC_KEY, GetContractsOptions, MAX_SAFE_UNIX_TIME_VALUE, METADATA_SEED, ORIGINAL_CONTRACT_SENDER_OFFSET, 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, TEST_ORACLE_DISCRIMINATOR, TEST_ORACLE_SEED, TX_FINALITY_CONFIRMED, TabulariumContract, 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, requestCancelStreamInstruction, sendAndConfirmStreamRawTransaction, signAllTransactionWithRecipients, timelockIDL, topupStreamInstruction, transferStreamInstruction, transformContract, updateStreamInstruction, withdrawCancelRequestInstruction, withdrawStreamInstruction } from './solana/index.js';
2
3
  export { ContractError, ICluster, getBN, getNumberFromBN } from '@streamflow/common';
3
- import 'p-queue';
4
- import '@solana/web3.js';
5
- import '@coral-xyz/anchor';
6
4
  import '@solana/wallet-adapter-base';
5
+ import '@solana/web3.js';
7
6
  import 'bn.js';
7
+ import '@coral-xyz/anchor';
8
+ import 'p-queue';
8
9
  import './solana/descriptor/streamflow_aligned_unlocks.js';
9
10
  import 'buffer';
package/dist/esm/index.js CHANGED
@@ -606,9 +606,9 @@ var decodeStream = (buf) => {
606
606
  };
607
607
  };
608
608
  async function signAllTransactionWithRecipients(sender, items) {
609
- const isKeypair = isSignerKeypair(sender);
609
+ const isKeypair2 = isSignerKeypair(sender);
610
610
  const isWallet = isSignerWallet(sender);
611
- if (isKeypair) {
611
+ if (isKeypair2) {
612
612
  return items.map((t) => {
613
613
  t.tx.sign([sender]);
614
614
  return { tx: t.tx, recipient: t.recipient };
@@ -3323,6 +3323,19 @@ var SolanaStreamClient = class {
3323
3323
  this.schedulingParams = {
3324
3324
  sendThrottler: sendThrottler ?? buildSendThrottler(sendRate)
3325
3325
  };
3326
+ } else if ("connection" in optionsOrClusterUrl) {
3327
+ const { connection, cluster: cluster2, commitment: commitment2, programId: programId2 = "", sendScheduler } = optionsOrClusterUrl;
3328
+ this.connection = connection;
3329
+ this.commitment = commitment2 ?? "confirmed";
3330
+ this.programId = programId2 !== "" ? new PublicKey(programId2) : new PublicKey(PROGRAM_ID[cluster2]);
3331
+ this.partnerOracleProgramId = new PublicKey(PARTNER_ORACLE_PROGRAM_ID[cluster2]);
3332
+ this.feeOraclePublicKey = new PublicKey(FEE_ORACLE_PUBLIC_KEY[cluster2]);
3333
+ const schedulingOptions = sendScheduler && "sendRate" in sendScheduler ? sendScheduler : void 0;
3334
+ const sendThrottler2 = !sendScheduler ? buildSendThrottler(1) : "sendRate" in sendScheduler ? buildSendThrottler(sendScheduler.sendRate ?? 1, sendScheduler.sendInterval) : sendScheduler;
3335
+ this.schedulingParams = {
3336
+ ...schedulingOptions,
3337
+ sendThrottler: sendThrottler2
3338
+ };
3326
3339
  } else {
3327
3340
  const {
3328
3341
  clusterUrl,
@@ -3349,7 +3362,7 @@ var SolanaStreamClient = class {
3349
3362
  };
3350
3363
  this.alignedProxyProgram = new Program(alignedUnlocksProgram, { connection: this.connection });
3351
3364
  this.apiClient = createClient(
3352
- typeof optionsOrClusterUrl === "object" && optionsOrClusterUrl.cluster !== ICluster.Mainnet ? { cluster: "devnet" } : { cluster: "mainnet" }
3365
+ typeof optionsOrClusterUrl === "object" && ("connection" in optionsOrClusterUrl ? optionsOrClusterUrl.cluster !== ICluster.Mainnet : optionsOrClusterUrl.cluster !== ICluster.Mainnet) ? { cluster: "devnet" } : { cluster: "mainnet" }
3353
3366
  );
3354
3367
  }
3355
3368
  getConnection() {
@@ -4062,7 +4075,7 @@ var SolanaStreamClient = class {
4062
4075
  }
4063
4076
  const signedBatch = await signAllTransactionWithRecipients(sender, batch);
4064
4077
  if (prepareInstructions.length > 0) {
4065
- const prepareTx = signedBatch.shift();
4078
+ const prepareTx = signedBatch.pop();
4066
4079
  await sendAndConfirmStreamRawTransaction(this.connection, prepareTx, { hash, context }, this.schedulingParams);
4067
4080
  }
4068
4081
  const responses = [];
@@ -4157,9 +4170,9 @@ var SolanaStreamClient = class {
4157
4170
  mintAccount,
4158
4171
  tokenProgramId,
4159
4172
  potentialTransfers: [
4160
- { source: escrowTokens, destination: recipientTokens, owner: streamPublicKey },
4161
- { source: escrowTokens, destination: streamflowTreasuryTokens, owner: streamPublicKey },
4162
- { source: escrowTokens, destination: partnerTokens, owner: streamPublicKey }
4173
+ { source: escrowTokens, destination: recipientTokens, owner: escrowTokens },
4174
+ { source: escrowTokens, destination: streamflowTreasuryTokens, owner: escrowTokens },
4175
+ { source: escrowTokens, destination: partnerTokens, owner: escrowTokens }
4163
4176
  ]
4164
4177
  });
4165
4178
  ixs.push(...ataIx, withdrawIx);
@@ -4251,10 +4264,10 @@ var SolanaStreamClient = class {
4251
4264
  mintAccount,
4252
4265
  tokenProgramId,
4253
4266
  potentialTransfers: [
4254
- { source: escrowTokens, destination: recipientTokens, owner: streamPublicKey },
4255
- { source: escrowTokens, destination: streamflowTreasuryTokens, owner: streamPublicKey },
4256
- { source: escrowTokens, destination: partnerTokens, owner: streamPublicKey },
4257
- { source: escrowTokens, destination: proxyTokens, owner: streamPublicKey },
4267
+ { source: escrowTokens, destination: recipientTokens, owner: escrowTokens },
4268
+ { source: escrowTokens, destination: streamflowTreasuryTokens, owner: escrowTokens },
4269
+ { source: escrowTokens, destination: partnerTokens, owner: escrowTokens },
4270
+ { source: escrowTokens, destination: proxyTokens, owner: escrowTokens },
4258
4271
  { source: proxyTokens, destination: senderTokens, owner: proxyMetadata }
4259
4272
  ]
4260
4273
  });
@@ -4308,10 +4321,10 @@ var SolanaStreamClient = class {
4308
4321
  mintAccount,
4309
4322
  tokenProgramId,
4310
4323
  potentialTransfers: [
4311
- { source: escrowTokens, destination: recipientTokens, owner: streamPublicKey },
4312
- { source: escrowTokens, destination: streamflowTreasuryTokens, owner: streamPublicKey },
4313
- { source: escrowTokens, destination: partnerTokens, owner: streamPublicKey },
4314
- { source: escrowTokens, destination: senderTokens, owner: streamPublicKey }
4324
+ { source: escrowTokens, destination: recipientTokens, owner: escrowTokens },
4325
+ { source: escrowTokens, destination: streamflowTreasuryTokens, owner: escrowTokens },
4326
+ { source: escrowTokens, destination: partnerTokens, owner: escrowTokens },
4327
+ { source: escrowTokens, destination: senderTokens, owner: escrowTokens }
4315
4328
  ]
4316
4329
  });
4317
4330
  ixs.push(...ixsAta, cancelIx);
@@ -4500,11 +4513,13 @@ var SolanaStreamClient = class {
4500
4513
  if (!escrow?.data) {
4501
4514
  throw new Error("Couldn't get account info");
4502
4515
  }
4503
- const { mint, partner, senderTokens, escrowTokens } = decodeStream(escrow?.data);
4516
+ const { mint, partner, senderTokens, escrowTokens, partnerFeePercent, streamflowFeePercent } = decodeStream(
4517
+ escrow?.data
4518
+ );
4504
4519
  const { mint: mintAccount, tokenProgramId } = await getMintAndProgram(this.connection, mint);
4505
4520
  const streamflowTreasuryTokens = await ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
4506
4521
  const partnerTokens = await ata(mint, partner, tokenProgramId);
4507
- const totalFee = await this.getTotalFee({ address: partner.toBase58() });
4522
+ const totalFee = partnerFeePercent + streamflowFeePercent;
4508
4523
  const totalAmountToTransfer = calculateTotalAmountToDeposit(amount, totalFee);
4509
4524
  if (isNative) {
4510
4525
  ixs.push(...await prepareWrappedAccount(this.connection, invoker.publicKey, totalAmountToTransfer));
@@ -4955,15 +4970,15 @@ var SolanaStreamClient = class {
4955
4970
  if (!transferHookProgramId) {
4956
4971
  return;
4957
4972
  }
4958
- for (const transfer of potentialTransfers) {
4973
+ for (const transfer2 of potentialTransfers) {
4959
4974
  await addExtraAccountMetasForExecute(
4960
4975
  this.connection,
4961
4976
  instruction,
4962
4977
  transferHookProgramId,
4963
- transfer.source,
4978
+ transfer2.source,
4964
4979
  mint,
4965
- transfer.destination,
4966
- transfer.owner,
4980
+ transfer2.destination,
4981
+ transfer2.owner,
4967
4982
  1n,
4968
4983
  this.getCommitment()
4969
4984
  );
@@ -5413,7 +5428,433 @@ var timelockIDL_default = {
5413
5428
  }
5414
5429
  ]
5415
5430
  };
5431
+ function normalizeInvoker(invoker) {
5432
+ if (typeof invoker.publicKey === "string") {
5433
+ return { ...invoker, publicKey: pk(invoker.publicKey) };
5434
+ }
5435
+ return invoker;
5436
+ }
5437
+ function resolveConnection(env) {
5438
+ if ("connection" in env) {
5439
+ return env.connection;
5440
+ }
5441
+ return new Connection(env.rpcUrl, {
5442
+ commitment: env.commitment
5443
+ });
5444
+ }
5445
+ function createClientFromEnv(env) {
5446
+ if (env.client) return env.client;
5447
+ if ("connection" in env) {
5448
+ return new SolanaStreamClient({
5449
+ connection: env.connection,
5450
+ cluster: env.cluster,
5451
+ commitment: env.commitment,
5452
+ programId: env.programId.toBase58()
5453
+ });
5454
+ }
5455
+ return new SolanaStreamClient(env.rpcUrl, env.cluster ?? ICluster.Mainnet, env.commitment, env.programId.toBase58());
5456
+ }
5457
+
5458
+ // solana/api/create.ts
5459
+ async function create(params, invoker, env) {
5460
+ const client = createClientFromEnv(env);
5461
+ const { ixs, metadataId, metadata } = await client.buildCreateTransactionInstructions(params, {
5462
+ sender: normalizeInvoker(invoker),
5463
+ isNative: env.isNative ?? false
5464
+ });
5465
+ return {
5466
+ instructions: ixs,
5467
+ signers: metadata ? [metadata] : void 0,
5468
+ metadata,
5469
+ metadataPubKey: new PublicKey(metadataId)
5470
+ };
5471
+ }
5472
+
5473
+ // solana/api/withdraw.ts
5474
+ async function withdraw(params, invoker, env) {
5475
+ const client = createClientFromEnv(env);
5476
+ const ixs = await client.prepareWithdrawInstructions(params, {
5477
+ invoker: normalizeInvoker(invoker)
5478
+ });
5479
+ return { instructions: ixs };
5480
+ }
5481
+
5482
+ // solana/api/topup.ts
5483
+ async function topup(params, invoker, env) {
5484
+ const client = createClientFromEnv(env);
5485
+ const ixs = await client.prepareTopupInstructions(params, {
5486
+ invoker: normalizeInvoker(invoker),
5487
+ isNative: env.isNative ?? false
5488
+ });
5489
+ return { instructions: ixs };
5490
+ }
5491
+
5492
+ // solana/api/cancel.ts
5493
+ async function cancel(params, invoker, env) {
5494
+ const client = createClientFromEnv(env);
5495
+ const ixs = await client.prepareCancelInstructions(params, {
5496
+ invoker: normalizeInvoker(invoker)
5497
+ });
5498
+ return { instructions: ixs };
5499
+ }
5500
+
5501
+ // solana/api/transfer.ts
5502
+ async function transfer(params, invoker, env) {
5503
+ const client = createClientFromEnv(env);
5504
+ const ixs = await client.prepareTransferInstructions(params, {
5505
+ invoker: normalizeInvoker(invoker)
5506
+ });
5507
+ return { instructions: ixs };
5508
+ }
5509
+
5510
+ // solana/api/update.ts
5511
+ async function update(params, invoker, env) {
5512
+ const client = createClientFromEnv(env);
5513
+ const ixs = await client.prepareUpdateInstructions(params, {
5514
+ invoker: normalizeInvoker(invoker)
5515
+ });
5516
+ return { instructions: ixs };
5517
+ }
5518
+ async function createBatch(params, invoker, env) {
5519
+ const client = createClientFromEnv(env);
5520
+ const result = await client.buildCreateMultipleTransactionInstructions(params, {
5521
+ sender: normalizeInvoker(invoker),
5522
+ isNative: env.isNative ?? false
5523
+ });
5524
+ return {
5525
+ setupInstructions: result.prepareInstructions,
5526
+ creationBatches: result.instructionsBatch.map((batch, i) => ({
5527
+ instructions: batch.ixs,
5528
+ signers: batch.metadata ? [batch.metadata] : void 0,
5529
+ recipient: batch.recipient,
5530
+ metadataPubKey: new PublicKey(result.metadatas[i])
5531
+ }))
5532
+ };
5533
+ }
5534
+ function buildLockParams(params) {
5535
+ if (params.amount.ltn(1)) {
5536
+ throw new Error("Lock amount must be greater than or equal to 1");
5537
+ }
5538
+ return {
5539
+ recipient: params.recipient,
5540
+ tokenId: params.tokenId,
5541
+ amount: params.amount,
5542
+ start: params.unlockDate,
5543
+ cliff: params.unlockDate,
5544
+ period: 1,
5545
+ cliffAmount: params.amount,
5546
+ amountPerPeriod: new BN3(1),
5547
+ name: params.name,
5548
+ canTopup: false,
5549
+ cancelableBySender: false,
5550
+ cancelableByRecipient: false,
5551
+ transferableBySender: false,
5552
+ transferableByRecipient: params.transferableByRecipient ?? false,
5553
+ automaticWithdrawal: false,
5554
+ withdrawalFrequency: 0,
5555
+ ...params.partner !== void 0 && { partner: params.partner },
5556
+ ...params.tokenProgramId !== void 0 && { tokenProgramId: params.tokenProgramId }
5557
+ };
5558
+ }
5559
+ async function createLock(params, invoker, env) {
5560
+ return create(buildLockParams(params), invoker, env);
5561
+ }
5562
+ function buildLockBatchParams(params) {
5563
+ return {
5564
+ tokenId: params.tokenId,
5565
+ start: params.unlockDate,
5566
+ cliff: params.unlockDate,
5567
+ period: 1,
5568
+ canTopup: false,
5569
+ cancelableBySender: false,
5570
+ cancelableByRecipient: false,
5571
+ transferableBySender: false,
5572
+ transferableByRecipient: params.transferableByRecipient ?? false,
5573
+ automaticWithdrawal: false,
5574
+ withdrawalFrequency: 0,
5575
+ ...params.partner !== void 0 && { partner: params.partner },
5576
+ ...params.tokenProgramId !== void 0 && { tokenProgramId: params.tokenProgramId },
5577
+ recipients: params.recipients.map(
5578
+ (r) => ({
5579
+ recipient: r.recipient,
5580
+ amount: r.amount,
5581
+ name: r.name,
5582
+ cliffAmount: r.amount,
5583
+ amountPerPeriod: new BN3(1)
5584
+ })
5585
+ )
5586
+ };
5587
+ }
5588
+ async function createLockBatch(params, invoker, env) {
5589
+ if (params.recipients.length === 0) {
5590
+ throw new Error("At least one recipient required");
5591
+ }
5592
+ for (const r of params.recipients) {
5593
+ if (r.amount.ltn(1)) {
5594
+ throw new Error("Lock amount must be greater than or equal to 1");
5595
+ }
5596
+ }
5597
+ return createBatch(buildLockBatchParams(params), invoker, env);
5598
+ }
5599
+ function resolveDuration(params) {
5600
+ if (params.endDate !== void 0 && params.duration !== void 0) {
5601
+ throw new Error("Provide either endDate or duration, not both");
5602
+ }
5603
+ if (params.endDate === void 0 && params.duration === void 0) {
5604
+ throw new Error("Must provide either endDate or duration");
5605
+ }
5606
+ const duration = params.endDate !== void 0 ? params.endDate - params.start : params.duration;
5607
+ if (duration <= 0) {
5608
+ throw new Error("Duration must be positive");
5609
+ }
5610
+ return duration;
5611
+ }
5612
+ function computeAmountPerPeriod(amount, cliffAmount, duration, period) {
5613
+ const remaining = amount.sub(cliffAmount);
5614
+ if (remaining.lten(0)) {
5615
+ throw new Error("cliffAmount must be less than total amount");
5616
+ }
5617
+ const numPeriods = Math.floor(duration / period);
5618
+ if (numPeriods <= 0) {
5619
+ throw new Error("Duration must be at least equal to period");
5620
+ }
5621
+ return remaining.addn(numPeriods - 1).divn(numPeriods);
5622
+ }
5623
+ function buildVestingParams(params) {
5624
+ const cliffAmount = params.cliffAmount ?? new BN3(0);
5625
+ const duration = resolveDuration(params);
5626
+ return {
5627
+ recipient: params.recipient,
5628
+ tokenId: params.tokenId,
5629
+ amount: params.amount,
5630
+ start: params.start,
5631
+ cliff: params.start,
5632
+ period: params.period,
5633
+ name: params.name,
5634
+ cliffAmount,
5635
+ amountPerPeriod: params.amountPerPeriod ?? computeAmountPerPeriod(params.amount, cliffAmount, duration, params.period),
5636
+ canTopup: params.canTopup ?? false,
5637
+ cancelableByRecipient: false,
5638
+ cancelableBySender: params.cancelableBySender ?? false,
5639
+ transferableBySender: params.transferableBySender ?? false,
5640
+ transferableByRecipient: params.transferableByRecipient ?? false,
5641
+ automaticWithdrawal: params.automaticWithdrawal ?? false,
5642
+ withdrawalFrequency: params.withdrawalFrequency ?? (params.automaticWithdrawal ? params.period : 0),
5643
+ ...params.partner !== void 0 && { partner: params.partner },
5644
+ ...params.tokenProgramId !== void 0 && { tokenProgramId: params.tokenProgramId }
5645
+ };
5646
+ }
5647
+ async function createVesting(params, invoker, env) {
5648
+ if (!params.initialAllocation) {
5649
+ return create(buildVestingParams(params), invoker, env);
5650
+ }
5651
+ if (!params.initialAllocation.amount.gtn(1)) {
5652
+ throw new Error("Initial allocation amount must be greater than 1");
5653
+ }
5654
+ const client = createClientFromEnv(env);
5655
+ const mainData = buildVestingParams(params);
5656
+ const cancelableBySender = params.cancelableBySender ?? false;
5657
+ const allocData = {
5658
+ recipient: params.recipient,
5659
+ tokenId: params.tokenId,
5660
+ amount: params.initialAllocation.amount,
5661
+ start: params.start,
5662
+ cliff: params.start,
5663
+ period: 1,
5664
+ cliffAmount: params.initialAllocation.amount.subn(2),
5665
+ amountPerPeriod: new BN3(2),
5666
+ name: params.name,
5667
+ canTopup: false,
5668
+ cancelableBySender,
5669
+ cancelableByRecipient: false,
5670
+ transferableBySender: false,
5671
+ transferableByRecipient: false,
5672
+ automaticWithdrawal: false,
5673
+ withdrawalFrequency: 0,
5674
+ ...params.partner !== void 0 && { partner: params.partner },
5675
+ ...params.tokenProgramId !== void 0 && { tokenProgramId: params.tokenProgramId }
5676
+ };
5677
+ const normalizedInvoker = normalizeInvoker(invoker);
5678
+ const [mainResult, allocResult] = await Promise.all([
5679
+ client.buildCreateTransactionInstructions(mainData, {
5680
+ sender: normalizedInvoker,
5681
+ isNative: env.isNative ?? false
5682
+ }),
5683
+ client.buildCreateTransactionInstructions(allocData, {
5684
+ sender: normalizedInvoker,
5685
+ isNative: env.isNative ?? false
5686
+ })
5687
+ ]);
5688
+ return {
5689
+ setupInstructions: [...mainResult.ixs.slice(0, -1), ...allocResult.ixs.slice(0, -1)],
5690
+ creationBatches: [
5691
+ {
5692
+ instructions: [mainResult.ixs[mainResult.ixs.length - 1]],
5693
+ signers: mainResult.metadata ? [mainResult.metadata] : void 0,
5694
+ recipient: params.recipient,
5695
+ metadataPubKey: new PublicKey(mainResult.metadataId)
5696
+ },
5697
+ {
5698
+ instructions: [allocResult.ixs[allocResult.ixs.length - 1]],
5699
+ signers: allocResult.metadata ? [allocResult.metadata] : void 0,
5700
+ recipient: params.recipient,
5701
+ metadataPubKey: new PublicKey(allocResult.metadataId)
5702
+ }
5703
+ ]
5704
+ };
5705
+ }
5706
+ function buildVestingBatchParams(params) {
5707
+ const duration = resolveDuration(params);
5708
+ return {
5709
+ tokenId: params.tokenId,
5710
+ start: params.start,
5711
+ cliff: params.start,
5712
+ period: params.period,
5713
+ canTopup: false,
5714
+ cancelableByRecipient: false,
5715
+ cancelableBySender: params.cancelableBySender ?? false,
5716
+ transferableBySender: params.transferableBySender ?? false,
5717
+ transferableByRecipient: params.transferableByRecipient ?? false,
5718
+ automaticWithdrawal: params.automaticWithdrawal ?? false,
5719
+ withdrawalFrequency: params.withdrawalFrequency ?? (params.automaticWithdrawal ? params.period : 0),
5720
+ ...params.partner !== void 0 && { partner: params.partner },
5721
+ ...params.tokenProgramId !== void 0 && { tokenProgramId: params.tokenProgramId },
5722
+ recipients: params.recipients.map(
5723
+ (r) => ({
5724
+ recipient: r.recipient,
5725
+ amount: r.amount,
5726
+ name: r.name,
5727
+ cliffAmount: r.cliffAmount ?? new BN3(0),
5728
+ amountPerPeriod: r.amountPerPeriod ?? computeAmountPerPeriod(r.amount, r.cliffAmount ?? new BN3(0), duration, params.period)
5729
+ })
5730
+ )
5731
+ };
5732
+ }
5733
+ async function createVestingBatch(params, invoker, env) {
5734
+ if (params.recipients.length === 0) {
5735
+ throw new Error("At least one recipient required");
5736
+ }
5737
+ for (const r of params.recipients) {
5738
+ if (r.amount.lte(new BN3(0))) {
5739
+ throw new Error("Amount must be greater than zero");
5740
+ }
5741
+ }
5742
+ return createBatch(buildVestingBatchParams(params), invoker, env);
5743
+ }
5744
+ async function buildTransaction(instructions, options, env) {
5745
+ const connection = resolveConnection(env);
5746
+ const computeBudgetIxs = prepareBaseInstructions(connection, {
5747
+ computePrice: typeof options.computePrice === "function" ? void 0 : options.computePrice,
5748
+ computeLimit: typeof options.computeLimit !== "number" ? void 0 : options.computeLimit
5749
+ });
5750
+ const allIxs = [...computeBudgetIxs, ...instructions];
5751
+ const { tx, hash, context } = await prepareTransaction(connection, allIxs, options.feePayer, env.commitment);
5752
+ return {
5753
+ transaction: tx,
5754
+ blockhashWithExpiryBlockHeight: hash,
5755
+ context
5756
+ };
5757
+ }
5758
+
5759
+ // solana/api/sign.ts
5760
+ function isKeypair(signer) {
5761
+ return "secretKey" in signer;
5762
+ }
5763
+ function isWalletAdapter(signer) {
5764
+ return "signTransaction" in signer;
5765
+ }
5766
+ async function sign(transaction, signers) {
5767
+ for (const signer of signers) {
5768
+ if (isKeypair(signer)) {
5769
+ transaction.sign([signer]);
5770
+ } else if (isWalletAdapter(signer)) {
5771
+ await signer.signTransaction(transaction);
5772
+ }
5773
+ }
5774
+ return transaction;
5775
+ }
5776
+ async function execute(builtTx, env) {
5777
+ const connection = resolveConnection(env);
5778
+ return executeTransaction(
5779
+ connection,
5780
+ builtTx.transaction,
5781
+ {
5782
+ hash: builtTx.blockhashWithExpiryBlockHeight,
5783
+ context: builtTx.context,
5784
+ commitment: env.commitment
5785
+ },
5786
+ {
5787
+ sendRate: env.sendRate,
5788
+ sendThrottler: env.throttler,
5789
+ skipSimulation: env.skipPreflight
5790
+ }
5791
+ );
5792
+ }
5793
+ async function executeBatch(builtTransactions, env) {
5794
+ if (builtTransactions.length === 0) {
5795
+ return { signatures: [], errors: [] };
5796
+ }
5797
+ const first = builtTransactions[0];
5798
+ const firstBlockhash = first.blockhashWithExpiryBlockHeight.blockhash;
5799
+ for (const btx of builtTransactions) {
5800
+ if (btx.blockhashWithExpiryBlockHeight.blockhash !== firstBlockhash) {
5801
+ throw new Error("All transactions in executeBatch must share the same blockhash");
5802
+ }
5803
+ }
5804
+ const connection = resolveConnection(env);
5805
+ const results = await executeMultipleTransactions(
5806
+ connection,
5807
+ builtTransactions.map((btx) => btx.transaction),
5808
+ {
5809
+ hash: first.blockhashWithExpiryBlockHeight,
5810
+ context: first.context,
5811
+ commitment: env.commitment
5812
+ },
5813
+ {
5814
+ sendRate: env.sendRate,
5815
+ sendThrottler: env.throttler,
5816
+ skipSimulation: env.skipPreflight
5817
+ }
5818
+ );
5819
+ const signatures = [];
5820
+ const errors = [];
5821
+ for (const result of results) {
5822
+ if (result.status === "fulfilled") {
5823
+ signatures.push(result.value);
5824
+ } else {
5825
+ errors.push(result.reason instanceof Error ? result.reason : new Error(String(result.reason)));
5826
+ }
5827
+ }
5828
+ return { signatures, errors };
5829
+ }
5830
+ async function executeBatchSequential(builtTransactions, env) {
5831
+ const connection = resolveConnection(env);
5832
+ const signatures = [];
5833
+ const errors = [];
5834
+ for (const btx of builtTransactions) {
5835
+ try {
5836
+ const sig = await executeTransaction(
5837
+ connection,
5838
+ btx.transaction,
5839
+ {
5840
+ hash: btx.blockhashWithExpiryBlockHeight,
5841
+ context: btx.context,
5842
+ commitment: env.commitment
5843
+ },
5844
+ {
5845
+ sendRate: env.sendRate,
5846
+ sendThrottler: env.throttler,
5847
+ skipSimulation: env.skipPreflight
5848
+ }
5849
+ );
5850
+ signatures.push(sig);
5851
+ } catch (err) {
5852
+ errors.push(err instanceof Error ? err : new Error(String(err)));
5853
+ }
5854
+ }
5855
+ return { signatures, errors };
5856
+ }
5416
5857
 
5417
- export { AIRDROP_AMOUNT, AIRDROP_TEST_TOKEN, ALIGNED_COMPUTE_LIMIT, ALIGNED_PRECISION_FACTOR_POW2 as ALIGNED_PRECISION_FACTOR_POW, ALIGNED_UNLOCKS_PROGRAM_ID, AlignedContract, AlignedProxyErrorCode, CONTRACT_DISCRIMINATOR, CONTRACT_SEED, CREATE_PARAMS_PADDING, Contract, ContractErrorCode, DEFAULT_AUTO_CLAIM_FEE_SOL, DEFAULT_CREATION_FEE_SOL, DEFAULT_STREAMFLOW_FEE, ESCROW_SEED, FEES_METADATA_SEED, FEE_ORACLE_PUBLIC_KEY, MAX_SAFE_UNIX_TIME_VALUE2 as MAX_SAFE_UNIX_TIME_VALUE, METADATA_SEED, ORIGINAL_CONTRACT_SENDER_OFFSET, PARTNERS_SCHEMA, PARTNER_ORACLE_PROGRAM_ID, PARTNER_SCHEMA, PROGRAM_ID, 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, StreamDirection, StreamType, TEST_ORACLE_DISCRIMINATOR, TEST_ORACLE_SEED, TX_FINALITY_CONFIRMED, 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, requestCancelStreamInstruction, sendAndConfirmStreamRawTransaction, signAllTransactionWithRecipients, timelockIDL_default as timelockIDL, topupStreamInstruction, transferStreamInstruction, transformContract, updateStreamInstruction, withdrawCancelRequestInstruction, withdrawStreamInstruction };
5858
+ export { AIRDROP_AMOUNT, AIRDROP_TEST_TOKEN, ALIGNED_COMPUTE_LIMIT, ALIGNED_PRECISION_FACTOR_POW2 as ALIGNED_PRECISION_FACTOR_POW, ALIGNED_UNLOCKS_PROGRAM_ID, AlignedContract, AlignedProxyErrorCode, CONTRACT_DISCRIMINATOR, CONTRACT_SEED, CREATE_PARAMS_PADDING, Contract, ContractErrorCode, DEFAULT_AUTO_CLAIM_FEE_SOL, DEFAULT_CREATION_FEE_SOL, DEFAULT_STREAMFLOW_FEE, ESCROW_SEED, FEES_METADATA_SEED, FEE_ORACLE_PUBLIC_KEY, MAX_SAFE_UNIX_TIME_VALUE2 as MAX_SAFE_UNIX_TIME_VALUE, METADATA_SEED, ORIGINAL_CONTRACT_SENDER_OFFSET, PARTNERS_SCHEMA, PARTNER_ORACLE_PROGRAM_ID, PARTNER_SCHEMA, PROGRAM_ID, 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, StreamDirection, StreamType, TEST_ORACLE_DISCRIMINATOR, TEST_ORACLE_SEED, TX_FINALITY_CONFIRMED, WITHDRAWOR, WITHDRAWOR_PUBLIC_KEY, WITHDRAW_AVAILABLE_AMOUNT, buildLockBatchParams, buildLockParams, buildStreamType, buildTransaction, buildVestingBatchParams, buildVestingParams, calculateTotalAmountToDeposit, calculateUnlockedAmount, cancel, cancelStreamInstruction, computeAmountPerPeriod, create, createBatch, createClient, createClientFromEnv, createLock, createLockBatch, createStreamInstruction, createStreamV2Instruction, createUncheckedStreamInstruction, createUncheckedStreamV2Instruction, createVesting, createVestingBatch, decodeEndTime, decodeStream, deriveContractPDA, deriveEscrowPDA, deriveRepopulatedMetadataPDA, deriveStreamMetadataPDA, deriveTestOraclePDA, execute, executeBatch, executeBatchSequential, extractSolanaErrorCode, getMetadataKey, handleContractError, isAligned, isCliffCloseToDepositedAmount, isCreateAlignedStreamData, isDynamicLock, isTokenLock, isVesting, requestCancelStreamInstruction, resolveConnection, resolveDuration, sendAndConfirmStreamRawTransaction, sign, signAllTransactionWithRecipients, timelockIDL_default as timelockIDL, topup, topupStreamInstruction, transfer, transferStreamInstruction, transformContract, update, updateStreamInstruction, withdraw, withdrawCancelRequestInstruction, withdrawStreamInstruction };
5418
5859
  //# sourceMappingURL=index.js.map
5419
5860
  //# sourceMappingURL=index.js.map