@voltr/vault-sdk 0.1.2 → 0.1.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 +85 -65
- package/dist/client.d.ts +40 -7
- package/dist/client.js +47 -9
- package/dist/idl/voltr_vault.json +1071 -1011
- package/dist/types/voltr_vault.d.ts +1147 -1087
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,10 +6,10 @@ A TypeScript SDK for interacting with the Voltr protocol on Solana.
|
|
|
6
6
|
|
|
7
7
|
- Complete TypeScript support with type definitions
|
|
8
8
|
- Comprehensive vault management functionality
|
|
9
|
-
- Strategy handling and execution
|
|
10
|
-
- Asset deposit and withdrawal operations
|
|
11
|
-
- PDA (Program Derived Address) utilities
|
|
12
|
-
-
|
|
9
|
+
- Strategy handling and execution with adaptor support
|
|
10
|
+
- Asset deposit and withdrawal operations with direct withdraw capability
|
|
11
|
+
- Account data fetching and PDA (Program Derived Address) utilities
|
|
12
|
+
- Position and total value tracking
|
|
13
13
|
|
|
14
14
|
## Installation
|
|
15
15
|
|
|
@@ -60,28 +60,6 @@ const ix = await client.createInitializeVaultIx(vaultParams, {
|
|
|
60
60
|
});
|
|
61
61
|
```
|
|
62
62
|
|
|
63
|
-
### Deposit Assets
|
|
64
|
-
|
|
65
|
-
```typescript
|
|
66
|
-
const depositIx = await client.createDepositIx(new BN("1000000000"), {
|
|
67
|
-
userAuthority: userPubkey,
|
|
68
|
-
vault: vaultPubkey,
|
|
69
|
-
vaultAssetMint: mintPubkey,
|
|
70
|
-
assetTokenProgram: tokenProgramPubkey,
|
|
71
|
-
});
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
### Withdraw Assets
|
|
75
|
-
|
|
76
|
-
```typescript
|
|
77
|
-
const withdrawIx = await client.createWithdrawIx(new BN("1000000000"), {
|
|
78
|
-
userAuthority: userPubkey,
|
|
79
|
-
vault: vaultPubkey,
|
|
80
|
-
vaultAssetMint: mintPubkey,
|
|
81
|
-
assetTokenProgram: tokenProgramPubkey,
|
|
82
|
-
});
|
|
83
|
-
```
|
|
84
|
-
|
|
85
63
|
### Strategy Management
|
|
86
64
|
|
|
87
65
|
```typescript
|
|
@@ -89,6 +67,7 @@ const withdrawIx = await client.createWithdrawIx(new BN("1000000000"), {
|
|
|
89
67
|
const addAdaptorIx = await client.createAddAdaptorIx({
|
|
90
68
|
vault: vaultPubkey,
|
|
91
69
|
payer: payerPubkey,
|
|
70
|
+
admin: adminPubkey,
|
|
92
71
|
adaptorProgram: adaptorProgramPubkey,
|
|
93
72
|
});
|
|
94
73
|
|
|
@@ -104,20 +83,58 @@ const initStrategyIx = await client.createInitializeStrategyIx(
|
|
|
104
83
|
manager: managerPubkey,
|
|
105
84
|
strategy: strategyPubkey,
|
|
106
85
|
adaptorProgram: adaptorProgramPubkey,
|
|
86
|
+
remainingAccounts: [],
|
|
107
87
|
}
|
|
108
88
|
);
|
|
109
89
|
|
|
110
|
-
//
|
|
111
|
-
const
|
|
90
|
+
// Initialize direct withdraw strategy
|
|
91
|
+
const initDirectWithdrawIx =
|
|
92
|
+
await client.createInitializeDirectWithdrawStrategyIx(
|
|
93
|
+
{
|
|
94
|
+
instructionDiscriminator: null,
|
|
95
|
+
additionalArgs: null,
|
|
96
|
+
allowUserArgs: true,
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
payer: payerPubkey,
|
|
100
|
+
admin: adminPubkey,
|
|
101
|
+
vault: vaultPubkey,
|
|
102
|
+
strategy: strategyPubkey,
|
|
103
|
+
adaptorProgram: adaptorProgramPubkey,
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Asset Operations
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
// Deposit assets
|
|
112
|
+
const depositIx = await client.createDepositIx(new BN("1000000000"), {
|
|
113
|
+
userAuthority: userPubkey,
|
|
114
|
+
vault: vaultPubkey,
|
|
115
|
+
vaultAssetMint: mintPubkey,
|
|
116
|
+
assetTokenProgram: tokenProgramPubkey,
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
// Withdraw assets
|
|
120
|
+
const withdrawIx = await client.createWithdrawIx(new BN("1000000000"), {
|
|
121
|
+
userAuthority: userPubkey,
|
|
122
|
+
vault: vaultPubkey,
|
|
123
|
+
vaultAssetMint: mintPubkey,
|
|
124
|
+
assetTokenProgram: tokenProgramPubkey,
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// Direct withdraw from strategy
|
|
128
|
+
const directWithdrawIx = await client.createDirectWithdrawStrategyIx(
|
|
112
129
|
{
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
additionalArgs: null,
|
|
130
|
+
withdrawAmount: new BN("1000000000"),
|
|
131
|
+
userArgs: null,
|
|
116
132
|
},
|
|
117
133
|
{
|
|
134
|
+
user: userPubkey,
|
|
118
135
|
vault: vaultPubkey,
|
|
119
|
-
vaultAssetMint: mintPubkey,
|
|
120
136
|
strategy: strategyPubkey,
|
|
137
|
+
vaultAssetMint: mintPubkey,
|
|
121
138
|
assetTokenProgram: tokenProgramPubkey,
|
|
122
139
|
adaptorProgram: adaptorProgramPubkey,
|
|
123
140
|
remainingAccounts: [],
|
|
@@ -125,53 +142,56 @@ const depositStrategyIx = await client.createDepositStrategyIx(
|
|
|
125
142
|
);
|
|
126
143
|
```
|
|
127
144
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
### VoltrClient
|
|
131
|
-
|
|
132
|
-
The main client class for interacting with the Voltr protocol.
|
|
133
|
-
|
|
134
|
-
#### Constructor
|
|
145
|
+
### Position and Value Tracking
|
|
135
146
|
|
|
136
147
|
```typescript
|
|
137
|
-
|
|
148
|
+
// Get position and total values for a vault
|
|
149
|
+
const values = await client.getPositionAndTotalValuesForVault(vaultPubkey);
|
|
150
|
+
console.log(`Total Value: ${values.totalValue}`);
|
|
151
|
+
console.log("Strategy Positions:", values.strategies);
|
|
138
152
|
```
|
|
139
153
|
|
|
140
|
-
|
|
154
|
+
## API Reference
|
|
155
|
+
|
|
156
|
+
### VoltrClient Methods
|
|
157
|
+
|
|
158
|
+
#### Vault Management
|
|
141
159
|
|
|
142
|
-
- `createInitializeVaultIx(vaultParams
|
|
143
|
-
- `createDepositIx(amount
|
|
144
|
-
- `createWithdrawIx(amount
|
|
160
|
+
- `createInitializeVaultIx(vaultParams, params)`
|
|
161
|
+
- `createDepositIx(amount, params)`
|
|
162
|
+
- `createWithdrawIx(amount, params)`
|
|
145
163
|
|
|
146
|
-
#### Strategy Management
|
|
164
|
+
#### Strategy Management
|
|
147
165
|
|
|
148
|
-
- `createAddAdaptorIx(params
|
|
149
|
-
- `createInitializeStrategyIx(initArgs
|
|
150
|
-
- `createDepositStrategyIx(depositArgs
|
|
151
|
-
- `createWithdrawStrategyIx(withdrawArgs
|
|
152
|
-
- `
|
|
166
|
+
- `createAddAdaptorIx(params)`
|
|
167
|
+
- `createInitializeStrategyIx(initArgs, params)`
|
|
168
|
+
- `createDepositStrategyIx(depositArgs, params)`
|
|
169
|
+
- `createWithdrawStrategyIx(withdrawArgs, params)`
|
|
170
|
+
- `createInitializeDirectWithdrawStrategyIx(initArgs, params)`
|
|
171
|
+
- `createDirectWithdrawStrategyIx(withdrawArgs, params)`
|
|
172
|
+
- `createRemoveAdaptorIx(params)`
|
|
153
173
|
|
|
154
|
-
#### Account
|
|
174
|
+
#### Account Data
|
|
155
175
|
|
|
156
|
-
- `fetchVaultAccount(vault
|
|
176
|
+
- `fetchVaultAccount(vault)`
|
|
157
177
|
- `fetchAllStrategyInitReceiptAccounts()`
|
|
158
|
-
- `fetchAllStrategyInitReceiptAccountsOfVault(vault
|
|
159
|
-
- `fetchAllAdaptorAddReceiptAccountsOfVault(vault
|
|
160
|
-
- `getPositionAndTotalValuesForVault(vault
|
|
178
|
+
- `fetchAllStrategyInitReceiptAccountsOfVault(vault)`
|
|
179
|
+
- `fetchAllAdaptorAddReceiptAccountsOfVault(vault)`
|
|
180
|
+
- `getPositionAndTotalValuesForVault(vault)`
|
|
161
181
|
|
|
162
|
-
#### PDA Finding
|
|
182
|
+
#### PDA Finding
|
|
163
183
|
|
|
164
|
-
- `findVaultLpMint(vault
|
|
165
|
-
- `findVaultAssetIdleAuth(vault
|
|
166
|
-
- `
|
|
167
|
-
- `
|
|
168
|
-
- `
|
|
169
|
-
- `
|
|
184
|
+
- `findVaultLpMint(vault)`
|
|
185
|
+
- `findVaultAssetIdleAuth(vault)`
|
|
186
|
+
- `findVaultAddresses(vault)`
|
|
187
|
+
- `findVaultStrategyAuth(vault, strategy)`
|
|
188
|
+
- `findStrategyInitReceipt(vault, strategy)`
|
|
189
|
+
- `findDirectWithdrawInitReceipt(vault, strategy)`
|
|
170
190
|
|
|
171
|
-
####
|
|
191
|
+
#### Calculations
|
|
172
192
|
|
|
173
|
-
- `calculateAssetsForWithdraw(vaultPk
|
|
174
|
-
- `calculateLpTokensForDeposit(depositAmount
|
|
193
|
+
- `calculateAssetsForWithdraw(vaultPk, lpAmount)`
|
|
194
|
+
- `calculateLpTokensForDeposit(depositAmount, vaultPk)`
|
|
175
195
|
|
|
176
196
|
## License
|
|
177
197
|
|
package/dist/client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Program, AnchorProvider, Idl, BN } from "@coral-xyz/anchor";
|
|
2
2
|
import { Connection, Keypair, PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
3
|
-
import { VaultParams, VoltrVault, InitializeStrategyArgs, DepositStrategyArgs, WithdrawStrategyArgs, InitializeDirectWithdrawStrategyArgs, DirectWithdrawStrategyArgs } from "./types";
|
|
3
|
+
import { VaultParams, VaultConfig, VoltrVault, InitializeStrategyArgs, DepositStrategyArgs, WithdrawStrategyArgs, InitializeDirectWithdrawStrategyArgs, DirectWithdrawStrategyArgs } from "./types";
|
|
4
4
|
declare class AccountUtils {
|
|
5
5
|
conn: Connection;
|
|
6
6
|
constructor(conn: Connection);
|
|
@@ -165,7 +165,40 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
165
165
|
payer: PublicKey;
|
|
166
166
|
}): Promise<TransactionInstruction>;
|
|
167
167
|
/**
|
|
168
|
-
* Creates a
|
|
168
|
+
* Creates an instruction to update a vault
|
|
169
|
+
* @param {VaultConfig} vaultConfig - Configuration parameters for the vault
|
|
170
|
+
* @param {BN} vaultConfig.maxCap - Maximum capacity of the vault
|
|
171
|
+
* @param {BN} vaultConfig.startAtTs - Vault start timestamp in seconds
|
|
172
|
+
* @param {number} vaultConfig.managerManagementFee - Manager's management fee in basis points (e.g., 50 = 0.5%)
|
|
173
|
+
* @param {number} vaultConfig.managerPerformanceFee - Manager's performance fee in basis points (e.g., 1000 = 10%)
|
|
174
|
+
* @param {number} vaultConfig.adminManagementFee - Admin's management fee in basis points (e.g., 50 = 0.5%)
|
|
175
|
+
* @param {number} vaultConfig.adminPerformanceFee - Admin's performance fee in basis points (e.g., 1000 = 10%)
|
|
176
|
+
* @param {Object} params - Parameters for updating the vault
|
|
177
|
+
* @param {PublicKey} params.vault - Public key of the vault
|
|
178
|
+
* @param {PublicKey} params.admin - Public key of the vault admin
|
|
179
|
+
* @returns Transaction instruction for updating the vault
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* const ix = await client.createUpdateVaultIx(
|
|
184
|
+
* {
|
|
185
|
+
* maxCap: new BN('1000000000'),
|
|
186
|
+
* startAtTs: new BN(Math.floor(Date.now() / 1000)),
|
|
187
|
+
* managerManagementFee: 50,
|
|
188
|
+
* managerPerformanceFee: 1000,
|
|
189
|
+
* adminManagementFee: 50,
|
|
190
|
+
* adminPerformanceFee: 1000,
|
|
191
|
+
* },
|
|
192
|
+
* { vault: vaultPubkey, admin: adminPubkey }
|
|
193
|
+
* );
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
createUpdateVaultIx(vaultConfig: VaultConfig, { vault, admin, }: {
|
|
197
|
+
vault: PublicKey;
|
|
198
|
+
admin: PublicKey;
|
|
199
|
+
}): Promise<TransactionInstruction>;
|
|
200
|
+
/**
|
|
201
|
+
* Creates a deposit instruction for a vault
|
|
169
202
|
*
|
|
170
203
|
* @param {BN} amount - Amount of tokens to deposit
|
|
171
204
|
* @param {Object} params - Deposit parameters
|
|
@@ -178,7 +211,7 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
178
211
|
*
|
|
179
212
|
* @example
|
|
180
213
|
* ```typescript
|
|
181
|
-
* const ix = await client.
|
|
214
|
+
* const ix = await client.createDepositVaultIx(
|
|
182
215
|
* new BN('1000000000'),
|
|
183
216
|
* {
|
|
184
217
|
* userAuthority: userPubkey,
|
|
@@ -189,14 +222,14 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
189
222
|
* );
|
|
190
223
|
* ```
|
|
191
224
|
*/
|
|
192
|
-
|
|
225
|
+
createDepositVaultIx(amount: BN, { userAuthority, vault, vaultAssetMint, assetTokenProgram, }: {
|
|
193
226
|
userAuthority: PublicKey;
|
|
194
227
|
vault: PublicKey;
|
|
195
228
|
vaultAssetMint: PublicKey;
|
|
196
229
|
assetTokenProgram: PublicKey;
|
|
197
230
|
}): Promise<TransactionInstruction>;
|
|
198
231
|
/**
|
|
199
|
-
* Creates a withdraw instruction
|
|
232
|
+
* Creates a withdraw instruction for a vault
|
|
200
233
|
*
|
|
201
234
|
* @param amount - Amount of LP tokens to withdraw
|
|
202
235
|
* @param {Object} params - Withdraw parameters
|
|
@@ -209,7 +242,7 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
209
242
|
* @throws {Error} If the instruction creation fails
|
|
210
243
|
*
|
|
211
244
|
* @example
|
|
212
|
-
* const ix = await client.
|
|
245
|
+
* const ix = await client.createWithdrawVaultIx(
|
|
213
246
|
* new BN('1000000000'),
|
|
214
247
|
* {
|
|
215
248
|
* userAuthority: userPubkey,
|
|
@@ -219,7 +252,7 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
219
252
|
* }
|
|
220
253
|
* );
|
|
221
254
|
*/
|
|
222
|
-
|
|
255
|
+
createWithdrawVaultIx(amount: BN, { userAuthority, vault, vaultAssetMint, assetTokenProgram, }: {
|
|
223
256
|
userAuthority: PublicKey;
|
|
224
257
|
vault: PublicKey;
|
|
225
258
|
vaultAssetMint: PublicKey;
|
package/dist/client.js
CHANGED
|
@@ -278,7 +278,7 @@ class VoltrClient extends AccountUtils {
|
|
|
278
278
|
const addresses = this.findVaultAddresses(vault.publicKey);
|
|
279
279
|
const vaultAssetIdleAta = (0, spl_token_1.getAssociatedTokenAddressSync)(vaultAssetMint, addresses.vaultAssetIdleAuth, true);
|
|
280
280
|
return await this.vaultProgram.methods
|
|
281
|
-
.
|
|
281
|
+
.initializeVault(vaultParams.config, vaultParams.name, vaultParams.description)
|
|
282
282
|
.accounts({
|
|
283
283
|
payer,
|
|
284
284
|
admin,
|
|
@@ -291,7 +291,45 @@ class VoltrClient extends AccountUtils {
|
|
|
291
291
|
.instruction();
|
|
292
292
|
}
|
|
293
293
|
/**
|
|
294
|
-
* Creates a
|
|
294
|
+
* Creates an instruction to update a vault
|
|
295
|
+
* @param {VaultConfig} vaultConfig - Configuration parameters for the vault
|
|
296
|
+
* @param {BN} vaultConfig.maxCap - Maximum capacity of the vault
|
|
297
|
+
* @param {BN} vaultConfig.startAtTs - Vault start timestamp in seconds
|
|
298
|
+
* @param {number} vaultConfig.managerManagementFee - Manager's management fee in basis points (e.g., 50 = 0.5%)
|
|
299
|
+
* @param {number} vaultConfig.managerPerformanceFee - Manager's performance fee in basis points (e.g., 1000 = 10%)
|
|
300
|
+
* @param {number} vaultConfig.adminManagementFee - Admin's management fee in basis points (e.g., 50 = 0.5%)
|
|
301
|
+
* @param {number} vaultConfig.adminPerformanceFee - Admin's performance fee in basis points (e.g., 1000 = 10%)
|
|
302
|
+
* @param {Object} params - Parameters for updating the vault
|
|
303
|
+
* @param {PublicKey} params.vault - Public key of the vault
|
|
304
|
+
* @param {PublicKey} params.admin - Public key of the vault admin
|
|
305
|
+
* @returns Transaction instruction for updating the vault
|
|
306
|
+
*
|
|
307
|
+
* @example
|
|
308
|
+
* ```typescript
|
|
309
|
+
* const ix = await client.createUpdateVaultIx(
|
|
310
|
+
* {
|
|
311
|
+
* maxCap: new BN('1000000000'),
|
|
312
|
+
* startAtTs: new BN(Math.floor(Date.now() / 1000)),
|
|
313
|
+
* managerManagementFee: 50,
|
|
314
|
+
* managerPerformanceFee: 1000,
|
|
315
|
+
* adminManagementFee: 50,
|
|
316
|
+
* adminPerformanceFee: 1000,
|
|
317
|
+
* },
|
|
318
|
+
* { vault: vaultPubkey, admin: adminPubkey }
|
|
319
|
+
* );
|
|
320
|
+
* ```
|
|
321
|
+
*/
|
|
322
|
+
async createUpdateVaultIx(vaultConfig, { vault, admin, }) {
|
|
323
|
+
return await this.vaultProgram.methods
|
|
324
|
+
.updateVault(vaultConfig)
|
|
325
|
+
.accountsPartial({
|
|
326
|
+
admin,
|
|
327
|
+
vault,
|
|
328
|
+
})
|
|
329
|
+
.instruction();
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Creates a deposit instruction for a vault
|
|
295
333
|
*
|
|
296
334
|
* @param {BN} amount - Amount of tokens to deposit
|
|
297
335
|
* @param {Object} params - Deposit parameters
|
|
@@ -304,7 +342,7 @@ class VoltrClient extends AccountUtils {
|
|
|
304
342
|
*
|
|
305
343
|
* @example
|
|
306
344
|
* ```typescript
|
|
307
|
-
* const ix = await client.
|
|
345
|
+
* const ix = await client.createDepositVaultIx(
|
|
308
346
|
* new BN('1000000000'),
|
|
309
347
|
* {
|
|
310
348
|
* userAuthority: userPubkey,
|
|
@@ -315,9 +353,9 @@ class VoltrClient extends AccountUtils {
|
|
|
315
353
|
* );
|
|
316
354
|
* ```
|
|
317
355
|
*/
|
|
318
|
-
async
|
|
356
|
+
async createDepositVaultIx(amount, { userAuthority, vault, vaultAssetMint, assetTokenProgram, }) {
|
|
319
357
|
return await this.vaultProgram.methods
|
|
320
|
-
.
|
|
358
|
+
.depositVault(amount)
|
|
321
359
|
.accounts({
|
|
322
360
|
userTransferAuthority: userAuthority,
|
|
323
361
|
vault,
|
|
@@ -327,7 +365,7 @@ class VoltrClient extends AccountUtils {
|
|
|
327
365
|
.instruction();
|
|
328
366
|
}
|
|
329
367
|
/**
|
|
330
|
-
* Creates a withdraw instruction
|
|
368
|
+
* Creates a withdraw instruction for a vault
|
|
331
369
|
*
|
|
332
370
|
* @param amount - Amount of LP tokens to withdraw
|
|
333
371
|
* @param {Object} params - Withdraw parameters
|
|
@@ -340,7 +378,7 @@ class VoltrClient extends AccountUtils {
|
|
|
340
378
|
* @throws {Error} If the instruction creation fails
|
|
341
379
|
*
|
|
342
380
|
* @example
|
|
343
|
-
* const ix = await client.
|
|
381
|
+
* const ix = await client.createWithdrawVaultIx(
|
|
344
382
|
* new BN('1000000000'),
|
|
345
383
|
* {
|
|
346
384
|
* userAuthority: userPubkey,
|
|
@@ -350,9 +388,9 @@ class VoltrClient extends AccountUtils {
|
|
|
350
388
|
* }
|
|
351
389
|
* );
|
|
352
390
|
*/
|
|
353
|
-
async
|
|
391
|
+
async createWithdrawVaultIx(amount, { userAuthority, vault, vaultAssetMint, assetTokenProgram, }) {
|
|
354
392
|
return await this.vaultProgram.methods
|
|
355
|
-
.
|
|
393
|
+
.withdrawVault(amount)
|
|
356
394
|
.accounts({
|
|
357
395
|
userTransferAuthority: userAuthority,
|
|
358
396
|
vault,
|