@zebec-network/zebec-vault-sdk 5.0.1 → 5.0.3
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 +491 -133
- package/dist/constants.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,219 +1,577 @@
|
|
|
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
|
+
});
|
|
108
|
+
|
|
109
|
+
await payload.execute();
|
|
67
110
|
|
|
68
|
-
|
|
69
|
-
const vaultsInfo = await service.getVaultsInfoOfUser(wallet.publicKey);
|
|
70
|
-
console.log("vaults info:", JSON.stringify(vaultsInfo, null, 2));
|
|
71
|
-
const vault = vaultsInfo[0].vault;
|
|
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
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
import { SystemProgram } from '@solana/web3.js';
|
|
75
120
|
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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();
|
|
135
|
+
```
|
|
136
|
+
|
|
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
|
+
});
|
|
145
|
+
|
|
146
|
+
await payload.execute();
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
#### Execute Proposal Directly (Single Transaction)
|
|
150
|
+
|
|
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();
|
|
81
159
|
```
|
|
82
160
|
|
|
83
|
-
###
|
|
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
|
+
});
|
|
84
186
|
|
|
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" });
|
|
187
|
+
await payload.execute();
|
|
90
188
|
```
|
|
91
189
|
|
|
92
|
-
|
|
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
|
+
});
|
|
93
212
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const vault = <vault public key>;
|
|
97
|
-
const amount = 1000
|
|
98
|
-
const payload = await service.depositToken({ amount, vault, tokenMint });
|
|
99
|
-
const signature = await payload.execute({ commitment: "finalized" });
|
|
213
|
+
// Execute all streams in multiple transactions
|
|
214
|
+
await payload.executeAll();
|
|
100
215
|
```
|
|
101
216
|
|
|
102
|
-
|
|
217
|
+
#### Pause/Resume a Stream
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
const payload = await vaultService.pauseResumeStream({
|
|
221
|
+
vaultOwner: wallet.publicKey,
|
|
222
|
+
streamMetadata: streamAddress
|
|
223
|
+
});
|
|
103
224
|
|
|
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" });
|
|
225
|
+
await payload.execute();
|
|
110
226
|
```
|
|
111
227
|
|
|
112
|
-
|
|
228
|
+
#### Cancel a Stream
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
const payload = await vaultService.cancelStream({
|
|
232
|
+
vaultOwner: wallet.publicKey,
|
|
233
|
+
streamMetadata: streamAddress
|
|
234
|
+
});
|
|
113
235
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const vault = <vault public key>;
|
|
236
|
+
await payload.execute();
|
|
237
|
+
```
|
|
117
238
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
239
|
+
#### Withdraw from Stream
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
const payload = await vaultService.withdrawStream({
|
|
243
|
+
vaultOwner: wallet.publicKey,
|
|
244
|
+
streamMetadata: streamAddress
|
|
122
245
|
});
|
|
123
|
-
const actions = [memoInstruction];
|
|
124
246
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
|
129
257
|
});
|
|
130
258
|
|
|
131
|
-
|
|
132
|
-
console.log("Execute Proposal Direct Signature:", signature);
|
|
259
|
+
await payload.execute();
|
|
133
260
|
```
|
|
134
261
|
|
|
135
|
-
|
|
262
|
+
#### Get Stream Information
|
|
136
263
|
|
|
137
|
-
```
|
|
138
|
-
const
|
|
139
|
-
const receiver = <wallet public Key>;
|
|
140
|
-
const vault = <vault public key>;
|
|
264
|
+
```typescript
|
|
265
|
+
const streamInfo = await vaultService.getStreamMetadataInfo(streamAddress);
|
|
141
266
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
|
148
276
|
});
|
|
149
|
-
|
|
150
|
-
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### 4. Staking
|
|
280
|
+
|
|
281
|
+
#### Stake Tokens
|
|
151
282
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
|
158
290
|
});
|
|
159
291
|
|
|
160
|
-
|
|
292
|
+
await payload.execute();
|
|
161
293
|
```
|
|
162
294
|
|
|
163
|
-
|
|
295
|
+
#### Unstake Tokens
|
|
164
296
|
|
|
165
|
-
```
|
|
166
|
-
const
|
|
297
|
+
```typescript
|
|
298
|
+
const payload = await vaultService.unstake({
|
|
299
|
+
lockupName: 'main-lockup',
|
|
300
|
+
vaultOwner: wallet.publicKey,
|
|
301
|
+
nonce: 0n
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
await payload.execute();
|
|
305
|
+
```
|
|
167
306
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
307
|
+
#### Get Stake Nonce Information
|
|
308
|
+
|
|
309
|
+
```typescript
|
|
310
|
+
const nonceInfo = await vaultService.getStakeUserNonceInfo(
|
|
311
|
+
'main-lockup',
|
|
312
|
+
wallet.publicKey
|
|
313
|
+
);
|
|
314
|
+
|
|
315
|
+
console.log('Current nonce:', nonceInfo?.nonce);
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
### 5. Virtual Cards
|
|
319
|
+
|
|
320
|
+
#### Create a Silver Card
|
|
321
|
+
|
|
322
|
+
```typescript
|
|
323
|
+
const nextIndex = await vaultService.getNextCardIndex();
|
|
324
|
+
|
|
325
|
+
const payload = await vaultService.createSilverCard({
|
|
326
|
+
vaultOwnerAddress: wallet.publicKey,
|
|
327
|
+
nextCardIndex: nextIndex,
|
|
328
|
+
amount: 100, // USDC amount
|
|
329
|
+
usdcAddress: USDC_MINT_ADDRESS,
|
|
330
|
+
emailHash: Buffer.from('your-32-byte-hash'),
|
|
331
|
+
currency: 'USD'
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
await payload.execute();
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
#### Load a Carbon Card
|
|
338
|
+
|
|
339
|
+
```typescript
|
|
340
|
+
const nextIndex = await vaultService.getNextCardIndex();
|
|
341
|
+
|
|
342
|
+
const payload = await vaultService.loadCarbonCard({
|
|
343
|
+
vaultOwnerAddress: wallet.publicKey,
|
|
344
|
+
nextCardIndex: nextIndex,
|
|
345
|
+
amount: 50,
|
|
346
|
+
usdcAddress: USDC_MINT_ADDRESS,
|
|
347
|
+
emailHash: Buffer.from('your-32-byte-hash'),
|
|
348
|
+
currency: 'USD',
|
|
349
|
+
reloadCardId: 'CARD_ID'
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
await payload.execute();
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
#### Swap and Create Silver Card
|
|
356
|
+
|
|
357
|
+
```typescript
|
|
358
|
+
// First, get a Jupiter quote
|
|
359
|
+
const quoteResponse = await fetch(
|
|
360
|
+
`https://quote-api.jup.ag/v6/quote?inputMint=${inputMint}&outputMint=${USDC}&amount=${amount}&slippageBps=50`
|
|
361
|
+
);
|
|
362
|
+
const quoteInfo = await quoteResponse.json();
|
|
363
|
+
|
|
364
|
+
const payload = await vaultService.swapAndCreateSilverCard({
|
|
365
|
+
vaultOwnerAddress: wallet.publicKey,
|
|
366
|
+
quoteInfo: quoteInfo,
|
|
367
|
+
nextCardCounter: nextIndex,
|
|
368
|
+
emailHash: Buffer.from('your-32-byte-hash'),
|
|
369
|
+
currency: 'USD',
|
|
370
|
+
wrapAndUnwrapSol: true // if swapping SOL
|
|
172
371
|
});
|
|
173
|
-
const actionsB = [ixB];
|
|
174
372
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
373
|
+
await payload.execute();
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
#### Swap and Load Carbon Card
|
|
377
|
+
|
|
378
|
+
```typescript
|
|
379
|
+
const payload = await vaultService.swapAndLoadCarbonCard({
|
|
380
|
+
vaultOwnerAddress: wallet.publicKey,
|
|
381
|
+
quoteInfo: quoteInfo,
|
|
382
|
+
nextCardCounter: nextIndex,
|
|
383
|
+
emailHash: Buffer.from('your-32-byte-hash'),
|
|
384
|
+
currency: 'USD',
|
|
385
|
+
reloadCardId: 'CARD_ID',
|
|
386
|
+
wrapAndUnwrapSol: true
|
|
178
387
|
});
|
|
179
388
|
|
|
180
|
-
|
|
389
|
+
await payload.execute();
|
|
181
390
|
```
|
|
182
391
|
|
|
183
|
-
|
|
392
|
+
#### Get Card Custom Token Fees
|
|
393
|
+
|
|
394
|
+
```typescript
|
|
395
|
+
const tokenFees = await vaultService.getCardCustomTokenFees();
|
|
184
396
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
const payload = await service.executeProposal({
|
|
188
|
-
proposal,
|
|
397
|
+
tokenFees.forEach(fee => {
|
|
398
|
+
console.log(`Token: ${fee.tokenAddress}, Fee: ${fee.fee}%`);
|
|
189
399
|
});
|
|
400
|
+
```
|
|
190
401
|
|
|
191
|
-
|
|
192
|
-
|
|
402
|
+
## Query Functions
|
|
403
|
+
|
|
404
|
+
### Get Vault Information
|
|
405
|
+
|
|
406
|
+
```typescript
|
|
407
|
+
// Get specific user's vault
|
|
408
|
+
const vaultInfo = await vaultService.getVaultInfoOfUser(userAddress);
|
|
409
|
+
|
|
410
|
+
if (vaultInfo) {
|
|
411
|
+
console.log('Vault:', vaultInfo.vault.toString());
|
|
412
|
+
console.log('Owner:', vaultInfo.owner.toString());
|
|
413
|
+
console.log('Created:', new Date(vaultInfo.createdDate * 1000));
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// Get all vaults
|
|
417
|
+
const allVaults = await vaultService.getAllVaultsInfo();
|
|
418
|
+
console.log(`Total vaults: ${allVaults.length}`);
|
|
193
419
|
```
|
|
194
420
|
|
|
195
|
-
###
|
|
421
|
+
### Get Proposals
|
|
196
422
|
|
|
197
|
-
```
|
|
198
|
-
const
|
|
423
|
+
```typescript
|
|
424
|
+
const proposals = await vaultService.getProposalsInfoOfVault(vaultAddress);
|
|
199
425
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
426
|
+
proposals.forEach(proposal => {
|
|
427
|
+
console.log('Proposal:', proposal.name);
|
|
428
|
+
console.log('Status:', proposal.proposalStage);
|
|
429
|
+
console.log('Actions:', proposal.actions.length);
|
|
430
|
+
console.log('Executed:', proposal.isExecuted);
|
|
203
431
|
});
|
|
204
|
-
console.log("Delete Proposal Signature:", deleteProposalSignature);
|
|
205
432
|
```
|
|
206
433
|
|
|
207
|
-
|
|
434
|
+
## Readonly Provider
|
|
435
|
+
|
|
436
|
+
For read-only operations without a wallet:
|
|
437
|
+
|
|
438
|
+
```typescript
|
|
439
|
+
import { createReadonlyProvider } from '@zebec-network/zebec-vault-sdk';
|
|
440
|
+
|
|
441
|
+
const readonlyProvider = createReadonlyProvider(
|
|
442
|
+
connection,
|
|
443
|
+
optionalWalletAddress
|
|
444
|
+
);
|
|
445
|
+
|
|
446
|
+
const service = ZebecVaultService.create(readonlyProvider, 'mainnet-beta');
|
|
447
|
+
|
|
448
|
+
// Can only call query methods
|
|
449
|
+
const vaultInfo = await service.getVaultInfoOfUser(someAddress);
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
## Error Handling
|
|
453
|
+
|
|
454
|
+
The SDK provides custom error types:
|
|
455
|
+
|
|
456
|
+
```typescript
|
|
457
|
+
import {
|
|
458
|
+
AmountOutOfRangeError,
|
|
459
|
+
DailyCardLimitReachedError,
|
|
460
|
+
NotEnoughBalanceError,
|
|
461
|
+
AssociatedTokenAccountDoesNotExistsError
|
|
462
|
+
} from '@zebec-network/zebec-vault-sdk';
|
|
463
|
+
|
|
464
|
+
try {
|
|
465
|
+
await payload.execute();
|
|
466
|
+
} catch (error) {
|
|
467
|
+
if (error instanceof AmountOutOfRangeError) {
|
|
468
|
+
console.error('Amount must be between', error.minRange, 'and', error.maxRange);
|
|
469
|
+
} else if (error instanceof DailyCardLimitReachedError) {
|
|
470
|
+
console.error('Daily limit:', error.dailyCardLimit);
|
|
471
|
+
} else if (error instanceof NotEnoughBalanceError) {
|
|
472
|
+
console.error('Insufficient balance');
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
## Advanced Features
|
|
478
|
+
|
|
479
|
+
### Program Derived Addresses (PDAs)
|
|
480
|
+
|
|
481
|
+
```typescript
|
|
482
|
+
import {
|
|
483
|
+
deriveUserVault,
|
|
484
|
+
deriveVaultSigner,
|
|
485
|
+
deriveStreamConfigPda,
|
|
486
|
+
deriveCardConfigPda,
|
|
487
|
+
deriveLockupAddress
|
|
488
|
+
} from '@zebec-network/zebec-vault-sdk';
|
|
489
|
+
|
|
490
|
+
const [vaultAddress, vaultBump] = deriveUserVault(
|
|
491
|
+
userAddress,
|
|
492
|
+
vaultProgramId
|
|
493
|
+
);
|
|
494
|
+
|
|
495
|
+
const [signerAddress, signerBump] = deriveVaultSigner(
|
|
496
|
+
vaultAddress,
|
|
497
|
+
vaultProgramId
|
|
498
|
+
);
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
### Transaction Utilities
|
|
502
|
+
|
|
503
|
+
```typescript
|
|
504
|
+
import {
|
|
505
|
+
calculateProposalSize,
|
|
506
|
+
transactionInstructionToProposalAction
|
|
507
|
+
} from '@zebec-network/zebec-vault-sdk';
|
|
508
|
+
|
|
509
|
+
// Calculate proposal size
|
|
510
|
+
const size = calculateProposalSize('proposal-name', actions);
|
|
511
|
+
|
|
512
|
+
// Convert instruction to proposal action
|
|
513
|
+
const action = transactionInstructionToProposalAction(instruction);
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
## Network Configuration
|
|
208
517
|
|
|
209
|
-
```
|
|
210
|
-
|
|
518
|
+
```typescript
|
|
519
|
+
// Mainnet
|
|
520
|
+
const mainnetService = ZebecVaultService.create(provider, 'mainnet-beta');
|
|
211
521
|
|
|
212
|
-
|
|
522
|
+
// Devnet
|
|
523
|
+
const devnetService = ZebecVaultService.create(provider, 'devnet');
|
|
213
524
|
```
|
|
214
525
|
|
|
215
|
-
|
|
526
|
+
## Constants
|
|
527
|
+
|
|
528
|
+
```typescript
|
|
529
|
+
import {
|
|
530
|
+
ZEBEC_VAULT_PROGRAM_ID,
|
|
531
|
+
JUPITER_AGGREGATOR_PROGRAM_ID,
|
|
532
|
+
CARD_LOOKUP_TABLE_ADDRESS,
|
|
533
|
+
STAKE_LOOKUP_TABLE_ADDRESS
|
|
534
|
+
} from '@zebec-network/zebec-vault-sdk';
|
|
216
535
|
|
|
217
|
-
|
|
218
|
-
const vaultsInfo = await service.getAllVaultsInfo();
|
|
536
|
+
console.log('Vault Program:', ZEBEC_VAULT_PROGRAM_ID['mainnet-beta']);
|
|
219
537
|
```
|
|
538
|
+
|
|
539
|
+
## Types
|
|
540
|
+
|
|
541
|
+
The SDK exports comprehensive TypeScript types:
|
|
542
|
+
|
|
543
|
+
```typescript
|
|
544
|
+
import type {
|
|
545
|
+
VaultInfo,
|
|
546
|
+
ProposalInfo,
|
|
547
|
+
ProposalAction,
|
|
548
|
+
CreateStreamFromVaultParams,
|
|
549
|
+
StreamMetadataInfo,
|
|
550
|
+
TokenFeeRecord,
|
|
551
|
+
QuoteInfo,
|
|
552
|
+
StakeUserNonceInfo
|
|
553
|
+
} from '@zebec-network/zebec-vault-sdk';
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
## Best Practices
|
|
557
|
+
|
|
558
|
+
1. **Always check balances** before operations
|
|
559
|
+
2. **Use proposals** for critical operations requiring multiple approvals
|
|
560
|
+
3. **Handle errors** appropriately with the provided error types
|
|
561
|
+
4. **Verify stream parameters** before creation (duration, amounts, permissions)
|
|
562
|
+
5. **Test on devnet** before deploying to mainnet
|
|
563
|
+
6. **Use address lookup tables** for complex transactions to reduce size
|
|
564
|
+
|
|
565
|
+
## Support
|
|
566
|
+
|
|
567
|
+
- **Documentation**: [Zebec Network Docs](https://docs.zebec.io)
|
|
568
|
+
- **GitHub**: [zebec-network](https://github.com/zebec-network)
|
|
569
|
+
- **Discord**: [Join our community](https://discord.gg/zebec)
|
|
570
|
+
|
|
571
|
+
## License
|
|
572
|
+
|
|
573
|
+
MIT
|
|
574
|
+
|
|
575
|
+
## Contributing
|
|
576
|
+
|
|
577
|
+
Contributions are welcome! Please read our contributing guidelines before submitting pull requests.
|
package/dist/constants.js
CHANGED
|
@@ -9,11 +9,11 @@ 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";
|
|
16
16
|
exports.STAKE_LOOKUP_TABLE_ADDRESS = {
|
|
17
|
-
"mainnet-beta": "
|
|
17
|
+
"mainnet-beta": "EoKjJejKr4XsBdtUuYwzZcYd6tpGNijxCGgQocxtxQ8t",
|
|
18
18
|
devnet: "C4R2sL6yj7bzKfbdfwCfH68DZZ3QnzdmedE9wQqTfAAA",
|
|
19
19
|
};
|