@streamflow/stream 13.4.0 → 13.5.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.
@@ -847,6 +847,15 @@ declare class SolanaStreamClient {
847
847
  * @returns Fees
848
848
  */
849
849
  getFees({ address }: IGetFeesData): Promise<IFees | null>;
850
+ private getFeeRows;
851
+ /**
852
+ * Fee rates the program applies to a create from `sender` with `partnerLink`, used to size the WSOL wrap.
853
+ * Mirrors `resolve_vesting_partner`: a `partnerLink` counts if it signs or the partner oracle owns it, and a
854
+ * PartnerLink account stands for its partner. A link to another wallet fails the program's lookup, which then
855
+ * charges its hardcoded fallback and skips the sender's own row. Otherwise the sender's own row, then the
856
+ * partner's, then the default row. `partner` only takes a share and never picks the row.
857
+ */
858
+ private getCreateFeeRates;
850
859
  /**
851
860
  * Gets default streamflow fee
852
861
  * @returns Default streamflow fee
@@ -1101,4 +1110,4 @@ declare function execute(builtTx: BuiltTransaction, env: ExecutionEnv): Promise<
1101
1110
  declare function executeBatch(builtTransactions: BuiltTransaction[], env: ExecutionEnv): Promise<BatchExecuteResult>;
1102
1111
  declare function executeBatchSequential(builtTransactions: BuiltTransaction[], env: ExecutionEnv): Promise<BatchExecuteResult>;
1103
1112
 
1104
- export { type ICreateStreamInstructions as $, type AlignedStream as A, type BatchItem as B, type CancelFn as C, type DecodedStream as D, type CreateTestOracleParams as E, type Env as F, type ExecuteBatchFn as G, type ExecuteBatchSequentialFn as H, type IUpdateData as I, type ExecuteFn as J, type ExecutionEnv as K, type IAlignedStreamConfig as L, type IBaseStreamConfig as M, type ICancelData as N, type IClaimRoutedFeeData as O, type ICreateExt as P, type ICreateLinearStreamData as Q, type RoutedFeeDestination as R, StreamType as S, type ICreateLockBatchParams as T, type ICreateLockParams as U, type ICreateMultiError as V, type ICreateMultipleAlignedStreamData as W, type ICreateMultipleLinearStreamData as X, type ICreateMultipleStreamData as Y, type ICreateResult as Z, type ICreateStreamExt as _, type BatchItemResult as a, update as a$, type ICreateVestingBatchParams as a0, type ICreateVestingParams as a1, type IFees as a2, type IGetAllData as a3, type IGetFeesData as a4, type IGetOneData as a5, type IInteractData as a6, type IInteractStreamExt as a7, type ILockBatchRecipient as a8, type IMultiTransactionResult as a9, type TransactionSchedulingOptions as aA, type TransferFn as aB, type UpdateFn as aC, type UpdateTestOracleParams as aD, type WithdrawFn as aE, buildLockBatchParams as aF, buildLockParams as aG, buildTransaction as aH, buildVestingBatchParams as aI, buildVestingParams as aJ, cancel as aK, computeAmountPerPeriod as aL, create as aM, createBatch as aN, createClientFromEnv as aO, createLock as aP, createLockBatch as aQ, createVesting as aR, createVestingBatch as aS, execute as aT, executeBatch as aU, executeBatchSequential as aV, resolveConnection as aW, resolveDuration as aX, sign as aY, topup as aZ, transfer as a_, type IPrepareCreateStreamExt as aa, type IPrepareStreamExt as ab, type IPrepareTopUpstreamExt as ac, type IRecipient as ad, type ITopUpData as ae, type ITopUpStreamExt as af, type ITransactionExtWithInstructions as ag, type ITransactionResult as ah, type ITransferData as ai, type IVestingBatchRecipient as aj, type IWithdrawData as ak, type InstructionGenerator as al, type InstructionResult as am, type Invoker as an, type LinearStream as ao, type MetadataRecipientHashMap as ap, type NativeOptions as aq, type OracleType as ar, type OracleTypeName as as, type SignFn as at, SolanaStreamClient as au, type StreamClientOptions as av, type StreamClientOptionsWithConnection as aw, StreamDirection as ax, type TestOracle as ay, type TopupFn as az, type Stream as b, withdraw as b0, type ICreateStreamData as c, type ICreateAlignedStreamData as d, type ISearchStreams as e, type Account as f, AlignedContract as g, AlignedProxyErrorCode as h, type AlignedStreamData as i, type AlignedUnlocksContract as j, type BatchCreationItem as k, type BatchExecuteResult as l, type BatchInstructionResult as m, type BatchItemError as n, type BatchItemSuccess as o, type BuildTransactionFn as p, type BuildTransactionOptions as q, type BuiltTransaction as r, type ChangeOracleParams as s, type ClientCreationOptions as t, Contract as u, ContractErrorCode as v, type CreateBatchFn as w, type CreateFn as x, type CreateInstructionResult as y, type CreateParams as z };
1113
+ export { type ICreateStreamInstructions as $, type AlignedStream as A, type BatchItem as B, type CancelFn as C, type DecodedStream as D, type CreateParams as E, type CreateTestOracleParams as F, type Env as G, type ExecuteBatchFn as H, type IUpdateData as I, type ExecuteBatchSequentialFn as J, type ExecuteFn as K, type ExecutionEnv as L, type IAlignedStreamConfig as M, type IBaseStreamConfig as N, type ICancelData as O, type IClaimRoutedFeeData as P, type ICreateExt as Q, type RoutedFeeDestination as R, StreamType as S, type ICreateLockBatchParams as T, type ICreateLockParams as U, type ICreateMultiError as V, type ICreateMultipleAlignedStreamData as W, type ICreateMultipleLinearStreamData as X, type ICreateMultipleStreamData as Y, type ICreateResult as Z, type ICreateStreamExt as _, type BatchItemResult as a, update as a$, type ICreateVestingBatchParams as a0, type ICreateVestingParams as a1, type IFees as a2, type IGetAllData as a3, type IGetFeesData as a4, type IGetOneData as a5, type IInteractData as a6, type IInteractStreamExt as a7, type ILockBatchRecipient as a8, type IMultiTransactionResult as a9, type TransactionSchedulingOptions as aA, type TransferFn as aB, type UpdateFn as aC, type UpdateTestOracleParams as aD, type WithdrawFn as aE, buildLockBatchParams as aF, buildLockParams as aG, buildTransaction as aH, buildVestingBatchParams as aI, buildVestingParams as aJ, cancel as aK, computeAmountPerPeriod as aL, create as aM, createBatch as aN, createClientFromEnv as aO, createLock as aP, createLockBatch as aQ, createVesting as aR, createVestingBatch as aS, execute as aT, executeBatch as aU, executeBatchSequential as aV, resolveConnection as aW, resolveDuration as aX, sign as aY, topup as aZ, transfer as a_, type IPrepareCreateStreamExt as aa, type IPrepareStreamExt as ab, type IPrepareTopUpstreamExt as ac, type IRecipient as ad, type ITopUpData as ae, type ITopUpStreamExt as af, type ITransactionExtWithInstructions as ag, type ITransactionResult as ah, type ITransferData as ai, type IVestingBatchRecipient as aj, type IWithdrawData as ak, type InstructionGenerator as al, type InstructionResult as am, type Invoker as an, type LinearStream as ao, type MetadataRecipientHashMap as ap, type NativeOptions as aq, type OracleType as ar, type OracleTypeName as as, type SignFn as at, SolanaStreamClient as au, type StreamClientOptions as av, type StreamClientOptionsWithConnection as aw, StreamDirection as ax, type TestOracle as ay, type TopupFn as az, type Stream as b, withdraw as b0, type ICreateStreamData as c, type ICreateAlignedStreamData as d, type ICreateLinearStreamData as e, type ISearchStreams as f, type Account as g, AlignedContract as h, AlignedProxyErrorCode as i, type AlignedStreamData as j, type AlignedUnlocksContract as k, type BatchCreationItem as l, type BatchExecuteResult as m, type BatchInstructionResult as n, type BatchItemError as o, type BatchItemSuccess as p, type BuildTransactionFn as q, type BuildTransactionOptions as r, type BuiltTransaction as s, type ChangeOracleParams as t, type ClientCreationOptions as u, Contract as v, ContractErrorCode as w, type CreateBatchFn as x, type CreateFn as y, type CreateInstructionResult as z };
@@ -87,6 +87,24 @@ var isTokenLock = (streamData) => {
87
87
  }
88
88
  return false;
89
89
  };
90
+ var isStrictTokenLockCreate = (data, now = Math.floor(Date.now() / 1e3)) => {
91
+ if (data.canTopup || data.automaticWithdrawal || data.cancelableBySender || data.cancelableByRecipient || data.transferableBySender) {
92
+ return false;
93
+ }
94
+ if (!isCliffCloseToDepositedAmount({ depositedAmount: data.amount, cliffAmount: data.cliffAmount })) {
95
+ return false;
96
+ }
97
+ if (data.cliffAmount.gt(data.amount) || data.amountPerPeriod.isZero()) {
98
+ return false;
99
+ }
100
+ const remaining = data.amount.sub(data.cliffAmount);
101
+ const periodsLeft = remaining.add(data.amountPerPeriod).subn(1).div(data.amountPerPeriod);
102
+ const cliff = data.start === 0 ? now : data.cliff;
103
+ const unlockStart = cliff > 0 ? cliff : data.start;
104
+ const end = new BN3__default.default(unlockStart).add(periodsLeft.mul(new BN3__default.default(data.period)));
105
+ const cliffEndGap = end.sub(new BN3__default.default(cliff));
106
+ return !cliffEndGap.isNeg() && cliffEndGap.lten(MAX_CLIFF_END_GAP_SECONDS);
107
+ };
90
108
  var buildStreamType = (streamData) => {
91
109
  if (isTokenLock(streamData)) {
92
110
  return "lock" /* Lock */;
@@ -3365,6 +3383,27 @@ var transformContract = async (schema) => {
3365
3383
  // solana/StreamClient.ts
3366
3384
  var METADATA_ACC_SIZE = 1104;
3367
3385
  var ALIGNED_METADATA_ACC_SIZE = 320;
3386
+ var PARTNER_LINK_DISCRIMINATOR = buffer.Buffer.from([114, 220, 250, 94, 181, 182, 195, 222]);
3387
+ var PARTNER_LINK_SIZE = 8 + 32 + 32 + 32;
3388
+ var decodePartnerLink = (data) => data.length >= PARTNER_LINK_SIZE && data.subarray(0, 8).equals(PARTNER_LINK_DISCRIMINATOR) ? { partnerPubkey: new web3_js.PublicKey(data.subarray(8, 40)), linkedPubkey: new web3_js.PublicKey(data.subarray(40, 72)) } : null;
3389
+ var findFees = (partners, address) => {
3390
+ const filteredPartners = partners.filter((partner2) => new web3_js.PublicKey(partner2.pubkey).toString() === address);
3391
+ if (filteredPartners.length === 0) {
3392
+ return null;
3393
+ }
3394
+ if (filteredPartners.length > 1) {
3395
+ throw new Error("More than one partner found, fees fetching is not possible.");
3396
+ }
3397
+ const partner = filteredPartners[0];
3398
+ return {
3399
+ creationFeeSol: Number(partner.creation_fee),
3400
+ autoClaimFeeSol: Number(partner.auto_claim_fee),
3401
+ streamflowFee: Number(partner.token_fee_percent.toFixed(4)),
3402
+ streamflowLockFee: Number(partner.token_lock_token_fee_percent.toFixed(4)),
3403
+ partnerFee: 0
3404
+ };
3405
+ };
3406
+ var getWrapFeePercent = (rates, data) => isStrictTokenLockCreate(data) ? rates.streamflowLockFee : rates.streamflowFee;
3368
3407
  var SolanaStreamClient = class {
3369
3408
  /**
3370
3409
  * Create Stream instance
@@ -3458,10 +3497,8 @@ var SolanaStreamClient = class {
3458
3497
  tokenProgramId ? new web3_js.PublicKey(tokenProgramId) : void 0
3459
3498
  );
3460
3499
  if (isNative) {
3461
- const totalFee = await this.getTotalFee({
3462
- address: partnerPublicKey.toString()
3463
- });
3464
- const totalAmount = calculateTotalAmountToDeposit(amount, totalFee);
3500
+ const rates = await this.getCreateFeeRates(data.partnerLink, sender.publicKey);
3501
+ const totalAmount = calculateTotalAmountToDeposit(amount, getWrapFeePercent(rates, data));
3465
3502
  ixs.push(...await common.prepareWrappedAccount(this.connection, sender.publicKey, totalAmount));
3466
3503
  }
3467
3504
  const {
@@ -3848,7 +3885,20 @@ var SolanaStreamClient = class {
3848
3885
  computeLimit
3849
3886
  });
3850
3887
  if (isNative) {
3851
- const totalFee = await this.getTotalFee({ address: partnerPublicKey.toString() });
3888
+ const rates = await this.getCreateFeeRates(partnerLink, sender.publicKey);
3889
+ const totalFee = getWrapFeePercent(rates, {
3890
+ start,
3891
+ amount: depositedAmount,
3892
+ period,
3893
+ cliff,
3894
+ cliffAmount,
3895
+ amountPerPeriod,
3896
+ canTopup,
3897
+ automaticWithdrawal,
3898
+ cancelableBySender,
3899
+ cancelableByRecipient,
3900
+ transferableBySender
3901
+ });
3852
3902
  const totalAmount = calculateTotalAmountToDeposit(depositedAmount, totalFee);
3853
3903
  ixs.push(...await common.prepareWrappedAccount(this.connection, sender.publicKey, totalAmount));
3854
3904
  }
@@ -3938,6 +3988,7 @@ var SolanaStreamClient = class {
3938
3988
  if (recipients.length === 0) {
3939
3989
  throw new Error("Recipients array is empty!");
3940
3990
  }
3991
+ const wrapFeeRates = isNative ? await this.getCreateFeeRates(data.partnerLink, sender.publicKey) : void 0;
3941
3992
  for (let i = 0; i < recipients.length; i++) {
3942
3993
  const recipientData = recipients[i];
3943
3994
  const createStreamData = { ...streamParams, ...recipientData };
@@ -3946,8 +3997,8 @@ var SolanaStreamClient = class {
3946
3997
  metadataPubKeys: metadataPubKeysExt?.[i] ? [metadataPubKeysExt[i]] : void 0
3947
3998
  };
3948
3999
  const wrapInstructions = [];
3949
- if (isNative) {
3950
- const totalFee = await this.getTotalFee({ address: partnerPublicKey.toString() });
4000
+ if (wrapFeeRates) {
4001
+ const totalFee = getWrapFeePercent(wrapFeeRates, createStreamData);
3951
4002
  const recipientAmount = calculateTotalAmountToDeposit(recipientData.amount, totalFee);
3952
4003
  wrapInstructions.push(...await common.prepareWrappedAccount(this.connection, sender.publicKey, recipientAmount));
3953
4004
  }
@@ -4858,26 +4909,38 @@ var SolanaStreamClient = class {
4858
4909
  * @returns Fees
4859
4910
  */
4860
4911
  async getFees({ address }) {
4912
+ const partners = await this.getFeeRows();
4913
+ return partners ? findFees(partners, address) : null;
4914
+ }
4915
+ async getFeeRows() {
4861
4916
  const data = await this.connection.getAccountInfo(this.feeOraclePublicKey);
4862
- if (!data) {
4863
- return null;
4864
- }
4865
- const partners = borsh__namespace.deserialize(PARTNERS_SCHEMA, data.data);
4866
- const filteredPartners = partners.filter((partner2) => new web3_js.PublicKey(partner2.pubkey).toString() === address);
4867
- if (filteredPartners.length === 0) {
4868
- return null;
4869
- }
4870
- if (filteredPartners.length > 1) {
4871
- throw new Error("More than one partner found, fees fetching is not possible.");
4917
+ return data ? borsh__namespace.deserialize(PARTNERS_SCHEMA, data.data) : null;
4918
+ }
4919
+ /**
4920
+ * Fee rates the program applies to a create from `sender` with `partnerLink`, used to size the WSOL wrap.
4921
+ * Mirrors `resolve_vesting_partner`: a `partnerLink` counts if it signs or the partner oracle owns it, and a
4922
+ * PartnerLink account stands for its partner. A link to another wallet fails the program's lookup, which then
4923
+ * charges its hardcoded fallback and skips the sender's own row. Otherwise the sender's own row, then the
4924
+ * partner's, then the default row. `partner` only takes a share and never picks the row.
4925
+ */
4926
+ async getCreateFeeRates(partnerLink, sender) {
4927
+ const fallback = { streamflowFee: DEFAULT_STREAMFLOW_FEE, streamflowLockFee: DEFAULT_STREAMFLOW_FEE };
4928
+ let linkedPartner;
4929
+ if (partnerLink?.isSigner) {
4930
+ linkedPartner = common.pk(partnerLink.address).toBase58();
4931
+ } else if (partnerLink) {
4932
+ const address = common.pk(partnerLink.address);
4933
+ const account = await this.connection.getAccountInfo(address);
4934
+ if (account?.owner.equals(this.partnerOracleProgramId)) {
4935
+ const link = decodePartnerLink(account.data);
4936
+ if (link && !link.linkedPubkey.equals(sender)) {
4937
+ return fallback;
4938
+ }
4939
+ linkedPartner = (link?.partnerPubkey ?? address).toBase58();
4940
+ }
4872
4941
  }
4873
- const partner = filteredPartners[0];
4874
- return {
4875
- creationFeeSol: Number(partner.creation_fee),
4876
- autoClaimFeeSol: Number(partner.auto_claim_fee),
4877
- streamflowFee: Number(partner.token_fee_percent.toFixed(4)),
4878
- streamflowLockFee: Number(partner.token_lock_token_fee_percent.toFixed(4)),
4879
- partnerFee: 0
4880
- };
4942
+ const partners = await this.getFeeRows() ?? [];
4943
+ return findFees(partners, sender.toBase58()) ?? (linkedPartner ? findFees(partners, linkedPartner) : null) ?? findFees(partners, WITHDRAWOR) ?? fallback;
4881
4944
  }
4882
4945
  /**
4883
4946
  * Gets default streamflow fee
@@ -6001,6 +6064,7 @@ exports.isAligned = isAligned;
6001
6064
  exports.isCliffCloseToDepositedAmount = isCliffCloseToDepositedAmount;
6002
6065
  exports.isCreateAlignedStreamData = isCreateAlignedStreamData;
6003
6066
  exports.isDynamicLock = isDynamicLock;
6067
+ exports.isStrictTokenLockCreate = isStrictTokenLockCreate;
6004
6068
  exports.isTokenLock = isTokenLock;
6005
6069
  exports.isVesting = isVesting;
6006
6070
  exports.resolveConnection = resolveConnection;