@drift-labs/vaults-sdk 0.1.461 → 0.1.463
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 +6 -1
- package/lib/accounts/vaultAccount.js +115 -0
- package/lib/addresses.d.ts +1 -0
- package/lib/addresses.js +7 -0
- package/lib/math/vaultDepositor.d.ts +11 -2
- package/lib/math/vaultDepositor.js +20 -2
- package/lib/types/drift_vaults.d.ts +587 -24
- package/lib/types/drift_vaults.js +587 -24
- package/lib/types/types.d.ts +77 -1
- package/lib/vaultClient.d.ts +52 -3
- package/lib/vaultClient.js +400 -42
- package/package.json +1 -1
- package/src/accounts/vaultAccount.ts +163 -2
- package/src/addresses.ts +13 -0
- package/src/idl/drift_vaults.json +598 -24
- package/src/math/vaultDepositor.ts +36 -4
- package/src/types/drift_vaults.ts +1231 -105
- package/src/types/types.ts +94 -1
- package/src/vaultClient.ts +532 -42
package/lib/types/types.d.ts
CHANGED
|
@@ -19,6 +19,47 @@ export type WithdrawRequest = {
|
|
|
19
19
|
value: BN;
|
|
20
20
|
ts: BN;
|
|
21
21
|
};
|
|
22
|
+
export type VaultParams = {
|
|
23
|
+
name: number[];
|
|
24
|
+
spotMarketIndex: number;
|
|
25
|
+
redeemPeriod: BN;
|
|
26
|
+
maxTokens: BN;
|
|
27
|
+
minDepositAmount: BN;
|
|
28
|
+
managementFee: BN;
|
|
29
|
+
profitShare: number;
|
|
30
|
+
hurdleRate: number;
|
|
31
|
+
permissioned: boolean;
|
|
32
|
+
};
|
|
33
|
+
export type VaultWithProtocolParams = {
|
|
34
|
+
name: number[];
|
|
35
|
+
spotMarketIndex: number;
|
|
36
|
+
redeemPeriod: BN;
|
|
37
|
+
maxTokens: BN;
|
|
38
|
+
minDepositAmount: BN;
|
|
39
|
+
managementFee: BN;
|
|
40
|
+
profitShare: number;
|
|
41
|
+
hurdleRate: number;
|
|
42
|
+
permissioned: boolean;
|
|
43
|
+
vaultProtocol: VaultProtocolParams;
|
|
44
|
+
};
|
|
45
|
+
export type VaultProtocolParams = {
|
|
46
|
+
protocol: PublicKey;
|
|
47
|
+
protocolFee: BN;
|
|
48
|
+
protocolProfitShare: number;
|
|
49
|
+
};
|
|
50
|
+
export type UpdateVaultParams = {
|
|
51
|
+
redeemPeriod: BN | null;
|
|
52
|
+
maxTokens: BN | null;
|
|
53
|
+
minDepositAmount: BN | null;
|
|
54
|
+
managementFee: BN | null;
|
|
55
|
+
profitShare: number | null;
|
|
56
|
+
hurdleRate: number | null;
|
|
57
|
+
permissioned: boolean | null;
|
|
58
|
+
};
|
|
59
|
+
export type UpdateVaultProtocolParams = {
|
|
60
|
+
protocolFee: BN | null;
|
|
61
|
+
protocolProfitShare: number | null;
|
|
62
|
+
};
|
|
22
63
|
export type Vault = {
|
|
23
64
|
name: number[];
|
|
24
65
|
pubkey: PublicKey;
|
|
@@ -53,6 +94,7 @@ export type Vault = {
|
|
|
53
94
|
bump: number;
|
|
54
95
|
permissioned: boolean;
|
|
55
96
|
lastManagerWithdrawRequest: WithdrawRequest;
|
|
97
|
+
vaultProtocol: boolean;
|
|
56
98
|
};
|
|
57
99
|
export type VaultDepositor = {
|
|
58
100
|
vault: PublicKey;
|
|
@@ -67,7 +109,20 @@ export type VaultDepositor = {
|
|
|
67
109
|
cumulativeProfitShareAmount: BN;
|
|
68
110
|
vaultSharesBase: number;
|
|
69
111
|
profitShareFeePaid: BN;
|
|
70
|
-
|
|
112
|
+
padding1: number;
|
|
113
|
+
padding: BN[];
|
|
114
|
+
};
|
|
115
|
+
export type VaultProtocol = {
|
|
116
|
+
protocol: PublicKey;
|
|
117
|
+
protocolProfitAndFeeShares: BN;
|
|
118
|
+
protocolFee: BN;
|
|
119
|
+
protocolTotalWithdraws: BN;
|
|
120
|
+
protocolTotalFee: BN;
|
|
121
|
+
protocolTotalProfitShare: BN;
|
|
122
|
+
lastProtocolWithdrawRequest: WithdrawRequest;
|
|
123
|
+
protocolProfitShare: number;
|
|
124
|
+
bump: number;
|
|
125
|
+
version: number;
|
|
71
126
|
};
|
|
72
127
|
export type VaultsProgramAccountBaseEvents = {
|
|
73
128
|
update: void;
|
|
@@ -125,6 +180,27 @@ export type VaultDepositorRecord = {
|
|
|
125
180
|
managementFee: BN;
|
|
126
181
|
managementFeeShares: BN;
|
|
127
182
|
};
|
|
183
|
+
export type VaultDepositorV1Record = {
|
|
184
|
+
ts: BN;
|
|
185
|
+
vault: PublicKey;
|
|
186
|
+
depositorAuthority: PublicKey;
|
|
187
|
+
action: VaultDepositorAction;
|
|
188
|
+
amount: BN;
|
|
189
|
+
spotMarketIndex: number;
|
|
190
|
+
vaultSharesBefore: BN;
|
|
191
|
+
vaultSharesAfter: BN;
|
|
192
|
+
vaultEquityBefore: BN;
|
|
193
|
+
userVaultSharesBefore: BN;
|
|
194
|
+
totalVaultSharesBefore: BN;
|
|
195
|
+
userVaultSharesAfter: BN;
|
|
196
|
+
totalVaultSharesAfter: BN;
|
|
197
|
+
protocolProfitShare: BN;
|
|
198
|
+
protocolFee: BN;
|
|
199
|
+
protocolFeeShares: BN;
|
|
200
|
+
managerProfitShare: BN;
|
|
201
|
+
managementFee: BN;
|
|
202
|
+
managementFeeShares: BN;
|
|
203
|
+
};
|
|
128
204
|
export type VaultsEventMap = {
|
|
129
205
|
VaultDepositorRecord: Event<VaultDepositorRecord>;
|
|
130
206
|
};
|
package/lib/vaultClient.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Program, ProgramAccount } from '@coral-xyz/anchor';
|
|
|
3
3
|
import { DriftVaults } from './types/drift_vaults';
|
|
4
4
|
import { CompetitionsClient } from '@drift-labs/competitions-sdk';
|
|
5
5
|
import { AddressLookupTableAccount, PublicKey, TransactionInstruction, TransactionSignature, VersionedTransaction } from '@solana/web3.js';
|
|
6
|
-
import { Vault, VaultDepositor, WithdrawUnit } from './types/types';
|
|
6
|
+
import { Vault, VaultDepositor, VaultProtocol, VaultProtocolParams, WithdrawUnit } from './types/types';
|
|
7
7
|
import { UserMapConfig } from '@drift-labs/sdk/lib/userMap/userMapConfig';
|
|
8
8
|
export type TxParams = {
|
|
9
9
|
cuLimit?: number;
|
|
@@ -25,6 +25,10 @@ export declare class VaultClient {
|
|
|
25
25
|
cliMode?: boolean;
|
|
26
26
|
userMapConfig?: UserMapConfig;
|
|
27
27
|
});
|
|
28
|
+
/**
|
|
29
|
+
* Unsubscribes from the vault users map. Call this to clean up any dangling promises.
|
|
30
|
+
*/
|
|
31
|
+
unsubscribe(): Promise<void>;
|
|
28
32
|
getVault(vault: PublicKey): Promise<Vault>;
|
|
29
33
|
getVaultAndSlot(vault: PublicKey): Promise<{
|
|
30
34
|
vault: Vault;
|
|
@@ -35,26 +39,55 @@ export declare class VaultClient {
|
|
|
35
39
|
vaultDepositor: any;
|
|
36
40
|
slot: number;
|
|
37
41
|
}>;
|
|
42
|
+
getVaultProtocolAddress(vault: PublicKey): PublicKey;
|
|
43
|
+
getVaultProtocol(vaultProtocol: PublicKey): Promise<VaultProtocol>;
|
|
44
|
+
getVaultProtocolAndSlot(vaultProtocol: PublicKey): Promise<{
|
|
45
|
+
vaultProtocol: VaultProtocol;
|
|
46
|
+
slot: number;
|
|
47
|
+
}>;
|
|
38
48
|
getAllVaultDepositorsWithNoWithdrawRequest(vault: PublicKey): Promise<ProgramAccount<VaultDepositor>[]>;
|
|
39
49
|
getAllVaultDepositors(vault: PublicKey): Promise<ProgramAccount<VaultDepositor>[]>;
|
|
40
50
|
getSubscribedVaultUser(vaultDriftUserAccountPubKey: PublicKey): Promise<import("@drift-labs/sdk").User>;
|
|
41
51
|
/**
|
|
42
52
|
*
|
|
43
53
|
* @param vault pubkey
|
|
54
|
+
* @param factorUnrealizedPNL add unrealized pnl to net balance
|
|
44
55
|
* @returns vault equity, in USDC
|
|
45
56
|
*/
|
|
46
57
|
calculateVaultEquity(params: {
|
|
47
58
|
address?: PublicKey;
|
|
48
59
|
vault?: Vault;
|
|
60
|
+
factorUnrealizedPNL?: boolean;
|
|
49
61
|
}): Promise<BN>;
|
|
50
62
|
/**
|
|
51
63
|
*
|
|
52
64
|
* @param vault pubkey
|
|
53
|
-
* @
|
|
65
|
+
* @param factorUnrealizedPNL add unrealized pnl to existing equity
|
|
66
|
+
* @returns total vault equity, in spot deposit asset
|
|
54
67
|
*/
|
|
55
68
|
calculateVaultEquityInDepositAsset(params: {
|
|
56
69
|
address?: PublicKey;
|
|
57
70
|
vault?: Vault;
|
|
71
|
+
factorUnrealizedPNL?: boolean;
|
|
72
|
+
}): Promise<BN>;
|
|
73
|
+
/**
|
|
74
|
+
* @param params
|
|
75
|
+
* @returns vault depositor equity, in spot market value (which is usually USDC)
|
|
76
|
+
*/
|
|
77
|
+
calculateWithdrawableVaultDepositorEquity(params: {
|
|
78
|
+
vaultDepositorAddress?: PublicKey;
|
|
79
|
+
vaultDepositor?: VaultDepositor;
|
|
80
|
+
vaultAddress?: PublicKey;
|
|
81
|
+
vault?: Vault;
|
|
82
|
+
}): Promise<BN>;
|
|
83
|
+
calculateWithdrawableVaultDepositorEquityInDepositAsset(params: {
|
|
84
|
+
vaultDepositorAddress?: PublicKey;
|
|
85
|
+
vaultDepositor?: VaultDepositor;
|
|
86
|
+
vaultAddress?: PublicKey;
|
|
87
|
+
vault?: Vault;
|
|
88
|
+
}): Promise<BN>;
|
|
89
|
+
calculateVaultProtocolEquity(params: {
|
|
90
|
+
vault: PublicKey;
|
|
58
91
|
}): Promise<BN>;
|
|
59
92
|
initializeVault(params: {
|
|
60
93
|
name: number[];
|
|
@@ -66,6 +99,7 @@ export declare class VaultClient {
|
|
|
66
99
|
profitShare: number;
|
|
67
100
|
hurdleRate: number;
|
|
68
101
|
permissioned: boolean;
|
|
102
|
+
vaultProtocol?: VaultProtocolParams;
|
|
69
103
|
}): Promise<TransactionSignature>;
|
|
70
104
|
/**
|
|
71
105
|
* Updates the delegate address for a vault. The delegate address will be allowed to trade
|
|
@@ -78,7 +112,7 @@ export declare class VaultClient {
|
|
|
78
112
|
/**
|
|
79
113
|
* Updates the vault margin trading status.
|
|
80
114
|
* @param vault vault address to update
|
|
81
|
-
* @param
|
|
115
|
+
* @param enabled whether to enable margin trading
|
|
82
116
|
* @returns
|
|
83
117
|
*/
|
|
84
118
|
updateMarginTradingEnabled(vault: PublicKey, enabled: boolean): Promise<TransactionSignature>;
|
|
@@ -152,6 +186,8 @@ export declare class VaultClient {
|
|
|
152
186
|
spotMarketIndex: number;
|
|
153
187
|
bump: number;
|
|
154
188
|
permissioned: boolean;
|
|
189
|
+
vaultProtocol: boolean;
|
|
190
|
+
padding1: number[];
|
|
155
191
|
padding: BN[];
|
|
156
192
|
};
|
|
157
193
|
accounts: {
|
|
@@ -168,6 +204,15 @@ export declare class VaultClient {
|
|
|
168
204
|
};
|
|
169
205
|
remainingAccounts: import("@solana/web3.js").AccountMeta[];
|
|
170
206
|
}>;
|
|
207
|
+
/**
|
|
208
|
+
* Creates a transaction to deposit funds into the specified vault.
|
|
209
|
+
* Uses the associated token account of the vault depositor authority and spot market mint,
|
|
210
|
+
* and assumes it exists before calling this function.
|
|
211
|
+
* @param vaultDepositor
|
|
212
|
+
* @param amount
|
|
213
|
+
* @param initVaultDepositor If true, will initialize the vault depositor account
|
|
214
|
+
* @returns transaction
|
|
215
|
+
*/
|
|
171
216
|
createDepositTx(vaultDepositor: PublicKey, amount: BN, initVaultDepositor?: {
|
|
172
217
|
authority: PublicKey;
|
|
173
218
|
vault: PublicKey;
|
|
@@ -177,6 +222,7 @@ export declare class VaultClient {
|
|
|
177
222
|
* @param vaultDepositor
|
|
178
223
|
* @param amount
|
|
179
224
|
* @param initVaultDepositor If true, will initialize the vault depositor account
|
|
225
|
+
* @param txParams
|
|
180
226
|
* @returns
|
|
181
227
|
*/
|
|
182
228
|
deposit(vaultDepositor: PublicKey, amount: BN, initVaultDepositor?: {
|
|
@@ -214,4 +260,7 @@ export declare class VaultClient {
|
|
|
214
260
|
* @returns
|
|
215
261
|
*/
|
|
216
262
|
initializeCompetitor(vault: PublicKey, competitionsClient: CompetitionsClient, competitionName: string): Promise<TransactionSignature>;
|
|
263
|
+
protocolRequestWithdraw(vault: PublicKey, amount: BN, withdrawUnit: WithdrawUnit): Promise<TransactionSignature>;
|
|
264
|
+
protocolCancelWithdrawRequest(vault: PublicKey): Promise<TransactionSignature>;
|
|
265
|
+
protocolWithdraw(vault: PublicKey): Promise<TransactionSignature>;
|
|
217
266
|
}
|