@streamflow/stream 7.0.0-alpha.8 → 7.0.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.
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 +303 -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 +22 -16
  41. package/dist/esm/solana/StreamClient.js +306 -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
package/README.md CHANGED
@@ -22,7 +22,8 @@ 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 { BN } from "bn.js";
26
+ import { GenericStreamClient, getBN, getNumberFromBN } from "@streamflow/stream";
26
27
  ```
27
28
 
28
29
  _Check the SDK for other types and utility functions._
@@ -124,11 +125,11 @@ const createStreamParams: Types.ICreateStreamData = {
124
125
  recipient: "4ih00075bKjVg000000tLdk4w42NyG3Mv0000dc0M00", // Recipient address.
125
126
  tokenId: "DNw99999M7e24g99999999WJirKeZ5fQc6KY999999gK", // Token mint address.
126
127
  start: 1643363040, // Timestamp (in seconds) when the stream/token vesting starts.
127
- amount: getScaledBigNumber(100, 9), // depositing 100 tokens with 9 decimals mint.
128
+ amount: getBN(100, 9), // depositing 100 tokens with 9 decimals mint.
128
129
  period: 1, // Time step (period) in seconds per which the unlocking occurs.
129
130
  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.
131
+ cliffAmount: new BN(10), // Amount unlocked at the "cliff" timestamp.
132
+ amountPerPeriod: getBN(5, 9), // Release rate: how many tokens are unlocked per each period.
132
133
  name: "Transfer to Jane Doe.", // The stream name or subject.
133
134
  canTopup: false, // Whether additional tokens can be deposited after creation, setting to FALSE will effectively create a vesting contract.
134
135
  canUpdateRate: false, // settings to TRUE allows sender to update amountPerPeriod
@@ -169,10 +170,10 @@ try {
169
170
  const recipients = [
170
171
  {
171
172
  recipient: "4ih00075bKjVg000000tLdk4w42NyG3Mv0000dc0M00", // Solana recipient address.
172
- amount: getScaledBgNumber(100, 9), // depositing 100 tokens with 9 decimals mint.
173
+ amount: getBN(100, 9), // depositing 100 tokens with 9 decimals mint.
173
174
  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
175
+ cliffAmount: getBN(10, 9), // amount released on cliff for this recipient
176
+ amountPerPeriod: getBN(1, 9), //amount released every specified period epoch
176
177
  },
177
178
  ];
178
179
  const createMultiStreamsParams: ICreateMultipleStreamData = {
@@ -234,7 +235,7 @@ interface ICreateResult {
234
235
  ```javascript
235
236
  const withdrawStreamParams: Types.IWithdrawData = {
236
237
  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.
238
+ amount: getBN(100, 9), // Requested amount to withdraw. If stream is completed, the whole amount will be withdrawn.
238
239
  };
239
240
 
240
241
  const solanaParams = {
@@ -265,7 +266,7 @@ try {
265
266
  ```javascript
266
267
  const topupStreamParams: ITopUpData = {
267
268
  id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier (address) of a stream to be topped up.
268
- amount: getScaledBgNumber(100, 9), // Specified amount to topup (increases deposited amount).
269
+ amount: getBN(100, 9), // Specified amount to topup (increases deposited amount).
269
270
  };
270
271
 
271
272
  const solanaParams = {
@@ -360,7 +361,7 @@ const updateStreamParams: IUpdateData = {
360
361
  id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to update.
361
362
  enableAutomaticWithdrawal: true, // [optional], allows to enable AW if it wasn't, disable is not possible
362
363
  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
364
+ amountPerPeriod: getBN(10, 9), // [optional], allows to update release amount effective on next unlock
364
365
  }
365
366
 
366
367
  const solanaParams = {
@@ -405,8 +406,8 @@ const stream = await client.getOne({
405
406
  id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA",
406
407
  });
407
408
 
408
- const unlocked = stream.unlocked(tsInSeconds); // bignumber amount unlocked at the tsInSeconds
409
- console.log(getNumberFromBigNumber(unlocked, 9));
409
+ const unlocked = stream.unlocked(tsInSeconds); // BN amount unlocked at the tsInSeconds
410
+ console.log(getNumberFromBN(unlocked, 9));
410
411
  ```
411
412
 
412
413
  - Note: unlocked amount is determined based on configuration set on creation, no dynamic data is involved.
@@ -417,8 +418,8 @@ console.log(getNumberFromBigNumber(unlocked, 9));
417
418
  const stream = await client.getOne({
418
419
  id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA",
419
420
  });
420
- const withdrawn = stream.withdrawnAmount; // big number amount withdrawn already
421
- console.log(getNumberFromBigNumber(wihtdrawn, 9));
421
+ const withdrawn = stream.withdrawnAmount; // bn amount withdrawn already
422
+ console.log(getNumberFromBN(wihtdrawn, 9));
422
423
  const remaining = stream.remaining(9); // amount of remaining funds
423
424
  console.log(remaining);
424
425
  ```
@@ -489,10 +490,14 @@ Streamflow protocol program IDs
489
490
  | Testnet | 0xf1916c119a6c917d4b36f96ffc0443930745789f3126a716e05a62223c48993a |
490
491
  | Mainnet | 0xa283fd6b45f1103176e7ae27e870c89df7c8783b15345e2b13faa81ec25c4fa6 |
491
492
 
492
- **All BigNumber amounts are denominated in their smallest units.**
493
+ **All BN amounts are denominated in their smallest units.**
493
494
 
494
495
  E.g, if the amount is 1 SOL than this amount in lamports is `1000 \* 10^9 = 1_000_000_000.`
495
496
 
496
- And `BigNumber(1_000_000_000)` is used.
497
+ And `new BN(1_000_000_000)` is used.
497
498
 
498
- Use `getScaledBigNumber` and `getNumberFromBigNumber` utility functions for conversions between `BigNumber` and `Number` types.
499
+ Use `getBN` and `getNumberFromBN` utility functions for conversions between `BN` and `Number` types.
500
+
501
+ `getBN(1, 9)` is equal to `new BN(1_000_000_000)`
502
+
503
+ `getNumberFromBN(new BN(1_000_000_000), 9)` will return 1
@@ -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;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeAptosAddress = exports.extractAptosErrorCode = void 0;
3
+ exports.extractAptosErrorCode = extractAptosErrorCode;
4
+ exports.normalizeAptosAddress = normalizeAptosAddress;
4
5
  const constants_js_1 = require("./constants.js");
5
6
  function extractAptosErrorCode(errorText) {
6
7
  const match = constants_js_1.APTOS_ERROR_MATCH_REGEX.exec(errorText);
@@ -9,7 +10,6 @@ function extractAptosErrorCode(errorText) {
9
10
  }
10
11
  return match[2];
11
12
  }
12
- exports.extractAptosErrorCode = extractAptosErrorCode;
13
13
  function isAddressSpecial(address) {
14
14
  if (address.length === 3) {
15
15
  return true;
@@ -32,4 +32,3 @@ function normalizeAptosAddress(address) {
32
32
  const missingZeros = 66 - length;
33
33
  return address.slice(0, 2) + "0".repeat(missingZeros) + address.slice(2);
34
34
  }
35
- exports.normalizeAptosAddress = normalizeAptosAddress;
@@ -3,7 +3,8 @@ 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.WITHDRAW_AVAILABLE_AMOUNT = exports.BASE_FEE = void 0;
7
- const bignumber_js_1 = __importDefault(require("bignumber.js"));
6
+ exports.WITHDRAW_AVAILABLE_AMOUNT = exports.BASE_FEE = exports.MAX_SAFE_UNIX_TIME_VALUE = void 0;
7
+ const bn_js_1 = __importDefault(require("bn.js"));
8
+ exports.MAX_SAFE_UNIX_TIME_VALUE = 8640000000000;
8
9
  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
10
+ exports.WITHDRAW_AVAILABLE_AMOUNT = new bn_js_1.default("18446744073709551615"); // Magical number to withdraw all available amount from a Contract
@@ -3,25 +3,26 @@ 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.buildStreamType = exports.isTokenLock = exports.isVesting = exports.isPayment = exports.isCliffCloseToDepositedAmount = exports.calculateUnlockedAmount = void 0;
7
- const bignumber_js_1 = __importDefault(require("bignumber.js"));
6
+ exports.decodeEndTime = exports.buildStreamType = exports.isTokenLock = exports.isCreateAlignedStreamData = exports.isAligned = exports.isVesting = exports.isPayment = exports.isCliffCloseToDepositedAmount = exports.calculateUnlockedAmount = void 0;
7
+ const bn_js_1 = __importDefault(require("bn.js"));
8
8
  const types_js_1 = require("./types.js");
9
+ const constants_js_1 = require("./constants.js");
9
10
  const calculateUnlockedAmount = ({ depositedAmount, cliff, cliffAmount, end, currentTimestamp, lastRateChangeTime, period, amountPerPeriod, fundsUnlockedAtLastRateChange, }) => {
10
11
  const deposited = depositedAmount;
11
12
  if (currentTimestamp < cliff)
12
- return (0, bignumber_js_1.default)(0);
13
+ return new bn_js_1.default(0);
13
14
  if (currentTimestamp > end)
14
15
  return deposited;
15
16
  const savedUnlockedFunds = lastRateChangeTime === 0 ? cliffAmount : fundsUnlockedAtLastRateChange;
16
17
  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);
18
+ const streamed = new bn_js_1.default(Math.floor((currentTimestamp - savedUnlockedFundsTime) / period))
19
+ .mul(amountPerPeriod)
20
+ .add(savedUnlockedFunds);
20
21
  return streamed.lt(deposited) ? streamed : deposited;
21
22
  };
22
23
  exports.calculateUnlockedAmount = calculateUnlockedAmount;
23
24
  const isCliffCloseToDepositedAmount = (streamData) => {
24
- return streamData.cliffAmount.gte(streamData.depositedAmount.minus((0, bignumber_js_1.default)(1)));
25
+ return streamData.cliffAmount.gte(streamData.depositedAmount.sub(new bn_js_1.default(1)));
25
26
  };
26
27
  exports.isCliffCloseToDepositedAmount = isCliffCloseToDepositedAmount;
27
28
  const isPayment = (streamData) => {
@@ -32,6 +33,14 @@ const isVesting = (streamData) => {
32
33
  return !streamData.canTopup && !(0, exports.isCliffCloseToDepositedAmount)(streamData);
33
34
  };
34
35
  exports.isVesting = isVesting;
36
+ const isAligned = (stream) => {
37
+ return "minPrice" in stream && "maxPrice" in stream && "minPercentage" in stream && "maxPercentage" in stream;
38
+ };
39
+ exports.isAligned = isAligned;
40
+ const isCreateAlignedStreamData = (obj) => {
41
+ return "minPrice" in obj && "maxPrice" in obj && "minPercentage" in obj && "maxPercentage" in obj;
42
+ };
43
+ exports.isCreateAlignedStreamData = isCreateAlignedStreamData;
35
44
  const isTokenLock = (streamData) => {
36
45
  return (!streamData.canTopup &&
37
46
  !streamData.automaticWithdrawal &&
@@ -52,3 +61,10 @@ const buildStreamType = (streamData) => {
52
61
  return types_js_1.StreamType.Payment;
53
62
  };
54
63
  exports.buildStreamType = buildStreamType;
64
+ const decodeEndTime = (endTime) => {
65
+ if (endTime.gt(new bn_js_1.default(constants_js_1.MAX_SAFE_UNIX_TIME_VALUE))) {
66
+ return constants_js_1.MAX_SAFE_UNIX_TIME_VALUE;
67
+ }
68
+ return endTime.toNumber();
69
+ };
70
+ exports.decodeEndTime = decodeEndTime;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SolanaContractErrorCode = exports.ContractErrorCode = exports.StreamType = exports.StreamDirection = exports.ContractError = exports.ICluster = exports.IChain = void 0;
3
+ exports.SolanaAlignedProxyErrorCode = exports.SolanaContractErrorCode = exports.ContractErrorCode = exports.StreamType = exports.StreamDirection = exports.ContractError = exports.ICluster = exports.IChain = void 0;
4
4
  var common_1 = require("@streamflow/common");
5
5
  Object.defineProperty(exports, "IChain", { enumerable: true, get: function () { return common_1.IChain; } });
6
6
  Object.defineProperty(exports, "ICluster", { enumerable: true, get: function () { return common_1.ICluster; } });
@@ -110,3 +110,32 @@ var SolanaContractErrorCode;
110
110
  /** Meta account is not rent exempt */
111
111
  SolanaContractErrorCode["MetadataNotRentExempt"] = "MetadataNotRentExempt";
112
112
  })(SolanaContractErrorCode || (exports.SolanaContractErrorCode = SolanaContractErrorCode = {}));
113
+ var SolanaAlignedProxyErrorCode;
114
+ (function (SolanaAlignedProxyErrorCode) {
115
+ /** Authority does not have permission for this action */
116
+ SolanaAlignedProxyErrorCode["Unauthorized"] = "Unauthorized";
117
+ /** Arithmetic error */
118
+ SolanaAlignedProxyErrorCode["ArithmeticError"] = "ArithmeticError";
119
+ /** Mint has unsupported Token Extensions */
120
+ SolanaAlignedProxyErrorCode["UnsupportedTokenExtensions"] = "UnsupportedTokenExtensions";
121
+ /** Provided period is too short, should be equal or more than 30 seconds */
122
+ SolanaAlignedProxyErrorCode["PeriodTooShort"] = "PeriodTooShort";
123
+ /** Provided percentage tick size is invalid */
124
+ SolanaAlignedProxyErrorCode["InvalidTickSize"] = "InvalidTickSize";
125
+ /** Provided percentage bounds are invalid */
126
+ SolanaAlignedProxyErrorCode["InvalidPercentageBoundaries"] = "InvalidPercentageBoundaries";
127
+ /** Provided price bounds are invalid */
128
+ SolanaAlignedProxyErrorCode["InvalidPriceBoundaries"] = "InvalidPriceBoundaries";
129
+ /** Unsupported price oracle */
130
+ SolanaAlignedProxyErrorCode["UnsupportedOracle"] = "UnsupportedOracle";
131
+ /** Invalid oracle account */
132
+ SolanaAlignedProxyErrorCode["InvalidOracleAccount"] = "InvalidOracleAccount";
133
+ /** Invalid oracle price */
134
+ SolanaAlignedProxyErrorCode["InvalidOraclePrice"] = "InvalidOraclePrice";
135
+ /** Invalid Stream Metadata */
136
+ SolanaAlignedProxyErrorCode["InvalidStreamMetadata"] = "InvalidStreamMetadata";
137
+ /** Release amount has already been updated in this period */
138
+ SolanaAlignedProxyErrorCode["AmountAlreadyUpdated"] = "AmountAlreadyUpdated";
139
+ /** All funds are already unlocked */
140
+ SolanaAlignedProxyErrorCode["AllFundsUnlocked"] = "AllFundsUnlocked";
141
+ })(SolanaAlignedProxyErrorCode || (exports.SolanaAlignedProxyErrorCode = SolanaAlignedProxyErrorCode = {}));
@@ -3,35 +3,39 @@ 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.calculateTotalAmountToDeposit = exports.getNumberFromBN = exports.getBN = void 0;
7
+ exports.handleContractError = handleContractError;
8
+ const bn_js_1 = __importDefault(require("bn.js"));
8
9
  const types_js_1 = require("./types.js");
9
10
  const FEE_PRECISION = 4;
10
11
  const FEE_NORMALIZER = 10 ** FEE_PRECISION;
11
- const FEE_MULTIPLIER = (0, bignumber_js_1.default)(10 ** 6);
12
+ const FEE_MULTIPLIER = new bn_js_1.default(10 ** 6);
12
13
  /**
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.
14
+ * Used for conversion of token amounts to their Big Number representation.
15
+ * Get Big Number representation in the smallest units from the same value in the highest units.
16
+ * @param {number} value - Number of tokens you want to convert to its BN representation.
16
17
  * @param {number} decimals - Number of decimals the token has.
17
18
  */
18
- const getNumberFromBigNumber = (bigNum, decimals) => {
19
- return bigNum.div((0, bignumber_js_1.default)(10).pow(decimals)).toNumber();
19
+ const getBN = (value, decimals) => {
20
+ const decimalPart = value - Math.trunc(value);
21
+ const integerPart = new bn_js_1.default(Math.trunc(value));
22
+ const decimalE = new bn_js_1.default(decimalPart * 1e9);
23
+ const sum = integerPart.mul(new bn_js_1.default(1e9)).add(decimalE);
24
+ const resultE = sum.mul(new bn_js_1.default(10).pow(new bn_js_1.default(decimals)));
25
+ return resultE.div(new bn_js_1.default(1e9));
20
26
  };
21
- exports.getNumberFromBigNumber = getNumberFromBigNumber;
27
+ exports.getBN = getBN;
22
28
  /**
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.
29
+ * Used for token amounts conversion from their Big Number representation to number.
30
+ * Get value in the highest units from BN representation of the same value in the smallest units.
31
+ * @param {BN} value - Big Number representation of value in the smallest units.
26
32
  * @param {number} decimals - Number of decimals the token has.
27
33
  */
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;
34
+ 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;
35
+ exports.getNumberFromBN = getNumberFromBN;
32
36
  /**
33
37
  * Calculate total amount of a Contract including all fees.
34
- * - first we convert fee floating to a BigNumber with up to 4 decimals precision
38
+ * - first we convert fee floating to a BN with up to 4 decimals precision
35
39
  * - then we reverse the fee with `FEE_MULTIPLIER` to safely multiply it by depositedAmount
36
40
  * to receive a total number and not percentage of depositedAmount
37
41
  * @param depositedAmount deposited raw tokens
@@ -39,8 +43,8 @@ exports.getScaledBigNumber = getScaledBigNumber;
39
43
  * @returns total tokens amount that Contract will retrieve from the Sender
40
44
  */
41
45
  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);
46
+ const totalFeeNormalized = new bn_js_1.default(totalFee * FEE_NORMALIZER);
47
+ return depositedAmount.mul(totalFeeNormalized.add(FEE_MULTIPLIER)).div(FEE_MULTIPLIER);
44
48
  };
45
49
  exports.calculateTotalAmountToDeposit = calculateTotalAmountToDeposit;
46
50
  /**
@@ -63,4 +67,3 @@ async function handleContractError(func, callback) {
63
67
  throw err;
64
68
  }
65
69
  }
66
- exports.handleContractError = handleContractError;
@@ -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;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractEvmErrorCode = void 0;
3
+ exports.extractEvmErrorCode = extractEvmErrorCode;
4
4
  const constants_js_1 = require("./constants.js");
5
5
  function extractEvmErrorCode(errorText) {
6
6
  const match = constants_js_1.EVM_ERROR_MATCH_REGEX.exec(errorText);
@@ -9,4 +9,3 @@ function extractEvmErrorCode(errorText) {
9
9
  }
10
10
  return match[1];
11
11
  }
12
- exports.extractEvmErrorCode = extractEvmErrorCode;