http://localhost:4000/api/v2/ranges?oracle=BNB&vault=venus-bnb
http://localhost:4000/api/v2/prices?oracle=BNB&bucket=4h_3M
http://localhost:4000/api/v2/apys?vault=venus-bnb&bucket=4h_3M
http://localhost:4000/api/v2/tvls?vault=venus-bnb&bucket=4h_3M
This app is composed of 2 simple modules:
snapshot
periodically fetches info from the api and stores it in a databaseapi
basic fastify server that allows us to query the stored data
.env
is automatically loaded when running the app via yarn dev:*
commands.
.env.example
contains an example set of variables for development
DATABASE_URL
- postgres connection string
DATABASE_SSL
- false: no SSL, true: SSL, default: SSL allowing self-signed certs
PORT
- port to run the api on, default: 4000
API_CORS_ORIGIN
- RegExp for CORS origin, default: ^(https:\/\/app\.beefy\.(com|finance)|http:\/\/localhost(:[0-9]+)?)$
SNAPSHOT_INTERVAL
- interval in seconds between snapshots, default: 900 (15 minutes)
SNAPSHOT_RETRY_DELAY
- delay in seconds between snapshot retries, default: 60 (1 minute)
SNAPSHOT_RETRY_MAX
- max number of retries, default: 5 (SNAPSHOT_RETRY_DELAY * SNAPSHOT_RETRY_MAX
must be less than SNAPSHOT_INTERVAL
)
NODE_ENV
- development / production, default: development - CSP/CORS is disabled when not production
LOG_LEVEL
- 'fatal', 'error', 'warn', 'info', 'debug', 'trace', 'silent', default: 'info' - you may want to set this to warn or above for production
yarn dev:infra:start
- start postgres via docker-compose
yarn dev:migrate
- run database migrations via ts-node
yarn dev:snapshot
- run the snapshot module via ts-node
yarn dev:api
- run the api module via ts-node
yarn build
- compile typescript to javascript
yarn migrate
- run database migrations
yarn snapshot
- run the snapshot module
yarn api
- run the api module
Heroku will automatically run the build
command (via package.json
) on deploy.
Heroku will automatically run the migrate
command (via Procfile
) on release.
The snapshot
module is run via the worker
process (see Procfile
).
The api
module is run via the web
process (see Procfile
).
Logging is handled by pino
Pino outputs logs in JSON format to stdout. In development this is then piped to pino-pretty for pretty printing.
/api/v2/ranges?oracle={oracleId}&vault={vaultId}
oracle
- a price oracle id, e.g. BNB
vault
- a vault id, e.g. venus-bnb
{
"apys": {
"min": "1627759800",
"max": "1679023800"
},
"tvls": {
"min": "1627759800",
"max": "1679023800"
},
"prices": {
"min": "1627759800",
"max": "1679023800"
}
}
/api/v2/prices?oracle={oracleId}&bucket={bucket}
oracle
- a price oracle id, e.g. BNB
bucket
- a bucket, size_range e.g. 1h_1d | 1h_1w | 1d_1M | 1d_1Y
[
{
"t": 1671244200,
"v": 0.002845395315750137
}
]
t
- timestamp in seconds, start of bucket
v
- high for bucket
/api/v2/apys?vault={vaultId}&bucket={bucket}
vault
- a vault id, e.g. venus-bnb
bucket
- as above
as above for prices
/api/v2/tvls?vault={vaultId}&bucket={bucket}
vault
- a vault id, e.g. venus-bnb
bucket
- as above
as above for prices
/api/v2/tvlByChain?chain={chainId}&bucket={bucket}
chain
- a chain id, e.g. arbitrum
bucket
- as above
[
{
"t": 1671244200,
"total": 100000000,
"vault": 30000000,
"gov": 20000000,
"clm": 50000000
}
]
/api/v2/tvlByChains?bucket={bucket}
bucket
- as above
{
"fields" : ["t", "total", "vault", "gov", "clm"],
"data" : {
"arbitrum": [[1671244200,100000000,30000000,20000000,50000000],[1671244200,100000000,30000000,20000000,50000000]],
... , // all chain ids
}
}
Database migrations are handled by postgrator and are available in /migrations/