KomodoPlatform / komodo-defi-framework

This is the official Komodo DeFi Framework repository
https://komodoplatform.com/en/docs/komodo-defi-framework/
103 stars 94 forks source link

Add support for SLP tokens on the BCH network (Bitcoin colored coins) #701

Closed damascene closed 1 year ago

damascene commented 4 years ago

SLP tokens are Bitcoin colored coins on the BCH network. SLP stands for Simple Ledger Protocol. SLP tokens are growing in popularity, Tether is now available as a Standard Ledger Protocol token on the Bitcoin Cash network.

image

SLP tokens are cheap to trade, they benefit from BCH simple and low transfer cost ($0.0012). I've noticed that most stable currencies on the AtomicDEX are Ethereum based which makes it a bit expensive to trade, I think SLP tokens can solve this issue and benefit the project.

I'm opening this issue after a suggestion by KomodoWorld on reddit.

artemii235 commented 3 years ago

I have just sent and spent USDF HTLC on BCH testnet using MM2 code only:

  1. Payment - https://explorer.bitcoin.com/tbch/tx/afa7785fdb0e49e649aa9b6467fa183c8185c398095baac2c11df50175a7f92b
  2. Spend using secret - https://explorer.bitcoin.com/tbch/tx/06f38595a2d5d23df8a81a0d744ac3a70c3e46a01efa64a4be862b9d582167b0

I'm focusing now on the RICK/USDF order matching and swap demo. Will provide a more detailed progress report next week.

artemii235 commented 3 years ago

PS link to the code: https://github.com/KomodoPlatform/atomicDEX-API/commit/a000c1c377cc943607743df233c31c37f5e27622

damascene commented 3 years ago

@artemii235 thank you for keep us updated on the progress. I'm happy to see successful tests.

molecular commented 3 years ago

Does this mean we can assume this will work? At what point would we be able to list SLP token/BCH pairs and what are the conditions for "listing"?

artemii235 commented 3 years ago

I have done the first RICK/FUSD swap today! Taker fee - https://testnet.simpleledger.info/tx/c5f46ccc5431687154335d5b6526f1b9cfa961c44b97956b7bec77f884f56c73 Maker payment - https://rick.explorer.dexstats.info/tx/24f8f79a71c9b608c05876ff0bd32f1c3466e6caf6fa93ab8104d3933631812e Taker payment - https://testnet.simpleledger.info/tx/e935160bfb5b45007a0fc6f8fbe8da618f28df6573731f1ffb54d9560abb49b2 Taker payment spent by the maker - https://testnet.simpleledger.info/tx/62af7742930d62f02edca0dbb5b042bba7d063ccac6623bca45aff4b0145419c Maker payment spent by the taker - https://rick.explorer.dexstats.info/tx/1241b3424785b585da804c9c5a707201e0faab8a252f5baa74f089169c37f487

Code is in the https://github.com/KomodoPlatform/atomicDEX-API/tree/mm2.1-slp-swap branch.

The swap demo was delayed a bit since I had to switch to some bug hotfixes. Links to SLP transactions are provided from https://testnet.simpleledger.info as https://explorer.bitcoin.com/tbch seems to be down for a while.

@molecular

Does this mean we can assume this will work?

Yes, we were already sure it would work when HTLC proof of concept was implemented.

At what point would we be able to list SLP token/BCH pairs and what are the conditions for "listing"?

As per Flipstarter, the implementation time is about 6 months and it's going as planned as of now. Full integration into GUIs should be available in September/October this year. Listing in AtomicDEX desktop will be free of charge, mobile listing for five SLP tokens will be also free if their teams provide liquidity on the DEX. For others, there will be a listing fee that is determined case by case.

artemii235 commented 3 years ago

The SLP integration is now ready for alpha testing on the BCH testnet in CLI mode. I've also opened the issue in the desktop GUI repo, the alpha should be released by the end of August or early September (https://github.com/KomodoPlatform/atomicDEX-Desktop/issues/1168). I will post a message here when it is ready.

Please note that the following features are unavailable for now:

  1. Transaction history.
  2. SLP validation. DO NOT use the current code on the BCH mainnet - the tokens can be occasionally burned.

The testing instruction for SLP users familiar with CLI:

  1. Build API using https://github.com/KomodoPlatform/atomicDEX-API/tree/mm2.1-slp-swap branch or download the prebuilt binaries from http://195.201.0.6/mm2.1-slp-swap/
  2. Use the coins config from https://github.com/KomodoPlatform/coins/blob/tbch-fusd/coins
  3. Start MM2. Activate tBCH: curl --url "http://127.0.0.1:7783" --data '{"userpass":"'$userpass'","method":"electrum","coin":"tBCH","servers":[{"url":"tbch.loping.net:60002","protocol":"SSL"},{"url":"electroncash.de:50004","protocol":"SSL"},{"url":"testnet.bitcoincash.network:60002","protocol":"SSL"},{"url":"electrs.electroncash.de:60002","protocol":"SSL"}]}'
  4. Activate USDF: curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"USDF\"}"
  5. Send some coins to addresses returned by activation results. You are now set to use the wallet and trading RPCs listed in the docs: https://developers.atomicdex.io/basic-docs/atomicdex/atomicdex-api.html

If you notice that AtomicDEX generates an invalid SLP transaction/burns tokens please report it as soon as possible in this issue. Also, any other feedback and bug reports will be appreciated.

Milerius commented 3 years ago

I successfully made an AtomicSwap between RICK & USDF.

gui available here

Screen of a swap:

Capture d’écran 2021-08-10 à 19 24 30 (1)
artemii235 commented 3 years ago

I have recently added BCHD gRPC-web API support to validate SLP UTXOs and transactions generated by AtomicDEX to prevent token burning. As we have ongoing work on web browser support, I was curious to try it in WASM to have SLP tokens supported on the web right away. I faced the CORS issue during my tests: https://github.com/gcash/bchd/issues/489. If someone has a direct communication channel with BCHD developers/public instances maintainers, please let me know.

Also an update regarding overall progress: BCHD support seems to work well in the desktop GUI. I'm currently working on tx history implementation, which requires a bit of refactoring including enable 2.0 RPC. It may take a few weeks, but we are on the home stretch for sure :slightly_smiling_face:

artemii235 commented 2 years ago

We can consider the SLP integration status as final on the API side and ready for the pre-release testing! It took a while so I'm posting a detailed report of what has been done since the last update:

  1. Added a new enable_bch_with_tokens RPC 2.0 method. It allows activating BCH and any number of SLP tokens at once in a traffic effective manner returning balances for all of them in a single response. It also took some effort to perform internal refactoring and design abstractions allowing to use of the same concept for other protocols.
  2. Added a new enable_slp RPC 2.0 method. It allows enabling more tokens in addition to ones activated using the enable_bch_with_tokens.
  3. Implemented transactions history background fetching for BCH and SLP from scratch using our internal state machine pattern. It stores the data for SLP transfers if tokens are not activated or even not added to the config. If BCH history fetch is complete, all SLPs' history will be immediately available after activation.
  4. Added the TxHistoryStorage trait and implemented it for our SQLite DB. This is more effective than our old way of using plain JSON files. The abstraction will also allow implementing tx history easier for WASM in the future.
  5. Implemented a new my_tx_history 2.0 RPC that works on top of TxHistoryStorage.

For testing, please use the https://github.com/KomodoPlatform/atomicDEX-API/tree/dev branch and config from https://github.com/KomodoPlatform/coins/tree/bch-slp-mainnet-TEST-ONLY. In the beginning, please avoid using a significant amount of the real value assets. If any tokens get burned, please let us know about it immediately in this issue.

New RPCs will be documented and published on the website soon, examples can be found in the corresponding issue https://github.com/KomodoPlatform/developer-docs/issues/343.

I'm now preparing issues for the final integration in our GUIs. The desktop release should happen in early 2022. Mobile can happen a bit later afterward.

molecular commented 2 years ago

Is anyone testing? I'm not savvy enough to do it.

artemii235 commented 2 years ago

@molecular The desktop GUI initial integration should be coming quite soon - you and everyone will be able to test it without digging into the CLI stuff :slightly_smiling_face:

Milerius commented 2 years ago

I finished the last rpc call implementation, after @smk762 confirm the basic tests we can extend the testing to the community!

artemii235 commented 2 years ago

Our internal testing stage is finished, but we also need to complete additional internal security reviews of the https://github.com/KomodoPlatform/atomicDEX-API/pull/1184 PR. It takes more time than I initially expected - it should be finished in March. I apologize for the delay and thank everyone for their patience.

artemii235 commented 2 years ago

Hello everyone! SLP integration is complete, but the release PR (https://github.com/KomodoPlatform/atomicDEX-API/pull/1184) is still on ongoing security review, which is taking more time than we initially expected. Unfortunately, we can't release this PR until this review is finished, but we are doing our best to complete it as fast as possible. Thanks everyone for their patience!

molecular commented 2 years ago

Status?

artemii235 commented 2 years ago

@molecular API PR with SLP was merged and published few months ago. We will finally have a desktop release with SLP support in the coming week or two. Also, SLP will be likely included in the upcoming web version public alpha release.

smk762 commented 2 years ago

Status?

Can you please recommend where I can trade to get some SLP tokens for testing? Everywhere I look seems to have "Smooth Love Potion", but I'm pretty sure that's not what I need.

artemii235 commented 1 year ago

@molecular @damascene We have released a new desktop GUI version https://github.com/KomodoPlatform/atomicDEX-Desktop/releases/tag/0.5.7-beta with SLP support. Please note that it's still beta software, so it's not recommended to store and trade significant amounts. The list of currently available tokens is mentioned in release notes. If you would like to add more, please feel free to create a PR in coins repo: https://github.com/KomodoPlatform/coins

I can also confirm that SLP tokens will be added to the upcoming web version public alpha. Will post an announcement to this issue once it is released.

smk762 commented 1 year ago

Closed as completed.