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

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 (39) hide show
  1. package/README.md +15 -15
  2. package/dist/cjs/__tests__/aptos/streamClient.spec.js +4 -4
  3. package/dist/cjs/aptos/types.js +12 -12
  4. package/dist/cjs/common/constants.js +2 -2
  5. package/dist/cjs/common/contractUtils.js +6 -6
  6. package/dist/cjs/common/utils.js +22 -19
  7. package/dist/cjs/evm/StreamClient.js +7 -7
  8. package/dist/cjs/evm/types.js +12 -12
  9. package/dist/cjs/solana/StreamClient.js +19 -19
  10. package/dist/cjs/solana/instructions.js +18 -19
  11. package/dist/cjs/solana/types.js +1 -1
  12. package/dist/cjs/solana/utils.js +27 -34
  13. package/dist/cjs/sui/StreamClient.js +1 -1
  14. package/dist/cjs/sui/types.js +12 -12
  15. package/dist/esm/__tests__/aptos/streamClient.spec.js +4 -4
  16. package/dist/esm/aptos/types.d.ts +12 -12
  17. package/dist/esm/aptos/types.js +13 -13
  18. package/dist/esm/common/constants.d.ts +2 -2
  19. package/dist/esm/common/constants.js +2 -2
  20. package/dist/esm/common/contractUtils.d.ts +14 -14
  21. package/dist/esm/common/contractUtils.js +6 -6
  22. package/dist/esm/common/types.d.ts +19 -19
  23. package/dist/esm/common/utils.d.ts +11 -11
  24. package/dist/esm/common/utils.js +19 -16
  25. package/dist/esm/evm/StreamClient.d.ts +2 -2
  26. package/dist/esm/evm/StreamClient.js +7 -7
  27. package/dist/esm/evm/types.d.ts +12 -12
  28. package/dist/esm/evm/types.js +13 -13
  29. package/dist/esm/solana/StreamClient.js +19 -19
  30. package/dist/esm/solana/instructions.d.ts +17 -17
  31. package/dist/esm/solana/instructions.js +18 -19
  32. package/dist/esm/solana/types.d.ts +36 -36
  33. package/dist/esm/solana/types.js +2 -2
  34. package/dist/esm/solana/utils.d.ts +0 -2
  35. package/dist/esm/solana/utils.js +26 -32
  36. package/dist/esm/sui/StreamClient.js +1 -1
  37. package/dist/esm/sui/types.d.ts +12 -12
  38. package/dist/esm/sui/types.js +13 -13
  39. package/package.json +6 -5
package/README.md CHANGED
@@ -22,7 +22,7 @@ API Documentation available here: [docs site →](https://streamflow-finance.git
22
22
  Most common imports:
23
23
 
24
24
  ```javascript
25
- import { Types, GenericStreamClient, getScaledBigNumber, getNumberFromBigNumber } from "@streamflow/stream";
25
+ import { Types, GenericStreamClient, getBN, getNumberFromBN } from "@streamflow/stream";
26
26
  ```
27
27
 
28
28
  _Check the SDK for other types and utility functions._
@@ -124,11 +124,11 @@ const createStreamParams: Types.ICreateStreamData = {
124
124
  recipient: "4ih00075bKjVg000000tLdk4w42NyG3Mv0000dc0M00", // Recipient address.
125
125
  tokenId: "DNw99999M7e24g99999999WJirKeZ5fQc6KY999999gK", // Token mint address.
126
126
  start: 1643363040, // Timestamp (in seconds) when the stream/token vesting starts.
127
- amount: getScaledBigNumber(100, 9), // depositing 100 tokens with 9 decimals mint.
127
+ amount: getBN(100, 9), // depositing 100 tokens with 9 decimals mint.
128
128
  period: 1, // Time step (period) in seconds per which the unlocking occurs.
129
129
  cliff: 1643363160, // Vesting contract "cliff" timestamp in seconds.
130
- cliffAmount: 10, // Amount unlocked at the "cliff" timestamp.
131
- amountPerPeriod: getScaledBigNumber(5, 9), // Release rate: how many tokens are unlocked per each period.
130
+ cliffAmount: new BN(10), // Amount unlocked at the "cliff" timestamp.
131
+ amountPerPeriod: getBN(5, 9), // Release rate: how many tokens are unlocked per each period.
132
132
  name: "Transfer to Jane Doe.", // The stream name or subject.
133
133
  canTopup: false, // Whether additional tokens can be deposited after creation, setting to FALSE will effectively create a vesting contract.
134
134
  canUpdateRate: false, // settings to TRUE allows sender to update amountPerPeriod
@@ -169,10 +169,10 @@ try {
169
169
  const recipients = [
170
170
  {
171
171
  recipient: "4ih00075bKjVg000000tLdk4w42NyG3Mv0000dc0M00", // Solana recipient address.
172
- amount: getScaledBgNumber(100, 9), // depositing 100 tokens with 9 decimals mint.
172
+ amount: getBN(100, 9), // depositing 100 tokens with 9 decimals mint.
173
173
  name: "January Payroll", // The stream name/subject.
174
- cliffAmount: getScaledBgNumber(10, 9), // amount released on cliff for this recipient
175
- amountPerPeriod: getScaledBgNumber(1, 9), //amount released every specified period epoch
174
+ cliffAmount: getBN(10, 9), // amount released on cliff for this recipient
175
+ amountPerPeriod: getBN(1, 9), //amount released every specified period epoch
176
176
  },
177
177
  ];
178
178
  const createMultiStreamsParams: ICreateMultipleStreamData = {
@@ -234,7 +234,7 @@ interface ICreateResult {
234
234
  ```javascript
235
235
  const withdrawStreamParams: Types.IWithdrawData = {
236
236
  id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier (address) of a stream to be withdrawn from.
237
- amount: getScaledBgNumber(100, 9), // Requested amount to withdraw. If stream is completed, the whole amount will be withdrawn.
237
+ amount: getBN(100, 9), // Requested amount to withdraw. If stream is completed, the whole amount will be withdrawn.
238
238
  };
239
239
 
240
240
  const solanaParams = {
@@ -265,7 +265,7 @@ try {
265
265
  ```javascript
266
266
  const topupStreamParams: ITopUpData = {
267
267
  id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier (address) of a stream to be topped up.
268
- amount: getScaledBgNumber(100, 9), // Specified amount to topup (increases deposited amount).
268
+ amount: getBN(100, 9), // Specified amount to topup (increases deposited amount).
269
269
  };
270
270
 
271
271
  const solanaParams = {
@@ -360,7 +360,7 @@ const updateStreamParams: IUpdateData = {
360
360
  id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to update.
361
361
  enableAutomaticWithdrawal: true, // [optional], allows to enable AW if it wasn't, disable is not possible
362
362
  withdrawFrequency: 60, // [optional], allows to update withdrawal frequency, may result in additional AW fees
363
- amountPerPeriod: getScaledBgNumber(10, 9), // [optional], allows to update release amount effective on next unlock
363
+ amountPerPeriod: getBN(10, 9), // [optional], allows to update release amount effective on next unlock
364
364
  }
365
365
 
366
366
  const solanaParams = {
@@ -406,7 +406,7 @@ const stream = await client.getOne({
406
406
  });
407
407
 
408
408
  const unlocked = stream.unlocked(tsInSeconds); // bignumber amount unlocked at the tsInSeconds
409
- console.log(getNumberFromBigNumber(unlocked, 9));
409
+ console.log(getNumberFromBN(unlocked, 9));
410
410
  ```
411
411
 
412
412
  - Note: unlocked amount is determined based on configuration set on creation, no dynamic data is involved.
@@ -418,7 +418,7 @@ const stream = await client.getOne({
418
418
  id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA",
419
419
  });
420
420
  const withdrawn = stream.withdrawnAmount; // big number amount withdrawn already
421
- console.log(getNumberFromBigNumber(wihtdrawn, 9));
421
+ console.log(getNumberFromBN(wihtdrawn, 9));
422
422
  const remaining = stream.remaining(9); // amount of remaining funds
423
423
  console.log(remaining);
424
424
  ```
@@ -489,10 +489,10 @@ Streamflow protocol program IDs
489
489
  | Testnet | 0xf1916c119a6c917d4b36f96ffc0443930745789f3126a716e05a62223c48993a |
490
490
  | Mainnet | 0xa283fd6b45f1103176e7ae27e870c89df7c8783b15345e2b13faa81ec25c4fa6 |
491
491
 
492
- **All BigNumber amounts are denominated in their smallest units.**
492
+ **All BN amounts are denominated in their smallest units.**
493
493
 
494
494
  E.g, if the amount is 1 SOL than this amount in lamports is `1000 \* 10^9 = 1_000_000_000.`
495
495
 
496
- And `BigNumber(1_000_000_000)` is used.
496
+ And `BN(1_000_000_000)` is used.
497
497
 
498
- Use `getScaledBigNumber` and `getNumberFromBigNumber` utility functions for conversions between `BigNumber` and `Number` types.
498
+ Use `getBN` and `getNumberFromBN` utility functions for conversions between `BN` and `Number` types.
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const bignumber_js_1 = require("bignumber.js");
6
+ const bn_js_1 = require("bn.js");
7
7
  const vitest_1 = require("vitest");
8
8
  const StreamClient_js_1 = __importDefault(require("../../aptos/StreamClient.js"));
9
9
  const types_js_1 = require("../../common/types.js");
@@ -37,10 +37,10 @@ const types_js_1 = require("../../common/types.js");
37
37
  };
38
38
  const mockRecipient = {
39
39
  recipient: "0xtest",
40
- amount: (0, bignumber_js_1.BigNumber)(1000),
40
+ amount: new bn_js_1.BN(1000),
41
41
  name: "test name",
42
- cliffAmount: (0, bignumber_js_1.BigNumber)(1),
43
- amountPerPeriod: (0, bignumber_js_1.BigNumber)(1),
42
+ cliffAmount: new bn_js_1.BN(1),
43
+ amountPerPeriod: new bn_js_1.BN(1),
44
44
  };
45
45
  const mockData = {
46
46
  period: 100,
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Contract = void 0;
7
- const bignumber_js_1 = __importDefault(require("bignumber.js"));
7
+ const bn_js_1 = __importDefault(require("bn.js"));
8
8
  const buffer_1 = require("buffer");
9
9
  const contractUtils_js_1 = require("../common/contractUtils.js");
10
10
  const utils_js_1 = require("./utils.js");
@@ -14,7 +14,7 @@ class Contract {
14
14
  this.magic = 0;
15
15
  this.version = 0;
16
16
  this.createdAt = parseInt(stream.created);
17
- this.withdrawnAmount = (0, bignumber_js_1.default)(stream.withdrawn);
17
+ this.withdrawnAmount = new bn_js_1.default(stream.withdrawn);
18
18
  this.canceledAt = parseInt(stream.canceled_at);
19
19
  this.end = parseInt(stream.end);
20
20
  this.lastWithdrawnAt = parseInt(stream.last_withdrawn_at);
@@ -26,20 +26,20 @@ class Contract {
26
26
  this.escrowTokens = "";
27
27
  this.streamflowTreasury = "";
28
28
  this.streamflowTreasuryTokens = "";
29
- this.streamflowFeeTotal = (0, bignumber_js_1.default)(0);
30
- this.streamflowFeeWithdrawn = (0, bignumber_js_1.default)(0);
29
+ this.streamflowFeeTotal = new bn_js_1.default(0);
30
+ this.streamflowFeeWithdrawn = new bn_js_1.default(0);
31
31
  this.streamflowFeePercent = parseInt(stream.fees.streamflow_fee_percentage) / 10000;
32
- this.partnerFeeTotal = (0, bignumber_js_1.default)(0);
33
- this.partnerFeeWithdrawn = (0, bignumber_js_1.default)(0);
32
+ this.partnerFeeTotal = new bn_js_1.default(0);
33
+ this.partnerFeeWithdrawn = new bn_js_1.default(0);
34
34
  this.partnerFeePercent = 0;
35
35
  this.partner = "";
36
36
  this.partnerTokens = "";
37
37
  this.start = parseInt(stream.start);
38
- this.depositedAmount = (0, bignumber_js_1.default)(stream.amount);
38
+ this.depositedAmount = new bn_js_1.default(stream.amount);
39
39
  this.period = parseInt(stream.period);
40
- this.amountPerPeriod = (0, bignumber_js_1.default)(stream.amount_per_period);
40
+ this.amountPerPeriod = new bn_js_1.default(stream.amount_per_period);
41
41
  this.cliff = parseInt(stream.start);
42
- this.cliffAmount = (0, bignumber_js_1.default)(stream.cliff_amount);
42
+ this.cliffAmount = new bn_js_1.default(stream.cliff_amount);
43
43
  this.cancelableBySender = stream.meta.cancelable_by_sender;
44
44
  this.cancelableByRecipient = stream.meta.cancelable_by_recipient;
45
45
  this.automaticWithdrawal = stream.meta.automatic_withdrawal;
@@ -51,9 +51,9 @@ class Contract {
51
51
  this.withdrawalFrequency = parseInt(stream.meta.withdrawal_frequency);
52
52
  this.closed = stream.closed;
53
53
  this.currentPauseStart = parseInt(stream.current_pause_start);
54
- this.pauseCumulative = (0, bignumber_js_1.default)(stream.pause_cumulative);
54
+ this.pauseCumulative = new bn_js_1.default(stream.pause_cumulative);
55
55
  this.lastRateChangeTime = parseInt(stream.last_rate_change_time);
56
- this.fundsUnlockedAtLastRateChange = (0, bignumber_js_1.default)(stream.funds_unlocked_at_last_rate_change);
56
+ this.fundsUnlockedAtLastRateChange = new bn_js_1.default(stream.funds_unlocked_at_last_rate_change);
57
57
  this.type = (0, contractUtils_js_1.buildStreamType)(this);
58
58
  }
59
59
  unlocked(currentTimestamp) {
@@ -63,7 +63,7 @@ class Contract {
63
63
  });
64
64
  }
65
65
  remaining(decimals) {
66
- return (0, utils_js_2.getNumberFromBigNumber)(this.depositedAmount.minus(this.withdrawnAmount), decimals);
66
+ return (0, utils_js_2.getNumberFromBN)(this.depositedAmount.sub(this.withdrawnAmount), decimals);
67
67
  }
68
68
  }
69
69
  exports.Contract = Contract;
@@ -4,6 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.WITHDRAW_AVAILABLE_AMOUNT = exports.BASE_FEE = void 0;
7
- const bignumber_js_1 = __importDefault(require("bignumber.js"));
7
+ const bn_js_1 = __importDefault(require("bn.js"));
8
8
  exports.BASE_FEE = 1009900; // Buffer to include usual fees when calculating stream amount
9
- exports.WITHDRAW_AVAILABLE_AMOUNT = (0, bignumber_js_1.default)("18446744073709551615"); // Magical number to withdraw all available amount from a Contract
9
+ exports.WITHDRAW_AVAILABLE_AMOUNT = new bn_js_1.default("18446744073709551615"); // Magical number to withdraw all available amount from a Contract
@@ -4,24 +4,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.buildStreamType = exports.isTokenLock = exports.isVesting = exports.isPayment = exports.isCliffCloseToDepositedAmount = exports.calculateUnlockedAmount = void 0;
7
- const bignumber_js_1 = __importDefault(require("bignumber.js"));
7
+ const bn_js_1 = __importDefault(require("bn.js"));
8
8
  const types_js_1 = require("./types.js");
9
9
  const calculateUnlockedAmount = ({ depositedAmount, cliff, cliffAmount, end, currentTimestamp, lastRateChangeTime, period, amountPerPeriod, fundsUnlockedAtLastRateChange, }) => {
10
10
  const deposited = depositedAmount;
11
11
  if (currentTimestamp < cliff)
12
- return (0, bignumber_js_1.default)(0);
12
+ return new bn_js_1.default(0);
13
13
  if (currentTimestamp > end)
14
14
  return deposited;
15
15
  const savedUnlockedFunds = lastRateChangeTime === 0 ? cliffAmount : fundsUnlockedAtLastRateChange;
16
16
  const savedUnlockedFundsTime = lastRateChangeTime === 0 ? cliff : lastRateChangeTime;
17
- const streamed = (0, bignumber_js_1.default)(Math.floor((currentTimestamp - savedUnlockedFundsTime) / period))
18
- .times(amountPerPeriod)
19
- .plus(savedUnlockedFunds);
17
+ const streamed = new bn_js_1.default(Math.floor((currentTimestamp - savedUnlockedFundsTime) / period))
18
+ .mul(amountPerPeriod)
19
+ .add(savedUnlockedFunds);
20
20
  return streamed.lt(deposited) ? streamed : deposited;
21
21
  };
22
22
  exports.calculateUnlockedAmount = calculateUnlockedAmount;
23
23
  const isCliffCloseToDepositedAmount = (streamData) => {
24
- return streamData.cliffAmount.gte(streamData.depositedAmount.minus((0, bignumber_js_1.default)(1)));
24
+ return streamData.cliffAmount.gte(streamData.depositedAmount.sub(new bn_js_1.default(1)));
25
25
  };
26
26
  exports.isCliffCloseToDepositedAmount = isCliffCloseToDepositedAmount;
27
27
  const isPayment = (streamData) => {
@@ -3,35 +3,38 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.handleContractError = exports.calculateTotalAmountToDeposit = exports.getScaledBigNumber = exports.getNumberFromBigNumber = void 0;
7
- const bignumber_js_1 = __importDefault(require("bignumber.js"));
6
+ exports.handleContractError = exports.calculateTotalAmountToDeposit = exports.getNumberFromBN = exports.getBN = void 0;
7
+ const bn_js_1 = __importDefault(require("bn.js"));
8
8
  const types_js_1 = require("./types.js");
9
9
  const FEE_PRECISION = 4;
10
10
  const FEE_NORMALIZER = 10 ** FEE_PRECISION;
11
- const FEE_MULTIPLIER = (0, bignumber_js_1.default)(10 ** 6);
11
+ const FEE_MULTIPLIER = new bn_js_1.default(10 ** 6);
12
12
  /**
13
- * Used for token amounts conversion from their Big Number representation to number.
14
- * Get value in the highest units from BigNumber representation of the same value in the smallest units.
15
- * @param {BigNumber} value - Big Number representation of value in the smallest units.
13
+ * Used for conversion of token amounts to their Big Number representation.
14
+ * Get Big Number representation in the smallest units from the same value in the highest units.
15
+ * @param {number} value - Number of tokens you want to convert to its BN representation.
16
16
  * @param {number} decimals - Number of decimals the token has.
17
17
  */
18
- const getNumberFromBigNumber = (bigNum, decimals) => {
19
- return bigNum.div((0, bignumber_js_1.default)(10).pow(decimals)).toNumber();
18
+ const getBN = (value, decimals) => {
19
+ const decimalPart = value - Math.trunc(value);
20
+ const integerPart = new bn_js_1.default(Math.trunc(value));
21
+ const decimalE = new bn_js_1.default(decimalPart * 1e9);
22
+ const sum = integerPart.mul(new bn_js_1.default(1e9)).add(decimalE);
23
+ const resultE = sum.mul(new bn_js_1.default(10).pow(new bn_js_1.default(decimals)));
24
+ return resultE.div(new bn_js_1.default(1e9));
20
25
  };
21
- exports.getNumberFromBigNumber = getNumberFromBigNumber;
26
+ exports.getBN = getBN;
22
27
  /**
23
- * Used for conversion of token amounts to their Big Number representation.
24
- * Get Big Number representation in the smallest units from the same value in the highest units.
25
- * @param {number} value - Number of tokens you want to convert to its BigNumber representation.
28
+ * Used for token amounts conversion from their Big Number representation to number.
29
+ * Get value in the highest units from BN representation of the same value in the smallest units.
30
+ * @param {BN} value - Big Number representation of value in the smallest units.
26
31
  * @param {number} decimals - Number of decimals the token has.
27
32
  */
28
- const getScaledBigNumber = (value, decimals) => {
29
- return new bignumber_js_1.default(value).times(new bignumber_js_1.default(10).pow(decimals));
30
- };
31
- exports.getScaledBigNumber = getScaledBigNumber;
33
+ const getNumberFromBN = (value, decimals) => value.gt(new bn_js_1.default(2 ** 53 - 1)) ? value.div(new bn_js_1.default(10 ** decimals)).toNumber() : value.toNumber() / 10 ** decimals;
34
+ exports.getNumberFromBN = getNumberFromBN;
32
35
  /**
33
36
  * Calculate total amount of a Contract including all fees.
34
- * - first we convert fee floating to a BigNumber with up to 4 decimals precision
37
+ * - first we convert fee floating to a BN with up to 4 decimals precision
35
38
  * - then we reverse the fee with `FEE_MULTIPLIER` to safely multiply it by depositedAmount
36
39
  * to receive a total number and not percentage of depositedAmount
37
40
  * @param depositedAmount deposited raw tokens
@@ -39,8 +42,8 @@ exports.getScaledBigNumber = getScaledBigNumber;
39
42
  * @returns total tokens amount that Contract will retrieve from the Sender
40
43
  */
41
44
  const calculateTotalAmountToDeposit = (depositedAmount, totalFee) => {
42
- const totalFeeNormalized = (0, bignumber_js_1.default)(totalFee).times(FEE_NORMALIZER);
43
- return depositedAmount.times(totalFeeNormalized.plus(FEE_MULTIPLIER)).div(FEE_MULTIPLIER);
45
+ const totalFeeNormalized = new bn_js_1.default(totalFee * FEE_NORMALIZER);
46
+ return depositedAmount.mul(totalFeeNormalized.add(FEE_MULTIPLIER)).div(FEE_MULTIPLIER);
44
47
  };
45
48
  exports.calculateTotalAmountToDeposit = calculateTotalAmountToDeposit;
46
49
  /**
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const ethers_1 = require("ethers");
7
- const bignumber_js_1 = __importDefault(require("bignumber.js"));
7
+ const bn_js_1 = __importDefault(require("bn.js"));
8
8
  const ethereum_checksum_address_1 = require("ethereum-checksum-address");
9
9
  const BaseStreamClient_js_1 = require("../common/BaseStreamClient.js");
10
10
  const types_js_1 = require("../common/types.js");
@@ -49,7 +49,7 @@ class EvmStreamClient extends BaseStreamClient_js_1.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.times((0, bignumber_js_1.default)(constants_js_2.BASE_FEE)).div((0, bignumber_js_1.default)(1000000));
52
+ const sum = streamData.amount.mul(new bn_js_1.default(constants_js_2.BASE_FEE)).div(new bn_js_1.default(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 @@ class EvmStreamClient extends BaseStreamClient_js_1.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.plus(v.amount), (0, bignumber_js_1.default)(0))
70
- .times((0, bignumber_js_1.default)(constants_js_2.BASE_FEE))
71
- .div((0, bignumber_js_1.default)(1000000));
69
+ .reduce((acc, v) => acc.add(v.amount), new bn_js_1.default(0))
70
+ .mul(new bn_js_1.default(constants_js_2.BASE_FEE))
71
+ .div(new bn_js_1.default(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 @@ class EvmStreamClient extends BaseStreamClient_js_1.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.times((0, bignumber_js_1.default)(constants_js_2.BASE_FEE)).div((0, bignumber_js_1.default)(1000000));
123
+ const sum = topupData.amount.mul(new bn_js_1.default(constants_js_2.BASE_FEE)).div(new bn_js_1.default(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 @@ class EvmStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
185
185
  const tokenContract = new ethers_1.ethers.Contract(tokenId, ercAbi_js_1.default, this.signer);
186
186
  const address = await this.signer.getAddress();
187
187
  const allowance = await tokenContract.allowance(address, this.programId);
188
- if ((0, bignumber_js_1.default)(allowance.toString()).gte(amount)) {
188
+ if (new bn_js_1.default(allowance.toString()).gte(amount)) {
189
189
  return;
190
190
  }
191
191
  const approvalTx = await tokenContract.approve(this.programId, amount.toString());
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.EvmContract = void 0;
7
- const bignumber_js_1 = __importDefault(require("bignumber.js"));
7
+ const bn_js_1 = __importDefault(require("bn.js"));
8
8
  const contractUtils_js_1 = require("../common/contractUtils.js");
9
9
  const utils_js_1 = require("../common/utils.js");
10
10
  class EvmContract {
@@ -12,7 +12,7 @@ class EvmContract {
12
12
  this.magic = 0;
13
13
  this.version = 0;
14
14
  this.createdAt = stream.created.toNumber();
15
- this.withdrawnAmount = (0, bignumber_js_1.default)(stream.withdrawn.toString());
15
+ this.withdrawnAmount = new bn_js_1.default(stream.withdrawn.toString());
16
16
  this.canceledAt = stream.canceled_at.toNumber();
17
17
  this.end = stream.end.toNumber();
18
18
  this.lastWithdrawnAt = stream.last_withdrawn_at.toNumber();
@@ -24,20 +24,20 @@ class EvmContract {
24
24
  this.escrowTokens = "";
25
25
  this.streamflowTreasury = "";
26
26
  this.streamflowTreasuryTokens = "";
27
- this.streamflowFeeTotal = (0, bignumber_js_1.default)(stream.fees.streamflow_fee.toString());
28
- this.streamflowFeeWithdrawn = (0, bignumber_js_1.default)(stream.fees.streamflow_fee_withdrawn.toString());
27
+ this.streamflowFeeTotal = new bn_js_1.default(stream.fees.streamflow_fee.toString());
28
+ this.streamflowFeeWithdrawn = new bn_js_1.default(stream.fees.streamflow_fee_withdrawn.toString());
29
29
  this.streamflowFeePercent = stream.fees.streamflow_fee_percentage.toNumber() / 10000;
30
- this.partnerFeeTotal = (0, bignumber_js_1.default)(0);
31
- this.partnerFeeWithdrawn = (0, bignumber_js_1.default)(0);
30
+ this.partnerFeeTotal = new bn_js_1.default(0);
31
+ this.partnerFeeWithdrawn = new bn_js_1.default(0);
32
32
  this.partnerFeePercent = 0;
33
33
  this.partner = "";
34
34
  this.partnerTokens = "";
35
35
  this.start = stream.start.toNumber();
36
- this.depositedAmount = (0, bignumber_js_1.default)(stream.amount.toString());
36
+ this.depositedAmount = new bn_js_1.default(stream.amount.toString());
37
37
  this.period = stream.period.toNumber();
38
- this.amountPerPeriod = (0, bignumber_js_1.default)(stream.amount_per_period.toString());
38
+ this.amountPerPeriod = new bn_js_1.default(stream.amount_per_period.toString());
39
39
  this.cliff = stream.start.toNumber();
40
- this.cliffAmount = (0, bignumber_js_1.default)(stream.cliff_amount.toString());
40
+ this.cliffAmount = new bn_js_1.default(stream.cliff_amount.toString());
41
41
  this.cancelableBySender = stream.meta.cancelable_by_sender;
42
42
  this.cancelableByRecipient = stream.meta.cancelable_by_recipient;
43
43
  this.automaticWithdrawal = stream.meta.automatic_withdrawal;
@@ -48,9 +48,9 @@ class EvmContract {
48
48
  this.withdrawalFrequency = stream.meta.withdrawal_frequency.toNumber();
49
49
  this.closed = stream.closed;
50
50
  this.currentPauseStart = stream.current_pause_start.toNumber();
51
- this.pauseCumulative = (0, bignumber_js_1.default)(stream.pause_cumulative.toString());
51
+ this.pauseCumulative = new bn_js_1.default(stream.pause_cumulative.toString());
52
52
  this.lastRateChangeTime = stream.last_rate_change_time.toNumber();
53
- this.fundsUnlockedAtLastRateChange = (0, bignumber_js_1.default)(stream.funds_unlocked_at_last_rate_change.toString());
53
+ this.fundsUnlockedAtLastRateChange = new bn_js_1.default(stream.funds_unlocked_at_last_rate_change.toString());
54
54
  this.type = (0, contractUtils_js_1.buildStreamType)(this);
55
55
  }
56
56
  unlocked(currentTimestamp) {
@@ -60,7 +60,7 @@ class EvmContract {
60
60
  });
61
61
  }
62
62
  remaining(decimals) {
63
- return (0, utils_js_1.getNumberFromBigNumber)(this.depositedAmount.minus(this.withdrawnAmount), decimals);
63
+ return (0, utils_js_1.getNumberFromBN)(this.depositedAmount.sub(this.withdrawnAmount), decimals);
64
64
  }
65
65
  }
66
66
  exports.EvmContract = EvmContract;
@@ -28,7 +28,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  };
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
30
  exports.SolanaStreamClient = void 0;
31
- const bignumber_js_1 = __importDefault(require("bignumber.js"));
31
+ const bn_js_1 = __importDefault(require("bn.js"));
32
32
  const buffer_1 = require("buffer");
33
33
  const spl_token_1 = require("@solana/spl-token");
34
34
  const web3_js_1 = require("@solana/web3.js");
@@ -101,18 +101,18 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
101
101
  const partnerTokens = await (0, solana_1.ata)(mintPublicKey, partnerPublicKey, tokenProgramId);
102
102
  if (isNative) {
103
103
  const totalFee = await this.getTotalFee({
104
- address: partner ?? sender.publicKey.toBase58(),
104
+ address: partnerPublicKey.toString(),
105
105
  });
106
106
  const totalAmount = (0, utils_js_2.calculateTotalAmountToDeposit)(depositedAmount, totalFee);
107
107
  ixs.push(...(await (0, solana_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalAmount)));
108
108
  }
109
109
  ixs.push((0, instructions_js_1.createStreamInstruction)({
110
- start: (0, bignumber_js_1.default)(start),
110
+ start: new bn_js_1.default(start),
111
111
  depositedAmount,
112
- period: (0, bignumber_js_1.default)(period),
112
+ period: new bn_js_1.default(period),
113
113
  amountPerPeriod,
114
- cliff: (0, bignumber_js_1.default)(cliff),
115
- cliffAmount: (0, bignumber_js_1.default)(cliffAmount),
114
+ cliff: new bn_js_1.default(cliff),
115
+ cliffAmount: new bn_js_1.default(cliffAmount),
116
116
  cancelableBySender,
117
117
  cancelableByRecipient,
118
118
  automaticWithdrawal,
@@ -122,7 +122,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
122
122
  canUpdateRate: !!canUpdateRate,
123
123
  canPause: !!canPause,
124
124
  name,
125
- withdrawFrequency: (0, bignumber_js_1.default)(automaticWithdrawal ? withdrawalFrequency : period),
125
+ withdrawFrequency: new bn_js_1.default(automaticWithdrawal ? withdrawalFrequency : period),
126
126
  }, this.programId, {
127
127
  sender: sender.publicKey,
128
128
  senderTokens,
@@ -192,17 +192,17 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
192
192
  computeLimit,
193
193
  });
194
194
  if (isNative) {
195
- const totalFee = await this.getTotalFee({ address: partner ?? sender.publicKey.toBase58() });
195
+ const totalFee = await this.getTotalFee({ address: partnerPublicKey.toString() });
196
196
  const totalAmount = (0, utils_js_2.calculateTotalAmountToDeposit)(depositedAmount, totalFee);
197
197
  ixs.push(...(await (0, solana_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalAmount)));
198
198
  }
199
199
  const createInstruction = (0, instructions_js_1.createUncheckedStreamInstruction)({
200
- start: (0, bignumber_js_1.default)(start),
200
+ start: new bn_js_1.default(start),
201
201
  depositedAmount,
202
- period: (0, bignumber_js_1.default)(period),
202
+ period: new bn_js_1.default(period),
203
203
  amountPerPeriod,
204
- cliff: (0, bignumber_js_1.default)(cliff),
205
- cliffAmount: (0, bignumber_js_1.default)(cliffAmount),
204
+ cliff: new bn_js_1.default(cliff),
205
+ cliffAmount: new bn_js_1.default(cliffAmount),
206
206
  cancelableBySender,
207
207
  cancelableByRecipient,
208
208
  automaticWithdrawal,
@@ -212,7 +212,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
212
212
  canUpdateRate: !!canUpdateRate,
213
213
  canPause: !!canPause,
214
214
  name,
215
- withdrawFrequency: (0, bignumber_js_1.default)(automaticWithdrawal ? withdrawalFrequency : period),
215
+ withdrawFrequency: new bn_js_1.default(automaticWithdrawal ? withdrawalFrequency : period),
216
216
  recipient: recipientPublicKey,
217
217
  partner: partnerPublicKey,
218
218
  }, this.programId, {
@@ -277,7 +277,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
277
277
  batch.push({ tx, recipient });
278
278
  }
279
279
  if (isNative) {
280
- const totalDepositedAmount = recipients.reduce((acc, recipient) => recipient.amount.plus(acc), (0, bignumber_js_1.default)(0));
280
+ const totalDepositedAmount = recipients.reduce((acc, recipient) => recipient.amount.add(acc), new bn_js_1.default(0));
281
281
  const nativeInstructions = await (0, solana_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalDepositedAmount);
282
282
  const messageV0 = new web3_js_1.TransactionMessage({
283
283
  payerKey: sender.publicKey,
@@ -665,12 +665,12 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
665
665
  const partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_js_1.WITHDRAWOR_PUBLIC_KEY;
666
666
  const partnerTokens = await (0, solana_1.ata)(mintPublicKey, partnerPublicKey, tokenProgramId);
667
667
  ixs.push((0, instructions_js_1.createStreamInstruction)({
668
- start: (0, bignumber_js_1.default)(start),
668
+ start: new bn_js_1.default(start),
669
669
  depositedAmount: recipient.amount,
670
- period: (0, bignumber_js_1.default)(period),
670
+ period: new bn_js_1.default(period),
671
671
  amountPerPeriod: recipient.amountPerPeriod,
672
- cliff: (0, bignumber_js_1.default)(cliff),
673
- cliffAmount: (0, bignumber_js_1.default)(recipient.cliffAmount),
672
+ cliff: new bn_js_1.default(cliff),
673
+ cliffAmount: new bn_js_1.default(recipient.cliffAmount),
674
674
  cancelableBySender,
675
675
  cancelableByRecipient,
676
676
  automaticWithdrawal,
@@ -680,7 +680,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
680
680
  canUpdateRate: !!canUpdateRate,
681
681
  canPause: !!canPause,
682
682
  name: recipient.name,
683
- withdrawFrequency: (0, bignumber_js_1.default)(automaticWithdrawal ? withdrawalFrequency : period),
683
+ withdrawFrequency: new bn_js_1.default(automaticWithdrawal ? withdrawalFrequency : period),
684
684
  }, this.programId, {
685
685
  sender: sender.publicKey,
686
686
  senderTokens,
@@ -28,7 +28,6 @@ const buffer_1 = require("buffer");
28
28
  const web3_js_1 = require("@solana/web3.js");
29
29
  const node_crypto_1 = require("node:crypto");
30
30
  const Layout = __importStar(require("./layout.js"));
31
- const utils_js_1 = require("./utils.js");
32
31
  const hasher = () => (0, node_crypto_1.createHash)("sha256");
33
32
  const sha256 = {
34
33
  digest: (data) => new Uint8Array(hasher().update(data).digest()),
@@ -70,12 +69,12 @@ const createStreamInstruction = (data, programId, accounts) => {
70
69
  const encodedUIntArray = new TextEncoder().encode(data.name);
71
70
  const streamNameBuffer = buffer_1.Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
72
71
  const decodedData = {
73
- start_time: (0, utils_js_1.toBuffer)(data.start),
74
- net_amount_deposited: (0, utils_js_1.toBuffer)(data.depositedAmount),
75
- period: (0, utils_js_1.toBuffer)(data.period),
76
- amount_per_period: (0, utils_js_1.toBuffer)(data.amountPerPeriod),
77
- cliff: (0, utils_js_1.toBuffer)(data.cliff),
78
- cliff_amount: (0, utils_js_1.toBuffer)(data.cliffAmount),
72
+ start_time: data.start.toArrayLike(buffer_1.Buffer, "le", 8),
73
+ net_amount_deposited: data.depositedAmount.toArrayLike(buffer_1.Buffer, "le", 8),
74
+ period: data.period.toArrayLike(buffer_1.Buffer, "le", 8),
75
+ amount_per_period: data.amountPerPeriod.toArrayLike(buffer_1.Buffer, "le", 8),
76
+ cliff: data.cliff.toArrayLike(buffer_1.Buffer, "le", 8),
77
+ cliff_amount: data.cliffAmount.toArrayLike(buffer_1.Buffer, "le", 8),
79
78
  cancelable_by_sender: Number(data.cancelableBySender),
80
79
  cancelable_by_recipient: Number(data.cancelableByRecipient),
81
80
  automatic_withdrawal: Number(data.automaticWithdrawal),
@@ -87,7 +86,7 @@ const createStreamInstruction = (data, programId, accounts) => {
87
86
  _can_update_rate_discriminator: 1,
88
87
  pausable: Number(data.canPause),
89
88
  stream_name: streamNameBuffer,
90
- withdraw_frequency: (0, utils_js_1.toBuffer)(data.withdrawFrequency),
89
+ withdraw_frequency: data.withdrawFrequency.toArrayLike(buffer_1.Buffer, "le", 8),
91
90
  };
92
91
  const encodeLength = Layout.createStreamLayout.encode(decodedData, bufferData);
93
92
  bufferData = bufferData.slice(0, encodeLength);
@@ -124,12 +123,12 @@ const createUncheckedStreamInstruction = (data, programId, accounts) => {
124
123
  const encodedUIntArray = new TextEncoder().encode(data.name);
125
124
  const streamNameBuffer = buffer_1.Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
126
125
  const decodedData = {
127
- start_time: (0, utils_js_1.toBuffer)(data.start),
128
- net_amount_deposited: (0, utils_js_1.toBuffer)(data.depositedAmount),
129
- period: (0, utils_js_1.toBuffer)(data.period),
130
- amount_per_period: (0, utils_js_1.toBuffer)(data.amountPerPeriod),
131
- cliff: (0, utils_js_1.toBuffer)(data.cliff),
132
- cliff_amount: (0, utils_js_1.toBuffer)(data.cliffAmount),
126
+ start_time: data.start.toArrayLike(buffer_1.Buffer, "le", 8),
127
+ net_amount_deposited: data.depositedAmount.toArrayLike(buffer_1.Buffer, "le", 8),
128
+ period: data.period.toArrayLike(buffer_1.Buffer, "le", 8),
129
+ amount_per_period: data.amountPerPeriod.toArrayLike(buffer_1.Buffer, "le", 8),
130
+ cliff: data.cliff.toArrayLike(buffer_1.Buffer, "le", 8),
131
+ cliff_amount: data.cliffAmount.toArrayLike(buffer_1.Buffer, "le", 8),
133
132
  cancelable_by_sender: Number(data.cancelableBySender),
134
133
  cancelable_by_recipient: Number(data.cancelableByRecipient),
135
134
  automatic_withdrawal: Number(data.automaticWithdrawal),
@@ -137,7 +136,7 @@ const createUncheckedStreamInstruction = (data, programId, accounts) => {
137
136
  transferable_by_recipient: Number(data.transferableByRecipient),
138
137
  can_topup: Number(data.canTopup),
139
138
  stream_name: streamNameBuffer,
140
- withdraw_frequency: (0, utils_js_1.toBuffer)(data.withdrawFrequency),
139
+ withdraw_frequency: data.withdrawFrequency.toArrayLike(buffer_1.Buffer, "le", 8),
141
140
  recipient: data.recipient.toBuffer(),
142
141
  partner: data.partner.toBuffer(),
143
142
  pausable: Number(data.canPause),
@@ -175,7 +174,7 @@ const withdrawStreamInstruction = (amount, programId, { authority, recipient, re
175
174
  { pubkey: tokenProgram, isSigner: false, isWritable: false },
176
175
  ];
177
176
  let data = buffer_1.Buffer.alloc(Layout.withdrawStreamLayout.span);
178
- const decodedData = { amount: (0, utils_js_1.toBuffer)(amount) };
177
+ const decodedData = { amount: amount.toArrayLike(buffer_1.Buffer, "le", 8) };
179
178
  const encodeLength = Layout.withdrawStreamLayout.encode(decodedData, data);
180
179
  data = data.slice(0, encodeLength);
181
180
  data = buffer_1.Buffer.concat([buffer_1.Buffer.from(sha256.digest("global:withdraw")).slice(0, 8), data, buffer_1.Buffer.alloc(10)]);
@@ -196,8 +195,8 @@ const updateStreamInstruction = (params, programId, { authority, metadata, withd
196
195
  let data = buffer_1.Buffer.alloc(100);
197
196
  const decodedData = {
198
197
  enable_automatic_withdrawal: Number(params.enableAutomaticWithdrawal),
199
- withdraw_frequency: params.withdrawFrequency ? (0, utils_js_1.toBuffer)(params.withdrawFrequency) : undefined,
200
- amount_per_period: params.amountPerPeriod ? (0, utils_js_1.toBuffer)(params.amountPerPeriod) : undefined,
198
+ withdraw_frequency: params.withdrawFrequency ? params.withdrawFrequency.toArrayLike(buffer_1.Buffer, "le", 8) : undefined,
199
+ amount_per_period: params.amountPerPeriod ? params.amountPerPeriod.toArrayLike(buffer_1.Buffer, "le", 8) : undefined,
201
200
  };
202
201
  const encodeLength = Layout.encodeUpdateStream(decodedData, data);
203
202
  data = data.slice(0, encodeLength);
@@ -277,7 +276,7 @@ const topupStreamInstruction = (amount, programId, { sender, senderTokens, metad
277
276
  { pubkey: systemProgram, isSigner: false, isWritable: false },
278
277
  ];
279
278
  let data = buffer_1.Buffer.alloc(Layout.topupStreamLayout.span);
280
- const decodedData = { amount: (0, utils_js_1.toBuffer)(amount) };
279
+ const decodedData = { amount: amount.toArrayLike(buffer_1.Buffer, "le", 8) };
281
280
  const encodeLength = Layout.topupStreamLayout.encode(decodedData, data);
282
281
  data = data.slice(0, encodeLength);
283
282
  data = buffer_1.Buffer.concat([buffer_1.Buffer.from(sha256.digest("global:topup")).slice(0, 8), data, buffer_1.Buffer.alloc(10)]);
@@ -56,7 +56,7 @@ class Contract {
56
56
  });
57
57
  }
58
58
  remaining(decimals) {
59
- return (0, utils_js_1.getNumberFromBigNumber)(this.depositedAmount.minus(this.withdrawnAmount), decimals);
59
+ return (0, utils_js_1.getNumberFromBN)(this.depositedAmount.sub(this.withdrawnAmount), decimals);
60
60
  }
61
61
  }
62
62
  exports.Contract = Contract;