This is a technical guide for the developers who wish to add/remove liquidity using cleos.
In order to add liquidity to a Bancor relay or remove liquidity from a Bancor relay, you will need to follow these steps:
- Add Liquidity (Buy the Relay Token) or Remove Liquidity (Sell the Relay Token)
- Turn your transactions into one atomic transaction
- Submit the transaction to the blockchain
We will use cleos to build the transactions for the sake of this example.
-
Adding / Removing Liquidity
To add or remove liquidity, you will need to build two separate transactions that execute the purchase or the sale of the relay tokens from each side of the relay (each connector).
Adding Liquidity - Buy the Relay Token
If you wish to purchase the Relay Token, follow this step.
You will need to run this call twice, once with each connector token
cleos -u http://node2.liquideos.com:8888 push action -j -d -s -x 3600 <CONNECTOR_TOKEN_CONTRACT> transfer '["<SENDER_ACCOUNT>","<BANCOR_NETWORK_CONTRACT>","<AMOUNT> <TOKEN_CODE>","<MEMO_VERSION>,<CONVERTER_ACCOUNT> <RELAY_SYMBOL>,<MIN_RETURN>,<SENDER_ACCOUNT>"]' -p <SENDER_ACCOUNT> |
Values and Definitions:
- <CONNECTOR_TOKEN_CONTRACT> - The contract of the token you want to use to make the purchase. It must be one of the defined connectors of the relay.
Example: for “BNT”, the contract is “bntbntbntbnt” - <SENDER_ACCOUNT> - The account name that will execute the transaction.
- <BANCOR_NETWORK_CONTRACT> - Use the account name for bancor network contract, “thisisbancor”
- <AMOUNT> - The amount of tokens you wish to use.
- <TOKEN_CODE> - The token code. For example, “BNT”
- <MEMO_VERSION> - Replace this with “1” for the current memo version
- <CONVERTER_ACCOUNT> - The contract name of the relevant converter.
For example, the account name for eosBLACK converter is “bancorc11111” - <RELAY_SYMBOL> - The relay token code you wish to receive. For example, BNTBLK is the relay token code for the BNT/eosBLACK relay
- <MIN_RETURN> - Restriction that is used to protect you from an unexpected price change. Indicate the minimum amount of tokens you wish to receive. Keep in mind that if the calculation result is below this amount, the transaction will fail and not get executed.
IMPORTANT: make sure both purchases are made with the equivalent value (EOS, USD, etc) of tokens to avoid creating an arbitrage opportunity on the converter.
Removing Liquidity - Sell the Relay Token
If you wish to sell the Relay Token, follow this step.
You will need to run this call twice, once for each connector token
cleos -u http://node2.liquideos.com:8888 push action -j -d -s -x 3600 <RELAY_TOKEN_CONTRACT> transfer '["<SENDER_ACCOUNT>","<BANCOR_NETWORK_CONTRACT>","<AMOUNT> <RELAY_SYMBOL>","<MEMO_VERSION>,<CONVERTER_ACCOUNT> <TOKEN_CODE>,<MIN_RETURN>,<SENDER_ACCOUNT>"]' -p <SENDER_ACCOUNT> |
Values and Definitions:
- <RELAY_TOKEN_CONTRACT> - The contract of the relay token you want to sell.
Example: for “BNTBLK”, the contract is “bancorr11111” - <SENDER_ACCOUNT> - The account name that will execute the transaction.
- <BANCOR_NETWORK_CONTRACT> - Use the account name for bancor network contract, “thisisbancor”
- <AMOUNT> - The amount of tokens you wish to use.
- <TOKEN_CODE> - The token code. For example, “BNT”
- <MEMO_VERSION> - Replace this with “1” for the current memo version
- <CONVERTER_ACCOUNT> - The contract name of the relevant converter.
For example, the account name for eosBLACK converter is “bancorc11111” - <RELAY_SYMBOL> - The relay token code you wish to receive. For example, BNTBLK is the relay token code for the BNT/eosBLACK relay
- <MIN_RETURN> - Restriction that is used to protect you from an unexpected price change. Indicate the minimum amount of tokens you wish to receive. Keep in mind that if the calculation result is below this amount, the transaction will fail and not get executed.
IMPORTANT: make sure both the transactions resulting with the equivalent value (EOS, USD, etc) of tokens to avoid creating an arbitrage opportunity on the converter.
Sample Response
The response you will receive should look like this (different data, do not use the code below)
{ <!-- Transaction #1 --> |
{ <!-- Transaction #2 --> < !-- you will need this section in step #2 --> < !-- end of section --> |
- Turn your transactions into one atomic transaction
In order to execute both transactions in a single atomic transaction, you should follow the following instructions and merge the previous 2 transactions (from step 1) into a single atomic one.
Make sure you have 2 transactions for the same action. Meaning, either 2 transactions to BUY relay tokens, or 2 transactions to SELL relay tokens.
Take the “actions” code from the second transaction, and append it after the “actions” code section of the first transaction in the following way:
{ <!--transaction #1--> <!-- Append the “actions” section from transaction #2 here --> { <!-- end of “actions” section from transaction #2 --> |
This will combine both transactions’ ”actions” into a single executable transaction that, once sent to the blockchain, will be mined atomically.
Save the atomic transaction as a .json file, so you can call it on the next step. For the sake of simplicity, we will refer to this file as atomic_tx.json.
-
Execute - Submit to the blockchain
Now that you have the above atomic transaction, you can use cleos to broadcast it to the blockchain.
Cleos code:
cleos -u http://node2.liquideos.com:8888 push transaction <absolute_path_to_tx.json> |
Values and Definitions:
<absolute_path_to_tx.json> - the full destination path to the file. Do not use “atomic_tx.json”.