@drift-labs/vaults-sdk 0.1.0
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/.env.example +2 -0
- package/README.md +58 -0
- package/cli/cli.ts +105 -0
- package/cli/commands/applyProfitShare.ts +48 -0
- package/cli/commands/deposit.ts +35 -0
- package/cli/commands/index.ts +13 -0
- package/cli/commands/initVault.ts +61 -0
- package/cli/commands/initVaultDepositor.ts +43 -0
- package/cli/commands/listDepositorsForVault.ts +33 -0
- package/cli/commands/managerCancelWithdraw.ts +25 -0
- package/cli/commands/managerDeposit.ts +34 -0
- package/cli/commands/managerRequestWithdraw.ts +27 -0
- package/cli/commands/managerUpdateVault.ts +36 -0
- package/cli/commands/managerWithdraw.ts +25 -0
- package/cli/commands/requestWithdraw.ts +29 -0
- package/cli/commands/vaultDeposit.ts +43 -0
- package/cli/commands/vaultWithdraw.ts +43 -0
- package/cli/commands/viewVault.ts +30 -0
- package/cli/commands/viewVaultDepositor.ts +37 -0
- package/cli/commands/withdraw.ts +25 -0
- package/cli/utils.ts +119 -0
- package/lib/accountSubscribers/index.d.ts +2 -0
- package/lib/accountSubscribers/index.js +14 -0
- package/lib/accountSubscribers/pollingVaultDepositorSubscriber.d.ts +7 -0
- package/lib/accountSubscribers/pollingVaultDepositorSubscriber.js +44 -0
- package/lib/accountSubscribers/pollingVaultSubscriber.d.ts +7 -0
- package/lib/accountSubscribers/pollingVaultSubscriber.js +44 -0
- package/lib/accountSubscribers/pollingVaultsProgramAccountSubscriber.d.ts +28 -0
- package/lib/accountSubscribers/pollingVaultsProgramAccountSubscriber.js +68 -0
- package/lib/accounts/index.d.ts +2 -0
- package/lib/accounts/index.js +14 -0
- package/lib/accounts/vaultAccount.d.ts +15 -0
- package/lib/accounts/vaultAccount.js +53 -0
- package/lib/accounts/vaultDepositorAccount.d.ts +18 -0
- package/lib/accounts/vaultDepositorAccount.js +45 -0
- package/lib/accounts/vaultsProgramAccount.d.ts +13 -0
- package/lib/accounts/vaultsProgramAccount.js +25 -0
- package/lib/addresses.d.ts +4 -0
- package/lib/addresses.js +46 -0
- package/lib/constants/index.d.ts +3 -0
- package/lib/constants/index.js +5 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.js +21 -0
- package/lib/name.d.ts +3 -0
- package/lib/name.js +19 -0
- package/lib/parsers/index.d.ts +1 -0
- package/lib/parsers/index.js +13 -0
- package/lib/parsers/logParser.d.ts +14 -0
- package/lib/parsers/logParser.js +21 -0
- package/lib/types/drift_vaults.d.ts +1475 -0
- package/lib/types/drift_vaults.js +1477 -0
- package/lib/types/types.d.ts +137 -0
- package/lib/types/types.js +20 -0
- package/lib/utils.d.ts +7 -0
- package/lib/utils.js +43 -0
- package/lib/vaultClient.d.ts +100 -0
- package/lib/vaultClient.js +596 -0
- package/package.json +29 -0
- package/src/accountSubscribers/index.ts +2 -0
- package/src/accountSubscribers/pollingVaultDepositorSubscriber.ts +68 -0
- package/src/accountSubscribers/pollingVaultSubscriber.ts +62 -0
- package/src/accountSubscribers/pollingVaultsProgramAccountSubscriber.ts +111 -0
- package/src/accounts/index.ts +2 -0
- package/src/accounts/vaultAccount.ts +86 -0
- package/src/accounts/vaultDepositorAccount.ts +67 -0
- package/src/accounts/vaultsProgramAccount.ts +37 -0
- package/src/addresses.ts +43 -0
- package/src/constants/index.ts +3 -0
- package/src/idl/drift_vaults.json +1547 -0
- package/src/index.ts +9 -0
- package/src/name.ts +18 -0
- package/src/parsers/index.ts +1 -0
- package/src/parsers/logParser.ts +28 -0
- package/src/types/drift_vaults.ts +2949 -0
- package/src/types/types.ts +158 -0
- package/src/utils.ts +33 -0
- package/src/vaultClient.ts +904 -0
- package/tsconfig.json +13 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { BN, DataAndSlot, Event } from '@drift-labs/sdk';
|
|
2
|
+
import { PublicKey } from '@solana/web3.js';
|
|
3
|
+
import { EventEmitter } from 'events';
|
|
4
|
+
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
5
|
+
|
|
6
|
+
export const VAULT_PROGRAM_ID = new PublicKey(
|
|
7
|
+
'vAuLTsyrvSfZRuRB3XgvkPwNGgYSs9YRYymVebLKoxR'
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
export class WithdrawUnit {
|
|
11
|
+
static readonly SHARES = { shares: {} };
|
|
12
|
+
static readonly TOKEN = { token: {} };
|
|
13
|
+
static readonly SHARES_PERCENT = { sharesPercent: {} };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type WithdrawRequest = {
|
|
17
|
+
shares: BN;
|
|
18
|
+
value: BN;
|
|
19
|
+
ts: BN;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// Vault program accounts
|
|
23
|
+
|
|
24
|
+
export type Vault = {
|
|
25
|
+
name: number[];
|
|
26
|
+
pubkey: PublicKey;
|
|
27
|
+
manager: PublicKey;
|
|
28
|
+
tokenAccount: PublicKey;
|
|
29
|
+
userStats: PublicKey;
|
|
30
|
+
user: PublicKey;
|
|
31
|
+
delegate: PublicKey;
|
|
32
|
+
liquidationDelegate: PublicKey;
|
|
33
|
+
userShares: BN;
|
|
34
|
+
totalShares: BN;
|
|
35
|
+
lastFeeUpdateTs: BN;
|
|
36
|
+
liquidationStartTs: BN;
|
|
37
|
+
redeemPeriod: BN;
|
|
38
|
+
totalWithdrawRequested: BN;
|
|
39
|
+
maxTokens: BN;
|
|
40
|
+
sharesBase: number;
|
|
41
|
+
managementFee: BN;
|
|
42
|
+
initTs: BN;
|
|
43
|
+
netDeposits: BN;
|
|
44
|
+
managerNetDeposits: BN;
|
|
45
|
+
totalDeposits: BN;
|
|
46
|
+
totalWithdraws: BN;
|
|
47
|
+
managerTotalDeposits: BN;
|
|
48
|
+
managerTotalWithdraws: BN;
|
|
49
|
+
managerTotalFee: BN;
|
|
50
|
+
managerTotalProfitShare: BN;
|
|
51
|
+
minDepositAmount: BN;
|
|
52
|
+
profitShare: number;
|
|
53
|
+
hurdleRate: number;
|
|
54
|
+
spotMarketIndex: number;
|
|
55
|
+
bump: number;
|
|
56
|
+
permissioned: boolean;
|
|
57
|
+
lastManagerWithdrawRequest: WithdrawRequest;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export type VaultDepositor = {
|
|
61
|
+
vault: PublicKey;
|
|
62
|
+
pubkey: PublicKey;
|
|
63
|
+
authority: PublicKey;
|
|
64
|
+
vaultShares: BN;
|
|
65
|
+
// lastWithdrawRequestShares: BN;
|
|
66
|
+
// lastWithdrawRequestValue: BN;
|
|
67
|
+
// lastWithdrawRequestTs: BN;
|
|
68
|
+
lastWithdrawRequest: WithdrawRequest;
|
|
69
|
+
lastValidTs: BN;
|
|
70
|
+
netDeposits: BN;
|
|
71
|
+
totalDeposits: BN;
|
|
72
|
+
totalWithdraws: BN;
|
|
73
|
+
cumulativeProfitShareAmount: BN;
|
|
74
|
+
vaultSharesBase: number;
|
|
75
|
+
profitShareFeePaid: BN;
|
|
76
|
+
padding: number[];
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export type VaultsProgramAccountBaseEvents = {
|
|
80
|
+
update: void;
|
|
81
|
+
error: (e: Error) => void;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export type VaultDepositorAccountEvents = {
|
|
85
|
+
vaultDepositorUpdate: (payload: VaultDepositor) => void;
|
|
86
|
+
} & VaultsProgramAccountBaseEvents;
|
|
87
|
+
|
|
88
|
+
export type VaultAccountEvents = {
|
|
89
|
+
vaultUpdate: (payload: Vault) => void;
|
|
90
|
+
} & VaultsProgramAccountBaseEvents;
|
|
91
|
+
|
|
92
|
+
export interface VaultsProgramAccountSubscriber<
|
|
93
|
+
Account,
|
|
94
|
+
AccountEvents extends VaultsProgramAccountBaseEvents
|
|
95
|
+
> {
|
|
96
|
+
eventEmitter: StrictEventEmitter<EventEmitter, AccountEvents>;
|
|
97
|
+
isSubscribed: boolean;
|
|
98
|
+
|
|
99
|
+
subscribe(): Promise<boolean>;
|
|
100
|
+
fetch(): Promise<void>;
|
|
101
|
+
updateData(account: Account, slot: number): void;
|
|
102
|
+
unsubscribe(): Promise<void>;
|
|
103
|
+
getAccountAndSlot(): DataAndSlot<Account>;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export type VaultAccountSubscriber = VaultsProgramAccountSubscriber<
|
|
107
|
+
Vault,
|
|
108
|
+
VaultAccountEvents
|
|
109
|
+
>;
|
|
110
|
+
|
|
111
|
+
export type VaultDepositorAccountSubscriber = VaultsProgramAccountSubscriber<
|
|
112
|
+
VaultDepositor,
|
|
113
|
+
VaultDepositorAccountEvents
|
|
114
|
+
>;
|
|
115
|
+
|
|
116
|
+
// Logs/Records
|
|
117
|
+
|
|
118
|
+
export class VaultDepositorAction {
|
|
119
|
+
static readonly DEPOSIT = { deposit: {} };
|
|
120
|
+
static readonly WITHDRAW = { withdraw: {} };
|
|
121
|
+
static readonly WITHDRAW_REQUEST = { withdrawRequest: {} };
|
|
122
|
+
static readonly CANCEL_WITHDRAW_REQUEST = { cancelWithdrawRequest: {} };
|
|
123
|
+
static readonly FEE_PAYMENT = { feePayment: {} };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export type VaultDepositorRecord = {
|
|
127
|
+
ts: BN;
|
|
128
|
+
|
|
129
|
+
vault: PublicKey;
|
|
130
|
+
depositorAuthority: PublicKey;
|
|
131
|
+
action: VaultDepositorAction;
|
|
132
|
+
amount: BN;
|
|
133
|
+
|
|
134
|
+
spotMarketIndex: number;
|
|
135
|
+
vaultSharesBefore: BN;
|
|
136
|
+
vaultSharesAfter: BN;
|
|
137
|
+
vaultEquityBefore: BN;
|
|
138
|
+
|
|
139
|
+
userVaultSharesBefore: BN;
|
|
140
|
+
totalVaultSharesBefore: BN;
|
|
141
|
+
|
|
142
|
+
userVaultSharesAfter: BN;
|
|
143
|
+
totalVaultSharesAfter: BN;
|
|
144
|
+
|
|
145
|
+
profitShare: BN;
|
|
146
|
+
managementFee: BN;
|
|
147
|
+
managementFeeShares: BN;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export type VaultsEventMap = {
|
|
151
|
+
VaultDepositorRecord: Event<VaultDepositorRecord>;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export type EventType = keyof VaultsEventMap;
|
|
155
|
+
export type WrappedEvent<Type extends EventType> = VaultsEventMap[Type] & {
|
|
156
|
+
eventType: Type;
|
|
157
|
+
};
|
|
158
|
+
export type WrappedEvents = WrappedEvent<EventType>[];
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { AnchorProvider } from '@coral-xyz/anchor';
|
|
2
|
+
import { DriftClient, IWallet } from '@drift-labs/sdk';
|
|
3
|
+
import { Connection } from '@solana/web3.js';
|
|
4
|
+
import { DriftVaults, IDL } from './types/drift_vaults';
|
|
5
|
+
import { VaultClient } from './vaultClient';
|
|
6
|
+
import * as anchor from '@coral-xyz/anchor';
|
|
7
|
+
import { VAULT_PROGRAM_ID } from './types/types';
|
|
8
|
+
|
|
9
|
+
export const getDriftVaultProgram = (
|
|
10
|
+
connection: Connection,
|
|
11
|
+
wallet: IWallet
|
|
12
|
+
): anchor.Program<DriftVaults> => {
|
|
13
|
+
const provider = new AnchorProvider(connection, wallet, {});
|
|
14
|
+
anchor.setProvider(provider);
|
|
15
|
+
const vaultProgram = new anchor.Program(IDL, VAULT_PROGRAM_ID, provider);
|
|
16
|
+
|
|
17
|
+
return vaultProgram;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const getVaultClient = (
|
|
21
|
+
connection: Connection,
|
|
22
|
+
wallet: IWallet,
|
|
23
|
+
driftClient: DriftClient
|
|
24
|
+
): VaultClient => {
|
|
25
|
+
const vaultProgram = getDriftVaultProgram(connection, wallet);
|
|
26
|
+
|
|
27
|
+
const vaultClient = new VaultClient({
|
|
28
|
+
driftClient,
|
|
29
|
+
program: vaultProgram,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
return vaultClient;
|
|
33
|
+
};
|