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

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 +17 -18
  2. package/dist/cjs/__tests__/aptos/streamClient.spec.js +4 -4
  3. package/dist/cjs/aptos/types.js +18 -18
  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 +18 -23
  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 +17 -17
  10. package/dist/cjs/solana/instructions.js +19 -18
  11. package/dist/cjs/solana/types.js +1 -1
  12. package/dist/cjs/solana/utils.js +38 -27
  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 +16 -19
  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 +37 -37
  28. package/dist/esm/evm/types.js +13 -13
  29. package/dist/esm/solana/StreamClient.js +17 -17
  30. package/dist/esm/solana/instructions.d.ts +17 -17
  31. package/dist/esm/solana/instructions.js +19 -18
  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 +2 -0
  35. package/dist/esm/solana/utils.js +32 -26
  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 +5 -6
@@ -65,7 +65,7 @@ var Contract = /** @class */ (function () {
65
65
  return (0, contractUtils_js_1.calculateUnlockedAmount)(__assign(__assign({}, this), { currentTimestamp: currentTimestamp }));
66
66
  };
67
67
  Contract.prototype.remaining = function (decimals) {
68
- return (0, utils_js_1.getNumberFromBN)(this.depositedAmount.sub(this.withdrawnAmount), decimals);
68
+ return (0, utils_js_1.getNumberFromBigNumber)(this.depositedAmount.minus(this.withdrawnAmount), decimals);
69
69
  };
70
70
  return Contract;
71
71
  }());
@@ -61,24 +61,35 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
61
61
  return (mod && mod.__esModule) ? mod : { "default": mod };
62
62
  };
63
63
  Object.defineProperty(exports, "__esModule", { value: true });
64
- exports.extractSolanaErrorCode = exports.sendAndConfirmStreamRawTransaction = exports.signAllTransactionWithRecipients = exports.decodeStream = void 0;
64
+ exports.extractSolanaErrorCode = exports.sendAndConfirmStreamRawTransaction = exports.signAllTransactionWithRecipients = exports.decodeStream = exports.toBuffer = void 0;
65
65
  var web3_js_1 = require("@solana/web3.js");
66
66
  var solana_1 = require("@streamflow/common/solana");
67
- var bn_js_1 = __importDefault(require("bn.js"));
67
+ var bignumber_js_1 = __importDefault(require("bignumber.js"));
68
68
  var layout_js_1 = require("./layout.js");
69
69
  var constants_js_1 = require("./constants.js");
70
70
  var decoder = new TextDecoder("utf-8");
71
- var LE = "le"; //little endian
71
+ var toUInt64String = function (uintArr) {
72
+ return new DataView(uintArr.buffer, uintArr.byteOffset, uintArr.byteLength).getBigUint64(0, true).toString();
73
+ };
74
+ var toUInt8 = function (uintArr) {
75
+ return new DataView(uintArr.buffer, uintArr.byteOffset, uintArr.byteLength).getUint8(0);
76
+ };
77
+ var toBuffer = function (bigNumber) {
78
+ var dv = new DataView(new ArrayBuffer(8), 0);
79
+ dv.setBigUint64(0, BigInt(bigNumber.integerValue().toString()), true);
80
+ return Buffer.from(dv.buffer);
81
+ };
82
+ exports.toBuffer = toBuffer;
72
83
  var decodeStream = function (buf) {
73
84
  var raw = layout_js_1.streamLayout.decode(buf);
74
85
  return {
75
- magic: new bn_js_1.default(raw.magic, LE),
76
- version: new bn_js_1.default(raw.version, LE),
77
- createdAt: new bn_js_1.default(raw.created_at, LE),
78
- withdrawnAmount: new bn_js_1.default(raw.withdrawn_amount, LE),
79
- canceledAt: new bn_js_1.default(raw.canceled_at, LE),
80
- end: new bn_js_1.default(raw.end_time, LE),
81
- lastWithdrawnAt: new bn_js_1.default(raw.last_withdrawn_at, LE),
86
+ magic: (0, bignumber_js_1.default)(toUInt64String(raw.magic)),
87
+ version: (0, bignumber_js_1.default)(toUInt8(raw.version)),
88
+ createdAt: (0, bignumber_js_1.default)(toUInt64String(raw.created_at)),
89
+ withdrawnAmount: (0, bignumber_js_1.default)(toUInt64String(raw.withdrawn_amount)),
90
+ canceledAt: (0, bignumber_js_1.default)(toUInt64String(raw.canceled_at)),
91
+ end: (0, bignumber_js_1.default)(toUInt64String(raw.end_time)),
92
+ lastWithdrawnAt: (0, bignumber_js_1.default)(toUInt64String(raw.last_withdrawn_at)),
82
93
  sender: new web3_js_1.PublicKey(raw.sender),
83
94
  senderTokens: new web3_js_1.PublicKey(raw.sender_tokens),
84
95
  recipient: new web3_js_1.PublicKey(raw.recipient),
@@ -87,20 +98,20 @@ var decodeStream = function (buf) {
87
98
  escrowTokens: new web3_js_1.PublicKey(raw.escrow_tokens),
88
99
  streamflowTreasury: new web3_js_1.PublicKey(raw.streamflow_treasury),
89
100
  streamflowTreasuryTokens: new web3_js_1.PublicKey(raw.streamflow_treasury_tokens),
90
- streamflowFeeTotal: new bn_js_1.default(raw.streamflow_fee_total, LE),
91
- streamflowFeeWithdrawn: new bn_js_1.default(raw.streamflow_fee_withdrawn, LE),
92
- streamflowFeePercent: new bn_js_1.default(raw.streamflow_fee_percent, LE),
93
- partnerFeeTotal: new bn_js_1.default(raw.partner_fee_total, LE),
94
- partnerFeeWithdrawn: new bn_js_1.default(raw.partner_fee_withdrawn, LE),
95
- partnerFeePercent: new bn_js_1.default(raw.partner_fee_percent, LE),
101
+ streamflowFeeTotal: (0, bignumber_js_1.default)(toUInt64String(raw.streamflow_fee_total)),
102
+ streamflowFeeWithdrawn: (0, bignumber_js_1.default)(toUInt64String(raw.streamflow_fee_withdrawn)),
103
+ streamflowFeePercent: (0, bignumber_js_1.default)(raw.streamflow_fee_percent),
104
+ partnerFeeTotal: (0, bignumber_js_1.default)(toUInt64String(raw.partner_fee_total)),
105
+ partnerFeeWithdrawn: (0, bignumber_js_1.default)(toUInt64String(raw.partner_fee_withdrawn)),
106
+ partnerFeePercent: (0, bignumber_js_1.default)(raw.partner_fee_percent),
96
107
  partner: new web3_js_1.PublicKey(raw.partner),
97
108
  partnerTokens: new web3_js_1.PublicKey(raw.partner_tokens),
98
- start: new bn_js_1.default(raw.start_time, LE),
99
- depositedAmount: new bn_js_1.default(raw.net_amount_deposited, LE),
100
- period: new bn_js_1.default(raw.period, LE),
101
- amountPerPeriod: new bn_js_1.default(raw.amount_per_period, LE),
102
- cliff: new bn_js_1.default(raw.cliff, LE),
103
- cliffAmount: new bn_js_1.default(raw.cliff_amount, LE),
109
+ start: (0, bignumber_js_1.default)(toUInt64String(raw.start_time)),
110
+ depositedAmount: (0, bignumber_js_1.default)(toUInt64String(raw.net_amount_deposited)),
111
+ period: (0, bignumber_js_1.default)(toUInt64String(raw.period)),
112
+ amountPerPeriod: (0, bignumber_js_1.default)(toUInt64String(raw.amount_per_period)),
113
+ cliff: (0, bignumber_js_1.default)(toUInt64String(raw.cliff)),
114
+ cliffAmount: (0, bignumber_js_1.default)(toUInt64String(raw.cliff_amount)),
104
115
  cancelableBySender: Boolean(raw.cancelable_by_sender),
105
116
  cancelableByRecipient: Boolean(raw.cancelable_by_recipient),
106
117
  automaticWithdrawal: Boolean(raw.automatic_withdrawal),
@@ -108,12 +119,12 @@ var decodeStream = function (buf) {
108
119
  transferableByRecipient: Boolean(raw.transferable_by_recipient),
109
120
  canTopup: Boolean(raw.can_topup),
110
121
  name: decoder.decode(raw.stream_name),
111
- withdrawFrequency: new bn_js_1.default(raw.withdraw_frequency, LE),
122
+ withdrawFrequency: (0, bignumber_js_1.default)(toUInt64String(raw.withdraw_frequency)),
112
123
  closed: Boolean(raw.closed),
113
- currentPauseStart: new bn_js_1.default(raw.current_pause_start, LE),
114
- pauseCumulative: new bn_js_1.default(raw.pause_cumulative, LE),
115
- lastRateChangeTime: new bn_js_1.default(raw.last_rate_change_time, LE),
116
- fundsUnlockedAtLastRateChange: new bn_js_1.default(raw.funds_unlocked_at_last_rate_change, LE),
124
+ currentPauseStart: (0, bignumber_js_1.default)(toUInt64String(raw.current_pause_start)),
125
+ pauseCumulative: (0, bignumber_js_1.default)(toUInt64String(raw.pause_cumulative)),
126
+ lastRateChangeTime: (0, bignumber_js_1.default)(toUInt64String(raw.last_rate_change_time)),
127
+ fundsUnlockedAtLastRateChange: (0, bignumber_js_1.default)(toUInt64String(raw.funds_unlocked_at_last_rate_change)),
117
128
  };
118
129
  };
119
130
  exports.decodeStream = decodeStream;
@@ -535,7 +535,7 @@ var SuiStreamClient = /** @class */ (function (_super) {
535
535
  coins = _a.sent();
536
536
  totalAmount = multipleStreamData.recipients
537
537
  .map(function (recipiient) { return recipiient.amount; })
538
- .reduce(function (prev, current) { return current.add(prev); });
538
+ .reduce(function (prev, current) { return current.plus(prev); });
539
539
  txb = new transactions_1.TransactionBlock();
540
540
  coinObject = this.splitCoinObjectForAmount(txb, totalAmount, multipleStreamData.tokenId, coins, totalFee);
541
541
  coins = [coins[0]];
@@ -40,7 +40,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
42
  exports.Contract = void 0;
43
- var bn_js_1 = __importDefault(require("bn.js"));
43
+ var bignumber_js_1 = __importDefault(require("bignumber.js"));
44
44
  var contractUtils_js_1 = require("../common/contractUtils.js");
45
45
  var utils_js_1 = require("../common/utils.js");
46
46
  var Contract = /** @class */ (function () {
@@ -50,7 +50,7 @@ var Contract = /** @class */ (function () {
50
50
  this.magic = 0;
51
51
  this.version = parseInt(stream.version);
52
52
  this.createdAt = parseInt(stream.created);
53
- this.withdrawnAmount = new bn_js_1.default(stream.withdrawn);
53
+ this.withdrawnAmount = (0, bignumber_js_1.default)(stream.withdrawn);
54
54
  this.canceledAt = parseInt(stream.canceled_at);
55
55
  this.end = parseInt(stream.end);
56
56
  this.lastWithdrawnAt = parseInt(stream.last_withdrawn_at);
@@ -62,20 +62,20 @@ var Contract = /** @class */ (function () {
62
62
  this.escrowTokens = "";
63
63
  this.streamflowTreasury = "";
64
64
  this.streamflowTreasuryTokens = "";
65
- this.streamflowFeeTotal = new bn_js_1.default(0);
66
- this.streamflowFeeWithdrawn = new bn_js_1.default(0);
65
+ this.streamflowFeeTotal = (0, bignumber_js_1.default)(0);
66
+ this.streamflowFeeWithdrawn = (0, bignumber_js_1.default)(0);
67
67
  this.streamflowFeePercent = parseInt(fees.streamflow_fee_percentage) / 10000;
68
- this.partnerFeeTotal = new bn_js_1.default(0);
69
- this.partnerFeeWithdrawn = new bn_js_1.default(0);
68
+ this.partnerFeeTotal = (0, bignumber_js_1.default)(0);
69
+ this.partnerFeeWithdrawn = (0, bignumber_js_1.default)(0);
70
70
  this.partnerFeePercent = parseInt(fees.partner_fee_percentage) / 10000;
71
71
  this.partner = stream.partner;
72
72
  this.partnerTokens = "";
73
73
  this.start = parseInt(stream.start);
74
- this.depositedAmount = new bn_js_1.default(stream.amount);
74
+ this.depositedAmount = (0, bignumber_js_1.default)(stream.amount);
75
75
  this.period = parseInt(stream.period);
76
- this.amountPerPeriod = new bn_js_1.default(stream.amount_per_period);
76
+ this.amountPerPeriod = (0, bignumber_js_1.default)(stream.amount_per_period);
77
77
  this.cliff = parseInt(stream.start);
78
- this.cliffAmount = new bn_js_1.default(stream.cliff_amount);
78
+ this.cliffAmount = (0, bignumber_js_1.default)(stream.cliff_amount);
79
79
  this.cancelableBySender = meta.cancelable_by_sender;
80
80
  this.cancelableByRecipient = meta.cancelable_by_recipient;
81
81
  this.automaticWithdrawal = meta.automatic_withdrawal;
@@ -86,16 +86,16 @@ var Contract = /** @class */ (function () {
86
86
  this.withdrawalFrequency = parseInt(meta.withdrawal_frequency);
87
87
  this.closed = stream.closed;
88
88
  this.currentPauseStart = parseInt(stream.current_pause_start);
89
- this.pauseCumulative = new bn_js_1.default(stream.pause_cumulative);
89
+ this.pauseCumulative = (0, bignumber_js_1.default)(stream.pause_cumulative);
90
90
  this.lastRateChangeTime = parseInt(stream.last_rate_change_time);
91
- this.fundsUnlockedAtLastRateChange = new bn_js_1.default(stream.funds_unlocked_at_last_rate_change);
91
+ this.fundsUnlockedAtLastRateChange = (0, bignumber_js_1.default)(stream.funds_unlocked_at_last_rate_change);
92
92
  this.type = (0, contractUtils_js_1.buildStreamType)(this);
93
93
  }
94
94
  Contract.prototype.unlocked = function (currentTimestamp) {
95
95
  return (0, contractUtils_js_1.calculateUnlockedAmount)(__assign(__assign({}, this), { currentTimestamp: currentTimestamp }));
96
96
  };
97
97
  Contract.prototype.remaining = function (decimals) {
98
- return (0, utils_js_1.getNumberFromBN)(this.depositedAmount.sub(this.withdrawnAmount), decimals);
98
+ return (0, utils_js_1.getNumberFromBigNumber)(this.depositedAmount.minus(this.withdrawnAmount), decimals);
99
99
  };
100
100
  return Contract;
101
101
  }());
@@ -1,4 +1,4 @@
1
- import { BN } from "bn.js";
1
+ import { BigNumber } from "bignumber.js";
2
2
  import { describe, expect, test, beforeEach, vi } from "vitest";
3
3
  import AptosStreamClient from "../../aptos/StreamClient.js";
4
4
  import { ICluster } from "../../common/types.js";
@@ -32,10 +32,10 @@ describe("AptosStreamClient", () => {
32
32
  };
33
33
  const mockRecipient = {
34
34
  recipient: "0xtest",
35
- amount: new BN(1000),
35
+ amount: BigNumber(1000),
36
36
  name: "test name",
37
- cliffAmount: new BN(1),
38
- amountPerPeriod: new BN(1),
37
+ cliffAmount: 1,
38
+ amountPerPeriod: BigNumber(1),
39
39
  };
40
40
  const mockData = {
41
41
  period: 100,
@@ -1,6 +1,6 @@
1
1
  import { AptosAccount } from "aptos";
2
2
  import { WalletContextState } from "@manahippo/aptos-wallet-adapter";
3
- import BN from "bn.js";
3
+ import BigNumber from "bignumber.js";
4
4
  import { Stream, StreamType } from "../common/types.js";
5
5
  export interface ICreateStreamAptosExt {
6
6
  senderWallet: WalletContextState | AptosAccount;
@@ -63,7 +63,7 @@ export declare class Contract implements Stream {
63
63
  magic: number;
64
64
  version: number;
65
65
  createdAt: number;
66
- withdrawnAmount: BN;
66
+ withdrawnAmount: BigNumber;
67
67
  canceledAt: number;
68
68
  end: number;
69
69
  lastWithdrawnAt: number;
@@ -75,20 +75,20 @@ export declare class Contract implements Stream {
75
75
  escrowTokens: string;
76
76
  streamflowTreasury: string;
77
77
  streamflowTreasuryTokens: string;
78
- streamflowFeeTotal: BN;
79
- streamflowFeeWithdrawn: BN;
78
+ streamflowFeeTotal: BigNumber;
79
+ streamflowFeeWithdrawn: BigNumber;
80
80
  streamflowFeePercent: number;
81
- partnerFeeTotal: BN;
82
- partnerFeeWithdrawn: BN;
81
+ partnerFeeTotal: BigNumber;
82
+ partnerFeeWithdrawn: BigNumber;
83
83
  partnerFeePercent: number;
84
84
  partner: string;
85
85
  partnerTokens: string;
86
86
  start: number;
87
- depositedAmount: BN;
87
+ depositedAmount: BigNumber;
88
88
  period: number;
89
- amountPerPeriod: BN;
89
+ amountPerPeriod: BigNumber;
90
90
  cliff: number;
91
- cliffAmount: BN;
91
+ cliffAmount: BigNumber;
92
92
  cancelableBySender: boolean;
93
93
  cancelableByRecipient: boolean;
94
94
  automaticWithdrawal: boolean;
@@ -99,11 +99,11 @@ export declare class Contract implements Stream {
99
99
  withdrawalFrequency: number;
100
100
  closed: boolean;
101
101
  currentPauseStart: number;
102
- pauseCumulative: BN;
102
+ pauseCumulative: BigNumber;
103
103
  lastRateChangeTime: number;
104
- fundsUnlockedAtLastRateChange: BN;
104
+ fundsUnlockedAtLastRateChange: BigNumber;
105
105
  type: StreamType;
106
106
  constructor(stream: StreamResource, tokenId: string);
107
- unlocked(currentTimestamp: number): BN;
107
+ unlocked(currentTimestamp: number): BigNumber;
108
108
  remaining(decimals: number): number;
109
109
  }
@@ -1,8 +1,8 @@
1
- import BN from "bn.js";
1
+ import BigNumber from "bignumber.js";
2
2
  import { Buffer } from "buffer";
3
3
  import { buildStreamType, calculateUnlockedAmount } from "../common/contractUtils.js";
4
- import { getNumberFromBN } from "../common/utils.js";
5
4
  import { normalizeAptosAddress } from "./utils.js";
5
+ import { getNumberFromBigNumber } from "../common/utils.js";
6
6
  export class Contract {
7
7
  magic;
8
8
  version;
@@ -51,7 +51,7 @@ export class Contract {
51
51
  this.magic = 0;
52
52
  this.version = 0;
53
53
  this.createdAt = parseInt(stream.created);
54
- this.withdrawnAmount = new BN(stream.withdrawn);
54
+ this.withdrawnAmount = BigNumber(stream.withdrawn);
55
55
  this.canceledAt = parseInt(stream.canceled_at);
56
56
  this.end = parseInt(stream.end);
57
57
  this.lastWithdrawnAt = parseInt(stream.last_withdrawn_at);
@@ -63,20 +63,20 @@ export class Contract {
63
63
  this.escrowTokens = "";
64
64
  this.streamflowTreasury = "";
65
65
  this.streamflowTreasuryTokens = "";
66
- this.streamflowFeeTotal = new BN(0);
67
- this.streamflowFeeWithdrawn = new BN(0);
66
+ this.streamflowFeeTotal = BigNumber(0);
67
+ this.streamflowFeeWithdrawn = BigNumber(0);
68
68
  this.streamflowFeePercent = parseInt(stream.fees.streamflow_fee_percentage) / 10000;
69
- this.partnerFeeTotal = new BN(0);
70
- this.partnerFeeWithdrawn = new BN(0);
69
+ this.partnerFeeTotal = BigNumber(0);
70
+ this.partnerFeeWithdrawn = BigNumber(0);
71
71
  this.partnerFeePercent = 0;
72
72
  this.partner = "";
73
73
  this.partnerTokens = "";
74
74
  this.start = parseInt(stream.start);
75
- this.depositedAmount = new BN(stream.amount);
75
+ this.depositedAmount = BigNumber(stream.amount);
76
76
  this.period = parseInt(stream.period);
77
- this.amountPerPeriod = new BN(stream.amount_per_period);
77
+ this.amountPerPeriod = BigNumber(stream.amount_per_period);
78
78
  this.cliff = parseInt(stream.start);
79
- this.cliffAmount = new BN(stream.cliff_amount);
79
+ this.cliffAmount = BigNumber(stream.cliff_amount);
80
80
  this.cancelableBySender = stream.meta.cancelable_by_sender;
81
81
  this.cancelableByRecipient = stream.meta.cancelable_by_recipient;
82
82
  this.automaticWithdrawal = stream.meta.automatic_withdrawal;
@@ -88,9 +88,9 @@ export class Contract {
88
88
  this.withdrawalFrequency = parseInt(stream.meta.withdrawal_frequency);
89
89
  this.closed = stream.closed;
90
90
  this.currentPauseStart = parseInt(stream.current_pause_start);
91
- this.pauseCumulative = new BN(stream.pause_cumulative);
91
+ this.pauseCumulative = BigNumber(stream.pause_cumulative);
92
92
  this.lastRateChangeTime = parseInt(stream.last_rate_change_time);
93
- this.fundsUnlockedAtLastRateChange = new BN(stream.funds_unlocked_at_last_rate_change);
93
+ this.fundsUnlockedAtLastRateChange = BigNumber(stream.funds_unlocked_at_last_rate_change);
94
94
  this.type = buildStreamType(this);
95
95
  }
96
96
  unlocked(currentTimestamp) {
@@ -100,6 +100,6 @@ export class Contract {
100
100
  });
101
101
  }
102
102
  remaining(decimals) {
103
- return getNumberFromBN(this.depositedAmount.sub(this.withdrawnAmount), decimals);
103
+ return getNumberFromBigNumber(this.depositedAmount.minus(this.withdrawnAmount), decimals);
104
104
  }
105
105
  }
@@ -1,3 +1,3 @@
1
- import BN from "bn.js";
1
+ import BigNumber from "bignumber.js";
2
2
  export declare const BASE_FEE = 1009900;
3
- export declare const WITHDRAW_AVAILABLE_AMOUNT: BN;
3
+ export declare const WITHDRAW_AVAILABLE_AMOUNT: BigNumber;
@@ -1,3 +1,3 @@
1
- import BN from "bn.js";
1
+ import BigNumber from "bignumber.js";
2
2
  export const BASE_FEE = 1009900; // Buffer to include usual fees when calculating stream amount
3
- export const WITHDRAW_AVAILABLE_AMOUNT = new BN("18446744073709551615"); // Magical number to withdraw all available amount from a Contract
3
+ export const WITHDRAW_AVAILABLE_AMOUNT = BigNumber("18446744073709551615"); // Magical number to withdraw all available amount from a Contract
@@ -1,28 +1,28 @@
1
- import BN from "bn.js";
1
+ import BigNumber from "bignumber.js";
2
2
  import { StreamType } from "./types.js";
3
3
  interface ICalculateUnlockedAmount {
4
- depositedAmount: BN;
4
+ depositedAmount: BigNumber;
5
5
  cliff: number;
6
- cliffAmount: BN;
6
+ cliffAmount: BigNumber;
7
7
  end: number;
8
8
  currentTimestamp: number;
9
9
  lastRateChangeTime: number;
10
10
  period: number;
11
- amountPerPeriod: BN;
12
- fundsUnlockedAtLastRateChange: BN;
11
+ amountPerPeriod: BigNumber;
12
+ fundsUnlockedAtLastRateChange: BigNumber;
13
13
  }
14
- export declare const calculateUnlockedAmount: ({ depositedAmount, cliff, cliffAmount, end, currentTimestamp, lastRateChangeTime, period, amountPerPeriod, fundsUnlockedAtLastRateChange, }: ICalculateUnlockedAmount) => BN;
14
+ export declare const calculateUnlockedAmount: ({ depositedAmount, cliff, cliffAmount, end, currentTimestamp, lastRateChangeTime, period, amountPerPeriod, fundsUnlockedAtLastRateChange, }: ICalculateUnlockedAmount) => BigNumber;
15
15
  export declare const isCliffCloseToDepositedAmount: (streamData: {
16
- depositedAmount: BN;
17
- cliffAmount: BN;
16
+ depositedAmount: BigNumber;
17
+ cliffAmount: BigNumber;
18
18
  }) => boolean;
19
19
  export declare const isPayment: (streamData: {
20
20
  canTopup: boolean;
21
21
  }) => boolean;
22
22
  export declare const isVesting: (streamData: {
23
23
  canTopup: boolean;
24
- depositedAmount: BN;
25
- cliffAmount: BN;
24
+ depositedAmount: BigNumber;
25
+ cliffAmount: BigNumber;
26
26
  }) => boolean;
27
27
  export declare const isTokenLock: (streamData: {
28
28
  canTopup: boolean;
@@ -31,8 +31,8 @@ export declare const isTokenLock: (streamData: {
31
31
  cancelableByRecipient: boolean;
32
32
  transferableBySender: boolean;
33
33
  transferableByRecipient: boolean;
34
- depositedAmount: BN;
35
- cliffAmount: BN;
34
+ depositedAmount: BigNumber;
35
+ cliffAmount: BigNumber;
36
36
  }) => boolean;
37
37
  export declare const buildStreamType: (streamData: {
38
38
  canTopup: boolean;
@@ -41,7 +41,7 @@ export declare const buildStreamType: (streamData: {
41
41
  cancelableByRecipient: boolean;
42
42
  transferableBySender: boolean;
43
43
  transferableByRecipient: boolean;
44
- depositedAmount: BN;
45
- cliffAmount: BN;
44
+ depositedAmount: BigNumber;
45
+ cliffAmount: BigNumber;
46
46
  }) => StreamType;
47
47
  export {};
@@ -1,20 +1,20 @@
1
- import BN from "bn.js";
1
+ import BigNumber from "bignumber.js";
2
2
  import { StreamType } from "./types.js";
3
3
  export const calculateUnlockedAmount = ({ depositedAmount, cliff, cliffAmount, end, currentTimestamp, lastRateChangeTime, period, amountPerPeriod, fundsUnlockedAtLastRateChange, }) => {
4
4
  const deposited = depositedAmount;
5
5
  if (currentTimestamp < cliff)
6
- return new BN(0);
6
+ return BigNumber(0);
7
7
  if (currentTimestamp > end)
8
8
  return deposited;
9
9
  const savedUnlockedFunds = lastRateChangeTime === 0 ? cliffAmount : fundsUnlockedAtLastRateChange;
10
10
  const savedUnlockedFundsTime = lastRateChangeTime === 0 ? cliff : lastRateChangeTime;
11
- const streamed = new BN(Math.floor((currentTimestamp - savedUnlockedFundsTime) / period))
12
- .mul(amountPerPeriod)
13
- .add(savedUnlockedFunds);
11
+ const streamed = BigNumber(Math.floor((currentTimestamp - savedUnlockedFundsTime) / period))
12
+ .times(amountPerPeriod)
13
+ .plus(savedUnlockedFunds);
14
14
  return streamed.lt(deposited) ? streamed : deposited;
15
15
  };
16
16
  export const isCliffCloseToDepositedAmount = (streamData) => {
17
- return streamData.cliffAmount.gte(streamData.depositedAmount.sub(new BN("1")));
17
+ return streamData.cliffAmount.gte(streamData.depositedAmount.minus(BigNumber(1)));
18
18
  };
19
19
  export const isPayment = (streamData) => {
20
20
  return streamData.canTopup;
@@ -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: string | number;
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