@streamflow/stream 4.0.0-Alpha.1 → 4.0.0-Alpha.3

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.
@@ -62,7 +62,7 @@ describe("AptosStreamClient", function () {
62
62
  it("should correctly set passed params", function () {
63
63
  var pid = "PID";
64
64
  var gas = "30";
65
- var instance = new StreamClient_1.default(types_1.ICluster.Devnet, gas, pid);
65
+ var instance = new StreamClient_1.default("https://cluster", types_1.ICluster.Devnet, gas, pid);
66
66
  expect(instance.getMaxGas()).toEqual({ max_gas_amount: gas });
67
67
  expect(instance.getProgramId()).toBe(pid);
68
68
  });
@@ -70,9 +70,9 @@ describe("AptosStreamClient", function () {
70
70
  describe("create", function () {
71
71
  var pid = "PID";
72
72
  var gas = "30";
73
- var instance = new StreamClient_1.default(types_1.ICluster.Devnet, gas, pid);
73
+ var instance = new StreamClient_1.default("https://cluster", types_1.ICluster.Devnet, gas, pid);
74
74
  beforeEach(function () {
75
- instance = new StreamClient_1.default(types_1.ICluster.Devnet, gas, pid);
75
+ instance = new StreamClient_1.default("https://cluster", types_1.ICluster.Devnet, gas, pid);
76
76
  });
77
77
  test("should create a stream with passed parameters", function () { return __awaiter(void 0, void 0, void 0, function () {
78
78
  var mockSigner, mockWallet, mockRecipient, mockData, mockReturn, result, callParam, args;
@@ -117,11 +117,11 @@ describe("AptosStreamClient", function () {
117
117
  delete callParam.arguments;
118
118
  args.shift();
119
119
  expect(args).toEqual([
120
- mockRecipient.amount,
120
+ mockRecipient.amount.toString(),
121
121
  100,
122
- mockRecipient.amountPerPeriod,
122
+ mockRecipient.amountPerPeriod.toString(),
123
123
  10,
124
- mockRecipient.cliffAmount,
124
+ mockRecipient.cliffAmount.toString(),
125
125
  true,
126
126
  false,
127
127
  false,
@@ -131,7 +131,7 @@ describe("AptosStreamClient", function () {
131
131
  false,
132
132
  false,
133
133
  10,
134
- "5354524d",
134
+ "test name",
135
135
  "0xtest",
136
136
  ]);
137
137
  expect(callParam).toEqual({
@@ -1,17 +1,18 @@
1
- import { GenericStreamClient } from "../common/StreamClient";
2
- import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateStreamData, ITopUpData, ITransferData, IWithdrawData } from "../common/types";
3
- import { ICreateStreamAptosExt, ITransactionAptosExt, ITransactionResult } from "./types";
4
- export default class AptosStreamClient extends GenericStreamClient {
1
+ import { BaseStreamClient } from "../common/BaseStreamClient";
2
+ import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IWithdrawData } from "../common/types";
3
+ import { ICreateStreamAptosExt, IMultiTransactionResult, ITransactionAptosExt, ITransactionResult } from "./types";
4
+ export default class AptosStreamClient extends BaseStreamClient {
5
5
  private programId;
6
6
  private maxGas;
7
- constructor(cluster: ICluster, maxGas?: string, programId?: string);
7
+ private client;
8
+ constructor(clusterUrl: string, cluster?: ICluster, maxGas?: string, programId?: string);
8
9
  create(streamData: ICreateStreamData, { senderWallet }: ICreateStreamAptosExt): Promise<ITransactionResult>;
9
- createMultiple(multipleStreamData: ICreateMultipleStreamData, { senderWallet }: ICreateStreamAptosExt): Promise<ITransactionResult[]>;
10
+ createMultiple(multipleStreamData: ICreateMultipleStreamData, { senderWallet }: ICreateStreamAptosExt): Promise<IMultiTransactionResult>;
10
11
  withdraw(withdrawData: IWithdrawData, { senderWallet, tokenId }: ITransactionAptosExt): Promise<ITransactionResult>;
11
12
  cancel(cancelData: ICancelData, { senderWallet, tokenId }: ITransactionAptosExt): Promise<any>;
12
13
  transfer(transferData: ITransferData, { senderWallet, tokenId }: ITransactionAptosExt): Promise<any>;
13
14
  topup(topupData: ITopUpData, { senderWallet, tokenId }: ITransactionAptosExt): Promise<any>;
14
- getOne(): Promise<any>;
15
+ getOne({ id }: IGetOneData): Promise<any>;
15
16
  getProgramId(): string;
16
17
  getMaxGas(): {
17
18
  max_gas_amount: string;
@@ -50,65 +50,53 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
50
50
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
51
  }
52
52
  };
53
- var __values = (this && this.__values) || function(o) {
54
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
55
- if (m) return m.call(o);
56
- if (o && typeof o.length === "number") return {
57
- next: function () {
58
- if (o && i >= o.length) o = void 0;
59
- return { value: o && o[i++], done: !o };
60
- }
61
- };
62
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
63
- };
64
53
  Object.defineProperty(exports, "__esModule", { value: true });
65
54
  var aptos_1 = require("aptos");
66
- var StreamClient_1 = require("../common/StreamClient");
55
+ var BaseStreamClient_1 = require("../common/BaseStreamClient");
67
56
  var types_1 = require("../common/types");
68
57
  var constants_1 = require("./constants");
58
+ var types_2 = require("./types");
69
59
  var AptosStreamClient = /** @class */ (function (_super) {
70
60
  __extends(AptosStreamClient, _super);
71
- function AptosStreamClient(cluster, maxGas, programId) {
61
+ function AptosStreamClient(clusterUrl, cluster, maxGas, programId) {
62
+ if (cluster === void 0) { cluster = types_1.ICluster.Mainnet; }
72
63
  if (maxGas === void 0) { maxGas = "10000"; }
73
64
  var _this = _super.call(this) || this;
74
- _this.programId = programId
75
- ? programId
76
- : constants_1.APTOS_PROGRAM_IDS[cluster] || constants_1.APTOS_PROGRAM_IDS[types_1.ICluster.Mainnet];
65
+ _this.programId = programId ? programId : constants_1.APTOS_PROGRAM_IDS[cluster];
77
66
  _this.maxGas = maxGas;
67
+ _this.client = new aptos_1.AptosClient(clusterUrl);
78
68
  return _this;
79
69
  }
80
70
  AptosStreamClient.prototype.create = function (streamData, _a) {
81
71
  var senderWallet = _a.senderWallet;
82
72
  return __awaiter(this, void 0, void 0, function () {
83
- var acc, seeds, strmEncoded, name, payload, hash;
73
+ var acc, seeds, payload, hash;
84
74
  return __generator(this, function (_b) {
85
75
  switch (_b.label) {
86
76
  case 0:
87
77
  acc = new aptos_1.AptosAccount();
88
78
  seeds = acc.address().hex();
89
- strmEncoded = new TextEncoder().encode("STRM");
90
- name = Buffer.from(strmEncoded).toString("hex");
91
79
  payload = {
92
80
  type: "create",
93
81
  function: "".concat(this.programId, "::protocol::create"),
94
82
  type_arguments: [streamData.tokenId],
95
83
  arguments: [
96
84
  seeds,
97
- streamData.amount,
85
+ streamData.amount.toString(),
98
86
  streamData.period,
99
- streamData.amountPerPeriod,
87
+ streamData.amountPerPeriod.toString(),
100
88
  streamData.start,
101
- streamData.cliffAmount,
89
+ streamData.cliffAmount.toString(),
102
90
  streamData.cancelableBySender,
103
91
  streamData.cancelableByRecipient,
104
92
  streamData.transferableBySender,
105
93
  streamData.transferableByRecipient,
106
94
  streamData.canTopup,
107
- streamData.canPause,
108
- streamData.canUpdateRate,
109
- streamData.automaticWithdrawal,
110
- streamData.withdrawalFrequency,
111
- name,
95
+ streamData.canPause || false,
96
+ streamData.canUpdateRate || false,
97
+ streamData.automaticWithdrawal || false,
98
+ streamData.withdrawalFrequency || 0,
99
+ streamData.name,
112
100
  streamData.recipient,
113
101
  ],
114
102
  };
@@ -121,43 +109,53 @@ var AptosStreamClient = /** @class */ (function (_super) {
121
109
  });
122
110
  };
123
111
  AptosStreamClient.prototype.createMultiple = function (multipleStreamData, _a) {
112
+ var _b;
124
113
  var senderWallet = _a.senderWallet;
125
114
  return __awaiter(this, void 0, void 0, function () {
126
- var payloads, ids, payloads_1, payloads_1_1, payload, hash, e_1_1;
127
- var e_1, _b;
115
+ var payloads, txs, metadatas, metadataToRecipient, errors, i, payload, recipient, hash, e_1, metadataId;
128
116
  return __generator(this, function (_c) {
129
117
  switch (_c.label) {
130
118
  case 0:
131
119
  payloads = this.generateMultiPayloads(multipleStreamData);
132
- ids = [];
120
+ txs = [];
121
+ metadatas = [];
122
+ metadataToRecipient = {};
123
+ errors = [];
124
+ i = 0;
133
125
  _c.label = 1;
134
126
  case 1:
135
- _c.trys.push([1, 6, 7, 8]);
136
- payloads_1 = __values(payloads), payloads_1_1 = payloads_1.next();
127
+ if (!(i < payloads.length)) return [3 /*break*/, 7];
128
+ payload = payloads[i];
129
+ recipient = multipleStreamData.recipients[i];
137
130
  _c.label = 2;
138
131
  case 2:
139
- if (!!payloads_1_1.done) return [3 /*break*/, 5];
140
- payload = payloads_1_1.value;
132
+ _c.trys.push([2, 4, 5, 6]);
141
133
  return [4 /*yield*/, senderWallet.signAndSubmitTransaction(payload)];
142
134
  case 3:
143
135
  hash = (_c.sent()).hash;
144
- ids.push({ txId: hash });
145
- _c.label = 4;
136
+ txs.push(hash);
137
+ return [3 /*break*/, 6];
146
138
  case 4:
147
- payloads_1_1 = payloads_1.next();
148
- return [3 /*break*/, 2];
149
- case 5: return [3 /*break*/, 8];
150
- case 6:
151
- e_1_1 = _c.sent();
152
- e_1 = { error: e_1_1 };
153
- return [3 /*break*/, 8];
154
- case 7:
155
- try {
156
- if (payloads_1_1 && !payloads_1_1.done && (_b = payloads_1.return)) _b.call(payloads_1);
157
- }
158
- finally { if (e_1) throw e_1.error; }
139
+ e_1 = _c.sent();
140
+ errors.push({
141
+ error: (_b = e_1 === null || e_1 === void 0 ? void 0 : e_1.toString()) !== null && _b !== void 0 ? _b : "Unkown error!",
142
+ recipient: recipient.recipient,
143
+ });
144
+ return [3 /*break*/, 6];
145
+ case 5:
146
+ metadataId = payload.arguments[0];
147
+ metadatas.push(metadataId);
148
+ metadataToRecipient[metadataId] = recipient;
159
149
  return [7 /*endfinally*/];
160
- case 8: return [2 /*return*/, ids];
150
+ case 6:
151
+ i++;
152
+ return [3 /*break*/, 1];
153
+ case 7: return [2 /*return*/, {
154
+ txs: txs,
155
+ metadatas: metadatas,
156
+ metadataToRecipient: metadataToRecipient,
157
+ errors: errors,
158
+ }];
161
159
  }
162
160
  });
163
161
  });
@@ -246,10 +244,25 @@ var AptosStreamClient = /** @class */ (function (_super) {
246
244
  });
247
245
  });
248
246
  };
249
- AptosStreamClient.prototype.getOne = function () {
247
+ AptosStreamClient.prototype.getOne = function (_a) {
248
+ var _b;
249
+ var id = _a.id;
250
250
  return __awaiter(this, void 0, void 0, function () {
251
- return __generator(this, function (_a) {
252
- throw new Error("Not implemented.");
251
+ var contractResources, contract, tokenIdMatch, tokenId, data;
252
+ return __generator(this, function (_c) {
253
+ switch (_c.label) {
254
+ case 0: return [4 /*yield*/, this.client.getAccountResources(id)];
255
+ case 1:
256
+ contractResources = _c.sent();
257
+ contract = contractResources.find(function (r) { return r.type.includes("protocol::Contract"); });
258
+ if (!contract) {
259
+ throw new Error("Contract with id ".concat(id, " could not be found!"));
260
+ }
261
+ tokenIdMatch = contract.type.match(/0x[0-9a-f]+::protocol::Contract<(.*)>/);
262
+ tokenId = (_b = tokenIdMatch === null || tokenIdMatch === void 0 ? void 0 : tokenIdMatch[1]) !== null && _b !== void 0 ? _b : "";
263
+ data = contract.data;
264
+ return [2 /*return*/, [id, new types_2.Contract(data, tokenId)]];
265
+ }
253
266
  });
254
267
  });
255
268
  };
@@ -264,34 +277,32 @@ var AptosStreamClient = /** @class */ (function (_super) {
264
277
  return multipleStreamData.recipients.map(function (recipient) {
265
278
  var acc = new aptos_1.AptosAccount(); // Generate random address as seeds for derriving "escrow" account
266
279
  var seeds = acc.address().hex();
267
- var strmEncoded = new TextEncoder().encode("STRM");
268
- var name = Buffer.from(strmEncoded).toString("hex");
269
280
  return {
270
281
  type: "create",
271
282
  function: "".concat(_this.programId, "::protocol::create"),
272
283
  type_arguments: [multipleStreamData.tokenId],
273
284
  arguments: [
274
285
  seeds,
275
- recipient.amount,
286
+ recipient.amount.toString(),
276
287
  multipleStreamData.period,
277
- recipient.amountPerPeriod,
288
+ recipient.amountPerPeriod.toString(),
278
289
  multipleStreamData.start,
279
- recipient.cliffAmount,
290
+ recipient.cliffAmount.toString(),
280
291
  multipleStreamData.cancelableBySender,
281
292
  multipleStreamData.cancelableByRecipient,
282
293
  multipleStreamData.transferableBySender,
283
294
  multipleStreamData.transferableByRecipient,
284
295
  multipleStreamData.canTopup,
285
- multipleStreamData.canPause,
286
- multipleStreamData.canUpdateRate,
287
- multipleStreamData.automaticWithdrawal,
288
- multipleStreamData.withdrawalFrequency,
289
- name,
296
+ multipleStreamData.canPause || false,
297
+ multipleStreamData.canUpdateRate || false,
298
+ multipleStreamData.automaticWithdrawal || false,
299
+ multipleStreamData.withdrawalFrequency || 0,
300
+ recipient.name,
290
301
  recipient.recipient,
291
302
  ],
292
303
  };
293
304
  });
294
305
  };
295
306
  return AptosStreamClient;
296
- }(StreamClient_1.GenericStreamClient));
307
+ }(BaseStreamClient_1.BaseStreamClient));
297
308
  exports.default = AptosStreamClient;
@@ -5,8 +5,8 @@ exports.APTOS_PROGRAM_IDS = void 0;
5
5
  var types_1 = require("../common/types");
6
6
  exports.APTOS_PROGRAM_IDS = (_a = {},
7
7
  _a[types_1.ICluster.Mainnet] = "0x9009d93d52576bf9ac6dc6cf10b870610bcb316342fef6eff80662fbbfce51b0",
8
- _a[types_1.ICluster.Devnet] = "0x1dda724347d7776cb1817054eaf49d03cb6f58dae92c90d62edd5d3b90ba733c",
9
8
  // TODO: Add a correct programID for Test net
10
- _a[types_1.ICluster.Testnet] = "0x1dda724347d7776cb1817054eaf49d03cb6f58dae92c90d62edd5d3b90ba733c",
9
+ _a[types_1.ICluster.Devnet] = "0xc6737de143d91b2f99a7e490d4f8348fdfa3bdd1eb8737a27d0455f8a3625688",
10
+ _a[types_1.ICluster.Testnet] = "0xc6737de143d91b2f99a7e490d4f8348fdfa3bdd1eb8737a27d0455f8a3625688",
11
11
  _a[types_1.ICluster.Local] = "0x9009d93d52576bf9ac6dc6cf10b870610bcb316342fef6eff80662fbbfce51b0",
12
12
  _a);
@@ -1,2 +1,2 @@
1
- export { default } from "./StreamClient";
1
+ export { default, default as AptosStreamClient } from "./StreamClient";
2
2
  export * from "./types";
@@ -17,7 +17,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.default = void 0;
20
+ exports.AptosStreamClient = exports.default = void 0;
21
21
  var StreamClient_1 = require("./StreamClient");
22
22
  Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(StreamClient_1).default; } });
23
+ Object.defineProperty(exports, "AptosStreamClient", { enumerable: true, get: function () { return __importDefault(StreamClient_1).default; } });
23
24
  __exportStar(require("./types"), exports);
@@ -1,10 +1,145 @@
1
1
  import { WalletContextState } from "@manahippo/aptos-wallet-adapter";
2
+ import BN from "bn.js";
3
+ import { IRecipient } from "../common/types";
2
4
  export interface ICreateStreamAptosExt {
3
5
  senderWallet: WalletContextState;
4
6
  }
7
+ declare type MetadataId = string;
8
+ export interface CreateMultiError {
9
+ recipient: string;
10
+ error: string;
11
+ }
12
+ export interface IMultiTransactionResult {
13
+ txs: string[];
14
+ metadatas: MetadataId[];
15
+ metadataToRecipient: Record<MetadataId, IRecipient>;
16
+ errors: CreateMultiError[];
17
+ }
5
18
  export interface ITransactionResult {
6
19
  txId: string;
7
20
  }
8
21
  export declare type ITransactionAptosExt = ICreateStreamAptosExt & {
9
22
  tokenId: string;
10
23
  };
24
+ export interface StreamResource {
25
+ amount: string;
26
+ amount_per_period: string;
27
+ canceled_at: string;
28
+ cliff_amount: string;
29
+ closed: boolean;
30
+ contract_signer_cap: {
31
+ account: string;
32
+ };
33
+ created: string;
34
+ current_pause_start: string;
35
+ end: string;
36
+ fees: {
37
+ streamflow_fee: string;
38
+ streamflow_fee_percentage: string;
39
+ streamflow_fee_withdrawn: string;
40
+ };
41
+ funds_unlocked_at_last_rate_change: string;
42
+ last_rate_change_time: string;
43
+ last_withdrawn_at: string;
44
+ meta: {
45
+ automatic_withdrawal: boolean;
46
+ can_topup: boolean;
47
+ can_update_rate: boolean;
48
+ cancelable_by_recipient: boolean;
49
+ cancelable_by_sender: boolean;
50
+ contract_name: string;
51
+ pausable: boolean;
52
+ transferable_by_recipient: boolean;
53
+ transferable_by_sender: boolean;
54
+ withdrawal_frequency: string;
55
+ };
56
+ pause_cumulative: string;
57
+ period: string;
58
+ recipient: string;
59
+ sender: string;
60
+ start: string;
61
+ withdrawn: string;
62
+ }
63
+ export interface Stream {
64
+ magic: number;
65
+ version: number;
66
+ createdAt: number;
67
+ withdrawnAmount: BN;
68
+ canceledAt: number;
69
+ end: number;
70
+ lastWithdrawnAt: number;
71
+ sender: string;
72
+ senderTokens: string;
73
+ recipient: string;
74
+ recipientTokens: string;
75
+ mint: string;
76
+ escrowTokens: string;
77
+ streamflowTreasury: string;
78
+ streamflowTreasuryTokens: string;
79
+ streamflowFeeTotal: BN;
80
+ streamflowFeeWithdrawn: BN;
81
+ streamflowFeePercent: number;
82
+ partnerFeeTotal: BN;
83
+ partnerFeeWithdrawn: BN;
84
+ partnerFeePercent: number;
85
+ partner: string;
86
+ partnerTokens: string;
87
+ start: number;
88
+ depositedAmount: BN;
89
+ period: number;
90
+ amountPerPeriod: BN;
91
+ cliff: number;
92
+ cliffAmount: BN;
93
+ cancelableBySender: boolean;
94
+ cancelableByRecipient: boolean;
95
+ automaticWithdrawal: boolean;
96
+ transferableBySender: boolean;
97
+ transferableByRecipient: boolean;
98
+ canTopup: boolean;
99
+ name: string;
100
+ withdrawalFrequency: number;
101
+ unlocked(currentTimestamp: number, decimals: number): number;
102
+ }
103
+ export declare class Contract implements 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
+ constructor(stream: StreamResource, tokenId: string);
142
+ unlocked(currentTimestamp: number, decimals: number): number;
143
+ remaining(decimals: number): number;
144
+ }
145
+ export {};
@@ -1,2 +1,65 @@
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 });
6
+ exports.Contract = void 0;
7
+ var bn_js_1 = __importDefault(require("bn.js"));
8
+ var utils_1 = require("../common/utils");
9
+ var Contract = /** @class */ (function () {
10
+ function Contract(stream, tokenId) {
11
+ this.magic = 0;
12
+ this.version = 0;
13
+ this.createdAt = parseInt(stream.created);
14
+ this.withdrawnAmount = new bn_js_1.default(stream.withdrawn);
15
+ this.canceledAt = parseInt(stream.canceled_at);
16
+ this.end = parseInt(stream.end);
17
+ this.lastWithdrawnAt = parseInt(stream.last_withdrawn_at);
18
+ this.sender = stream.sender;
19
+ this.senderTokens = stream.sender;
20
+ this.recipient = stream.recipient;
21
+ this.recipientTokens = stream.recipient;
22
+ this.mint = tokenId;
23
+ this.escrowTokens = "";
24
+ this.streamflowTreasury = "";
25
+ this.streamflowTreasuryTokens = "";
26
+ this.streamflowFeeTotal = new bn_js_1.default(0);
27
+ this.streamflowFeeWithdrawn = new bn_js_1.default(0);
28
+ this.streamflowFeePercent = parseInt(stream.fees.streamflow_fee_percentage) / 10000;
29
+ this.partnerFeeTotal = new bn_js_1.default(0);
30
+ this.partnerFeeWithdrawn = new bn_js_1.default(0);
31
+ this.partnerFeePercent = 0;
32
+ this.partner = "";
33
+ this.partnerTokens = "";
34
+ this.start = parseInt(stream.start);
35
+ this.depositedAmount = new bn_js_1.default(stream.amount);
36
+ this.period = parseInt(stream.period);
37
+ this.amountPerPeriod = new bn_js_1.default(stream.amount_per_period);
38
+ this.cliff = parseInt(stream.start);
39
+ this.cliffAmount = new bn_js_1.default(stream.cliff_amount);
40
+ this.cancelableBySender = stream.meta.cancelable_by_sender;
41
+ this.cancelableByRecipient = stream.meta.cancelable_by_recipient;
42
+ this.automaticWithdrawal = stream.meta.automatic_withdrawal;
43
+ this.transferableBySender = stream.meta.transferable_by_sender;
44
+ this.transferableByRecipient = stream.meta.transferable_by_recipient;
45
+ this.canTopup = stream.meta.can_topup;
46
+ var name = stream.meta.contract_name.replace("0x", "");
47
+ this.name = Buffer.from(name, "hex").toString("utf8");
48
+ this.withdrawalFrequency = parseInt(stream.meta.withdrawal_frequency);
49
+ }
50
+ Contract.prototype.unlocked = function (currentTimestamp, decimals) {
51
+ var deposited = (0, utils_1.getNumberFromBN)(this.depositedAmount, decimals);
52
+ if (currentTimestamp < this.cliff)
53
+ return 0;
54
+ if (currentTimestamp > this.end)
55
+ return deposited;
56
+ var streamedBN = this.cliffAmount.add(new bn_js_1.default(Math.floor((currentTimestamp - this.cliff) / this.period)).mul(this.amountPerPeriod));
57
+ var streamed = (0, utils_1.getNumberFromBN)(streamedBN, decimals);
58
+ return streamed < deposited ? streamed : deposited;
59
+ };
60
+ Contract.prototype.remaining = function (decimals) {
61
+ return (0, utils_1.getNumberFromBN)(this.depositedAmount.sub(this.withdrawnAmount), decimals);
62
+ };
63
+ return Contract;
64
+ }());
65
+ exports.Contract = Contract;
@@ -1,5 +1,5 @@
1
1
  import { ICreateStreamData, ICreateMultipleStreamData, IWithdrawData, ICancelData, ITransferData, ITopUpData, IGetOneData } from "./types";
2
- export declare abstract class GenericStreamClient {
2
+ export declare abstract class BaseStreamClient {
3
3
  abstract create(streamData: ICreateStreamData, ...chainSpecificParams: any[]): Promise<any>;
4
4
  abstract createMultiple(multipleStreamData: ICreateMultipleStreamData, ...chainSpecificParams: any[]): Promise<any>;
5
5
  abstract withdraw(withdrawData: IWithdrawData, ...chainSpecificParams: any[]): Promise<any>;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseStreamClient = void 0;
4
+ var BaseStreamClient = /** @class */ (function () {
5
+ function BaseStreamClient() {
6
+ }
7
+ return BaseStreamClient;
8
+ }());
9
+ exports.BaseStreamClient = BaseStreamClient;
@@ -0,0 +1,35 @@
1
+ import { Commitment, ConnectionConfig } from "@solana/web3.js";
2
+ import SolanaStreamClient from "../solana/StreamClient";
3
+ import AptosStreamClient from "../aptos/StreamClient";
4
+ import { BaseStreamClient } from "./BaseStreamClient";
5
+ import { ICancelData, IChain, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IWithdrawData } from "./types";
6
+ import { ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt } from "../solana";
7
+ import { ICreateStreamAptosExt, ITransactionAptosExt } from "../aptos";
8
+ export interface SolanaStreamClientOptions {
9
+ chain: IChain.Solana;
10
+ clusterUrl: string;
11
+ cluster?: ICluster;
12
+ programId?: string;
13
+ commitment?: Commitment | ConnectionConfig;
14
+ }
15
+ export interface AptosStreamClientOptions {
16
+ chain: IChain.Aptos;
17
+ clusterUrl: string;
18
+ cluster?: ICluster;
19
+ programId?: string;
20
+ maxGas?: string;
21
+ }
22
+ declare type GenericStreamClientOptions = SolanaStreamClientOptions | AptosStreamClientOptions;
23
+ export default class GenericStreamClient extends BaseStreamClient {
24
+ nativeStreamClient: SolanaStreamClient | AptosStreamClient;
25
+ chain: IChain;
26
+ constructor(options: GenericStreamClientOptions);
27
+ create(streamData: ICreateStreamData, chainSpecificParams: ICreateStreamAptosExt | ICreateStreamSolanaExt): Promise<import("../solana").CreateResponse> | Promise<import("../aptos").ITransactionResult>;
28
+ createMultiple(multipleStreamData: ICreateMultipleStreamData, chainSpecificParams: ICreateStreamAptosExt | ICreateStreamSolanaExt): Promise<import("../solana").CreateMultiResponse> | Promise<import("../aptos").IMultiTransactionResult>;
29
+ withdraw(withdrawData: IWithdrawData, chainSpecificParams: ITransactionAptosExt | IInteractStreamSolanaExt): Promise<import("../solana").TxResponse> | Promise<import("../aptos").ITransactionResult>;
30
+ cancel(cancelData: ICancelData, chainSpecificParams: ITransactionAptosExt | IInteractStreamSolanaExt): Promise<any>;
31
+ transfer(transferData: ITransferData, chainSpecificParams: ITransactionAptosExt | IInteractStreamSolanaExt): Promise<any>;
32
+ topup(topupData: ITopUpData, chainSpecificParams: ITransactionAptosExt | ITopUpStreamSolanaExt): Promise<any>;
33
+ getOne(getOneData: IGetOneData): Promise<any>;
34
+ }
35
+ export {};
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ var StreamClient_1 = __importDefault(require("../solana/StreamClient"));
22
+ var StreamClient_2 = __importDefault(require("../aptos/StreamClient"));
23
+ var BaseStreamClient_1 = require("./BaseStreamClient");
24
+ var types_1 = require("./types");
25
+ var GenericStreamClient = /** @class */ (function (_super) {
26
+ __extends(GenericStreamClient, _super);
27
+ function GenericStreamClient(options) {
28
+ var _this = _super.call(this) || this;
29
+ _this.chain = options.chain;
30
+ if (options.chain === types_1.IChain.Solana) {
31
+ _this.nativeStreamClient = new StreamClient_1.default(options.clusterUrl, options.cluster, options.commitment, options.programId);
32
+ }
33
+ else {
34
+ _this.nativeStreamClient = new StreamClient_2.default(options.clusterUrl, options.cluster, options.maxGas, options.programId);
35
+ }
36
+ return _this;
37
+ }
38
+ GenericStreamClient.prototype.create = function (streamData, chainSpecificParams) {
39
+ if (this.nativeStreamClient instanceof StreamClient_1.default) {
40
+ var params = chainSpecificParams;
41
+ return this.nativeStreamClient.create(streamData, params);
42
+ }
43
+ else {
44
+ var params = chainSpecificParams;
45
+ return this.nativeStreamClient.create(streamData, params);
46
+ }
47
+ };
48
+ GenericStreamClient.prototype.createMultiple = function (multipleStreamData, chainSpecificParams) {
49
+ if (this.nativeStreamClient instanceof StreamClient_1.default) {
50
+ var params = chainSpecificParams;
51
+ return this.nativeStreamClient.createMultiple(multipleStreamData, params);
52
+ }
53
+ else {
54
+ var params = chainSpecificParams;
55
+ return this.nativeStreamClient.createMultiple(multipleStreamData, params);
56
+ }
57
+ };
58
+ GenericStreamClient.prototype.withdraw = function (withdrawData, chainSpecificParams) {
59
+ if (this.nativeStreamClient instanceof StreamClient_1.default) {
60
+ var params = chainSpecificParams;
61
+ return this.nativeStreamClient.withdraw(withdrawData, params);
62
+ }
63
+ else {
64
+ var params = chainSpecificParams;
65
+ return this.nativeStreamClient.withdraw(withdrawData, params);
66
+ }
67
+ };
68
+ GenericStreamClient.prototype.cancel = function (cancelData, chainSpecificParams) {
69
+ if (this.nativeStreamClient instanceof StreamClient_1.default) {
70
+ var params = chainSpecificParams;
71
+ return this.nativeStreamClient.cancel(cancelData, params);
72
+ }
73
+ else {
74
+ var params = chainSpecificParams;
75
+ return this.nativeStreamClient.cancel(cancelData, params);
76
+ }
77
+ };
78
+ GenericStreamClient.prototype.transfer = function (transferData, chainSpecificParams) {
79
+ if (this.nativeStreamClient instanceof StreamClient_1.default) {
80
+ var params = chainSpecificParams;
81
+ return this.nativeStreamClient.transfer(transferData, params);
82
+ }
83
+ else {
84
+ var params = chainSpecificParams;
85
+ return this.nativeStreamClient.transfer(transferData, params);
86
+ }
87
+ };
88
+ GenericStreamClient.prototype.topup = function (topupData, chainSpecificParams) {
89
+ if (this.nativeStreamClient instanceof StreamClient_1.default) {
90
+ var params = chainSpecificParams;
91
+ return this.nativeStreamClient.topup(topupData, params);
92
+ }
93
+ else {
94
+ var params = chainSpecificParams;
95
+ return this.nativeStreamClient.topup(topupData, params);
96
+ }
97
+ };
98
+ GenericStreamClient.prototype.getOne = function (getOneData) {
99
+ return this.nativeStreamClient.getOne(getOneData);
100
+ };
101
+ return GenericStreamClient;
102
+ }(BaseStreamClient_1.BaseStreamClient));
103
+ exports.default = GenericStreamClient;
@@ -59,3 +59,7 @@ export declare enum StreamType {
59
59
  Vesting = "vesting",
60
60
  All = "all"
61
61
  }
62
+ export declare enum IChain {
63
+ Solana = "Solana",
64
+ Aptos = "Aptos"
65
+ }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StreamType = exports.StreamDirection = exports.ICluster = void 0;
3
+ exports.IChain = exports.StreamType = exports.StreamDirection = exports.ICluster = void 0;
4
4
  // Utility types
5
5
  var ICluster;
6
6
  (function (ICluster) {
@@ -21,3 +21,8 @@ var StreamType;
21
21
  StreamType["Vesting"] = "vesting";
22
22
  StreamType["All"] = "all";
23
23
  })(StreamType = exports.StreamType || (exports.StreamType = {}));
24
+ var IChain;
25
+ (function (IChain) {
26
+ IChain["Solana"] = "Solana";
27
+ IChain["Aptos"] = "Aptos";
28
+ })(IChain = exports.IChain || (exports.IChain = {}));
package/dist/index.d.ts CHANGED
@@ -2,3 +2,4 @@ export * as StreamflowSolana from "./solana";
2
2
  export * as StreamflowAptos from "./aptos";
3
3
  export * as Types from "./common/types";
4
4
  export * from "./common/utils";
5
+ export { default as GenericStreamClient } from "./common/GenericStreamClient";
package/dist/index.js CHANGED
@@ -25,9 +25,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
26
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
27
  };
28
+ var __importDefault = (this && this.__importDefault) || function (mod) {
29
+ return (mod && mod.__esModule) ? mod : { "default": mod };
30
+ };
28
31
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.Types = exports.StreamflowAptos = exports.StreamflowSolana = void 0;
32
+ exports.GenericStreamClient = exports.Types = exports.StreamflowAptos = exports.StreamflowSolana = void 0;
30
33
  exports.StreamflowSolana = __importStar(require("./solana"));
31
34
  exports.StreamflowAptos = __importStar(require("./aptos"));
32
35
  exports.Types = __importStar(require("./common/types"));
33
36
  __exportStar(require("./common/utils"), exports);
37
+ var GenericStreamClient_1 = require("./common/GenericStreamClient");
38
+ Object.defineProperty(exports, "GenericStreamClient", { enumerable: true, get: function () { return __importDefault(GenericStreamClient_1).default; } });
@@ -1,8 +1,8 @@
1
1
  import { Connection, Commitment, ConnectionConfig } from "@solana/web3.js";
2
2
  import { Stream as StreamData, GetAllParams, CreateResponse, CreateMultiResponse, TxResponse, ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt } from "./types";
3
3
  import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IWithdrawData } from "../common/types";
4
- import { GenericStreamClient } from "../common/StreamClient";
5
- export default class SolanaStreamClient extends GenericStreamClient {
4
+ import { BaseStreamClient } from "../common/BaseStreamClient";
5
+ export default class SolanaStreamClient extends BaseStreamClient {
6
6
  private connection;
7
7
  private programId;
8
8
  private commitment;
@@ -112,7 +112,7 @@ var utils_1 = require("./utils");
112
112
  var constants_1 = require("./constants");
113
113
  var instructions_1 = require("./instructions");
114
114
  var types_2 = require("../common/types");
115
- var StreamClient_1 = require("../common/StreamClient");
115
+ var BaseStreamClient_1 = require("../common/BaseStreamClient");
116
116
  var METADATA_ACC_SIZE = 1104;
117
117
  var SolanaStreamClient = /** @class */ (function (_super) {
118
118
  __extends(SolanaStreamClient, _super);
@@ -173,7 +173,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
173
173
  throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
174
174
  }
175
175
  ixs = [];
176
- mintPublicKey = isNative ? new web3_js_1.PublicKey(mint) : spl_token_1.NATIVE_MINT;
176
+ mintPublicKey = isNative ? spl_token_1.NATIVE_MINT : new web3_js_1.PublicKey(mint);
177
177
  recipientPublicKey = new web3_js_1.PublicKey(recipient);
178
178
  metadata = web3_js_1.Keypair.generate();
179
179
  return [4 /*yield*/, web3_js_1.PublicKey.findProgramAddress([buffer_1.Buffer.from("strm"), metadata.publicKey.toBuffer()], this.programId)];
@@ -949,5 +949,5 @@ var SolanaStreamClient = /** @class */ (function (_super) {
949
949
  });
950
950
  };
951
951
  return SolanaStreamClient;
952
- }(StreamClient_1.GenericStreamClient));
952
+ }(BaseStreamClient_1.BaseStreamClient));
953
953
  exports.default = SolanaStreamClient;
@@ -1,4 +1,4 @@
1
- export { default } from "./StreamClient";
1
+ export { default, default as SolanaStreamClient } from "./StreamClient";
2
2
  export * from "./utils";
3
3
  export * from "./types";
4
4
  export * from "./instructions";
@@ -29,9 +29,10 @@ 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.BN = exports.timelockIDL = exports.constants = exports.default = void 0;
32
+ exports.BN = exports.timelockIDL = exports.constants = exports.SolanaStreamClient = exports.default = void 0;
33
33
  var StreamClient_1 = require("./StreamClient");
34
34
  Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(StreamClient_1).default; } });
35
+ Object.defineProperty(exports, "SolanaStreamClient", { enumerable: true, get: function () { return __importDefault(StreamClient_1).default; } });
35
36
  __exportStar(require("./utils"), exports);
36
37
  __exportStar(require("./types"), exports);
37
38
  __exportStar(require("./instructions"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamflow/stream",
3
- "version": "4.0.0-Alpha.1",
3
+ "version": "4.0.0-Alpha.3",
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/",
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GenericStreamClient = void 0;
4
- var GenericStreamClient = /** @class */ (function () {
5
- function GenericStreamClient() {
6
- }
7
- return GenericStreamClient;
8
- }());
9
- exports.GenericStreamClient = GenericStreamClient;