@drift-labs/vaults-sdk

中文文档
0.11.1发布于 2026/03/30TypeScriptCommonJS近 30 天下载 2.6万

This repo has a simple CLI for interacting with the vault (run from this package.json):

原始使用文档
文档目录11 节
  1. Manager Commands
  2. Initialize a new vault
  3. Update Vault Params
  4. Update Margin Trading Enabled
  5. Manager Deposit
  6. Manager Withdraw
  7. Apply Profit Share
  8. Depositor Commands
  9. Deposit into a vault
  10. Withdraw from a vault
  11. View only commands

CLI Usage

This repo has a simple CLI for interacting with the vault (run from this package.json):

This CLI utility requires an RPC node and keypair to sign transactions. You can either provide these as environment variables, in a .env file, or use cli flags (like --keypair and --url).

Required Environment Variables or Flags:

Environment Variablecommand line flagDescription
RPC_URL--urlThe RPC node to connect to for transactions
KEYPAIR_PATH--keypairPath to keypair (file or base58) to sign transactions. This may also be a ledger filepath (e.g. usb://ledger/<wallet_id>?key=0/0)
ENV--env'devnet' or 'mainnet' (default: 'mainnet')

View available commands, run with --help in nested commands to get available options for each command

yarn cli --help

Manager Commands

The following commands are menat to be run by Vault Managers. KEYPAIR_PATH should be the manager's keypair.

Initialize a new vault

Init a new vault. This will initialize a new vault and update you (the manager) as the delegate, unless --delegate is specified.

$ yarn cli init-vault --help
Usage: cli init-vault [options]

Initialize a new vault

Options:
  -n, --name <string>               Name of the vault to create
  -i, --market-index <number>       Spot market index to accept for deposits (default 0 == USDC) (default: "0")
  -r, --redeem-period <number>      The period (in seconds) depositors must wait after requesting a withdraw (default: 7 days) (default: "604800")
  -x, --max-tokens <number>         The max number of spot marketIndex tokens the vault can accept (default 0 == unlimited) (default: "0")
  -m, --management-fee <percent>    The annualized management fee to charge depositors (default: "0")
  -s, --profit-share <percent>      The percentage of profits charged by manager (default: "0")
  -p, --permissioned                Provide this flag to make the vault permissioned, vault-depositors will need to be initialized by the manager
                                    (default: false)
  -a, --min-deposit-amount <number  The minimum token amount allowed to deposit (default: "0")
  -d, --delegate <publicKey>        The address to make the delegate of the vault
  -h, --help                        display help for command

Update Vault Params

To update params in a vault:

$ yarn cli manager-update-vault --help
Usage: cli manager-update-vault [options]

Update vault params for a manager

Options:
  --vault-address <address>         Address of the vault to update
  -r, --redeem-period <number>      The new redeem period (can only be lowered)
  -x, --max-tokens <number>         The max tokens the vault can accept
  -a, --min-deposit-amount <number  The minimum token amount allowed to deposit
  -m, --management-fee <percent>    The new management fee (can only be lowered)
  -s, --profit-share <percent>      The new profit share percentage (can only be lowered)
  -p, --permissioned <boolean>      Set the vault as permissioned (true) or open (false) (default: false)
  -h, --help                        display help for command

Update Margin Trading Enabled

If you wish to trade with spot margin on the vault, you must enable margin trading:

yarn cli manager-update-margin-trading-enabled --vault-address=<VAULT_ADDRESS> --enabled=<true|false>

Manager Deposit

Make a deposit into a vault as the manager (DEPOSIT_AMOUNT in human precision, e.g. 5 for 5 USDC):

yarn cli manager-deposit --vault-address=<VAULT_ADDRESS> --amount=<DEPOSIT_AMOUNT>

Manager Withdraw

Make a withdraw request from a vault as the manager (SHARES in raw precision):

yarn cli manager-request-withdraw --vault-address=<VAULT_ADDRESS> --amount=<SHARES>

After the redeem period has passed, the manager can complete the withdraw:

yarn cli manager-withdraw --vault-address=<VAULT_ADDRESS>

Apply Profit Share

Manager can trigger a profit share calculation (this looks up all VaultDepositors for a vault eligible for profit share and batch processes them):

yarn cli apply-profit-share-all --vault-address=<VAULT_ADDRESS>

Depositor Commands

Deposit into a vault

Permissioned Vaults

Permissioned vaults require the manager to initialize the VaultDepositor account before a depositor can deposit.

Initialize a VaultDepositor account for AUTHORITY_TO_ALLOW_DEPOSIT to deposit:

yarn cli init-vault-depositor --vault-address=<VAULT_ADDRESS> --deposit-authority=<AUTHORITY_TO_ALLOW_DEPOSIT>

Permissioneless Vaults

Permissionless vaults allow anyone to deposit. The deposit instruction will initialize a VaultDepositor account if one does not exist. DEPOSIT_AMOUNT in human precision of the deposit token (e.g. 5 for 5 USDC).

yarn cli deposit --vault-address=<VAULT_ADDRESS> --deposit-authority=<DEPOSIT_AUTHORITY> --amount=<DEPOSIT_AMOUNT>

Alternatively, you can pass in the VaultDepositor address directly:

yarn cli deposit --vault-depositor-address=<VAULT_DEPOSITOR_ADDRESS> --amount=<DEPOSIT_AMOUNT>

Withdraw from a vault

Request a withdraw from a vault:

yarn cli request-withdraw --vault-address=<VAULT_ADDRESS> --authority=<AUTHORITY> --amount=<WITHDRAW_AMOUNT>

After the redeem period has passed, the depositor can complete the withdraw:

yarn cli withdraw --vault-address=<VAULT_ADDRESS> --authority=<AUTHORITY>

View only commands

To print out the current state of a Vault:

yarn cli view-vault --vault-address=<VAULT_ADDRESS>

To print out the current state of a VaultDepositor:

yarn cli view-vault-depositor --vault-depositor-address=<VAULT_DEPOSITOR_ADDRESS>

版本与发布记录

@drift-labs/vaults-sdk 共发布 1,170 个版本,首次发布于 2023/09/12;过去 12 个月发布了 50 个版本。

版本发布日期距今
0.11.1latest2026/03/307 个月前
0.10.82026/03/307 个月前
0.10.72026/03/277 个月前
0.10.62026/03/277 个月前
0.10.52026/03/267 个月前
0.10.42026/03/247 个月前

关于 @drift-labs/vaults-sdk 的常见问题

@drift-labs/vaults-sdk 是什么?

This repo has a simple CLI for interacting with the vault (run from this package.json):

如何安装 @drift-labs/vaults-sdk?

在项目目录运行 npm install @drift-labs/vaults-sdk,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@solana/web3.js(1.98.0)、@coral-xyz/anchor(0.29.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@drift-labs/vaults-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@drift-labs/vaults-sdk 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@drift-labs/vaults-sdk 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js ^24.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@drift-labs/vaults-sdk 可以商用吗?

@drift-labs/vaults-sdk 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@drift-labs/vaults-sdk 的下载量有多少?

根据 npm 官方下载统计,@drift-labs/vaults-sdk 在 2026/10/13 – 2026/11/11 这 30 天内被下载 26,330 次,日均约 878 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@drift-labs/vaults-sdk 还在维护吗?

最新版本 0.11.1 发布于 2026/03/30(7 个月前);至今共发布 1170 个版本,其中过去 12 个月发布了 50 个;首次发布于 2023/09/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。