@voltr/vault-sdk 1.0.0 → 1.0.1
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 +69 -8
- package/dist/client.d.ts +49 -16
- package/dist/client.js +58 -16
- package/dist/decimals.d.ts +3 -0
- package/dist/decimals.js +10 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -46,8 +46,8 @@ const vaultParams = {
|
|
|
46
46
|
managerPerformanceFee: 1000, // 10%
|
|
47
47
|
adminManagementFee: 50, // 0.5%
|
|
48
48
|
adminPerformanceFee: 1000, // 10%
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
redemptionFee: 10, // 0.1%
|
|
50
|
+
issuanceFee: 10, // 0.1%
|
|
51
51
|
withdrawalWaitingPeriod: new BN(3600), // 1 hour
|
|
52
52
|
},
|
|
53
53
|
name: "My Vault",
|
|
@@ -113,8 +113,8 @@ const initDirectWithdrawIx =
|
|
|
113
113
|
|
|
114
114
|
```typescript
|
|
115
115
|
// Deposit assets
|
|
116
|
-
const depositIx = await client.
|
|
117
|
-
|
|
116
|
+
const depositIx = await client.createDepositVaultIx(new BN("1000000000"), {
|
|
117
|
+
userTransferAuthority: userPubkey,
|
|
118
118
|
vault: vaultPubkey,
|
|
119
119
|
vaultAssetMint: mintPubkey,
|
|
120
120
|
assetTokenProgram: tokenProgramPubkey,
|
|
@@ -129,7 +129,7 @@ const requestWithdrawIx = await client.createRequestWithdrawVaultIx(
|
|
|
129
129
|
},
|
|
130
130
|
{
|
|
131
131
|
payer: payerPubkey,
|
|
132
|
-
|
|
132
|
+
userTransferAuthority: userPubkey,
|
|
133
133
|
vault: vaultPubkey,
|
|
134
134
|
}
|
|
135
135
|
);
|
|
@@ -137,14 +137,14 @@ const requestWithdrawIx = await client.createRequestWithdrawVaultIx(
|
|
|
137
137
|
// Cancel withdraw request
|
|
138
138
|
const cancelRequestWithdrawIx = await client.createCancelRequestWithdrawVaultIx(
|
|
139
139
|
{
|
|
140
|
-
|
|
140
|
+
userTransferAuthority: userPubkey,
|
|
141
141
|
vault: vaultPubkey,
|
|
142
142
|
}
|
|
143
143
|
);
|
|
144
144
|
|
|
145
145
|
// Withdraw from vault
|
|
146
|
-
const withdrawIx = await client.
|
|
147
|
-
|
|
146
|
+
const withdrawIx = await client.createWithdrawVaultIx({
|
|
147
|
+
userTransferAuthority: userPubkey,
|
|
148
148
|
vault: vaultPubkey,
|
|
149
149
|
vaultAssetMint: mintPubkey,
|
|
150
150
|
assetTokenProgram: tokenProgramPubkey,
|
|
@@ -176,6 +176,66 @@ console.log(`Total Value: ${values.totalValue}`);
|
|
|
176
176
|
console.log("Strategy Positions:", values.strategies);
|
|
177
177
|
```
|
|
178
178
|
|
|
179
|
+
### Asset Calculation Utilities
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
// Calculate the amount of assets that would be received for a given LP token amount
|
|
183
|
+
const assetsToReceive = await client.calculateAssetsForWithdraw(
|
|
184
|
+
vaultPubkey,
|
|
185
|
+
new BN("1000000000")
|
|
186
|
+
);
|
|
187
|
+
console.log(`Assets to receive: ${assetsToReceive.toString()}`);
|
|
188
|
+
|
|
189
|
+
// Calculate the amount of LP tokens needed to withdraw a specific asset amount
|
|
190
|
+
const lpTokensRequired = await client.calculateLpForWithdraw(
|
|
191
|
+
vaultPubkey,
|
|
192
|
+
new BN("1000000000")
|
|
193
|
+
);
|
|
194
|
+
console.log(`LP tokens required: ${lpTokensRequired.toString()}`);
|
|
195
|
+
|
|
196
|
+
// Calculate the amount of LP tokens that would be received for a deposit
|
|
197
|
+
const lpTokensToReceive = await client.calculateLpForDeposit(
|
|
198
|
+
vaultPubkey,
|
|
199
|
+
new BN("1000000000")
|
|
200
|
+
);
|
|
201
|
+
console.log(`LP tokens to receive: ${lpTokensToReceive.toString()}`);
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Querying Pending Withdrawals
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
// Get all pending withdrawals for a vault
|
|
208
|
+
const pendingWithdrawals = await client.getAllPendingWithdrawalsForVault(
|
|
209
|
+
vaultPubkey
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
// Process the pending withdrawals
|
|
213
|
+
pendingWithdrawals.forEach((withdrawal, index) => {
|
|
214
|
+
console.log(`Withdrawal ${index + 1}:`);
|
|
215
|
+
console.log(` Asset amount: ${withdrawal.amountAssetToWithdraw}`);
|
|
216
|
+
|
|
217
|
+
// Check if withdrawal is available yet
|
|
218
|
+
const withdrawableTimestamp = withdrawal.withdrawableFromTs.toNumber();
|
|
219
|
+
const currentTime = Math.floor(Date.now() / 1000);
|
|
220
|
+
const isWithdrawable = currentTime >= withdrawableTimestamp;
|
|
221
|
+
|
|
222
|
+
console.log(
|
|
223
|
+
` Withdrawable from: ${new Date(
|
|
224
|
+
withdrawableTimestamp * 1000
|
|
225
|
+
).toLocaleString()}`
|
|
226
|
+
);
|
|
227
|
+
console.log(` Status: ${isWithdrawable ? "Available now" : "Pending"}`);
|
|
228
|
+
if (!isWithdrawable) {
|
|
229
|
+
const timeRemaining = Math.max(0, withdrawableTimestamp - currentTime);
|
|
230
|
+
console.log(
|
|
231
|
+
` Time remaining: ${Math.floor(timeRemaining / 3600)}h ${Math.floor(
|
|
232
|
+
(timeRemaining % 3600) / 60
|
|
233
|
+
)}m`
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
```
|
|
238
|
+
|
|
179
239
|
## API Reference
|
|
180
240
|
|
|
181
241
|
### VoltrClient Methods
|
|
@@ -183,6 +243,7 @@ console.log("Strategy Positions:", values.strategies);
|
|
|
183
243
|
#### Vault Management
|
|
184
244
|
|
|
185
245
|
- `createInitializeVaultIx(vaultParams, params)`
|
|
246
|
+
- `createUpdateVaultIx(vaultConfig, params)`
|
|
186
247
|
- `createRequestWithdrawVaultIx(requestWithdrawArgs, params)`
|
|
187
248
|
- `createCancelRequestWithdrawVaultIx(params)`
|
|
188
249
|
- `createWithdrawVaultIx(params)`
|
package/dist/client.d.ts
CHANGED
|
@@ -223,7 +223,7 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
223
223
|
*
|
|
224
224
|
* @param {BN} amount - Amount of tokens to deposit
|
|
225
225
|
* @param {Object} params - Deposit parameters
|
|
226
|
-
* @param {PublicKey} params.
|
|
226
|
+
* @param {PublicKey} params.userTransferAuthority - Public key of the user's transfer authority
|
|
227
227
|
* @param {PublicKey} params.vault - Public key of the vault
|
|
228
228
|
* @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
|
|
229
229
|
* @param {PublicKey} params.assetTokenProgram - Public key of the asset token program
|
|
@@ -235,7 +235,7 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
235
235
|
* const ix = await client.createDepositVaultIx(
|
|
236
236
|
* new BN('1000000000'),
|
|
237
237
|
* {
|
|
238
|
-
*
|
|
238
|
+
* userTransferAuthority: userPubkey,
|
|
239
239
|
* vault: vaultPubkey,
|
|
240
240
|
* vaultAssetMint: mintPubkey,
|
|
241
241
|
* assetTokenProgram: tokenProgramPubkey
|
|
@@ -243,8 +243,8 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
243
243
|
* );
|
|
244
244
|
* ```
|
|
245
245
|
*/
|
|
246
|
-
createDepositVaultIx(amount: BN, {
|
|
247
|
-
|
|
246
|
+
createDepositVaultIx(amount: BN, { userTransferAuthority, vault, vaultAssetMint, assetTokenProgram, }: {
|
|
247
|
+
userTransferAuthority: PublicKey;
|
|
248
248
|
vault: PublicKey;
|
|
249
249
|
vaultAssetMint: PublicKey;
|
|
250
250
|
assetTokenProgram: PublicKey;
|
|
@@ -258,7 +258,7 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
258
258
|
* @param {boolean} requestWithdrawArgs.isWithdrawAll - Whether to withdraw all assets
|
|
259
259
|
* @param {Object} params - Request withdraw parameters
|
|
260
260
|
* @param {PublicKey} params.payer - Public key of the payer
|
|
261
|
-
* @param {PublicKey} params.
|
|
261
|
+
* @param {PublicKey} params.userTransferAuthority - Public key of the user authority
|
|
262
262
|
* @param {PublicKey} params.vault - Public key of the vault
|
|
263
263
|
* @returns {Promise<TransactionInstruction>} Transaction instruction for withdrawal
|
|
264
264
|
*
|
|
@@ -273,21 +273,21 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
273
273
|
* },
|
|
274
274
|
* {
|
|
275
275
|
* payer: payerPubkey,
|
|
276
|
-
*
|
|
276
|
+
* userTransferAuthority: userPubkey,
|
|
277
277
|
* vault: vaultPubkey,
|
|
278
278
|
* }
|
|
279
279
|
* );
|
|
280
280
|
*/
|
|
281
|
-
createRequestWithdrawVaultIx({ amount, isAmountInLp, isWithdrawAll }: RequestWithdrawVaultArgs, { payer,
|
|
281
|
+
createRequestWithdrawVaultIx({ amount, isAmountInLp, isWithdrawAll }: RequestWithdrawVaultArgs, { payer, userTransferAuthority, vault, }: {
|
|
282
282
|
payer: PublicKey;
|
|
283
|
-
|
|
283
|
+
userTransferAuthority: PublicKey;
|
|
284
284
|
vault: PublicKey;
|
|
285
285
|
}): Promise<TransactionInstruction>;
|
|
286
286
|
/**
|
|
287
287
|
* Creates a cancel withdraw instruction for a vault
|
|
288
288
|
*
|
|
289
289
|
* @param {Object} params - Cancel withdraw request parameters
|
|
290
|
-
* @param {PublicKey} params.
|
|
290
|
+
* @param {PublicKey} params.userTransferAuthority - Public key of the user authority
|
|
291
291
|
* @param {PublicKey} params.vault - Public key of the vault
|
|
292
292
|
* @returns {Promise<TransactionInstruction>} Transaction instruction for withdrawal
|
|
293
293
|
*
|
|
@@ -296,20 +296,20 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
296
296
|
* @example
|
|
297
297
|
* const ix = await client.createCancelRequestWithdrawVaultIx(
|
|
298
298
|
* {
|
|
299
|
-
*
|
|
299
|
+
* userTransferAuthority: userPubkey,
|
|
300
300
|
* vault: vaultPubkey,
|
|
301
301
|
* }
|
|
302
302
|
* );
|
|
303
303
|
*/
|
|
304
|
-
createCancelRequestWithdrawVaultIx({
|
|
305
|
-
|
|
304
|
+
createCancelRequestWithdrawVaultIx({ userTransferAuthority, vault, }: {
|
|
305
|
+
userTransferAuthority: PublicKey;
|
|
306
306
|
vault: PublicKey;
|
|
307
307
|
}): Promise<TransactionInstruction>;
|
|
308
308
|
/**
|
|
309
309
|
* Creates a withdraw instruction for a vault
|
|
310
310
|
*
|
|
311
311
|
* @param {Object} params - Withdraw parameters
|
|
312
|
-
* @param {PublicKey} params.
|
|
312
|
+
* @param {PublicKey} params.userTransferAuthority - Public key of the user authority
|
|
313
313
|
* @param {PublicKey} params.vault - Public key of the vault
|
|
314
314
|
* @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
|
|
315
315
|
* @param {PublicKey} params.assetTokenProgram - Public key of the asset token program
|
|
@@ -320,15 +320,15 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
320
320
|
* @example
|
|
321
321
|
* const ix = await client.createWithdrawVaultIx(
|
|
322
322
|
* {
|
|
323
|
-
*
|
|
323
|
+
* userTransferAuthority: userPubkey,
|
|
324
324
|
* vault: vaultPubkey,
|
|
325
325
|
* vaultAssetMint: mintPubkey,
|
|
326
326
|
* assetTokenProgram: tokenProgramPubkey
|
|
327
327
|
* }
|
|
328
328
|
* );
|
|
329
329
|
*/
|
|
330
|
-
createWithdrawVaultIx({
|
|
331
|
-
|
|
330
|
+
createWithdrawVaultIx({ userTransferAuthority, vault, vaultAssetMint, assetTokenProgram, }: {
|
|
331
|
+
userTransferAuthority: PublicKey;
|
|
332
332
|
vault: PublicKey;
|
|
333
333
|
vaultAssetMint: PublicKey;
|
|
334
334
|
assetTokenProgram: PublicKey;
|
|
@@ -659,6 +659,25 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
659
659
|
padding0: number[];
|
|
660
660
|
reserved: number[];
|
|
661
661
|
}>[]>;
|
|
662
|
+
/**
|
|
663
|
+
* Fetches all request withdraw vault receipt accounts of a vault
|
|
664
|
+
* @param vault - Public key of the vault
|
|
665
|
+
* @returns Promise resolving to an array of request withdraw vault receipt accounts
|
|
666
|
+
*
|
|
667
|
+
* @example
|
|
668
|
+
* ```typescript
|
|
669
|
+
* const requestWithdrawVaultReceiptAccounts = await client.fetchAllRequestWithdrawVaultReceiptsOfVault(vaultPubkey);
|
|
670
|
+
* ```
|
|
671
|
+
*/
|
|
672
|
+
fetchAllRequestWithdrawVaultReceiptsOfVault(vault: PublicKey): Promise<import("@coral-xyz/anchor").ProgramAccount<{
|
|
673
|
+
vault: PublicKey;
|
|
674
|
+
user: PublicKey;
|
|
675
|
+
amountLpEscrowed: BN;
|
|
676
|
+
amountAssetToWithdrawDecimalBits: BN;
|
|
677
|
+
withdrawableFromTs: BN;
|
|
678
|
+
bump: number;
|
|
679
|
+
version: number;
|
|
680
|
+
}>[]>;
|
|
662
681
|
/**
|
|
663
682
|
* Fetches all adaptor add receipt accounts of a vault
|
|
664
683
|
* @param vault - Public key of the vault
|
|
@@ -787,6 +806,20 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
787
806
|
lastUpdatedEpoch: BN;
|
|
788
807
|
reserved: number[];
|
|
789
808
|
}>;
|
|
809
|
+
/**
|
|
810
|
+
* Fetches all pending withdrawals for a vault
|
|
811
|
+
* @param vault - Public key of the vault
|
|
812
|
+
* @returns Promise resolving to an array of pending withdrawals
|
|
813
|
+
*
|
|
814
|
+
* @example
|
|
815
|
+
* ```typescript
|
|
816
|
+
* const pendingWithdrawals = await client.getAllPendingWithdrawalsForVault(vaultPubkey);
|
|
817
|
+
* ```
|
|
818
|
+
*/
|
|
819
|
+
getAllPendingWithdrawalsForVault(vault: PublicKey): Promise<{
|
|
820
|
+
amountAssetToWithdraw: number;
|
|
821
|
+
withdrawableFromTs: BN;
|
|
822
|
+
}[]>;
|
|
790
823
|
calculateLockedProfit(lastUpdatedLockedProfit: BN, lockedProfitDegradationDuration: BN, currentTime: BN): BN;
|
|
791
824
|
/**
|
|
792
825
|
* Calculates the amount of assets that would be received for a given LP token amount
|
package/dist/client.js
CHANGED
|
@@ -44,6 +44,7 @@ const spl_token_1 = require("@solana/spl-token");
|
|
|
44
44
|
const constants_1 = require("./constants");
|
|
45
45
|
// Import IDL files
|
|
46
46
|
const vaultIdl = __importStar(require("./idl/voltr_vault.json"));
|
|
47
|
+
const decimals_1 = require("./decimals");
|
|
47
48
|
class CustomWallet {
|
|
48
49
|
constructor(payer) {
|
|
49
50
|
this.payer = payer;
|
|
@@ -360,7 +361,7 @@ class VoltrClient extends AccountUtils {
|
|
|
360
361
|
*
|
|
361
362
|
* @param {BN} amount - Amount of tokens to deposit
|
|
362
363
|
* @param {Object} params - Deposit parameters
|
|
363
|
-
* @param {PublicKey} params.
|
|
364
|
+
* @param {PublicKey} params.userTransferAuthority - Public key of the user's transfer authority
|
|
364
365
|
* @param {PublicKey} params.vault - Public key of the vault
|
|
365
366
|
* @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
|
|
366
367
|
* @param {PublicKey} params.assetTokenProgram - Public key of the asset token program
|
|
@@ -372,7 +373,7 @@ class VoltrClient extends AccountUtils {
|
|
|
372
373
|
* const ix = await client.createDepositVaultIx(
|
|
373
374
|
* new BN('1000000000'),
|
|
374
375
|
* {
|
|
375
|
-
*
|
|
376
|
+
* userTransferAuthority: userPubkey,
|
|
376
377
|
* vault: vaultPubkey,
|
|
377
378
|
* vaultAssetMint: mintPubkey,
|
|
378
379
|
* assetTokenProgram: tokenProgramPubkey
|
|
@@ -380,11 +381,11 @@ class VoltrClient extends AccountUtils {
|
|
|
380
381
|
* );
|
|
381
382
|
* ```
|
|
382
383
|
*/
|
|
383
|
-
async createDepositVaultIx(amount, {
|
|
384
|
+
async createDepositVaultIx(amount, { userTransferAuthority, vault, vaultAssetMint, assetTokenProgram, }) {
|
|
384
385
|
return await this.vaultProgram.methods
|
|
385
386
|
.depositVault(amount)
|
|
386
387
|
.accounts({
|
|
387
|
-
userTransferAuthority
|
|
388
|
+
userTransferAuthority,
|
|
388
389
|
vault,
|
|
389
390
|
vaultAssetMint,
|
|
390
391
|
assetTokenProgram,
|
|
@@ -400,7 +401,7 @@ class VoltrClient extends AccountUtils {
|
|
|
400
401
|
* @param {boolean} requestWithdrawArgs.isWithdrawAll - Whether to withdraw all assets
|
|
401
402
|
* @param {Object} params - Request withdraw parameters
|
|
402
403
|
* @param {PublicKey} params.payer - Public key of the payer
|
|
403
|
-
* @param {PublicKey} params.
|
|
404
|
+
* @param {PublicKey} params.userTransferAuthority - Public key of the user authority
|
|
404
405
|
* @param {PublicKey} params.vault - Public key of the vault
|
|
405
406
|
* @returns {Promise<TransactionInstruction>} Transaction instruction for withdrawal
|
|
406
407
|
*
|
|
@@ -415,17 +416,17 @@ class VoltrClient extends AccountUtils {
|
|
|
415
416
|
* },
|
|
416
417
|
* {
|
|
417
418
|
* payer: payerPubkey,
|
|
418
|
-
*
|
|
419
|
+
* userTransferAuthority: userPubkey,
|
|
419
420
|
* vault: vaultPubkey,
|
|
420
421
|
* }
|
|
421
422
|
* );
|
|
422
423
|
*/
|
|
423
|
-
async createRequestWithdrawVaultIx({ amount, isAmountInLp, isWithdrawAll }, { payer,
|
|
424
|
+
async createRequestWithdrawVaultIx({ amount, isAmountInLp, isWithdrawAll }, { payer, userTransferAuthority, vault, }) {
|
|
424
425
|
return await this.vaultProgram.methods
|
|
425
426
|
.requestWithdrawVault(amount, isAmountInLp, isWithdrawAll)
|
|
426
427
|
.accounts({
|
|
427
428
|
payer,
|
|
428
|
-
userTransferAuthority
|
|
429
|
+
userTransferAuthority,
|
|
429
430
|
vault,
|
|
430
431
|
})
|
|
431
432
|
.instruction();
|
|
@@ -434,7 +435,7 @@ class VoltrClient extends AccountUtils {
|
|
|
434
435
|
* Creates a cancel withdraw instruction for a vault
|
|
435
436
|
*
|
|
436
437
|
* @param {Object} params - Cancel withdraw request parameters
|
|
437
|
-
* @param {PublicKey} params.
|
|
438
|
+
* @param {PublicKey} params.userTransferAuthority - Public key of the user authority
|
|
438
439
|
* @param {PublicKey} params.vault - Public key of the vault
|
|
439
440
|
* @returns {Promise<TransactionInstruction>} Transaction instruction for withdrawal
|
|
440
441
|
*
|
|
@@ -443,16 +444,16 @@ class VoltrClient extends AccountUtils {
|
|
|
443
444
|
* @example
|
|
444
445
|
* const ix = await client.createCancelRequestWithdrawVaultIx(
|
|
445
446
|
* {
|
|
446
|
-
*
|
|
447
|
+
* userTransferAuthority: userPubkey,
|
|
447
448
|
* vault: vaultPubkey,
|
|
448
449
|
* }
|
|
449
450
|
* );
|
|
450
451
|
*/
|
|
451
|
-
async createCancelRequestWithdrawVaultIx({
|
|
452
|
+
async createCancelRequestWithdrawVaultIx({ userTransferAuthority, vault, }) {
|
|
452
453
|
return await this.vaultProgram.methods
|
|
453
454
|
.cancelRequestWithdrawVault()
|
|
454
455
|
.accounts({
|
|
455
|
-
userTransferAuthority
|
|
456
|
+
userTransferAuthority,
|
|
456
457
|
vault,
|
|
457
458
|
})
|
|
458
459
|
.instruction();
|
|
@@ -461,7 +462,7 @@ class VoltrClient extends AccountUtils {
|
|
|
461
462
|
* Creates a withdraw instruction for a vault
|
|
462
463
|
*
|
|
463
464
|
* @param {Object} params - Withdraw parameters
|
|
464
|
-
* @param {PublicKey} params.
|
|
465
|
+
* @param {PublicKey} params.userTransferAuthority - Public key of the user authority
|
|
465
466
|
* @param {PublicKey} params.vault - Public key of the vault
|
|
466
467
|
* @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
|
|
467
468
|
* @param {PublicKey} params.assetTokenProgram - Public key of the asset token program
|
|
@@ -472,18 +473,18 @@ class VoltrClient extends AccountUtils {
|
|
|
472
473
|
* @example
|
|
473
474
|
* const ix = await client.createWithdrawVaultIx(
|
|
474
475
|
* {
|
|
475
|
-
*
|
|
476
|
+
* userTransferAuthority: userPubkey,
|
|
476
477
|
* vault: vaultPubkey,
|
|
477
478
|
* vaultAssetMint: mintPubkey,
|
|
478
479
|
* assetTokenProgram: tokenProgramPubkey
|
|
479
480
|
* }
|
|
480
481
|
* );
|
|
481
482
|
*/
|
|
482
|
-
async createWithdrawVaultIx({
|
|
483
|
+
async createWithdrawVaultIx({ userTransferAuthority, vault, vaultAssetMint, assetTokenProgram, }) {
|
|
483
484
|
return await this.vaultProgram.methods
|
|
484
485
|
.withdrawVault()
|
|
485
486
|
.accounts({
|
|
486
|
-
userTransferAuthority
|
|
487
|
+
userTransferAuthority,
|
|
487
488
|
vault,
|
|
488
489
|
vaultAssetMint,
|
|
489
490
|
assetTokenProgram,
|
|
@@ -824,6 +825,26 @@ class VoltrClient extends AccountUtils {
|
|
|
824
825
|
},
|
|
825
826
|
]);
|
|
826
827
|
}
|
|
828
|
+
/**
|
|
829
|
+
* Fetches all request withdraw vault receipt accounts of a vault
|
|
830
|
+
* @param vault - Public key of the vault
|
|
831
|
+
* @returns Promise resolving to an array of request withdraw vault receipt accounts
|
|
832
|
+
*
|
|
833
|
+
* @example
|
|
834
|
+
* ```typescript
|
|
835
|
+
* const requestWithdrawVaultReceiptAccounts = await client.fetchAllRequestWithdrawVaultReceiptsOfVault(vaultPubkey);
|
|
836
|
+
* ```
|
|
837
|
+
*/
|
|
838
|
+
async fetchAllRequestWithdrawVaultReceiptsOfVault(vault) {
|
|
839
|
+
return await this.vaultProgram.account.requestWithdrawVaultReceipt.all([
|
|
840
|
+
{
|
|
841
|
+
memcmp: {
|
|
842
|
+
offset: 8, // 8 for discriminator
|
|
843
|
+
bytes: vault.toBase58(),
|
|
844
|
+
},
|
|
845
|
+
},
|
|
846
|
+
]);
|
|
847
|
+
}
|
|
827
848
|
/**
|
|
828
849
|
* Fetches all adaptor add receipt accounts of a vault
|
|
829
850
|
* @param vault - Public key of the vault
|
|
@@ -893,6 +914,27 @@ class VoltrClient extends AccountUtils {
|
|
|
893
914
|
return await this.vaultProgram.account.adaptorAddReceipt.fetch(adaptorAddReceipt, "confirmed");
|
|
894
915
|
}
|
|
895
916
|
// --------------------------------------- Helpers
|
|
917
|
+
/**
|
|
918
|
+
* Fetches all pending withdrawals for a vault
|
|
919
|
+
* @param vault - Public key of the vault
|
|
920
|
+
* @returns Promise resolving to an array of pending withdrawals
|
|
921
|
+
*
|
|
922
|
+
* @example
|
|
923
|
+
* ```typescript
|
|
924
|
+
* const pendingWithdrawals = await client.getAllPendingWithdrawalsForVault(vaultPubkey);
|
|
925
|
+
* ```
|
|
926
|
+
*/
|
|
927
|
+
async getAllPendingWithdrawalsForVault(vault) {
|
|
928
|
+
const requestWithdrawVaultReceipts = await this.fetchAllRequestWithdrawVaultReceiptsOfVault(vault);
|
|
929
|
+
return requestWithdrawVaultReceipts.map((receipt) => {
|
|
930
|
+
const amountAssetToWithdrawDecimal = (0, decimals_1.convertDecimalBitsToDecimal)(receipt.account.amountAssetToWithdrawDecimalBits);
|
|
931
|
+
const amountAssetToWithdraw = amountAssetToWithdrawDecimal.toNumber();
|
|
932
|
+
return {
|
|
933
|
+
amountAssetToWithdraw,
|
|
934
|
+
withdrawableFromTs: receipt.account.withdrawableFromTs,
|
|
935
|
+
};
|
|
936
|
+
});
|
|
937
|
+
}
|
|
896
938
|
calculateLockedProfit(lastUpdatedLockedProfit, lockedProfitDegradationDuration, currentTime) {
|
|
897
939
|
if (lockedProfitDegradationDuration.eq(new bn_js_1.default(0)))
|
|
898
940
|
return new bn_js_1.default(0);
|
package/dist/decimals.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertDecimalBitsToDecimal = convertDecimalBitsToDecimal;
|
|
4
|
+
const decimal_js_1 = require("decimal.js");
|
|
5
|
+
const DECIMAL_FRACTIONAL_BYTES = 6;
|
|
6
|
+
const DECIMAL_DIVISOR = new decimal_js_1.Decimal(2).pow(8 * DECIMAL_FRACTIONAL_BYTES);
|
|
7
|
+
function convertDecimalBitsToDecimal(value) {
|
|
8
|
+
let decimalValue = new decimal_js_1.Decimal(value.toString());
|
|
9
|
+
return decimalValue.div(DECIMAL_DIVISOR);
|
|
10
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voltr/vault-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "SDK for interacting with Voltr Protocol",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
"@coral-xyz/anchor": "^0.30.1",
|
|
30
30
|
"@solana/spl-token": "^0.4.9",
|
|
31
31
|
"@solana/web3.js": "^1.98.0",
|
|
32
|
-
"bn.js": "^5.2.1"
|
|
32
|
+
"bn.js": "^5.2.1",
|
|
33
|
+
"decimal.js": "^10.5.0"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
36
|
"@types/bn.js": "^5.1.6",
|