### Install and Configure Development Tools (Shell) Source: https://github.com/drift-labs/drift-vaults/blob/master/README.md Installs and configures the necessary development tools including Anchor, Rust, and Solana. It provides specific instructions for Apple Silicon users and for installing Solana if it's not already present. ```shell # if you don't have avm, install it here: # https://book.anchor-lang.com/getting_started/installation.html avm use 0.29.0 # if on Apple Silicon: # rustup override set 1.70.0-x86_64-apple-darwin # else rustup override set 1.70.0 # if you already have solana: # solana-install init 1.16.27 # else: sh -c "$(curl -sSfL https://release.solana.com/v1.16.27/install)" ``` -------------------------------- ### Install Dependencies and View Help Source: https://github.com/drift-labs/drift-vaults/wiki/Initialize-A-Vault This snippet shows how to clone the Drift Vaults repository, navigate to the SDK directory, install project dependencies using Yarn, and view the CLI's help information. ```shell git clone git@github.com:drift-labs/drift-vaults.git cd ts/sdk yarn yarn cli --help ``` -------------------------------- ### Run Drift Vaults Tests (Shell) Source: https://github.com/drift-labs/drift-vaults/blob/master/README.md Commands to set up the TypeScript SDK and run project tests. It includes installing dependencies, building the SDK, and executing the tests using Anchor. ```shell yarn && cd ts/sdk && yarn && yarn build && cd .. # can be any valid key ANCHOR_WALLET=~/.config/solana/id.json && anchor test ``` -------------------------------- ### Execute Build and Test Script (Bash) Source: https://github.com/drift-labs/drift-vaults/blob/master/README.md A convenience script to build and test the Drift Vaults project. It requires making the script executable before running. ```bash chmod +x ./test.sh ./test.sh ``` -------------------------------- ### Resolve Mac Validator Error (Shell) Source: https://github.com/drift-labs/drift-vaults/blob/master/README.md Provides commands to resolve a common 'failed to start validator: Failed to create ledger: blockstore error' when running on macOS. It involves installing gnu-tar and updating the PATH environment variable. ```shell brew install gnu-tar # Put this in ~/.zshrc export PATH="/opt/homebrew/opt/gnu-tar/libexec/gnubin:$PATH" ``` -------------------------------- ### Repay BTC to Zero Borrow Source: https://github.com/drift-labs/drift-vaults/wiki/Trusted-Vault-Class This example shows how to repay a larger amount of BTC into a vault, effectively reducing the outstanding borrow value to zero. It includes the CLI command and the resulting vault state. ```bash yarn cli manager-repay \ --vault-address=A6VbY18DDpnzm8tCsr8m6mFxaDdDtzHjrVCVSFyyXnGV \ --repay-spot-market-index=2 \ --repay-amount=0.4 ``` -------------------------------- ### Repay BTC and Reduce Borrow Source: https://github.com/drift-labs/drift-vaults/wiki/Trusted-Vault-Class This example demonstrates how to repay a specific amount of BTC into a vault and simultaneously reduce the outstanding borrow amount by a specified value in USDC. It shows the CLI command and the expected vault state after the transaction. ```bash yarn cli manager-repay \ --vault-address=A6VbY18DDpnzm8tCsr8m6mFxaDdDtzHjrVCVSFyyXnGV \ --repay-spot-market-index=2 \ --repay-amount=0.09 \ --repay-value=10000 ``` -------------------------------- ### Update Vault Borrow Value Source: https://github.com/drift-labs/drift-vaults/wiki/Trusted-Vault-Class This example demonstrates how to manually update the `managerBorrowedValue` for a vault to reflect the latest mark-to-deposit-asset value. It is useful when funds have been out of the vault for an extended period and their value has changed significantly. ```bash yarn cli manager-update-borrow \ --vault-address=A6VbY18DDpnzm8tCsr8m6mFxaDdDtzHjrVCVSFyyXnGV \ --new-borrow-value=42000 ``` -------------------------------- ### View CLI Help Source: https://github.com/drift-labs/drift-vaults/blob/master/ts/sdk/README.md Displays general help information for the CLI tool, listing available top-level commands. ```bash yarn cli --help ``` -------------------------------- ### Initialize a New Vault Source: https://github.com/drift-labs/drift-vaults/wiki/Initialize-A-Vault Demonstrates the command to initialize a new vault with various configuration parameters such as name, market index, redeem period, fees, and permissions. It requires specifying the RPC URL and a keypair for authentication. ```shell yarn cli init-vault \ --name "test vault" \ --market-index 1 \ --redeem-period 3600 \ --max-tokens 10000 \ --management-fee 2 \ --profit-share 20 \ --permissioned \ --min-deposit-amount 1 \ --url \ --keypair ~/.config/solana/keypair.json ``` -------------------------------- ### Initialize Vault CLI Command Source: https://github.com/drift-labs/drift-vaults/blob/master/ts/sdk/README.md Provides detailed options for initializing a new vault, including setting its name, market index, redeem period, maximum tokens, fees, and permissioning. ```bash yarn cli init-vault --help ``` -------------------------------- ### Initialize a Trusted Vault using CLI Source: https://github.com/drift-labs/drift-vaults/wiki/Trusted-Vault-Class Initializes a new vault with specified parameters and prepares it for use as a Trusted Vault. Requires setting vault name, market index, redeem period, management fee, profit share, and minimum deposit amount. ```bash yarn cli init-vault \ --name="trusted vault test" \ --market-index=0 \ --redeem-period=300 \ --management-fee=1 \ --profit-share=10 \ --min-deposit-amount=100 ``` -------------------------------- ### Initialize New Vault with Multisig Manager Source: https://github.com/drift-labs/drift-vaults/wiki/Multisig-Manager-For-Vaults Initializes a new Drift Vault and sets a multisig wallet as its manager. This command requires the `--dump-transaction-message` flag to output a base58 transaction blob that can be used with Squads. ```bash yarn cli init-vault \ --name= \ --market-index= \ --redeem-period= \ --profit-share= \ --min-deposit-amount= \ --manager= \ --dump-transaction-message ``` -------------------------------- ### View Vault Details Source: https://github.com/drift-labs/drift-vaults/wiki/Initialize-A-Vault Shows the command to retrieve and display the details of a specific vault using its address. ```shell yarn cli view-vault --vault-address= ``` -------------------------------- ### Initialize Vault Depositor CLI Command Source: https://github.com/drift-labs/drift-vaults/blob/master/ts/sdk/README.md Illustrates how to initialize a `VaultDepositor` account for a specific depositor in a permissioned vault, allowing them to deposit. ```bash yarn cli init-vault-depositor --vault-address= --deposit-authority= ``` -------------------------------- ### View Vault Details using CLI Source: https://github.com/drift-labs/drift-vaults/wiki/Trusted-Vault-Class Retrieves and displays detailed information about a specific vault, including its name, class, borrowed value, and equity. This is used to verify the vault's status after initialization and class updates. ```bash $ yarn cli view-vault --vault-address=A6VbY18DDpnzm8tCsr8m6mFxaDdDtzHjrVCVSFyyXnGV ``` -------------------------------- ### Manager Deposit CLI Command Source: https://github.com/drift-labs/drift-vaults/blob/master/ts/sdk/README.md Demonstrates how a manager can deposit tokens into a vault, specifying the vault address and the amount to deposit. ```bash yarn cli manager-deposit --vault-address= --amount= ``` -------------------------------- ### Drift Vaults: Deposit and Withdrawal Scenarios Source: https://github.com/drift-labs/drift-vaults/wiki/Vault-Shares-Math Illustrates the state changes in a Drift Vault following user deposits, withdrawals, and market price fluctuations. It shows how vault equity, total shares, share price, and individual user shares are affected. ```text Scenario 1: user1 deposits 100_000 USDC total depositors = 1 vault equity = 100_000 USDC total shares = 100_000_000_000 share price = 1 USDC user1 shares = 100_000_000_000 ``` ```text Scenario 2: user2 deposits 200_000 USDC total depositors = 2 vault equity = 300_000 USDC total shares = 300_000_000_000 share price = 1 USDC user2 shares = 200_000_000_000 ``` ```text Scenario 3: vault up 10%, user1 requests to withdraw 100% total depositors = 2 vault equity = 330_000 USDC total shares = 300_000_000_000 share price = 1.1 USDC user1 withdraw_shares = 100_000_000_000 user1 withdraw_amount = 110_000 ``` ```text Scenario 4: vault up 10% more, user1 cancels withdraw request total depositors = 2 vault equity = 363_000 USDC total shares = 286_956_521_739 share price = 1.265 USDC user1 shares = 86_956_521_739 user1 equity = 109,999.999999885 user2 shares = 200_000_000_000 user2 equity = 253,000.000000115 ``` ```text Scenario 5: vault loses 10% total depositors = 2 vault equity = 326_700 USDC total shares = 286_956_521_739 share price = 1.1385 USDC user1 shares = 86_956_521_739 user1 equity = 98,999.9999998965 user2 shares = 200_000_000_000 user2 equity = 227,700.0000001035 ``` ```text Scenario 6: user1 requests to withdraw all shares total depositors = 2 vault equity = 326_700 USDC total shares = 300_000_000_000 share price = 1.089 USDC user1 withdraw_shares = 86_956_521_739 user1 withdraw_amount = 98_999.999999 ``` ```text Scenario 7: vault loses 50% before user withdraw completion total depositors = 1 vault equity = 113_850 USDC total shares = 200_000_000_000 share price = 1.089 USDC user1 shares after = 0 user1 amount withdrawn = 49_499.999999 user2 shares = 200_000_000_000 user2 equity = 113_850 ``` -------------------------------- ### Borrow from Vault using CLI Source: https://github.com/drift-labs/drift-vaults/wiki/Trusted-Vault-Class Initiates a borrow transaction from a specified vault for a given spot market index and amount. This operation affects the vault's manager borrowed value and equity. ```bash yarn cli manager-borrow \ --vault-address=A6VbY18DDpnzm8tCsr8m6mFxaDdDtzHjrVCVSFyyXnGV \ --borrow-spot-market-index=0 \ --borrow-amount=49999.95 ``` -------------------------------- ### Enable Margin Trading for a Vault using CLI Source: https://github.com/drift-labs/drift-vaults/wiki/Trusted-Vault-Class Enables margin trading functionality for a specified vault. This command requires the vault's address and a boolean flag to indicate whether margin trading should be enabled. ```bash yarn cli manager-update-margin-trading-enabled --vault-address= --enabled=true ``` -------------------------------- ### Deposit to Vault CLI Source: https://github.com/drift-labs/drift-vaults/blob/master/ts/sdk/README.md Allows users to deposit assets into a permissionless vault. The command initializes a VaultDepositor account if it doesn't exist and requires the vault address, deposit authority, and the amount to deposit. Alternatively, a VaultDepositor address can be provided directly. ```bash yarn cli deposit --vault-address= --deposit-authority= --amount= ``` ```bash yarn cli deposit --vault-depositor-address= --amount= ``` -------------------------------- ### Update Vault Parameters Source: https://github.com/drift-labs/drift-vaults/wiki/Initialize-A-Vault Provides the command to update the parameters of an existing vault, including redeem period, maximum tokens, management fee, and profit share. The vault address, RPC URL, and keypair are necessary inputs. ```shell yarn cli manager-update-vault \ --vault-address \ --redeem-period 1000 \ --max-tokens 200000 \ --management-fee 0 \ --profit-share 0 \ --url \ --keypair ~/.config/solana/keypair.json ``` -------------------------------- ### View Vault Details (TypeScript CLI) Source: https://github.com/drift-labs/drift-vaults/wiki/Trusted-Vault-Class Retrieves and displays detailed information about a specific vault using the TypeScript CLI. This output shows the vault's equity, manager's share, and PnL after a borrow operation. ```typescript $ ts-node cli/cli.ts view-vault --vault-address=A6VbY18DDpnzm8tCsr8m6mFxaDdDtzHjrVCVSFyyXnGV ``` -------------------------------- ### Allow Depositor for Permissioned Vault Source: https://github.com/drift-labs/drift-vaults/wiki/Initialize-A-Vault Illustrates the command to grant deposit permissions to a new address for a permissioned vault. This requires the vault address and the new depositor's address. ```shell yarn cli init-vault-depositor --vault-address= --deposit-authority= ``` -------------------------------- ### Enable/Disable Margin Trading CLI Command Source: https://github.com/drift-labs/drift-vaults/blob/master/ts/sdk/README.md Shows how to enable or disable margin trading for a specific vault using its address and a boolean flag. ```bash yarn cli manager-update-margin-trading-enabled --vault-address= --enabled= ``` -------------------------------- ### Drift Vaults: Fuel Distribution Logic Source: https://github.com/drift-labs/drift-vaults/wiki/Vault-Shares-Math Explains how Fuel is managed within Drift Vaults, referencing the UserStats account and the lazy update mechanism for fuel shares. It details the calculation of a user's fuel share based on their deposited shares. ```rust user_fuel_share = VaultDepositor.shares / SHARES_DENOMINATOR ``` -------------------------------- ### Apply Profit Share CLI Command Source: https://github.com/drift-labs/drift-vaults/blob/master/ts/sdk/README.md Details the command for a manager to trigger a profit share calculation for all eligible depositors of a given vault. ```bash yarn cli apply-profit-share-all --vault-address= ``` -------------------------------- ### Update Vault Parameters CLI Command Source: https://github.com/drift-labs/drift-vaults/blob/master/ts/sdk/README.md Details the options for updating existing vault parameters such as redeem period, maximum tokens, minimum deposit amount, management fee, and permission status. ```bash yarn cli manager-update-vault --help ``` -------------------------------- ### View Vault State CLI Source: https://github.com/drift-labs/drift-vaults/blob/master/ts/sdk/README.md Prints the current state of a specified Vault. This command requires the address of the vault to view. ```bash yarn cli view-vault --vault-address= ``` -------------------------------- ### View Vault Depositor State CLI Source: https://github.com/drift-labs/drift-vaults/blob/master/ts/sdk/README.md Prints the current state of a specified VaultDepositor. This command requires the address of the VaultDepositor to view. ```bash yarn cli view-vault-depositor --vault-depositor-address= ``` -------------------------------- ### Manager Withdraw Request CLI Command Source: https://github.com/drift-labs/drift-vaults/blob/master/ts/sdk/README.md Explains how a manager can request a withdrawal from a vault, specifying the vault address and the number of shares to withdraw. ```bash yarn cli manager-request-withdraw --vault-address= --amount= ``` -------------------------------- ### Calculate Shares on Deposit Source: https://github.com/drift-labs/drift-vaults/wiki/Vault-Shares-Math Determines the number of shares to be created for a user when they deposit a certain amount into the vault. This calculation ensures the user receives a proportional share of the vault's assets based on their deposit. ```Solidity shares = amount * total_shares / vault_equity ``` -------------------------------- ### Drift Vaults: Fuel Distribution Modes Source: https://github.com/drift-labs/drift-vaults/wiki/Vault-Shares-Math Describes the two modes for Fuel distribution in Drift Vaults: 'UsersOnly' (default) where managers earn no fuel and it's pro-rata shared among users, and 'UsersAndManager' where the denominator includes the manager's shares. ```rust fuel_distribution_mode = FuelDistributionMode::UsersOnly (default behavior) SHARES_DENOMINATOR = vault.user_shares ``` ```rust fuel_distribution_mode = FuelDistributionMode::UsersAndManager SHARES_DENOMINATOR = vault.total_shares ``` -------------------------------- ### Manager Complete Withdraw CLI Command Source: https://github.com/drift-labs/drift-vaults/blob/master/ts/sdk/README.md Shows the command for a manager to complete a previously requested withdrawal after the redeem period has passed. ```bash yarn cli manager-withdraw --vault-address= ``` -------------------------------- ### Drift Vaults: Manager Fuel Distribution Mode Update Source: https://github.com/drift-labs/drift-vaults/wiki/Vault-Shares-Math Shows how a manager can switch the fuel distribution mode using the `manager_update_fuel_distribution_mode` instruction. This is linked to a Typescript SDK function for managing this setting. ```typescript vaultClient.managerUpdateFuelDistributionMode(...) ``` -------------------------------- ### Request Withdraw from Vault CLI Source: https://github.com/drift-labs/drift-vaults/blob/master/ts/sdk/README.md Initiates a withdrawal request from a vault. This command requires the vault address, the authority performing the withdrawal, and the amount to be withdrawn. The actual withdrawal is completed after a redeem period. ```bash yarn cli request-withdraw --vault-address= --authority= --amount= ``` -------------------------------- ### Calculate Shares for Withdrawal Request Source: https://github.com/drift-labs/drift-vaults/wiki/Vault-Shares-Math Calculates the number of shares a user needs to withdraw a specific amount from the vault. This is done at the time of the withdrawal request, before the actual withdrawal can be completed. ```Solidity withdraw_shares = withdraw_amount * total_shares / vault_equity ``` -------------------------------- ### Generate Multisig Transaction Message Source: https://github.com/drift-labs/drift-vaults/wiki/Multisig-Manager-For-Vaults Generates a base58 encoded transaction message for manager commands. This message can then be imported into Squads for multisig approval and execution. Ensure the multisig wallet has sufficient SOL for fees. ```bash yarn cli manager- --dump-transaction-message ``` -------------------------------- ### Update Vault Manager to Multisig Source: https://github.com/drift-labs/drift-vaults/wiki/Multisig-Manager-For-Vaults Updates the manager of an existing Drift Vault to a new multisig wallet address. This operation requires the current manager's signature. ```bash yarn cli manager-update-vault-manager --vault-address= --new-manager= ``` -------------------------------- ### Complete Withdraw from Vault CLI Source: https://github.com/drift-labs/drift-vaults/blob/master/ts/sdk/README.md Completes a previously requested withdrawal from a vault after the redeem period has passed. This command requires the vault address and the authority that initiated the withdrawal. ```bash yarn cli withdraw --vault-address= --authority= ``` -------------------------------- ### Calculate Shares Lost on Withdrawal Cancel Source: https://github.com/drift-labs/drift-vaults/wiki/Vault-Shares-Math Computes the number of shares that are burned when a user cancels a withdrawal request after the vault has experienced profit during the withdrawal window. This forfeits any potential profit the user would have gained. ```Solidity current_value_in_shares = withdraw_amount * (total_shares - withdraw_shares) / (vault_equity - withdraw_amount) shares_lost = withdraw_shares - current_value_in_shares ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.