This repository contains the JavaScript source code for the Fuse Uniswap V2 TWAP Bot. See here for the Fuse dApp, here for the Fuse SDK, or here for the Fuse contracts.
This bot updates on-chain price data for Fuse pools via TWAPs of Uniswap V2 (and SushiSwap) pairs based in ETH. If you are using prices for which others are not reliably posting TWAPs, you will need to run a bot and a redundancy bot; if others are reliably posting TWAPs, simply run your own redundancy bot for additional security. Note that the more often you update the oracle and the more assets you do so for, the ETH you will spend on gas fees. However, also note that infrequent updates to an asset's price could leave room for attackers to profit via arbitrage at the expense of your users.
You can run this bot on Heroku on their free tier using the Deploy to Heroku button. Upon clicking it, you'll be prompted to enter the bot name and the region where it'll be running. You'll also be required to pass a few variables required by the bot. Namely:
ETHEREUM_ADMIN_ACCOUNT
: Ethereum account that will post the prices to the oracleETHEREUM_ADMIN_PRIVATE_KEY
: Private key of the account that will post the prices to the oracleSUPPORTED_PAIRS
: The pairs your bot should support. The format of this variable should be:
'0x97c4adc5d28a86f9470c70dd91dc6cc2f20d2d4d|0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48,0x088ee5007c98a9677165d78dd2109ae4a3d04d0c|0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
These are for instance, the FRAX/USDC Uniswap address pairs, and the YFI/ETH SushiSwap pairs.
4. WEB3_HTTP_PROVIDER_URL
: Your node provider URL. Infura or otherwise
5. ROOT_PRICE_ORACLE_CONTRACT_ADDRESS
: the root oracle address, defaults to Rari's deployed mainnet oracle address
NOTE: make sure the Ethereum account has sufficient funds to make its transactions!
Then, click on "Deploy App".
All going smoothly, your app should be deployed. If you're using Heroku's free tier, you'll have to assign a Dyno to the app. On your heroku dashboard, click on your app -> Resources -> Edit Button and flip the switch on. Your bot should be now running!
Alternatively, if you have the heroku cli installed, run:
>>> heroku login -i
...
>>> heroku ps:scale worker=1 -a <app name>
The logs of the bot can be accessed via the UI: Heroku Dashboard -> App -> More Button -> View Logs or with the CLI command:
>>> heroku logs <app name>
Nothing prevents you from running the bot on your own infra (AWS, local server or otherwise). You probably know what you're doing in this case, but we've also added some tooling to make development easier:
- Fill in the
development.env
orproduction.env
env files with the parameters described in the above section - Build the Docker image:
>>> ENV=development make build # or ENV=production make build, to use the production.env file
- Run the docker image
>>> ENV=development make run # or ENV=production make run, to run the production bot
- Install
fuse-twap-bot
dependencies
>>> npm i -g pm2
>>> npm i
- Export env variables described above
>>> export ETHEREUM_ADMIN_ACCOUNT="..."
...
- Run the bot in the background
>>> pm2 start ecosystem.config.js # development
>>> pm2 start ecosystem.config.js --env production # production
- Stop, check status and logs
>>> pm2 list # check process status
>>> pm2 stop ecosystem.config.js # stop the bot
>>> cat ~/.pm2/logs # check the logs
See LICENSE
.
Fuse's dApp is developed by David Lucid of Rari Capital. Find out more about Rari Capital at rari.capital.