# Discord faucet bot
## Features
- Responds to requests for vega and theta testnet tokens
- Response includes a link to the transaction detail in the appropriate block explorer
- Limits the tokens a user can get within a time period for a given testnet
- Limits the tokens an address can get within a time period for a given testnet
- Daily cap for each testnet token
- Requests are saved in local csv file: date, cosmos address, amount, and testnet
- Errors are logged to systemd journal
## Deployment
- The bot will be run in a Cosmos Digital Ocean droplet that Hypha has access to
- The bot is a python script that makes calls to gaiad
- The script can be run as a service
- gaiad must be initialized (it can remain offline though) and the faucets' keys must be added to the keyring
- The `config.toml` file must be modified with the token for the Testnet Faucet linked to the Cosmos Discord server
- See [the cosmos-discord-faucet repo](https://github.com/hyphacoop/cosmos-discord-faucet) for further details
Follow these steps starting from a base Ubuntu droplet.
### Build environment
```
apt update
apt upgrade -y
apt install --yes libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libgdbm-dev lzma lzma-dev tcl-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev wget curl make build-essential python-openssl
```
### gaiad
1. Install golang
```
curl -OL https://go.dev/dl/go1.18.linux-amd64.tar.gz
tar -C /usr/local -xvf go1.18.linux-amd64.tar.gz
```
2. Update .bashrc with go paths (add this line at the end)
```
PATH="$PATH:/usr/local/go/bin:$HOME/go/bin"
```
3. Activate PATH environment variable
```
~ source .bashrc
```
4. Install gaia 6.0.4
```
~
git clone https://github.com/cosmos/gaia
cd gaia
git checkout release/v6.0.4
git pull
make install
```
5. Configure gaia and set up faucet keys
We will use the mnemonic for address `cosmos15aptdqmm7ddgtcrjvc5hs988rlrkze40l4q0he`
```
export CHAIN_ID=faucet-localnet
export NODE_MONIKER=faucet-bridge
export BINARY=gaiad
export NODE_HOME=$HOME/.gaia
$BINARY config chain-id $CHAIN_ID --home $NODE_HOME
$BINARY config keyring-backend test --home $NODE_HOME
$BINARY config broadcast-mode block --home $NODE_HOME
$BINARY init $NODE_MONIKER --home $NODE_HOME --chain-id=$CHAIN_ID
export FAUCET_MNEMONIC="[moniker goes here]"
echo $FAUCET_MNEMONIC | gaiad --home /root/.gaia keys add faucet --recover --keyring-backend=test
```
6. Test keys work for all chains
We are using `cosmos15aptdqmm7ddgtcrjvc5hs988rlrkze40l4q0he` as a faucet
```
gaiad tx bank send cosmos15aptdqmm7ddgtcrjvc5hs988rlrkze40l4q0he cosmos1j7qzunvzx4cdqya80wvnrsmzyt9069d3gwhu5p 1000uatom --fees=500uatom --chain-id="vega-testnet" --keyring-backend=test --node="http://165.22.235.50:26657" --yes
gaiad tx bank send cosmos15aptdqmm7ddgtcrjvc5hs988rlrkze40l4q0he cosmos1j7qzunvzx4cdqya80wvnrsmzyt9069d3gwhu5p 1000uatom --fees=500uatom --chain-id="theta-testnet-001" --keyring-backend=test --node="http://state-sync-01.theta-testnet.polypore.xyz:26657" --yes
gaiad tx bank send cosmos15aptdqmm7ddgtcrjvc5hs988rlrkze40l4q0he cosmos1j7qzunvzx4cdqya80wvnrsmzyt9069d3gwhu5p 1000uatom --fees=50uatom --chain-id="theta-devnet" --keyring-backend=test --node="http://one.theta-devnet.polypore.xyz:26657" --yes
```
### Python
1. Install pyenv
```
curl https://pyenv.run | bash
```
2. Add the following lines to `.bashrc`
```
# Pyenv environment variables
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
# Pyenv initialization
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init --path)"
fi
```
3. Update the environment variables
```
~ source .bashrc
```
4. Install Python
```
pyenv install 3.8.12
pyenv global 3.8.12
```
5. Set up cosmos-discord-faucet environment
```
~
git clone https://github.com/hyphacoop/cosmos-discord-faucet.git
cd cosmos-discord-faucet
git pull
python -m venv .env
source .env/bin/activate
pip install -r requirements.txt
```
6. Update config.toml
Add token and channels to listen to under the `[discord]` section
7. Update `cosmos-discord-faucet.service`
```
User=root
Environment="PATH=/usr/local/go/bin:/root/go/bin:$PATH"
WorkingDirectory=/root/cosmos-discord-faucet
ExecStart=/root/cosmos-discord-faucet/.env/bin/python cosmos_discord_faucet.py
```
8. Make a link in `/etc/systemd/system` to the service file
```
ln -s /root/cosmos-discord-faucet/cosmos-discord-faucet.service /etc/systemd/system/cosmos-discord-faucet.service
```
9. Start the service
```
systemctl daemon-reload
systemctl enable cosmos-discord-faucet.service
systemctl start cosmos-discord-faucet.service
```
10. Check the service is running
```
# journalctl -fu cosmos-discord-faucet
Mar 23 13:52:39 testnet-faucet-bot systemd[1]: Started "Discord testnet faucet bot".
Mar 23 13:52:42 testnet-faucet-bot python[62239]: 2022-03-23 13:52:42,455 INFO Logged into Discord as Testnet Faucet#2049
```
## Default Settings
- 10 ATOM sent per request on vega and theta, 1 ATOM on devnet
- 400 ATOM daily cap for vega and theta, 50 ATOM for devnet
- As of 2022-03-23, has:
- >800,000 ATOM on both vega and theta
- >90 ATOM on devnet
- A user can only get tokens for the same testnet every 24h
- An address can get tokens for the same testnet every 24h