Skip to content

Commit

Permalink
FAssets transition guide, database setup
Browse files Browse the repository at this point in the history
  • Loading branch information
JeznaSpianca authored and fassko committed Aug 21, 2024
1 parent e0ece3e commit 0c1beb2
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 22 deletions.
24 changes: 23 additions & 1 deletion docs/infra/fassets/deploying-agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ These are ERC-20 representations of test tokens to be used by the FAssets system

The FAsset-wrapped TestXRP token, ready to be used on Coston.

--8<-- "./include/fassets/prerequisites-agent.md"
--8<-- "./include/fassets/setup-commandline.md"
--8<-- "./include/fassets/setup-mysql.md"

### Configure the Access Keys

Expand Down Expand Up @@ -68,11 +70,31 @@ The FAsset agents operate with multiple keys for the Flare and underlying networ
"xrp_rpc": "4tg3AxysaZodxTqsCtcMnBdBIEkR6KDKGTdqBEA8g9MKq4bH",
"indexer": "123456",
```

!!! info

These values apply only to the [Coston Testnet](../../dev/reference/network-config.md) and will be different for other networks.

7. Fill in the `database` field in the `secrets.json` with the MySQL database username and password you created during setup.

### MySQL Setup for Existing Agents

Agents who have already configured `fasset-bots` to switch to MySQL should follow these steps:

1. Install MySQL server.
2. [Create a user](#setting-up-mysql-database) in the MySQL database.
3. Modify the `FASSET_BOT_CONFIG` variable in the `.env` file located in the root of the repository:
```json
FASSET_BOT_CONFIG="./packages/fasset-bots-core/run-config/coston-bot-mysql.json"
```
4. In the `secrets.json` file, add a new key, `database` which is an object with two keys `username` and `password` and fill with values you used when created the user in the MySQL database:
```json
"database": {
"user": "fassetbot",
"password": "VerySafePassword"
}
```

### Whitelist the Management Address

To access the FAssets system during the open beta, you must be whitelisted for security reasons.
Expand Down
1 change: 1 addition & 0 deletions docs/infra/fassets/liquidator.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This guide explains how to run a program called an FAssets bot that observes the

--8<-- "./include/fassets/open-beta.md"

--8<-- "./include/fassets/prerequisites-agent.md"
--8<-- "./include/fassets/setup-commandline.md"

## Configure the Access Keys
Expand Down
47 changes: 38 additions & 9 deletions docs/infra/fassets/managing-agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ After you have successfully deployed the agent bot and it is running, you can co
2. Copy the following text, and paste it into the `.env` file you just created:

```ini
## Path to config file for the agent bot (and other bots)
FASSET_BOT_CONFIG="../fasset-bots-core/run-config/coston-bot.json"
## Path to config file for the agent bot (and other bots) for MYSQL
FASSET_BOT_CONFIG="../fasset-bots-core/run-config/coston-bot-mysql.json"
## If you want to use SQLite (not recommended), uncomment the line below and comment on the line above
# FASSET_BOT_CONFIG="../fasset-bots-core/run-config/coston-bot.json"

## Path to secrets file for the agent bot (and other bots)
FASSET_BOT_SECRETS="../../secrets.json"
Expand All @@ -50,15 +52,15 @@ After you have successfully deployed the agent bot and it is running, you can co
## parameter.
# FASSET_USER_SECRETS=""

## (Optional) Path to directory, used for storing unexecuted minting.
## Defaults to `fasset` subdirectory in user's home directory.
## (Optional) Path to directory, used for storing unexecuted minting
## Defaults to `fasset` subdirectory in user's home directory
# FASSET_USER_DATA_DIR=""

## (Optional) Path to database file for the bot.
FASSET_BOT_SQLITE_DB="../../path-to-.db-file"
## (Optional) Path to the database file for the bot (only needed if SQLite database)
# FASSET_BOT_SQLITE_DB="../../path-to-.db-file"
```

3. Choose one of the following options:
3. If you are using SQLite (not recommended) choose one of the following options:
* If you already have [agent vaults](../../tech/fassets/collateral.md#vault-collateral):
1. Navigate to the root of the `fasset-bots` repository, and locate the `.db` file.
The file name will be in the
Expand All @@ -80,7 +82,7 @@ You can enable alerts to be sent to the backend and displayed in the frontend.

```json
{
"extends": "coston-bot.json",
"extends": "coston-bot-mysql.json",
"apiNotifierConfigs": [
{
"apiKey": "",
Expand All @@ -90,16 +92,43 @@ You can enable alerts to be sent to the backend and displayed in the frontend.
}
```

Optionally (not recommended), if you use SQLite, change the `extends` value in the JSON to `coston-bot.json`.

3. Open the `.env` file in this same folder, and change the path specified for `FASSET_BOT_CONFIG` to the `alerts.json` file:

```ini
FASSET_BOT_CONFIG="./alerts.json"
```

## Configure Existing Agents to Setup MySQL

Agents that already have successfully configured `fasset-bots` backend need to do the following:

1. Install the MySQL server.
2. Create a user in MySQL as stated above.
3. In the `.env` file located at the root of the repository, you should modify the `FASSET_BOT_CONFIG` variable:
```
FASSET_BOT_CONFIG="./packages/fasset-bots-core/run-config/coston-bot-mysql.json"
```
4. In the `secrets.json` file, fill the `database` field with the username and password you created in MySQL.
5. In the `.env` file located at `fasset-bots/packages/fasset-bots-api`, you must update the `FASSET_BOT_CONFIG` variable:
```
FASSET_BOT_CONFIG="../fasset-bots-core/run-config/coston-bot-mysql.json"
```
6. If you have enabled alerts, you need to change the `extends` parameter in `alerts.json`:
```
"extends": "coston-bot-mysql.json"
```


### Running the Admin Console Backend

1. In the root of the repository, run the command:

```bash
yarn start_agent_api
```
or
```bash
yarn start_agent_api_debug
```
Expand All @@ -109,7 +138,7 @@ When you are finished using the UI and want to stop the server, press Ctrl + C.

!!! info

Run start_agent_api_debug as a service to maximize uptime for production use. Here, you have instructions to run the agent as a `systemd` service for [running the bot as a daemon](https://github.com/flare-labs-ltd/fasset-bots/blob/main/docs/systemd/systemd-service.md).
Run `start_agent_api` or `start_agent_api_debug` as a service to maximize uptime for production use. Here, you have instructions to run the agent as a `systemd` service for [running the bot as a daemon](https://github.com/flare-labs-ltd/fasset-bots/blob/main/docs/systemd/systemd-service.md).

### Setting Up the Admin Console

Expand Down
1 change: 1 addition & 0 deletions docs/user/fassets/depositing-collateral-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ It provides the following information:

--8<-- "./include/fassets/open-beta.md"

--8<-- "./include/fassets/prerequisites-user.md"
--8<-- "./include/fassets/setup-commandline.md"

### Configure User's Access Keys
Expand Down
1 change: 1 addition & 0 deletions docs/user/fassets/minting-redeeming-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Alternatively, you can [use the dapp to mint and redeem FAssets](./minting-redee

--8<-- "./include/fassets/open-beta.md"

--8<-- "./include/fassets/prerequisites-user.md"
--8<-- "./include/fassets/setup-commandline.md"

### Configure User's Access Keys
Expand Down
12 changes: 12 additions & 0 deletions include/fassets/prerequisites-agent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Prerequisites

You need a server with at least a minimum of 2 CPUs and 4GB RAM, or 2GB if the database is on a separate server.

You need knowledge of the following tools:

* [Git](https://git-scm.com/) version control system
* [Yarn](https://yarnpkg.com/) package manager
* A [wallet](../../user/wallets/index.md) configured for [Flare networks](../../dev/reference/network-config.md)
* Command-line terminal
* Code editor
* [MySQL](https://dev.mysql.com/doc/) server
11 changes: 11 additions & 0 deletions include/fassets/prerequisites-user.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Prerequisites

You need a server with at least a minimum of 2 CPUs and 4GB RAM, or 2GB if the database is on a separate server.

You need knowledge of the following tools:

* [Git](https://git-scm.com/) version control system
* [Yarn](https://yarnpkg.com/) package manager
* A [wallet](../../user/wallets/index.md) configured for [Flare networks](../../dev/reference/network-config.md)
* Command-line terminal
* Code editor
25 changes: 13 additions & 12 deletions include/fassets/setup-commandline.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
## Prerequisites
!!! warning

You need a server with at least a minimum of 2 CPUs and 4GB RAM, or 2GB if the database is on a separate server.
If you are using Windows, it is strongly recommended to use [Windows Subsystem for Linux, version 2](https://docs.microsoft.com/en-us/windows/wsl/about) (WSL 2).

You need knowledge of the following tools:
## Setting up the FAssets tools

* [Git](https://git-scm.com/) version control system
* [Yarn](https://yarnpkg.com/) package manager
* A [wallet](../../user/wallets/index.md) configured for [Flare networks](../../dev/reference/network-config.md)
* Command-line terminal
* Code editor
### Setting up After Testnet XRP Reset

!!! warning
!!! info

If you are using Windows, it is strongly recommended to use [Windows Subsystem for Linux, version 2](https://docs.microsoft.com/en-us/windows/wsl/about) (WSL 2).
This section is only for users using FAssets before the testnet XRP reset, so please [read more](https://flare.network/important-update-xrp-testnet-reset-fassets-beta-reset/).

## Setting up the FAssets tools
Suppose you previously ran the FAssets agent before the XRP testnet reset. You will need to skip the whitelisting part but still need to:

* pull the latest changes from the repository by `git pull`;
* build then with `yarn && yarn build`;
* installing the MySQL database and setting it up [following the guide](#setting-up-mysql-database) later in this document;
* create a new agent using the existing management address following the guide.

### Clone and Setup the Tools Repository

Expand Down Expand Up @@ -49,4 +50,4 @@ You need knowledge of the following tools:

```bash
cp .env.template .env
```
```
36 changes: 36 additions & 0 deletions include/fassets/setup-mysql.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
### Setting up MySQL Database

You must set up a MySQL database to continue with this process. For detailed instructions and additional guidance, refer to the official [MySQL documentation](https://dev.mysql.com/doc/).

You can find MySQL database connection parameters in the file listed as the value for the variable `FASSET_BOT_CONFIG` in the `.env` file.

Create a new user in MySQL that will be used by the `fasset-bots` to connect to the database. In this example, we will create a user with the username `fassetbot` and password `VerySafePassword`, which you must replace with a secure value.

!!! warning
You only need to create the user in the database and grant privileges to that user. Do not create the database.

1. Open your terminal or command prompt and login to MySQL database using the `mysql` command with the appropriate credentials:

2. Create a new user `fassetbot` in MySQL database using the "CREATE USER" command with the password "VerySafePassword":

```sql
CREATE USER 'fassetbot'@'localhost' IDENTIFIED BY 'VerySafePassword';
```

3. Grant all privileges on all databases to the user by using the `GRANT` statement:

```sql
GRANT ALL PRIVILEGES ON *.* TO 'fassetbot'@'localhost' WITH GRANT OPTION;
```

4. **Grant Privileges:**
After creating the user, you need to grant appropriate privileges to the user. Use the `GRANT` statement to give permissions to the user. For example, to grant all privileges on `fasset_bots` database:
```sql
GRANT ALL PRIVILEGES ON fasset_bots.* TO 'fassetbot'@'localhost' WITH GRANT OPTION;
```

5. Exit the MySQL database prompt by typing:

```bash
exit;
```

0 comments on commit 0c1beb2

Please sign in to comment.