@streamflow/stream 5.0.1 → 5.2.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.
@@ -1,5 +1,6 @@
1
1
  import { WalletContextState } from "@manahippo/aptos-wallet-adapter";
2
2
  import BN from "bn.js";
3
+ import { Stream, StreamType } from "../common/types";
3
4
  export interface ICreateStreamAptosExt {
4
5
  senderWallet: WalletContextState;
5
6
  }
@@ -45,51 +46,6 @@ export interface StreamResource {
45
46
  start: string;
46
47
  withdrawn: string;
47
48
  }
48
- export interface Stream {
49
- magic: number;
50
- version: number;
51
- createdAt: number;
52
- withdrawnAmount: BN;
53
- canceledAt: number;
54
- end: number;
55
- lastWithdrawnAt: number;
56
- sender: string;
57
- senderTokens: string;
58
- recipient: string;
59
- recipientTokens: string;
60
- mint: string;
61
- escrowTokens: string;
62
- streamflowTreasury: string;
63
- streamflowTreasuryTokens: string;
64
- streamflowFeeTotal: BN;
65
- streamflowFeeWithdrawn: BN;
66
- streamflowFeePercent: number;
67
- partnerFeeTotal: BN;
68
- partnerFeeWithdrawn: BN;
69
- partnerFeePercent: number;
70
- partner: string;
71
- partnerTokens: string;
72
- start: number;
73
- depositedAmount: BN;
74
- period: number;
75
- amountPerPeriod: BN;
76
- cliff: number;
77
- cliffAmount: BN;
78
- cancelableBySender: boolean;
79
- cancelableByRecipient: boolean;
80
- automaticWithdrawal: boolean;
81
- transferableBySender: boolean;
82
- transferableByRecipient: boolean;
83
- canTopup: boolean;
84
- name: string;
85
- withdrawalFrequency: number;
86
- closed: boolean;
87
- currentPauseStart: number;
88
- pauseCumulative: BN;
89
- lastRateChangeTime: number;
90
- fundsUnlockedAtLastRateChange: BN;
91
- unlocked(currentTimestamp: number): BN;
92
- }
93
49
  export declare class Contract implements Stream {
94
50
  magic: number;
95
51
  version: number;
@@ -133,6 +89,7 @@ export declare class Contract implements Stream {
133
89
  pauseCumulative: BN;
134
90
  lastRateChangeTime: number;
135
91
  fundsUnlockedAtLastRateChange: BN;
92
+ type: StreamType;
136
93
  constructor(stream: StreamResource, tokenId: string);
137
94
  unlocked(currentTimestamp: number): BN;
138
95
  remaining(decimals: number): number;
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
15
  };
@@ -52,9 +63,10 @@ var Contract = /** @class */ (function () {
52
63
  this.pauseCumulative = new bn_js_1.default(stream.pause_cumulative);
53
64
  this.lastRateChangeTime = parseInt(stream.last_rate_change_time);
54
65
  this.fundsUnlockedAtLastRateChange = new bn_js_1.default(stream.funds_unlocked_at_last_rate_change);
66
+ this.type = (0, contractUtils_1.buildStreamType)(this);
55
67
  }
56
68
  Contract.prototype.unlocked = function (currentTimestamp) {
57
- return (0, contractUtils_1.calculateUnlockedAmount)(this.depositedAmount, this.cliff, this.cliffAmount, this.end, currentTimestamp, this.lastRateChangeTime, this.period, this.amountPerPeriod, this.fundsUnlockedAtLastRateChange);
69
+ return (0, contractUtils_1.calculateUnlockedAmount)(__assign(__assign({}, this), { currentTimestamp: currentTimestamp }));
58
70
  };
59
71
  Contract.prototype.remaining = function (decimals) {
60
72
  return (0, utils_1.getNumberFromBN)(this.depositedAmount.sub(this.withdrawnAmount), decimals);
@@ -1,5 +1,4 @@
1
- import { Stream } from "../solana";
2
- import { ICreateStreamData, ICreateMultipleStreamData, IWithdrawData, ICancelData, ITransferData, ITopUpData, IGetOneData, IUpdateData, ITransactionResult, IMultiTransactionResult, ICreateResult, IGetAllData } from "./types";
1
+ import { ICreateStreamData, ICreateMultipleStreamData, IWithdrawData, ICancelData, ITransferData, ITopUpData, IGetOneData, IUpdateData, ITransactionResult, IMultiTransactionResult, ICreateResult, IGetAllData, Stream } from "./types";
3
2
  export declare abstract class BaseStreamClient {
4
3
  protected abstract create(streamData: ICreateStreamData, chainSpecificParams: any): Promise<ICreateResult>;
5
4
  protected abstract createMultiple(multipleStreamData: ICreateMultipleStreamData, chainSpecificParams: any): Promise<IMultiTransactionResult>;
@@ -1,12 +1,11 @@
1
1
  import { Commitment, ConnectionConfig } from "@solana/web3.js";
2
2
  import { Signer } from "ethers";
3
- import SolanaStreamClient from "../solana/StreamClient";
4
- import AptosStreamClient from "../aptos/StreamClient";
5
3
  import { BaseStreamClient } from "./BaseStreamClient";
6
- import { ICancelData, IChain, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IUpdateData, IWithdrawData, ITransactionResult, IMultiTransactionResult, ICreateResult, IGetAllData } from "./types";
7
- import { ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt, Stream } from "../solana";
8
- import { ICreateStreamAptosExt, ITransactionAptosExt } from "../aptos";
4
+ import { ICancelData, IChain, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IUpdateData, IWithdrawData, ITransactionResult, IMultiTransactionResult, ICreateResult, IGetAllData, Stream } from "./types";
5
+ import { AptosStreamClient, ICreateStreamAptosExt, ITransactionAptosExt } from "../aptos";
9
6
  import { EvmStreamClient } from "../evm";
7
+ import { SolanaStreamClient, ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt } from "../solana";
8
+ import { ICreateStreamSuiExt, ITransactionSuiExt, ISuiIdParameters, SuiStreamClient } from "../sui";
10
9
  export interface SolanaStreamClientOptions {
11
10
  chain: IChain.Solana;
12
11
  clusterUrl: string;
@@ -28,12 +27,18 @@ export interface EvmStreamClientOptions {
28
27
  cluster?: ICluster;
29
28
  programId?: string;
30
29
  }
31
- declare type StreamClientOptions<T extends IChain> = T extends IChain.Solana ? SolanaStreamClientOptions : T extends IChain.Aptos ? AptosStreamClientOptions : EvmStreamClientOptions;
32
- declare type StreamClientType<T extends IChain> = T extends IChain.Solana ? SolanaStreamClient : T extends IChain.Aptos ? AptosStreamClient : EvmStreamClient;
33
- declare type ChainSpecificParams<T, SolanaExt, AptosExt> = T extends SolanaStreamClient ? SolanaExt : T extends AptosStreamClient ? AptosExt : undefined;
34
- declare type CreateSpecificParams<T extends IChain> = ChainSpecificParams<StreamClientType<T>, ICreateStreamSolanaExt, ICreateStreamAptosExt>;
35
- declare type TopupSpecificParams<T extends IChain> = ChainSpecificParams<StreamClientType<T>, ITopUpStreamSolanaExt, ITransactionAptosExt>;
36
- declare type InteractSpecificParams<T extends IChain> = ChainSpecificParams<StreamClientType<T>, IInteractStreamSolanaExt, ITransactionAptosExt>;
30
+ export interface SuiStreamClientOptions {
31
+ chain: IChain.Sui;
32
+ clusterUrl: string;
33
+ cluster?: ICluster;
34
+ ids?: ISuiIdParameters;
35
+ }
36
+ declare type StreamClientOptions<T extends IChain> = T extends IChain.Solana ? SolanaStreamClientOptions : T extends IChain.Aptos ? AptosStreamClientOptions : T extends IChain.Sui ? SuiStreamClientOptions : EvmStreamClientOptions;
37
+ declare type StreamClientType<T extends IChain> = T extends IChain.Solana ? SolanaStreamClient : T extends IChain.Aptos ? AptosStreamClient : T extends IChain.Sui ? SuiStreamClient : EvmStreamClient;
38
+ declare type ChainSpecificParams<T, SolanaExt, AptosExt, SuiExt> = T extends SolanaStreamClient ? SolanaExt : T extends AptosStreamClient ? AptosExt : T extends SuiStreamClient ? SuiExt : undefined;
39
+ declare type CreateSpecificParams<T extends IChain> = ChainSpecificParams<StreamClientType<T>, ICreateStreamSolanaExt, ICreateStreamAptosExt, ICreateStreamSuiExt>;
40
+ declare type TopupSpecificParams<T extends IChain> = ChainSpecificParams<StreamClientType<T>, ITopUpStreamSolanaExt, ITransactionAptosExt, ITransactionSuiExt>;
41
+ declare type InteractSpecificParams<T extends IChain> = ChainSpecificParams<StreamClientType<T>, IInteractStreamSolanaExt, ITransactionAptosExt, ITransactionSuiExt>;
37
42
  export default class GenericStreamClient<T extends IChain> extends BaseStreamClient {
38
43
  nativeStreamClient: StreamClientType<T>;
39
44
  chain: IChain;
@@ -14,15 +14,13 @@ var __extends = (this && this.__extends) || (function () {
14
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
15
  };
16
16
  })();
17
- var __importDefault = (this && this.__importDefault) || function (mod) {
18
- return (mod && mod.__esModule) ? mod : { "default": mod };
19
- };
20
17
  Object.defineProperty(exports, "__esModule", { value: true });
21
- var StreamClient_1 = __importDefault(require("../solana/StreamClient"));
22
- var StreamClient_2 = __importDefault(require("../aptos/StreamClient"));
23
18
  var BaseStreamClient_1 = require("./BaseStreamClient");
24
19
  var types_1 = require("./types");
20
+ var aptos_1 = require("../aptos");
25
21
  var evm_1 = require("../evm");
22
+ var solana_1 = require("../solana");
23
+ var sui_1 = require("../sui");
26
24
  var GenericStreamClient = /** @class */ (function (_super) {
27
25
  __extends(GenericStreamClient, _super);
28
26
  function GenericStreamClient(options) {
@@ -30,16 +28,18 @@ var GenericStreamClient = /** @class */ (function (_super) {
30
28
  _this.chain = options.chain;
31
29
  switch (options.chain) {
32
30
  case types_1.IChain.Solana:
33
- _this.nativeStreamClient = new StreamClient_1.default(options.clusterUrl, options.cluster, options.commitment, options.programId);
31
+ _this.nativeStreamClient = new solana_1.SolanaStreamClient(options.clusterUrl, options.cluster, options.commitment, options.programId);
34
32
  break;
35
33
  case types_1.IChain.Aptos:
36
- _this.nativeStreamClient = new StreamClient_2.default(options.clusterUrl, options.cluster, options.maxGas, options.programId);
34
+ _this.nativeStreamClient = new aptos_1.AptosStreamClient(options.clusterUrl, options.cluster, options.maxGas, options.programId);
37
35
  break;
38
36
  case types_1.IChain.BNB:
39
37
  case types_1.IChain.Ethereum:
40
38
  case types_1.IChain.Polygon:
41
39
  _this.nativeStreamClient = new evm_1.EvmStreamClient(options.clusterUrl, options.chain, options.signer, options.cluster, options.programId);
42
40
  break;
41
+ case types_1.IChain.Sui:
42
+ _this.nativeStreamClient = new sui_1.SuiStreamClient(options.clusterUrl, options.cluster, options.ids);
43
43
  }
44
44
  return _this;
45
45
  }
@@ -47,73 +47,37 @@ var GenericStreamClient = /** @class */ (function (_super) {
47
47
  * Creates a new stream/vesting contract.
48
48
  */
49
49
  GenericStreamClient.prototype.create = function (streamData, chainSpecificParams) {
50
- if (this.nativeStreamClient instanceof StreamClient_1.default) {
51
- return this.nativeStreamClient.create(streamData, chainSpecificParams);
52
- }
53
- else if (this.nativeStreamClient instanceof StreamClient_2.default) {
54
- return this.nativeStreamClient.create(streamData, chainSpecificParams);
55
- }
56
- return this.nativeStreamClient.create(streamData);
50
+ return this.nativeStreamClient.create(streamData, chainSpecificParams);
57
51
  };
58
52
  /**
59
53
  * Creates multiple stream/vesting contracts.
60
54
  */
61
55
  GenericStreamClient.prototype.createMultiple = function (multipleStreamData, chainSpecificParams) {
62
- if (this.nativeStreamClient instanceof StreamClient_1.default) {
63
- return this.nativeStreamClient.createMultiple(multipleStreamData, chainSpecificParams);
64
- }
65
- else if (this.nativeStreamClient instanceof StreamClient_2.default) {
66
- return this.nativeStreamClient.createMultiple(multipleStreamData, chainSpecificParams);
67
- }
68
- return this.nativeStreamClient.createMultiple(multipleStreamData);
56
+ return this.nativeStreamClient.createMultiple(multipleStreamData, chainSpecificParams);
69
57
  };
70
58
  /**
71
59
  * Attempts withdrawing from the specified stream.
72
60
  */
73
61
  GenericStreamClient.prototype.withdraw = function (withdrawData, chainSpecificParams) {
74
- if (this.nativeStreamClient instanceof StreamClient_1.default) {
75
- return this.nativeStreamClient.withdraw(withdrawData, chainSpecificParams);
76
- }
77
- else if (this.nativeStreamClient instanceof StreamClient_2.default) {
78
- return this.nativeStreamClient.withdraw(withdrawData, chainSpecificParams);
79
- }
80
- return this.nativeStreamClient.withdraw(withdrawData);
62
+ return this.nativeStreamClient.withdraw(withdrawData, chainSpecificParams);
81
63
  };
82
64
  /**
83
65
  * Attempts canceling the specified stream.
84
66
  */
85
67
  GenericStreamClient.prototype.cancel = function (cancelData, chainSpecificParams) {
86
- if (this.nativeStreamClient instanceof StreamClient_1.default) {
87
- return this.nativeStreamClient.cancel(cancelData, chainSpecificParams);
88
- }
89
- else if (this.nativeStreamClient instanceof StreamClient_2.default) {
90
- return this.nativeStreamClient.cancel(cancelData, chainSpecificParams);
91
- }
92
- return this.nativeStreamClient.cancel(cancelData);
68
+ return this.nativeStreamClient.cancel(cancelData, chainSpecificParams);
93
69
  };
94
70
  /**
95
71
  * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
96
72
  */
97
73
  GenericStreamClient.prototype.transfer = function (transferData, chainSpecificParams) {
98
- if (this.nativeStreamClient instanceof StreamClient_1.default) {
99
- return this.nativeStreamClient.transfer(transferData, chainSpecificParams);
100
- }
101
- else if (this.nativeStreamClient instanceof StreamClient_2.default) {
102
- return this.nativeStreamClient.transfer(transferData, chainSpecificParams);
103
- }
104
- return this.nativeStreamClient.transfer(transferData);
74
+ return this.nativeStreamClient.transfer(transferData, chainSpecificParams);
105
75
  };
106
76
  /**
107
77
  * Tops up stream account with specified amount.
108
78
  */
109
79
  GenericStreamClient.prototype.topup = function (topupData, chainSpecificParams) {
110
- if (this.nativeStreamClient instanceof StreamClient_1.default) {
111
- return this.nativeStreamClient.topup(topupData, chainSpecificParams);
112
- }
113
- else if (this.nativeStreamClient instanceof StreamClient_2.default) {
114
- return this.nativeStreamClient.topup(topupData, chainSpecificParams);
115
- }
116
- return this.nativeStreamClient.topup(topupData);
80
+ return this.nativeStreamClient.topup(topupData, chainSpecificParams);
117
81
  };
118
82
  /**
119
83
  * Fetch stream data by its id (address).
@@ -131,13 +95,7 @@ var GenericStreamClient = /** @class */ (function (_super) {
131
95
  * Attempts updating the stream auto withdrawal params and amount per period
132
96
  */
133
97
  GenericStreamClient.prototype.update = function (updateData, chainSpecificParams) {
134
- if (this.nativeStreamClient instanceof StreamClient_1.default) {
135
- return this.nativeStreamClient.update(updateData, chainSpecificParams);
136
- }
137
- else if (this.nativeStreamClient instanceof StreamClient_2.default) {
138
- return this.nativeStreamClient.update(updateData, chainSpecificParams);
139
- }
140
- return this.nativeStreamClient.update(updateData);
98
+ return this.nativeStreamClient.update(updateData, chainSpecificParams);
141
99
  };
142
100
  return GenericStreamClient;
143
101
  }(BaseStreamClient_1.BaseStreamClient));
@@ -0,0 +1 @@
1
+ export declare const BASE_FEE = 1002500;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BASE_FEE = void 0;
4
+ exports.BASE_FEE = 1002500; // Buffer to include usual fees when calculating stream amount
@@ -1,2 +1,28 @@
1
1
  import BN from "bn.js";
2
- export declare const calculateUnlockedAmount: (depositedAmount: BN, cliff: number, cliffAmount: BN, end: number, currentTimestamp: number, lastRateChangeTime: number, period: number, amountPerPeriod: BN, fundsUnlockedAtLastRateChange: BN) => BN;
2
+ import { StreamType } from "./types";
3
+ interface ICalculateUnlockedAmount {
4
+ depositedAmount: BN;
5
+ cliff: number;
6
+ cliffAmount: BN;
7
+ end: number;
8
+ currentTimestamp: number;
9
+ lastRateChangeTime: number;
10
+ period: number;
11
+ amountPerPeriod: BN;
12
+ fundsUnlockedAtLastRateChange: BN;
13
+ }
14
+ export declare const calculateUnlockedAmount: ({ depositedAmount, cliff, cliffAmount, end, currentTimestamp, lastRateChangeTime, period, amountPerPeriod, fundsUnlockedAtLastRateChange, }: ICalculateUnlockedAmount) => BN;
15
+ export declare const isPayment: (streamData: {
16
+ canTopup: boolean;
17
+ }) => boolean;
18
+ export declare const isTokenLock: (streamData: {
19
+ canTopup: boolean;
20
+ depositedAmount: BN;
21
+ cliffAmount: BN;
22
+ }) => boolean;
23
+ export declare const buildStreamType: (streamData: {
24
+ canTopup: boolean;
25
+ depositedAmount: BN;
26
+ cliffAmount: BN;
27
+ }) => StreamType;
28
+ export {};
@@ -3,9 +3,11 @@ 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.calculateUnlockedAmount = void 0;
6
+ exports.buildStreamType = exports.isTokenLock = exports.isPayment = exports.calculateUnlockedAmount = void 0;
7
7
  var bn_js_1 = __importDefault(require("bn.js"));
8
- var calculateUnlockedAmount = function (depositedAmount, cliff, cliffAmount, end, currentTimestamp, lastRateChangeTime, period, amountPerPeriod, fundsUnlockedAtLastRateChange) {
8
+ var types_1 = require("./types");
9
+ var calculateUnlockedAmount = function (_a) {
10
+ var depositedAmount = _a.depositedAmount, cliff = _a.cliff, cliffAmount = _a.cliffAmount, end = _a.end, currentTimestamp = _a.currentTimestamp, lastRateChangeTime = _a.lastRateChangeTime, period = _a.period, amountPerPeriod = _a.amountPerPeriod, fundsUnlockedAtLastRateChange = _a.fundsUnlockedAtLastRateChange;
9
11
  var deposited = depositedAmount;
10
12
  if (currentTimestamp < cliff)
11
13
  return new bn_js_1.default(0);
@@ -19,3 +21,21 @@ var calculateUnlockedAmount = function (depositedAmount, cliff, cliffAmount, end
19
21
  return streamed.lt(deposited) ? streamed : deposited;
20
22
  };
21
23
  exports.calculateUnlockedAmount = calculateUnlockedAmount;
24
+ var isPayment = function (streamData) {
25
+ return streamData.canTopup;
26
+ };
27
+ exports.isPayment = isPayment;
28
+ var isTokenLock = function (streamData) {
29
+ return (!streamData.canTopup && streamData.cliffAmount.gte(streamData.depositedAmount.sub(new bn_js_1.default("1"))));
30
+ };
31
+ exports.isTokenLock = isTokenLock;
32
+ var buildStreamType = function (streamData) {
33
+ if ((0, exports.isPayment)(streamData)) {
34
+ return types_1.StreamType.Payment;
35
+ }
36
+ if ((0, exports.isTokenLock)(streamData)) {
37
+ return types_1.StreamType.Lock;
38
+ }
39
+ return types_1.StreamType.Vesting;
40
+ };
41
+ exports.buildStreamType = buildStreamType;
@@ -87,9 +87,10 @@ export declare enum StreamDirection {
87
87
  All = "all"
88
88
  }
89
89
  export declare enum StreamType {
90
- Stream = "stream",
90
+ All = "all",
91
+ Payment = "payment",
91
92
  Vesting = "vesting",
92
- All = "all"
93
+ Lock = "lock"
93
94
  }
94
95
  export declare enum IChain {
95
96
  Solana = "Solana",
@@ -99,4 +100,50 @@ export declare enum IChain {
99
100
  Polygon = "Polygon",
100
101
  Sui = "Sui"
101
102
  }
103
+ export interface Stream {
104
+ magic: number;
105
+ version: number;
106
+ createdAt: number;
107
+ withdrawnAmount: BN;
108
+ canceledAt: number;
109
+ end: number;
110
+ lastWithdrawnAt: number;
111
+ sender: string;
112
+ senderTokens: string;
113
+ recipient: string;
114
+ recipientTokens: string;
115
+ mint: string;
116
+ escrowTokens: string;
117
+ streamflowTreasury: string;
118
+ streamflowTreasuryTokens: string;
119
+ streamflowFeeTotal: BN;
120
+ streamflowFeeWithdrawn: BN;
121
+ streamflowFeePercent: number;
122
+ partnerFeeTotal: BN;
123
+ partnerFeeWithdrawn: BN;
124
+ partnerFeePercent: number;
125
+ partner: string;
126
+ partnerTokens: string;
127
+ start: number;
128
+ depositedAmount: BN;
129
+ period: number;
130
+ amountPerPeriod: BN;
131
+ cliff: number;
132
+ cliffAmount: BN;
133
+ cancelableBySender: boolean;
134
+ cancelableByRecipient: boolean;
135
+ automaticWithdrawal: boolean;
136
+ transferableBySender: boolean;
137
+ transferableByRecipient: boolean;
138
+ canTopup: boolean;
139
+ name: string;
140
+ withdrawalFrequency: number;
141
+ closed: boolean;
142
+ currentPauseStart: number;
143
+ pauseCumulative: BN;
144
+ lastRateChangeTime: number;
145
+ fundsUnlockedAtLastRateChange: BN;
146
+ type: StreamType;
147
+ unlocked(currentTimestamp: number): BN;
148
+ }
102
149
  export {};
@@ -17,9 +17,10 @@ var StreamDirection;
17
17
  })(StreamDirection = exports.StreamDirection || (exports.StreamDirection = {}));
18
18
  var StreamType;
19
19
  (function (StreamType) {
20
- StreamType["Stream"] = "stream";
21
- StreamType["Vesting"] = "vesting";
22
20
  StreamType["All"] = "all";
21
+ StreamType["Payment"] = "payment";
22
+ StreamType["Vesting"] = "vesting";
23
+ StreamType["Lock"] = "lock";
23
24
  })(StreamType = exports.StreamType || (exports.StreamType = {}));
24
25
  var IChain;
25
26
  (function (IChain) {
@@ -1,7 +1,6 @@
1
1
  import { ethers } from "ethers";
2
2
  import { BaseStreamClient } from "../common/BaseStreamClient";
3
- import { ICancelData, IChain, ICluster, ICreateMultipleStreamData, ICreateResult, ICreateStreamData, IGetAllData, IGetOneData, IMultiTransactionResult, ITopUpData, ITransactionResult, ITransferData, IUpdateData, IWithdrawData } from "../common/types";
4
- import { Stream } from "../solana";
3
+ import { ICancelData, IChain, ICluster, ICreateMultipleStreamData, ICreateResult, ICreateStreamData, IGetAllData, IGetOneData, IMultiTransactionResult, ITopUpData, ITransactionResult, ITransferData, IUpdateData, IWithdrawData, Stream } from "../common/types";
5
4
  export default class EvmStreamClient extends BaseStreamClient {
6
5
  private programId;
7
6
  private provider;
@@ -98,7 +98,7 @@ var types_1 = require("../common/types");
98
98
  var constants_1 = require("./constants");
99
99
  var abi_1 = __importDefault(require("./abi"));
100
100
  var ercAbi_1 = __importDefault(require("./ercAbi"));
101
- var constants_2 = require("../solana/constants");
101
+ var constants_2 = require("../common/constants");
102
102
  var types_2 = require("./types");
103
103
  var EvmStreamClient = /** @class */ (function (_super) {
104
104
  __extends(EvmStreamClient, _super);
@@ -1,5 +1,6 @@
1
1
  import BN from "bn.js";
2
2
  import { BigNumber } from "ethers";
3
+ import { Stream, StreamType } from "../common/types";
3
4
  export interface StreamAbiResult {
4
5
  amount: BigNumber;
5
6
  amount_per_period: BigNumber;
@@ -42,51 +43,6 @@ export interface StreamAbiResult {
42
43
  token: string;
43
44
  withdrawn: BigNumber;
44
45
  }
45
- export interface Stream {
46
- magic: number;
47
- version: number;
48
- createdAt: number;
49
- withdrawnAmount: BN;
50
- canceledAt: number;
51
- end: number;
52
- lastWithdrawnAt: number;
53
- sender: string;
54
- senderTokens: string;
55
- recipient: string;
56
- recipientTokens: string;
57
- mint: string;
58
- escrowTokens: string;
59
- streamflowTreasury: string;
60
- streamflowTreasuryTokens: string;
61
- streamflowFeeTotal: BN;
62
- streamflowFeeWithdrawn: BN;
63
- streamflowFeePercent: number;
64
- partnerFeeTotal: BN;
65
- partnerFeeWithdrawn: BN;
66
- partnerFeePercent: number;
67
- partner: string;
68
- partnerTokens: string;
69
- start: number;
70
- depositedAmount: BN;
71
- period: number;
72
- amountPerPeriod: BN;
73
- cliff: number;
74
- cliffAmount: BN;
75
- cancelableBySender: boolean;
76
- cancelableByRecipient: boolean;
77
- automaticWithdrawal: boolean;
78
- transferableBySender: boolean;
79
- transferableByRecipient: boolean;
80
- canTopup: boolean;
81
- name: string;
82
- withdrawalFrequency: number;
83
- closed: boolean;
84
- currentPauseStart: number;
85
- pauseCumulative: BN;
86
- lastRateChangeTime: number;
87
- fundsUnlockedAtLastRateChange: BN;
88
- unlocked(currentTimestamp: number, decimals: number): BN;
89
- }
90
46
  export declare class EvmContract implements Stream {
91
47
  magic: number;
92
48
  version: number;
@@ -130,6 +86,7 @@ export declare class EvmContract implements Stream {
130
86
  pauseCumulative: BN;
131
87
  lastRateChangeTime: number;
132
88
  fundsUnlockedAtLastRateChange: BN;
89
+ type: StreamType;
133
90
  constructor(stream: StreamAbiResult);
134
91
  unlocked(currentTimestamp: number): BN;
135
92
  remaining(decimals: number): number;
package/dist/evm/types.js CHANGED
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
15
  };
@@ -51,9 +62,10 @@ var EvmContract = /** @class */ (function () {
51
62
  this.pauseCumulative = new bn_js_1.default(stream.pause_cumulative.toString());
52
63
  this.lastRateChangeTime = stream.last_rate_change_time.toNumber();
53
64
  this.fundsUnlockedAtLastRateChange = new bn_js_1.default(stream.funds_unlocked_at_last_rate_change.toString());
65
+ this.type = (0, contractUtils_1.buildStreamType)(this);
54
66
  }
55
67
  EvmContract.prototype.unlocked = function (currentTimestamp) {
56
- return (0, contractUtils_1.calculateUnlockedAmount)(this.depositedAmount, this.cliff, this.cliffAmount, this.end, currentTimestamp, this.lastRateChangeTime, this.period, this.amountPerPeriod, this.fundsUnlockedAtLastRateChange);
68
+ return (0, contractUtils_1.calculateUnlockedAmount)(__assign(__assign({}, this), { currentTimestamp: currentTimestamp }));
57
69
  };
58
70
  EvmContract.prototype.remaining = function (decimals) {
59
71
  return (0, utils_1.getNumberFromBN)(this.depositedAmount.sub(this.withdrawnAmount), decimals);
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
- export * as StreamflowSolana from "./solana";
2
1
  export * as StreamflowAptos from "./aptos";
3
2
  export * as StreamflowEVM from "./evm";
3
+ export * as StreamflowSolana from "./solana";
4
+ export * as StreamflowSui from "./sui";
4
5
  export * as Types from "./common/types";
5
6
  export * from "./common/utils";
7
+ export * from "./common/constants";
6
8
  export { default as GenericStreamClient } from "./common/GenericStreamClient";
package/dist/index.js CHANGED
@@ -29,11 +29,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
29
29
  return (mod && mod.__esModule) ? mod : { "default": mod };
30
30
  };
31
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.GenericStreamClient = exports.Types = exports.StreamflowEVM = exports.StreamflowAptos = exports.StreamflowSolana = void 0;
33
- exports.StreamflowSolana = __importStar(require("./solana"));
32
+ exports.GenericStreamClient = exports.Types = exports.StreamflowSui = exports.StreamflowSolana = exports.StreamflowEVM = exports.StreamflowAptos = void 0;
34
33
  exports.StreamflowAptos = __importStar(require("./aptos"));
35
34
  exports.StreamflowEVM = __importStar(require("./evm"));
35
+ exports.StreamflowSolana = __importStar(require("./solana"));
36
+ exports.StreamflowSui = __importStar(require("./sui"));
36
37
  exports.Types = __importStar(require("./common/types"));
37
38
  __exportStar(require("./common/utils"), exports);
39
+ __exportStar(require("./common/constants"), exports);
38
40
  var GenericStreamClient_1 = require("./common/GenericStreamClient");
39
41
  Object.defineProperty(exports, "GenericStreamClient", { enumerable: true, get: function () { return __importDefault(GenericStreamClient_1).default; } });
@@ -1,6 +1,6 @@
1
1
  import { Connection, Commitment, ConnectionConfig } from "@solana/web3.js";
2
- import { Stream as StreamData, ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt } from "./types";
3
- import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateResult, ICreateStreamData, IGetAllData, IGetOneData, IMultiTransactionResult, ITopUpData, ITransactionResult, ITransferData, IUpdateData, IWithdrawData } from "../common/types";
2
+ import { ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt } from "./types";
3
+ import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateResult, ICreateStreamData, IGetAllData, IGetOneData, IMultiTransactionResult, ITopUpData, ITransactionResult, ITransferData, IUpdateData, IWithdrawData, Stream } from "../common/types";
4
4
  import { BaseStreamClient } from "../common/BaseStreamClient";
5
5
  export default class SolanaStreamClient extends BaseStreamClient {
6
6
  private connection;
@@ -53,12 +53,12 @@ export default class SolanaStreamClient extends BaseStreamClient {
53
53
  /**
54
54
  * Fetch stream data by its id (address).
55
55
  */
56
- getOne({ id }: IGetOneData): Promise<StreamData>;
56
+ getOne({ id }: IGetOneData): Promise<Stream>;
57
57
  /**
58
58
  * Fetch streams/contracts by providing direction.
59
59
  * Streams are sorted by start time in ascending order.
60
60
  */
61
- get({ address, type, direction, }: IGetAllData): Promise<[string, StreamData][]>;
61
+ get({ address, type, direction, }: IGetAllData): Promise<[string, Stream][]>;
62
62
  private sign;
63
63
  /**
64
64
  * Attempts updating the stream auto withdrawal params and amount per period
@@ -748,13 +748,11 @@ var SolanaStreamClient = /** @class */ (function (_super) {
748
748
  sortedStreams = Object.entries(streams).sort(function (_a, _b) {
749
749
  var _c = __read(_a, 2), stream1 = _c[1];
750
750
  var _d = __read(_b, 2), stream2 = _d[1];
751
- return stream2.startTime - stream1.startTime;
751
+ return stream2.start - stream1.start;
752
752
  });
753
753
  if (type === "all")
754
754
  return [2 /*return*/, sortedStreams];
755
- return [2 /*return*/, type === "stream"
756
- ? sortedStreams.filter(function (stream) { return stream[1].canTopup; })
757
- : sortedStreams.filter(function (stream) { return !stream[1].canTopup; })];
755
+ return [2 /*return*/, sortedStreams.filter(function (stream) { return stream[1].type === type; })];
758
756
  }
759
757
  });
760
758
  });
@@ -16,4 +16,3 @@ export declare const WITHDRAWOR_PUBLIC_KEY: PublicKey;
16
16
  export declare const FEE_ORACLE_PUBLIC_KEY: PublicKey;
17
17
  export declare const AIRDROP_TEST_TOKEN = "Gssm3vfi8s65R31SBdmQRq6cKeYojGgup7whkw4VCiQj";
18
18
  export declare const AIRDROP_AMOUNT = 1;
19
- export declare const BASE_FEE = 1002500;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.BASE_FEE = exports.AIRDROP_AMOUNT = exports.AIRDROP_TEST_TOKEN = exports.FEE_ORACLE_PUBLIC_KEY = exports.WITHDRAWOR_PUBLIC_KEY = exports.STREAMFLOW_TREASURY_PUBLIC_KEY = exports.STREAMFLOW_DEVNET_PROGRAM_ID = exports.STREAMFLOW_PROGRAM_ID = exports.PROGRAM_ID = exports.CREATE_PARAMS_PADDING = exports.STREAM_STRUCT_OFFSET_RECIPIENT = exports.STREAM_STRUCT_OFFSET_SENDER = exports.TX_FINALITY_CONFIRMED = void 0;
4
+ exports.AIRDROP_AMOUNT = exports.AIRDROP_TEST_TOKEN = exports.FEE_ORACLE_PUBLIC_KEY = exports.WITHDRAWOR_PUBLIC_KEY = exports.STREAMFLOW_TREASURY_PUBLIC_KEY = exports.STREAMFLOW_DEVNET_PROGRAM_ID = exports.STREAMFLOW_PROGRAM_ID = exports.PROGRAM_ID = exports.CREATE_PARAMS_PADDING = exports.STREAM_STRUCT_OFFSET_RECIPIENT = exports.STREAM_STRUCT_OFFSET_SENDER = exports.TX_FINALITY_CONFIRMED = void 0;
5
5
  var web3_js_1 = require("@solana/web3.js");
6
6
  var types_1 = require("../common/types");
7
7
  exports.TX_FINALITY_CONFIRMED = "confirmed";
@@ -22,4 +22,3 @@ exports.WITHDRAWOR_PUBLIC_KEY = new web3_js_1.PublicKey("wdrwhnCv4pzW8beKsbPa4S2
22
22
  exports.FEE_ORACLE_PUBLIC_KEY = new web3_js_1.PublicKey("B743wFVk2pCYhV91cn287e1xY7f1vt4gdY48hhNiuQmT");
23
23
  exports.AIRDROP_TEST_TOKEN = "Gssm3vfi8s65R31SBdmQRq6cKeYojGgup7whkw4VCiQj";
24
24
  exports.AIRDROP_AMOUNT = 1; // 1 SOL is the cap on the testnet
25
- exports.BASE_FEE = 1002500; // Basic buffer for intermediary swaps