@streamflow/stream 3.0.4 → 3.0.7

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.
package/dist/Stream.js CHANGED
@@ -410,7 +410,7 @@ var Stream = /** @class */ (function () {
410
410
  if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
411
411
  throw new Error("Couldn't get account info.");
412
412
  }
413
- return [2 /*return*/, (0, utils_1.formatDecodedStream)((0, utils_1.decodeStream)(escrow === null || escrow === void 0 ? void 0 : escrow.data))];
413
+ return [2 /*return*/, new types_1.Contract((0, utils_1.decodeStream)(escrow === null || escrow === void 0 ? void 0 : escrow.data))];
414
414
  }
415
415
  });
416
416
  });
@@ -454,7 +454,7 @@ var Stream = /** @class */ (function () {
454
454
  streams = {};
455
455
  accounts.forEach(function (account) {
456
456
  var _a;
457
- var decoded = (0, utils_1.formatDecodedStream)((0, utils_1.decodeStream)(account.account.data));
457
+ var decoded = new types_1.Contract((0, utils_1.decodeStream)(account.account.data));
458
458
  streams = __assign(__assign({}, streams), (_a = {}, _a[account.pubkey.toBase58()] = decoded, _a));
459
459
  });
460
460
  sortedStreams = Object.entries(streams).sort(function (_a, _b) {
@@ -9,8 +9,9 @@ export default class StreamClient {
9
9
  /**
10
10
  * Create Stream instance
11
11
  */
12
- constructor(clusterUrl: string, cluster?: ClusterExtended, commitment?: Commitment | ConnectionConfig);
12
+ constructor(clusterUrl: string, cluster?: ClusterExtended, commitment?: Commitment | ConnectionConfig, programId?: string);
13
13
  getConnection(): web3.Connection;
14
+ getProgramId(): string;
14
15
  /**
15
16
  * Creates a new stream/vesting contract.
16
17
  * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
@@ -102,17 +102,24 @@ var StreamClient = /** @class */ (function () {
102
102
  /**
103
103
  * Create Stream instance
104
104
  */
105
- function StreamClient(clusterUrl, cluster, commitment) {
105
+ function StreamClient(clusterUrl, cluster, commitment, programId) {
106
106
  if (cluster === void 0) { cluster = types_1.Cluster.Mainnet; }
107
107
  if (commitment === void 0) { commitment = "confirmed"; }
108
+ if (programId === void 0) { programId = ""; }
108
109
  this.commitment = commitment;
109
110
  this.cluster = cluster;
110
111
  this.connection = new web3_js_1.Connection(clusterUrl, this.commitment);
111
112
  this.programId = new web3_js_1.PublicKey(constants_1.PROGRAM_ID[cluster]);
113
+ if (programId != "") {
114
+ this.programId = new web3_js_1.PublicKey(programId);
115
+ }
112
116
  }
113
117
  StreamClient.prototype.getConnection = function () {
114
118
  return this.connection;
115
119
  };
120
+ StreamClient.prototype.getProgramId = function () {
121
+ return this.programId.toBase58();
122
+ };
116
123
  /**
117
124
  * Creates a new stream/vesting contract.
118
125
  * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
@@ -598,7 +605,7 @@ var StreamClient = /** @class */ (function () {
598
605
  if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
599
606
  throw new Error("Couldn't get account info.");
600
607
  }
601
- return [2 /*return*/, (0, utils_1.formatDecodedStream)((0, utils_1.decodeStream)(escrow === null || escrow === void 0 ? void 0 : escrow.data))];
608
+ return [2 /*return*/, new types_1.Contract((0, utils_1.decodeStream)(escrow === null || escrow === void 0 ? void 0 : escrow.data))];
602
609
  }
603
610
  });
604
611
  });
@@ -620,10 +627,10 @@ var StreamClient = /** @class */ (function () {
620
627
  case 0:
621
628
  accounts = [];
622
629
  if (!(direction === "all")) return [3 /*break*/, 3];
623
- return [4 /*yield*/, getProgramAccounts(this.connection, wallet, constants_1.STREAM_STRUCT_OFFSET_SENDER, this.cluster)];
630
+ return [4 /*yield*/, getProgramAccounts(this.connection, wallet, constants_1.STREAM_STRUCT_OFFSET_SENDER, this.programId)];
624
631
  case 1:
625
632
  outgoingAccounts = _d.sent();
626
- return [4 /*yield*/, getProgramAccounts(this.connection, wallet, constants_1.STREAM_STRUCT_OFFSET_RECIPIENT, this.cluster)];
633
+ return [4 /*yield*/, getProgramAccounts(this.connection, wallet, constants_1.STREAM_STRUCT_OFFSET_RECIPIENT, this.programId)];
627
634
  case 2:
628
635
  incomingAccounts = _d.sent();
629
636
  accounts = __spreadArray(__spreadArray([], __read(outgoingAccounts), false), __read(incomingAccounts), false);
@@ -632,7 +639,7 @@ var StreamClient = /** @class */ (function () {
632
639
  offset = direction === "outgoing"
633
640
  ? constants_1.STREAM_STRUCT_OFFSET_SENDER
634
641
  : constants_1.STREAM_STRUCT_OFFSET_RECIPIENT;
635
- return [4 /*yield*/, getProgramAccounts(this.connection, wallet, offset, this.cluster)];
642
+ return [4 /*yield*/, getProgramAccounts(this.connection, wallet, offset, this.programId)];
636
643
  case 4:
637
644
  accounts = _d.sent();
638
645
  _d.label = 5;
@@ -640,7 +647,7 @@ var StreamClient = /** @class */ (function () {
640
647
  streams = {};
641
648
  accounts.forEach(function (account) {
642
649
  var _a;
643
- var decoded = (0, utils_1.formatDecodedStream)((0, utils_1.decodeStream)(account.account.data));
650
+ var decoded = new types_1.Contract((0, utils_1.decodeStream)(account.account.data));
644
651
  streams = __assign(__assign({}, streams), (_a = {}, _a[account.pubkey.toBase58()] = decoded, _a));
645
652
  });
646
653
  sortedStreams = Object.entries(streams).sort(function (_a, _b) {
@@ -772,11 +779,10 @@ var StreamClient = /** @class */ (function () {
772
779
  return StreamClient;
773
780
  }());
774
781
  exports.default = StreamClient;
775
- function getProgramAccounts(connection, wallet, offset, cluster) {
776
- if (cluster === void 0) { cluster = types_1.Cluster.Mainnet; }
782
+ function getProgramAccounts(connection, wallet, offset, programId) {
777
783
  return __awaiter(this, void 0, void 0, function () {
778
784
  return __generator(this, function (_a) {
779
- return [2 /*return*/, connection === null || connection === void 0 ? void 0 : connection.getProgramAccounts(new web3_js_1.PublicKey(constants_1.PROGRAM_ID[cluster]), {
785
+ return [2 /*return*/, connection === null || connection === void 0 ? void 0 : connection.getProgramAccounts(programId, {
780
786
  filters: [
781
787
  {
782
788
  memcmp: {
package/dist/types.d.ts CHANGED
@@ -85,7 +85,7 @@ export interface WithdrawStreamParams extends WithdrawStreamData {
85
85
  cluster?: ClusterExtended;
86
86
  }
87
87
  export interface WithdrawParams extends WithdrawStreamData {
88
- invoker: Wallet;
88
+ invoker: Wallet | Keypair;
89
89
  }
90
90
  export interface TopupStreamData {
91
91
  id: string;
@@ -97,7 +97,7 @@ export interface TopupStreamParams extends TopupStreamData {
97
97
  cluster?: ClusterExtended;
98
98
  }
99
99
  export interface TopupParams extends TopupStreamData {
100
- invoker: Wallet;
100
+ invoker: Wallet | Keypair;
101
101
  }
102
102
  export interface CancelStreamData {
103
103
  id: string;
@@ -108,7 +108,7 @@ export interface CancelStreamParams extends CancelStreamData {
108
108
  cluster?: ClusterExtended;
109
109
  }
110
110
  export interface CancelParams extends CancelStreamData {
111
- invoker: Wallet;
111
+ invoker: Wallet | Keypair;
112
112
  }
113
113
  export interface TransferStreamData {
114
114
  id: string;
@@ -120,7 +120,7 @@ export interface TransferStreamParams extends TransferStreamData {
120
120
  cluster?: ClusterExtended;
121
121
  }
122
122
  export interface TransferParams extends TransferStreamData {
123
- invoker: Wallet;
123
+ invoker: Wallet | Keypair;
124
124
  }
125
125
  export interface GetStreamParams {
126
126
  connection: Connection;
@@ -176,6 +176,49 @@ export interface Stream {
176
176
  canTopup: boolean;
177
177
  name: string;
178
178
  withdrawalFrequency: number;
179
+ unlocked(currentTimestamp: number, decimals: number): number;
180
+ }
181
+ export declare class Contract implements Stream {
182
+ magic: number;
183
+ version: number;
184
+ createdAt: number;
185
+ withdrawnAmount: BN;
186
+ canceledAt: number;
187
+ end: number;
188
+ lastWithdrawnAt: number;
189
+ sender: string;
190
+ senderTokens: string;
191
+ recipient: string;
192
+ recipientTokens: string;
193
+ mint: string;
194
+ escrowTokens: string;
195
+ streamflowTreasury: string;
196
+ streamflowTreasuryTokens: string;
197
+ streamflowFeeTotal: BN;
198
+ streamflowFeeWithdrawn: BN;
199
+ streamflowFeePercent: number;
200
+ partnerFeeTotal: BN;
201
+ partnerFeeWithdrawn: BN;
202
+ partnerFeePercent: number;
203
+ partner: string;
204
+ partnerTokens: string;
205
+ start: number;
206
+ depositedAmount: BN;
207
+ period: number;
208
+ amountPerPeriod: BN;
209
+ cliff: number;
210
+ cliffAmount: BN;
211
+ cancelableBySender: boolean;
212
+ cancelableByRecipient: boolean;
213
+ automaticWithdrawal: boolean;
214
+ transferableBySender: boolean;
215
+ transferableByRecipient: boolean;
216
+ canTopup: boolean;
217
+ name: string;
218
+ withdrawalFrequency: number;
219
+ constructor(stream: DecodedStream);
220
+ unlocked(currentTimestamp: number, decimals: number): number;
221
+ remaining(decimals: number): number;
179
222
  }
180
223
  export interface DecodedStream {
181
224
  magic: BN;
package/dist/types.js CHANGED
@@ -1,6 +1,11 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TransferCancelOptions = exports.LocalCluster = exports.StreamType = exports.StreamDirection = exports.Cluster = void 0;
6
+ exports.TransferCancelOptions = exports.Contract = exports.LocalCluster = exports.StreamType = exports.StreamDirection = exports.Cluster = void 0;
7
+ var bn_js_1 = __importDefault(require("bn.js"));
8
+ var utils_1 = require("./utils");
4
9
  var wallet_adapter_base_1 = require("@solana/wallet-adapter-base");
5
10
  Object.defineProperty(exports, "Cluster", { enumerable: true, get: function () { return wallet_adapter_base_1.WalletAdapterNetwork; } });
6
11
  var StreamDirection;
@@ -19,6 +24,64 @@ var LocalCluster;
19
24
  (function (LocalCluster) {
20
25
  LocalCluster["Local"] = "local";
21
26
  })(LocalCluster = exports.LocalCluster || (exports.LocalCluster = {}));
27
+ var Contract = /** @class */ (function () {
28
+ function Contract(stream) {
29
+ var _a;
30
+ this.magic = stream.magic.toNumber();
31
+ this.version = stream.version.toNumber();
32
+ this.createdAt = stream.createdAt.toNumber();
33
+ this.withdrawnAmount = stream.withdrawnAmount;
34
+ this.canceledAt = stream.canceledAt.toNumber();
35
+ this.end = stream.end.toNumber();
36
+ this.lastWithdrawnAt = stream.lastWithdrawnAt.toNumber();
37
+ this.sender = stream.sender.toBase58();
38
+ this.senderTokens = stream.senderTokens.toBase58();
39
+ this.recipient = stream.recipient.toBase58();
40
+ this.recipientTokens = stream.recipientTokens.toBase58();
41
+ this.mint = stream.mint.toBase58();
42
+ this.escrowTokens = stream.escrowTokens.toBase58();
43
+ this.streamflowTreasury = stream.streamflowTreasury.toBase58();
44
+ this.streamflowTreasuryTokens =
45
+ stream.streamflowTreasuryTokens.toBase58();
46
+ this.streamflowFeeTotal = stream.streamflowFeeTotal;
47
+ this.streamflowFeeWithdrawn = stream.streamflowFeeWithdrawn;
48
+ this.streamflowFeePercent = stream.streamflowFeePercent.toNumber();
49
+ this.partnerFeeTotal = stream.partnerFeeTotal;
50
+ this.partnerFeeWithdrawn = stream.partnerFeeWithdrawn;
51
+ this.partnerFeePercent = stream.partnerFeePercent.toNumber();
52
+ this.partner = stream.partner.toBase58();
53
+ this.partnerTokens = (_a = stream.partnerTokens) === null || _a === void 0 ? void 0 : _a.toBase58();
54
+ this.start = stream.start.toNumber();
55
+ this.depositedAmount = stream.depositedAmount;
56
+ this.period = stream.period.toNumber();
57
+ this.amountPerPeriod = stream.amountPerPeriod;
58
+ this.cliff = stream.cliff.toNumber();
59
+ this.cliffAmount = stream.cliffAmount;
60
+ this.cancelableBySender = stream.cancelableBySender;
61
+ this.cancelableByRecipient = stream.cancelableByRecipient;
62
+ this.automaticWithdrawal = stream.automaticWithdrawal;
63
+ this.transferableBySender = stream.transferableBySender;
64
+ this.transferableByRecipient = stream.transferableByRecipient;
65
+ this.canTopup = stream.canTopup;
66
+ this.name = stream.name;
67
+ this.withdrawalFrequency = stream.withdrawFrequency.toNumber();
68
+ }
69
+ Contract.prototype.unlocked = function (currentTimestamp, decimals) {
70
+ var deposited = (0, utils_1.getNumberFromBN)(this.depositedAmount, decimals);
71
+ if (currentTimestamp < this.cliff)
72
+ return 0;
73
+ if (currentTimestamp > this.end)
74
+ return deposited;
75
+ var streamedBN = this.cliffAmount.add(new bn_js_1.default(Math.floor((currentTimestamp - this.cliff) / this.period)).mul(this.amountPerPeriod));
76
+ var streamed = (0, utils_1.getNumberFromBN)(streamedBN, decimals);
77
+ return streamed < deposited ? streamed : deposited;
78
+ };
79
+ Contract.prototype.remaining = function (decimals) {
80
+ return (0, utils_1.getNumberFromBN)(this.depositedAmount.sub(this.withdrawnAmount), decimals);
81
+ };
82
+ return Contract;
83
+ }());
84
+ exports.Contract = Contract;
22
85
  var TransferCancelOptions;
23
86
  (function (TransferCancelOptions) {
24
87
  TransferCancelOptions["Recipient"] = "recipient";
package/dist/utils.js CHANGED
@@ -52,9 +52,11 @@ var decodeStream = function (buf) {
52
52
  };
53
53
  };
54
54
  exports.decodeStream = decodeStream;
55
+ // DeprecationWarning: This object will be deprecated starting from the version 4.0.0. Use
56
+ // types/Contract instead
55
57
  var formatDecodedStream = function (stream) {
56
58
  var _a;
57
- return ({
59
+ var resp = {
58
60
  magic: stream.magic.toNumber(),
59
61
  version: stream.version.toNumber(),
60
62
  createdAt: stream.createdAt.toNumber(),
@@ -92,7 +94,10 @@ var formatDecodedStream = function (stream) {
92
94
  canTopup: stream.canTopup,
93
95
  name: stream.name,
94
96
  withdrawalFrequency: stream.withdrawFrequency.toNumber(),
95
- });
97
+ unlocked: function () { return 0; },
98
+ withdrawn: function () { return new bn_js_1.default(0); } //phantom method to preserve partial support of this object
99
+ };
100
+ return resp;
96
101
  };
97
102
  exports.formatDecodedStream = formatDecodedStream;
98
103
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamflow/stream",
3
- "version": "3.0.4",
3
+ "version": "3.0.7",
4
4
  "description": "JavaScript SDK to interact with Streamflow protocol.",
5
5
  "main": "dist/index.js",
6
6
  "homepage": "https://github.com/streamflow-finance/js-sdk/",