@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
package/.env.example
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# CLI Usage
|
|
2
|
+
|
|
3
|
+
This repo has a simple CLI for interacting with the vault (run from this `package.json`):
|
|
4
|
+
|
|
5
|
+
First create a `.env` and fill it out:
|
|
6
|
+
```
|
|
7
|
+
cp .env.example .env
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
View available commands, run with `--help` in nested commands to get available options for each command
|
|
11
|
+
```
|
|
12
|
+
yarn cli --help
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
Init a new vault. This will initialize a new vault and update you as the delegate.
|
|
17
|
+
Note that defaults are used for the vault (permissioned, 2% mgmt fee, 20% profit share), take
|
|
18
|
+
care to edit these as required.
|
|
19
|
+
```
|
|
20
|
+
yarn cli init-vault --name="super safe vault"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
Make a deposit into a vault (as a manager, `DEPOSIT_AMOUNT` in human precision):
|
|
25
|
+
```
|
|
26
|
+
yarn cli manager-deposit --vault-address=<VAULT_ADDRESS> --amount=<DEPOSIT_AMOUNT>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Make a withdraw request from a vault (as a manager, `SHARES` in raw precision):
|
|
30
|
+
```
|
|
31
|
+
yarn cli manager-request-withdraw --vault-address=<VAULT_ADDRESS> --amount=<SHARES>
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Manager can trigger a profit share calculation (this looks up all `VaultDepositors` for a vault eligible for profit share and batch processes them):
|
|
35
|
+
```
|
|
36
|
+
yarn cli apply-profit-share-all --vault-address=<VAULT_ADDRESS>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
For permissioned vaults, initialize a `VaultDepositor` for someone to deposit.
|
|
41
|
+
```
|
|
42
|
+
yarn cli init-vault-depositor --vault-address=<VAULT_ADDRESS> --deposit-authority=<AUTHORITY_TO_ALLOW_DEPOSIT>
|
|
43
|
+
```
|
|
44
|
+
Then send them the `VAULT_DEPOSITOR_ADDRESS`
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
Make a deposit into a vault (as a non-manager, `DEPOSIT_AMOUNT` in human precision):
|
|
48
|
+
```
|
|
49
|
+
yarn cli deposit --vault-depositor-address=<VAULT_DEPOSITOR_ADDRESS> --amount=<DEPOSIT_AMOUNT>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
To print out the current state of a `Vault` or `VaultDepositor`:
|
|
54
|
+
```
|
|
55
|
+
yarn cli view-vault --vault-address=<VAULT_ADDRESS>
|
|
56
|
+
|
|
57
|
+
yarn cli view-vault-depositor --vault-depositor-address=<VAULT_DEPOSITOR_ADDRESS>
|
|
58
|
+
```
|
package/cli/cli.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import {
|
|
2
|
+
initVault,
|
|
3
|
+
viewVault,
|
|
4
|
+
managerDeposit,
|
|
5
|
+
managerRequestWithdraw,
|
|
6
|
+
managerCancelWithdraw,
|
|
7
|
+
managerWithdraw,
|
|
8
|
+
managerUpdateVault,
|
|
9
|
+
applyProfitShare,
|
|
10
|
+
initVaultDepositor,
|
|
11
|
+
deposit,
|
|
12
|
+
requestWithdraw,
|
|
13
|
+
withdraw,
|
|
14
|
+
listDepositorsForVault,
|
|
15
|
+
} from "./commands";
|
|
16
|
+
|
|
17
|
+
import { Command, Option } from 'commander';
|
|
18
|
+
import { viewVaultDepositor } from "./commands/viewVaultDepositor";
|
|
19
|
+
require('dotenv').config();
|
|
20
|
+
|
|
21
|
+
const program = new Command();
|
|
22
|
+
program
|
|
23
|
+
.addOption(new Option("-r, --rpc <url>", "RPC URL to use").env("RPC_URL").makeOptionMandatory(true))
|
|
24
|
+
.addOption(new Option("-k, --keypair <fiilepath>", "Path to keypair file").env("KEYPAIR_PATH"))
|
|
25
|
+
.addOption(new Option("--commitment <commitment>", "State commitment to use").default("confirmed"));
|
|
26
|
+
program
|
|
27
|
+
.command("init")
|
|
28
|
+
.description("Initialize a new vault")
|
|
29
|
+
.option("-n, --name <vaultName>", "Name of the vault to create", "my new vault")
|
|
30
|
+
.action((opts) => initVault(program, opts));
|
|
31
|
+
program
|
|
32
|
+
.command("view-vault")
|
|
33
|
+
.description("View Vault account details")
|
|
34
|
+
.addOption(new Option("--vault-address <address>", "Address of the Vault to view").makeOptionMandatory(true))
|
|
35
|
+
.action((opts) => viewVault(program, opts));
|
|
36
|
+
program
|
|
37
|
+
.command("view-vault-depositor")
|
|
38
|
+
.description("View VaultDepositor account details")
|
|
39
|
+
.addOption(new Option("--vault-depositor-address <address>", "Address of the VaultDepositor to view").makeOptionMandatory(false))
|
|
40
|
+
.addOption(new Option("--vault-address <address>", "Address of the Vault to view").makeOptionMandatory(false))
|
|
41
|
+
.addOption(new Option("--authority <vaultDepositorAuthority>", "VaultDepositor authority address").makeOptionMandatory(false))
|
|
42
|
+
.action((opts) => viewVaultDepositor(program, opts));
|
|
43
|
+
program
|
|
44
|
+
.command("list-vault-depositors")
|
|
45
|
+
.description("List VaultDepositors for a Vault")
|
|
46
|
+
.addOption(new Option("--vault-address <address>", "Address of the Vault to view").makeOptionMandatory(true))
|
|
47
|
+
.action((opts) => listDepositorsForVault(program, opts));
|
|
48
|
+
program
|
|
49
|
+
.command("manager-deposit")
|
|
50
|
+
.description("Make a deposit to your vault")
|
|
51
|
+
.addOption(new Option("--vault-address <address>", "Address of the vault to view").makeOptionMandatory(true))
|
|
52
|
+
.addOption(new Option("--amount <amount>", "Amount to deposit (human format, 5 for 5 USDC)").makeOptionMandatory(true))
|
|
53
|
+
.action((opts) => managerDeposit(program, opts));
|
|
54
|
+
program
|
|
55
|
+
.command("manager-request-withdraw")
|
|
56
|
+
.description("Make a withdraw request from your vault")
|
|
57
|
+
.addOption(new Option("--vault-address <address>", "Address of the vault to view").makeOptionMandatory(true))
|
|
58
|
+
.addOption(new Option("--shares <shares>", "Amount of shares to withdraw (raw precision, as expected by contract)").makeOptionMandatory(true))
|
|
59
|
+
.action((opts) => managerRequestWithdraw(program, opts));
|
|
60
|
+
program
|
|
61
|
+
.command("manager-update-vault")
|
|
62
|
+
.description("Update vault params for a manager")
|
|
63
|
+
.addOption(new Option("--vault-address <address>", "Address of the vault to view").makeOptionMandatory(true))
|
|
64
|
+
.action((opts) => managerUpdateVault(program, opts));
|
|
65
|
+
program
|
|
66
|
+
.command("manager-withdraw")
|
|
67
|
+
.description("Make a withdraw from your vault")
|
|
68
|
+
.addOption(new Option("--vault-address <address>", "Address of the vault to view").makeOptionMandatory(true))
|
|
69
|
+
.action((opts) => managerWithdraw(program, opts));
|
|
70
|
+
program
|
|
71
|
+
.command("manager-cancel-withdraw")
|
|
72
|
+
.description("Cancel a pending manager withdraw withdraw from your vault")
|
|
73
|
+
.addOption(new Option("--vault-address <address>", "Address of the vault to view").makeOptionMandatory(true))
|
|
74
|
+
.action((opts) => managerCancelWithdraw(program, opts));
|
|
75
|
+
program
|
|
76
|
+
.command("apply-profit-share-all")
|
|
77
|
+
.description("Turn the profit share crank for all depositors")
|
|
78
|
+
.addOption(new Option("--vault-address <address>", "Address of the vault to view").makeOptionMandatory(true))
|
|
79
|
+
.action((opts) => applyProfitShare(program, opts));
|
|
80
|
+
program
|
|
81
|
+
.command("init-vault-depositor")
|
|
82
|
+
.description("Initialize a VaultDepositor for someone to deposit into your vault")
|
|
83
|
+
.addOption(new Option("--vault-address <address>", "Address of the vault to create a VaultDepositor for").makeOptionMandatory(true))
|
|
84
|
+
.addOption(new Option("--deposit-authority <depositAuthority>", "Authority to create the VaultDepositor for, only they can deposit in the vault.").makeOptionMandatory(true))
|
|
85
|
+
.action((opts) => initVaultDepositor(program, opts));
|
|
86
|
+
program
|
|
87
|
+
.command("deposit")
|
|
88
|
+
.description("Deposit into a vault via VaultDepositor")
|
|
89
|
+
.addOption(new Option("--vault-depositor-address <vaultDepositorAddress>", "VaultDepositor address").makeOptionMandatory(true))
|
|
90
|
+
.addOption(new Option("--amount <amount>", "Amount to deposit (human format, 5 for 5 USDC)").makeOptionMandatory(true))
|
|
91
|
+
.action((opts) => deposit(program, opts));
|
|
92
|
+
program
|
|
93
|
+
.command("request-withdraw")
|
|
94
|
+
.description("Make a request to withdraw shares from the vaultm, redeem period starts now")
|
|
95
|
+
.addOption(new Option("--vault-depositor-address <vaultDepositorAddress>", "VaultDepositor address").makeOptionMandatory(true))
|
|
96
|
+
.addOption(new Option("--amount <amount>", "Amount of shares to withdraw (raw format, as expected in the program)").makeOptionMandatory(true))
|
|
97
|
+
.action((opts) => requestWithdraw(program, opts));
|
|
98
|
+
program
|
|
99
|
+
.command("withdraw")
|
|
100
|
+
.description("Initiate the withdraw, after the redeem period has passed")
|
|
101
|
+
.addOption(new Option("--vault-depositor-address <vaultDepositorAddress>", "VaultDepositor address").makeOptionMandatory(false))
|
|
102
|
+
.addOption(new Option("--authority <vaultDepositorAuthority>", "VaultDepositor authority address").makeOptionMandatory(false))
|
|
103
|
+
.action((opts) => withdraw(program, opts));
|
|
104
|
+
|
|
105
|
+
program.parseAsync().then(() => { });
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
2
|
+
import {
|
|
3
|
+
OptionValues,
|
|
4
|
+
Command
|
|
5
|
+
} from "commander";
|
|
6
|
+
import { getCommandContext } from "../utils";
|
|
7
|
+
|
|
8
|
+
export const applyProfitShare = async (program: Command, cmdOpts: OptionValues) => {
|
|
9
|
+
|
|
10
|
+
let vaultAddress: PublicKey;
|
|
11
|
+
try {
|
|
12
|
+
vaultAddress = new PublicKey(cmdOpts.vaultAddress as string);
|
|
13
|
+
} catch (err) {
|
|
14
|
+
console.error("Invalid vault address");
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const {
|
|
19
|
+
driftVault
|
|
20
|
+
} = await getCommandContext(program, true);
|
|
21
|
+
|
|
22
|
+
const allVaultDepositors = await driftVault.getAllVaultDepositors(vaultAddress);
|
|
23
|
+
// console.log(allVaultDepositors);
|
|
24
|
+
|
|
25
|
+
console.log(`Cranking profit share for ${allVaultDepositors.length} depositors...`);
|
|
26
|
+
|
|
27
|
+
const chunkSize = 10;
|
|
28
|
+
const ixChunks: Array<Array<TransactionInstruction>> = [];
|
|
29
|
+
for (let i = 0; i < allVaultDepositors.length; i += chunkSize) {
|
|
30
|
+
const chunk = allVaultDepositors.slice(i, i + chunkSize);
|
|
31
|
+
const ixs = await Promise.all(chunk.map((vaultDepositor) => {
|
|
32
|
+
return driftVault.getApplyProfitShareIx(vaultAddress, vaultDepositor.publicKey);
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
ixChunks.push(ixs);
|
|
36
|
+
}
|
|
37
|
+
console.log(`Cranking ${ixChunks.length} of ${chunkSize} depositors at a time...`);
|
|
38
|
+
|
|
39
|
+
const txs = await Promise.all(ixChunks.map((ixs) => driftVault.createAndSendTxn(ixs)));
|
|
40
|
+
for (const tx of txs) {
|
|
41
|
+
console.log(`Crank tx: https://solscan.io/tx/${tx}`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
// const ix = await driftVault.getApplyProfitShareIx(vaultAddress, );
|
|
46
|
+
// console.log(`Withrew ${cmdOpts.shares} shares as vault manager: ${tx}`);
|
|
47
|
+
console.log("Done!");
|
|
48
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { BN, TEN } from "@drift-labs/sdk";
|
|
2
|
+
import { PublicKey } from "@solana/web3.js";
|
|
3
|
+
import {
|
|
4
|
+
OptionValues,
|
|
5
|
+
Command
|
|
6
|
+
} from "commander";
|
|
7
|
+
import { getCommandContext } from "../utils";
|
|
8
|
+
|
|
9
|
+
export const deposit = async (program: Command, cmdOpts: OptionValues) => {
|
|
10
|
+
|
|
11
|
+
let vaultDepositorAddress: PublicKey;
|
|
12
|
+
try {
|
|
13
|
+
vaultDepositorAddress = new PublicKey(cmdOpts.vaultDepositorAddress as string);
|
|
14
|
+
} catch (err) {
|
|
15
|
+
console.error("Invalid vault depositor address");
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const {
|
|
20
|
+
driftClient,
|
|
21
|
+
driftVault
|
|
22
|
+
} = await getCommandContext(program, true);
|
|
23
|
+
|
|
24
|
+
const spotMarket = driftClient.getSpotMarketAccount(0); // takes USDC deposits
|
|
25
|
+
if (!spotMarket) {
|
|
26
|
+
throw new Error("No spot market found");
|
|
27
|
+
}
|
|
28
|
+
const spotPrecision = TEN.pow(new BN(spotMarket.decimals));
|
|
29
|
+
const depositBN = new BN(cmdOpts.amount * spotPrecision.toNumber());
|
|
30
|
+
|
|
31
|
+
console.log(`depositing: ${depositBN.toString()}`);
|
|
32
|
+
const tx = await driftVault.deposit(vaultDepositorAddress, depositBN);
|
|
33
|
+
console.log(`Deposited ${cmdOpts.amount} to vault as manager: ${tx}`);
|
|
34
|
+
console.log("Done!");
|
|
35
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from './initVault';
|
|
2
|
+
export * from './viewVault';
|
|
3
|
+
export * from './managerDeposit';
|
|
4
|
+
export * from './managerRequestWithdraw';
|
|
5
|
+
export * from './managerCancelWithdraw';
|
|
6
|
+
export * from './managerWithdraw';
|
|
7
|
+
export * from './managerUpdateVault';
|
|
8
|
+
export * from './applyProfitShare';
|
|
9
|
+
export * from './initVaultDepositor';
|
|
10
|
+
export * from './deposit';
|
|
11
|
+
export * from './requestWithdraw';
|
|
12
|
+
export * from './withdraw';
|
|
13
|
+
export * from './listDepositorsForVault';
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BN,
|
|
3
|
+
PERCENTAGE_PRECISION,
|
|
4
|
+
PublicKey,
|
|
5
|
+
TEN,
|
|
6
|
+
} from "@drift-labs/sdk";
|
|
7
|
+
import {
|
|
8
|
+
OptionValues,
|
|
9
|
+
Command
|
|
10
|
+
} from "commander";
|
|
11
|
+
import {
|
|
12
|
+
encodeName,
|
|
13
|
+
getVaultAddressSync,
|
|
14
|
+
} from "../../src";
|
|
15
|
+
import { getCommandContext } from "../utils";
|
|
16
|
+
import { VAULT_PROGRAM_ID } from "../../src/types/types";
|
|
17
|
+
|
|
18
|
+
export const initVault = async (program: Command, cmdOpts: OptionValues) => {
|
|
19
|
+
const {
|
|
20
|
+
driftClient,
|
|
21
|
+
driftVault
|
|
22
|
+
} = await getCommandContext(program, true);
|
|
23
|
+
|
|
24
|
+
const spotMarket = driftClient.getSpotMarketAccount(0); // takes USDC deposits
|
|
25
|
+
if (!spotMarket) {
|
|
26
|
+
throw new Error("No spot market found");
|
|
27
|
+
}
|
|
28
|
+
const spotPrecision = TEN.pow(new BN(spotMarket.decimals));
|
|
29
|
+
|
|
30
|
+
let newVaultName = cmdOpts.name;
|
|
31
|
+
if (!newVaultName) {
|
|
32
|
+
newVaultName = "my new vault";
|
|
33
|
+
}
|
|
34
|
+
const vaultNameBytes = encodeName(newVaultName!);
|
|
35
|
+
console.log(`Initializing a new vault named '${newVaultName}'`);
|
|
36
|
+
|
|
37
|
+
const initTx = await driftVault.initializeVault({
|
|
38
|
+
name: vaultNameBytes,
|
|
39
|
+
spotMarketIndex: 0,
|
|
40
|
+
redeemPeriod: new BN(3 * 60 * 60), // 3 hours
|
|
41
|
+
maxTokens: new BN(1000).mul(spotPrecision), // 1000 USDC cap
|
|
42
|
+
managementFee: PERCENTAGE_PRECISION.div(new BN(50)), // 2%
|
|
43
|
+
profitShare: PERCENTAGE_PRECISION.div(new BN(5)), // 20%
|
|
44
|
+
hurdleRate: 0,
|
|
45
|
+
permissioned: false,
|
|
46
|
+
minDepositAmount: new BN(10).mul(spotPrecision), // 10 USDC minimum deposit
|
|
47
|
+
});
|
|
48
|
+
console.log(`Initialized vault, tx: ${initTx}`);
|
|
49
|
+
|
|
50
|
+
const vaultAddress = getVaultAddressSync(VAULT_PROGRAM_ID, vaultNameBytes);
|
|
51
|
+
console.log(`New vault address: ${vaultAddress}`);
|
|
52
|
+
|
|
53
|
+
let delegate = cmdOpts.delegate;
|
|
54
|
+
if (!delegate) {
|
|
55
|
+
delegate = driftClient.wallet.publicKey.toBase58();
|
|
56
|
+
}
|
|
57
|
+
console.log(`Updating the drift account delegate to: ${delegate}`);
|
|
58
|
+
const updateDelegateTx = await driftVault.updateDelegate(vaultAddress, new PublicKey(delegate));
|
|
59
|
+
console.log(`update delegate tx: ${updateDelegateTx}`);
|
|
60
|
+
console.log("Done!");
|
|
61
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
import {
|
|
3
|
+
getVaultDepositorAddressSync
|
|
4
|
+
} from "../../src/addresses";
|
|
5
|
+
import {
|
|
6
|
+
OptionValues,
|
|
7
|
+
Command
|
|
8
|
+
} from "commander";
|
|
9
|
+
import { getCommandContext } from "../utils";
|
|
10
|
+
import { VAULT_PROGRAM_ID } from "../../src/types/types";
|
|
11
|
+
|
|
12
|
+
export const initVaultDepositor = async (program: Command, cmdOpts: OptionValues) => {
|
|
13
|
+
|
|
14
|
+
let vaultAddress: PublicKey;
|
|
15
|
+
try {
|
|
16
|
+
vaultAddress = new PublicKey(cmdOpts.vaultAddress as string);
|
|
17
|
+
} catch (err) {
|
|
18
|
+
console.error("Invalid vault address");
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let depositAuthority: PublicKey;
|
|
23
|
+
try {
|
|
24
|
+
depositAuthority = new PublicKey(cmdOpts.depositAuthority as string);
|
|
25
|
+
} catch (err) {
|
|
26
|
+
console.error("Invalid deposit authority");
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const {
|
|
31
|
+
driftVault
|
|
32
|
+
} = await getCommandContext(program, true);
|
|
33
|
+
|
|
34
|
+
const vaultDepositorAddress = getVaultDepositorAddressSync(
|
|
35
|
+
VAULT_PROGRAM_ID,
|
|
36
|
+
vaultAddress,
|
|
37
|
+
depositAuthority,
|
|
38
|
+
);
|
|
39
|
+
const tx = await driftVault.initializeVaultDepositor(vaultAddress, depositAuthority);
|
|
40
|
+
console.log(`VaultDepositor initialized for ${depositAuthority}: ${tx}`);
|
|
41
|
+
console.log(`VaultDepositor address: ${vaultDepositorAddress}`);
|
|
42
|
+
console.log("Done!");
|
|
43
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
import {
|
|
3
|
+
OptionValues,
|
|
4
|
+
Command
|
|
5
|
+
} from "commander";
|
|
6
|
+
import { getCommandContext } from "../utils";
|
|
7
|
+
|
|
8
|
+
export const listDepositorsForVault = async (program: Command, cmdOpts: OptionValues) => {
|
|
9
|
+
|
|
10
|
+
const {
|
|
11
|
+
driftVault
|
|
12
|
+
} = await getCommandContext(program, false);
|
|
13
|
+
|
|
14
|
+
let vaultAddress: PublicKey | undefined = undefined;
|
|
15
|
+
try {
|
|
16
|
+
if (cmdOpts.vaultAddress !== undefined) {
|
|
17
|
+
vaultAddress = new PublicKey(cmdOpts.vaultAddress as string);
|
|
18
|
+
} else {
|
|
19
|
+
console.error("Must supply --vault-address");
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
} catch (err) {
|
|
23
|
+
console.error("Failed to load VaultDepositor address");
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const vaultDepositors = await driftVault.getAllVaultDepositors(vaultAddress);
|
|
28
|
+
vaultDepositors.forEach((vaultDepositor) => {
|
|
29
|
+
console.log(vaultDepositor.publicKey.toBase58());
|
|
30
|
+
});
|
|
31
|
+
// printVaultDepositor(vaultDepositor);
|
|
32
|
+
console.log("Done!");
|
|
33
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
import {
|
|
3
|
+
OptionValues,
|
|
4
|
+
Command
|
|
5
|
+
} from "commander";
|
|
6
|
+
import { getCommandContext } from "../utils";
|
|
7
|
+
|
|
8
|
+
export const managerCancelWithdraw = async (program: Command, cmdOpts: OptionValues) => {
|
|
9
|
+
|
|
10
|
+
let vaultAddress: PublicKey;
|
|
11
|
+
try {
|
|
12
|
+
vaultAddress = new PublicKey(cmdOpts.vaultAddress as string);
|
|
13
|
+
} catch (err) {
|
|
14
|
+
console.error("Invalid vault address");
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const {
|
|
19
|
+
driftVault
|
|
20
|
+
} = await getCommandContext(program, true);
|
|
21
|
+
|
|
22
|
+
const tx = await driftVault.managerCancelWithdrawRequest(vaultAddress);
|
|
23
|
+
console.log(`Canceled withdraw as vault manager: https://solscan.io/tx/${tx}`);
|
|
24
|
+
console.log("Done!");
|
|
25
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { BN, TEN } from "@drift-labs/sdk";
|
|
2
|
+
import { PublicKey } from "@solana/web3.js";
|
|
3
|
+
import {
|
|
4
|
+
OptionValues,
|
|
5
|
+
Command
|
|
6
|
+
} from "commander";
|
|
7
|
+
import { getCommandContext } from "../utils";
|
|
8
|
+
|
|
9
|
+
export const managerDeposit = async (program: Command, cmdOpts: OptionValues) => {
|
|
10
|
+
|
|
11
|
+
let vaultAddress: PublicKey;
|
|
12
|
+
try {
|
|
13
|
+
vaultAddress = new PublicKey(cmdOpts.vaultAddress as string);
|
|
14
|
+
} catch (err) {
|
|
15
|
+
console.error("Invalid vault address");
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const {
|
|
20
|
+
driftClient,
|
|
21
|
+
driftVault
|
|
22
|
+
} = await getCommandContext(program, true);
|
|
23
|
+
|
|
24
|
+
const spotMarket = driftClient.getSpotMarketAccount(0); // takes USDC deposits
|
|
25
|
+
if (!spotMarket) {
|
|
26
|
+
throw new Error("No spot market found");
|
|
27
|
+
}
|
|
28
|
+
const spotPrecision = TEN.pow(new BN(spotMarket.decimals));
|
|
29
|
+
const depositBN = new BN(cmdOpts.amount * spotPrecision.toNumber());
|
|
30
|
+
|
|
31
|
+
const tx = await driftVault.managerDeposit(vaultAddress, depositBN);
|
|
32
|
+
console.log(`Deposited ${cmdOpts.amount} to vault as manager: ${tx}`);
|
|
33
|
+
console.log("Done!");
|
|
34
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { BN } from "@drift-labs/sdk";
|
|
2
|
+
import { PublicKey } from "@solana/web3.js";
|
|
3
|
+
import {
|
|
4
|
+
OptionValues,
|
|
5
|
+
Command
|
|
6
|
+
} from "commander";
|
|
7
|
+
import { getCommandContext } from "../utils";
|
|
8
|
+
import { WithdrawUnit } from "../../src/types/types";
|
|
9
|
+
|
|
10
|
+
export const managerRequestWithdraw = async (program: Command, cmdOpts: OptionValues) => {
|
|
11
|
+
|
|
12
|
+
let vaultAddress: PublicKey;
|
|
13
|
+
try {
|
|
14
|
+
vaultAddress = new PublicKey(cmdOpts.vaultAddress as string);
|
|
15
|
+
} catch (err) {
|
|
16
|
+
console.error("Invalid vault address");
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
driftVault
|
|
22
|
+
} = await getCommandContext(program, true);
|
|
23
|
+
|
|
24
|
+
const tx = await driftVault.managerRequestWithdraw(vaultAddress, new BN(cmdOpts.shares), WithdrawUnit.SHARES);
|
|
25
|
+
console.log(`Requested to withraw ${cmdOpts.shares} shares as vault manager: https://solscan.io/tx/${tx}`);
|
|
26
|
+
console.log("Done!");
|
|
27
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
import {
|
|
3
|
+
OptionValues,
|
|
4
|
+
Command
|
|
5
|
+
} from "commander";
|
|
6
|
+
import { getCommandContext } from "../utils";
|
|
7
|
+
import { BN } from "@drift-labs/sdk";
|
|
8
|
+
|
|
9
|
+
export const managerUpdateVault = async (program: Command, cmdOpts: OptionValues) => {
|
|
10
|
+
|
|
11
|
+
let vaultAddress: PublicKey;
|
|
12
|
+
try {
|
|
13
|
+
vaultAddress = new PublicKey(cmdOpts.vaultAddress as string);
|
|
14
|
+
} catch (err) {
|
|
15
|
+
console.error("Invalid vault address");
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const {
|
|
20
|
+
driftVault
|
|
21
|
+
} = await getCommandContext(program, true);
|
|
22
|
+
|
|
23
|
+
const newParams = {
|
|
24
|
+
redeemPeriod: new BN(30 * 60 * 60 * 24), // 30 days
|
|
25
|
+
maxTokens: null,
|
|
26
|
+
managementFee: null,
|
|
27
|
+
minDepositAmount: null,
|
|
28
|
+
profitShare: null,
|
|
29
|
+
hurdleRate: null,
|
|
30
|
+
permissioned: null,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const tx = await driftVault.managerUpdateVault(vaultAddress, newParams);
|
|
34
|
+
console.log(`Updated vault params as vault manager: https://solscan.io/tx/${tx}`);
|
|
35
|
+
console.log("Done!");
|
|
36
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
import {
|
|
3
|
+
OptionValues,
|
|
4
|
+
Command
|
|
5
|
+
} from "commander";
|
|
6
|
+
import { getCommandContext } from "../utils";
|
|
7
|
+
|
|
8
|
+
export const managerWithdraw = async (program: Command, cmdOpts: OptionValues) => {
|
|
9
|
+
|
|
10
|
+
let vaultAddress: PublicKey;
|
|
11
|
+
try {
|
|
12
|
+
vaultAddress = new PublicKey(cmdOpts.vaultAddress as string);
|
|
13
|
+
} catch (err) {
|
|
14
|
+
console.error("Invalid vault address");
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const {
|
|
19
|
+
driftVault
|
|
20
|
+
} = await getCommandContext(program, true);
|
|
21
|
+
|
|
22
|
+
const tx = await driftVault.managerWithdraw(vaultAddress);
|
|
23
|
+
console.log(`Withrew as vault manager: https://solscan.io/tx/${tx}`);
|
|
24
|
+
console.log("Done!");
|
|
25
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { BN } from "@drift-labs/sdk";
|
|
2
|
+
import { PublicKey } from "@solana/web3.js";
|
|
3
|
+
import {
|
|
4
|
+
OptionValues,
|
|
5
|
+
Command
|
|
6
|
+
} from "commander";
|
|
7
|
+
import { getCommandContext } from "../utils";
|
|
8
|
+
import { WithdrawUnit } from "../../src/types/types";
|
|
9
|
+
|
|
10
|
+
export const requestWithdraw = async (program: Command, cmdOpts: OptionValues) => {
|
|
11
|
+
|
|
12
|
+
let vaultDepositorAddress: PublicKey;
|
|
13
|
+
try {
|
|
14
|
+
vaultDepositorAddress = new PublicKey(cmdOpts.vaultDepositorAddress as string);
|
|
15
|
+
} catch (err) {
|
|
16
|
+
console.error("Invalid vault depositor address");
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
driftVault
|
|
22
|
+
} = await getCommandContext(program, true);
|
|
23
|
+
|
|
24
|
+
const withdrawAmountBN = new BN(cmdOpts.amount);
|
|
25
|
+
|
|
26
|
+
const tx = await driftVault.requestWithdraw(vaultDepositorAddress, withdrawAmountBN, WithdrawUnit.SHARES);
|
|
27
|
+
console.log(`Requsted to withdraw ${cmdOpts.amount} shares from the vault: ${tx}`);
|
|
28
|
+
console.log("Done!");
|
|
29
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
import {
|
|
3
|
+
getVaultDepositorAddressSync
|
|
4
|
+
} from "../../src/addresses";
|
|
5
|
+
import {
|
|
6
|
+
OptionValues,
|
|
7
|
+
Command
|
|
8
|
+
} from "commander";
|
|
9
|
+
import { getCommandContext } from "../utils";
|
|
10
|
+
import { VAULT_PROGRAM_ID } from "../../src/types/types";
|
|
11
|
+
|
|
12
|
+
export const vaultDeposit = async (program: Command, cmdOpts: OptionValues) => {
|
|
13
|
+
|
|
14
|
+
let vaultAddress: PublicKey;
|
|
15
|
+
try {
|
|
16
|
+
vaultAddress = new PublicKey(cmdOpts.vaultAddress as string);
|
|
17
|
+
} catch (err) {
|
|
18
|
+
console.error("Invalid vault address");
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let depositAuthority: PublicKey;
|
|
23
|
+
try {
|
|
24
|
+
depositAuthority = new PublicKey(cmdOpts.depositAuthority as string);
|
|
25
|
+
} catch (err) {
|
|
26
|
+
console.error("Invalid deposit authority");
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const {
|
|
31
|
+
driftVault
|
|
32
|
+
} = await getCommandContext(program, true);
|
|
33
|
+
|
|
34
|
+
const vaultDepositorAddress = getVaultDepositorAddressSync(
|
|
35
|
+
VAULT_PROGRAM_ID,
|
|
36
|
+
vaultAddress,
|
|
37
|
+
depositAuthority,
|
|
38
|
+
);
|
|
39
|
+
const tx = await driftVault.initializeVaultDepositor(vaultAddress, depositAuthority);
|
|
40
|
+
console.log(`VaultDepositor initialized for ${depositAuthority}: ${tx}`);
|
|
41
|
+
console.log(`VaultDepositor address: ${vaultDepositorAddress}`);
|
|
42
|
+
console.log("Done!");
|
|
43
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
import {
|
|
3
|
+
getVaultDepositorAddressSync
|
|
4
|
+
} from "../../src/addresses";
|
|
5
|
+
import {
|
|
6
|
+
OptionValues,
|
|
7
|
+
Command
|
|
8
|
+
} from "commander";
|
|
9
|
+
import { getCommandContext } from "../utils";
|
|
10
|
+
import { VAULT_PROGRAM_ID } from "../../src/types/types";
|
|
11
|
+
|
|
12
|
+
export const vaultWithdraw= async (program: Command, cmdOpts: OptionValues) => {
|
|
13
|
+
|
|
14
|
+
let vaultAddress: PublicKey;
|
|
15
|
+
try {
|
|
16
|
+
vaultAddress = new PublicKey(cmdOpts.vaultAddress as string);
|
|
17
|
+
} catch (err) {
|
|
18
|
+
console.error("Invalid vault address");
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let depositAuthority: PublicKey;
|
|
23
|
+
try {
|
|
24
|
+
depositAuthority = new PublicKey(cmdOpts.depositAuthority as string);
|
|
25
|
+
} catch (err) {
|
|
26
|
+
console.error("Invalid deposit authority");
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const {
|
|
31
|
+
driftVault
|
|
32
|
+
} = await getCommandContext(program, true);
|
|
33
|
+
|
|
34
|
+
const vaultDepositorAddress = getVaultDepositorAddressSync(
|
|
35
|
+
VAULT_PROGRAM_ID,
|
|
36
|
+
vaultAddress,
|
|
37
|
+
depositAuthority,
|
|
38
|
+
);
|
|
39
|
+
const tx = await driftVault.initializeVaultDepositor(vaultAddress, depositAuthority);
|
|
40
|
+
console.log(`VaultDepositor initialized for ${depositAuthority}: ${tx}`);
|
|
41
|
+
console.log(`VaultDepositor address: ${vaultDepositorAddress}`);
|
|
42
|
+
console.log("Done!");
|
|
43
|
+
};
|