@zebec-network/zebec-stream-sdk 1.0.0
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/LICENSE +21 -0
- package/README.md +354 -0
- package/dist/artifacts/index.d.ts +3 -0
- package/dist/artifacts/index.js +9 -0
- package/dist/artifacts/zebec_stream.d.ts +1307 -0
- package/dist/artifacts/zebec_stream.js +2 -0
- package/dist/artifacts/zebec_stream.json +1061 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +4 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +21 -0
- package/dist/pda.d.ts +4 -0
- package/dist/pda.js +15 -0
- package/dist/providers.d.ts +17 -0
- package/dist/providers.js +24 -0
- package/dist/service.d.ts +108 -0
- package/dist/service.js +337 -0
- package/dist/types.d.ts +43 -0
- package/dist/types.js +2 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Zebec Protocol
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
# Zebec Stream SDK
|
|
2
|
+
|
|
3
|
+
A TypeScript SDK for interacting with the Zebec Stream protocol on Solana. This SDK provides a comprehensive interface for creating, managing, and interacting with payment streams on the Zebec Network.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Stream Management**: Create, cancel, pause, and resume payment streams
|
|
8
|
+
- **Token Streaming**: Support for SPL token streaming with customizable parameters
|
|
9
|
+
- **Admin Functions**: Configuration management and token whitelisting
|
|
10
|
+
- **Flexible Permissions**: Granular control over stream permissions and capabilities
|
|
11
|
+
- **Type Safety**: Full TypeScript support with comprehensive type definitions
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @zebec-network/stream-sdk
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
yarn add @zebec-network/stream-sdk
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
### Setting up the Service
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
29
|
+
import { ZebecStreamService, createAnchorProvider } from "@zebec-network/stream-sdk";
|
|
30
|
+
|
|
31
|
+
// Create connection
|
|
32
|
+
const connection = new Connection("https://api.devnet.solana.com");
|
|
33
|
+
|
|
34
|
+
// Create provider with your wallet
|
|
35
|
+
const provider = createAnchorProvider(connection, wallet);
|
|
36
|
+
|
|
37
|
+
// Initialize the service
|
|
38
|
+
const streamService = ZebecStreamService.create(provider, "devnet");
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Creating a Stream
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
const streamParams = {
|
|
45
|
+
receiver: "ReceiverPublicKeyHere",
|
|
46
|
+
sender: "SenderPublicKeyHere",
|
|
47
|
+
streamToken: "TokenMintAddressHere",
|
|
48
|
+
amount: "1000", // Amount in token units
|
|
49
|
+
duration: 86400, // 1 day in seconds
|
|
50
|
+
streamFrequency: 3600, // 1 hour in seconds
|
|
51
|
+
streamName: "Monthly Salary",
|
|
52
|
+
startNow: true,
|
|
53
|
+
automaticWithdrawal: false,
|
|
54
|
+
cancelableByRecipient: true,
|
|
55
|
+
cancelableBySender: true,
|
|
56
|
+
isPausable: true,
|
|
57
|
+
transferableByRecipient: false,
|
|
58
|
+
transferableBySender: false,
|
|
59
|
+
canTopup: true,
|
|
60
|
+
rateUpdatable: false,
|
|
61
|
+
cliffPercentage: 0, // No cliff
|
|
62
|
+
startTime: Math.floor(Date.now() / 1000)
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const transaction = await streamService.createStream(streamParams);
|
|
66
|
+
const signature = await transaction.execute();
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## API Reference
|
|
70
|
+
|
|
71
|
+
### ZebecStreamService
|
|
72
|
+
|
|
73
|
+
The main service class for interacting with Zebec streams.
|
|
74
|
+
|
|
75
|
+
#### Constructor
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
static create(provider: Provider, network: "mainnet-beta" | "devnet"): ZebecStreamService
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Stream Operations
|
|
82
|
+
|
|
83
|
+
#### createStream(params: CreateStreamParams)
|
|
84
|
+
|
|
85
|
+
Creates a new payment stream.
|
|
86
|
+
|
|
87
|
+
**Parameters:**
|
|
88
|
+
|
|
89
|
+
- `receiver`: Address - The recipient's public key
|
|
90
|
+
- `sender`: Address - The sender's public key
|
|
91
|
+
- `streamToken`: Address - The SPL token mint address
|
|
92
|
+
- `amount`: Numeric - Amount to stream (in token units)
|
|
93
|
+
- `duration`: number - Stream duration in seconds
|
|
94
|
+
- `streamFrequency`: number - Withdrawal frequency in seconds
|
|
95
|
+
- `streamName`: string - Human-readable stream name
|
|
96
|
+
- `startNow`: boolean - Whether to start immediately
|
|
97
|
+
- `startTime`: number - Unix timestamp for stream start
|
|
98
|
+
- `cliffPercentage`: Numeric - Percentage locked until cliff period
|
|
99
|
+
- `automaticWithdrawal`: boolean - Enable automatic withdrawals
|
|
100
|
+
- `cancelableByRecipient`: boolean - Allow recipient to cancel
|
|
101
|
+
- `cancelableBySender`: boolean - Allow sender to cancel
|
|
102
|
+
- `isPausable`: boolean - Allow stream pausing
|
|
103
|
+
- `transferableByRecipient`: boolean - Allow recipient to transfer
|
|
104
|
+
- `transferableBySender`: boolean - Allow sender to transfer
|
|
105
|
+
- `canTopup`: boolean - Allow adding funds to stream
|
|
106
|
+
- `rateUpdatable`: boolean - Allow rate modifications
|
|
107
|
+
- `feePayer?`: Address - Optional custom fee payer
|
|
108
|
+
- `streamMetadataKeypair?`: Keypair - Optional custom metadata keypair
|
|
109
|
+
|
|
110
|
+
#### cancelStream(params: CancelStreamParams)
|
|
111
|
+
|
|
112
|
+
Cancels an existing stream.
|
|
113
|
+
|
|
114
|
+
**Parameters:**
|
|
115
|
+
|
|
116
|
+
- `streamMetadata`: Address - The stream metadata account address
|
|
117
|
+
- `user`: Address - The user canceling the stream (sender or receiver)
|
|
118
|
+
- `feePayer?`: Address - Optional custom fee payer
|
|
119
|
+
|
|
120
|
+
#### pauseResumeStream(params: PauseResumeStreamParams)
|
|
121
|
+
|
|
122
|
+
Pauses or resumes a stream.
|
|
123
|
+
|
|
124
|
+
**Parameters:**
|
|
125
|
+
|
|
126
|
+
- `streamMetadata`: Address - The stream metadata account address
|
|
127
|
+
|
|
128
|
+
#### withdrawStream(params: WithdrawStreamParams)
|
|
129
|
+
|
|
130
|
+
Withdraws available tokens from a stream.
|
|
131
|
+
|
|
132
|
+
**Parameters:**
|
|
133
|
+
|
|
134
|
+
- `streamMetadata`: Address - The stream metadata account address
|
|
135
|
+
- `receiver`: Address - The recipient's address
|
|
136
|
+
- `withdrawer?`: Address - Optional custom withdrawer (defaults to receiver)
|
|
137
|
+
|
|
138
|
+
#### changeStreamReceiver(params: ChangeStreamReceiverParams)
|
|
139
|
+
|
|
140
|
+
Changes the recipient of a stream.
|
|
141
|
+
|
|
142
|
+
**Parameters:**
|
|
143
|
+
|
|
144
|
+
- `streamMetadata`: Address - The stream metadata account address
|
|
145
|
+
- `newRecipient`: Address - The new recipient's address
|
|
146
|
+
- `signer`: Address - The current authorized signer
|
|
147
|
+
|
|
148
|
+
### Information Retrieval
|
|
149
|
+
|
|
150
|
+
#### getStreamMetadataInfo(streamMetadata: Address, commitment?: Commitment)
|
|
151
|
+
|
|
152
|
+
Retrieves detailed information about a stream.
|
|
153
|
+
|
|
154
|
+
**Returns:** `StreamMetadataInfo` containing:
|
|
155
|
+
|
|
156
|
+
- `parties`: Sender and receiver addresses
|
|
157
|
+
- `financials`: Token info, amounts, and cliff percentage
|
|
158
|
+
- `schedule`: Timing information and status
|
|
159
|
+
- `permissions`: Stream permission settings
|
|
160
|
+
- `streamName`: The stream's name
|
|
161
|
+
|
|
162
|
+
#### getStreamConfigInfo(commitment?: Commitment)
|
|
163
|
+
|
|
164
|
+
Retrieves global stream configuration.
|
|
165
|
+
|
|
166
|
+
**Returns:** `StreamConfigInfo` containing:
|
|
167
|
+
|
|
168
|
+
- `admin`: Admin public key
|
|
169
|
+
- `withdrawerAccount`: Withdraw account address
|
|
170
|
+
- `whitelistedTokens`: Array of whitelisted token addresses
|
|
171
|
+
- `platformFee`: Platform fee percentage
|
|
172
|
+
- `baseFee`: Base fee percentage
|
|
173
|
+
- `frequencies`: Allowed stream frequencies
|
|
174
|
+
|
|
175
|
+
### Admin Operations
|
|
176
|
+
|
|
177
|
+
#### initializeConfig(params: InitializeConfigParams)
|
|
178
|
+
|
|
179
|
+
Initializes the global stream configuration (admin only).
|
|
180
|
+
|
|
181
|
+
**Parameters:**
|
|
182
|
+
|
|
183
|
+
- `admin?`: Address - Admin address (defaults to provider wallet)
|
|
184
|
+
- `config.baseFeePercent`: Numeric - Base fee percentage
|
|
185
|
+
- `config.platformFeePercent`: Numeric - Platform fee percentage
|
|
186
|
+
- `config.frequencies`: number[] - Allowed stream frequencies
|
|
187
|
+
- `config.withdrawAccount`: Address - Platform withdraw account
|
|
188
|
+
|
|
189
|
+
#### whiteListTokens(params: WhiteListTokensParams)
|
|
190
|
+
|
|
191
|
+
Adds tokens to the whitelist (admin only).
|
|
192
|
+
|
|
193
|
+
**Parameters:**
|
|
194
|
+
|
|
195
|
+
- `admin`: Address - Admin address
|
|
196
|
+
- `tokens`: Address[] - Array of token mint addresses to whitelist
|
|
197
|
+
|
|
198
|
+
## Types
|
|
199
|
+
|
|
200
|
+
### StreamMetadataInfo
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
type StreamMetadataInfo = {
|
|
204
|
+
parties: {
|
|
205
|
+
sender: PublicKey;
|
|
206
|
+
receiver: PublicKey;
|
|
207
|
+
};
|
|
208
|
+
financials: {
|
|
209
|
+
streamToken: PublicKey;
|
|
210
|
+
cliffPercentage: number;
|
|
211
|
+
depositedAmount: string;
|
|
212
|
+
withdrawnAmount: string;
|
|
213
|
+
};
|
|
214
|
+
schedule: {
|
|
215
|
+
startTime: number;
|
|
216
|
+
endTime: number;
|
|
217
|
+
lastWithdrawTime: number;
|
|
218
|
+
frequency: number;
|
|
219
|
+
duration: number;
|
|
220
|
+
pausedTimestamp: number;
|
|
221
|
+
pausedInterval: number;
|
|
222
|
+
canceledTimestamp: number;
|
|
223
|
+
};
|
|
224
|
+
permissions: {
|
|
225
|
+
cancelableBySender: boolean;
|
|
226
|
+
cancelableByRecipient: boolean;
|
|
227
|
+
automaticWithdrawal: boolean;
|
|
228
|
+
transferableBySender: boolean;
|
|
229
|
+
transferableByRecipient: boolean;
|
|
230
|
+
canTopup: boolean;
|
|
231
|
+
isPausable: boolean;
|
|
232
|
+
rateUpdatable: boolean;
|
|
233
|
+
};
|
|
234
|
+
streamName: string;
|
|
235
|
+
};
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### StreamConfigInfo
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
type StreamConfigInfo = {
|
|
242
|
+
admin: PublicKey;
|
|
243
|
+
withdrawerAccount: PublicKey;
|
|
244
|
+
whitelistedTokens: PublicKey[];
|
|
245
|
+
platformFee: number;
|
|
246
|
+
baseFee: number;
|
|
247
|
+
frequencies: number[];
|
|
248
|
+
};
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## Provider Setup
|
|
252
|
+
|
|
253
|
+
### AnchorProvider (Read/Write Operations)
|
|
254
|
+
|
|
255
|
+
For operations that require signing transactions:
|
|
256
|
+
|
|
257
|
+
```typescript
|
|
258
|
+
import { createAnchorProvider } from "@zebec-network/stream-sdk";
|
|
259
|
+
|
|
260
|
+
const provider = createAnchorProvider(connection, wallet, {
|
|
261
|
+
commitment: "confirmed",
|
|
262
|
+
preflightCommitment: "confirmed"
|
|
263
|
+
});
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### ReadonlyProvider (Read-Only Operations)
|
|
267
|
+
|
|
268
|
+
For read-only operations:
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
import { createReadonlyProvider } from "@zebec-network/stream-sdk";
|
|
272
|
+
|
|
273
|
+
const provider = createReadonlyProvider(connection, optionalWalletAddress);
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
## Examples
|
|
277
|
+
|
|
278
|
+
### Complete Stream Lifecycle
|
|
279
|
+
|
|
280
|
+
```typescript
|
|
281
|
+
// 1. Create a stream
|
|
282
|
+
const createParams = {
|
|
283
|
+
receiver: receiverAddress,
|
|
284
|
+
sender: senderAddress,
|
|
285
|
+
streamToken: tokenMintAddress,
|
|
286
|
+
amount: "1000",
|
|
287
|
+
duration: 86400, // 1 day
|
|
288
|
+
streamFrequency: 3600, // 1 hour
|
|
289
|
+
streamName: "Test Stream",
|
|
290
|
+
startNow: true,
|
|
291
|
+
// ... other parameters
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
const createTx = await streamService.createStream(createParams);
|
|
295
|
+
await createTx.execute();
|
|
296
|
+
|
|
297
|
+
// 2. Get stream info
|
|
298
|
+
const streamInfo = await streamService.getStreamMetadataInfo(streamMetadata);
|
|
299
|
+
console.log("Stream info:", streamInfo);
|
|
300
|
+
|
|
301
|
+
// 3. Withdraw from stream
|
|
302
|
+
const withdrawTx = await streamService.withdrawStream({
|
|
303
|
+
streamMetadata,
|
|
304
|
+
receiver: receiverAddress
|
|
305
|
+
});
|
|
306
|
+
await withdrawTx.execute();
|
|
307
|
+
|
|
308
|
+
// 4. Cancel stream
|
|
309
|
+
const cancelTx = await streamService.cancelStream({
|
|
310
|
+
streamMetadata,
|
|
311
|
+
user: senderAddress
|
|
312
|
+
});
|
|
313
|
+
await cancelTx.execute();
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### Error Handling
|
|
317
|
+
|
|
318
|
+
```typescript
|
|
319
|
+
try {
|
|
320
|
+
const transaction = await streamService.createStream(params);
|
|
321
|
+
const signature = await transaction.execute();
|
|
322
|
+
console.log("Stream created:", signature);
|
|
323
|
+
} catch (error) {
|
|
324
|
+
if (error.message.includes("Invalid stream frequency")) {
|
|
325
|
+
console.error("Please use an allowed stream frequency");
|
|
326
|
+
} else {
|
|
327
|
+
console.error("Stream creation failed:", error);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
## Network Support
|
|
333
|
+
|
|
334
|
+
- **Mainnet Beta**: Production environment
|
|
335
|
+
- **Devnet**: Development and testing environment
|
|
336
|
+
- **Testnet**: Not supported
|
|
337
|
+
|
|
338
|
+
## Dependencies
|
|
339
|
+
|
|
340
|
+
- `@coral-xyz/anchor`: Anchor framework for Solana
|
|
341
|
+
- `@solana/web3.js`: Solana Web3 JavaScript API
|
|
342
|
+
- `@zebec-network/core-utils`: Zebec utility functions
|
|
343
|
+
- `@zebec-network/solana-common`: Common Solana utilities
|
|
344
|
+
- `bignumber.js`: Arbitrary precision arithmetic
|
|
345
|
+
|
|
346
|
+
## License
|
|
347
|
+
|
|
348
|
+
This project is licensed under the MIT License.
|
|
349
|
+
|
|
350
|
+
## Support
|
|
351
|
+
|
|
352
|
+
For issues and questions:
|
|
353
|
+
|
|
354
|
+
- GitHub Issues: [Repository Issues](https://github.com/zebec-network/stream-sdk/issues)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ZEBEC_STREAM_IDL = void 0;
|
|
7
|
+
const zebec_stream_json_1 = __importDefault(require("./zebec_stream.json"));
|
|
8
|
+
const ZEBEC_STREAM_IDL = zebec_stream_json_1.default;
|
|
9
|
+
exports.ZEBEC_STREAM_IDL = ZEBEC_STREAM_IDL;
|