Create a Discord webhook to poll Etherscan ERC-20 internal transactions associated with MetaVault v2 contract and display buybacks executed by its active strategies.
Runs on node.js and a Postgres SQL database. Tested with node.js v16.1.0 and Postgres SQL v13.2.
node.js code is really 2 files:
lib/app.js
containing most of the code, andlib/db.js
encapsulating the DB initialization routines and exposing aquery()
method to run all SQL queries. It's worth noticing that thedb.js::init()
function creates all needed tables in the PSQL database that you chose via theDATABASE_URL
environment variable (see below).
PSQL database uses 2 tables:
transactions
saving the data relative to all past buyback transactionstokenHistoricalPrices
saving YAXIS v2 token price at the time of each transactions
- Install latest version of node.js and PSQL
- Create a PSQL database of your choosing and set the URI accordingly (e.g.
yaxis_discord
) - (Optional) Run the SQL install script to load historical token prices. It's optional to run it, if no data exists the script will use the current token price (same behavior as Etherscan but not accurate for past transactions)
- Edit package.json file and update the environment variables in
script.local
(see environment variables below)
Several environment variables were created to override the content of config.json
WEBHOOK_ID
: the ID of Discord's webhook to post messages toWEBHOOK_TOKEN
: associated Discord's webhook tokenYAXIS_EMOJI_NAME
&YAXIS_EMOJI_ID
: Discord emoji code used to display the Yaxis emjoi. As it's a custom emoji, you'll have to install it on your server and use the following command to get the ID\:[your token name]
ETHERSCAN_API_KEY
: Etherscan API (should work without any API key as a default rate limit of 1 txn per 5s will be applied)
discord.webhook
> same asWEBHOOK_ID
&WEBHOOK_TOKEN
environment variablesdiscord.emoji
> sameYAXIS_EMOJI_NAME
&YAXIS_EMOJI_ID
environment variablesetherscan.api_key
> same asETHERSCAN_API_KEY
environment variableyaxis
> various constants relative to the YAXIS project.yaxis.metavault.startblock
is the startblock used in case none can be found in the DBrefresh
> default sleep time before fetch new transactions from Etherscan API (5min by default)
Use npm run local
. npm start
is used by Heroku or equivalent solutions.