Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/0xNineteen/drift-funding-vault
Capture Drift Funding Rates On-Chain -- if the funding rate is negative (longs get paid) then the vault opens a new long and captures the funding rate
https://github.com/0xNineteen/drift-funding-vault
anchor drift funding-rates solana
Last synced: 2 months ago
JSON representation
Capture Drift Funding Rates On-Chain -- if the funding rate is negative (longs get paid) then the vault opens a new long and captures the funding rate
- Host: GitHub
- URL: https://github.com/0xNineteen/drift-funding-vault
- Owner: 0xNineteen
- Created: 2022-04-08T02:55:10.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-04-15T02:32:59.000Z (almost 3 years ago)
- Last Synced: 2024-11-18T11:23:50.184Z (2 months ago)
- Topics: anchor, drift, funding-rates, solana
- Language: TypeScript
- Homepage:
- Size: 539 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Capture Drift Funding Rates On-Chain
## Program API
- `initialize_vault`: initialize a new vault
- `deposit`: deposit collateral (usdc) into vault and get vault tokens
- `withdraw`: withdraw deposited collateral from vault by burning vault tokens
- `update_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## Tests
- `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 APIother files are copy-pasta'd from the `cpi-examples` repo (see References).
## Setup
- change `[provider]` `wallet` path in `Anchor.toml`
- install anchor version manager (`avm`) with versions `0.22.0` and `0.19.0` installed
- `bash setup.sh`: build the clearing house, sdk, mock-pyth program, and vault program## Notes
- `protocol-v1` is modified to include a new method `update_twaps` which allows anyone to set the oracle / mark twaps to whatever they want -- was useful for unit testing different funding rates
## References
- largely based off of drift's [cpi-example](https://github.com/drift-labs/cpi-example)