@drift-labs/vaults-sdk 0.6.30 → 0.6.31
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/cli/cli.ts +31 -2
- package/cli/commands/adminDeleteFeeUpdate.ts +73 -0
- package/cli/commands/adminInitFeeUpdate.ts +73 -0
- package/cli/commands/applyProfitShare.ts +5 -2
- package/cli/commands/decodeLogs.ts +3 -2
- package/cli/commands/deposit.ts +2 -2
- package/cli/commands/forceWithdrawAll.ts +1 -1
- package/cli/commands/index.ts +2 -0
- package/cli/commands/initVault.ts +2 -2
- package/cli/commands/managerApplyProfitShare.ts +1 -1
- package/cli/commands/managerCancelWithdraw.ts +1 -1
- package/cli/commands/managerDeposit.ts +1 -1
- package/cli/commands/managerRequestWithdraw.ts +2 -2
- package/cli/commands/managerUpdateFees.ts +121 -0
- package/cli/commands/managerUpdateMarginTradingEnabled.ts +1 -1
- package/cli/commands/managerUpdatePoolId.ts +1 -1
- package/cli/commands/managerUpdateVault.ts +13 -2
- package/cli/commands/managerUpdateVaultDelegate.ts +1 -1
- package/cli/commands/managerUpdateVaultManager.ts +1 -1
- package/cli/commands/managerWithdraw.ts +1 -1
- package/cli/commands/requestWithdraw.ts +1 -1
- package/cli/commands/viewVault.ts +12 -1
- package/cli/commands/withdraw.ts +1 -1
- package/cli/utils.ts +12 -3
- package/lib/addresses.d.ts +1 -0
- package/lib/addresses.d.ts.map +1 -1
- package/lib/addresses.js +7 -0
- package/lib/constants/index.d.ts +2 -0
- package/lib/constants/index.d.ts.map +1 -1
- package/lib/constants/index.js +3 -1
- package/lib/types/drift_vaults.d.ts +275 -1
- package/lib/types/drift_vaults.d.ts.map +1 -1
- package/lib/types/drift_vaults.js +275 -1
- package/lib/types/types.d.ts +33 -0
- package/lib/types/types.d.ts.map +1 -1
- package/lib/types/types.js +11 -1
- package/lib/vaultClient.d.ts +22 -1
- package/lib/vaultClient.d.ts.map +1 -1
- package/lib/vaultClient.js +115 -22
- package/package.json +1 -1
- package/src/addresses.ts +13 -0
- package/src/constants/index.ts +5 -0
- package/src/idl/drift_vaults.json +281 -1
- package/src/types/drift_vaults.ts +550 -2
- package/src/types/types.ts +33 -0
- package/src/vaultClient.ts +229 -22
package/lib/vaultClient.js
CHANGED
|
@@ -6,9 +6,11 @@ const anchor_1 = require("@coral-xyz/anchor");
|
|
|
6
6
|
const addresses_1 = require("./addresses");
|
|
7
7
|
const web3_js_1 = require("@solana/web3.js");
|
|
8
8
|
const spl_token_1 = require("@solana/spl-token");
|
|
9
|
+
const types_1 = require("./types/types");
|
|
9
10
|
const bytes_1 = require("@coral-xyz/anchor/dist/cjs/utils/bytes");
|
|
10
11
|
const math_1 = require("./math");
|
|
11
12
|
const utils_1 = require("./utils");
|
|
13
|
+
const constants_1 = require("./constants");
|
|
12
14
|
class VaultClient {
|
|
13
15
|
constructor({ driftClient, program, metaplex,
|
|
14
16
|
// @deprecated, no longer used
|
|
@@ -31,7 +33,7 @@ class VaultClient {
|
|
|
31
33
|
this.vaultUsers = new sdk_1.UserMap(userMapConfig);
|
|
32
34
|
}
|
|
33
35
|
}
|
|
34
|
-
getRemainingAccountsForUser(userAccounts, writableSpotMarketIndexes, vaultAccount, userStats) {
|
|
36
|
+
getRemainingAccountsForUser(userAccounts, writableSpotMarketIndexes, vaultAccount, userStats, skipVaultProtocol = false, skipFuelOverflow = false, skipFeeUpdate = false) {
|
|
35
37
|
const remainingAccounts = this.driftClient.getRemainingAccounts({
|
|
36
38
|
userAccounts,
|
|
37
39
|
writableSpotMarketIndexes,
|
|
@@ -39,7 +41,17 @@ class VaultClient {
|
|
|
39
41
|
const hasVaultProtocol = vaultAccount.vaultProtocol === true;
|
|
40
42
|
const hasFuelOverflow = (userStats.fuelOverflowStatus & sdk_1.FuelOverflowStatus.Exists) ===
|
|
41
43
|
sdk_1.FuelOverflowStatus.Exists;
|
|
42
|
-
|
|
44
|
+
const hasFeeUpdate = (vaultAccount.feeUpdateStatus & types_1.FeeUpdateStatus.PendingFeeUpdate) ===
|
|
45
|
+
types_1.FeeUpdateStatus.PendingFeeUpdate;
|
|
46
|
+
if (hasFeeUpdate && !skipFeeUpdate) {
|
|
47
|
+
const feeUpdate = (0, addresses_1.getFeeUpdateAddressSync)(this.program.programId, vaultAccount.pubkey);
|
|
48
|
+
remainingAccounts.push({
|
|
49
|
+
pubkey: feeUpdate,
|
|
50
|
+
isSigner: false,
|
|
51
|
+
isWritable: true,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
if (hasFuelOverflow && !skipFuelOverflow) {
|
|
43
55
|
const fuelOverflow = (0, sdk_1.getFuelOverflowAccountPublicKey)(this.driftClient.program.programId, vaultAccount.pubkey);
|
|
44
56
|
remainingAccounts.push({
|
|
45
57
|
pubkey: fuelOverflow,
|
|
@@ -47,7 +59,7 @@ class VaultClient {
|
|
|
47
59
|
isWritable: false,
|
|
48
60
|
});
|
|
49
61
|
}
|
|
50
|
-
if (hasVaultProtocol) {
|
|
62
|
+
if (hasVaultProtocol && !skipVaultProtocol) {
|
|
51
63
|
const vaultProtocol = this.getVaultProtocolAddress(vaultAccount.pubkey);
|
|
52
64
|
remainingAccounts.push({
|
|
53
65
|
pubkey: vaultProtocol,
|
|
@@ -57,6 +69,16 @@ class VaultClient {
|
|
|
57
69
|
}
|
|
58
70
|
return remainingAccounts;
|
|
59
71
|
}
|
|
72
|
+
async checkIfAccountExists(account) {
|
|
73
|
+
try {
|
|
74
|
+
const accountInfo = await this.driftClient.connection.getAccountInfo(account);
|
|
75
|
+
return accountInfo != null;
|
|
76
|
+
}
|
|
77
|
+
catch (e) {
|
|
78
|
+
// Doesn't already exist
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
60
82
|
/**
|
|
61
83
|
* Unsubscribes from the vault users map. Call this to clean up any dangling promises.
|
|
62
84
|
*/
|
|
@@ -68,6 +90,9 @@ class VaultClient {
|
|
|
68
90
|
async getVault(vault) {
|
|
69
91
|
return await this.program.account.vault.fetch(vault);
|
|
70
92
|
}
|
|
93
|
+
async getFeeUpdate(feeUpdate) {
|
|
94
|
+
return await this.program.account.feeUpdate.fetch(feeUpdate);
|
|
95
|
+
}
|
|
71
96
|
async getVaultAndSlot(vault) {
|
|
72
97
|
const vaultAndSlot = await this.program.account.vault.fetchAndContext(vault);
|
|
73
98
|
return {
|
|
@@ -536,7 +561,7 @@ class VaultClient {
|
|
|
536
561
|
const user = await this.getSubscribedVaultUser(vaultAccount.user);
|
|
537
562
|
const userStatsKey = (0, sdk_1.getUserStatsAccountPublicKey)(this.driftClient.program.programId, vault);
|
|
538
563
|
const userStats = (await this.driftClient.program.account.userStats.fetch(userStatsKey));
|
|
539
|
-
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [vaultAccount.spotMarketIndex], vaultAccount, userStats);
|
|
564
|
+
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [vaultAccount.spotMarketIndex], vaultAccount, userStats, false, true, true);
|
|
540
565
|
const accounts = {
|
|
541
566
|
vault,
|
|
542
567
|
vaultTokenAccount: vaultAccount.tokenAccount,
|
|
@@ -571,7 +596,7 @@ class VaultClient {
|
|
|
571
596
|
const user = await this.getSubscribedVaultUser(vaultAccount.user);
|
|
572
597
|
const userStatsKey = (0, sdk_1.getUserStatsAccountPublicKey)(this.driftClient.program.programId, vault);
|
|
573
598
|
const userStats = (await this.driftClient.program.account.userStats.fetch(userStatsKey));
|
|
574
|
-
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [vaultAccount.spotMarketIndex], vaultAccount, userStats);
|
|
599
|
+
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [vaultAccount.spotMarketIndex], vaultAccount, userStats, false, true, true);
|
|
575
600
|
const accounts = {
|
|
576
601
|
vault,
|
|
577
602
|
driftUser: vaultAccount.user,
|
|
@@ -602,7 +627,7 @@ class VaultClient {
|
|
|
602
627
|
};
|
|
603
628
|
const user = await this.getSubscribedVaultUser(vaultAccount.user);
|
|
604
629
|
const userStats = (await this.driftClient.program.account.userStats.fetch(userStatsKey));
|
|
605
|
-
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [], vaultAccount, userStats);
|
|
630
|
+
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [], vaultAccount, userStats, false, true, true);
|
|
606
631
|
return this.program.instruction.mangerCancelWithdrawRequest({
|
|
607
632
|
accounts,
|
|
608
633
|
remainingAccounts,
|
|
@@ -617,7 +642,7 @@ class VaultClient {
|
|
|
617
642
|
const user = await this.getSubscribedVaultUser(vaultAccount.user);
|
|
618
643
|
const userStatsKey = (0, sdk_1.getUserStatsAccountPublicKey)(this.driftClient.program.programId, vault);
|
|
619
644
|
const userStats = (await this.driftClient.program.account.userStats.fetch(userStatsKey));
|
|
620
|
-
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [vaultAccount.spotMarketIndex], vaultAccount, userStats);
|
|
645
|
+
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [vaultAccount.spotMarketIndex], vaultAccount, userStats, false, false, false);
|
|
621
646
|
const spotMarket = this.driftClient.getSpotMarketAccount(vaultAccount.spotMarketIndex);
|
|
622
647
|
if (!spotMarket) {
|
|
623
648
|
throw new Error(`Spot market ${vaultAccount.spotMarketIndex} not found on driftClient`);
|
|
@@ -678,7 +703,7 @@ class VaultClient {
|
|
|
678
703
|
}
|
|
679
704
|
const userStatsKey = (0, sdk_1.getUserStatsAccountPublicKey)(this.driftClient.program.programId, vault);
|
|
680
705
|
const userStats = (await this.driftClient.program.account.userStats.fetch(userStatsKey));
|
|
681
|
-
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [vaultAccount.spotMarketIndex], vaultAccount, userStats);
|
|
706
|
+
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [vaultAccount.spotMarketIndex], vaultAccount, userStats, false, false, false);
|
|
682
707
|
const accounts = {
|
|
683
708
|
vault,
|
|
684
709
|
vaultDepositor,
|
|
@@ -705,7 +730,7 @@ class VaultClient {
|
|
|
705
730
|
}
|
|
706
731
|
const userStatsKey = (0, sdk_1.getUserStatsAccountPublicKey)(this.driftClient.program.programId, vault);
|
|
707
732
|
const userStats = (await this.driftClient.program.account.userStats.fetch(userStatsKey));
|
|
708
|
-
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [vaultAccount.spotMarketIndex], vaultAccount, userStats);
|
|
733
|
+
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [vaultAccount.spotMarketIndex], vaultAccount, userStats, false, true, true);
|
|
709
734
|
const accounts = {
|
|
710
735
|
vault,
|
|
711
736
|
tokenizedVaultDepositor,
|
|
@@ -735,7 +760,7 @@ class VaultClient {
|
|
|
735
760
|
}
|
|
736
761
|
const userStatsKey = (0, sdk_1.getUserStatsAccountPublicKey)(this.driftClient.program.programId, vault);
|
|
737
762
|
const userStats = (await this.driftClient.program.account.userStats.fetch(userStatsKey));
|
|
738
|
-
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [vaultAccount.spotMarketIndex], vaultAccount, userStats);
|
|
763
|
+
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [vaultAccount.spotMarketIndex], vaultAccount, userStats, false, true, true);
|
|
739
764
|
const accounts = {
|
|
740
765
|
vault,
|
|
741
766
|
vaultDepositor,
|
|
@@ -838,7 +863,7 @@ class VaultClient {
|
|
|
838
863
|
const user = await this.getSubscribedVaultUser(vaultAccount.user);
|
|
839
864
|
const userStatsKey = (0, sdk_1.getUserStatsAccountPublicKey)(this.driftClient.program.programId, vaultDepositorAccount.vault);
|
|
840
865
|
const userStats = (await this.driftClient.program.account.userStats.fetch(userStatsKey));
|
|
841
|
-
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [vaultAccount.spotMarketIndex], vaultAccount, userStats);
|
|
866
|
+
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [vaultAccount.spotMarketIndex], vaultAccount, userStats, false, true, true);
|
|
842
867
|
ixs.push(await this.program.methods
|
|
843
868
|
// anchor idl bug: https://github.com/coral-xyz/anchor/issues/2914
|
|
844
869
|
// @ts-ignore
|
|
@@ -870,7 +895,7 @@ class VaultClient {
|
|
|
870
895
|
const user = await this.getSubscribedVaultUser(vaultAccount.user);
|
|
871
896
|
const userStatsKey = (0, sdk_1.getUserStatsAccountPublicKey)(this.driftClient.program.programId, vaultDepositorAccount.vault);
|
|
872
897
|
const userStats = (await this.driftClient.program.account.userStats.fetch(userStatsKey));
|
|
873
|
-
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [vaultAccount.spotMarketIndex], vaultAccount, userStats);
|
|
898
|
+
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [vaultAccount.spotMarketIndex], vaultAccount, userStats, false, true, true);
|
|
874
899
|
return await this.program.methods
|
|
875
900
|
.redeemTokens(tokensToBurn)
|
|
876
901
|
.accounts({
|
|
@@ -912,7 +937,7 @@ class VaultClient {
|
|
|
912
937
|
const user = await this.getSubscribedVaultUser(vaultAccount.user);
|
|
913
938
|
const userStatsKey = (0, sdk_1.getUserStatsAccountPublicKey)(this.driftClient.program.programId, vaultPubKey);
|
|
914
939
|
const userStats = (await this.driftClient.program.account.userStats.fetch(userStatsKey));
|
|
915
|
-
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [vaultAccount.spotMarketIndex], vaultAccount, userStats);
|
|
940
|
+
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [vaultAccount.spotMarketIndex], vaultAccount, userStats, false, false, false);
|
|
916
941
|
const driftStateKey = await this.driftClient.getStatePublicKey();
|
|
917
942
|
const spotMarket = this.driftClient.getSpotMarketAccount(vaultAccount.spotMarketIndex);
|
|
918
943
|
if (!spotMarket) {
|
|
@@ -995,7 +1020,7 @@ class VaultClient {
|
|
|
995
1020
|
const user = await this.getSubscribedVaultUser(vaultAccount.user);
|
|
996
1021
|
const userStatsKey = (0, sdk_1.getUserStatsAccountPublicKey)(this.driftClient.program.programId, vaultDepositorAccount.vault);
|
|
997
1022
|
const userStats = (await this.driftClient.program.account.userStats.fetch(userStatsKey));
|
|
998
|
-
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [vaultAccount.spotMarketIndex], vaultAccount, userStats);
|
|
1023
|
+
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [vaultAccount.spotMarketIndex], vaultAccount, userStats, false, false, false);
|
|
999
1024
|
const accounts = {
|
|
1000
1025
|
vault: vaultDepositorAccount.vault,
|
|
1001
1026
|
vaultDepositor,
|
|
@@ -1027,7 +1052,7 @@ class VaultClient {
|
|
|
1027
1052
|
const user = await this.getSubscribedVaultUser(vaultAccount.user);
|
|
1028
1053
|
const userStatsKey = (0, sdk_1.getUserStatsAccountPublicKey)(this.driftClient.program.programId, vaultDepositorAccount.vault);
|
|
1029
1054
|
const userStats = (await this.driftClient.program.account.userStats.fetch(userStatsKey));
|
|
1030
|
-
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [vaultAccount.spotMarketIndex], vaultAccount, userStats);
|
|
1055
|
+
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [vaultAccount.spotMarketIndex], vaultAccount, userStats, false, false, false);
|
|
1031
1056
|
const driftStateKey = await this.driftClient.getStatePublicKey();
|
|
1032
1057
|
const spotMarket = this.driftClient.getSpotMarketAccount(vaultAccount.spotMarketIndex);
|
|
1033
1058
|
if (!spotMarket) {
|
|
@@ -1090,7 +1115,7 @@ class VaultClient {
|
|
|
1090
1115
|
const user = await this.getSubscribedVaultUser(vaultAccount.user);
|
|
1091
1116
|
const userStatsKey = (0, sdk_1.getUserStatsAccountPublicKey)(this.driftClient.program.programId, vaultDepositorAccount.vault);
|
|
1092
1117
|
const userStats = (await this.driftClient.program.account.userStats.fetch(userStatsKey));
|
|
1093
|
-
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [vaultAccount.spotMarketIndex], vaultAccount, userStats);
|
|
1118
|
+
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [vaultAccount.spotMarketIndex], vaultAccount, userStats, false, false, false);
|
|
1094
1119
|
if (vaultAccount.vaultProtocol) {
|
|
1095
1120
|
const vaultProtocol = this.getVaultProtocolAddress(vaultDepositorAccount.vault);
|
|
1096
1121
|
remainingAccounts.push({
|
|
@@ -1149,7 +1174,7 @@ class VaultClient {
|
|
|
1149
1174
|
};
|
|
1150
1175
|
const user = await this.getSubscribedVaultUser(vaultAccount.user);
|
|
1151
1176
|
const userStats = (await this.driftClient.program.account.userStats.fetch(userStatsKey));
|
|
1152
|
-
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [vaultAccount.spotMarketIndex], vaultAccount, userStats);
|
|
1177
|
+
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [vaultAccount.spotMarketIndex], vaultAccount, userStats, false, false, false);
|
|
1153
1178
|
if (this.cliMode) {
|
|
1154
1179
|
return [
|
|
1155
1180
|
await this.program.methods
|
|
@@ -1182,13 +1207,16 @@ class VaultClient {
|
|
|
1182
1207
|
return await this.createAndSendTxn([ix], txParams);
|
|
1183
1208
|
}
|
|
1184
1209
|
async getLiquidateIx(vaultDepositor) {
|
|
1210
|
+
if (!this.driftClient.wallet.publicKey.equals(constants_1.VAULT_ADMIN_KEY)) {
|
|
1211
|
+
throw new Error('Only vault admin can liquidate');
|
|
1212
|
+
}
|
|
1185
1213
|
const vaultDepositorAccount = await this.program.account.vaultDepositor.fetch(vaultDepositor);
|
|
1186
1214
|
const vault = vaultDepositorAccount.vault;
|
|
1187
1215
|
const vaultAccount = await this.program.account.vault.fetch(vault);
|
|
1188
1216
|
const user = await this.getSubscribedVaultUser(vaultAccount.user);
|
|
1189
1217
|
const userStatsKey = (0, sdk_1.getUserStatsAccountPublicKey)(this.driftClient.program.programId, vault);
|
|
1190
1218
|
const userStats = (await this.driftClient.program.account.userStats.fetch(userStatsKey));
|
|
1191
|
-
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [vaultAccount.spotMarketIndex], vaultAccount, userStats);
|
|
1219
|
+
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [vaultAccount.spotMarketIndex], vaultAccount, userStats, false, true, true);
|
|
1192
1220
|
const driftStateKey = await this.driftClient.getStatePublicKey();
|
|
1193
1221
|
const accounts = {
|
|
1194
1222
|
vault,
|
|
@@ -1198,6 +1226,7 @@ class VaultClient {
|
|
|
1198
1226
|
driftUser: vaultAccount.user,
|
|
1199
1227
|
driftState: driftStateKey,
|
|
1200
1228
|
driftProgram: this.driftClient.program.programId,
|
|
1229
|
+
authority: vaultDepositorAccount.authority,
|
|
1201
1230
|
};
|
|
1202
1231
|
if (this.cliMode) {
|
|
1203
1232
|
return await this.program.methods
|
|
@@ -1209,8 +1238,8 @@ class VaultClient {
|
|
|
1209
1238
|
else {
|
|
1210
1239
|
return this.program.instruction.liquidate({
|
|
1211
1240
|
accounts: {
|
|
1212
|
-
authority: this.driftClient.wallet.publicKey,
|
|
1213
1241
|
...accounts,
|
|
1242
|
+
admin: this.driftClient.wallet.publicKey,
|
|
1214
1243
|
},
|
|
1215
1244
|
remainingAccounts,
|
|
1216
1245
|
});
|
|
@@ -1465,7 +1494,7 @@ class VaultClient {
|
|
|
1465
1494
|
const user = await this.getSubscribedVaultUser(vaultAccount.user);
|
|
1466
1495
|
const userStatsKey = (0, sdk_1.getUserStatsAccountPublicKey)(this.driftClient.program.programId, vault);
|
|
1467
1496
|
const userStats = (await this.driftClient.program.account.userStats.fetch(userStatsKey));
|
|
1468
|
-
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [], vaultAccount, userStats);
|
|
1497
|
+
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [], vaultAccount, userStats, false, true, true);
|
|
1469
1498
|
const accounts = {
|
|
1470
1499
|
vault,
|
|
1471
1500
|
driftUserStats: userStatsKey,
|
|
@@ -1507,7 +1536,7 @@ class VaultClient {
|
|
|
1507
1536
|
};
|
|
1508
1537
|
const user = await this.getSubscribedVaultUser(vaultAccount.user);
|
|
1509
1538
|
const userStats = (await this.driftClient.program.account.userStats.fetch(userStatsKey));
|
|
1510
|
-
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [], vaultAccount, userStats);
|
|
1539
|
+
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [], vaultAccount, userStats, false, true, true);
|
|
1511
1540
|
if (this.cliMode) {
|
|
1512
1541
|
return [
|
|
1513
1542
|
await this.program.methods
|
|
@@ -1540,7 +1569,7 @@ class VaultClient {
|
|
|
1540
1569
|
const user = await this.getSubscribedVaultUser(vaultAccount.user);
|
|
1541
1570
|
const userStatsKey = (0, sdk_1.getUserStatsAccountPublicKey)(this.driftClient.program.programId, vault);
|
|
1542
1571
|
const userStats = (await this.driftClient.program.account.userStats.fetch(userStatsKey));
|
|
1543
|
-
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [], vaultAccount, userStats);
|
|
1572
|
+
const remainingAccounts = this.getRemainingAccountsForUser([user.getUserAccount()], [], vaultAccount, userStats, false, true, true);
|
|
1544
1573
|
const spotMarket = this.driftClient.getSpotMarketAccount(vaultAccount.spotMarketIndex);
|
|
1545
1574
|
if (!spotMarket) {
|
|
1546
1575
|
throw new Error(`Spot market ${vaultAccount.spotMarketIndex} not found on driftClient`);
|
|
@@ -1756,5 +1785,69 @@ class VaultClient {
|
|
|
1756
1785
|
})
|
|
1757
1786
|
.instruction();
|
|
1758
1787
|
}
|
|
1788
|
+
async adminInitFeeUpdate(vault, uiTxParams) {
|
|
1789
|
+
const ix = await this.getAdminInitFeeUpdateIx(vault);
|
|
1790
|
+
return await this.createAndSendTxn([ix], uiTxParams);
|
|
1791
|
+
}
|
|
1792
|
+
async getAdminInitFeeUpdateIx(vault) {
|
|
1793
|
+
const feeUpdate = (0, addresses_1.getFeeUpdateAddressSync)(this.program.programId, vault);
|
|
1794
|
+
return this.program.instruction.adminInitFeeUpdate({
|
|
1795
|
+
accounts: {
|
|
1796
|
+
vault,
|
|
1797
|
+
admin: this.driftClient.wallet.publicKey,
|
|
1798
|
+
feeUpdate,
|
|
1799
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
1800
|
+
},
|
|
1801
|
+
});
|
|
1802
|
+
}
|
|
1803
|
+
async adminDeleteFeeUpdate(vault, uiTxParams) {
|
|
1804
|
+
const ix = await this.getAdminDeleteFeeUpdateIx(vault);
|
|
1805
|
+
return await this.createAndSendTxn([ix], uiTxParams);
|
|
1806
|
+
}
|
|
1807
|
+
async getAdminDeleteFeeUpdateIx(vault) {
|
|
1808
|
+
const feeUpdate = (0, addresses_1.getFeeUpdateAddressSync)(this.program.programId, vault);
|
|
1809
|
+
return this.program.instruction.adminDeleteFeeUpdate({
|
|
1810
|
+
accounts: {
|
|
1811
|
+
vault,
|
|
1812
|
+
admin: this.driftClient.wallet.publicKey,
|
|
1813
|
+
feeUpdate,
|
|
1814
|
+
},
|
|
1815
|
+
});
|
|
1816
|
+
}
|
|
1817
|
+
async managerUpdateFees(vault, params, uiTxParams) {
|
|
1818
|
+
const feeUpdate = (0, addresses_1.getFeeUpdateAddressSync)(this.program.programId, vault);
|
|
1819
|
+
const ixs = [];
|
|
1820
|
+
if (!(await this.checkIfAccountExists(feeUpdate))) {
|
|
1821
|
+
throw new Error('Fee update account does not exist, it must be created by an admin first');
|
|
1822
|
+
}
|
|
1823
|
+
ixs.push(await this.getManagerUpdateFeesIx(vault, params));
|
|
1824
|
+
return await this.createAndSendTxn(ixs, uiTxParams);
|
|
1825
|
+
}
|
|
1826
|
+
async getManagerUpdateFeesIx(vault, params) {
|
|
1827
|
+
const vaultAccount = await this.program.account.vault.fetch(vault);
|
|
1828
|
+
const feeUpdate = (0, addresses_1.getFeeUpdateAddressSync)(this.program.programId, vault);
|
|
1829
|
+
return this.program.instruction.managerUpdateFees(params, {
|
|
1830
|
+
accounts: {
|
|
1831
|
+
vault,
|
|
1832
|
+
manager: vaultAccount.manager,
|
|
1833
|
+
feeUpdate,
|
|
1834
|
+
},
|
|
1835
|
+
});
|
|
1836
|
+
}
|
|
1837
|
+
async managerCancelFeeUpdate(vault, uiTxParams) {
|
|
1838
|
+
const ix = await this.getManagerCancelFeeUpdateIx(vault);
|
|
1839
|
+
return await this.createAndSendTxn([ix], uiTxParams);
|
|
1840
|
+
}
|
|
1841
|
+
async getManagerCancelFeeUpdateIx(vault) {
|
|
1842
|
+
const vaultAccount = await this.program.account.vault.fetch(vault);
|
|
1843
|
+
const feeUpdate = (0, addresses_1.getFeeUpdateAddressSync)(this.program.programId, vault);
|
|
1844
|
+
return this.program.instruction.managerCancelFeeUpdate({
|
|
1845
|
+
accounts: {
|
|
1846
|
+
vault,
|
|
1847
|
+
manager: vaultAccount.manager,
|
|
1848
|
+
feeUpdate,
|
|
1849
|
+
},
|
|
1850
|
+
});
|
|
1851
|
+
}
|
|
1759
1852
|
}
|
|
1760
1853
|
exports.VaultClient = VaultClient;
|
package/package.json
CHANGED
package/src/addresses.ts
CHANGED
|
@@ -99,3 +99,16 @@ export function getTokenizedVaultMintAddressSync(
|
|
|
99
99
|
programId
|
|
100
100
|
)[0];
|
|
101
101
|
}
|
|
102
|
+
|
|
103
|
+
export function getFeeUpdateAddressSync(
|
|
104
|
+
programId: PublicKey,
|
|
105
|
+
vault: PublicKey
|
|
106
|
+
): PublicKey {
|
|
107
|
+
return PublicKey.findProgramAddressSync(
|
|
108
|
+
[
|
|
109
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('fee_update')),
|
|
110
|
+
vault.toBuffer(),
|
|
111
|
+
],
|
|
112
|
+
programId
|
|
113
|
+
)[0];
|
|
114
|
+
}
|
package/src/constants/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BN, TEN } from '@drift-labs/sdk';
|
|
2
|
+
import { PublicKey } from '@solana/web3.js';
|
|
2
3
|
|
|
3
4
|
export const VAULT_SHARES_PRECISION_EXP = new BN(6);
|
|
4
5
|
|
|
@@ -8,3 +9,7 @@ export const FUEL_SHARE_PRECISION = TEN.pow(FUEL_SHARE_PRECISION_EXP);
|
|
|
8
9
|
|
|
9
10
|
// some arbitrary timestamp to identify VaultDepositors created after fuel distribution started.
|
|
10
11
|
export const MAGIC_FUEL_START_TS = 123;
|
|
12
|
+
|
|
13
|
+
export const VAULT_ADMIN_KEY = new PublicKey(
|
|
14
|
+
'4wbNjWbj3kPDbyKnSq8SXVEtAJw4uzE8mJ2QwuK1BCYZ'
|
|
15
|
+
);
|