@drift-labs/vaults-sdk 0.1.415 → 0.1.417
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 +116 -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 +450 -24
- package/lib/types/drift_vaults.js +450 -24
- package/lib/types/types.d.ts +66 -1
- package/lib/vaultClient.d.ts +53 -5
- package/lib/vaultClient.js +407 -42
- package/package.json +2 -2
- package/src/accounts/vaultAccount.ts +164 -3
- package/src/addresses.ts +13 -0
- package/src/idl/drift_vaults.json +453 -24
- package/src/math/vaultDepositor.ts +36 -4
- package/src/types/drift_vaults.ts +907 -55
- package/src/types/types.ts +79 -1
- package/src/vaultClient.ts +540 -42
package/lib/types/types.d.ts
CHANGED
|
@@ -19,6 +19,36 @@ 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
|
+
vaultProtocol: VaultProtocolParams | null;
|
|
33
|
+
};
|
|
34
|
+
export type VaultProtocolParams = {
|
|
35
|
+
protocol: PublicKey;
|
|
36
|
+
protocolFee: BN;
|
|
37
|
+
protocolProfitShare: number;
|
|
38
|
+
};
|
|
39
|
+
export type UpdateVaultParams = {
|
|
40
|
+
redeemPeriod: BN | null;
|
|
41
|
+
maxTokens: BN | null;
|
|
42
|
+
minDepositAmount: BN | null;
|
|
43
|
+
managementFee: BN | null;
|
|
44
|
+
profitShare: number | null;
|
|
45
|
+
hurdleRate: number | null;
|
|
46
|
+
permissioned: boolean | null;
|
|
47
|
+
};
|
|
48
|
+
export type UpdateVaultProtocolParams = {
|
|
49
|
+
protocolFee: BN | null;
|
|
50
|
+
protocolProfitShare: number | null;
|
|
51
|
+
};
|
|
22
52
|
export type Vault = {
|
|
23
53
|
name: number[];
|
|
24
54
|
pubkey: PublicKey;
|
|
@@ -53,6 +83,7 @@ export type Vault = {
|
|
|
53
83
|
bump: number;
|
|
54
84
|
permissioned: boolean;
|
|
55
85
|
lastManagerWithdrawRequest: WithdrawRequest;
|
|
86
|
+
vaultProtocol: PublicKey;
|
|
56
87
|
};
|
|
57
88
|
export type VaultDepositor = {
|
|
58
89
|
vault: PublicKey;
|
|
@@ -67,7 +98,20 @@ export type VaultDepositor = {
|
|
|
67
98
|
cumulativeProfitShareAmount: BN;
|
|
68
99
|
vaultSharesBase: number;
|
|
69
100
|
profitShareFeePaid: BN;
|
|
70
|
-
|
|
101
|
+
padding1: number;
|
|
102
|
+
padding: BN[];
|
|
103
|
+
};
|
|
104
|
+
export type VaultProtocol = {
|
|
105
|
+
protocol: PublicKey;
|
|
106
|
+
protocolProfitAndFeeShares: BN;
|
|
107
|
+
protocolFee: BN;
|
|
108
|
+
protocolTotalWithdraws: BN;
|
|
109
|
+
protocolTotalFee: BN;
|
|
110
|
+
protocolTotalProfitShare: BN;
|
|
111
|
+
lastProtocolWithdrawRequest: WithdrawRequest;
|
|
112
|
+
protocolProfitShare: number;
|
|
113
|
+
bump: number;
|
|
114
|
+
version: number;
|
|
71
115
|
};
|
|
72
116
|
export type VaultsProgramAccountBaseEvents = {
|
|
73
117
|
update: void;
|
|
@@ -125,6 +169,27 @@ export type VaultDepositorRecord = {
|
|
|
125
169
|
managementFee: BN;
|
|
126
170
|
managementFeeShares: BN;
|
|
127
171
|
};
|
|
172
|
+
export type VaultDepositorV1Record = {
|
|
173
|
+
ts: BN;
|
|
174
|
+
vault: PublicKey;
|
|
175
|
+
depositorAuthority: PublicKey;
|
|
176
|
+
action: VaultDepositorAction;
|
|
177
|
+
amount: BN;
|
|
178
|
+
spotMarketIndex: number;
|
|
179
|
+
vaultSharesBefore: BN;
|
|
180
|
+
vaultSharesAfter: BN;
|
|
181
|
+
vaultEquityBefore: BN;
|
|
182
|
+
userVaultSharesBefore: BN;
|
|
183
|
+
totalVaultSharesBefore: BN;
|
|
184
|
+
userVaultSharesAfter: BN;
|
|
185
|
+
totalVaultSharesAfter: BN;
|
|
186
|
+
protocolProfitShare: BN;
|
|
187
|
+
protocolFee: BN;
|
|
188
|
+
protocolFeeShares: BN;
|
|
189
|
+
managerProfitShare: BN;
|
|
190
|
+
managementFee: BN;
|
|
191
|
+
managementFeeShares: BN;
|
|
192
|
+
};
|
|
128
193
|
export type VaultsEventMap = {
|
|
129
194
|
VaultDepositorRecord: Event<VaultDepositorRecord>;
|
|
130
195
|
};
|
package/lib/vaultClient.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { BN, DriftClient, UserMap } from '@drift-labs/sdk';
|
|
|
2
2
|
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
|
-
import { AddressLookupTableAccount, PublicKey, TransactionInstruction, TransactionSignature, VersionedTransaction } from '@solana/web3.js';
|
|
6
|
-
import { Vault, VaultDepositor, WithdrawUnit } from './types/types';
|
|
5
|
+
import { AccountMeta, AddressLookupTableAccount, PublicKey, TransactionInstruction, TransactionSignature, VersionedTransaction } from '@solana/web3.js';
|
|
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,7 @@ export declare class VaultClient {
|
|
|
152
186
|
spotMarketIndex: number;
|
|
153
187
|
bump: number;
|
|
154
188
|
permissioned: boolean;
|
|
189
|
+
vaultProtocol: PublicKey;
|
|
155
190
|
padding: BN[];
|
|
156
191
|
};
|
|
157
192
|
accounts: {
|
|
@@ -166,8 +201,17 @@ export declare class VaultClient {
|
|
|
166
201
|
driftProgram: PublicKey;
|
|
167
202
|
tokenProgram: PublicKey;
|
|
168
203
|
};
|
|
169
|
-
remainingAccounts:
|
|
204
|
+
remainingAccounts: AccountMeta[];
|
|
170
205
|
}>;
|
|
206
|
+
/**
|
|
207
|
+
* Creates a transaction to deposit funds into the specified vault.
|
|
208
|
+
* Uses the associated token account of the vault depositor authority and spot market mint,
|
|
209
|
+
* and assumes it exists before calling this function.
|
|
210
|
+
* @param vaultDepositor
|
|
211
|
+
* @param amount
|
|
212
|
+
* @param initVaultDepositor If true, will initialize the vault depositor account
|
|
213
|
+
* @returns transaction
|
|
214
|
+
*/
|
|
171
215
|
createDepositTx(vaultDepositor: PublicKey, amount: BN, initVaultDepositor?: {
|
|
172
216
|
authority: PublicKey;
|
|
173
217
|
vault: PublicKey;
|
|
@@ -177,6 +221,7 @@ export declare class VaultClient {
|
|
|
177
221
|
* @param vaultDepositor
|
|
178
222
|
* @param amount
|
|
179
223
|
* @param initVaultDepositor If true, will initialize the vault depositor account
|
|
224
|
+
* @param txParams
|
|
180
225
|
* @returns
|
|
181
226
|
*/
|
|
182
227
|
deposit(vaultDepositor: PublicKey, amount: BN, initVaultDepositor?: {
|
|
@@ -214,4 +259,7 @@ export declare class VaultClient {
|
|
|
214
259
|
* @returns
|
|
215
260
|
*/
|
|
216
261
|
initializeCompetitor(vault: PublicKey, competitionsClient: CompetitionsClient, competitionName: string): Promise<TransactionSignature>;
|
|
262
|
+
protocolRequestWithdraw(vault: PublicKey, amount: BN, withdrawUnit: WithdrawUnit): Promise<TransactionSignature>;
|
|
263
|
+
protocolCancelWithdrawRequest(vault: PublicKey): Promise<TransactionSignature>;
|
|
264
|
+
protocolWithdraw(vault: PublicKey): Promise<TransactionSignature>;
|
|
217
265
|
}
|