@drift-labs/vaults-sdk 0.1.423 → 0.1.424
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/lib/accounts/vaultAccount.d.ts +1 -6
- package/lib/accounts/vaultAccount.js +0 -116
- package/lib/addresses.d.ts +0 -1
- package/lib/addresses.js +0 -7
- package/lib/math/vaultDepositor.d.ts +2 -11
- package/lib/math/vaultDepositor.js +2 -20
- package/lib/types/drift_vaults.d.ts +24 -450
- package/lib/types/drift_vaults.js +24 -450
- package/lib/types/types.d.ts +1 -66
- package/lib/vaultClient.d.ts +5 -53
- package/lib/vaultClient.js +42 -407
- package/package.json +1 -1
- package/src/accounts/vaultAccount.ts +3 -164
- package/src/addresses.ts +0 -13
- package/src/idl/drift_vaults.json +24 -453
- package/src/math/vaultDepositor.ts +4 -36
- package/src/types/drift_vaults.ts +55 -907
- package/src/types/types.ts +1 -79
- package/src/vaultClient.ts +42 -540
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
unstakeSharesToAmount as depositSharesToVaultAmount,
|
|
6
6
|
stakeAmountToShares as vaultAmountToDepositorShares,
|
|
7
7
|
} from '@drift-labs/sdk';
|
|
8
|
-
import { Vault, VaultDepositor
|
|
8
|
+
import { Vault, VaultDepositor } from '../types/types';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Calculates the unrealized profitShare for a vaultDepositor
|
|
@@ -42,49 +42,17 @@ export function calculateApplyProfitShare(
|
|
|
42
42
|
export function calculateProfitShare(
|
|
43
43
|
vaultDepositor: VaultDepositor,
|
|
44
44
|
totalAmount: BN,
|
|
45
|
-
vault: Vault
|
|
46
|
-
vaultProtocol?: VaultProtocol
|
|
45
|
+
vault: Vault
|
|
47
46
|
) {
|
|
48
47
|
const profit = totalAmount.sub(
|
|
49
48
|
vaultDepositor.netDeposits.add(vaultDepositor.cumulativeProfitShareAmount)
|
|
50
49
|
);
|
|
51
|
-
let profitShare = vault.profitShare;
|
|
52
|
-
if (vaultProtocol) {
|
|
53
|
-
profitShare += vaultProtocol.protocolProfitShare;
|
|
54
|
-
}
|
|
55
50
|
if (profit.gt(ZERO)) {
|
|
56
51
|
const profitShareAmount = profit
|
|
57
|
-
.mul(new BN(profitShare))
|
|
52
|
+
.mul(new BN(vault.profitShare))
|
|
58
53
|
.div(PERCENTAGE_PRECISION);
|
|
59
54
|
return profitShareAmount;
|
|
60
55
|
}
|
|
61
|
-
return ZERO;
|
|
62
|
-
}
|
|
63
56
|
|
|
64
|
-
|
|
65
|
-
* Calculates the equity across deposits and realized profit for a vaultDepositor
|
|
66
|
-
* @param vaultDepositor vault depositor account
|
|
67
|
-
* @param vaultEquity total vault equity
|
|
68
|
-
* @param vault vault account
|
|
69
|
-
* @param vaultProtocol if vault account has "vaultProtocol" then this is needed
|
|
70
|
-
* @returns
|
|
71
|
-
*/
|
|
72
|
-
export function calculateRealizedVaultDepositorEquity(
|
|
73
|
-
vaultDepositor: VaultDepositor,
|
|
74
|
-
vaultEquity: BN,
|
|
75
|
-
vault: Vault,
|
|
76
|
-
vaultProtocol?: VaultProtocol
|
|
77
|
-
): BN {
|
|
78
|
-
const vdAmount = depositSharesToVaultAmount(
|
|
79
|
-
vaultDepositor.vaultShares,
|
|
80
|
-
vault.totalShares,
|
|
81
|
-
vaultEquity
|
|
82
|
-
);
|
|
83
|
-
const profitShareAmount = calculateProfitShare(
|
|
84
|
-
vaultDepositor,
|
|
85
|
-
vdAmount,
|
|
86
|
-
vault,
|
|
87
|
-
vaultProtocol
|
|
88
|
-
);
|
|
89
|
-
return vdAmount.sub(profitShareAmount);
|
|
57
|
+
return ZERO;
|
|
90
58
|
}
|