@streamflow/stream 3.0.0 → 3.0.1-3.1
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/README.md +93 -91
- package/dist/Stream.js +15 -15
- package/dist/StreamClient.d.ts +50 -11
- package/dist/StreamClient.js +453 -183
- package/dist/__tests__/test_dependencies/airdrop/airdrop-request.d.ts +3 -0
- package/dist/__tests__/test_dependencies/airdrop/airdrop-request.js +67 -0
- package/dist/__tests__/test_dependencies/airdrop/airdrop.d.ts +6 -0
- package/dist/__tests__/test_dependencies/airdrop/airdrop.js +215 -0
- package/dist/__tests__/test_dependencies/constants/index.d.ts +122 -0
- package/dist/__tests__/test_dependencies/constants/index.js +158 -0
- package/dist/__tests__/test_dependencies/idl/airdrop.d.ts +27 -0
- package/dist/__tests__/test_dependencies/idl/airdrop.js +171 -0
- package/dist/constants.d.ts +3 -0
- package/dist/constants.js +4 -1
- package/dist/{idl.d.ts → idl/timelock.d.ts} +0 -0
- package/dist/{idl.js → idl/timelock.js} +0 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +7 -3
- package/dist/instructions.d.ts +46 -11
- package/dist/instructions.js +183 -13
- package/dist/layout.d.ts +4 -0
- package/dist/layout.js +24 -1
- package/dist/types.d.ts +125 -41
- package/dist/types.js +71 -1
- package/dist/utils.d.ts +6 -6
- package/dist/utils.js +38 -30
- package/package.json +16 -2
package/dist/types.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { Wallet } from "@project-serum/anchor/src/provider";
|
|
3
3
|
import { WalletAdapterNetwork } from "@solana/wallet-adapter-base";
|
|
4
4
|
import { AccountInfo, Connection, PublicKey, Keypair, TransactionSignature, TransactionInstruction } from "@solana/web3.js";
|
|
5
|
-
import
|
|
5
|
+
import BN from "bn.js";
|
|
6
6
|
export { WalletAdapterNetwork as Cluster } from "@solana/wallet-adapter-base";
|
|
7
7
|
export declare enum StreamDirection {
|
|
8
8
|
Outgoing = "outgoing",
|
|
@@ -26,11 +26,11 @@ export interface CreateStreamData {
|
|
|
26
26
|
recipient: string;
|
|
27
27
|
mint: string;
|
|
28
28
|
start: number;
|
|
29
|
-
depositedAmount:
|
|
29
|
+
depositedAmount: BN;
|
|
30
30
|
period: number;
|
|
31
31
|
cliff: number;
|
|
32
|
-
cliffAmount:
|
|
33
|
-
amountPerPeriod:
|
|
32
|
+
cliffAmount: BN;
|
|
33
|
+
amountPerPeriod: BN;
|
|
34
34
|
name: string;
|
|
35
35
|
canTopup: boolean;
|
|
36
36
|
cancelableBySender: boolean;
|
|
@@ -42,8 +42,10 @@ export interface CreateStreamData {
|
|
|
42
42
|
}
|
|
43
43
|
export interface MultiRecipient {
|
|
44
44
|
recipient: string;
|
|
45
|
-
depositedAmount:
|
|
45
|
+
depositedAmount: BN;
|
|
46
46
|
name: string;
|
|
47
|
+
cliffAmount: BN;
|
|
48
|
+
amountPerPeriod: BN;
|
|
47
49
|
}
|
|
48
50
|
export interface CreateMultiData {
|
|
49
51
|
recipientsData: MultiRecipient[];
|
|
@@ -51,8 +53,6 @@ export interface CreateMultiData {
|
|
|
51
53
|
start: number;
|
|
52
54
|
period: number;
|
|
53
55
|
cliff: number;
|
|
54
|
-
cliffAmount: u64;
|
|
55
|
-
amountPerPeriod: u64;
|
|
56
56
|
canTopup: boolean;
|
|
57
57
|
cancelableBySender: boolean;
|
|
58
58
|
cancelableByRecipient: boolean;
|
|
@@ -70,14 +70,16 @@ export interface CreateStreamParams extends CreateStreamData {
|
|
|
70
70
|
export interface CreateParams extends CreateStreamData {
|
|
71
71
|
sender: Wallet | Keypair;
|
|
72
72
|
partner?: string | null;
|
|
73
|
+
isNative?: boolean;
|
|
73
74
|
}
|
|
74
75
|
export interface CreateMultiParams extends CreateMultiData {
|
|
75
76
|
sender: Wallet | Keypair;
|
|
76
77
|
partner?: string | null;
|
|
78
|
+
isNative?: boolean;
|
|
77
79
|
}
|
|
78
80
|
export interface WithdrawStreamData {
|
|
79
81
|
id: string;
|
|
80
|
-
amount:
|
|
82
|
+
amount: BN;
|
|
81
83
|
}
|
|
82
84
|
export interface WithdrawStreamParams extends WithdrawStreamData {
|
|
83
85
|
connection: Connection;
|
|
@@ -85,11 +87,11 @@ export interface WithdrawStreamParams extends WithdrawStreamData {
|
|
|
85
87
|
cluster?: ClusterExtended;
|
|
86
88
|
}
|
|
87
89
|
export interface WithdrawParams extends WithdrawStreamData {
|
|
88
|
-
invoker: Wallet;
|
|
90
|
+
invoker: Wallet | Keypair;
|
|
89
91
|
}
|
|
90
92
|
export interface TopupStreamData {
|
|
91
93
|
id: string;
|
|
92
|
-
amount:
|
|
94
|
+
amount: BN;
|
|
93
95
|
}
|
|
94
96
|
export interface TopupStreamParams extends TopupStreamData {
|
|
95
97
|
connection: Connection;
|
|
@@ -97,7 +99,8 @@ export interface TopupStreamParams extends TopupStreamData {
|
|
|
97
99
|
cluster?: ClusterExtended;
|
|
98
100
|
}
|
|
99
101
|
export interface TopupParams extends TopupStreamData {
|
|
100
|
-
invoker: Wallet;
|
|
102
|
+
invoker: Wallet | Keypair;
|
|
103
|
+
isNative?: boolean;
|
|
101
104
|
}
|
|
102
105
|
export interface CancelStreamData {
|
|
103
106
|
id: string;
|
|
@@ -108,7 +111,7 @@ export interface CancelStreamParams extends CancelStreamData {
|
|
|
108
111
|
cluster?: ClusterExtended;
|
|
109
112
|
}
|
|
110
113
|
export interface CancelParams extends CancelStreamData {
|
|
111
|
-
invoker: Wallet;
|
|
114
|
+
invoker: Wallet | Keypair;
|
|
112
115
|
}
|
|
113
116
|
export interface TransferStreamData {
|
|
114
117
|
id: string;
|
|
@@ -120,7 +123,7 @@ export interface TransferStreamParams extends TransferStreamData {
|
|
|
120
123
|
cluster?: ClusterExtended;
|
|
121
124
|
}
|
|
122
125
|
export interface TransferParams extends TransferStreamData {
|
|
123
|
-
invoker: Wallet;
|
|
126
|
+
invoker: Wallet | Keypair;
|
|
124
127
|
}
|
|
125
128
|
export interface GetStreamParams {
|
|
126
129
|
connection: Connection;
|
|
@@ -142,7 +145,47 @@ export interface Stream {
|
|
|
142
145
|
magic: number;
|
|
143
146
|
version: number;
|
|
144
147
|
createdAt: number;
|
|
145
|
-
withdrawnAmount:
|
|
148
|
+
withdrawnAmount: BN;
|
|
149
|
+
canceledAt: number;
|
|
150
|
+
end: number;
|
|
151
|
+
lastWithdrawnAt: number;
|
|
152
|
+
sender: string;
|
|
153
|
+
senderTokens: string;
|
|
154
|
+
recipient: string;
|
|
155
|
+
recipientTokens: string;
|
|
156
|
+
mint: string;
|
|
157
|
+
escrowTokens: string;
|
|
158
|
+
streamflowTreasury: string;
|
|
159
|
+
streamflowTreasuryTokens: string;
|
|
160
|
+
streamflowFeeTotal: BN;
|
|
161
|
+
streamflowFeeWithdrawn: BN;
|
|
162
|
+
streamflowFeePercent: number;
|
|
163
|
+
partnerFeeTotal: BN;
|
|
164
|
+
partnerFeeWithdrawn: BN;
|
|
165
|
+
partnerFeePercent: number;
|
|
166
|
+
partner: string;
|
|
167
|
+
partnerTokens: string;
|
|
168
|
+
start: number;
|
|
169
|
+
depositedAmount: BN;
|
|
170
|
+
period: number;
|
|
171
|
+
amountPerPeriod: BN;
|
|
172
|
+
cliff: number;
|
|
173
|
+
cliffAmount: BN;
|
|
174
|
+
cancelableBySender: boolean;
|
|
175
|
+
cancelableByRecipient: boolean;
|
|
176
|
+
automaticWithdrawal: boolean;
|
|
177
|
+
transferableBySender: boolean;
|
|
178
|
+
transferableByRecipient: boolean;
|
|
179
|
+
canTopup: boolean;
|
|
180
|
+
name: string;
|
|
181
|
+
withdrawalFrequency: number;
|
|
182
|
+
unlocked(currentTimestamp: number, decimals: number): number;
|
|
183
|
+
}
|
|
184
|
+
export declare class Contract implements Stream {
|
|
185
|
+
magic: number;
|
|
186
|
+
version: number;
|
|
187
|
+
createdAt: number;
|
|
188
|
+
withdrawnAmount: BN;
|
|
146
189
|
canceledAt: number;
|
|
147
190
|
end: number;
|
|
148
191
|
lastWithdrawnAt: number;
|
|
@@ -154,20 +197,20 @@ export interface Stream {
|
|
|
154
197
|
escrowTokens: string;
|
|
155
198
|
streamflowTreasury: string;
|
|
156
199
|
streamflowTreasuryTokens: string;
|
|
157
|
-
streamflowFeeTotal:
|
|
158
|
-
streamflowFeeWithdrawn:
|
|
200
|
+
streamflowFeeTotal: BN;
|
|
201
|
+
streamflowFeeWithdrawn: BN;
|
|
159
202
|
streamflowFeePercent: number;
|
|
160
|
-
partnerFeeTotal:
|
|
161
|
-
partnerFeeWithdrawn:
|
|
203
|
+
partnerFeeTotal: BN;
|
|
204
|
+
partnerFeeWithdrawn: BN;
|
|
162
205
|
partnerFeePercent: number;
|
|
163
206
|
partner: string;
|
|
164
207
|
partnerTokens: string;
|
|
165
208
|
start: number;
|
|
166
|
-
depositedAmount:
|
|
209
|
+
depositedAmount: BN;
|
|
167
210
|
period: number;
|
|
168
|
-
amountPerPeriod:
|
|
211
|
+
amountPerPeriod: BN;
|
|
169
212
|
cliff: number;
|
|
170
|
-
cliffAmount:
|
|
213
|
+
cliffAmount: BN;
|
|
171
214
|
cancelableBySender: boolean;
|
|
172
215
|
cancelableByRecipient: boolean;
|
|
173
216
|
automaticWithdrawal: boolean;
|
|
@@ -176,15 +219,18 @@ export interface Stream {
|
|
|
176
219
|
canTopup: boolean;
|
|
177
220
|
name: string;
|
|
178
221
|
withdrawalFrequency: number;
|
|
222
|
+
constructor(stream: DecodedStream);
|
|
223
|
+
unlocked(currentTimestamp: number, decimals: number): number;
|
|
224
|
+
remaining(decimals: number): number;
|
|
179
225
|
}
|
|
180
226
|
export interface DecodedStream {
|
|
181
|
-
magic:
|
|
182
|
-
version:
|
|
183
|
-
createdAt:
|
|
184
|
-
withdrawnAmount:
|
|
185
|
-
canceledAt:
|
|
186
|
-
end:
|
|
187
|
-
lastWithdrawnAt:
|
|
227
|
+
magic: BN;
|
|
228
|
+
version: BN;
|
|
229
|
+
createdAt: BN;
|
|
230
|
+
withdrawnAmount: BN;
|
|
231
|
+
canceledAt: BN;
|
|
232
|
+
end: BN;
|
|
233
|
+
lastWithdrawnAt: BN;
|
|
188
234
|
sender: PublicKey;
|
|
189
235
|
senderTokens: PublicKey;
|
|
190
236
|
recipient: PublicKey;
|
|
@@ -193,20 +239,20 @@ export interface DecodedStream {
|
|
|
193
239
|
escrowTokens: PublicKey;
|
|
194
240
|
streamflowTreasury: PublicKey;
|
|
195
241
|
streamflowTreasuryTokens: PublicKey;
|
|
196
|
-
streamflowFeeTotal:
|
|
197
|
-
streamflowFeeWithdrawn:
|
|
198
|
-
streamflowFeePercent:
|
|
199
|
-
partnerFeeTotal:
|
|
200
|
-
partnerFeeWithdrawn:
|
|
201
|
-
partnerFeePercent:
|
|
242
|
+
streamflowFeeTotal: BN;
|
|
243
|
+
streamflowFeeWithdrawn: BN;
|
|
244
|
+
streamflowFeePercent: BN;
|
|
245
|
+
partnerFeeTotal: BN;
|
|
246
|
+
partnerFeeWithdrawn: BN;
|
|
247
|
+
partnerFeePercent: BN;
|
|
202
248
|
partner: PublicKey;
|
|
203
249
|
partnerTokens: PublicKey;
|
|
204
|
-
start:
|
|
205
|
-
depositedAmount:
|
|
206
|
-
period:
|
|
207
|
-
amountPerPeriod:
|
|
208
|
-
cliff:
|
|
209
|
-
cliffAmount:
|
|
250
|
+
start: BN;
|
|
251
|
+
depositedAmount: BN;
|
|
252
|
+
period: BN;
|
|
253
|
+
amountPerPeriod: BN;
|
|
254
|
+
cliff: BN;
|
|
255
|
+
cliffAmount: BN;
|
|
210
256
|
cancelableBySender: boolean;
|
|
211
257
|
cancelableByRecipient: boolean;
|
|
212
258
|
automaticWithdrawal: boolean;
|
|
@@ -214,7 +260,7 @@ export interface DecodedStream {
|
|
|
214
260
|
transferableByRecipient: boolean;
|
|
215
261
|
canTopup: boolean;
|
|
216
262
|
name: string;
|
|
217
|
-
withdrawFrequency:
|
|
263
|
+
withdrawFrequency: BN;
|
|
218
264
|
}
|
|
219
265
|
export interface TransactionResponse {
|
|
220
266
|
tx: TransactionSignature;
|
|
@@ -229,6 +275,44 @@ export interface TxResponse {
|
|
|
229
275
|
export interface CreateResponse extends TxResponse {
|
|
230
276
|
metadata: Keypair;
|
|
231
277
|
}
|
|
278
|
+
export interface MetadataRecipientHashMap {
|
|
279
|
+
[metadataPubKey: string]: MultiRecipient;
|
|
280
|
+
}
|
|
281
|
+
export interface CreateMultiError {
|
|
282
|
+
recipient: string;
|
|
283
|
+
error: string;
|
|
284
|
+
}
|
|
232
285
|
export interface CreateMultiResponse {
|
|
233
286
|
txs: TransactionSignature[];
|
|
287
|
+
metadatas: Keypair[];
|
|
288
|
+
metadataToRecipient: MetadataRecipientHashMap;
|
|
289
|
+
errors: CreateMultiError[];
|
|
290
|
+
}
|
|
291
|
+
export declare enum TransferCancelOptions {
|
|
292
|
+
Recipient = "recipient",
|
|
293
|
+
Sender = "sender",
|
|
294
|
+
Both = "both",
|
|
295
|
+
Neither = "neither"
|
|
296
|
+
}
|
|
297
|
+
export interface Recipient {
|
|
298
|
+
recipient: string;
|
|
299
|
+
recipientEmail: string;
|
|
300
|
+
name: string;
|
|
301
|
+
depositedAmount: number;
|
|
302
|
+
}
|
|
303
|
+
export interface CreateMultipleStreamsValues {
|
|
304
|
+
releaseAmount: number;
|
|
305
|
+
email: string;
|
|
306
|
+
tokenSymbol: string;
|
|
307
|
+
startDate: string;
|
|
308
|
+
startTime: string;
|
|
309
|
+
releaseFrequencyCounter: number;
|
|
310
|
+
whoCanTransfer: TransferCancelOptions;
|
|
311
|
+
whoCanCancel: TransferCancelOptions;
|
|
312
|
+
releaseFrequencyPeriod: number;
|
|
313
|
+
automaticWithdrawal: boolean;
|
|
314
|
+
withdrawalFrequencyCounter: number;
|
|
315
|
+
withdrawalFrequencyPeriod: number;
|
|
316
|
+
referral: string;
|
|
317
|
+
recipients: Recipient[];
|
|
234
318
|
}
|
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.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,3 +24,68 @@ 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;
|
|
85
|
+
var TransferCancelOptions;
|
|
86
|
+
(function (TransferCancelOptions) {
|
|
87
|
+
TransferCancelOptions["Recipient"] = "recipient";
|
|
88
|
+
TransferCancelOptions["Sender"] = "sender";
|
|
89
|
+
TransferCancelOptions["Both"] = "both";
|
|
90
|
+
TransferCancelOptions["Neither"] = "neither";
|
|
91
|
+
})(TransferCancelOptions = exports.TransferCancelOptions || (exports.TransferCancelOptions = {}));
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import
|
|
2
|
+
import BN from "bn.js";
|
|
3
3
|
import { Stream, DecodedStream } from "./types";
|
|
4
4
|
export declare const decodeStream: (buf: Buffer) => DecodedStream;
|
|
5
5
|
export declare const formatDecodedStream: (stream: DecodedStream) => Stream;
|
|
6
6
|
/**
|
|
7
7
|
* Used for conversion of token amounts to their Big Number representation.
|
|
8
8
|
* Get Big Number representation in the smallest units from the same value in the highest units.
|
|
9
|
-
* @param {number} value - Number of tokens you want to convert to its
|
|
9
|
+
* @param {number} value - Number of tokens you want to convert to its BN representation.
|
|
10
10
|
* @param {number} decimals - Number of decimals the token has.
|
|
11
11
|
*/
|
|
12
|
-
export declare const getBN: (value: number, decimals: number) =>
|
|
12
|
+
export declare const getBN: (value: number, decimals: number) => BN;
|
|
13
13
|
/**
|
|
14
14
|
* Used for token amounts conversion from their Big Number representation to number.
|
|
15
|
-
* Get value in the highest units from
|
|
16
|
-
* @param {
|
|
15
|
+
* Get value in the highest units from BN representation of the same value in the smallest units.
|
|
16
|
+
* @param {BN} value - Big Number representation of value in the smallest units.
|
|
17
17
|
* @param {number} decimals - Number of decimals the token has.
|
|
18
18
|
*/
|
|
19
|
-
export declare const getNumberFromBN: (value:
|
|
19
|
+
export declare const getNumberFromBN: (value: BN, decimals: number) => number;
|
package/dist/utils.js
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
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
6
|
exports.getNumberFromBN = exports.getBN = exports.formatDecodedStream = exports.decodeStream = void 0;
|
|
4
7
|
var web3_js_1 = require("@solana/web3.js");
|
|
5
|
-
var
|
|
8
|
+
var bn_js_1 = __importDefault(require("bn.js"));
|
|
6
9
|
var layout_1 = require("./layout");
|
|
7
10
|
var decoder = new TextDecoder("utf-8");
|
|
8
11
|
var LE = "le"; //little endian
|
|
9
12
|
var decodeStream = function (buf) {
|
|
10
13
|
var raw = layout_1.streamLayout.decode(buf);
|
|
11
14
|
return {
|
|
12
|
-
magic: new
|
|
13
|
-
version: new
|
|
14
|
-
createdAt: new
|
|
15
|
-
withdrawnAmount: new
|
|
16
|
-
canceledAt: new
|
|
17
|
-
end: new
|
|
18
|
-
lastWithdrawnAt: new
|
|
15
|
+
magic: new bn_js_1.default(raw.magic, LE),
|
|
16
|
+
version: new bn_js_1.default(raw.version, LE),
|
|
17
|
+
createdAt: new bn_js_1.default(raw.created_at, LE),
|
|
18
|
+
withdrawnAmount: new bn_js_1.default(raw.withdrawn_amount, LE),
|
|
19
|
+
canceledAt: new bn_js_1.default(raw.canceled_at, LE),
|
|
20
|
+
end: new bn_js_1.default(raw.end_time, LE),
|
|
21
|
+
lastWithdrawnAt: new bn_js_1.default(raw.last_withdrawn_at, LE),
|
|
19
22
|
sender: new web3_js_1.PublicKey(raw.sender),
|
|
20
23
|
senderTokens: new web3_js_1.PublicKey(raw.sender_tokens),
|
|
21
24
|
recipient: new web3_js_1.PublicKey(raw.recipient),
|
|
@@ -24,20 +27,20 @@ var decodeStream = function (buf) {
|
|
|
24
27
|
escrowTokens: new web3_js_1.PublicKey(raw.escrow_tokens),
|
|
25
28
|
streamflowTreasury: new web3_js_1.PublicKey(raw.streamflow_treasury),
|
|
26
29
|
streamflowTreasuryTokens: new web3_js_1.PublicKey(raw.streamflow_treasury_tokens),
|
|
27
|
-
streamflowFeeTotal: new
|
|
28
|
-
streamflowFeeWithdrawn: new
|
|
29
|
-
streamflowFeePercent: new
|
|
30
|
-
partnerFeeTotal: new
|
|
31
|
-
partnerFeeWithdrawn: new
|
|
32
|
-
partnerFeePercent: new
|
|
30
|
+
streamflowFeeTotal: new bn_js_1.default(raw.streamflow_fee_total, LE),
|
|
31
|
+
streamflowFeeWithdrawn: new bn_js_1.default(raw.streamflow_fee_withdrawn, LE),
|
|
32
|
+
streamflowFeePercent: new bn_js_1.default(raw.streamflow_fee_percent, LE),
|
|
33
|
+
partnerFeeTotal: new bn_js_1.default(raw.partner_fee_total, LE),
|
|
34
|
+
partnerFeeWithdrawn: new bn_js_1.default(raw.partner_fee_withdrawn, LE),
|
|
35
|
+
partnerFeePercent: new bn_js_1.default(raw.partner_fee_percent, LE),
|
|
33
36
|
partner: new web3_js_1.PublicKey(raw.partner),
|
|
34
37
|
partnerTokens: new web3_js_1.PublicKey(raw.partner_tokens),
|
|
35
|
-
start: new
|
|
36
|
-
depositedAmount: new
|
|
37
|
-
period: new
|
|
38
|
-
amountPerPeriod: new
|
|
39
|
-
cliff: new
|
|
40
|
-
cliffAmount: new
|
|
38
|
+
start: new bn_js_1.default(raw.start_time, LE),
|
|
39
|
+
depositedAmount: new bn_js_1.default(raw.net_amount_deposited, LE),
|
|
40
|
+
period: new bn_js_1.default(raw.period, LE),
|
|
41
|
+
amountPerPeriod: new bn_js_1.default(raw.amount_per_period, LE),
|
|
42
|
+
cliff: new bn_js_1.default(raw.cliff, LE),
|
|
43
|
+
cliffAmount: new bn_js_1.default(raw.cliff_amount, LE),
|
|
41
44
|
cancelableBySender: Boolean(raw.cancelable_by_sender),
|
|
42
45
|
cancelableByRecipient: Boolean(raw.cancelable_by_recipient),
|
|
43
46
|
automaticWithdrawal: Boolean(raw.automatic_withdrawal),
|
|
@@ -45,13 +48,15 @@ var decodeStream = function (buf) {
|
|
|
45
48
|
transferableByRecipient: Boolean(raw.transferable_by_recipient),
|
|
46
49
|
canTopup: Boolean(raw.can_topup),
|
|
47
50
|
name: decoder.decode(raw.stream_name),
|
|
48
|
-
withdrawFrequency: new
|
|
51
|
+
withdrawFrequency: new bn_js_1.default(raw.withdraw_frequency, LE),
|
|
49
52
|
};
|
|
50
53
|
};
|
|
51
54
|
exports.decodeStream = decodeStream;
|
|
55
|
+
// DeprecationWarning: This object will be deprecated starting from the version 4.0.0. Use
|
|
56
|
+
// types/Contract instead
|
|
52
57
|
var formatDecodedStream = function (stream) {
|
|
53
58
|
var _a;
|
|
54
|
-
|
|
59
|
+
var resp = {
|
|
55
60
|
magic: stream.magic.toNumber(),
|
|
56
61
|
version: stream.version.toNumber(),
|
|
57
62
|
createdAt: stream.createdAt.toNumber(),
|
|
@@ -89,30 +94,33 @@ var formatDecodedStream = function (stream) {
|
|
|
89
94
|
canTopup: stream.canTopup,
|
|
90
95
|
name: stream.name,
|
|
91
96
|
withdrawalFrequency: stream.withdrawFrequency.toNumber(),
|
|
92
|
-
|
|
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;
|
|
93
101
|
};
|
|
94
102
|
exports.formatDecodedStream = formatDecodedStream;
|
|
95
103
|
/**
|
|
96
104
|
* Used for conversion of token amounts to their Big Number representation.
|
|
97
105
|
* Get Big Number representation in the smallest units from the same value in the highest units.
|
|
98
|
-
* @param {number} value - Number of tokens you want to convert to its
|
|
106
|
+
* @param {number} value - Number of tokens you want to convert to its BN representation.
|
|
99
107
|
* @param {number} decimals - Number of decimals the token has.
|
|
100
108
|
*/
|
|
101
109
|
var getBN = function (value, decimals) {
|
|
102
110
|
return value > (Math.pow(2, 53) - 1) / Math.pow(10, decimals)
|
|
103
|
-
? new
|
|
104
|
-
: new
|
|
111
|
+
? new bn_js_1.default(value).mul(new bn_js_1.default(Math.pow(10, decimals)))
|
|
112
|
+
: new bn_js_1.default(value * Math.pow(10, decimals));
|
|
105
113
|
};
|
|
106
114
|
exports.getBN = getBN;
|
|
107
115
|
/**
|
|
108
116
|
* Used for token amounts conversion from their Big Number representation to number.
|
|
109
|
-
* Get value in the highest units from
|
|
110
|
-
* @param {
|
|
117
|
+
* Get value in the highest units from BN representation of the same value in the smallest units.
|
|
118
|
+
* @param {BN} value - Big Number representation of value in the smallest units.
|
|
111
119
|
* @param {number} decimals - Number of decimals the token has.
|
|
112
120
|
*/
|
|
113
121
|
var getNumberFromBN = function (value, decimals) {
|
|
114
|
-
return value.gt(new
|
|
115
|
-
? value.div(new
|
|
122
|
+
return value.gt(new bn_js_1.default(Math.pow(2, 53) - 1))
|
|
123
|
+
? value.div(new bn_js_1.default(Math.pow(10, decimals))).toNumber()
|
|
116
124
|
: value.toNumber() / Math.pow(10, decimals);
|
|
117
125
|
};
|
|
118
126
|
exports.getNumberFromBN = getNumberFromBN;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamflow/stream",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.13.1",
|
|
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/",
|
|
@@ -9,5 +9,19 @@
|
|
|
9
9
|
"build": "tsc --outDir ./dist",
|
|
10
10
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
11
|
},
|
|
12
|
-
"gitHead": "a37306eba0e762af096db642fa22f07194014cfd"
|
|
12
|
+
"gitHead": "a37306eba0e762af096db642fa22f07194014cfd",
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@types/bn.js": "5.1.0",
|
|
15
|
+
"date-fns": "2.28.0",
|
|
16
|
+
"typescript": "4.6.4"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@project-serum/anchor": "^0.16.2",
|
|
20
|
+
"@project-serum/common": "^0.0.1-beta.3",
|
|
21
|
+
"@solana/spl-token": "^0.1.8",
|
|
22
|
+
"@solana/wallet-adapter-base": "^0.9.2",
|
|
23
|
+
"@solana/web3.js": "^1.42.0",
|
|
24
|
+
"bn.js": "^5.2.0",
|
|
25
|
+
"buffer-layout": "^1.2.1"
|
|
26
|
+
}
|
|
13
27
|
}
|