initialize_vault
: initialize a new vaultdeposit
: deposit collateral (usdc) into vault and get vault tokenswithdraw
: withdraw deposited collateral from vault by burning vault tokensupdate_position
: update the vault's position (can be called by anyone)- if the funding rate means the shorts pays the longs => will go long
- if the funding rate means the longs pays the shorts => will go short
test/
drift_vault.ts
: main vault tests- ✔ initializes the vault (500ms)
- ✔ deposits into vault (545ms)
- ✔ opens a long when mark < oracle (1539ms)
- ✔ closes long and goes short when mark > oracle (1555ms)
- ✔ withdraws from the vault (510ms)
- ✔ re-deposits in the vault, goes long, captures funding, closes for profit (15625ms)
clearing_house_primitives
: example tests of how to interact directly with the clearing house via API
other files are copy-pasta'd from the cpi-examples
repo (see References).
- change
[provider]
wallet
path inAnchor.toml
- install anchor version manager (
avm
) with versions0.22.0
and0.19.0
installed bash setup.sh
: build the clearing house, sdk, mock-pyth program, and vault program
protocol-v1
is modified to include a new methodupdate_twaps
which allows anyone to set the oracle / mark twaps to whatever they want -- was useful for unit testing different funding rates
- largely based off of drift's cpi-example