@voltr/vault-sdk 1.0.5 → 1.0.7
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 +4 -0
- package/dist/client.d.ts +68 -7
- package/dist/client.js +93 -13
- package/dist/idl/voltr_vault.json +1101 -45
- package/dist/types/voltr_vault.d.ts +1101 -45
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -265,6 +265,7 @@ pendingWithdrawals.forEach((withdrawal, index) => {
|
|
|
265
265
|
- `fetchVaultAccount(vault)`
|
|
266
266
|
- `fetchStrategyInitReceiptAccount(strategyInitReceipt)`
|
|
267
267
|
- `fetchAdaptorAddReceiptAccount(adaptorAddReceipt)`
|
|
268
|
+
- `fetchRequestWithdrawVaultReceiptAccount(requestWithdrawVaultReceipt)`
|
|
268
269
|
- `fetchAllStrategyInitReceiptAccounts()`
|
|
269
270
|
- `fetchAllStrategyInitReceiptAccountsOfVault(vault)`
|
|
270
271
|
- `fetchAllAdaptorAddReceiptAccountsOfVault(vault)`
|
|
@@ -272,7 +273,10 @@ pendingWithdrawals.forEach((withdrawal, index) => {
|
|
|
272
273
|
- `getPositionAndTotalValuesForVault(vault)`
|
|
273
274
|
- `getAccumulatedAdminFeesForVault(vault)`
|
|
274
275
|
- `getAccumulatedManagerFeesForVault(vault)`
|
|
276
|
+
- `getPendingWithdrawalForUser(vault, user)`
|
|
275
277
|
- `getAllPendingWithdrawalsForVault(vault)`
|
|
278
|
+
- `getCurrentAssetPerLpForVault(vault)`
|
|
279
|
+
- `getHighWaterMarkForVault(vault)`
|
|
276
280
|
|
|
277
281
|
#### PDA Finding
|
|
278
282
|
|
package/dist/client.d.ts
CHANGED
|
@@ -645,6 +645,32 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
645
645
|
protocolAdmin: PublicKey;
|
|
646
646
|
vault: PublicKey;
|
|
647
647
|
}): Promise<TransactionInstruction>;
|
|
648
|
+
/**
|
|
649
|
+
* Creates an instruction to close a strategy
|
|
650
|
+
* @param {Object} params - Parameters for closing strategy
|
|
651
|
+
* @param {PublicKey} params.payer - Public key of the payer
|
|
652
|
+
* @param {PublicKey} params.manager - Public key of the manager
|
|
653
|
+
* @param {PublicKey} params.vault - Public key of the vault
|
|
654
|
+
* @param {PublicKey} params.strategy - Public key of the strategy
|
|
655
|
+
* @returns {Promise<TransactionInstruction>} Transaction instruction for closing strategy
|
|
656
|
+
* @throws {Error} If instruction creation fails
|
|
657
|
+
*
|
|
658
|
+
* @example
|
|
659
|
+
* ```typescript
|
|
660
|
+
* const ix = await client.createCloseStrategyIx({
|
|
661
|
+
* payer: payerPubkey,
|
|
662
|
+
* manager: managerPubkey,
|
|
663
|
+
* vault: vaultPubkey,
|
|
664
|
+
* strategy: strategyPubkey,
|
|
665
|
+
* });
|
|
666
|
+
* ```
|
|
667
|
+
*/
|
|
668
|
+
createCloseStrategyIx({ payer, manager, vault, strategy, }: {
|
|
669
|
+
payer: PublicKey;
|
|
670
|
+
manager: PublicKey;
|
|
671
|
+
vault: PublicKey;
|
|
672
|
+
strategy: PublicKey;
|
|
673
|
+
}): Promise<TransactionInstruction>;
|
|
648
674
|
/**
|
|
649
675
|
* Fetches all strategy init receipt accounts
|
|
650
676
|
* @returns Promise resolving to an array of strategy init receipt accounts
|
|
@@ -726,13 +752,6 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
726
752
|
lastUpdatedEpoch: BN;
|
|
727
753
|
reserved: number[];
|
|
728
754
|
}>[]>;
|
|
729
|
-
getPositionAndTotalValuesForVault(vault: PublicKey): Promise<{
|
|
730
|
-
totalValue: number;
|
|
731
|
-
strategies: {
|
|
732
|
-
strategyId: string;
|
|
733
|
-
amount: number;
|
|
734
|
-
}[];
|
|
735
|
-
}>;
|
|
736
755
|
/**
|
|
737
756
|
* Fetches a vault account's data
|
|
738
757
|
* @param vault - Public key of the vault
|
|
@@ -852,6 +871,23 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
852
871
|
bump: number;
|
|
853
872
|
version: number;
|
|
854
873
|
}>;
|
|
874
|
+
/**
|
|
875
|
+
* Fetches the position and total values for a vault
|
|
876
|
+
* @param vault - Public key of the vault
|
|
877
|
+
* @returns Promise resolving to the position and total values
|
|
878
|
+
*
|
|
879
|
+
* @example
|
|
880
|
+
* ```typescript
|
|
881
|
+
* const positionAndTotalValues = await client.getPositionAndTotalValuesForVault(vaultPubkey);
|
|
882
|
+
* ```
|
|
883
|
+
*/
|
|
884
|
+
getPositionAndTotalValuesForVault(vault: PublicKey): Promise<{
|
|
885
|
+
totalValue: number;
|
|
886
|
+
strategies: {
|
|
887
|
+
strategyId: string;
|
|
888
|
+
amount: number;
|
|
889
|
+
}[];
|
|
890
|
+
}>;
|
|
855
891
|
/**
|
|
856
892
|
* Fetches the accumulated admin fees for a vault
|
|
857
893
|
* @param vault - Public key of the vault
|
|
@@ -874,6 +910,31 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
874
910
|
* ```
|
|
875
911
|
*/
|
|
876
912
|
getAccumulatedManagerFeesForVault(vault: PublicKey): Promise<BN>;
|
|
913
|
+
/**
|
|
914
|
+
* Fetches the current asset per LP for a vault
|
|
915
|
+
* @param vault - Public key of the vault
|
|
916
|
+
* @returns Promise resolving to the current asset per LP
|
|
917
|
+
*
|
|
918
|
+
* @example
|
|
919
|
+
* ```typescript
|
|
920
|
+
* const currentAssetPerLp = await client.getCurrentAssetPerLpForVault(vaultPubkey);
|
|
921
|
+
* ```
|
|
922
|
+
*/
|
|
923
|
+
getCurrentAssetPerLpForVault(vault: PublicKey): Promise<number>;
|
|
924
|
+
/**
|
|
925
|
+
* Fetches the high water mark for a vault
|
|
926
|
+
* @param vault - Public key of the vault
|
|
927
|
+
* @returns Promise resolving to the high water mark
|
|
928
|
+
*
|
|
929
|
+
* @example
|
|
930
|
+
* ```typescript
|
|
931
|
+
* const highWaterMark = await client.getHighWaterMarkForVault(vaultPubkey);
|
|
932
|
+
* ```
|
|
933
|
+
*/
|
|
934
|
+
getHighWaterMarkForVault(vault: PublicKey): Promise<{
|
|
935
|
+
highestAssetPerLp: number;
|
|
936
|
+
lastUpdatedTs: number;
|
|
937
|
+
}>;
|
|
877
938
|
/**
|
|
878
939
|
* Processes a withdrawal receipt into a standardized withdrawal info object
|
|
879
940
|
* @private
|
package/dist/client.js
CHANGED
|
@@ -831,6 +831,37 @@ class VoltrClient extends AccountUtils {
|
|
|
831
831
|
})
|
|
832
832
|
.instruction();
|
|
833
833
|
}
|
|
834
|
+
/**
|
|
835
|
+
* Creates an instruction to close a strategy
|
|
836
|
+
* @param {Object} params - Parameters for closing strategy
|
|
837
|
+
* @param {PublicKey} params.payer - Public key of the payer
|
|
838
|
+
* @param {PublicKey} params.manager - Public key of the manager
|
|
839
|
+
* @param {PublicKey} params.vault - Public key of the vault
|
|
840
|
+
* @param {PublicKey} params.strategy - Public key of the strategy
|
|
841
|
+
* @returns {Promise<TransactionInstruction>} Transaction instruction for closing strategy
|
|
842
|
+
* @throws {Error} If instruction creation fails
|
|
843
|
+
*
|
|
844
|
+
* @example
|
|
845
|
+
* ```typescript
|
|
846
|
+
* const ix = await client.createCloseStrategyIx({
|
|
847
|
+
* payer: payerPubkey,
|
|
848
|
+
* manager: managerPubkey,
|
|
849
|
+
* vault: vaultPubkey,
|
|
850
|
+
* strategy: strategyPubkey,
|
|
851
|
+
* });
|
|
852
|
+
* ```
|
|
853
|
+
*/
|
|
854
|
+
async createCloseStrategyIx({ payer, manager, vault, strategy, }) {
|
|
855
|
+
return await this.vaultProgram.methods
|
|
856
|
+
.closeStrategy()
|
|
857
|
+
.accounts({
|
|
858
|
+
payer,
|
|
859
|
+
manager,
|
|
860
|
+
vault,
|
|
861
|
+
strategy,
|
|
862
|
+
})
|
|
863
|
+
.instruction();
|
|
864
|
+
}
|
|
834
865
|
// --------------------------------------- Account Fetching All
|
|
835
866
|
/**
|
|
836
867
|
* Fetches all strategy init receipt accounts
|
|
@@ -904,19 +935,6 @@ class VoltrClient extends AccountUtils {
|
|
|
904
935
|
},
|
|
905
936
|
]);
|
|
906
937
|
}
|
|
907
|
-
async getPositionAndTotalValuesForVault(vault) {
|
|
908
|
-
const vaultAccount = await this.fetchVaultAccount(vault);
|
|
909
|
-
const totalAssetValue = vaultAccount.asset.totalValue;
|
|
910
|
-
const strategyInitReceiptAccounts = await this.fetchAllStrategyInitReceiptAccountsOfVault(vault);
|
|
911
|
-
const strategyInfo = strategyInitReceiptAccounts.map((vaultStrategyAccount) => ({
|
|
912
|
-
strategyId: vaultStrategyAccount.account.strategy.toBase58(),
|
|
913
|
-
amount: vaultStrategyAccount.account.positionValue.toNumber(),
|
|
914
|
-
}));
|
|
915
|
-
return {
|
|
916
|
-
totalValue: totalAssetValue.toNumber(),
|
|
917
|
-
strategies: strategyInfo,
|
|
918
|
-
};
|
|
919
|
-
}
|
|
920
938
|
// --------------------------------------- Account Fetching
|
|
921
939
|
/**
|
|
922
940
|
* Fetches a vault account's data
|
|
@@ -966,6 +984,29 @@ class VoltrClient extends AccountUtils {
|
|
|
966
984
|
return await this.vaultProgram.account.requestWithdrawVaultReceipt.fetch(requestWithdrawVaultReceipt, "confirmed");
|
|
967
985
|
}
|
|
968
986
|
// --------------------------------------- Helpers
|
|
987
|
+
/**
|
|
988
|
+
* Fetches the position and total values for a vault
|
|
989
|
+
* @param vault - Public key of the vault
|
|
990
|
+
* @returns Promise resolving to the position and total values
|
|
991
|
+
*
|
|
992
|
+
* @example
|
|
993
|
+
* ```typescript
|
|
994
|
+
* const positionAndTotalValues = await client.getPositionAndTotalValuesForVault(vaultPubkey);
|
|
995
|
+
* ```
|
|
996
|
+
*/
|
|
997
|
+
async getPositionAndTotalValuesForVault(vault) {
|
|
998
|
+
const vaultAccount = await this.fetchVaultAccount(vault);
|
|
999
|
+
const totalAssetValue = vaultAccount.asset.totalValue;
|
|
1000
|
+
const strategyInitReceiptAccounts = await this.fetchAllStrategyInitReceiptAccountsOfVault(vault);
|
|
1001
|
+
const strategyInfo = strategyInitReceiptAccounts.map((vaultStrategyAccount) => ({
|
|
1002
|
+
strategyId: vaultStrategyAccount.account.strategy.toBase58(),
|
|
1003
|
+
amount: vaultStrategyAccount.account.positionValue.toNumber(),
|
|
1004
|
+
}));
|
|
1005
|
+
return {
|
|
1006
|
+
totalValue: totalAssetValue.toNumber(),
|
|
1007
|
+
strategies: strategyInfo,
|
|
1008
|
+
};
|
|
1009
|
+
}
|
|
969
1010
|
/**
|
|
970
1011
|
* Fetches the accumulated admin fees for a vault
|
|
971
1012
|
* @param vault - Public key of the vault
|
|
@@ -994,6 +1035,45 @@ class VoltrClient extends AccountUtils {
|
|
|
994
1035
|
const vaultAccount = await this.fetchVaultAccount(vault);
|
|
995
1036
|
return vaultAccount.feeState.accumulatedLpManagerFees;
|
|
996
1037
|
}
|
|
1038
|
+
/**
|
|
1039
|
+
* Fetches the current asset per LP for a vault
|
|
1040
|
+
* @param vault - Public key of the vault
|
|
1041
|
+
* @returns Promise resolving to the current asset per LP
|
|
1042
|
+
*
|
|
1043
|
+
* @example
|
|
1044
|
+
* ```typescript
|
|
1045
|
+
* const currentAssetPerLp = await client.getCurrentAssetPerLpForVault(vaultPubkey);
|
|
1046
|
+
* ```
|
|
1047
|
+
*/
|
|
1048
|
+
async getCurrentAssetPerLpForVault(vault) {
|
|
1049
|
+
const vaultLpMint = this.findVaultLpMint(vault);
|
|
1050
|
+
const vaultAccount = await this.fetchVaultAccount(vault);
|
|
1051
|
+
const lpSupply = await (0, spl_token_1.getMint)(this.conn, vaultLpMint).then((lp) => new bn_js_1.default(lp.supply.toString()));
|
|
1052
|
+
const unharvestedFeesLp = vaultAccount.feeState.accumulatedLpAdminFees
|
|
1053
|
+
.add(vaultAccount.feeState.accumulatedLpManagerFees)
|
|
1054
|
+
.add(vaultAccount.feeState.accumulatedLpProtocolFees);
|
|
1055
|
+
const totalLpSupply = unharvestedFeesLp.add(lpSupply);
|
|
1056
|
+
const currentAssetPerLp = vaultAccount.asset.totalValue.toNumber() / totalLpSupply.toNumber();
|
|
1057
|
+
return currentAssetPerLp;
|
|
1058
|
+
}
|
|
1059
|
+
/**
|
|
1060
|
+
* Fetches the high water mark for a vault
|
|
1061
|
+
* @param vault - Public key of the vault
|
|
1062
|
+
* @returns Promise resolving to the high water mark
|
|
1063
|
+
*
|
|
1064
|
+
* @example
|
|
1065
|
+
* ```typescript
|
|
1066
|
+
* const highWaterMark = await client.getHighWaterMarkForVault(vaultPubkey);
|
|
1067
|
+
* ```
|
|
1068
|
+
*/
|
|
1069
|
+
async getHighWaterMarkForVault(vault) {
|
|
1070
|
+
const vaultAccount = await this.fetchVaultAccount(vault);
|
|
1071
|
+
const highWaterMarkValue = (0, decimals_1.convertDecimalBitsToDecimal)(vaultAccount.highWaterMark.highestAssetPerLpDecimalBits);
|
|
1072
|
+
return {
|
|
1073
|
+
highestAssetPerLp: highWaterMarkValue.toNumber(),
|
|
1074
|
+
lastUpdatedTs: vaultAccount.highWaterMark.lastUpdatedTs.toNumber(),
|
|
1075
|
+
};
|
|
1076
|
+
}
|
|
997
1077
|
/**
|
|
998
1078
|
* Processes a withdrawal receipt into a standardized withdrawal info object
|
|
999
1079
|
* @private
|