@voltr/vault-sdk 1.0.5 → 1.0.6
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 +42 -7
- package/dist/client.js +62 -13
- package/package.json +1 -1
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
|
@@ -726,13 +726,6 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
726
726
|
lastUpdatedEpoch: BN;
|
|
727
727
|
reserved: number[];
|
|
728
728
|
}>[]>;
|
|
729
|
-
getPositionAndTotalValuesForVault(vault: PublicKey): Promise<{
|
|
730
|
-
totalValue: number;
|
|
731
|
-
strategies: {
|
|
732
|
-
strategyId: string;
|
|
733
|
-
amount: number;
|
|
734
|
-
}[];
|
|
735
|
-
}>;
|
|
736
729
|
/**
|
|
737
730
|
* Fetches a vault account's data
|
|
738
731
|
* @param vault - Public key of the vault
|
|
@@ -852,6 +845,23 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
852
845
|
bump: number;
|
|
853
846
|
version: number;
|
|
854
847
|
}>;
|
|
848
|
+
/**
|
|
849
|
+
* Fetches the position and total values for a vault
|
|
850
|
+
* @param vault - Public key of the vault
|
|
851
|
+
* @returns Promise resolving to the position and total values
|
|
852
|
+
*
|
|
853
|
+
* @example
|
|
854
|
+
* ```typescript
|
|
855
|
+
* const positionAndTotalValues = await client.getPositionAndTotalValuesForVault(vaultPubkey);
|
|
856
|
+
* ```
|
|
857
|
+
*/
|
|
858
|
+
getPositionAndTotalValuesForVault(vault: PublicKey): Promise<{
|
|
859
|
+
totalValue: number;
|
|
860
|
+
strategies: {
|
|
861
|
+
strategyId: string;
|
|
862
|
+
amount: number;
|
|
863
|
+
}[];
|
|
864
|
+
}>;
|
|
855
865
|
/**
|
|
856
866
|
* Fetches the accumulated admin fees for a vault
|
|
857
867
|
* @param vault - Public key of the vault
|
|
@@ -874,6 +884,31 @@ export declare class VoltrClient extends AccountUtils {
|
|
|
874
884
|
* ```
|
|
875
885
|
*/
|
|
876
886
|
getAccumulatedManagerFeesForVault(vault: PublicKey): Promise<BN>;
|
|
887
|
+
/**
|
|
888
|
+
* Fetches the current asset per LP for a vault
|
|
889
|
+
* @param vault - Public key of the vault
|
|
890
|
+
* @returns Promise resolving to the current asset per LP
|
|
891
|
+
*
|
|
892
|
+
* @example
|
|
893
|
+
* ```typescript
|
|
894
|
+
* const currentAssetPerLp = await client.getCurrentAssetPerLpForVault(vaultPubkey);
|
|
895
|
+
* ```
|
|
896
|
+
*/
|
|
897
|
+
getCurrentAssetPerLpForVault(vault: PublicKey): Promise<number>;
|
|
898
|
+
/**
|
|
899
|
+
* Fetches the high water mark for a vault
|
|
900
|
+
* @param vault - Public key of the vault
|
|
901
|
+
* @returns Promise resolving to the high water mark
|
|
902
|
+
*
|
|
903
|
+
* @example
|
|
904
|
+
* ```typescript
|
|
905
|
+
* const highWaterMark = await client.getHighWaterMarkForVault(vaultPubkey);
|
|
906
|
+
* ```
|
|
907
|
+
*/
|
|
908
|
+
getHighWaterMarkForVault(vault: PublicKey): Promise<{
|
|
909
|
+
highestAssetPerLp: number;
|
|
910
|
+
lastUpdatedTs: number;
|
|
911
|
+
}>;
|
|
877
912
|
/**
|
|
878
913
|
* Processes a withdrawal receipt into a standardized withdrawal info object
|
|
879
914
|
* @private
|
package/dist/client.js
CHANGED
|
@@ -904,19 +904,6 @@ class VoltrClient extends AccountUtils {
|
|
|
904
904
|
},
|
|
905
905
|
]);
|
|
906
906
|
}
|
|
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
907
|
// --------------------------------------- Account Fetching
|
|
921
908
|
/**
|
|
922
909
|
* Fetches a vault account's data
|
|
@@ -966,6 +953,29 @@ class VoltrClient extends AccountUtils {
|
|
|
966
953
|
return await this.vaultProgram.account.requestWithdrawVaultReceipt.fetch(requestWithdrawVaultReceipt, "confirmed");
|
|
967
954
|
}
|
|
968
955
|
// --------------------------------------- Helpers
|
|
956
|
+
/**
|
|
957
|
+
* Fetches the position and total values for a vault
|
|
958
|
+
* @param vault - Public key of the vault
|
|
959
|
+
* @returns Promise resolving to the position and total values
|
|
960
|
+
*
|
|
961
|
+
* @example
|
|
962
|
+
* ```typescript
|
|
963
|
+
* const positionAndTotalValues = await client.getPositionAndTotalValuesForVault(vaultPubkey);
|
|
964
|
+
* ```
|
|
965
|
+
*/
|
|
966
|
+
async getPositionAndTotalValuesForVault(vault) {
|
|
967
|
+
const vaultAccount = await this.fetchVaultAccount(vault);
|
|
968
|
+
const totalAssetValue = vaultAccount.asset.totalValue;
|
|
969
|
+
const strategyInitReceiptAccounts = await this.fetchAllStrategyInitReceiptAccountsOfVault(vault);
|
|
970
|
+
const strategyInfo = strategyInitReceiptAccounts.map((vaultStrategyAccount) => ({
|
|
971
|
+
strategyId: vaultStrategyAccount.account.strategy.toBase58(),
|
|
972
|
+
amount: vaultStrategyAccount.account.positionValue.toNumber(),
|
|
973
|
+
}));
|
|
974
|
+
return {
|
|
975
|
+
totalValue: totalAssetValue.toNumber(),
|
|
976
|
+
strategies: strategyInfo,
|
|
977
|
+
};
|
|
978
|
+
}
|
|
969
979
|
/**
|
|
970
980
|
* Fetches the accumulated admin fees for a vault
|
|
971
981
|
* @param vault - Public key of the vault
|
|
@@ -994,6 +1004,45 @@ class VoltrClient extends AccountUtils {
|
|
|
994
1004
|
const vaultAccount = await this.fetchVaultAccount(vault);
|
|
995
1005
|
return vaultAccount.feeState.accumulatedLpManagerFees;
|
|
996
1006
|
}
|
|
1007
|
+
/**
|
|
1008
|
+
* Fetches the current asset per LP for a vault
|
|
1009
|
+
* @param vault - Public key of the vault
|
|
1010
|
+
* @returns Promise resolving to the current asset per LP
|
|
1011
|
+
*
|
|
1012
|
+
* @example
|
|
1013
|
+
* ```typescript
|
|
1014
|
+
* const currentAssetPerLp = await client.getCurrentAssetPerLpForVault(vaultPubkey);
|
|
1015
|
+
* ```
|
|
1016
|
+
*/
|
|
1017
|
+
async getCurrentAssetPerLpForVault(vault) {
|
|
1018
|
+
const vaultLpMint = this.findVaultLpMint(vault);
|
|
1019
|
+
const vaultAccount = await this.fetchVaultAccount(vault);
|
|
1020
|
+
const lpSupply = await (0, spl_token_1.getMint)(this.conn, vaultLpMint).then((lp) => new bn_js_1.default(lp.supply.toString()));
|
|
1021
|
+
const unharvestedFeesLp = vaultAccount.feeState.accumulatedLpAdminFees
|
|
1022
|
+
.add(vaultAccount.feeState.accumulatedLpManagerFees)
|
|
1023
|
+
.add(vaultAccount.feeState.accumulatedLpProtocolFees);
|
|
1024
|
+
const totalLpSupply = unharvestedFeesLp.add(lpSupply);
|
|
1025
|
+
const currentAssetPerLp = vaultAccount.asset.totalValue.toNumber() / totalLpSupply.toNumber();
|
|
1026
|
+
return currentAssetPerLp;
|
|
1027
|
+
}
|
|
1028
|
+
/**
|
|
1029
|
+
* Fetches the high water mark for a vault
|
|
1030
|
+
* @param vault - Public key of the vault
|
|
1031
|
+
* @returns Promise resolving to the high water mark
|
|
1032
|
+
*
|
|
1033
|
+
* @example
|
|
1034
|
+
* ```typescript
|
|
1035
|
+
* const highWaterMark = await client.getHighWaterMarkForVault(vaultPubkey);
|
|
1036
|
+
* ```
|
|
1037
|
+
*/
|
|
1038
|
+
async getHighWaterMarkForVault(vault) {
|
|
1039
|
+
const vaultAccount = await this.fetchVaultAccount(vault);
|
|
1040
|
+
const highWaterMarkValue = (0, decimals_1.convertDecimalBitsToDecimal)(vaultAccount.highWaterMark.highestAssetPerLpDecimalBits);
|
|
1041
|
+
return {
|
|
1042
|
+
highestAssetPerLp: highWaterMarkValue.toNumber(),
|
|
1043
|
+
lastUpdatedTs: vaultAccount.highWaterMark.lastUpdatedTs.toNumber(),
|
|
1044
|
+
};
|
|
1045
|
+
}
|
|
997
1046
|
/**
|
|
998
1047
|
* Processes a withdrawal receipt into a standardized withdrawal info object
|
|
999
1048
|
* @private
|