On this page

latest contributor to this doc

Last Edit:

@gcharang

How To Become a Liquidity Provider on Komodo DeFi Framework

The following tutorial introduces the reader to a simple method to become a liquidity provider on the main network of the Komodo DeFi Framework software.

We recommend that the user have a Virtual Private Server (VPS) with at least the following specifications.

  • 2 vCPU
  • 4GB RAM
  • OS: Ubuntu 18.04 (Preferably a clean installation)

If the user prefers to use computer hardware at home, instead of a VPS, we recommend that the user have a very strong Internet connection. We also recommend that the user have a competitive hardware setup running on Ubuntu 18.04.

  • Internet speed - at least 1 MBPS
  • RAM - at least 4 GB
  • Processor - at least i5 or equivalent

You can get the Komodo DeFi Framework API binary by downloading pre-compiled versions from the official repository or by building from source.

We will create ~/komodo-defi-framework/target/debug directory for compatibility with building from source method.

You can get the latest release of the Komodo DeFi Framework API binary from the komodo-defi-framework/releases page on Github. Download and extract it to ~/komodo-defi-framework/target/debug.

For example:

mkdir -p ~/komodo-defi-framework/target/debug
cd ~/komodo-defi-framework/target/debug
wget https://github.com/KomodoPlatform/komodo-defi-framework/releases/download/beta-2.1.4315/mm2-9fe6e9402-Linux-Release.zip
unzip mm2-9fe6e9402-Linux-Release.zip

Then you can proceed to download the coins configuration file.

If you decide to build from source, please follow the Build Komodo DeFi Framework API from source guide

cd ~/komodo-defi-framework/target/debug ; wget https://raw.githubusercontent.com/KomodoPlatform/coins/master/coins

Navigate to the directory: ~/komodo-defi-framework/target/debug

cd ~/komodo-defi-framework/target/debug

Download the scripts used to start and interact with the Komodo DeFi Framework API.

git clone https://github.com/gcharang/mm2scripts

Copy those scripts to the current directory.

cp mm2scripts/* .

The user must create a seed phrase that will serve as a type of password for accessing all coins in the user's digital wallet.

Various tools are available in the cryptocurrency community to create a secure seed phrase. One available method is to use the automated procedure that is included in the Komodo Desktop Wallet.

Backup these 24 words carefully. They provide access to the coins that are stored in the addresses created by the Komodo DeFi Framework API.

To learn more about creating secure phrases, read this linked content on the Bitcoin wiki.

We are about to place the seed phrase in the start.sh file. Failure to properly execute this step can lead to a loss of your funds.

Open the start.sh file in the current directory using the nano text-editor.

nano start.sh

Replace the value REPLACE_TRADING_WALLET_PASSPHRASE in the file with the seed phrase.

Keep the nano software and start.sh file open.

Separately, create an additional password for Remote Procedure Call (RPC) access.

This should be a simple password that is sufficiently random, has at least eight digits, and is based on numbers and letters.

Replace the text "RPC_UserP@SSW0RD" with your RPC user password.

The below example shows how to launch the Komodo DeFi Framework API software with a 24-word passphrase. This is provided for demonstration purposes only. You should NOT copy/paste this example. Type this command in manually to your terminal, and MAKE SURE TO CHANGE THE PASSPHRASE TO YOUR OWN.

Failure to properly manage your passphrase can (and likely will) result in lost funds.

Hit Ctrl + X to save and exit.

Observe the bottom of the terminal for any prompts. Hit y when asked to save. When the file name is shown, hit Enter if the name matches start.sh.

Replace the text RPC_UserP@SSW0RD with the same password used in the start.sh file.

userpass=GlHjhvYlev8fh8xZgSB

We now have basic scripts to use the Komodo DeFi Framework API as a liquidity provider.

./start.sh

Starting the Komodo DeFi Framework API in the above manner causes the passphrase to be visible to other programs such as htop.

To avoid this issue, there is an alternate method that uses a json file to replace the command line parameters

To use it:

cp MM2_sample.json MM2.json
nano MM2.json

Edit the values of the keys "rpc_password" and "passphrase" with the same values used in the start.sh file. Save and close the file.

To start the Komodo DeFi Framework API:

stdbuf -oL nohup ./mm2

Open a new terminal and navigate to the directory: ~/komodo-defi-framework/target/debug

cd ~/komodo-defi-framework/target/debug

./KMDconnect.sh
{"address":"RG1yR8UGqyHmRBcrwAakUEi8u1AC5jNABY","balance":"0","coin":"KMD","result":"success"}

Take note of the address.

We recommend here that you make sure that the public address above matches the address generated by the same passphrase, when entered into the Komodo wallet or the Verus Desktop wallet.

./LTCconnect.sh
{"address":"LRxjbptpKojFbywpe8avejShLx4sYvKSBZ","balance":"0","coin":"LTC","result":"success"}

Again, a best practice here is to ensure that the public address above matches with the address in the Komodo Wallet or Verus Desktop wallets.

To connect to a coin network other than KMD or LTC, first make sure that the coin's details are present in the coins file you downloaded. Also make sure that the file has the property "mm2": 1.

Next, create a new file named "COINNAMEconnect.sh" and add the following contents; replace the characters < and > and all text between them with values from your coins file. (For example: <text where 7771 should be inserted> becomes 7771.)

POST
electrum
{
  "userpass": "RPC_UserP@SSW0RD",
  "method": "electrum",
  "coin": "<COIN TICKER>",
  "servers": [
    {
      "url": "<url of electrum server 1>"
    },
    {
      "url": "<url of electrum server 2>"
    }
  ]
}

Make the file executable

cd ~/komodo-defi-framework/target/debug
chmod +x COINNAMEconnect.sh

Execute the command ./COINNAMEconnect.sh to instruct your Komodo DeFi Framework API instance to connect to the coin's electrum server.

Display the KMD/LTC Orderbook.

See this linked document for an explanation of the output.

./orderbook.sh KMD LTC | jq '.'

Display the LTC/KMD Orderbook.

./orderbook.sh LTC KMD | jq '.'

In this example, we sell KMD for LTC.

To achieve this, we first fund the KMD address created by the Komodo DeFi Framework API.

Use the following command to find the address and check the balance.

./mybalance.sh KMD
{"address":"RFmQiF4Zbzxchv9AG6dw6ZaX8PbrA8FXAb","balance":"2.98","coin":"KMD"}

Execute the following command to sell 2 KMD at the price of 1 KMD = 0.013 LTC.

./place_order.sh KMD LTC 0.013 2 | jq '.'
{
  "result": {
    "base": "KMD",
    "created_at": 1563800688606,
    "matches": {},
    "max_base_vol": "2",
    "min_base_vol": "0",
    "price": "0.013",
    "rel": "LTC",
    "started_swaps": [],
    "uuid": "d375fce0-5d7c-4d1d-9cfa-6177c78df44a"
  }
}

Check the status of an order by referring to its uuid.

./order_status.sh 6621efd5-72dd-422c-89a8-7b655b744ead | jq '.'
{
  "order": {
    "available_amount": "2",
    "base": "KMD",
    "cancellable": true,
    "created_at": 1563800688606,
    "matches": {},
    "max_base_vol": "2",
    "min_base_vol": "0",
    "price": "0.013",
    "rel": "LTC",
    "started_swaps": [],
    "uuid": "d375fce0-5d7c-4d1d-9cfa-6177c78df44a"
  },
  "type": "Maker"
}

After someone accepts the order and your trade is finished, the coins received (LTC) and the coins leftover (KMD) can be withdrawn.

Execute the following command to withdraw 0.97 KMD to the address RUFf4de7gZE7sp5vPcxaAsvv6j79ZbQgAu.

./withdraw.sh KMD RUFf4de7gZE7sp5vPcxaAsvv6j79ZbQgAu 0.97 | jq '.'
{
  "tx_hex": "0400008085202f8901c25ecb12f5fc17120bf92ed18ff71754b5f58e6eece2fba44fc114f14176df04010000006a4730440220732047807944afcb062f5dc7af87fe5b9979e447cd235ef1b130e50008c3d51a02201b232814bcee9c0b5a29aa24d453e493cd121a0e21d94c0e84476de0a15e74a101210217a6aa6c0fe017f9e469c3c00de5b3aa164ca410e632d1c04169fd7040e20e06ffffffff02401ac805000000001976a914d020156e7d0fead249cfb5a458952ae941ac9f9e88ac5800fb0b000000001976a9144726f2838fc4d6ac66615e10604e18926e9b556e88ac06a5355d000000000000000000000000000000",
  "tx_hash": "e07709088fa2690fdc71b43b5d7760689e42ca90f7dfb74b18bf47a1ad94c855",
  "from": ["RFmQiF4Zbzxchv9AG6dw6ZaX8PbrA8FXAb"],
  "to": ["RUFf4de7gZE7sp5vPcxaAsvv6j79ZbQgAu"],
  "total_amount": 2.98,
  "spent_by_me": 2.98,
  "received_by_me": 2.00999,
  "my_balance_change": -0.97001,
  "block_height": 0,
  "timestamp": 1563798788,
  "fee_details": {
    "type": "Utxo",
    "amount": 1e-5
  },
  "coin": "KMD",
  "internal_id": ""
}

Copy the "tx_hex" value from the above response and send it to the network using the sendrawtransaction.sh script.

./sendrawtransaction.sh KMD 0400008085202f8901c25ecb12f5fc17120bf92ed18ff71754b5f58e6eece2fba44fc114f14176df04010000006a4730440220732047807944afcb062f5dc7af87fe5b9979e447cd235ef1b130e50008c3d51a02201b232814bcee9c0b5a29aa24d453e493cd121a0e21d94c0e84476de0a15e74a101210217a6aa6c0fe017f9e469c3c00de5b3aa164ca410e632d1c04169fd7040e20e06ffffffff02401ac805000000001976a914d020156e7d0fead249cfb5a458952ae941ac9f9e88ac5800fb0b000000001976a9144726f2838fc4d6ac66615e10604e18926e9b556e88ac06a5355d000000000000000000000000000000
{
  "tx_hash": "e07709088fa2690fdc71b43b5d7760689e42ca90f7dfb74b18bf47a1ad94c855"
}

The above tx_hash can be searched for in an explorer to check the status of the withdraw.

To stop the Komodo DeFi Framework API, use the stop.sh script.

./stop.sh
{
  "result": "success"
}

./myorders.sh  | jq .
{
  "result": {
    "maker_orders": {
      "d82357c5-22c9-483d-bf3d-1d09d0d921bf": {
        "available_amount": "2",
        "base": "KMD",
        "cancellable": true,
        "created_at": 1563797287088,
        "matches": {},
        "max_base_vol": "2",
        "min_base_vol": "0",
        "price": "0.013",
        "rel": "LTC",
        "started_swaps": [],
        "uuid": "d82357c5-22c9-483d-bf3d-1d09d0d921bf"
      }
    },
    "taker_orders": {}
  }
}

Cancel an order by referring to its uuid.

./cancel_order.sh 6621efd5-72dd-422c-89a8-7b655b744ead
{
  "result": "success"
}