-
@ nostrbird
2023-05-17 14:03:46Introduction: Howto Atomic Swap (trust-less way to swap using Hashed Timelock Contract (HTLC) a coin pair using AtomicDEX aka A-DEX CLI MM2 for an existing or new coin pair. It also show how to keep maker limitorder open and provide liquidity in the chosen pair. This article is only for advanced technical CLI user who have prior experience in windows or linux command line interface already for years and readers are responsible to use it at their own risk. For any new coin user must have fair technical knowledge to research n find its compatibility and thereafter conduct a successful "genesis swap" on mainnet pair with small funds by trial and error method first (not covered here) or contact whoever that coin team has done. Thereafter any swap limit maker order can be setup and kept open on mainnet for another taker order to match. Hence a new coin will unlikely to find a matching taker order than a listed coin pair unless more users knows the info and setup the same pair active taker limit orders. This is also to help in swapping a new coin that has undergone successful genesis swap and waiting to be formally listed. Any swap has a coin pair (2 coins) maker n taker order that must match for swap to complete (or else order can remain open/cancelled/refunded based on the situation).
Pre-requisites: One windows (W10) or linux (ubuntu18.04) host and 2 command line terminals with "curl" (2 hosts+2 wallets if practicing/trying/testing swap completion or genesis swap on new coin).
Any publicly reachable electrumx server endpoint info of listed or new tested coin can be used. or else need Coin Node aka coind + Electrumx Server for new coin fully synchronized to latest block on mainnet (not covered here).
"coins" file, but for unlisted and swap-tested coin obtain the info from tester manually and add/insert in "coins" file using some text editor, and also electrumx server url/ip:port ssl/tcp info from tester for enabling the coin step.
latest "mm2" for windows or linux - save and unzip in your custom folder location. "coins" file also in same folder and create MM2.json file in same folder as below step.
Prepare CLI tools Open you CLI 2 terminals from you admin console. First for mm2 and Second for curl http commands cd to folder where mm2 was unzip in before and "coins" file saved must have 3 items as below mm2 , MM2.json, coins (obtain manually "coins" file from whoever has tested this already) create MM2.json file suing notepad or nano as per example below: NEVER share/show SEED or password. "gui": "CLI-1", "netid": 7777, "rpc_password": "rpcpassword", "passphrase": "you twelve letter seed word obtain separately from other tool as needed", "allow_weak_password": false, "userhome": "/${HOME#\"/\"}", "dbdir": "/custom/dir/mm2/db"
Start mm2 in first terminal, and using second terminal as client for commands. (verify if MM2 is LISTEN-ing in TCP 7783 or another port) (windows n linux command syntax are bit different - below is for linux - windows are in dev doc site.) (change ticker symbol when operating in other coins accordingly) Enabling a coin curl --url "http://127.0.0.1:7783" --data '{"coin":"AVN", "method":"electrum", "servers":[{"url":"electrum-us.avn.network:50001"}], "required_confirmations":3, "requires_notarization":false, "mm2":1, "userpass":"rpcpasword"}' Enabling a coin in mm2 - example screenshot - MUST do for at least 2 coins - send funds to both addresses
Now open your main multi-coin or each coin wallet of above 2 or more coins u enabled and send funds to all in dust small amount for paying onchain tx fee (gas)
See "enabled" coins (if mm2 is stopped need to repeat above to re-enable) curl --url "http://127.0.0.1:7783" --data '{"userpass":"rpcpassword", "method":"get_enabled_coins"}' Checking Balance curl --url "http://127.0.0.1:7783" --data '{"userpass":"rpcpassword", "method":"my_balance","coin":"AVN"}'
Withdraw Entire Balance back to secure wallet - repeat for EACH coin you have balance left. Sign withdraw amount ALL balance curl --url "http://127.0.0.1:7783" --data '{"userpass":"rpcpassword", "method":"withdraw", "coin":"AVN", "to":"RSe235reJ1Rw8K4cdAzfhGPqDNZn9sxxxxxxxxxxx", "max":true"}' Now you see raw tx hex after signed Broadcast hex txid curl --url "http://127.0.0.1:7783" --data '{"userpass":"rpcpassword", "method":"send_raw_transaction","coin":"AVN","tx_hex":"RAW_TX_HERE"}' txid{xxxxxxxx-will-show-up-if-success- or show error exact reason}
Do above withdraw step just to be sure you can transfer fund back to you main wallet when swap done or cancelled Once tested then send again dust small amount 2+coins and larger amount of only the you want swap out Then proceed to do the actual swap command order setup as below.
Doing the swap🔄 Once all setup and tools are prepared as above it will be the time to do the actual swap command setup (practice/play with with small amount first with 2 hosts + 2 wallets if needed) then just leave your "maker limitorder" open n live on the mainnet.
BUY MAKER LimitOrder setup command example - *** most important command *** - manually calculate VOLUME and PRICE yourself which you would done in GUI terminal usually and read reference doc. base = coin you want to receive (wanted coin) , rel = coin you want to give away (desire to sell) say example 1BTE=10AVN ur desired price expectation curl --url "http://127.0.0.1:7783" --data '{"userpass":"rpcpassword","method":"buy","base":"AVN","rel":"BTE","volume":"10","price":"0.1"}'
Verify active swap(s) orders curl --url "http://127.0.0.1:7783" --data '{"userpass":"rpcpassword","method":"my_orders"}'
CANCEL all orders curl --url "http://127.0.0.1:7783" --data '{"userpass":"rpcpassword","method":"cancel_all_orders","cancel_by":{"type":"All"}}'
Check Order book of a pair curl --url "http://127.0.0.1:7783" --data '{"userpass":"rpcpassword","method":"orderbook","base":"AVN","rel":"BTE"}'
Verify ONGOING if any active swaps after match found and obtain swap-ID curl --url "http://127.0.0.1:7783" --data '{"userpass":"rpcpassword","method":"active_swaps"}'
N.B. windows curl syntax is different from linux bash. refer to dev doc site.
Leave terminals open+connected until swap is matched or order cancelled or hosts need to shutdown (redo all again). Some coins are listed as example BTC and BTC-segwit which has segwit enabled n listed.
***Special OPTIONAL step - Self Testing or practice only setup in another windows or linux "host" and only use test small amounts - all above steps and matching TAKER command as below *** SELL TAKER LimitOrder to match existing BUY order with same or higher price base = coin you want to give (desire to sell) , rel = coin you want to receive (desire to obtain)
curl --url "http://127.0.0.1:7783" --data '{"userpass":"rpcpassword","method":"sell","base":"AVN","rel":"BTE","volume":"10","price":"0.1"}' [do you math correctly to match price level of you own MAKER order]
IF successful swap has been completed - withdraw new obtained coins to secure wallet using above withdraw+broadcast commands. Failed swaps wait will get back "base" coin at later time when HTLC unlocked. Verify swap details from log anytime provided you know swap-ID in jsonformat curl --url "http://127.0.0.1:7783" --data '{"method":"my_swap_status","params":{"uuid":"d15552bb-e82d-44a0-86b0-10d443533de34"},"userpass":"rpcpassword"}'
Summary 1. Prepare you preferred windows or linux CLI 2 terminals 2. Get necessary software n tools 3. Start mm2 as server and issue curl commands from client terminal 4. Deposit enabled coins by send trading + fee funds to dex wallet 5. Start maker limit order (buy/sell) of you preferred coin pair n wait until matching taker order found 6. Leave mm2 terminal on and connected for order to be live n valid 7. Withdraw funds back to main secure wallet if successful swap happens or refunded or cancelled.
Conclusion Now any experienced cli user can do existing or new compatible coin start swap using A-DEX cli tool. At least 2 parties are needed to agree on price to match and complete a successful swap of a coin pair. Any new coin can be tested after finding correct blockchain parameters from github by trial n error between 2 wallets in test lab on 2 hosts on live mainnet. More people learn n uses n place LIMIT MAKER ORDERs on any pair and keeps it ON, more popular n liquid the coin pair becomes. Marketplace is where any trader meet to barter 🔄 exchange ! enjoy
Also can DM anytime if you need to add a new coin to the list of A-DEX urgently.
Thank You ! Hope this helps many with P2P swaps of any UTXO compatible coins ! ⚡️https://getalby.com/p/hulahula ⚡️ https://nowpayments.io/donation/bird ⚡️🙏💜
References : Github
Disclaimer : Above is not any recommendation or advice - Users are responsible for their own actions n mistakes if any in setup or usage. No way tool or procedure or author is liable for any error whatsoever.