Skip to content

Deploying an FAssets Agent#

The FAssets agents play an essential role and help to run the system, allowing tokens on blockchains that do not support smart contracts to be used trustlessly with smart contracts on the Flare blockchain.

This guide provides the following information:

  • How to set up the FAssets command line interface;
  • How to set up access keys for interacting with the Flare test and test XRP Ledger network;
  • How to set up an FAssets agent and provide collateral;
  • How to run the agent so FAssets system users can convert (mint and redeem) assets from the testnet XRP Ledger to the Flare test network and back.

Open Beta

The FAssets system is currently in the Open Beta period. During this phase, user-friendly tools are still being developed.

Some web browsers and ad blockers might prevent this functionality.

Alternatively, you can contact support@flarelabs.org.

Contract Addresses#

These are important FAssets smart contract addresses representing test tokens and notable system components, provided for your convenience during the Open Beta on the Coston test network. Please note that these addresses are exclusive to the Coston test network and unavailable on other Flare networks.

Test Tokens#

These are ERC-20 representations of test tokens to be used by the FAssets system:

FAssets System Contracts#

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:

Warning

If you are using Windows, it is strongly recommended to use Windows Subsystem for Linux, version 2 (WSL 2).

Setting up the FAssets tools#

Setting up After Testnet XRP Reset#

Info

This section is only for users using FAssets before the testnet XRP reset, so please read more.

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 later in this document;
  • create a new agent using the existing management address following the guide.

Clone and Setup the Tools Repository#

Info

If you set up an FAssets agent, bot or user, please use a separate directory for each role.

  1. Clone the repository and enter the working directory:

    git clone https://github.com/flare-labs-ltd/fasset-bots.git
    cd fasset-bots
    
  2. Switch to the open_beta branch:

    git checkout open_beta
    
  3. Install dependencies and build the project:

    yarn && yarn build
    

    Info

    Fresh installation can take more than 10 minutes, depending on if you have cached dependencies before.

  4. Copy the environment file from a template .env.template to .env:

    cp .env.template .env
    

    Setting up Database for FAssets Agent#

To proceed with this process, you must set up a database, either MySQL or PostgreSQL.

Setting up MySQL Database#

You have two options to set up a MySQL database: using Docker (preferred) or installing it manually.

Setting up MySQL Database with Docker

  1. Download and install Docker Desktop.
  2. Create a docker-compose.yml file in your directory, add the following lines, and change the value of VerySafePassword according to your security standards:
    services:
      mysql:
        image: mysql:8.0
      environment:
        MYSQL_ROOT_PASSWORD: 'root'
        MYSQL_DATABASE: 'fasset_bots'
        MYSQL_USER: 'fassetbot'
        MYSQL_PASSWORD: 'my1beta2password3'
      volumes:
        - ./data:/var/lib/mysql
        - ./init.mysql.sql:/docker-entrypoint-initdb.d/init.mysql.sql
      ports:
        - "3306:3306"
      healthcheck:
        test: ['CMD', 'mysqladmin', 'ping', '-h', '127.0.0.1', '-u', 'root', '-p$MYSQL_ROOT_PASSWORD']
        timeout: 20s
        retries: 10
    
    volumes:
      mysql_data:
    
  3. Create a file named init.mysql.sql in the same directory, add the following lines, and change the value of VerySafePassword according to your security standards:
    CREATE USER IF NOT EXISTS 'fassetbot'@'%' IDENTIFIED BY 'my1beta2password3';
    GRANT ALL PRIVILEGES ON *.* TO 'fassetbot'@'%' WITH GRANT OPTION;
    GRANT ALL PRIVILEGES ON fasset_bots.* TO 'fassetbot'@'%' WITH GRANT OPTION;
    
  4. Start the MySQL server as a Docker container by running docker-compose up -d. After the MySQL database is started, it will continue to run in the background every time you run the agent.
  5. In the secrets.json file, add this block to the list to set the database user and password, and change the value of password to the same password you have been using.
    "database": {
        "user": "fassetbot",
        "password": "my1beta2password3"
    }
    

Setting up MySQL Database Manually

To install the MySQL database manually, refer to the official MySQL documentation.

The MySQL database connection parameters are listed in the file 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":

    CREATE USER 'fassetbot'@'localhost' IDENTIFIED BY 'VerySafePassword';
    
  3. Grant all privileges on all databases to the user by using the GRANT statement:

    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 the fasset_bots database:

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

  5. Exit the MySQL database prompt by typing:

    exit;
    

Setting up PostgreSQL Database#

To set up a PostgreSQL database, you have two options: using Docker (preferred) or installing it manually.

Setting up PostgreSQL Database with Docker

  1. Download and install Docker Desktop.
  2. Create a docker-compose.yml file in your directory, add the following lines, and change the value of VerySafePassword according to your security standards:

    services:
      postgres:
        image: postgres:15
        container_name: postgres_db
        environment:
          POSTGRES_USER: fassetbot
          POSTGRES_PASSWORD: my1beta2password3
          POSTGRES_DB: fasset_bots
        ports:
          - "5432:5432"
        volumes:
          - pgdata:/var/lib/postgresql/data
          - ./init.postgresql.sql:/docker-entrypoint-initdb.d/init.postgresql.sql
        healthcheck:
          test: ["CMD-SHELL", "pg_isready -U $POSTGRES_USER -d $POSTGRES_DB -h 127.0.0.1"]
          timeout: 20s
          retries: 10
    
    volumes:
      pgdata:
    

  3. Start the PostgreSQL server as a Docker container by running docker-compose up -d. After the PostgreSQL database is started, it will continue to run in the background every time you run the agent.

  4. In the secrets.json file, add this block to the list to set the database user and password, and change the value of password to the same password you have been using.
    "database": {
        "user": "fassetbot",
        "password": "my1beta2password3"
    }
    
  5. Modify the FASSET_BOT_CONFIG variable in the .env file located in the root of the repository.
    FASSET_BOT_CONFIG="./packages/fasset-bots-core/run-config/coston-bot-postgresql.json"
    

Setting up PostgreSQL Database Manually

To install the PostgreSQL database manually, refer to the official PostgreSQL documentation.

You can find PostgreSQL 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 PostgreSQL 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 PostgreSQL database using the psql command with the appropriate credentials.

  2. Create a new user fassetbot in the PostgreSQL database command with the password "VerySafePassword" and grant the superuser privileges:

    CREATE ROLE fassetbot WITH SUPERUSER LOGIN PASSWORD 'VerySafePassword';
    
  3. Exit the PostgreSQL database prompt by typing:

    exit;
    
  4. Modify the FASSET_BOT_CONFIG variable in the .env file located in the root of the repository.

    FASSET_BOT_CONFIG="./packages/fasset-bots-core/run-config/coston-bot-postgresql.json"
    

Configure the Access Keys#

The FAsset agents operate with multiple keys for the Flare and underlying network chains. You should generate these keys to make the agent operational.

  1. Create or use an existing management wallet that will be your agent's management address. Fund this wallet with some CFLR so you can pay the gas fees for various smart contract calls using the Flare faucet.

  2. Generate the secrets using this command by replacing the MANAGEMENT_WALLET_ADDRESS with your cold wallet address:

    yarn key-gen generateSecrets --user --agent MANAGEMENT_WALLET_ADDRESS --other -o secrets.json
    

    Info

    This command can only be executed once, after which all secret keys will be generated. You must use a separate directory for each role you want to perform: agent, bot, or minter and redeemer.

    Warning

    • The addresses in secrets.json are for hot wallets and should not hold large token amounts, as their private keys are on an always-online machine. Keep your main account in an offline wallet and transfer funds as needed.
    • As soon as you create the secrets.json file, back it up, and remember to back it up again whenever you add new keys. Store the backup securely, preferably on an external drive in a physical vault, as unauthorized access can compromise the agent. You need to make regular backups only if you make changes.
  3. Follow the whitelisting process to grant your agent's management address access to the FAssets system. While waiting for approval, you can proceed to the next steps.

  4. The secrets.json file contains the owner.native.address field, representing the Flare account responsible for funding agent vaults and covering gas fees for smart contract calls. Please ensure this wallet has enough CFLR tokens to cover gas fees for smart contract calls. You can obtain CFLR tokens from the Flare faucet.

  5. Prevent other users from reading the secrets.json file:

    chmod 600 secrets.json
    
  6. Fill the native_rpc, xrp_rpc and indexer fields in the secrets.json file with the following values:

    "native_rpc": "AavSehMLhcgz3crQHH5YJ3Rt8GMQGdV9aViGilADXGnTcjij",
    "xrp_rpc": "4tg3AxysaZodxTqsCtcMnBdBIEkR6KDKGTdqBEA8g9MKq4bH",
    "indexer": "123456",
    

    Info

    These values apply only to the Coston Testnet 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 or PostgreSQL should follow these steps:

  1. Install MySQL or PostgreSQL server.
  2. Create a user in the MySQL or PostgreSQL database.
  3. Modify the FASSET_BOT_CONFIG variable in the .env file located in the root of the repository.

    • MySQL database:

      FASSET_BOT_CONFIG="./packages/fasset-bots-core/run-config/coston-bot-mysql.json"
      

    • PostgreSQL database:

      FASSET_BOT_CONFIG="./packages/fasset-bots-core/run-config/coston-bot-postgresql.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 the values you used when creating the user in the MySQL or PostgreSQL database:

    "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. This ensures only authorized participants interact with the system, maintaining a secure and controlled environment for testing and platform improvement. The whitelisting process will be removed after the opening beta.

  1. Find your agent owner address, which is the value from the secrets.json file in the owner.management.address field.
  2. Use the FlareFAssetsBot Telegram channel, specifically designed for registration, and provide the necessary information, including your agent name, description, and a link to your icon.
  3. Enter the information and confirm, and the Telegram bot will inform you about the successful process.
  4. You need to wait for Flare support engineers to approve registrations and issue test assets such as Coston Flare (CFLR), testUSDC, testUSDT, and testETH assets, which will be sent to your owner.management.address. While you wait, you can continue with the rest of this guide.
  5. If the information you entered is correct, the Telegram Bot will notify you that you have been whitelisted for the FAssets Open Beta.

Check Whitelist Status#

Checking if your agent's management address has been whitelisted is a straightforward process. Follow these steps:

  1. Navigate with the Coston block explorer to AgentOwnerRegistry smart contract on address 0xDb6c11b8D074D4488f5fFd0129AA5F91C4f00fb6 and open the Read Contract tab.
  2. Connect your wallet with any address to the block explorer so you can gain access to read functions from the smart contract.
  3. Execute the isWhitelisted function with the value of owner.management.address from the secrets.json file. This function returns bool: true for whitelisted or false for not whitelisted.

Setting Up the Agent#

Configure the Native Address#

Configuring the native address links your agent's work address to the management address and grants access.

  1. Navigate with the Coston block explorer to AgentOwnerRegistry smart contract on address 0xDb6c11b8D074D4488f5fFd0129AA5F91C4f00fb6 and open the Write Contract tab.

  2. Connect the cold wallet you used to generate the access keys.

  3. Register the work address by executing the setWorkAddress function with the value of owner.native.address from the secrets.json file.

Configure the Agent for XRP#

You need to set up your agent's parameters like name, collateral, and fund with underlying assets.

  1. Prepare the agent settings tmp.agent-settings.json file:

    yarn agent-bot --fasset FTestXRP create --prepare
    
  2. Choose a suffix for your agent's collateral pool and fill in the poolTokenSuffix field in the tmp.agent-settings.json file with it. The poolTokenSuffix should only include uppercase letters, numbers, and the - symbol. This suffix will be used for the FAsset Collateral Pool Token. For example, if you use MY-ALPHA-AGENT-1, it would be FCPT-TXRP-MY-ALPHA-AGENT-1.

  3. Choose one of the stable tokens (testUSDT or testUSDC) or wrapped ETH in vaultCollateralFtsoSymbol to back up the agent vault collateral.

  4. In the secrets.json file, the owner.testXRP.address field is the underlying testnet XRP Ledger account that pays the underlying chain's transaction fees. Activate your underlying XRP Ledger account by sending at least 100 test-XRP to it by using one of the XRP Ledger testnet faucets:

  5. Create the agent by specifying the FAsset and agent settings, noting that this operation can take up to 10 minutes because the FAssets verifies the underlying assets. This command will print out your agent's address.

    yarn agent-bot --fasset FTestXRP create tmp.agent-settings.json
    

Deposit Collateral#

To make your newly created agent public, it must hold enough collateral to mint one lot. This means its agent vault contract needs to be funded with the two collaterals (CFLR and a stablecoin or wrapped ETH) held by your owner.native.address. Flare support sends test assets to your owner.management.address, so remember to move these funds to the owner.native.address.

You have two options: either deposit the vault collateral and buy pool collateral separately or use the system function to calculate the needed collateral for you.

Deposit Collaterals Together#

To deposit both vault and pool collateral together and let the tool calculate the minimum required collateral to back the lots, you can use the depositCollateral function to the agent, specifying your created agent address in the AGENT_ADDRESS and lot size in the LOTS:

yarn agent-bot depositCollaterals AGENT_ADDRESS LOTS --fasset FTestXRP

Deposit Collateral Separately#

  1. Deposit enough vault collateral to the agent specifying your created agent address in the AGENT_ADDRESS and the amount of the stablecoin or wrapped ETH in the AMOUNT field.

    yarn agent-bot depositVaultCollateral AGENT_ADDRESS AMOUNT --fasset FTestXRP
    
  2. Buy enough pool collateral for the agent specifying your agent's address in the AGENT_ADDRESS and the amount of the CFLR in the CFLR_AMOUNT field.

    yarn agent-bot buyPoolCollateral AGENT_ADDRESS CFLR_AMOUNT --fasset FTestXRP
    

Register the Agent as Available#

You need to make your agent available to mint and redeem FAssets.

  1. Register your agent as available to the network by executing this command replacing the AGENT_ADDRESS with your agent address:

    yarn agent-bot enter AGENT_ADDRESS --fasset FTestXRP
    

    Info

    Note that your agent owner's Flare account has to be whitelisted via the FlareFAssetsBot Telegram channel. Otherwise, it will fail.

  2. If you deposited enough collateral, you should see that your agent has at least one lot available by running the command.

    yarn user-bot agents --fasset FTestXRP
    

If you don't have available lots, check if the vault and pool collaterals are enough.

Upgrade Your Agent to Support BTC#

  1. Repeat the steps to clone and set up the Tools repository.
  2. Generate a new secrets.json file using this command by replacing the MANAGEMENT_WALLET_ADDRESS with your cold wallet address:

    yarn key-gen generateSecrets --user --agent MANAGEMENT_WALLET_ADDRESS --other -o secrets.json
    
  3. Make a copy of your old secrets.json file, open it, and replace the owner and user testBTC addresses and private keys from the generated secrets.json in the previous step. A new instance with your old secrets.json file that includes your BTC addresses is created.

  4. In the FlareFAssetsBot Telegram channel, run /register_btc_address ADDRESS, where ADDRESS is your TestBTC address in the secrets.json file. Your TestBTC address is registered, an amount of TestBTC is sent to the address, and your API key is returned.
  5. In your secrets.json file, add the btc_rpc parameter to the apiKey section.
  6. Prepare the agent for FTestBTC:

    yarn agent-bot --fasset FTestBTC create --prepare
    
  7. Choose a suffix for your agent's collateral pool and fill in the poolTokenSuffix field in the tmp.agent-settings.json file with it. The poolTokenSuffix should only include uppercase letters, numbers, and the - symbol. This suffix will be used for the FAsset Collateral Pool Token. For example, if you use MY-ALPHA-AGENT-1, it would be FCPT-TBTC-MY-ALPHA-AGENT-1.

  8. If you need more TestBTC, request more from the TestBTC faucet.

  9. Top up your owner.testBTC address from secrets.json with at least 0.5 TestBTC.
  10. Create the agent by specifying the FAsset and agent settings, noting that this operation can take up to 10 minutes because the FAssets verifies the underlying assets. This command will print out your agent's address.

    yarn agent-bot --fasset FTestBTC create tmp.agent-settings.json
    
  11. Deposit collaterals for your agent:

    yarn agent-bot depositCollaterals AGENT_ADDRESS LOTS --fasset FTestBTC
    
  12. Register your agent as available to the network by executing this command replacing the AGENT_ADDRESS with your agent address:

    yarn agent-bot enter AGENT_ADDRESS --fasset FTestBTC
    

Running the Agent#

The agent bot responds to all requests made to the agent vaults you have created. To run the agent bot, you need to run the following command:

yarn run-agent

When you want to stop the server, press Ctrl + C.

Info

Run the run-agent 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.

Verifying Collateral Pool Smart Contracts#

Verification of a smart contract on a block explorer allows future users of the smart contract to inspect the Solidity source code instead of the bytecode, greatly improving the security and transparency of the ecosystem. Follow these steps to upload the source code for the Collateral Pool and Collateral Pool Token smart contracts, verifying them on the block explorer.

  1. Execute the FAssets system information command to determine your collateral pool smart contract address.

    For XRP, run:

    yarn agent-bot info AGENT_ADDRESS --fasset FTestXRP
    

    For BTC, run:

    yarn agent-bot info AGENT_ADDRESS --fasset FTestBTC
    

    Look for the value of the Agent collateral pool field and copy the address, as shown in the following example for XRP.

    Tokens:
       Native token: CFLR
       Wrapped native token: WCFLR
       FAsset token: FTestXRP
       Underlying token: testXRP
       Vault collateral token: testETH
       Collateral pool token: FCPT-SIMX-KGR-25061612
    Network exchange rates:
       CFLR/USD: 0.033
       testETH/USD: 3800
       testXRP/USD: 0.53
    Agent mint and collateral:
       Status: healthy
       Public: true
       Free lots: 10
       Minted: 0 FTestXRP  (0 lots)
       Reserved: 0 FTestXRP  (0 lots)
       Redeeming: 0 FTestXRP  (0 lots)
       Vault CR: <inf>  (minCR=1.4, mintingCR=1.6)
       Pool CR: <inf>  (minCR=2, mintingCR=2.4)
       Free vault collateral: 0.046863112858734529 testETH  (10 lots)
       Free pool collateral: 8071.878095157464265083 WCFLR  (10 lots)
    Lots:
       Lot size: 20 testXRP
       Lot vault collateral: 0.004463157894736842 testETH
       Lot pool collateral: 770.909090909090909091 CFLR
    Agent address (vault): 0xa6d7dF2d68b4b687d7408Cd613192103DBdA1F33
       Balance: 0.046863112858734529 testETH
       Balance: 8071.878095157464265083 FCPT-SIMX-KGR-25061612
    Agent collateral pool: 0x5Bf5cD267F5a5185d0d91567979CCa397A2E504a
       Balance: 8071.878095157464265083 WCFLR
       Collected fees: 0 FTestXRP
    Agent vault underlying (testXRP) address: r4aiumSs3xrSeeeQ9frhrDkhJ6dL1Sr1iL
       Actual balance: 10 testXRP
       Tracked balance: 0 testXRP
       Required balance: 0 testXRP
       Free balance: 0 testXRP
    Agent owner management address: 0x6827101103BE87eDadf77202F8973c5046245401
       Balance: 90.4216184475 CFLR
       Balance: 0 testETH
    Agent owner work address: 0xEfA4D9561fEc607eAe35D76a8034d9dBBe730449
       Balance: 4105.334310744331909805 CFLR  (5 lots)
       Balance: 0.042177240174410518 testETH  (9 lots)
    Agent owner underlying (testXRP) address: rndED5w8xQ2sVC2hT5J5e8GTfxouRcKfjR
       Balance: 40.27988 testXRP
    
  2. Clone the FAsset repository in a new directory and enter it:

    git clone https://github.com/flare-labs-ltd/fassets.git
    cd fassets
    
  3. Switch to the open_beta branch:

    git checkout open_beta
    
  4. Install dependencies and build the project:

    yarn && yarn c
    

    Info

    A fresh build can take more than 10 minutes, depending on if you have cached dependencies before.

  5. Verify the Collateral Pool and Collateral Pool Token smart contracts by running the following command and specifying the collateral pool address that you obtained in the first step as AGENT_POOL_ADDRESS:

    yarn verify-collateral-pool-coston AGENT_POOL_ADDRESS
    

    Verifying the smart contract on the blockchain will take a minute or two, and you should get an output stating that Collateral Pool and Collateral Pool Token smart contracts have been verified. It should be similar to this:

    Verifying CollateralPool at 0x5Bf5cD267F5a5185d0d91567979CCa397A2E504a
    Successfully submitted source code for contract
    contracts/fasset/implementation/CollateralPool.sol:CollateralPool at 0x5Bf5cD267F5a5185d0d91567979CCa397A2E504a
    for verification on the block explorer. Waiting for verification result...
    
    Successfully verified contract CollateralPool on the block explorer.
    https://coston-explorer.flare.network/address/0x5Bf5cD267F5a5185d0d91567979CCa397A2E504a#code
    
    Verifying CollateralPoolToken at 0x63937c0AD9506C61B2Fca6103E1828E2fcEf8a08
    Successfully submitted source code for contract
    contracts/fasset/implementation/CollateralPoolToken.sol:CollateralPoolToken at 0x63937c0AD9506C61B2Fca6103E1828E2fcEf8a08
    for verification on the block explorer. Waiting for verification result...
    
    Successfully verified contract CollateralPoolToken on the block explorer.
    https://coston-explorer.flare.network/address/0x63937c0AD9506C61B2Fca6103E1828E2fcEf8a08#code    
    

Visit the original Flare block explorer at the address of the contract you just verified:

https://coston-explorer.flare.network/address/{AGENT_POOL_ADDRESS}

And check that the Code tab has a green checkmark next to it.