@streamflow/stream 7.0.0-alpha.9 → 7.0.1

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.
Files changed (61) hide show
  1. package/README.md +22 -17
  2. package/dist/cjs/__tests__/aptos/streamClient.spec.js +4 -4
  3. package/dist/cjs/aptos/types.js +12 -12
  4. package/dist/cjs/aptos/utils.js +2 -3
  5. package/dist/cjs/common/constants.js +4 -3
  6. package/dist/cjs/common/contractUtils.js +23 -7
  7. package/dist/cjs/common/types.js +30 -1
  8. package/dist/cjs/common/utils.js +23 -20
  9. package/dist/cjs/evm/StreamClient.js +7 -7
  10. package/dist/cjs/evm/types.js +12 -12
  11. package/dist/cjs/evm/utils.js +1 -2
  12. package/dist/cjs/solana/StreamClient.js +399 -152
  13. package/dist/cjs/solana/constants.js +29 -1
  14. package/dist/cjs/solana/descriptor/idl/streamflow_aligned_unlocks.json +1471 -0
  15. package/dist/cjs/solana/descriptor/streamflow_aligned_unlocks.js +2 -0
  16. package/dist/cjs/solana/index.js +2 -1
  17. package/dist/cjs/solana/instructions.js +18 -19
  18. package/dist/cjs/solana/lib/derive-accounts.js +17 -0
  19. package/dist/cjs/solana/{utils.js → lib/utils.js} +32 -39
  20. package/dist/cjs/solana/types.js +26 -3
  21. package/dist/cjs/sui/StreamClient.js +1 -1
  22. package/dist/cjs/sui/types.js +12 -12
  23. package/dist/cjs/sui/utils.js +1 -2
  24. package/dist/cjs/sui/wallet.js +2 -2
  25. package/dist/esm/__tests__/aptos/streamClient.spec.js +4 -4
  26. package/dist/esm/aptos/types.d.ts +14 -14
  27. package/dist/esm/aptos/types.js +13 -13
  28. package/dist/esm/common/constants.d.ts +3 -2
  29. package/dist/esm/common/constants.js +3 -2
  30. package/dist/esm/common/contractUtils.d.ts +18 -15
  31. package/dist/esm/common/contractUtils.js +19 -6
  32. package/dist/esm/common/types.d.ts +112 -57
  33. package/dist/esm/common/types.js +29 -0
  34. package/dist/esm/common/utils.d.ts +11 -11
  35. package/dist/esm/common/utils.js +19 -16
  36. package/dist/esm/evm/StreamClient.d.ts +2 -2
  37. package/dist/esm/evm/StreamClient.js +7 -7
  38. package/dist/esm/evm/types.d.ts +14 -14
  39. package/dist/esm/evm/types.js +13 -13
  40. package/dist/esm/solana/StreamClient.d.ts +27 -16
  41. package/dist/esm/solana/StreamClient.js +402 -154
  42. package/dist/esm/solana/constants.d.ts +14 -1
  43. package/dist/esm/solana/constants.js +29 -1
  44. package/dist/esm/solana/descriptor/idl/streamflow_aligned_unlocks.json +1471 -0
  45. package/dist/esm/solana/descriptor/streamflow_aligned_unlocks.d.ts +1272 -0
  46. package/dist/esm/solana/descriptor/streamflow_aligned_unlocks.js +1 -0
  47. package/dist/esm/solana/index.d.ts +2 -1
  48. package/dist/esm/solana/index.js +2 -1
  49. package/dist/esm/solana/instructions.d.ts +17 -17
  50. package/dist/esm/solana/instructions.js +18 -19
  51. package/dist/esm/solana/layout.d.ts +0 -1
  52. package/dist/esm/solana/lib/derive-accounts.d.ts +4 -0
  53. package/dist/esm/solana/lib/derive-accounts.js +11 -0
  54. package/dist/esm/solana/{utils.d.ts → lib/utils.d.ts} +1 -4
  55. package/dist/esm/solana/{utils.js → lib/utils.js} +28 -34
  56. package/dist/esm/solana/types.d.ts +67 -40
  57. package/dist/esm/solana/types.js +32 -4
  58. package/dist/esm/sui/StreamClient.js +1 -1
  59. package/dist/esm/sui/types.d.ts +14 -14
  60. package/dist/esm/sui/types.js +13 -13
  61. package/package.json +11 -9
@@ -1,6 +1,6 @@
1
- import BigNumber from "bignumber.js";
1
+ import BN from "bn.js";
2
2
  import { buildStreamType, calculateUnlockedAmount } from "../common/contractUtils.js";
3
- import { getNumberFromBigNumber } from "../common/utils.js";
3
+ import { getNumberFromBN } from "../common/utils.js";
4
4
  export class EvmContract {
5
5
  magic;
6
6
  version;
@@ -49,7 +49,7 @@ export class EvmContract {
49
49
  this.magic = 0;
50
50
  this.version = 0;
51
51
  this.createdAt = stream.created.toNumber();
52
- this.withdrawnAmount = BigNumber(stream.withdrawn.toString());
52
+ this.withdrawnAmount = new BN(stream.withdrawn.toString());
53
53
  this.canceledAt = stream.canceled_at.toNumber();
54
54
  this.end = stream.end.toNumber();
55
55
  this.lastWithdrawnAt = stream.last_withdrawn_at.toNumber();
@@ -61,20 +61,20 @@ export class EvmContract {
61
61
  this.escrowTokens = "";
62
62
  this.streamflowTreasury = "";
63
63
  this.streamflowTreasuryTokens = "";
64
- this.streamflowFeeTotal = BigNumber(stream.fees.streamflow_fee.toString());
65
- this.streamflowFeeWithdrawn = BigNumber(stream.fees.streamflow_fee_withdrawn.toString());
64
+ this.streamflowFeeTotal = new BN(stream.fees.streamflow_fee.toString());
65
+ this.streamflowFeeWithdrawn = new BN(stream.fees.streamflow_fee_withdrawn.toString());
66
66
  this.streamflowFeePercent = stream.fees.streamflow_fee_percentage.toNumber() / 10000;
67
- this.partnerFeeTotal = BigNumber(0);
68
- this.partnerFeeWithdrawn = BigNumber(0);
67
+ this.partnerFeeTotal = new BN(0);
68
+ this.partnerFeeWithdrawn = new BN(0);
69
69
  this.partnerFeePercent = 0;
70
70
  this.partner = "";
71
71
  this.partnerTokens = "";
72
72
  this.start = stream.start.toNumber();
73
- this.depositedAmount = BigNumber(stream.amount.toString());
73
+ this.depositedAmount = new BN(stream.amount.toString());
74
74
  this.period = stream.period.toNumber();
75
- this.amountPerPeriod = BigNumber(stream.amount_per_period.toString());
75
+ this.amountPerPeriod = new BN(stream.amount_per_period.toString());
76
76
  this.cliff = stream.start.toNumber();
77
- this.cliffAmount = BigNumber(stream.cliff_amount.toString());
77
+ this.cliffAmount = new BN(stream.cliff_amount.toString());
78
78
  this.cancelableBySender = stream.meta.cancelable_by_sender;
79
79
  this.cancelableByRecipient = stream.meta.cancelable_by_recipient;
80
80
  this.automaticWithdrawal = stream.meta.automatic_withdrawal;
@@ -85,9 +85,9 @@ export class EvmContract {
85
85
  this.withdrawalFrequency = stream.meta.withdrawal_frequency.toNumber();
86
86
  this.closed = stream.closed;
87
87
  this.currentPauseStart = stream.current_pause_start.toNumber();
88
- this.pauseCumulative = BigNumber(stream.pause_cumulative.toString());
88
+ this.pauseCumulative = new BN(stream.pause_cumulative.toString());
89
89
  this.lastRateChangeTime = stream.last_rate_change_time.toNumber();
90
- this.fundsUnlockedAtLastRateChange = BigNumber(stream.funds_unlocked_at_last_rate_change.toString());
90
+ this.fundsUnlockedAtLastRateChange = new BN(stream.funds_unlocked_at_last_rate_change.toString());
91
91
  this.type = buildStreamType(this);
92
92
  }
93
93
  unlocked(currentTimestamp) {
@@ -97,6 +97,6 @@ export class EvmContract {
97
97
  });
98
98
  }
99
99
  remaining(decimals) {
100
- return getNumberFromBigNumber(this.depositedAmount.minus(this.withdrawnAmount), decimals);
100
+ return getNumberFromBN(this.depositedAmount.sub(this.withdrawnAmount), decimals);
101
101
  }
102
102
  }
@@ -1,14 +1,15 @@
1
1
  import PQueue from "p-queue";
2
2
  import { Connection, Keypair, PublicKey, TransactionInstruction, Commitment, ConnectionConfig } from "@solana/web3.js";
3
3
  import { IProgramAccount } from "@streamflow/common/solana";
4
- import { ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt, ISearchStreams } from "./types.js";
5
- import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateResult, ICreateStreamData, IGetAllData, IGetFeesData, IGetOneData, IFees, IMultiTransactionResult, ITopUpData, ITransactionResult, ITransferData, IUpdateData, IWithdrawData, Stream } from "../common/types.js";
4
+ import { ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt, ISearchStreams, ICreateStreamInstructions } from "./types.js";
5
+ import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateResult, ICreateStreamData, IGetAllData, IGetFeesData, IGetOneData, IFees, IMultiTransactionResult, ITopUpData, ITransactionResult, ITransferData, IUpdateData, IWithdrawData, Stream, ICreateAlignedStreamData } from "../common/types.js";
6
6
  import { BaseStreamClient } from "../common/BaseStreamClient.js";
7
7
  export declare class SolanaStreamClient extends BaseStreamClient {
8
8
  private connection;
9
9
  private programId;
10
10
  private commitment;
11
11
  private sendThrottler;
12
+ private alignedProxyProgram;
12
13
  /**
13
14
  * Create Stream instance
14
15
  */
@@ -21,15 +22,13 @@ export declare class SolanaStreamClient extends BaseStreamClient {
21
22
  * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
22
23
  */
23
24
  create(data: ICreateStreamData, extParams: ICreateStreamSolanaExt): Promise<ICreateResult>;
25
+ prepareCreateInstructions(streamParams: ICreateStreamData, extParams: ICreateStreamSolanaExt): Promise<ICreateStreamInstructions>;
26
+ prepareCreateAlignedUnlockInstructions(streamParams: ICreateAlignedStreamData, extParams: ICreateStreamSolanaExt): Promise<ICreateStreamInstructions>;
24
27
  /**
25
28
  * Creates a new stream/vesting contract.
26
29
  * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
27
30
  */
28
- prepareCreateInstructions({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canPause, canUpdateRate, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, partner, }: ICreateStreamData, { sender, metadataPubKeys, isNative, computePrice, computeLimit }: ICreateStreamSolanaExt): Promise<{
29
- ixs: TransactionInstruction[];
30
- metadata: Keypair | undefined;
31
- metadataPubKey: PublicKey;
32
- }>;
31
+ prepareCreateStreamInstructions({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canPause, canUpdateRate, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, partner, }: ICreateStreamData, { sender, metadataPubKeys, isNative, computePrice, computeLimit }: ICreateStreamSolanaExt): Promise<ICreateStreamInstructions>;
33
32
  /**
34
33
  * Creates a new stream/vesting contract using unchecked instruction.
35
34
  *
@@ -53,7 +52,12 @@ export declare class SolanaStreamClient extends BaseStreamClient {
53
52
  * Creates multiple stream/vesting contracts.
54
53
  * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
55
54
  */
56
- createMultiple(data: ICreateMultipleStreamData, { sender, metadataPubKeys, isNative, computePrice, computeLimit }: ICreateStreamSolanaExt): Promise<IMultiTransactionResult>;
55
+ createMultiple(data: ICreateMultipleStreamData, extParams: ICreateStreamSolanaExt): Promise<IMultiTransactionResult>;
56
+ /**
57
+ * Creates multiple stream/vesting contracts, and send all transactions sequentially.
58
+ * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
59
+ */
60
+ createMultipleSequential(data: ICreateMultipleStreamData, extParams: ICreateStreamSolanaExt): Promise<IMultiTransactionResult>;
57
61
  /**
58
62
  * Attempts withdrawing from the specified stream.
59
63
  */
@@ -65,11 +69,13 @@ export declare class SolanaStreamClient extends BaseStreamClient {
65
69
  /**
66
70
  * Attempts canceling the specified stream.
67
71
  */
68
- cancel({ id }: ICancelData, extParams: IInteractStreamSolanaExt): Promise<ITransactionResult>;
72
+ cancel(cancelData: ICancelData, extParams: IInteractStreamSolanaExt): Promise<ITransactionResult>;
73
+ prepareCancelInstructions(cancelData: ICancelData, extParams: IInteractStreamSolanaExt): Promise<TransactionInstruction[]>;
74
+ prepareCancelAlignedUnlockInstructions({ id }: ICancelData, { invoker, checkTokenAccounts, computePrice, computeLimit }: IInteractStreamSolanaExt): Promise<TransactionInstruction[]>;
69
75
  /**
70
76
  * Creates Transaction Instructions for cancel
71
77
  */
72
- prepareCancelInstructions({ id }: ICancelData, { invoker, checkTokenAccounts, computePrice, computeLimit }: IInteractStreamSolanaExt): Promise<TransactionInstruction[]>;
78
+ prepareCancelStreamInstructions({ id }: ICancelData, { invoker, checkTokenAccounts, computePrice, computeLimit }: IInteractStreamSolanaExt): Promise<TransactionInstruction[]>;
73
79
  /**
74
80
  * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
75
81
  * Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
@@ -92,6 +98,11 @@ export declare class SolanaStreamClient extends BaseStreamClient {
92
98
  * Fetch stream data by its id (address).
93
99
  */
94
100
  getOne({ id }: IGetOneData): Promise<Stream>;
101
+ /**
102
+ * Fetch all aligned outgoing streams/contracts by the provided public key.
103
+ */
104
+ private getOutgoingAlignedStreams;
105
+ private getIncomingAlignedStreams;
95
106
  /**
96
107
  * Fetch streams/contracts by providing direction.
97
108
  * Streams are sorted by start time in ascending order.
@@ -109,16 +120,16 @@ export declare class SolanaStreamClient extends BaseStreamClient {
109
120
  getFees({ address }: IGetFeesData): Promise<IFees | null>;
110
121
  getDefaultStreamflowFee(): Promise<number>;
111
122
  extractErrorCode(err: Error): string | null;
112
- /**
113
- * Forms instructions from params, creates a raw transaction and fetch recent blockhash.
114
- */
115
- private prepareStreamInstructions;
116
123
  /**
117
124
  * Utility function to generate metadata for a Contract or return existing Pubkey
118
125
  */
119
126
  private getOrCreateStreamMetadata;
120
127
  /**
121
- * Utility function that checks whether associated token accounts still exist and adds instructions to add them if not
128
+ * Utility function that checks whether the associated stream address is an aligned unlock contract, indicated by whether the sender/creator is a PDA
129
+ */
130
+ private isAlignedUnlock;
131
+ /**
132
+ * Returns insrtuctions for creating associated token accounts for the provided owners
122
133
  */
123
- private checkAssociatedTokenAccounts;
134
+ private getCreateATAInstructions;
124
135
  }