The front-end of Harvest.finance is accompanied by the API hosted on https://api.harvest.finance/ and https://api-ui.harvest.finance/.
The API:
- Encapsulates the formulas and logic necessary for APY computations to keep the front-end code clean
- Frees up the front-end from excessive CPU and memory load by doing all the computations and caching the results globally
- Provides data for list of farming opportunities on websites like CoinMarketCap.
The API is currently deployed in two separate instances sharing the same code base (but different paths are active depending on the environment):
- https://api-ui.harvest.finance/ - exposes functions originally intended for use by
https://harvest.finance
exclusively - https://api.harvest.finance/ - exposes data originally intended for public use (CoinMarketCap, third parties, etc.)
Both endpoints are public, but the format of https://api-ui.harvest.finance/ is subject to change at any point while the intention for https://api.harvest.finance/ is relatively stable.
When run locally, all paths are active by default.
The API is public, and the authentication key is publicly available as well since there is no private information to protect. In the future, access control may be changed.
The API, on the hourly basis, does the following:
- Runs the necessary computations in formulas by querying third-party APIs, including
Coingecko
(for prices data),Infura
(for computations using on-chain data), and APIs exposed by farming opportunities (such as,apy.vision
,Convex
,curve.fi
,Idle.finance
) - Caches the individual terms as well as the results of the computation in memory and in the database.
The MongoDB-compatible database is purely used for caching. It can be cleared and re-created at any time.
All source is located in the src
folder.
src/lib/*
: Shared supplementary methods, constants, and db/cache managementsrc/data/*
: All the information about vaults, pools, and associated contract addresses consumed by the UIsrc/lib/data/addresses.json
: Ethereum addresses of general frequently-used smart contracts. It intends to not duplicate or hard-code any data already contained in front-end'stokens.json
orpools.json
.src/lib/constants.js
: Some constants and declarations.src/prices/*
: Encapsulates formulas for price computationssrc/pools
: Logic related to pools, which includes pool APY computationssrc/vaults
: Logic related to vaultssrc/vaults/apys/*
: Implementations of APY computation formulas for vaults.src/vaults/trading-apys/*
: Implementations of trading APY (liquidity provider APY) computation formulas for vaults.src/runtime/router/*
: Route definitions, boilerplate code, and middleware of the web service.src/runtime/pollers.js
: Pollers that run periodically (asynchronously to the web service), fetch and cache the data.
Name | Description | Example (or default value) |
---|---|---|
HTTP_PORT | The port on which to run the API w/o SSL | 80 |
HTTPS_PORT | The port on which to run the API w/ SSL | 443 |
INFURA_KEY | Infura access key | |
API_KEY | The authentication token that needs to be appended to all queries on this API | 'harvest-key' |
UPDATE_LOOP_INTERVAL_MS | Interval for polling to update the data (refresh caches) | Default: 1 Hour |
ACTIVE_ENDPOINTS | Selecting which routes to make active (api.harvest.finance and api-ui.harvest.finance exposing different set of routes) |
Default: ENDPOINT_TYPES.INTERNAL |
CG_CACHE_TTL | caching TTL for Coingecko requests | Default: 10 Min |
GENERAL_CACHE_TTL | caching TTL for general responses | Default: 10 Min |
BSC_RPC_URL | Blockchain node endpoint for Binance Smart Chain | 'https://bsc-dataseed2.binance.org/' |
MATIC_RPC_URL | Blockchain node endpoint for Polygon (Matic) | https://polygon-mainnet.infura.io/v3/${MATIC_INFURA_KEY} |
MATIC_INFURA_KEY | Infura key used in case of default MATIC_RPC_URL | |
DEBUG_MODE | Computes and exposes some debug-only information | false |
MONGODB_URI | MongoDB connection string | mongodb://127.0.0.1:27017 |
MONGODB_DB_NAME | MongoDB database name | harvest-local |
- Fork the repository, make a change and test locally
- Open a pull request with a detailed description of the purpose of the PR
- Wait for the CI to finish and fix any issues
- If the change is deemed as necessary/useful by the team, it will be merged and promoted.