@streamflow/stream 3.0.0-test.1 → 3.0.0-test.4
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 +11 -11
- package/dist/StreamClient.d.ts +7 -7
- package/dist/StreamClient.js +38 -35
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/instructions.d.ts +10 -10
- package/dist/instructions.js +9 -9
- package/dist/types.d.ts +37 -37
- package/dist/utils.d.ts +6 -6
- package/dist/utils.js +31 -28
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -35,23 +35,23 @@ Most common imports:
|
|
|
35
35
|
|
|
36
36
|
```javascript
|
|
37
37
|
import {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
38
|
+
StreamClient,
|
|
39
|
+
Stream,
|
|
40
|
+
CreateParams,
|
|
41
|
+
CreateMultiParams,
|
|
42
|
+
WithdrawParams,
|
|
43
|
+
TransferParams,
|
|
44
|
+
TopupParams,
|
|
45
|
+
CancelParams,
|
|
46
|
+
GetAllParams,
|
|
47
|
+
StreamDirection,
|
|
48
|
+
StreamType,
|
|
49
|
+
Cluster,
|
|
50
|
+
TxResponse,
|
|
51
|
+
CreateResponse,
|
|
52
|
+
BN,
|
|
53
|
+
getBN,
|
|
54
|
+
getNumberFromBN,
|
|
55
55
|
} from "@streamflow/stream";
|
|
56
56
|
```
|
|
57
57
|
|
|
@@ -66,9 +66,9 @@ All streams functions are methods on this instance.
|
|
|
66
66
|
import { StreamClient } from "@streamflow/stream";
|
|
67
67
|
|
|
68
68
|
const StreamClient = new StreamClient(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
"https://api.mainnet-beta.solana.com",
|
|
70
|
+
Cluster.Mainnet,
|
|
71
|
+
"confirmed"
|
|
72
72
|
);
|
|
73
73
|
```
|
|
74
74
|
|
|
@@ -76,30 +76,30 @@ const StreamClient = new StreamClient(
|
|
|
76
76
|
|
|
77
77
|
```javascript
|
|
78
78
|
const createStreamParams = {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
79
|
+
sender: wallet, // Wallet/Keypair signing the transaction, creating and sending the stream.
|
|
80
|
+
recipient: "4ih00075bKjVg000000tLdk4w42NyG3Mv0000dc0M00", // Solana recipient address.
|
|
81
|
+
mint: "DNw99999M7e24g99999999WJirKeZ5fQc6KY999999gK", // SPL Token mint.
|
|
82
|
+
start: 1643363040, // Timestamp (in seconds) when the stream/token vesting starts.
|
|
83
|
+
depositedAmount: getBN(1000000000000, 9), // Deposited amount of tokens (using smallest denomination).
|
|
84
|
+
period: 1, // Time step (period) in seconds per which the unlocking occurs.
|
|
85
|
+
cliff: 1643363160, // Vesting contract "cliff" timestamp in seconds.
|
|
86
|
+
cliffAmount: new BN(100000000000), // Amount (smallest denomination) unlocked at the "cliff" timestamp.
|
|
87
|
+
amountPerPeriod: getBN(5000000000, 9), // Release rate: how many tokens are unlocked per each period.
|
|
88
|
+
name: "Transfer to Jane Doe.", // The stream name or subject.
|
|
89
|
+
canTopup: false, // setting to FALSE will effectively create a vesting contract.
|
|
90
|
+
cancelableBySender: true, // Whether or not sender can cancel the stream.
|
|
91
|
+
cancelableByRecipient: false, // Whether or not recipient can cancel the stream.
|
|
92
|
+
transferableBySender: true, // Whether or not sender can transfer the stream.
|
|
93
|
+
transferableByRecipient: false, // Whether or not recipient can transfer the stream.
|
|
94
|
+
automaticWithdrawal: true, // [WIP] Whether or not a 3rd party (e.g. cron job, "cranker") can initiate a token withdraw/transfer.
|
|
95
|
+
withdrawalFrequency: 10, // [WIP] Relevant when automatic withdrawal is enabled. If greater than 0 our withdrawor will take care of withdrawals. If equal to 0 our withdrawor will skip, but everyone else can initiate withdrawals.
|
|
96
|
+
partner: null, // (optional) Partner's wallet address (string | null).
|
|
97
97
|
};
|
|
98
98
|
|
|
99
99
|
try {
|
|
100
|
-
|
|
100
|
+
const { ixs, tx, metadata } = await StreamClient.create(createStreamParams);
|
|
101
101
|
} catch (exception) {
|
|
102
|
-
|
|
102
|
+
// handle exception
|
|
103
103
|
}
|
|
104
104
|
```
|
|
105
105
|
|
|
@@ -107,35 +107,35 @@ try {
|
|
|
107
107
|
|
|
108
108
|
```javascript
|
|
109
109
|
const recipients = [
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
110
|
+
{
|
|
111
|
+
recipient: "4ih00075bKjVg000000tLdk4w42NyG3Mv0000dc0M00", // Solana recipient address.
|
|
112
|
+
depositedAmount: getBN(1000000000000, 9), // Deposited amount of tokens (in the smallest units).
|
|
113
|
+
name: "January Payroll", // The stream name/subject.
|
|
114
|
+
},
|
|
115
115
|
];
|
|
116
116
|
|
|
117
117
|
const createMultiStreamsParams = {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
118
|
+
sender: wallet, // Wallet/Keypair signing the transaction, creating and sending the stream.
|
|
119
|
+
recipientsData: recipients, // Array of Solana recipient address.
|
|
120
|
+
mint: "DNw99999M7e24g99999999WJirKeZ5fQc6KY999999gK", // SPL Token mint.
|
|
121
|
+
start: 1643363040, // Timestamp (in seconds) when the stream/token vesting starts.
|
|
122
|
+
period: 1, // Time step (period) in seconds per which the unlocking occurs.
|
|
123
|
+
cliff: 1643363160, // Vesting contract "cliff" timestamp in seconds.
|
|
124
|
+
cliffAmount: getBN(100000000000, 9), // Amount unlocked at the "cliff" timestamp.
|
|
125
|
+
amountPerPeriod: getBN(5000000000, 9), // Release rate: how many tokens are unlocked per each period.
|
|
126
|
+
canTopup: true, // setting to FALSE will effectively create a vesting contract.
|
|
127
|
+
cancelableBySender: true, // Whether or not sender can cancel the stream.
|
|
128
|
+
cancelableByRecipient: false, // Whether or not recipient can cancel the stream.
|
|
129
|
+
transferableBySender: true, // Whether or not sender can transfer the stream.
|
|
130
|
+
transferableByRecipient: false, // Whether or not recipient can transfer the stream.
|
|
131
|
+
automaticWithdrawal: false, // Whether or not a 3rd party can initiate withdraw in the name of recipient (currently not used, set it to FALSE).
|
|
132
|
+
partner: null, // (optional) Partner's wallet address (string | null).
|
|
133
133
|
};
|
|
134
134
|
|
|
135
135
|
try {
|
|
136
|
-
|
|
136
|
+
const { txs } = await StreamClient.createMultiple(createMultiStreamsParams);
|
|
137
137
|
} catch (exception) {
|
|
138
|
-
|
|
138
|
+
// handle exception
|
|
139
139
|
}
|
|
140
140
|
```
|
|
141
141
|
|
|
@@ -147,15 +147,15 @@ Please note that transaction fees for the scheduled transfers are paid upfront b
|
|
|
147
147
|
|
|
148
148
|
```javascript
|
|
149
149
|
const withdrawStreamParams = {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
150
|
+
invoker: wallet, // Wallet/Keypair signing the transaction.
|
|
151
|
+
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be withdrawn from.
|
|
152
|
+
amount: getBN(100000000000, 9), // Requested amount to withdraw. If stream is completed, the whole amount will be withdrawn.
|
|
153
153
|
};
|
|
154
154
|
|
|
155
155
|
try {
|
|
156
|
-
|
|
156
|
+
const { ixs, tx } = await StreamClient.withdraw(withdrawStreamParams);
|
|
157
157
|
} catch (exception) {
|
|
158
|
-
|
|
158
|
+
// handle exception
|
|
159
159
|
}
|
|
160
160
|
```
|
|
161
161
|
|
|
@@ -163,15 +163,15 @@ try {
|
|
|
163
163
|
|
|
164
164
|
```javascript
|
|
165
165
|
const topupStreamParams = {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
166
|
+
invoker: wallet, // Wallet/Keypair signing the transaction.
|
|
167
|
+
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be topped up.
|
|
168
|
+
amount: getBN(100000000000, 9), // Specified amount to topup (increases deposited amount).
|
|
169
169
|
};
|
|
170
170
|
|
|
171
171
|
try {
|
|
172
|
-
|
|
172
|
+
const { ixs, tx } = await StreamClient.topup(topupStreamParams);
|
|
173
173
|
} catch (exception) {
|
|
174
|
-
|
|
174
|
+
// handle exception
|
|
175
175
|
}
|
|
176
176
|
```
|
|
177
177
|
|
|
@@ -179,15 +179,15 @@ try {
|
|
|
179
179
|
|
|
180
180
|
```javascript
|
|
181
181
|
const data = {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
182
|
+
invoker: wallet, // Wallet/Keypair signing the transaction.
|
|
183
|
+
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA",
|
|
184
|
+
recipientId: "99h00075bKjVg000000tLdk4w42NyG3Mv0000dc0M99", // Identifier of a stream to be transferred.
|
|
185
185
|
};
|
|
186
186
|
|
|
187
187
|
try {
|
|
188
|
-
|
|
188
|
+
const { tx } = await StreamClient.transfer(data);
|
|
189
189
|
} catch (exception) {
|
|
190
|
-
|
|
190
|
+
// handle exception
|
|
191
191
|
}
|
|
192
192
|
```
|
|
193
193
|
|
|
@@ -195,14 +195,14 @@ try {
|
|
|
195
195
|
|
|
196
196
|
```javascript
|
|
197
197
|
const cancelStreamParams = {
|
|
198
|
-
|
|
199
|
-
|
|
198
|
+
invoker: wallet, // Wallet/Keypair signing the transaction.
|
|
199
|
+
id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be canceled.
|
|
200
200
|
};
|
|
201
201
|
|
|
202
202
|
try {
|
|
203
|
-
|
|
203
|
+
const { ixs, tx } = await StreamClient.cancel(cancelStreamParams);
|
|
204
204
|
} catch (exception) {
|
|
205
|
-
|
|
205
|
+
// handle exception
|
|
206
206
|
}
|
|
207
207
|
```
|
|
208
208
|
|
|
@@ -210,11 +210,11 @@ try {
|
|
|
210
210
|
|
|
211
211
|
```javascript
|
|
212
212
|
try {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
213
|
+
const stream = await StreamClient.getOne(
|
|
214
|
+
"AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA" // Identifier of a stream that is fetched.
|
|
215
|
+
);
|
|
216
216
|
} catch (exception) {
|
|
217
|
-
|
|
217
|
+
// handle exception
|
|
218
218
|
}
|
|
219
219
|
```
|
|
220
220
|
|
|
@@ -222,13 +222,13 @@ try {
|
|
|
222
222
|
|
|
223
223
|
```javascript
|
|
224
224
|
try {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
225
|
+
const streams = StreamClient.get({
|
|
226
|
+
wallet: wallet, // Wallet signing the transaction.
|
|
227
|
+
type: StreamType.All, // (optional) Type, default is StreamType.All
|
|
228
|
+
direction: StreamDirection.All, // (optional) Direction, default is StreamDirection.All)
|
|
229
|
+
});
|
|
230
230
|
} catch (exception) {
|
|
231
|
-
|
|
231
|
+
// handle exception
|
|
232
232
|
}
|
|
233
233
|
```
|
|
234
234
|
|
|
@@ -250,4 +250,6 @@ Use `getBN` and `getNumberFromBN` utility functions for conversions between `BN`
|
|
|
250
250
|
|
|
251
251
|
**Streamflow Community** (free and open source version, with a limited feature set) is available [here](https://github.com/streamflow-finance/js-sdk/tree/community).
|
|
252
252
|
|
|
253
|
+
`npx typedoc packages/stream/index.ts`
|
|
254
|
+
|
|
253
255
|
WAGMI.
|
package/dist/Stream.js
CHANGED
|
@@ -76,10 +76,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
76
76
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
77
77
|
};
|
|
78
78
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
79
|
-
var
|
|
79
|
+
var bn_js_1 = __importDefault(require("bn.js"));
|
|
80
80
|
var buffer_1 = require("buffer");
|
|
81
81
|
var anchor_1 = require("@project-serum/anchor");
|
|
82
|
-
var
|
|
82
|
+
var spl_token_1 = require("@solana/spl-token");
|
|
83
83
|
var web3_js_1 = require("@solana/web3.js");
|
|
84
84
|
var types_1 = require("./types");
|
|
85
85
|
var utils_1 = require("./utils");
|
|
@@ -151,7 +151,7 @@ var Stream = /** @class */ (function () {
|
|
|
151
151
|
nameUtf8EncodedArr = encoder.encode(name);
|
|
152
152
|
return [4 /*yield*/, program.rpc.create(
|
|
153
153
|
// Order of the parameters must match the ones in the program
|
|
154
|
-
new
|
|
154
|
+
new bn_js_1.default(start), depositedAmount, new bn_js_1.default(period), amountPerPeriod, new bn_js_1.default(cliff), cliffAmount, cancelableBySender, cancelableByRecipient, automaticWithdrawal, transferableBySender, transferableByRecipient, canTopup, nameUtf8EncodedArr, new bn_js_1.default(automaticWithdrawal ? withdrawalFrequency : period), {
|
|
155
155
|
accounts: {
|
|
156
156
|
sender: sender.publicKey,
|
|
157
157
|
senderTokens: senderTokens,
|
|
@@ -167,8 +167,8 @@ var Stream = /** @class */ (function () {
|
|
|
167
167
|
feeOracle: constants_1.FEE_ORACLE_PUBLIC_KEY,
|
|
168
168
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
169
169
|
timelockProgram: program.programId,
|
|
170
|
-
tokenProgram:
|
|
171
|
-
associatedTokenProgram:
|
|
170
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
171
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
172
172
|
withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
|
|
173
173
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
174
174
|
},
|
|
@@ -224,7 +224,7 @@ var Stream = /** @class */ (function () {
|
|
|
224
224
|
partner: data.partner,
|
|
225
225
|
partnerTokens: partnerTokens,
|
|
226
226
|
mint: data.mint,
|
|
227
|
-
tokenProgram:
|
|
227
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
228
228
|
},
|
|
229
229
|
})];
|
|
230
230
|
case 4:
|
|
@@ -278,7 +278,7 @@ var Stream = /** @class */ (function () {
|
|
|
278
278
|
partner: data.partner,
|
|
279
279
|
partnerTokens: partnerTokens,
|
|
280
280
|
mint: data.mint,
|
|
281
|
-
tokenProgram:
|
|
281
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
282
282
|
},
|
|
283
283
|
})];
|
|
284
284
|
case 4:
|
|
@@ -326,8 +326,8 @@ var Stream = /** @class */ (function () {
|
|
|
326
326
|
metadata: stream,
|
|
327
327
|
mint: mint,
|
|
328
328
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
329
|
-
tokenProgram:
|
|
330
|
-
associatedTokenProgram:
|
|
329
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
330
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
331
331
|
systemProgram: anchor_1.web3.SystemProgram.programId,
|
|
332
332
|
},
|
|
333
333
|
})];
|
|
@@ -380,7 +380,7 @@ var Stream = /** @class */ (function () {
|
|
|
380
380
|
partner: partner,
|
|
381
381
|
partnerTokens: partnerTokens,
|
|
382
382
|
mint: mint,
|
|
383
|
-
tokenProgram:
|
|
383
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
384
384
|
withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
|
|
385
385
|
systemProgram: anchor_1.web3.SystemProgram.programId,
|
|
386
386
|
},
|
|
@@ -495,7 +495,7 @@ function ata(mint, account) {
|
|
|
495
495
|
return __awaiter(this, void 0, void 0, function () {
|
|
496
496
|
return __generator(this, function (_a) {
|
|
497
497
|
switch (_a.label) {
|
|
498
|
-
case 0: return [4 /*yield*/,
|
|
498
|
+
case 0: return [4 /*yield*/, spl_token_1.Token.getAssociatedTokenAddress(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, mint, account, true)];
|
|
499
499
|
case 1: return [2 /*return*/, _a.sent()];
|
|
500
500
|
}
|
|
501
501
|
});
|
package/dist/StreamClient.d.ts
CHANGED
|
@@ -19,11 +19,11 @@ export default class StreamClient {
|
|
|
19
19
|
* @param {string} data.recipient - Solana address of the recipient. Associated token account will be derived using this address and token mint address.
|
|
20
20
|
* @param {string} data.mint - SPL Token mint.
|
|
21
21
|
* @param {number} data.start - Timestamp (in seconds) when the stream/token vesting starts.
|
|
22
|
-
* @param {
|
|
22
|
+
* @param {BN} data.depositedAmount - Initially deposited amount of tokens (in the smallest units).
|
|
23
23
|
* @param {number} data.period - Time step (period) in seconds per which the unlocking occurs.
|
|
24
24
|
* @param {number} data.cliff - Vesting contract "cliff" timestamp in seconds.
|
|
25
|
-
* @param {
|
|
26
|
-
* @param {
|
|
25
|
+
* @param {BN} data.cliffAmount - Amount unlocked at the "cliff".
|
|
26
|
+
* @param {BN} data.amountPerPeriod - Amount unlocked per each period.
|
|
27
27
|
* @param {string} data.name - Stream name/subject.
|
|
28
28
|
* @param {boolean} data.canTopup - TRUE for streams, FALSE for vesting contracts.
|
|
29
29
|
* @param {boolean} data.cancelableBySender - Whether or not sender can cancel the stream.
|
|
@@ -45,8 +45,8 @@ export default class StreamClient {
|
|
|
45
45
|
* @param {number} data.start - Timestamp (in seconds) when the stream/token vesting starts.
|
|
46
46
|
* @param {number} data.period - Time step (period) in seconds per which the unlocking occurs.
|
|
47
47
|
* @param {number} data.cliff - Vesting contract "cliff" timestamp in seconds.
|
|
48
|
-
* @param {
|
|
49
|
-
* @param {
|
|
48
|
+
* @param {BN} data.cliffAmount - Amount unlocked at the "cliff".
|
|
49
|
+
* @param {BN} data.amountPerPeriod - Amount unlocked per each period.
|
|
50
50
|
* @param {boolean} data.canTopup - TRUE for streams, FALSE for vesting contracts.
|
|
51
51
|
* @param {boolean} data.cancelableBySender - Whether or not sender can cancel the stream.
|
|
52
52
|
* @param {boolean} data.cancelableByRecipient - Whether or not recipient can cancel the stream.
|
|
@@ -62,7 +62,7 @@ export default class StreamClient {
|
|
|
62
62
|
* @param {WithdrawParams} data
|
|
63
63
|
* @param {Wallet | Keypair} data.invoker - Wallet signing the transaction. It's address should match authorized wallet (recipient) or transaction will fail.
|
|
64
64
|
* @param {string} data.id - Identifier of a stream (escrow account with metadata) to be withdrawn from.
|
|
65
|
-
* @param {
|
|
65
|
+
* @param {BN} data.amount - Requested amount (in the smallest units) to withdraw (while streaming). If stream is completed, the whole amount will be withdrawn.
|
|
66
66
|
*/
|
|
67
67
|
withdraw({ invoker, id, amount, }: WithdrawParams): Promise<TxResponse>;
|
|
68
68
|
/**
|
|
@@ -86,7 +86,7 @@ export default class StreamClient {
|
|
|
86
86
|
* @param {TopupParams} data
|
|
87
87
|
* @param {Wallet | Keypair} data.invoker - Wallet signing the transaction. It's address should match current stream sender or transaction will fail.
|
|
88
88
|
* @param {string} data.id - Identifier of a stream (escrow account with metadata) to be topped up.
|
|
89
|
-
* @param {
|
|
89
|
+
* @param {BN} data.amount - Specified amount (in the smallest units) to topup (increases deposited amount).
|
|
90
90
|
*/
|
|
91
91
|
topup({ invoker, id, amount, }: TopupParams): Promise<TxResponse>;
|
|
92
92
|
/**
|
package/dist/StreamClient.js
CHANGED
|
@@ -83,11 +83,14 @@ var __values = (this && this.__values) || function(o) {
|
|
|
83
83
|
};
|
|
84
84
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
85
85
|
};
|
|
86
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
87
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
88
|
+
};
|
|
86
89
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
87
|
-
var
|
|
90
|
+
var bn_js_1 = __importDefault(require("bn.js"));
|
|
88
91
|
var buffer_1 = require("buffer");
|
|
89
92
|
var anchor_1 = require("@project-serum/anchor");
|
|
90
|
-
var
|
|
93
|
+
var spl_token_1 = require("@solana/spl-token");
|
|
91
94
|
var web3_js_1 = require("@solana/web3.js");
|
|
92
95
|
var types_1 = require("./types");
|
|
93
96
|
var utils_1 = require("./utils");
|
|
@@ -116,11 +119,11 @@ var StreamClient = /** @class */ (function () {
|
|
|
116
119
|
* @param {string} data.recipient - Solana address of the recipient. Associated token account will be derived using this address and token mint address.
|
|
117
120
|
* @param {string} data.mint - SPL Token mint.
|
|
118
121
|
* @param {number} data.start - Timestamp (in seconds) when the stream/token vesting starts.
|
|
119
|
-
* @param {
|
|
122
|
+
* @param {BN} data.depositedAmount - Initially deposited amount of tokens (in the smallest units).
|
|
120
123
|
* @param {number} data.period - Time step (period) in seconds per which the unlocking occurs.
|
|
121
124
|
* @param {number} data.cliff - Vesting contract "cliff" timestamp in seconds.
|
|
122
|
-
* @param {
|
|
123
|
-
* @param {
|
|
125
|
+
* @param {BN} data.cliffAmount - Amount unlocked at the "cliff".
|
|
126
|
+
* @param {BN} data.amountPerPeriod - Amount unlocked per each period.
|
|
124
127
|
* @param {string} data.name - Stream name/subject.
|
|
125
128
|
* @param {boolean} data.canTopup - TRUE for streams, FALSE for vesting contracts.
|
|
126
129
|
* @param {boolean} data.cancelableBySender - Whether or not sender can cancel the stream.
|
|
@@ -162,12 +165,12 @@ var StreamClient = /** @class */ (function () {
|
|
|
162
165
|
case 5:
|
|
163
166
|
partnerTokens = _g.sent();
|
|
164
167
|
ixs.push((0, instructions_1.createStreamInstruction)({
|
|
165
|
-
start: new
|
|
166
|
-
depositedAmount:
|
|
167
|
-
period: new
|
|
168
|
-
amountPerPeriod:
|
|
169
|
-
cliff: new
|
|
170
|
-
cliffAmount:
|
|
168
|
+
start: new bn_js_1.default(start),
|
|
169
|
+
depositedAmount: depositedAmount,
|
|
170
|
+
period: new bn_js_1.default(period),
|
|
171
|
+
amountPerPeriod: amountPerPeriod,
|
|
172
|
+
cliff: new bn_js_1.default(cliff),
|
|
173
|
+
cliffAmount: cliffAmount,
|
|
171
174
|
cancelableBySender: cancelableBySender,
|
|
172
175
|
cancelableByRecipient: cancelableByRecipient,
|
|
173
176
|
automaticWithdrawal: automaticWithdrawal,
|
|
@@ -175,7 +178,7 @@ var StreamClient = /** @class */ (function () {
|
|
|
175
178
|
transferableByRecipient: transferableByRecipient,
|
|
176
179
|
canTopup: canTopup,
|
|
177
180
|
name: name,
|
|
178
|
-
withdrawFrequency: new
|
|
181
|
+
withdrawFrequency: new bn_js_1.default(automaticWithdrawal ? withdrawalFrequency : period),
|
|
179
182
|
}, this.programId, {
|
|
180
183
|
sender: sender.publicKey,
|
|
181
184
|
senderTokens: senderTokens,
|
|
@@ -191,8 +194,8 @@ var StreamClient = /** @class */ (function () {
|
|
|
191
194
|
feeOracle: constants_1.FEE_ORACLE_PUBLIC_KEY,
|
|
192
195
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
193
196
|
timelockProgram: this.programId,
|
|
194
|
-
tokenProgram:
|
|
195
|
-
associatedTokenProgram:
|
|
197
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
198
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
196
199
|
withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
|
|
197
200
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
198
201
|
}));
|
|
@@ -225,8 +228,8 @@ var StreamClient = /** @class */ (function () {
|
|
|
225
228
|
* @param {number} data.start - Timestamp (in seconds) when the stream/token vesting starts.
|
|
226
229
|
* @param {number} data.period - Time step (period) in seconds per which the unlocking occurs.
|
|
227
230
|
* @param {number} data.cliff - Vesting contract "cliff" timestamp in seconds.
|
|
228
|
-
* @param {
|
|
229
|
-
* @param {
|
|
231
|
+
* @param {BN} data.cliffAmount - Amount unlocked at the "cliff".
|
|
232
|
+
* @param {BN} data.amountPerPeriod - Amount unlocked per each period.
|
|
230
233
|
* @param {boolean} data.canTopup - TRUE for streams, FALSE for vesting contracts.
|
|
231
234
|
* @param {boolean} data.cancelableBySender - Whether or not sender can cancel the stream.
|
|
232
235
|
* @param {boolean} data.cancelableByRecipient - Whether or not recipient can cancel the stream.
|
|
@@ -279,12 +282,12 @@ var StreamClient = /** @class */ (function () {
|
|
|
279
282
|
case 7:
|
|
280
283
|
partnerTokens = _h.sent();
|
|
281
284
|
ixs.push((0, instructions_1.createStreamInstruction)({
|
|
282
|
-
start: new
|
|
283
|
-
depositedAmount:
|
|
284
|
-
period: new
|
|
285
|
-
amountPerPeriod:
|
|
286
|
-
cliff: new
|
|
287
|
-
cliffAmount:
|
|
285
|
+
start: new bn_js_1.default(start),
|
|
286
|
+
depositedAmount: recipient.depositedAmount,
|
|
287
|
+
period: new bn_js_1.default(period),
|
|
288
|
+
amountPerPeriod: amountPerPeriod,
|
|
289
|
+
cliff: new bn_js_1.default(cliff),
|
|
290
|
+
cliffAmount: cliffAmount,
|
|
288
291
|
cancelableBySender: cancelableBySender,
|
|
289
292
|
cancelableByRecipient: cancelableByRecipient,
|
|
290
293
|
automaticWithdrawal: automaticWithdrawal,
|
|
@@ -292,7 +295,7 @@ var StreamClient = /** @class */ (function () {
|
|
|
292
295
|
transferableByRecipient: transferableByRecipient,
|
|
293
296
|
canTopup: canTopup,
|
|
294
297
|
name: recipient.name,
|
|
295
|
-
withdrawFrequency: new
|
|
298
|
+
withdrawFrequency: new bn_js_1.default(automaticWithdrawal ? withdrawalFrequency : period),
|
|
296
299
|
}, this.programId, {
|
|
297
300
|
sender: sender.publicKey,
|
|
298
301
|
senderTokens: senderTokens,
|
|
@@ -308,8 +311,8 @@ var StreamClient = /** @class */ (function () {
|
|
|
308
311
|
feeOracle: constants_1.FEE_ORACLE_PUBLIC_KEY,
|
|
309
312
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
310
313
|
timelockProgram: this.programId,
|
|
311
|
-
tokenProgram:
|
|
312
|
-
associatedTokenProgram:
|
|
314
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
315
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
313
316
|
withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
|
|
314
317
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
315
318
|
}));
|
|
@@ -378,7 +381,7 @@ var StreamClient = /** @class */ (function () {
|
|
|
378
381
|
* @param {WithdrawParams} data
|
|
379
382
|
* @param {Wallet | Keypair} data.invoker - Wallet signing the transaction. It's address should match authorized wallet (recipient) or transaction will fail.
|
|
380
383
|
* @param {string} data.id - Identifier of a stream (escrow account with metadata) to be withdrawn from.
|
|
381
|
-
* @param {
|
|
384
|
+
* @param {BN} data.amount - Requested amount (in the smallest units) to withdraw (while streaming). If stream is completed, the whole amount will be withdrawn.
|
|
382
385
|
*/
|
|
383
386
|
StreamClient.prototype.withdraw = function (_a) {
|
|
384
387
|
var invoker = _a.invoker, id = _a.id, amount = _a.amount;
|
|
@@ -403,7 +406,7 @@ var StreamClient = /** @class */ (function () {
|
|
|
403
406
|
return [4 /*yield*/, ata(data.mint, data.partner)];
|
|
404
407
|
case 3:
|
|
405
408
|
partnerTokens = _c.sent();
|
|
406
|
-
ixs.push((0, instructions_1.withdrawStreamInstruction)(
|
|
409
|
+
ixs.push((0, instructions_1.withdrawStreamInstruction)(amount, this.programId, {
|
|
407
410
|
authority: invoker.publicKey,
|
|
408
411
|
recipient: invoker.publicKey,
|
|
409
412
|
recipientTokens: data.recipientTokens,
|
|
@@ -414,7 +417,7 @@ var StreamClient = /** @class */ (function () {
|
|
|
414
417
|
partner: data.partner,
|
|
415
418
|
partnerTokens: partnerTokens,
|
|
416
419
|
mint: data.mint,
|
|
417
|
-
tokenProgram:
|
|
420
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
418
421
|
}));
|
|
419
422
|
commitment = typeof this.commitment == "string"
|
|
420
423
|
? this.commitment
|
|
@@ -476,7 +479,7 @@ var StreamClient = /** @class */ (function () {
|
|
|
476
479
|
partner: data.partner,
|
|
477
480
|
partnerTokens: partnerTokens,
|
|
478
481
|
mint: data.mint,
|
|
479
|
-
tokenProgram:
|
|
482
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
480
483
|
}));
|
|
481
484
|
commitment = typeof this.commitment == "string"
|
|
482
485
|
? this.commitment
|
|
@@ -532,8 +535,8 @@ var StreamClient = /** @class */ (function () {
|
|
|
532
535
|
metadata: stream,
|
|
533
536
|
mint: mint,
|
|
534
537
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
535
|
-
tokenProgram:
|
|
536
|
-
associatedTokenProgram:
|
|
538
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
539
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
537
540
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
538
541
|
}));
|
|
539
542
|
commitment = typeof this.commitment == "string"
|
|
@@ -559,7 +562,7 @@ var StreamClient = /** @class */ (function () {
|
|
|
559
562
|
* @param {TopupParams} data
|
|
560
563
|
* @param {Wallet | Keypair} data.invoker - Wallet signing the transaction. It's address should match current stream sender or transaction will fail.
|
|
561
564
|
* @param {string} data.id - Identifier of a stream (escrow account with metadata) to be topped up.
|
|
562
|
-
* @param {
|
|
565
|
+
* @param {BN} data.amount - Specified amount (in the smallest units) to topup (increases deposited amount).
|
|
563
566
|
*/
|
|
564
567
|
StreamClient.prototype.topup = function (_a) {
|
|
565
568
|
var invoker = _a.invoker, id = _a.id, amount = _a.amount;
|
|
@@ -584,7 +587,7 @@ var StreamClient = /** @class */ (function () {
|
|
|
584
587
|
return [4 /*yield*/, ata(mint, partner)];
|
|
585
588
|
case 3:
|
|
586
589
|
partnerTokens = _d.sent();
|
|
587
|
-
ixs.push((0, instructions_1.topupStreamInstruction)(
|
|
590
|
+
ixs.push((0, instructions_1.topupStreamInstruction)(amount, this.programId, {
|
|
588
591
|
sender: invoker.publicKey,
|
|
589
592
|
senderTokens: senderTokens,
|
|
590
593
|
metadata: streamPublicKey,
|
|
@@ -594,7 +597,7 @@ var StreamClient = /** @class */ (function () {
|
|
|
594
597
|
partner: partner,
|
|
595
598
|
partnerTokens: partnerTokens,
|
|
596
599
|
mint: mint,
|
|
597
|
-
tokenProgram:
|
|
600
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
598
601
|
withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
|
|
599
602
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
600
603
|
}));
|
|
@@ -739,7 +742,7 @@ function ata(mint, account) {
|
|
|
739
742
|
return __awaiter(this, void 0, void 0, function () {
|
|
740
743
|
return __generator(this, function (_a) {
|
|
741
744
|
switch (_a.label) {
|
|
742
|
-
case 0: return [4 /*yield*/,
|
|
745
|
+
case 0: return [4 /*yield*/, spl_token_1.Token.getAssociatedTokenAddress(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, mint, account)];
|
|
743
746
|
case 1: return [2 /*return*/, _a.sent()];
|
|
744
747
|
}
|
|
745
748
|
});
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -21,5 +21,5 @@ Object.defineProperty(exports, "StreamClient", { enumerable: true, get: function
|
|
|
21
21
|
__exportStar(require("./utils"), exports);
|
|
22
22
|
__exportStar(require("./types"), exports);
|
|
23
23
|
__exportStar(require("./instructions"), exports);
|
|
24
|
-
var
|
|
25
|
-
Object.defineProperty(exports, "BN", { enumerable: true, get: function () { return
|
|
24
|
+
var bn_js_1 = require("bn.js");
|
|
25
|
+
Object.defineProperty(exports, "BN", { enumerable: true, get: function () { return __importDefault(bn_js_1).default; } });
|
package/dist/instructions.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
2
|
-
import
|
|
2
|
+
import BN from "bn.js";
|
|
3
3
|
interface CreateStreamData {
|
|
4
|
-
start:
|
|
5
|
-
depositedAmount:
|
|
6
|
-
period:
|
|
7
|
-
amountPerPeriod:
|
|
8
|
-
cliff:
|
|
9
|
-
cliffAmount:
|
|
4
|
+
start: BN;
|
|
5
|
+
depositedAmount: BN;
|
|
6
|
+
period: BN;
|
|
7
|
+
amountPerPeriod: BN;
|
|
8
|
+
cliff: BN;
|
|
9
|
+
cliffAmount: BN;
|
|
10
10
|
cancelableBySender: boolean;
|
|
11
11
|
cancelableByRecipient: boolean;
|
|
12
12
|
automaticWithdrawal: boolean;
|
|
@@ -14,7 +14,7 @@ interface CreateStreamData {
|
|
|
14
14
|
transferableByRecipient: boolean;
|
|
15
15
|
canTopup: boolean;
|
|
16
16
|
name: string;
|
|
17
|
-
withdrawFrequency:
|
|
17
|
+
withdrawFrequency: BN;
|
|
18
18
|
}
|
|
19
19
|
interface CreateStreamAccounts {
|
|
20
20
|
sender: PublicKey;
|
|
@@ -50,7 +50,7 @@ interface WithdrawAccounts {
|
|
|
50
50
|
mint: PublicKey;
|
|
51
51
|
tokenProgram: PublicKey;
|
|
52
52
|
}
|
|
53
|
-
export declare const withdrawStreamInstruction: (amount:
|
|
53
|
+
export declare const withdrawStreamInstruction: (amount: BN, programId: PublicKey, { authority, recipient, recipientTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, }: WithdrawAccounts) => TransactionInstruction;
|
|
54
54
|
interface CancelAccounts {
|
|
55
55
|
authority: PublicKey;
|
|
56
56
|
sender: PublicKey;
|
|
@@ -93,5 +93,5 @@ interface TopupAccounts {
|
|
|
93
93
|
withdrawor: PublicKey;
|
|
94
94
|
systemProgram: PublicKey;
|
|
95
95
|
}
|
|
96
|
-
export declare const topupStreamInstruction: (amount:
|
|
96
|
+
export declare const topupStreamInstruction: (amount: BN, programId: PublicKey, { sender, senderTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, withdrawor, systemProgram, }: TopupAccounts) => TransactionInstruction;
|
|
97
97
|
export {};
|
package/dist/instructions.js
CHANGED
|
@@ -61,12 +61,12 @@ var createStreamInstruction = function (data, programId, accounts) {
|
|
|
61
61
|
var encodedUIntArray = new TextEncoder().encode(data.name);
|
|
62
62
|
var streamNameBuffer = buffer_1.Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
|
|
63
63
|
var decodedData = {
|
|
64
|
-
start_time: data.start.
|
|
65
|
-
net_amount_deposited: data.depositedAmount.
|
|
66
|
-
period: data.period.
|
|
67
|
-
amount_per_period: data.amountPerPeriod.
|
|
68
|
-
cliff: data.cliff.
|
|
69
|
-
cliff_amount: data.cliffAmount.
|
|
64
|
+
start_time: data.start.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
65
|
+
net_amount_deposited: data.depositedAmount.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
66
|
+
period: data.period.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
67
|
+
amount_per_period: data.amountPerPeriod.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
68
|
+
cliff: data.cliff.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
69
|
+
cliff_amount: data.cliffAmount.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
70
70
|
cancelable_by_sender: data.cancelableBySender,
|
|
71
71
|
cancelable_by_recipient: data.cancelableByRecipient,
|
|
72
72
|
automatic_withdrawal: data.automaticWithdrawal,
|
|
@@ -74,7 +74,7 @@ var createStreamInstruction = function (data, programId, accounts) {
|
|
|
74
74
|
transferable_by_recipient: data.transferableByRecipient,
|
|
75
75
|
can_topup: data.canTopup,
|
|
76
76
|
stream_name: streamNameBuffer,
|
|
77
|
-
withdraw_frequency: data.withdrawFrequency.
|
|
77
|
+
withdraw_frequency: data.withdrawFrequency.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
78
78
|
};
|
|
79
79
|
var encodeLength = Layout.createStreamLayout.encode(decodedData, bufferData);
|
|
80
80
|
bufferData = bufferData.slice(0, encodeLength);
|
|
@@ -109,7 +109,7 @@ var withdrawStreamInstruction = function (amount, programId, _a) {
|
|
|
109
109
|
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
110
110
|
];
|
|
111
111
|
var data = buffer_1.Buffer.alloc(Layout.withdrawStreamLayout.span);
|
|
112
|
-
var decodedData = { amount: amount.
|
|
112
|
+
var decodedData = { amount: amount.toArrayLike(buffer_1.Buffer, "le", 8) };
|
|
113
113
|
var encodeLength = Layout.withdrawStreamLayout.encode(decodedData, data);
|
|
114
114
|
data = data.slice(0, encodeLength);
|
|
115
115
|
data = buffer_1.Buffer.concat([
|
|
@@ -194,7 +194,7 @@ var topupStreamInstruction = function (amount, programId, _a) {
|
|
|
194
194
|
{ pubkey: systemProgram, isSigner: false, isWritable: false },
|
|
195
195
|
];
|
|
196
196
|
var data = buffer_1.Buffer.alloc(Layout.topupStreamLayout.span);
|
|
197
|
-
var decodedData = { amount: amount.
|
|
197
|
+
var decodedData = { amount: amount.toArrayLike(buffer_1.Buffer, "le", 8) };
|
|
198
198
|
var encodeLength = Layout.topupStreamLayout.encode(decodedData, data);
|
|
199
199
|
data = data.slice(0, encodeLength);
|
|
200
200
|
data = buffer_1.Buffer.concat([
|
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,7 +42,7 @@ export interface CreateStreamData {
|
|
|
42
42
|
}
|
|
43
43
|
export interface MultiRecipient {
|
|
44
44
|
recipient: string;
|
|
45
|
-
depositedAmount:
|
|
45
|
+
depositedAmount: BN;
|
|
46
46
|
name: string;
|
|
47
47
|
}
|
|
48
48
|
export interface CreateMultiData {
|
|
@@ -51,8 +51,8 @@ export interface CreateMultiData {
|
|
|
51
51
|
start: number;
|
|
52
52
|
period: number;
|
|
53
53
|
cliff: number;
|
|
54
|
-
cliffAmount:
|
|
55
|
-
amountPerPeriod:
|
|
54
|
+
cliffAmount: BN;
|
|
55
|
+
amountPerPeriod: BN;
|
|
56
56
|
canTopup: boolean;
|
|
57
57
|
cancelableBySender: boolean;
|
|
58
58
|
cancelableByRecipient: boolean;
|
|
@@ -77,7 +77,7 @@ export interface CreateMultiParams extends CreateMultiData {
|
|
|
77
77
|
}
|
|
78
78
|
export interface WithdrawStreamData {
|
|
79
79
|
id: string;
|
|
80
|
-
amount:
|
|
80
|
+
amount: BN;
|
|
81
81
|
}
|
|
82
82
|
export interface WithdrawStreamParams extends WithdrawStreamData {
|
|
83
83
|
connection: Connection;
|
|
@@ -89,7 +89,7 @@ export interface WithdrawParams extends WithdrawStreamData {
|
|
|
89
89
|
}
|
|
90
90
|
export interface TopupStreamData {
|
|
91
91
|
id: string;
|
|
92
|
-
amount:
|
|
92
|
+
amount: BN;
|
|
93
93
|
}
|
|
94
94
|
export interface TopupStreamParams extends TopupStreamData {
|
|
95
95
|
connection: Connection;
|
|
@@ -142,7 +142,7 @@ export interface Stream {
|
|
|
142
142
|
magic: number;
|
|
143
143
|
version: number;
|
|
144
144
|
createdAt: number;
|
|
145
|
-
withdrawnAmount:
|
|
145
|
+
withdrawnAmount: BN;
|
|
146
146
|
canceledAt: number;
|
|
147
147
|
end: number;
|
|
148
148
|
lastWithdrawnAt: number;
|
|
@@ -154,20 +154,20 @@ export interface Stream {
|
|
|
154
154
|
escrowTokens: string;
|
|
155
155
|
streamflowTreasury: string;
|
|
156
156
|
streamflowTreasuryTokens: string;
|
|
157
|
-
streamflowFeeTotal:
|
|
158
|
-
streamflowFeeWithdrawn:
|
|
157
|
+
streamflowFeeTotal: BN;
|
|
158
|
+
streamflowFeeWithdrawn: BN;
|
|
159
159
|
streamflowFeePercent: number;
|
|
160
|
-
partnerFeeTotal:
|
|
161
|
-
partnerFeeWithdrawn:
|
|
160
|
+
partnerFeeTotal: BN;
|
|
161
|
+
partnerFeeWithdrawn: BN;
|
|
162
162
|
partnerFeePercent: number;
|
|
163
163
|
partner: string;
|
|
164
164
|
partnerTokens: string;
|
|
165
165
|
start: number;
|
|
166
|
-
depositedAmount:
|
|
166
|
+
depositedAmount: BN;
|
|
167
167
|
period: number;
|
|
168
|
-
amountPerPeriod:
|
|
168
|
+
amountPerPeriod: BN;
|
|
169
169
|
cliff: number;
|
|
170
|
-
cliffAmount:
|
|
170
|
+
cliffAmount: BN;
|
|
171
171
|
cancelableBySender: boolean;
|
|
172
172
|
cancelableByRecipient: boolean;
|
|
173
173
|
automaticWithdrawal: boolean;
|
|
@@ -178,13 +178,13 @@ export interface Stream {
|
|
|
178
178
|
withdrawalFrequency: number;
|
|
179
179
|
}
|
|
180
180
|
export interface DecodedStream {
|
|
181
|
-
magic:
|
|
182
|
-
version:
|
|
183
|
-
createdAt:
|
|
184
|
-
withdrawnAmount:
|
|
185
|
-
canceledAt:
|
|
186
|
-
end:
|
|
187
|
-
lastWithdrawnAt:
|
|
181
|
+
magic: BN;
|
|
182
|
+
version: BN;
|
|
183
|
+
createdAt: BN;
|
|
184
|
+
withdrawnAmount: BN;
|
|
185
|
+
canceledAt: BN;
|
|
186
|
+
end: BN;
|
|
187
|
+
lastWithdrawnAt: BN;
|
|
188
188
|
sender: PublicKey;
|
|
189
189
|
senderTokens: PublicKey;
|
|
190
190
|
recipient: PublicKey;
|
|
@@ -193,20 +193,20 @@ export interface DecodedStream {
|
|
|
193
193
|
escrowTokens: PublicKey;
|
|
194
194
|
streamflowTreasury: PublicKey;
|
|
195
195
|
streamflowTreasuryTokens: PublicKey;
|
|
196
|
-
streamflowFeeTotal:
|
|
197
|
-
streamflowFeeWithdrawn:
|
|
198
|
-
streamflowFeePercent:
|
|
199
|
-
partnerFeeTotal:
|
|
200
|
-
partnerFeeWithdrawn:
|
|
201
|
-
partnerFeePercent:
|
|
196
|
+
streamflowFeeTotal: BN;
|
|
197
|
+
streamflowFeeWithdrawn: BN;
|
|
198
|
+
streamflowFeePercent: BN;
|
|
199
|
+
partnerFeeTotal: BN;
|
|
200
|
+
partnerFeeWithdrawn: BN;
|
|
201
|
+
partnerFeePercent: BN;
|
|
202
202
|
partner: PublicKey;
|
|
203
203
|
partnerTokens: PublicKey;
|
|
204
|
-
start:
|
|
205
|
-
depositedAmount:
|
|
206
|
-
period:
|
|
207
|
-
amountPerPeriod:
|
|
208
|
-
cliff:
|
|
209
|
-
cliffAmount:
|
|
204
|
+
start: BN;
|
|
205
|
+
depositedAmount: BN;
|
|
206
|
+
period: BN;
|
|
207
|
+
amountPerPeriod: BN;
|
|
208
|
+
cliff: BN;
|
|
209
|
+
cliffAmount: BN;
|
|
210
210
|
cancelableBySender: boolean;
|
|
211
211
|
cancelableByRecipient: boolean;
|
|
212
212
|
automaticWithdrawal: boolean;
|
|
@@ -214,7 +214,7 @@ export interface DecodedStream {
|
|
|
214
214
|
transferableByRecipient: boolean;
|
|
215
215
|
canTopup: boolean;
|
|
216
216
|
name: string;
|
|
217
|
-
withdrawFrequency:
|
|
217
|
+
withdrawFrequency: BN;
|
|
218
218
|
}
|
|
219
219
|
export interface TransactionResponse {
|
|
220
220
|
tx: TransactionSignature;
|
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,7 +48,7 @@ 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;
|
|
@@ -95,24 +98,24 @@ exports.formatDecodedStream = formatDecodedStream;
|
|
|
95
98
|
/**
|
|
96
99
|
* Used for conversion of token amounts to their Big Number representation.
|
|
97
100
|
* 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
|
|
101
|
+
* @param {number} value - Number of tokens you want to convert to its BN representation.
|
|
99
102
|
* @param {number} decimals - Number of decimals the token has.
|
|
100
103
|
*/
|
|
101
104
|
var getBN = function (value, decimals) {
|
|
102
105
|
return value > (Math.pow(2, 53) - 1) / Math.pow(10, decimals)
|
|
103
|
-
? new
|
|
104
|
-
: new
|
|
106
|
+
? new bn_js_1.default(value).mul(new bn_js_1.default(Math.pow(10, decimals)))
|
|
107
|
+
: new bn_js_1.default(value * Math.pow(10, decimals));
|
|
105
108
|
};
|
|
106
109
|
exports.getBN = getBN;
|
|
107
110
|
/**
|
|
108
111
|
* Used for token amounts conversion from their Big Number representation to number.
|
|
109
|
-
* Get value in the highest units from
|
|
110
|
-
* @param {
|
|
112
|
+
* Get value in the highest units from BN representation of the same value in the smallest units.
|
|
113
|
+
* @param {BN} value - Big Number representation of value in the smallest units.
|
|
111
114
|
* @param {number} decimals - Number of decimals the token has.
|
|
112
115
|
*/
|
|
113
116
|
var getNumberFromBN = function (value, decimals) {
|
|
114
|
-
return value.gt(new
|
|
115
|
-
? value.div(new
|
|
117
|
+
return value.gt(new bn_js_1.default(Math.pow(2, 53) - 1))
|
|
118
|
+
? value.div(new bn_js_1.default(Math.pow(10, decimals))).toNumber()
|
|
116
119
|
: value.toNumber() / Math.pow(10, decimals);
|
|
117
120
|
};
|
|
118
121
|
exports.getNumberFromBN = getNumberFromBN;
|
package/package.json
CHANGED