@streamflow/stream 7.0.0-alpha.1 → 7.0.0-alpha.10

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 (64) hide show
  1. package/README.md +65 -68
  2. package/dist/cjs/__tests__/aptos/streamClient.spec.js +83 -134
  3. package/dist/cjs/__tests__/common/GenericStreamClient.spec.js +9 -9
  4. package/dist/cjs/aptos/StreamClient.js +162 -367
  5. package/dist/cjs/aptos/constants.js +7 -8
  6. package/dist/cjs/aptos/index.js +3 -3
  7. package/dist/cjs/aptos/types.js +32 -41
  8. package/dist/cjs/aptos/utils.js +4 -4
  9. package/dist/cjs/aptos/wallet.js +20 -75
  10. package/dist/cjs/common/BaseStreamClient.js +11 -59
  11. package/dist/cjs/common/GenericStreamClient.js +46 -72
  12. package/dist/cjs/common/constants.js +2 -2
  13. package/dist/cjs/common/contractUtils.js +16 -17
  14. package/dist/cjs/common/utils.js +34 -84
  15. package/dist/cjs/evm/StreamClient.js +198 -456
  16. package/dist/cjs/evm/constants.js +19 -20
  17. package/dist/cjs/evm/types.js +25 -34
  18. package/dist/cjs/evm/utils.js +2 -2
  19. package/dist/cjs/index.js +10 -10
  20. package/dist/cjs/solana/StreamClient.js +608 -1090
  21. package/dist/cjs/solana/constants.js +16 -11
  22. package/dist/cjs/solana/instructions.js +76 -80
  23. package/dist/cjs/solana/layout.js +7 -8
  24. package/dist/cjs/solana/types.js +15 -25
  25. package/dist/cjs/solana/utils.js +77 -154
  26. package/dist/cjs/sui/StreamClient.js +325 -571
  27. package/dist/cjs/sui/constants.js +19 -20
  28. package/dist/cjs/sui/types.js +28 -62
  29. package/dist/cjs/sui/utils.js +7 -7
  30. package/dist/cjs/sui/wallet.js +13 -63
  31. package/dist/esm/__tests__/aptos/streamClient.spec.js +4 -4
  32. package/dist/esm/aptos/index.d.ts +3 -3
  33. package/dist/esm/aptos/index.js +3 -3
  34. package/dist/esm/aptos/types.d.ts +12 -12
  35. package/dist/esm/aptos/types.js +13 -13
  36. package/dist/esm/common/GenericStreamClient.d.ts +4 -4
  37. package/dist/esm/common/GenericStreamClient.js +4 -4
  38. package/dist/esm/common/constants.d.ts +2 -2
  39. package/dist/esm/common/constants.js +2 -2
  40. package/dist/esm/common/contractUtils.d.ts +14 -14
  41. package/dist/esm/common/contractUtils.js +6 -6
  42. package/dist/esm/common/types.d.ts +19 -19
  43. package/dist/esm/common/utils.d.ts +11 -11
  44. package/dist/esm/common/utils.js +16 -19
  45. package/dist/esm/evm/StreamClient.d.ts +2 -2
  46. package/dist/esm/evm/StreamClient.js +7 -7
  47. package/dist/esm/evm/types.d.ts +37 -37
  48. package/dist/esm/evm/types.js +13 -13
  49. package/dist/esm/index.d.ts +9 -9
  50. package/dist/esm/index.js +9 -9
  51. package/dist/esm/solana/StreamClient.d.ts +3 -1
  52. package/dist/esm/solana/StreamClient.js +36 -20
  53. package/dist/esm/solana/constants.d.ts +3 -0
  54. package/dist/esm/solana/constants.js +6 -0
  55. package/dist/esm/solana/instructions.d.ts +17 -17
  56. package/dist/esm/solana/instructions.js +19 -18
  57. package/dist/esm/solana/types.d.ts +41 -36
  58. package/dist/esm/solana/types.js +2 -2
  59. package/dist/esm/solana/utils.d.ts +2 -0
  60. package/dist/esm/solana/utils.js +32 -26
  61. package/dist/esm/sui/StreamClient.js +1 -1
  62. package/dist/esm/sui/types.d.ts +12 -12
  63. package/dist/esm/sui/types.js +13 -13
  64. package/package.json +10 -11
@@ -1,13 +1,13 @@
1
1
  import { TransactionInstruction } from "@solana/web3.js";
2
2
  import { Types } from "aptos";
3
- import BN from "bn.js";
3
+ import BigNumber from "bignumber.js";
4
4
  export { IChain, ICluster, ContractError } from "@streamflow/common";
5
5
  export interface IRecipient {
6
6
  recipient: string;
7
- amount: BN;
7
+ amount: BigNumber;
8
8
  name: string;
9
- cliffAmount: BN;
10
- amountPerPeriod: BN;
9
+ cliffAmount: BigNumber;
10
+ amountPerPeriod: BigNumber;
11
11
  }
12
12
  export interface IStreamConfig {
13
13
  period: number;
@@ -33,19 +33,19 @@ export interface IInteractData {
33
33
  id: string;
34
34
  }
35
35
  export interface IWithdrawData extends IInteractData {
36
- amount?: BN;
36
+ amount?: BigNumber;
37
37
  }
38
38
  export interface IUpdateData extends IInteractData {
39
39
  enableAutomaticWithdrawal?: boolean;
40
- withdrawFrequency?: BN;
41
- amountPerPeriod?: BN;
40
+ withdrawFrequency?: BigNumber;
41
+ amountPerPeriod?: BigNumber;
42
42
  }
43
43
  export type ICancelData = IInteractData;
44
44
  export interface ITransferData extends IInteractData {
45
45
  newRecipient: string;
46
46
  }
47
47
  export interface ITopUpData extends IInteractData {
48
- amount: BN;
48
+ amount: BigNumber;
49
49
  }
50
50
  export type IGetOneData = IInteractData;
51
51
  export interface IGetFeesData {
@@ -184,7 +184,7 @@ export interface Stream {
184
184
  magic: number;
185
185
  version: number;
186
186
  createdAt: number;
187
- withdrawnAmount: BN;
187
+ withdrawnAmount: BigNumber;
188
188
  canceledAt: number;
189
189
  end: number;
190
190
  lastWithdrawnAt: number;
@@ -196,20 +196,20 @@ export interface Stream {
196
196
  escrowTokens: string;
197
197
  streamflowTreasury: string;
198
198
  streamflowTreasuryTokens: string;
199
- streamflowFeeTotal: BN;
200
- streamflowFeeWithdrawn: BN;
199
+ streamflowFeeTotal: BigNumber;
200
+ streamflowFeeWithdrawn: BigNumber;
201
201
  streamflowFeePercent: number;
202
- partnerFeeTotal: BN;
203
- partnerFeeWithdrawn: BN;
202
+ partnerFeeTotal: BigNumber;
203
+ partnerFeeWithdrawn: BigNumber;
204
204
  partnerFeePercent: number;
205
205
  partner: string;
206
206
  partnerTokens: string;
207
207
  start: number;
208
- depositedAmount: BN;
208
+ depositedAmount: BigNumber;
209
209
  period: number;
210
- amountPerPeriod: BN;
210
+ amountPerPeriod: BigNumber;
211
211
  cliff: number;
212
- cliffAmount: BN;
212
+ cliffAmount: BigNumber;
213
213
  cancelableBySender: boolean;
214
214
  cancelableByRecipient: boolean;
215
215
  automaticWithdrawal: boolean;
@@ -220,10 +220,10 @@ export interface Stream {
220
220
  withdrawalFrequency: number;
221
221
  closed: boolean;
222
222
  currentPauseStart: number;
223
- pauseCumulative: BN;
223
+ pauseCumulative: BigNumber;
224
224
  lastRateChangeTime: number;
225
- fundsUnlockedAtLastRateChange: BN;
225
+ fundsUnlockedAtLastRateChange: BigNumber;
226
226
  type: StreamType;
227
- unlocked(currentTimestamp: number): BN;
227
+ unlocked(currentTimestamp: number): BigNumber;
228
228
  remaining(decimals: number): number;
229
229
  }
@@ -1,28 +1,28 @@
1
- import BN from "bn.js";
1
+ import BigNumber from "bignumber.js";
2
2
  /**
3
- * Used for conversion of token amounts to their Big Number representation.
4
- * Get Big Number representation in the smallest units from the same value in the highest units.
5
- * @param {number} value - Number of tokens you want to convert to its BN representation.
3
+ * Used for token amounts conversion from their Big Number representation to number.
4
+ * Get value in the highest units from BigNumber representation of the same value in the smallest units.
5
+ * @param {BigNumber} value - Big Number representation of value in the smallest units.
6
6
  * @param {number} decimals - Number of decimals the token has.
7
7
  */
8
- export declare const getBN: (value: number, decimals: number) => BN;
8
+ export declare const getNumberFromBigNumber: (bigNum: BigNumber, decimals: number) => number;
9
9
  /**
10
- * Used for token amounts conversion from their Big Number representation to number.
11
- * Get value in the highest units from BN representation of the same value in the smallest units.
12
- * @param {BN} value - Big Number representation of value in the smallest units.
10
+ * Used for conversion of token amounts to their Big Number representation.
11
+ * Get Big Number representation in the smallest units from the same value in the highest units.
12
+ * @param {number} value - Number of tokens you want to convert to its BigNumber representation.
13
13
  * @param {number} decimals - Number of decimals the token has.
14
14
  */
15
- export declare const getNumberFromBN: (value: BN, decimals: number) => number;
15
+ export declare const getScaledBigNumber: (value: number | string | BigNumber, decimals: number) => BigNumber;
16
16
  /**
17
17
  * Calculate total amount of a Contract including all fees.
18
- * - first we convert fee floating to a BN with up to 4 decimals precision
18
+ * - first we convert fee floating to a BigNumber with up to 4 decimals precision
19
19
  * - then we reverse the fee with `FEE_MULTIPLIER` to safely multiply it by depositedAmount
20
20
  * to receive a total number and not percentage of depositedAmount
21
21
  * @param depositedAmount deposited raw tokens
22
22
  * @param totalFee sum of all fees in percentage as floating number, e.g. 0.99% should be supplied as 0.99
23
23
  * @returns total tokens amount that Contract will retrieve from the Sender
24
24
  */
25
- export declare const calculateTotalAmountToDeposit: (depositedAmount: BN, totalFee: number) => BN;
25
+ export declare const calculateTotalAmountToDeposit: (depositedAmount: BigNumber, totalFee: number) => BigNumber;
26
26
  /**
27
27
  * Used to make on chain calls to the contract and wrap raised errors if any
28
28
  * @param func function that interacts with the contract
@@ -1,32 +1,29 @@
1
- import BN from "bn.js";
1
+ import BigNumber from "bignumber.js";
2
2
  import { ContractError } from "./types.js";
3
3
  const FEE_PRECISION = 4;
4
4
  const FEE_NORMALIZER = 10 ** FEE_PRECISION;
5
- const FEE_MULTIPLIER = new BN(10 ** 6);
5
+ const FEE_MULTIPLIER = BigNumber(10 ** 6);
6
6
  /**
7
- * Used for conversion of token amounts to their Big Number representation.
8
- * Get Big Number representation in the smallest units from the same value in the highest units.
9
- * @param {number} value - Number of tokens you want to convert to its BN representation.
7
+ * Used for token amounts conversion from their Big Number representation to number.
8
+ * Get value in the highest units from BigNumber representation of the same value in the smallest units.
9
+ * @param {BigNumber} value - Big Number representation of value in the smallest units.
10
10
  * @param {number} decimals - Number of decimals the token has.
11
11
  */
12
- export const getBN = (value, decimals) => {
13
- const decimalPart = value - Math.trunc(value);
14
- const integerPart = new BN(Math.trunc(value));
15
- const decimalE = new BN(decimalPart * 1e9);
16
- const sum = integerPart.mul(new BN(1e9)).add(decimalE);
17
- const resultE = sum.mul(new BN(10).pow(new BN(decimals)));
18
- return resultE.div(new BN(1e9));
12
+ export const getNumberFromBigNumber = (bigNum, decimals) => {
13
+ return bigNum.div(BigNumber(10).pow(decimals)).toNumber();
19
14
  };
20
15
  /**
21
- * Used for token amounts conversion from their Big Number representation to number.
22
- * Get value in the highest units from BN representation of the same value in the smallest units.
23
- * @param {BN} value - Big Number representation of value in the smallest units.
16
+ * Used for conversion of token amounts to their Big Number representation.
17
+ * Get Big Number representation in the smallest units from the same value in the highest units.
18
+ * @param {number} value - Number of tokens you want to convert to its BigNumber representation.
24
19
  * @param {number} decimals - Number of decimals the token has.
25
20
  */
26
- export const getNumberFromBN = (value, decimals) => value.gt(new BN(2 ** 53 - 1)) ? value.div(new BN(10 ** decimals)).toNumber() : value.toNumber() / 10 ** decimals;
21
+ export const getScaledBigNumber = (value, decimals) => {
22
+ return new BigNumber(value).times(new BigNumber(10).pow(decimals));
23
+ };
27
24
  /**
28
25
  * Calculate total amount of a Contract including all fees.
29
- * - first we convert fee floating to a BN with up to 4 decimals precision
26
+ * - first we convert fee floating to a BigNumber with up to 4 decimals precision
30
27
  * - then we reverse the fee with `FEE_MULTIPLIER` to safely multiply it by depositedAmount
31
28
  * to receive a total number and not percentage of depositedAmount
32
29
  * @param depositedAmount deposited raw tokens
@@ -34,8 +31,8 @@ export const getNumberFromBN = (value, decimals) => value.gt(new BN(2 ** 53 - 1)
34
31
  * @returns total tokens amount that Contract will retrieve from the Sender
35
32
  */
36
33
  export const calculateTotalAmountToDeposit = (depositedAmount, totalFee) => {
37
- const totalFeeNormalized = new BN(totalFee * FEE_NORMALIZER);
38
- return depositedAmount.mul(totalFeeNormalized.add(FEE_MULTIPLIER)).div(FEE_MULTIPLIER);
34
+ const totalFeeNormalized = BigNumber(totalFee).times(FEE_NORMALIZER);
35
+ return depositedAmount.times(totalFeeNormalized.plus(FEE_MULTIPLIER)).div(FEE_MULTIPLIER);
39
36
  };
40
37
  /**
41
38
  * Used to make on chain calls to the contract and wrap raised errors if any
@@ -1,5 +1,5 @@
1
1
  import { ethers } from "ethers";
2
- import BN from "bn.js";
2
+ import BigNumber from "bignumber.js";
3
3
  import { BaseStreamClient } from "../common/BaseStreamClient.js";
4
4
  import { ICancelData, IChain, ICluster, ICreateMultipleStreamData, ICreateResult, ICreateStreamData, IGetFeesData, IGetAllData, IGetOneData, IFees, IMultiTransactionResult, ITopUpData, ITransactionResult, ITransferData, IUpdateData, IWithdrawData, Stream } from "../common/types.js";
5
5
  export default class EvmStreamClient extends BaseStreamClient {
@@ -25,7 +25,7 @@ export default class EvmStreamClient extends BaseStreamClient {
25
25
  * Returns StreamClient protocol program ID.
26
26
  */
27
27
  getProgramId(): string;
28
- approveTokens(tokenId: string, amount: BN): Promise<void>;
28
+ approveTokens(tokenId: string, amount: BigNumber): Promise<void>;
29
29
  private generateMultiPayloads;
30
30
  private getFeeParams;
31
31
  private formatMetadataId;
@@ -1,5 +1,5 @@
1
1
  import { ethers } from "ethers";
2
- import BN from "bn.js";
2
+ import BigNumber from "bignumber.js";
3
3
  import { toChecksumAddress } from "ethereum-checksum-address";
4
4
  import { BaseStreamClient } from "../common/BaseStreamClient.js";
5
5
  import { IChain, ICluster, StreamDirection, } from "../common/types.js";
@@ -49,7 +49,7 @@ export default class EvmStreamClient extends BaseStreamClient {
49
49
  };
50
50
  const fees = await this.readContract.getWithdrawalFees(...this.getFeeParams(multiParams));
51
51
  const args = (await this.generateMultiPayloads(multiParams))[0];
52
- const sum = streamData.amount.mul(new BN(BASE_FEE)).div(new BN(1000000));
52
+ const sum = streamData.amount.times(BigNumber(BASE_FEE)).div(BigNumber(1000000));
53
53
  await this.approveTokens(streamData.tokenId, sum);
54
54
  const result = await this.writeContract.create(...args, {
55
55
  value: fees.value,
@@ -66,9 +66,9 @@ export default class EvmStreamClient extends BaseStreamClient {
66
66
  const fees = await this.readContract.getWithdrawalFees(...this.getFeeParams(multipleStreamData));
67
67
  const args = await this.generateMultiPayloads(multipleStreamData);
68
68
  const sum = multipleStreamData.recipients
69
- .reduce((acc, v) => acc.add(v.amount), new BN(0))
70
- .mul(new BN(BASE_FEE))
71
- .div(new BN(1000000));
69
+ .reduce((acc, v) => acc.plus(v.amount), BigNumber(0))
70
+ .times(BigNumber(BASE_FEE))
71
+ .div(BigNumber(1000000));
72
72
  await this.approveTokens(multipleStreamData.tokenId, sum);
73
73
  const creationPromises = args.map((item) => this.writeContract.create(...item, { value: fees.value }));
74
74
  const signatures = [];
@@ -120,7 +120,7 @@ export default class EvmStreamClient extends BaseStreamClient {
120
120
  }
121
121
  async topup(topupData) {
122
122
  const fees = await this.readContract.getTopUpWithdrawalFees(topupData.id, topupData.amount.toString());
123
- const sum = topupData.amount.mul(new BN(BASE_FEE)).div(new BN(1000000));
123
+ const sum = topupData.amount.times(BigNumber(BASE_FEE)).div(BigNumber(1000000));
124
124
  const stream = await this.getOne({ id: topupData.id });
125
125
  await this.approveTokens(stream.mint, sum);
126
126
  const result = await this.writeContract.topUp(topupData.id, topupData.amount.toString(), {
@@ -185,7 +185,7 @@ export default class EvmStreamClient extends BaseStreamClient {
185
185
  const tokenContract = new ethers.Contract(tokenId, ercAbi, this.signer);
186
186
  const address = await this.signer.getAddress();
187
187
  const allowance = await tokenContract.allowance(address, this.programId);
188
- if (new BN(allowance.toString()).gte(amount)) {
188
+ if (BigNumber(allowance.toString()).gte(amount)) {
189
189
  return;
190
190
  }
191
191
  const approvalTx = await tokenContract.approve(this.programId, amount.toString());
@@ -1,27 +1,27 @@
1
- import BN from "bn.js";
2
- import { BigNumber } from "ethers";
1
+ import BigNumber from "bignumber.js";
2
+ import { BigNumber as BigNumberEvm } from "ethers";
3
3
  import { Stream, StreamType } from "../common/types.js";
4
4
  export interface StreamAbiResult {
5
- amount: BigNumber;
6
- amount_per_period: BigNumber;
7
- canceled_at: BigNumber;
8
- cliff_amount: BigNumber;
5
+ amount: BigNumberEvm;
6
+ amount_per_period: BigNumberEvm;
7
+ canceled_at: BigNumberEvm;
8
+ cliff_amount: BigNumberEvm;
9
9
  closed: boolean;
10
- created: BigNumber;
11
- current_pause_start: BigNumber;
12
- end: BigNumber;
10
+ created: BigNumberEvm;
11
+ current_pause_start: BigNumberEvm;
12
+ end: BigNumberEvm;
13
13
  fees: {
14
- streamflow_fee_percentage: BigNumber;
15
- streamflow_fee: BigNumber;
16
- streamflow_fee_withdrawn: BigNumber;
17
- partner_fee_percentage: BigNumber;
18
- partner_fee: BigNumber;
19
- partner_fee_withdrawn: BigNumber;
20
- tx_fee: BigNumber;
14
+ streamflow_fee_percentage: BigNumberEvm;
15
+ streamflow_fee: BigNumberEvm;
16
+ streamflow_fee_withdrawn: BigNumberEvm;
17
+ partner_fee_percentage: BigNumberEvm;
18
+ partner_fee: BigNumberEvm;
19
+ partner_fee_withdrawn: BigNumberEvm;
20
+ tx_fee: BigNumberEvm;
21
21
  };
22
- funds_unlocked_at_last_rate_change: BigNumber;
23
- last_rate_change_time: BigNumber;
24
- last_withdrawn_at: BigNumber;
22
+ funds_unlocked_at_last_rate_change: BigNumberEvm;
23
+ last_rate_change_time: BigNumberEvm;
24
+ last_withdrawn_at: BigNumberEvm;
25
25
  meta: {
26
26
  automatic_withdrawal: boolean;
27
27
  can_topup: boolean;
@@ -32,27 +32,27 @@ export interface StreamAbiResult {
32
32
  pausable: boolean;
33
33
  transferable_by_recipient: boolean;
34
34
  transferable_by_sender: boolean;
35
- withdrawal_frequency: BigNumber;
35
+ withdrawal_frequency: BigNumberEvm;
36
36
  };
37
- pause_cumulative: BigNumber;
38
- period: BigNumber;
37
+ pause_cumulative: BigNumberEvm;
38
+ period: BigNumberEvm;
39
39
  recipient: string;
40
40
  sender: string;
41
41
  partner: string;
42
- start: BigNumber;
42
+ start: BigNumberEvm;
43
43
  token: string;
44
- withdrawn: BigNumber;
44
+ withdrawn: BigNumberEvm;
45
45
  }
46
46
  export interface FeesAbiResult {
47
47
  exists: boolean;
48
- streamflow_fee: BigNumber;
49
- partner_fee: BigNumber;
48
+ streamflow_fee: BigNumberEvm;
49
+ partner_fee: BigNumberEvm;
50
50
  }
51
51
  export declare class EvmContract implements Stream {
52
52
  magic: number;
53
53
  version: number;
54
54
  createdAt: number;
55
- withdrawnAmount: BN;
55
+ withdrawnAmount: BigNumber;
56
56
  canceledAt: number;
57
57
  end: number;
58
58
  lastWithdrawnAt: number;
@@ -64,20 +64,20 @@ export declare class EvmContract implements Stream {
64
64
  escrowTokens: string;
65
65
  streamflowTreasury: string;
66
66
  streamflowTreasuryTokens: string;
67
- streamflowFeeTotal: BN;
68
- streamflowFeeWithdrawn: BN;
67
+ streamflowFeeTotal: BigNumber;
68
+ streamflowFeeWithdrawn: BigNumber;
69
69
  streamflowFeePercent: number;
70
- partnerFeeTotal: BN;
71
- partnerFeeWithdrawn: BN;
70
+ partnerFeeTotal: BigNumber;
71
+ partnerFeeWithdrawn: BigNumber;
72
72
  partnerFeePercent: number;
73
73
  partner: string;
74
74
  partnerTokens: string;
75
75
  start: number;
76
- depositedAmount: BN;
76
+ depositedAmount: BigNumber;
77
77
  period: number;
78
- amountPerPeriod: BN;
78
+ amountPerPeriod: BigNumber;
79
79
  cliff: number;
80
- cliffAmount: BN;
80
+ cliffAmount: BigNumber;
81
81
  cancelableBySender: boolean;
82
82
  cancelableByRecipient: boolean;
83
83
  automaticWithdrawal: boolean;
@@ -88,11 +88,11 @@ export declare class EvmContract implements Stream {
88
88
  withdrawalFrequency: number;
89
89
  closed: boolean;
90
90
  currentPauseStart: number;
91
- pauseCumulative: BN;
91
+ pauseCumulative: BigNumber;
92
92
  lastRateChangeTime: number;
93
- fundsUnlockedAtLastRateChange: BN;
93
+ fundsUnlockedAtLastRateChange: BigNumber;
94
94
  type: StreamType;
95
95
  constructor(stream: StreamAbiResult);
96
- unlocked(currentTimestamp: number): BN;
96
+ unlocked(currentTimestamp: number): BigNumber;
97
97
  remaining(decimals: number): number;
98
98
  }
@@ -1,6 +1,6 @@
1
- import BN from "bn.js";
1
+ import BigNumber from "bignumber.js";
2
2
  import { buildStreamType, calculateUnlockedAmount } from "../common/contractUtils.js";
3
- import { getNumberFromBN } from "../common/utils.js";
3
+ import { getNumberFromBigNumber } 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 = new BN(stream.withdrawn.toString());
52
+ this.withdrawnAmount = BigNumber(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 = new BN(stream.fees.streamflow_fee.toString());
65
- this.streamflowFeeWithdrawn = new BN(stream.fees.streamflow_fee_withdrawn.toString());
64
+ this.streamflowFeeTotal = BigNumber(stream.fees.streamflow_fee.toString());
65
+ this.streamflowFeeWithdrawn = BigNumber(stream.fees.streamflow_fee_withdrawn.toString());
66
66
  this.streamflowFeePercent = stream.fees.streamflow_fee_percentage.toNumber() / 10000;
67
- this.partnerFeeTotal = new BN(0);
68
- this.partnerFeeWithdrawn = new BN(0);
67
+ this.partnerFeeTotal = BigNumber(0);
68
+ this.partnerFeeWithdrawn = BigNumber(0);
69
69
  this.partnerFeePercent = 0;
70
70
  this.partner = "";
71
71
  this.partnerTokens = "";
72
72
  this.start = stream.start.toNumber();
73
- this.depositedAmount = new BN(stream.amount.toString());
73
+ this.depositedAmount = BigNumber(stream.amount.toString());
74
74
  this.period = stream.period.toNumber();
75
- this.amountPerPeriod = new BN(stream.amount_per_period.toString());
75
+ this.amountPerPeriod = BigNumber(stream.amount_per_period.toString());
76
76
  this.cliff = stream.start.toNumber();
77
- this.cliffAmount = new BN(stream.cliff_amount.toString());
77
+ this.cliffAmount = BigNumber(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 = new BN(stream.pause_cumulative.toString());
88
+ this.pauseCumulative = BigNumber(stream.pause_cumulative.toString());
89
89
  this.lastRateChangeTime = stream.last_rate_change_time.toNumber();
90
- this.fundsUnlockedAtLastRateChange = new BN(stream.funds_unlocked_at_last_rate_change.toString());
90
+ this.fundsUnlockedAtLastRateChange = BigNumber(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 getNumberFromBN(this.depositedAmount.sub(this.withdrawnAmount), decimals);
100
+ return getNumberFromBigNumber(this.depositedAmount.minus(this.withdrawnAmount), decimals);
101
101
  }
102
102
  }
@@ -1,9 +1,9 @@
1
- export * as StreamflowAptos from "./aptos";
2
- export * as StreamflowEVM from "./evm";
3
- export * as StreamflowSolana from "./solana";
4
- export * as StreamflowSui from "./sui";
5
- export * from "./common/types";
6
- export * from "./common/utils";
7
- export * from "./common/constants";
8
- export * from "./common/contractUtils";
9
- export { default as GenericStreamClient } from "./common/GenericStreamClient";
1
+ export * as StreamflowAptos from "./aptos/index.js";
2
+ export * as StreamflowEVM from "./evm/index.js";
3
+ export * as StreamflowSolana from "./solana/index.js";
4
+ export * as StreamflowSui from "./sui/index.js";
5
+ export * from "./common/types.js";
6
+ export * from "./common/utils.js";
7
+ export * from "./common/constants.js";
8
+ export * from "./common/contractUtils.js";
9
+ export { default as GenericStreamClient } from "./common/GenericStreamClient.js";
package/dist/esm/index.js CHANGED
@@ -1,9 +1,9 @@
1
- export * as StreamflowAptos from "./aptos";
2
- export * as StreamflowEVM from "./evm";
3
- export * as StreamflowSolana from "./solana";
4
- export * as StreamflowSui from "./sui";
5
- export * from "./common/types";
6
- export * from "./common/utils";
7
- export * from "./common/constants";
8
- export * from "./common/contractUtils";
9
- export { default as GenericStreamClient } from "./common/GenericStreamClient";
1
+ export * as StreamflowAptos from "./aptos/index.js";
2
+ export * as StreamflowEVM from "./evm/index.js";
3
+ export * as StreamflowSolana from "./solana/index.js";
4
+ export * as StreamflowSui from "./sui/index.js";
5
+ export * from "./common/types.js";
6
+ export * from "./common/utils.js";
7
+ export * from "./common/constants.js";
8
+ export * from "./common/contractUtils.js";
9
+ export { default as GenericStreamClient } from "./common/GenericStreamClient.js";
@@ -1,6 +1,7 @@
1
1
  import PQueue from "p-queue";
2
2
  import { Connection, Keypair, PublicKey, TransactionInstruction, Commitment, ConnectionConfig } from "@solana/web3.js";
3
- import { ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt } from "./types.js";
3
+ import { IProgramAccount } from "@streamflow/common/solana";
4
+ import { ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt, ISearchStreams } from "./types.js";
4
5
  import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateResult, ICreateStreamData, IGetAllData, IGetFeesData, IGetOneData, IFees, IMultiTransactionResult, ITopUpData, ITransactionResult, ITransferData, IUpdateData, IWithdrawData, Stream } from "../common/types.js";
5
6
  import { BaseStreamClient } from "../common/BaseStreamClient.js";
6
7
  export declare class SolanaStreamClient extends BaseStreamClient {
@@ -96,6 +97,7 @@ export declare class SolanaStreamClient extends BaseStreamClient {
96
97
  * Streams are sorted by start time in ascending order.
97
98
  */
98
99
  get({ address, type, direction, }: IGetAllData): Promise<[string, Stream][]>;
100
+ searchStreams(data: ISearchStreams): Promise<IProgramAccount<Stream>[]>;
99
101
  /**
100
102
  * Attempts updating the stream auto withdrawal params and amount per period
101
103
  */
@@ -1,5 +1,5 @@
1
1
  // Latest version of the SDK that does not use Anchor. It supports raw instructions.
2
- import BN from "bn.js";
2
+ import BigNumber from "bignumber.js";
3
3
  import { Buffer } from "buffer";
4
4
  import { ASSOCIATED_TOKEN_PROGRAM_ID, NATIVE_MINT } from "@solana/spl-token";
5
5
  import { Connection, Keypair, PublicKey, SystemProgram, SYSVAR_RENT_PUBKEY, TransactionMessage, VersionedTransaction, } from "@solana/web3.js";
@@ -7,7 +7,7 @@ import { ata, checkOrCreateAtaBatch, signAndExecuteTransaction, getProgramAccoun
7
7
  import * as borsh from "borsh";
8
8
  import { Contract, } from "./types.js";
9
9
  import { decodeStream, extractSolanaErrorCode, sendAndConfirmStreamRawTransaction, signAllTransactionWithRecipients, } from "./utils.js";
10
- import { PROGRAM_ID, STREAMFLOW_TREASURY_PUBLIC_KEY, STREAM_STRUCT_OFFSET_RECIPIENT, STREAM_STRUCT_OFFSET_SENDER, TX_FINALITY_CONFIRMED, WITHDRAWOR_PUBLIC_KEY, FEE_ORACLE_PUBLIC_KEY, DEFAULT_STREAMFLOW_FEE, PARTNER_ORACLE_PROGRAM_ID, FEES_METADATA_SEED, PARTNERS_SCHEMA, } from "./constants.js";
10
+ import { PROGRAM_ID, STREAMFLOW_TREASURY_PUBLIC_KEY, STREAM_STRUCT_OFFSET_RECIPIENT, STREAM_STRUCT_OFFSET_SENDER, TX_FINALITY_CONFIRMED, WITHDRAWOR_PUBLIC_KEY, FEE_ORACLE_PUBLIC_KEY, DEFAULT_STREAMFLOW_FEE, PARTNER_ORACLE_PROGRAM_ID, FEES_METADATA_SEED, PARTNERS_SCHEMA, STREAM_STRUCT_OFFSETS, } from "./constants.js";
11
11
  import { withdrawStreamInstruction, cancelStreamInstruction, transferStreamInstruction, topupStreamInstruction, createStreamInstruction, createUncheckedStreamInstruction, updateStreamInstruction, } from "./instructions.js";
12
12
  import { ICluster, StreamDirection, StreamType, } from "../common/types.js";
13
13
  import { BaseStreamClient } from "../common/BaseStreamClient.js";
@@ -72,7 +72,7 @@ export class SolanaStreamClient extends BaseStreamClient {
72
72
  const senderTokens = await ata(mintPublicKey, sender.publicKey, tokenProgramId);
73
73
  const recipientTokens = await ata(mintPublicKey, recipientPublicKey, tokenProgramId);
74
74
  const streamflowTreasuryTokens = await ata(mintPublicKey, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
75
- const partnerPublicKey = partner ? new PublicKey(partner) : STREAMFLOW_TREASURY_PUBLIC_KEY;
75
+ const partnerPublicKey = partner ? new PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
76
76
  const partnerTokens = await ata(mintPublicKey, partnerPublicKey, tokenProgramId);
77
77
  if (isNative) {
78
78
  const totalFee = await this.getTotalFee({
@@ -82,12 +82,12 @@ export class SolanaStreamClient extends BaseStreamClient {
82
82
  ixs.push(...(await prepareWrappedAccount(this.connection, sender.publicKey, totalAmount)));
83
83
  }
84
84
  ixs.push(createStreamInstruction({
85
- start: new BN(start),
85
+ start: BigNumber(start),
86
86
  depositedAmount,
87
- period: new BN(period),
87
+ period: BigNumber(period),
88
88
  amountPerPeriod,
89
- cliff: new BN(cliff),
90
- cliffAmount,
89
+ cliff: BigNumber(cliff),
90
+ cliffAmount: BigNumber(cliffAmount),
91
91
  cancelableBySender,
92
92
  cancelableByRecipient,
93
93
  automaticWithdrawal,
@@ -97,7 +97,7 @@ export class SolanaStreamClient extends BaseStreamClient {
97
97
  canUpdateRate: !!canUpdateRate,
98
98
  canPause: !!canPause,
99
99
  name,
100
- withdrawFrequency: new BN(automaticWithdrawal ? withdrawalFrequency : period),
100
+ withdrawFrequency: BigNumber(automaticWithdrawal ? withdrawalFrequency : period),
101
101
  }, this.programId, {
102
102
  sender: sender.publicKey,
103
103
  senderTokens,
@@ -161,7 +161,7 @@ export class SolanaStreamClient extends BaseStreamClient {
161
161
  const [escrowTokens] = PublicKey.findProgramAddressSync([Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId);
162
162
  const { tokenProgramId } = await getMintAndProgram(this.connection, mintPublicKey);
163
163
  const senderTokens = await ata(mintPublicKey, sender.publicKey, tokenProgramId);
164
- const partnerPublicKey = partner ? new PublicKey(partner) : STREAMFLOW_TREASURY_PUBLIC_KEY;
164
+ const partnerPublicKey = partner ? new PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
165
165
  const ixs = prepareBaseInstructions(this.connection, {
166
166
  computePrice,
167
167
  computeLimit,
@@ -172,12 +172,12 @@ export class SolanaStreamClient extends BaseStreamClient {
172
172
  ixs.push(...(await prepareWrappedAccount(this.connection, sender.publicKey, totalAmount)));
173
173
  }
174
174
  const createInstruction = createUncheckedStreamInstruction({
175
- start: new BN(start),
175
+ start: BigNumber(start),
176
176
  depositedAmount,
177
- period: new BN(period),
177
+ period: BigNumber(period),
178
178
  amountPerPeriod,
179
- cliff: new BN(cliff),
180
- cliffAmount,
179
+ cliff: BigNumber(cliff),
180
+ cliffAmount: BigNumber(cliffAmount),
181
181
  cancelableBySender,
182
182
  cancelableByRecipient,
183
183
  automaticWithdrawal,
@@ -187,7 +187,7 @@ export class SolanaStreamClient extends BaseStreamClient {
187
187
  canUpdateRate: !!canUpdateRate,
188
188
  canPause: !!canPause,
189
189
  name,
190
- withdrawFrequency: new BN(automaticWithdrawal ? withdrawalFrequency : period),
190
+ withdrawFrequency: BigNumber(automaticWithdrawal ? withdrawalFrequency : period),
191
191
  recipient: recipientPublicKey,
192
192
  partner: partnerPublicKey,
193
193
  }, this.programId, {
@@ -252,7 +252,7 @@ export class SolanaStreamClient extends BaseStreamClient {
252
252
  batch.push({ tx, recipient });
253
253
  }
254
254
  if (isNative) {
255
- const totalDepositedAmount = recipients.reduce((acc, recipient) => recipient.amount.add(acc), new BN(0));
255
+ const totalDepositedAmount = recipients.reduce((acc, recipient) => recipient.amount.plus(acc), BigNumber(0));
256
256
  const nativeInstructions = await prepareWrappedAccount(this.connection, sender.publicKey, totalDepositedAmount);
257
257
  const messageV0 = new TransactionMessage({
258
258
  payerKey: sender.publicKey,
@@ -537,6 +537,22 @@ export class SolanaStreamClient extends BaseStreamClient {
537
537
  return sortedStreams;
538
538
  return sortedStreams.filter((stream) => stream[1].type === type);
539
539
  }
540
+ async searchStreams(data) {
541
+ const filters = Object.entries(data)
542
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
543
+ .filter(([_, value]) => value) // Only keep entries where the value is truthy
544
+ .map(([key, value]) => ({
545
+ memcmp: {
546
+ offset: STREAM_STRUCT_OFFSETS[key],
547
+ bytes: value,
548
+ },
549
+ }));
550
+ const accounts = await this.connection.getProgramAccounts(this.programId, { filters });
551
+ return accounts.map(({ pubkey, account }) => ({
552
+ publicKey: pubkey,
553
+ account: new Contract(decodeStream(account.data)),
554
+ }));
555
+ }
540
556
  /**
541
557
  * Attempts updating the stream auto withdrawal params and amount per period
542
558
  */
@@ -624,12 +640,12 @@ export class SolanaStreamClient extends BaseStreamClient {
624
640
  const partnerPublicKey = partner ? new PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
625
641
  const partnerTokens = await ata(mintPublicKey, partnerPublicKey, tokenProgramId);
626
642
  ixs.push(createStreamInstruction({
627
- start: new BN(start),
643
+ start: BigNumber(start),
628
644
  depositedAmount: recipient.amount,
629
- period: new BN(period),
645
+ period: BigNumber(period),
630
646
  amountPerPeriod: recipient.amountPerPeriod,
631
- cliff: new BN(cliff),
632
- cliffAmount: recipient.cliffAmount,
647
+ cliff: BigNumber(cliff),
648
+ cliffAmount: BigNumber(recipient.cliffAmount),
633
649
  cancelableBySender,
634
650
  cancelableByRecipient,
635
651
  automaticWithdrawal,
@@ -639,7 +655,7 @@ export class SolanaStreamClient extends BaseStreamClient {
639
655
  canUpdateRate: !!canUpdateRate,
640
656
  canPause: !!canPause,
641
657
  name: recipient.name,
642
- withdrawFrequency: new BN(automaticWithdrawal ? withdrawalFrequency : period),
658
+ withdrawFrequency: BigNumber(automaticWithdrawal ? withdrawalFrequency : period),
643
659
  }, this.programId, {
644
660
  sender: sender.publicKey,
645
661
  senderTokens,