Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #2

Open
wants to merge 117 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
0925910
wow
hamzi15 Nov 26, 2021
6b42673
added a comment
hamzi15 Nov 26, 2021
11405cc
added pseudo code of logic
musatarar Nov 26, 2021
3666ac7
added api.js
hamzi15 Nov 26, 2021
78d9092
Merge branch 'dev' of https://github.com/hamzi15/SSV-goerli-eth-bot i…
hamzi15 Nov 26, 2021
740cb80
created cache
musatarar Nov 27, 2021
533bb44
updated cache
hamzi15 Nov 30, 2021
bd69876
added postgres based cache
hamzi15 Dec 8, 2021
81003de
add balance api
musatarar Dec 9, 2021
fdd4211
Update db.js
kintama48 Dec 9, 2021
723412f
Update db.js
kintama48 Dec 9, 2021
ed4be6c
Update db.js
kintama48 Dec 9, 2021
9cb3666
Update db.js
kintama48 Dec 9, 2021
c36b496
Update db.js
kintama48 Dec 9, 2021
bec4175
Update db.js
kintama48 Dec 9, 2021
266b735
Update db.js
kintama48 Dec 9, 2021
956642f
Update db.js
kintama48 Dec 9, 2021
0c58c80
latest
hamzi15 Dec 13, 2021
8917ec6
ready for final test
hamzi15 Dec 13, 2021
1d4dbb8
latest
hamzi15 Dec 13, 2021
559ecc6
latest db.js
hamzi15 Dec 15, 2021
315a936
latest
hamzi15 Dec 16, 2021
4453d3f
Update goerliBot.js
kintama48 Dec 16, 2021
379b524
Update utils.js
kintama48 Dec 16, 2021
73f0c74
Update utils.js
kintama48 Dec 16, 2021
c597aaf
Update main.js
kintama48 Dec 16, 2021
dd7fb15
Update package.json
kintama48 Dec 16, 2021
cfdc75b
Update README.md
kintama48 Dec 23, 2021
f156409
Update README.md
kintama48 Dec 23, 2021
aa85f00
Update README.md
kintama48 Dec 23, 2021
b2160c1
Update README.md
kintama48 Dec 23, 2021
58470ec
Update README.md
kintama48 Dec 23, 2021
1284d07
Update README.md
kintama48 Dec 23, 2021
8fd3451
Update README.md
kintama48 Dec 23, 2021
9181f0f
Update README.md
kintama48 Dec 23, 2021
7b5ceba
Update README.md
kintama48 Dec 23, 2021
acb3936
Update README.md
kintama48 Dec 23, 2021
d1421d4
Update README.md
kintama48 Dec 23, 2021
95fde3d
Update README.md
kintama48 Dec 23, 2021
2d0085d
Update README.md
kintama48 Dec 23, 2021
842ed12
Update README.md
kintama48 Dec 23, 2021
14ad3cf
Update README.md
kintama48 Dec 23, 2021
73a22a8
Update README.md
kintama48 Dec 23, 2021
6d9bc2e
Update README.md
kintama48 Dec 23, 2021
c6fc9bb
Update README.md
kintama48 Dec 23, 2021
2a10b7b
Update README.md
kintama48 Dec 23, 2021
2a479df
Update README.md
kintama48 Dec 23, 2021
9dbba5c
Update README.md
kintama48 Dec 23, 2021
f5b92cc
Update README.md
kintama48 Dec 23, 2021
b06f195
Update README.md
kintama48 Dec 23, 2021
a6275f5
Update README.md
kintama48 Dec 23, 2021
57bdd47
Update README.md
kintama48 Dec 23, 2021
e0837ea
Update README.md
kintama48 Dec 23, 2021
9f236c8
Update README.md
kintama48 Dec 23, 2021
a75849d
Update README.md
kintama48 Dec 23, 2021
6de1e51
Update README.md
kintama48 Dec 23, 2021
f7ea4f2
Update README.md
kintama48 Dec 23, 2021
8674889
Update README.md
kintama48 Dec 23, 2021
97ad682
added error handling
hamzi15 Dec 23, 2021
8257f90
Merge branch 'dev' of https://github.com/hamzi15/SSV-goerli-eth-bot i…
hamzi15 Dec 23, 2021
89dfceb
Update README.md
kintama48 Dec 23, 2021
9e58d4e
Update README.md
kintama48 Dec 23, 2021
5f5b172
Update README.md
kintama48 Dec 23, 2021
a0b52f0
Update README.md
kintama48 Dec 23, 2021
32ad3a4
Update README.md
kintama48 Dec 23, 2021
4b0258e
Update README.md
hamzi15 Dec 23, 2021
1854e94
Update README.md
kintama48 Dec 23, 2021
da93e24
Update README.md
kintama48 Dec 23, 2021
0e36bd0
Update README.md
kintama48 Dec 23, 2021
17ec81d
Update README.md
hamzi15 Dec 23, 2021
a5a93c7
Update README.md
kintama48 Dec 23, 2021
47beb70
Update README.md
kintama48 Dec 23, 2021
8bbebb4
Update README.md
kintama48 Dec 23, 2021
4925eb9
Update README.md
kintama48 Dec 23, 2021
73d6055
Update README.md
kintama48 Dec 23, 2021
3d51cbc
Update README.md
kintama48 Dec 23, 2021
4fa0ec6
Update README.md
kintama48 Dec 23, 2021
00aebc7
Update README.md
kintama48 Dec 23, 2021
f97c86e
Update README.md
kintama48 Dec 23, 2021
bcccedf
Update README.md
kintama48 Dec 23, 2021
28cb8e4
Update README.md
kintama48 Dec 23, 2021
977ce20
Delete bog.py
kintama48 Dec 26, 2021
5446a65
Delete bog.js
kintama48 Dec 26, 2021
fe00c2b
type conversion for SQL queries
kintama48 Dec 26, 2021
b71b048
latest
hamzi15 Dec 28, 2021
5545c94
Update api.js
hamzi15 Dec 28, 2021
6317556
Update api.js
hamzi15 Dec 28, 2021
2fed01e
Update goerliBot.js
hamzi15 Dec 28, 2021
d5484b6
latest
hamzi15 Jan 5, 2022
95d7c6e
Update db.js
kintama48 Jan 5, 2022
d7635df
Update db.js
kintama48 Jan 5, 2022
c1ac858
switched return to normal
hamzi15 Jan 5, 2022
7aef323
Update package.json
kintama48 Jan 5, 2022
c38827b
latest
hamzi15 Jan 5, 2022
7dd0d65
Merge branch 'dev' of https://github.com/hamzi15/SSV-goerli-eth-bot i…
hamzi15 Jan 5, 2022
f64d2df
latest
hamzi15 Jan 5, 2022
646a112
Update main.js
hamzi15 Jan 5, 2022
efba6d1
Update main.js
kintama48 Jan 5, 2022
156d00e
Update utils.js
kintama48 Jan 5, 2022
3501828
Update goerliBot.js
kintama48 Jan 5, 2022
208956e
Update main.js
kintama48 Jan 5, 2022
983c026
Update utils.js
kintama48 Jan 5, 2022
d0d5260
Update utils.js
kintama48 Jan 5, 2022
22aaf8d
Update goerliBot.js
hamzi15 Jan 5, 2022
592c953
Merge branch 'dev' of https://github.com/hamzi15/SSV-goerli-eth-bot i…
hamzi15 Jan 5, 2022
abf21c4
Update goerliBot.js
kintama48 Jan 5, 2022
c9c2b04
Update package.json
kintama48 Jan 5, 2022
f7c19aa
Update utils.js
kintama48 Jan 6, 2022
853928c
Update main.js
kintama48 Jan 6, 2022
3510d76
Update main.js
kintama48 Jan 6, 2022
866b1e5
Update main.js
hamzi15 Jan 6, 2022
3b3d3db
Update goerliBot.js
hamzi15 Jan 6, 2022
946dd41
Update main.js
kintama48 Jan 6, 2022
27c906c
Update main.js
kintama48 Jan 6, 2022
e6e6701
Update main.js
kintama48 Jan 6, 2022
fc98670
added discordID limitation
hamzi15 Jan 9, 2022
462b7ba
Update README.md
kintama48 Jan 22, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
14 changes: 0 additions & 14 deletions .env.example

This file was deleted.

34 changes: 34 additions & 0 deletions .envexample
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Rename this file to .env and fill out the below

# See README.md for more info
DISCORD_BOT_TOKEN=

# The address and private key of the wallet holding the goerli eth you will distribute
FAUCET_ADDRESS=
FAUCET_PRIVATE_KEY=

# Infura HTTPS endpoint from settings on infura.io
INFURA_HTTPS_ENDPOINT= https://goerli.infura.io/v3/1cc5a78e2e72446880dee3ff4b82cae1

# Full path to nonce file location (file does not need to exist, but folder does)
NONCE_FILE= Provide a path to an empty .txt file

#API
ETHERSCAN_API_KEY = Provide an etherscan api key here from https://api.etherscan.io
ETHERSCAN_API_URL = https://api.etherscan.io/api

GOERLI_API_URL = https://api-goerli.etherscan.io/api

# Database information
DB_NAME =
DB_USERNAME = hamzaasaad
DB_HOST = localhost
DB_PASS = null
DB_PORT = 5431

#Limits information
MAX_DEPOSIT_AMOUNT = Max deposit the faucet can make to the user address (10^18) eg. 1000000000000000
DAILY_LIMIT = Daily limit deposit limit for each address
WEEKLY_LIMIT = Weekly deposit limit for each address
DEPOSIT_AMOUNT = Amount user has to deposit to faucet to be eligible. (10^18) eg.1000000000000000

5 changes: 5 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/goerli-eth-bot.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

105 changes: 87 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
# Goerli ETH Bot
![Current Version](https://img.shields.io/badge/version-v1.0-blue)
![GitHub contributors](https://img.shields.io/github/contributors/hamzi15/SSV-goerli-eth-bot)
![GitHub stars](https://img.shields.io/github/stars/hamzi15/SSV-goerli-eth-bot?style=social)
![GitHub forks](https://img.shields.io/github/forks/hamzi15/SSV-goerli-eth-bot?style=social)

A discord bot which distributes GoErli Test Token to the members of a server and keeps track of the amount distributed.

## Table of Contents
- [Configuration](#configuration)
- [Create Bot Application ](#create-bot-application)
- [Adding the Bot to your server](#adding-the-bot-to-your-server)
- [Running the bot backend](#running-the-bot-backend)
- [SSV.network Custom Checks](#ssv-network-custom-checks)
- [Code](#code)
- [.env](#env)
- [api.js](#api)
- [db.js](#dbjs)
- [goErliBot.js](#goErliBot)
- [utils.js](#utils)
- [main.js](#main)
- [Testing](#testing)
- [Acknowledgments](#acknowledgments)
<!-- - [Tools Required](#tools-required) -->
<!-- - [Installation](#installation) -->
<!-- - [Deployment](#deployment) -->
<!-- - [Authors](#authors) -->
<!-- - [License](#license) -->

## Configuration

### Discord Setup
## Configuration

#### Create bot application
### Create Bot Application

1) Head over to https://discord.com/developers/applications/

Expand All @@ -20,36 +46,79 @@

![mspaint_2021-07-09_09-35-59](https://user-images.githubusercontent.com/26490734/125041473-16ad3400-e099-11eb-81cc-34c7c4dc9261.png)

4) Add bot to your server
### Adding the Bot to your server
1) Add the bot to your server

![mspaint_2021-07-09_09-39-43](https://user-images.githubusercontent.com/26490734/125041956-9fc46b00-e099-11eb-8732-96442545b3bb.png)

5) Authorize the bot and it will appear in your server!
2) Authorize the bot and it will appear in your server!

_[image source](https://www.writebots.com/discord-bot-token/)_
![image](https://i.imgur.com/uVGsGJP.jpeg)

#### Run the bot backend
Note: The bot will stay offline until you run the bot's backend

## Running the Bot Backend

1) Clone this repo

2) `cp .env.example .env` and fill out the required variables, including the token from above
2) `cp .env.example .env` and fill out the required variables, including the bot token from above

3) Implement any custom checks you want your bot to run in the `receiverIsEligible` function in `src/goerliBot.js`
* If you implement custom checks, make sure to pass in `true` when calling `bot.commands.get('goerliBot').execute(message, args, 1, true);`
* The bot is currently configured to send 1 goerli eth, and if the address already has 1 it will not send
* The bot is currently configured to send 33 goerli eth, and if the address already has 33 goerli eth it will not send

4) Add discord user id's to the maintainers command if you would like to

5) Run the bot with the following commands
* `yarn install`
* `yarn start > logfile.txt`
* `npm install`
* `node main.js`

## SSV Network Custom Checks
### Code
All values, constants and variables related to ETH, are standardized to 10^18.
#### env
* `FAUCET_ADDRESS`: You have to provide the faucet address here; the address of the wallet holding the goerli eth you will distribute
* `FAUCET_PRIVATE_KEY`: You have to provide the faucet private key here; the private key of the wallet holding the goerli eth you will distribute
* `DISCORD_BOT_TOKEN`: Bot token generated [here](#create-bot-application).
* `INFURA_HTTPS_ENDPOINT`: https://goerli.infura.io/v3/1cc5a78e2e72446880dee3ff4b82cae1. Infura HTTPS endpoint from settings on infura.io
* `NONCE_FILE`: Full path to nonce file location (file does not need to exist, but folder does), i.e. `/Users/hamzaasaad/Documents/GitHub/goerli-eth-bot/nonceFolder/noncefile.txt`
* `ETHERSCAN_API_KEY`
* `ETHERSCAN_API_URL`: https://api.etherscan.io/api
* `DB_USERNAME`: Database username
* `DB_HOST`: Database host
* `DB_PASS`: Database password
* `DB_PORT`: Database port

#### api
`api.js` util file for dealing with the Etherscan API to fetch latest block and transactions data.
* `getBlockNumber(time)` helper function uses the Etherescan API to get a specific block by time. This is a helper function for it. Please refer to this [link](https://docs.bscscan.com/api-endpoints/blocks#get-block-number-by-timestamp) to read more about `get-block-number-by-timestamp` get request
* `getTransactions(address, fromBlock)` helper function uses the Etherscan API to get an address's transactions array. `fromBlock` parameter is the starting block. This function will return all the transactions from starting block till now.
* `getBalance(address)` helper function returns the current balance of an address
* `checkDeposit(address)` function returns an array containing all the transactions related to `FAUCET_ADDRESS` in the last 48 hours. The array contains objects which have the structure: `{hash: transactionHash, amount: amountSentToFaucet}`

#### db
`db.js` util file for updating and confirming transactions.
* `depositAmount`: Total ETH user should send to the `FAUCET_ADDRESS`. In our case, `32000000000000000000`.
* `dailyLimit`: The max daily amount an address can have
* `weeklyLimit`: The max weekly amount an address can have
* `confirmTransaction(addressDetails, topUpAmount)`: It is the main function where all helper functions come together to validate the transactions of a certain address. It deals with several edge cases. `addressDetails` param is stored and fetched from the database via `checkAddressExists(address)`.
* `validateTransaction(addressDetails, topUpAmount)`: Helper function used by `confirmTransaction` to validate whether or not an address has sent a new transaction of the required amount of ETH to the faucet address. Returns `true` if such a transaction exists otherwise `false`. The transactions of a certain address over the last 48 hours, are fetched via `checkDeposit(address)` helper function.

#### goErliBot
`goErliBot.js` file where all the exports in `db.js`, `api.js`, and `utils.js`, come together and then exported to `main.js` file in a single function `runGoerliFaucet(message, address, amount, runCustomChecks)`.
* `maxDepositAmount`: You have to set its value. It's the max amount `FAUCET_ADDRESS` can send (`32000000000000000000` in our case)
* `runCustomEligibilityChecks(address)`: `topUpAmount` is calculated like so: `maxDepositAmount - currentBalance`, where `maxDepositAmount` is the limit set by us which is `32000000000000000000` in our case and `currentBalance` is the current GoErli GoETH balance of an address.
* `runGoerliFaucet(message, address, amount, runCustomChecks)`: Contains several checks to ensure that the address provided by a user is eligible and valid. `message` param is the original message sent by the user on Discord. `address` is the address provided by the user. `amount` is the amount requested by the user. `runCustomChecks` bool value to decide if custom checks are to be run or not.

#### utils
`utils.js` util file containing the necessary methods to conduct GoErli ETH transactions.

#### main
`main.js` file which deals with Discord API via `discord.js` module. Recieves the command of a discord member, processes their request and dispatches the appropriate message in response.

## Testing
* `yarn install`
* take a look at the "Test Zone" at the bottom of `src/goerliBot.js` and write the appropriate function calls for the tests you want to run
* you can bypass the actual bot here and test the underlying functions
* `node src/goerliBot.js`

## Contributions
* Take a look at "Test Zone", at the bottom of `src/goerliBot.js` and write the appropriate function calls for the tests you want to run (you can bypass the actual bot here and test the underlying functions)
* Use `npm install` then `node src/goerliBot.js` to run the tests

This started off as the EthStaker goerli bot, and we wanted to make it available for anyone to use. Please let us know if you have any issues or suggestions for how to make things clearer. PRs are always welcome too :)
## Acknowledgements
This bot is forked from [Stake-house/GoErli-Eth-Bot](https://github.com/stake-house/goerli-eth-bot)
Loading