@streamflow/stream 4.0.0-Alpha.0 → 4.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.
- package/dist/__tests__/aptos/streamClient.spec.js +4 -4
- package/dist/aptos/StreamClient.d.ts +6 -5
- package/dist/aptos/StreamClient.js +53 -58
- package/dist/aptos/constants.js +2 -2
- package/dist/aptos/types.d.ts +135 -0
- package/dist/aptos/types.js +63 -0
- package/dist/common/BaseStreamClient.d.ts +10 -0
- package/dist/common/BaseStreamClient.js +9 -0
- package/dist/common/GenericStreamClient.d.ts +34 -0
- package/dist/common/GenericStreamClient.js +103 -0
- package/dist/common/types.d.ts +4 -9
- package/dist/common/types.js +6 -7
- package/dist/index.d.ts +1 -0
- package/dist/index.js +6 -1
- package/dist/solana/StreamClient.d.ts +3 -2
- package/dist/solana/StreamClient.js +2 -1
- package/dist/solana/index.d.ts +2 -0
- package/dist/solana/index.js +16 -1
- package/dist/solana/layout.d.ts +6 -6
- package/dist/solana/layout.js +100 -75
- package/package.json +3 -3
- package/dist/Stream.d.ts +0 -87
- package/dist/Stream.js +0 -503
- package/dist/StreamClient.d.ts +0 -145
- package/dist/StreamClient.js +0 -1031
- package/dist/__tests__/test_dependencies/airdrop/airdrop-request.d.ts +0 -2
- package/dist/__tests__/test_dependencies/airdrop/airdrop-request.js +0 -67
- package/dist/__tests__/test_dependencies/airdrop/airdrop.d.ts +0 -6
- package/dist/__tests__/test_dependencies/airdrop/airdrop.js +0 -215
- package/dist/__tests__/test_dependencies/constants/index.d.ts +0 -122
- package/dist/__tests__/test_dependencies/constants/index.js +0 -158
- package/dist/__tests__/test_dependencies/idl/airdrop.d.ts +0 -27
- package/dist/__tests__/test_dependencies/idl/airdrop.js +0 -171
- package/dist/constants.d.ts +0 -18
- package/dist/constants.js +0 -23
- package/dist/idl/timelock.d.ts +0 -22
- package/dist/idl/timelock.js +0 -422
- package/dist/instructionTypes.d.ts +0 -81
- package/dist/instructionTypes.js +0 -2
- package/dist/instructions.d.ts +0 -131
- package/dist/instructions.js +0 -379
- package/dist/layout.d.ts +0 -22
- package/dist/layout.js +0 -99
- package/dist/types.d.ts +0 -317
- package/dist/types.js +0 -91
- package/dist/utils.d.ts +0 -19
- package/dist/utils.js +0 -126
|
@@ -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
|
-
"
|
|
134
|
+
"test name",
|
|
135
135
|
"0xtest",
|
|
136
136
|
]);
|
|
137
137
|
expect(callParam).toEqual({
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { BaseStreamClient } from "../common/BaseStreamClient";
|
|
2
|
+
import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateStreamData, ITopUpData, ITransferData, IWithdrawData } from "../common/types";
|
|
3
|
+
import { ICreateStreamAptosExt, IMultiTransactionResult, ITransactionAptosExt, ITransactionResult } from "./types";
|
|
4
|
+
export default class AptosStreamClient extends BaseStreamClient {
|
|
4
5
|
private programId;
|
|
5
6
|
private maxGas;
|
|
6
|
-
constructor(cluster
|
|
7
|
+
constructor(cluster?: ICluster, maxGas?: string, programId?: string);
|
|
7
8
|
create(streamData: ICreateStreamData, { senderWallet }: ICreateStreamAptosExt): Promise<ITransactionResult>;
|
|
8
|
-
createMultiple(multipleStreamData: ICreateMultipleStreamData, { senderWallet }: ICreateStreamAptosExt): Promise<
|
|
9
|
+
createMultiple(multipleStreamData: ICreateMultipleStreamData, { senderWallet }: ICreateStreamAptosExt): Promise<IMultiTransactionResult>;
|
|
9
10
|
withdraw(withdrawData: IWithdrawData, { senderWallet, tokenId }: ITransactionAptosExt): Promise<ITransactionResult>;
|
|
10
11
|
cancel(cancelData: ICancelData, { senderWallet, tokenId }: ITransactionAptosExt): Promise<any>;
|
|
11
12
|
transfer(transferData: ITransferData, { senderWallet, tokenId }: ITransactionAptosExt): Promise<any>;
|
|
@@ -50,64 +50,51 @@ 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");
|
|
55
|
+
var BaseStreamClient_1 = require("../common/BaseStreamClient");
|
|
66
56
|
var types_1 = require("../common/types");
|
|
67
57
|
var constants_1 = require("./constants");
|
|
68
58
|
var AptosStreamClient = /** @class */ (function (_super) {
|
|
69
59
|
__extends(AptosStreamClient, _super);
|
|
70
60
|
function AptosStreamClient(cluster, maxGas, programId) {
|
|
61
|
+
if (cluster === void 0) { cluster = types_1.ICluster.Mainnet; }
|
|
71
62
|
if (maxGas === void 0) { maxGas = "10000"; }
|
|
72
63
|
var _this = _super.call(this) || this;
|
|
73
|
-
_this.programId = programId
|
|
74
|
-
? programId
|
|
75
|
-
: constants_1.APTOS_PROGRAM_IDS[cluster] || constants_1.APTOS_PROGRAM_IDS[types_1.ICluster.Mainnet];
|
|
64
|
+
_this.programId = programId ? programId : constants_1.APTOS_PROGRAM_IDS[cluster];
|
|
76
65
|
_this.maxGas = maxGas;
|
|
77
66
|
return _this;
|
|
78
67
|
}
|
|
79
68
|
AptosStreamClient.prototype.create = function (streamData, _a) {
|
|
80
69
|
var senderWallet = _a.senderWallet;
|
|
81
70
|
return __awaiter(this, void 0, void 0, function () {
|
|
82
|
-
var acc, seeds,
|
|
71
|
+
var acc, seeds, payload, hash;
|
|
83
72
|
return __generator(this, function (_b) {
|
|
84
73
|
switch (_b.label) {
|
|
85
74
|
case 0:
|
|
86
75
|
acc = new aptos_1.AptosAccount();
|
|
87
76
|
seeds = acc.address().hex();
|
|
88
|
-
strmEncoded = new TextEncoder().encode("STRM");
|
|
89
|
-
name = Buffer.from(strmEncoded).toString("hex");
|
|
90
77
|
payload = {
|
|
91
78
|
type: "create",
|
|
92
79
|
function: "".concat(this.programId, "::protocol::create"),
|
|
93
80
|
type_arguments: [streamData.tokenId],
|
|
94
81
|
arguments: [
|
|
95
82
|
seeds,
|
|
96
|
-
streamData.amount,
|
|
83
|
+
streamData.amount.toString(),
|
|
97
84
|
streamData.period,
|
|
98
|
-
streamData.amountPerPeriod,
|
|
85
|
+
streamData.amountPerPeriod.toString(),
|
|
99
86
|
streamData.start,
|
|
100
|
-
streamData.cliffAmount,
|
|
87
|
+
streamData.cliffAmount.toString(),
|
|
101
88
|
streamData.cancelableBySender,
|
|
102
89
|
streamData.cancelableByRecipient,
|
|
103
90
|
streamData.transferableBySender,
|
|
104
91
|
streamData.transferableByRecipient,
|
|
105
92
|
streamData.canTopup,
|
|
106
|
-
streamData.canPause,
|
|
107
|
-
streamData.canUpdateRate,
|
|
108
|
-
streamData.automaticWithdrawal,
|
|
109
|
-
streamData.withdrawalFrequency,
|
|
110
|
-
name,
|
|
93
|
+
streamData.canPause || false,
|
|
94
|
+
streamData.canUpdateRate || false,
|
|
95
|
+
streamData.automaticWithdrawal || false,
|
|
96
|
+
streamData.withdrawalFrequency || 0,
|
|
97
|
+
streamData.name,
|
|
111
98
|
streamData.recipient,
|
|
112
99
|
],
|
|
113
100
|
};
|
|
@@ -120,43 +107,53 @@ var AptosStreamClient = /** @class */ (function (_super) {
|
|
|
120
107
|
});
|
|
121
108
|
};
|
|
122
109
|
AptosStreamClient.prototype.createMultiple = function (multipleStreamData, _a) {
|
|
110
|
+
var _b;
|
|
123
111
|
var senderWallet = _a.senderWallet;
|
|
124
112
|
return __awaiter(this, void 0, void 0, function () {
|
|
125
|
-
var payloads,
|
|
126
|
-
var e_1, _b;
|
|
113
|
+
var payloads, txs, metadatas, metadataToRecipient, errors, i, payload, recipient, hash, e_1, metadataId;
|
|
127
114
|
return __generator(this, function (_c) {
|
|
128
115
|
switch (_c.label) {
|
|
129
116
|
case 0:
|
|
130
117
|
payloads = this.generateMultiPayloads(multipleStreamData);
|
|
131
|
-
|
|
118
|
+
txs = [];
|
|
119
|
+
metadatas = [];
|
|
120
|
+
metadataToRecipient = {};
|
|
121
|
+
errors = [];
|
|
122
|
+
i = 0;
|
|
132
123
|
_c.label = 1;
|
|
133
124
|
case 1:
|
|
134
|
-
|
|
135
|
-
|
|
125
|
+
if (!(i < payloads.length)) return [3 /*break*/, 7];
|
|
126
|
+
payload = payloads[i];
|
|
127
|
+
recipient = multipleStreamData.recipients[i];
|
|
136
128
|
_c.label = 2;
|
|
137
129
|
case 2:
|
|
138
|
-
|
|
139
|
-
payload = payloads_1_1.value;
|
|
130
|
+
_c.trys.push([2, 4, 5, 6]);
|
|
140
131
|
return [4 /*yield*/, senderWallet.signAndSubmitTransaction(payload)];
|
|
141
132
|
case 3:
|
|
142
133
|
hash = (_c.sent()).hash;
|
|
143
|
-
|
|
144
|
-
|
|
134
|
+
txs.push(hash);
|
|
135
|
+
return [3 /*break*/, 6];
|
|
145
136
|
case 4:
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
finally { if (e_1) throw e_1.error; }
|
|
137
|
+
e_1 = _c.sent();
|
|
138
|
+
errors.push({
|
|
139
|
+
error: (_b = e_1 === null || e_1 === void 0 ? void 0 : e_1.toString()) !== null && _b !== void 0 ? _b : "Unkown error!",
|
|
140
|
+
recipient: recipient.recipient,
|
|
141
|
+
});
|
|
142
|
+
return [3 /*break*/, 6];
|
|
143
|
+
case 5:
|
|
144
|
+
metadataId = payload.arguments[0];
|
|
145
|
+
metadatas.push(metadataId);
|
|
146
|
+
metadataToRecipient[metadataId] = recipient;
|
|
158
147
|
return [7 /*endfinally*/];
|
|
159
|
-
case
|
|
148
|
+
case 6:
|
|
149
|
+
i++;
|
|
150
|
+
return [3 /*break*/, 1];
|
|
151
|
+
case 7: return [2 /*return*/, {
|
|
152
|
+
txs: txs,
|
|
153
|
+
metadatas: metadatas,
|
|
154
|
+
metadataToRecipient: metadataToRecipient,
|
|
155
|
+
errors: errors,
|
|
156
|
+
}];
|
|
160
157
|
}
|
|
161
158
|
});
|
|
162
159
|
});
|
|
@@ -263,34 +260,32 @@ var AptosStreamClient = /** @class */ (function (_super) {
|
|
|
263
260
|
return multipleStreamData.recipients.map(function (recipient) {
|
|
264
261
|
var acc = new aptos_1.AptosAccount(); // Generate random address as seeds for derriving "escrow" account
|
|
265
262
|
var seeds = acc.address().hex();
|
|
266
|
-
var strmEncoded = new TextEncoder().encode("STRM");
|
|
267
|
-
var name = Buffer.from(strmEncoded).toString("hex");
|
|
268
263
|
return {
|
|
269
264
|
type: "create",
|
|
270
265
|
function: "".concat(_this.programId, "::protocol::create"),
|
|
271
266
|
type_arguments: [multipleStreamData.tokenId],
|
|
272
267
|
arguments: [
|
|
273
268
|
seeds,
|
|
274
|
-
recipient.amount,
|
|
269
|
+
recipient.amount.toString(),
|
|
275
270
|
multipleStreamData.period,
|
|
276
|
-
recipient.amountPerPeriod,
|
|
271
|
+
recipient.amountPerPeriod.toString(),
|
|
277
272
|
multipleStreamData.start,
|
|
278
|
-
recipient.cliffAmount,
|
|
273
|
+
recipient.cliffAmount.toString(),
|
|
279
274
|
multipleStreamData.cancelableBySender,
|
|
280
275
|
multipleStreamData.cancelableByRecipient,
|
|
281
276
|
multipleStreamData.transferableBySender,
|
|
282
277
|
multipleStreamData.transferableByRecipient,
|
|
283
278
|
multipleStreamData.canTopup,
|
|
284
|
-
multipleStreamData.canPause,
|
|
285
|
-
multipleStreamData.canUpdateRate,
|
|
286
|
-
multipleStreamData.automaticWithdrawal,
|
|
287
|
-
multipleStreamData.withdrawalFrequency,
|
|
288
|
-
name,
|
|
279
|
+
multipleStreamData.canPause || false,
|
|
280
|
+
multipleStreamData.canUpdateRate || false,
|
|
281
|
+
multipleStreamData.automaticWithdrawal || false,
|
|
282
|
+
multipleStreamData.withdrawalFrequency || 0,
|
|
283
|
+
recipient.name,
|
|
289
284
|
recipient.recipient,
|
|
290
285
|
],
|
|
291
286
|
};
|
|
292
287
|
});
|
|
293
288
|
};
|
|
294
289
|
return AptosStreamClient;
|
|
295
|
-
}(
|
|
290
|
+
}(BaseStreamClient_1.BaseStreamClient));
|
|
296
291
|
exports.default = AptosStreamClient;
|
package/dist/aptos/constants.js
CHANGED
|
@@ -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.
|
|
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);
|
package/dist/aptos/types.d.ts
CHANGED
|
@@ -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 {};
|
package/dist/aptos/types.js
CHANGED
|
@@ -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;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ICreateStreamData, ICreateMultipleStreamData, IWithdrawData, ICancelData, ITransferData, ITopUpData, IGetOneData } from "./types";
|
|
2
|
+
export declare abstract class BaseStreamClient {
|
|
3
|
+
abstract create(streamData: ICreateStreamData, ...chainSpecificParams: any[]): Promise<any>;
|
|
4
|
+
abstract createMultiple(multipleStreamData: ICreateMultipleStreamData, ...chainSpecificParams: any[]): Promise<any>;
|
|
5
|
+
abstract withdraw(withdrawData: IWithdrawData, ...chainSpecificParams: any[]): Promise<any>;
|
|
6
|
+
abstract cancel(cancelData: ICancelData, ...chainSpecificParams: any[]): Promise<any>;
|
|
7
|
+
abstract transfer(transferData: ITransferData, ...chainSpecificParams: any[]): Promise<any>;
|
|
8
|
+
abstract topup(topupData: ITopUpData, ...chainSpecificParams: any[]): Promise<any>;
|
|
9
|
+
abstract getOne(getOneData: IGetOneData, ...chainSpecificParams: any[]): Promise<any>;
|
|
10
|
+
}
|
|
@@ -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,34 @@
|
|
|
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
|
+
commitment?: Commitment | ConnectionConfig;
|
|
12
|
+
cluster?: ICluster;
|
|
13
|
+
programId?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface AptosStreamClientOptions {
|
|
16
|
+
chain: IChain.Aptos;
|
|
17
|
+
cluster?: ICluster;
|
|
18
|
+
programId?: string;
|
|
19
|
+
maxGas?: string;
|
|
20
|
+
}
|
|
21
|
+
declare type GenericStreamClientOptions = SolanaStreamClientOptions | AptosStreamClientOptions;
|
|
22
|
+
export default class GenericStreamClient extends BaseStreamClient {
|
|
23
|
+
nativeStreamClient: SolanaStreamClient | AptosStreamClient;
|
|
24
|
+
chain: IChain;
|
|
25
|
+
constructor(options: GenericStreamClientOptions);
|
|
26
|
+
create(streamData: ICreateStreamData, chainSpecificParams: ICreateStreamAptosExt | ICreateStreamSolanaExt): Promise<import("../solana").CreateResponse> | Promise<import("../aptos").ITransactionResult>;
|
|
27
|
+
createMultiple(multipleStreamData: ICreateMultipleStreamData, chainSpecificParams: ICreateStreamAptosExt | ICreateStreamSolanaExt): Promise<import("../solana").CreateMultiResponse> | Promise<import("../aptos").IMultiTransactionResult>;
|
|
28
|
+
withdraw(withdrawData: IWithdrawData, chainSpecificParams: ITransactionAptosExt | IInteractStreamSolanaExt): Promise<import("../solana").TxResponse> | Promise<import("../aptos").ITransactionResult>;
|
|
29
|
+
cancel(cancelData: ICancelData, chainSpecificParams: ITransactionAptosExt | IInteractStreamSolanaExt): Promise<any>;
|
|
30
|
+
transfer(transferData: ITransferData, chainSpecificParams: ITransactionAptosExt | IInteractStreamSolanaExt): Promise<any>;
|
|
31
|
+
topup(topupData: ITopUpData, chainSpecificParams: ITransactionAptosExt | ITopUpStreamSolanaExt): Promise<any>;
|
|
32
|
+
getOne(getOneData: IGetOneData): Promise<any>;
|
|
33
|
+
}
|
|
34
|
+
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.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;
|
package/dist/common/types.d.ts
CHANGED
|
@@ -43,15 +43,6 @@ export interface ITopUpData {
|
|
|
43
43
|
export interface IGetOneData {
|
|
44
44
|
id: string;
|
|
45
45
|
}
|
|
46
|
-
export declare abstract class GenericStreamClient {
|
|
47
|
-
abstract create(streamData: ICreateStreamData, ...chainSpecificParams: any[]): Promise<any>;
|
|
48
|
-
abstract createMultiple(multipleStreamData: ICreateMultipleStreamData, ...chainSpecificParams: any[]): Promise<any>;
|
|
49
|
-
abstract withdraw(withdrawData: IWithdrawData, ...chainSpecificParams: any[]): Promise<any>;
|
|
50
|
-
abstract cancel(cancelData: ICancelData, ...chainSpecificParams: any[]): Promise<any>;
|
|
51
|
-
abstract transfer(transferData: ITransferData, ...chainSpecificParams: any[]): Promise<any>;
|
|
52
|
-
abstract topup(topupData: ITopUpData, ...chainSpecificParams: any[]): Promise<any>;
|
|
53
|
-
abstract getOne(getOneData: IGetOneData, ...chainSpecificParams: any[]): Promise<any>;
|
|
54
|
-
}
|
|
55
46
|
export declare enum ICluster {
|
|
56
47
|
Mainnet = "mainnet",
|
|
57
48
|
Devnet = "devnet",
|
|
@@ -68,3 +59,7 @@ export declare enum StreamType {
|
|
|
68
59
|
Vesting = "vesting",
|
|
69
60
|
All = "all"
|
|
70
61
|
}
|
|
62
|
+
export declare enum IChain {
|
|
63
|
+
Solana = "Solana",
|
|
64
|
+
Aptos = "Aptos"
|
|
65
|
+
}
|