@zebec-network/zebec-vault-sdk 5.0.2 → 5.0.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 +476 -133
- package/dist/constants.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,219 +1,562 @@
|
|
|
1
|
-
# Zebec Vault
|
|
1
|
+
# Zebec Vault SDK
|
|
2
|
+
|
|
3
|
+
A TypeScript SDK for interacting with Zebec Vault on Solana, enabling secure multi operations, token streaming, staking, and virtual card management.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Vault Management**: Create and manage secure vaults with proposal-based execution
|
|
8
|
+
- **Token Operations**: Deposit and withdraw SOL and SPL tokens
|
|
9
|
+
- **Streaming Payments**: Create, manage, and cancel payment streams
|
|
10
|
+
- **Staking**: Stake tokens with customizable lock periods
|
|
11
|
+
- **Virtual Cards**: Create and load Zebec cards with automatic token swapping
|
|
12
|
+
- **Multi-Signature Support**: Execute operations through proposals with multiple signers
|
|
13
|
+
- **Jupiter Integration**: Built-in token swapping for card operations
|
|
2
14
|
|
|
3
15
|
## Installation
|
|
4
16
|
|
|
5
17
|
```bash
|
|
6
|
-
|
|
18
|
+
npm install @zebec-network/zebec-vault-sdk
|
|
7
19
|
```
|
|
8
20
|
|
|
9
21
|
```bash
|
|
10
|
-
|
|
22
|
+
yarn add @zebec-network/zebec-vault-sdk
|
|
11
23
|
```
|
|
12
24
|
|
|
13
|
-
##
|
|
25
|
+
## Quick Start
|
|
14
26
|
|
|
15
|
-
|
|
27
|
+
### Setup
|
|
16
28
|
|
|
17
|
-
|
|
29
|
+
```typescript
|
|
30
|
+
import { Connection, Keypair } from "@solana/web3.js";
|
|
31
|
+
import { createAnchorProvider, ZebecVaultService } from "@zebec-network/zebec-vault-sdk";
|
|
18
32
|
|
|
19
|
-
|
|
33
|
+
// Create connection
|
|
34
|
+
const connection = new Connection("https://api.mainnet-beta.solana.com"); // use private dedicatd rpc for production
|
|
20
35
|
|
|
21
|
-
|
|
22
|
-
|
|
36
|
+
// Create wallet adapter
|
|
37
|
+
// for frontend application you can use wallet provided by the wallet provider
|
|
38
|
+
const wallet = useAnchorWallet();
|
|
39
|
+
// for server side app you can use Wallet class provided by @coral-xyz/anchor
|
|
40
|
+
const wallet = new Wallet(keypair); // create keypair from secret key
|
|
41
|
+
|
|
42
|
+
// Create provider
|
|
43
|
+
const provider = createAnchorProvider(connection, wallet);
|
|
44
|
+
|
|
45
|
+
// Initialize service
|
|
46
|
+
const vaultService = ZebecVaultService.create(provider, "mainnet-beta");
|
|
23
47
|
```
|
|
24
48
|
|
|
25
|
-
|
|
49
|
+
## Core Features
|
|
26
50
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
51
|
+
### 1. Vault Operations
|
|
52
|
+
|
|
53
|
+
#### Create a Vault
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
const payload = await vaultService.createVault({
|
|
57
|
+
payer: wallet.publicKey, // optional if using AnchorProvider
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const signature = await payload.execute();
|
|
61
|
+
console.log("Vault created:", signature);
|
|
31
62
|
```
|
|
32
63
|
|
|
33
|
-
|
|
64
|
+
#### Deposit SOL
|
|
34
65
|
|
|
35
|
-
|
|
66
|
+
```typescript
|
|
67
|
+
const payload = await vaultService.depositSol({
|
|
68
|
+
depositor: wallet.publicKey,
|
|
69
|
+
amount: 1.5, // SOL amount
|
|
70
|
+
});
|
|
36
71
|
|
|
37
|
-
|
|
38
|
-
npm publish --access public
|
|
72
|
+
await payload.execute();
|
|
39
73
|
```
|
|
40
74
|
|
|
41
|
-
|
|
75
|
+
#### Deposit SPL Tokens
|
|
42
76
|
|
|
43
|
-
|
|
77
|
+
```typescript
|
|
78
|
+
const payload = await vaultService.deposit({
|
|
79
|
+
depositor: wallet.publicKey,
|
|
80
|
+
tokenMint: "TOKEN_MINT_ADDRESS",
|
|
81
|
+
amount: 100, // token amount
|
|
82
|
+
});
|
|
44
83
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const connection = <Connection Instance>;
|
|
49
|
-
const provider = createAnchorProvider(connection, wallet);
|
|
50
|
-
const service = await ZebecVaultService.create(provider, network);
|
|
84
|
+
await payload.execute();
|
|
85
|
+
|
|
86
|
+
// Note: if WSOL address is given in tokenMint, it will wrap SOL to WSOL and deposit.
|
|
51
87
|
```
|
|
52
88
|
|
|
53
|
-
|
|
89
|
+
#### Withdraw SOL
|
|
54
90
|
|
|
55
|
-
```
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
vaultKeypair,
|
|
91
|
+
```typescript
|
|
92
|
+
const payload = await vaultService.withdrawSol({
|
|
93
|
+
withdrawer: wallet.publicKey,
|
|
94
|
+
amount: 0.5,
|
|
60
95
|
});
|
|
61
96
|
|
|
62
|
-
|
|
63
|
-
console.log("Signature:", signature);
|
|
97
|
+
await payload.execute();
|
|
64
98
|
```
|
|
65
99
|
|
|
66
|
-
|
|
100
|
+
#### Withdraw SPL Tokens
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
const payload = await vaultService.withdraw({
|
|
104
|
+
withdrawer: wallet.publicKey,
|
|
105
|
+
tokenMint: "TOKEN_MINT_ADDRESS",
|
|
106
|
+
amount: 50,
|
|
107
|
+
});
|
|
67
108
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const vault = vaultsInfo[0].vault;
|
|
109
|
+
await payload.execute();
|
|
110
|
+
|
|
111
|
+
// Note: if WSOL is address in given in tokenMint, it will with withdraw WSOL and unwrap into withdrawer wallet.
|
|
72
112
|
```
|
|
73
113
|
|
|
74
|
-
###
|
|
114
|
+
### 2. Proposal System
|
|
115
|
+
|
|
116
|
+
#### Create a Proposal
|
|
75
117
|
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const
|
|
118
|
+
```typescript
|
|
119
|
+
import { SystemProgram } from "@solana/web3.js";
|
|
120
|
+
|
|
121
|
+
// Create custom instructions
|
|
122
|
+
const instruction = SystemProgram.transfer({
|
|
123
|
+
fromPubkey: vaultSigner,
|
|
124
|
+
toPubkey: recipient,
|
|
125
|
+
lamports: 1000000,
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
const payload = await vaultService.createProposal({
|
|
129
|
+
proposer: wallet.publicKey,
|
|
130
|
+
name: "Transfer SOL",
|
|
131
|
+
actions: [instruction],
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
await payload.execute();
|
|
81
135
|
```
|
|
82
136
|
|
|
83
|
-
|
|
137
|
+
#### Execute a Proposal
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
const payload = await vaultService.executeProposal({
|
|
141
|
+
caller: wallet.publicKey,
|
|
142
|
+
proposal: proposalAddress,
|
|
143
|
+
addressLookupTables: [lookupTableAddress], // optional
|
|
144
|
+
});
|
|
84
145
|
|
|
85
|
-
|
|
86
|
-
const vault = <vault public key>;
|
|
87
|
-
const amount = 0.01;
|
|
88
|
-
const payload = await service.withdrawSol({ amount, vault });
|
|
89
|
-
const signature = await payload.execute({ commitment: "finalized" });
|
|
146
|
+
await payload.execute();
|
|
90
147
|
```
|
|
91
148
|
|
|
92
|
-
|
|
149
|
+
#### Execute Proposal Directly (Single Transaction)
|
|
93
150
|
|
|
94
|
-
```
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
151
|
+
```typescript
|
|
152
|
+
const payload = await vaultService.executeProposalDirect({
|
|
153
|
+
proposer: wallet.publicKey,
|
|
154
|
+
actions: [instruction1, instruction2],
|
|
155
|
+
addressLookupTables: [lookupTableAddress],
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
await payload.execute();
|
|
100
159
|
```
|
|
101
160
|
|
|
102
|
-
###
|
|
161
|
+
### 3. Payment Streaming
|
|
162
|
+
|
|
163
|
+
#### Create a Stream
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
const payload = await vaultService.createStreamFromVault({
|
|
167
|
+
vaultOwner: wallet.publicKey,
|
|
168
|
+
receiver: recipientAddress,
|
|
169
|
+
streamToken: tokenMintAddress,
|
|
170
|
+
amount: 1000, // total amount
|
|
171
|
+
duration: 2592000, // 30 days in seconds
|
|
172
|
+
startNow: true,
|
|
173
|
+
startTime: Math.floor(Date.now() / 1000),
|
|
174
|
+
automaticWithdrawal: false,
|
|
175
|
+
cancelableByRecipient: true,
|
|
176
|
+
cancelableBySender: true,
|
|
177
|
+
isPausable: true,
|
|
178
|
+
transferableByRecipient: false,
|
|
179
|
+
transferableBySender: false,
|
|
180
|
+
canTopup: true,
|
|
181
|
+
rateUpdatable: false,
|
|
182
|
+
cliffPercentage: 0, // 0-100
|
|
183
|
+
autoWithdrawFrequency: 86400, // 1 day
|
|
184
|
+
streamName: "Monthly Payment",
|
|
185
|
+
});
|
|
103
186
|
|
|
104
|
-
|
|
105
|
-
const vault = <vault public key>;
|
|
106
|
-
const tokenMint = "De31sBPcDejCVpZZh1fq8SNs7AcuWcBKuU3k2jqnkmKc";
|
|
107
|
-
const amount = 1;
|
|
108
|
-
const payload = await service.withdrawToken({ amount, vault, tokenMint });
|
|
109
|
-
const signature = await payload.execute({ commitment: "finalized" });
|
|
187
|
+
await payload.execute();
|
|
110
188
|
```
|
|
111
189
|
|
|
112
|
-
|
|
190
|
+
#### Create Multiple Streams
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
const payload = await vaultService.createMultipleStreamFromVault({
|
|
194
|
+
vaultOwner: wallet.publicKey,
|
|
195
|
+
streamInfo: [
|
|
196
|
+
{
|
|
197
|
+
receiver: recipient1,
|
|
198
|
+
streamToken: tokenMint,
|
|
199
|
+
amount: 500,
|
|
200
|
+
duration: 2592000,
|
|
201
|
+
// ... other stream parameters
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
receiver: recipient2,
|
|
205
|
+
streamToken: tokenMint,
|
|
206
|
+
amount: 1000,
|
|
207
|
+
duration: 2592000,
|
|
208
|
+
// ... other stream parameters
|
|
209
|
+
},
|
|
210
|
+
],
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
// Execute all streams in multiple transactions
|
|
214
|
+
await payload.executeAll();
|
|
215
|
+
```
|
|
113
216
|
|
|
114
|
-
|
|
115
|
-
const proposer = <wallet public key>;
|
|
116
|
-
const vault = <vault public key>;
|
|
217
|
+
#### Pause/Resume a Stream
|
|
117
218
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
219
|
+
```typescript
|
|
220
|
+
const payload = await vaultService.pauseResumeStream({
|
|
221
|
+
vaultOwner: wallet.publicKey,
|
|
222
|
+
streamMetadata: streamAddress,
|
|
122
223
|
});
|
|
123
|
-
const actions = [memoInstruction];
|
|
124
224
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
225
|
+
await payload.execute();
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
#### Cancel a Stream
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
const payload = await vaultService.cancelStream({
|
|
232
|
+
vaultOwner: wallet.publicKey,
|
|
233
|
+
streamMetadata: streamAddress,
|
|
129
234
|
});
|
|
130
235
|
|
|
131
|
-
|
|
132
|
-
console.log("Execute Proposal Direct Signature:", signature);
|
|
236
|
+
await payload.execute();
|
|
133
237
|
```
|
|
134
238
|
|
|
135
|
-
|
|
239
|
+
#### Withdraw from Stream
|
|
136
240
|
|
|
137
|
-
```
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
241
|
+
```typescript
|
|
242
|
+
const payload = await vaultService.withdrawStream({
|
|
243
|
+
vaultOwner: wallet.publicKey,
|
|
244
|
+
streamMetadata: streamAddress,
|
|
245
|
+
});
|
|
141
246
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
247
|
+
await payload.execute();
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
#### Change Stream Receiver
|
|
251
|
+
|
|
252
|
+
```typescript
|
|
253
|
+
const payload = await vaultService.changeStreamReceiver({
|
|
254
|
+
vaultOwner: wallet.publicKey,
|
|
255
|
+
streamMetadata: streamAddress,
|
|
256
|
+
newRecipient: newRecipientAddress,
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
await payload.execute();
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
#### Get Stream Information
|
|
263
|
+
|
|
264
|
+
```typescript
|
|
265
|
+
const streamInfo = await vaultService.getStreamMetadataInfo(streamAddress);
|
|
266
|
+
|
|
267
|
+
console.log("Stream details:", {
|
|
268
|
+
sender: streamInfo.parties.sender,
|
|
269
|
+
receiver: streamInfo.parties.receiver,
|
|
270
|
+
token: streamInfo.financials.streamToken,
|
|
271
|
+
deposited: streamInfo.financials.depositedAmount,
|
|
272
|
+
withdrawn: streamInfo.financials.withdrawnAmount,
|
|
273
|
+
startTime: new Date(streamInfo.schedule.startTime * 1000),
|
|
274
|
+
endTime: new Date(streamInfo.schedule.endTime * 1000),
|
|
275
|
+
isPaused: streamInfo.schedule.pausedTimestamp > 0,
|
|
276
|
+
});
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### 4. Staking
|
|
280
|
+
|
|
281
|
+
#### Stake Tokens
|
|
282
|
+
|
|
283
|
+
```typescript
|
|
284
|
+
const payload = await vaultService.stake({
|
|
285
|
+
lockupName: "main-lockup",
|
|
286
|
+
vaultOwner: wallet.publicKey,
|
|
287
|
+
amount: 1000,
|
|
288
|
+
lockPeriod: 7776000, // 90 days in seconds
|
|
289
|
+
nonce: 0n,
|
|
148
290
|
});
|
|
149
|
-
const actions = [ix];
|
|
150
|
-
const proposalKeypair = Keypair.generate();
|
|
151
291
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
292
|
+
await payload.execute();
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
#### Unstake Tokens
|
|
296
|
+
|
|
297
|
+
```typescript
|
|
298
|
+
const payload = await vaultService.unstake({
|
|
299
|
+
lockupName: "main-lockup",
|
|
300
|
+
vaultOwner: wallet.publicKey,
|
|
301
|
+
nonce: 0n,
|
|
158
302
|
});
|
|
159
303
|
|
|
160
|
-
|
|
304
|
+
await payload.execute();
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
#### Get Stake Nonce Information
|
|
308
|
+
|
|
309
|
+
```typescript
|
|
310
|
+
const nonceInfo = await vaultService.getStakeUserNonceInfo("main-lockup", wallet.publicKey);
|
|
311
|
+
|
|
312
|
+
console.log("Current nonce:", nonceInfo?.nonce);
|
|
161
313
|
```
|
|
162
314
|
|
|
163
|
-
###
|
|
315
|
+
### 5. Virtual Cards
|
|
316
|
+
|
|
317
|
+
#### Create a Silver Card
|
|
164
318
|
|
|
165
|
-
```
|
|
166
|
-
const
|
|
319
|
+
```typescript
|
|
320
|
+
const nextIndex = await vaultService.getNextCardIndex();
|
|
167
321
|
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
322
|
+
const payload = await vaultService.createSilverCard({
|
|
323
|
+
vaultOwnerAddress: wallet.publicKey,
|
|
324
|
+
nextCardIndex: nextIndex,
|
|
325
|
+
amount: 100, // USDC amount
|
|
326
|
+
usdcAddress: USDC_MINT_ADDRESS,
|
|
327
|
+
emailHash: Buffer.from("your-32-byte-hash"),
|
|
328
|
+
currency: "USD",
|
|
172
329
|
});
|
|
173
|
-
const actionsB = [ixB];
|
|
174
330
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
331
|
+
await payload.execute();
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
#### Load a Carbon Card
|
|
335
|
+
|
|
336
|
+
```typescript
|
|
337
|
+
const nextIndex = await vaultService.getNextCardIndex();
|
|
338
|
+
|
|
339
|
+
const payload = await vaultService.loadCarbonCard({
|
|
340
|
+
vaultOwnerAddress: wallet.publicKey,
|
|
341
|
+
nextCardIndex: nextIndex,
|
|
342
|
+
amount: 50,
|
|
343
|
+
usdcAddress: USDC_MINT_ADDRESS,
|
|
344
|
+
emailHash: Buffer.from("your-32-byte-hash"),
|
|
345
|
+
currency: "USD",
|
|
346
|
+
reloadCardId: "CARD_ID",
|
|
178
347
|
});
|
|
179
348
|
|
|
180
|
-
|
|
349
|
+
await payload.execute();
|
|
181
350
|
```
|
|
182
351
|
|
|
183
|
-
|
|
352
|
+
#### Swap and Create Silver Card
|
|
353
|
+
|
|
354
|
+
```typescript
|
|
355
|
+
// First, get a Jupiter quote
|
|
356
|
+
const quoteResponse = await fetch(
|
|
357
|
+
`https://quote-api.jup.ag/v6/quote?inputMint=${inputMint}&outputMint=${USDC}&amount=${amount}&slippageBps=50`,
|
|
358
|
+
);
|
|
359
|
+
const quoteInfo = await quoteResponse.json();
|
|
360
|
+
|
|
361
|
+
const payload = await vaultService.swapAndCreateSilverCard({
|
|
362
|
+
vaultOwnerAddress: wallet.publicKey,
|
|
363
|
+
quoteInfo: quoteInfo,
|
|
364
|
+
nextCardCounter: nextIndex,
|
|
365
|
+
emailHash: Buffer.from("your-32-byte-hash"),
|
|
366
|
+
currency: "USD",
|
|
367
|
+
wrapAndUnwrapSol: true, // if swapping SOL
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
await payload.execute();
|
|
371
|
+
```
|
|
184
372
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
373
|
+
#### Swap and Load Carbon Card
|
|
374
|
+
|
|
375
|
+
```typescript
|
|
376
|
+
const payload = await vaultService.swapAndLoadCarbonCard({
|
|
377
|
+
vaultOwnerAddress: wallet.publicKey,
|
|
378
|
+
quoteInfo: quoteInfo,
|
|
379
|
+
nextCardCounter: nextIndex,
|
|
380
|
+
emailHash: Buffer.from("your-32-byte-hash"),
|
|
381
|
+
currency: "USD",
|
|
382
|
+
reloadCardId: "CARD_ID",
|
|
383
|
+
wrapAndUnwrapSol: true,
|
|
189
384
|
});
|
|
190
385
|
|
|
191
|
-
|
|
192
|
-
console.log("Execute Proposal Signature:", signature);
|
|
386
|
+
await payload.execute();
|
|
193
387
|
```
|
|
194
388
|
|
|
195
|
-
|
|
389
|
+
#### Get Card Custom Token Fees
|
|
196
390
|
|
|
197
|
-
```
|
|
198
|
-
const
|
|
391
|
+
```typescript
|
|
392
|
+
const tokenFees = await vaultService.getCardCustomTokenFees();
|
|
199
393
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
commitment: "confirmed",
|
|
394
|
+
tokenFees.forEach((fee) => {
|
|
395
|
+
console.log(`Token: ${fee.tokenAddress}, Fee: ${fee.fee}%`);
|
|
203
396
|
});
|
|
204
|
-
console.log("Delete Proposal Signature:", deleteProposalSignature);
|
|
205
397
|
```
|
|
206
398
|
|
|
207
|
-
|
|
399
|
+
## Query Functions
|
|
208
400
|
|
|
209
|
-
|
|
210
|
-
const vault = <vault public key>;
|
|
401
|
+
### Get Vault Information
|
|
211
402
|
|
|
212
|
-
|
|
403
|
+
```typescript
|
|
404
|
+
// Get specific user's vault
|
|
405
|
+
const vaultInfo = await vaultService.getVaultInfoOfUser(userAddress);
|
|
406
|
+
|
|
407
|
+
if (vaultInfo) {
|
|
408
|
+
console.log("Vault:", vaultInfo.vault.toString());
|
|
409
|
+
console.log("Owner:", vaultInfo.owner.toString());
|
|
410
|
+
console.log("Created:", new Date(vaultInfo.createdDate * 1000));
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// Get all vaults
|
|
414
|
+
const allVaults = await vaultService.getAllVaultsInfo();
|
|
415
|
+
console.log(`Total vaults: ${allVaults.length}`);
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
### Get Proposals
|
|
419
|
+
|
|
420
|
+
```typescript
|
|
421
|
+
const proposals = await vaultService.getProposalsInfoOfVault(vaultAddress);
|
|
422
|
+
|
|
423
|
+
proposals.forEach((proposal) => {
|
|
424
|
+
console.log("Proposal:", proposal.name);
|
|
425
|
+
console.log("Status:", proposal.proposalStage);
|
|
426
|
+
console.log("Actions:", proposal.actions.length);
|
|
427
|
+
console.log("Executed:", proposal.isExecuted);
|
|
428
|
+
});
|
|
213
429
|
```
|
|
214
430
|
|
|
215
|
-
|
|
431
|
+
## Readonly Provider
|
|
216
432
|
|
|
217
|
-
|
|
218
|
-
|
|
433
|
+
For read-only operations without a wallet:
|
|
434
|
+
|
|
435
|
+
```typescript
|
|
436
|
+
import { createReadonlyProvider } from "@zebec-network/zebec-vault-sdk";
|
|
437
|
+
|
|
438
|
+
const readonlyProvider = createReadonlyProvider(connection, optionalWalletAddress);
|
|
439
|
+
|
|
440
|
+
const service = ZebecVaultService.create(readonlyProvider, "mainnet-beta");
|
|
441
|
+
|
|
442
|
+
// Can only call query methods
|
|
443
|
+
const vaultInfo = await service.getVaultInfoOfUser(someAddress);
|
|
219
444
|
```
|
|
445
|
+
|
|
446
|
+
## Error Handling
|
|
447
|
+
|
|
448
|
+
The SDK provides custom error types:
|
|
449
|
+
|
|
450
|
+
```typescript
|
|
451
|
+
import {
|
|
452
|
+
AmountOutOfRangeError,
|
|
453
|
+
DailyCardLimitReachedError,
|
|
454
|
+
NotEnoughBalanceError,
|
|
455
|
+
AssociatedTokenAccountDoesNotExistsError,
|
|
456
|
+
} from "@zebec-network/zebec-vault-sdk";
|
|
457
|
+
|
|
458
|
+
try {
|
|
459
|
+
await payload.execute();
|
|
460
|
+
} catch (error) {
|
|
461
|
+
if (error instanceof AmountOutOfRangeError) {
|
|
462
|
+
console.error("Amount must be between", error.minRange, "and", error.maxRange);
|
|
463
|
+
} else if (error instanceof DailyCardLimitReachedError) {
|
|
464
|
+
console.error("Daily limit:", error.dailyCardLimit);
|
|
465
|
+
} else if (error instanceof NotEnoughBalanceError) {
|
|
466
|
+
console.error("Insufficient balance");
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
## Advanced Features
|
|
472
|
+
|
|
473
|
+
### Program Derived Addresses (PDAs)
|
|
474
|
+
|
|
475
|
+
```typescript
|
|
476
|
+
import {
|
|
477
|
+
deriveUserVault,
|
|
478
|
+
deriveVaultSigner,
|
|
479
|
+
deriveStreamConfigPda,
|
|
480
|
+
deriveCardConfigPda,
|
|
481
|
+
deriveLockupAddress,
|
|
482
|
+
} from "@zebec-network/zebec-vault-sdk";
|
|
483
|
+
|
|
484
|
+
const [vaultAddress, vaultBump] = deriveUserVault(userAddress, vaultProgramId);
|
|
485
|
+
|
|
486
|
+
const [signerAddress, signerBump] = deriveVaultSigner(vaultAddress, vaultProgramId);
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
### Transaction Utilities
|
|
490
|
+
|
|
491
|
+
```typescript
|
|
492
|
+
import { calculateProposalSize, transactionInstructionToProposalAction } from "@zebec-network/zebec-vault-sdk";
|
|
493
|
+
|
|
494
|
+
// Calculate proposal size
|
|
495
|
+
const size = calculateProposalSize("proposal-name", actions);
|
|
496
|
+
|
|
497
|
+
// Convert instruction to proposal action
|
|
498
|
+
const action = transactionInstructionToProposalAction(instruction);
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
## Network Configuration
|
|
502
|
+
|
|
503
|
+
```typescript
|
|
504
|
+
// Mainnet
|
|
505
|
+
const mainnetService = ZebecVaultService.create(provider, "mainnet-beta");
|
|
506
|
+
|
|
507
|
+
// Devnet
|
|
508
|
+
const devnetService = ZebecVaultService.create(provider, "devnet");
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
## Constants
|
|
512
|
+
|
|
513
|
+
```typescript
|
|
514
|
+
import {
|
|
515
|
+
ZEBEC_VAULT_PROGRAM_ID,
|
|
516
|
+
JUPITER_AGGREGATOR_PROGRAM_ID,
|
|
517
|
+
CARD_LOOKUP_TABLE_ADDRESS,
|
|
518
|
+
STAKE_LOOKUP_TABLE_ADDRESS,
|
|
519
|
+
} from "@zebec-network/zebec-vault-sdk";
|
|
520
|
+
|
|
521
|
+
console.log("Vault Program:", ZEBEC_VAULT_PROGRAM_ID["mainnet-beta"]);
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
## Types
|
|
525
|
+
|
|
526
|
+
The SDK exports comprehensive TypeScript types:
|
|
527
|
+
|
|
528
|
+
```typescript
|
|
529
|
+
import type {
|
|
530
|
+
VaultInfo,
|
|
531
|
+
ProposalInfo,
|
|
532
|
+
ProposalAction,
|
|
533
|
+
CreateStreamFromVaultParams,
|
|
534
|
+
StreamMetadataInfo,
|
|
535
|
+
TokenFeeRecord,
|
|
536
|
+
QuoteInfo,
|
|
537
|
+
StakeUserNonceInfo,
|
|
538
|
+
} from "@zebec-network/zebec-vault-sdk";
|
|
539
|
+
```
|
|
540
|
+
|
|
541
|
+
## Best Practices
|
|
542
|
+
|
|
543
|
+
1. **Always check balances** before operations
|
|
544
|
+
2. **Use proposals** for critical operations requiring multiple approvals
|
|
545
|
+
3. **Handle errors** appropriately with the provided error types
|
|
546
|
+
4. **Verify stream parameters** before creation (duration, amounts, permissions)
|
|
547
|
+
5. **Test on devnet** before deploying to mainnet
|
|
548
|
+
6. **Use address lookup tables** for complex transactions to reduce size
|
|
549
|
+
|
|
550
|
+
## Support
|
|
551
|
+
|
|
552
|
+
- **Documentation**: [Zebec Network Docs](https://docs.zebec.io)
|
|
553
|
+
- **GitHub**: [zebec-network](https://github.com/zebec-network)
|
|
554
|
+
- **Discord**: [Join our community](https://discord.gg/zebec)
|
|
555
|
+
|
|
556
|
+
## License
|
|
557
|
+
|
|
558
|
+
MIT
|
|
559
|
+
|
|
560
|
+
## Contributing
|
|
561
|
+
|
|
562
|
+
Contributions are welcome! Please read our contributing guidelines before submitting pull requests.
|
package/dist/constants.js
CHANGED
|
@@ -9,7 +9,7 @@ exports.ZEBEC_VAULT_PROGRAM_ID = {
|
|
|
9
9
|
exports.TEN_BIGNUM = (0, bignumber_js_1.BigNumber)(10);
|
|
10
10
|
exports.JUPITER_AGGREGATOR_PROGRAM_ID = "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4";
|
|
11
11
|
exports.CARD_LOOKUP_TABLE_ADDRESS = {
|
|
12
|
-
"mainnet-beta": "
|
|
12
|
+
"mainnet-beta": "9BSK7XgPgAZJK6BEdiFDV8WKGye31uffvGjhQ1Zxob7F",
|
|
13
13
|
devnet: "CgPARkLEbygMJ8C9Z1u6MP57gvdnUERCxdhmR9bTFUSJ",
|
|
14
14
|
};
|
|
15
15
|
exports.JUPITER_SWAP_API = "https://lite-api.jup.ag/swap/v1/swap";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zebec-network/zebec-vault-sdk",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.4",
|
|
4
4
|
"description": "An SDK for zebec vault solana program",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@solana/web3.js": "^1.98.2",
|
|
42
42
|
"@types/bn.js": "^5.2.0",
|
|
43
43
|
"@zebec-network/core-utils": "^1.1.1",
|
|
44
|
-
"@zebec-network/solana-common": "^2.3.
|
|
44
|
+
"@zebec-network/solana-common": "^2.3.1",
|
|
45
45
|
"bignumber.js": "^9.3.1",
|
|
46
46
|
"buffer": "^6.0.3"
|
|
47
47
|
}
|