komodo-wallet-desktop icon indicating copy to clipboard operation
komodo-wallet-desktop copied to clipboard

ARRR integration

Open artemii235 opened this issue 3 years ago • 11 comments

It works in native mode only now.

  1. Coins config: https://github.com/KomodoPlatform/coins/pull/303/files
  2. MM2 build: latest from http://195.201.0.6/mm2.1-slp-swap/
  3. It also requires http://195.201.0.6/ARRR_CACHE.db to be placed in the MM2 working directory.
  4. Enable command: curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"ARRR\"}"
  5. No tx history is available now.
  6. Block explorer link https://pirate.explorer.dexstats.info/
  7. PIRATE daemon is required to run and be fully synced before coin activation in the GUI.

Please consider this as very early alpha/PoC. It requires the checklist from https://github.com/KomodoPlatform/atomicDEX-API/issues/927 to be implemented to avoid linking different swaps between each other, etc.

Activation time is about 20 seconds. Withdraw can take minutes depending on the transaction size.

artemii235 avatar Aug 12 '21 11:08 artemii235

Updates on the integration status:

Activation and withdraw are implemented using 2.0 RPC protocol https://developers.atomicdex.io/basic-docs/atomicdex-api-20-dev/#atomicdex-api-rpc-protocol-v2-0-dev. It might be required to integrate it's generic structure first.

  1. Branch https://github.com/KomodoPlatform/atomicDEX-API/tree/arrr-light-mode-swap is usable to activate ZOMBIE and PIRATE in light mode.
  2. Please note that even light mode requires Sapling params files have to be downloaded even for light mode (./zcutil/fetch_params.sh/bat from either Zcash or Komodo).
  3. ZOMBIE conf:
{
  "coin":"ZOMBIE",
  "asset":"ZOMBIE",
  "txversion":4,
  "overwintered":1,
  "mm2":1,
  "protocol":{
    "type":"ZHTLC",
    "protocol_data":{
      "consensus_params":{
        "overwinter_activation_height":0,
        "sapling_activation_height":1,
        "blossom_activation_height":null,
        "heartwood_activation_height":null,
        "canopy_activation_height":null,
        "coin_type":133,
        "hrp_sapling_extended_spending_key":"secret-extended-key-main",
        "hrp_sapling_extended_full_viewing_key":"zxviews",
        "hrp_sapling_payment_address":"zs",
        "b58_pubkey_address_prefix":[
          28,
          184
        ],
        "b58_script_address_prefix":[
          28,
          189
        ]
      }
    }
  },
  "required_confirmations":1
}

For PIRATE, it should be the same, except overwinter_activation_height and sapling_activation_height fields. Please also use "requires_notarization":true.

  1. enable/electrum won't work for ZHTLC protocol. GUI has to use init_z_coin call https://github.com/KomodoPlatform/atomicDEX-API/blob/28749e38e22137c64a025d348bae22db4e33d3c3/mm2src/common/for_tests.rs#L1308 that will return task_id, which then should be used in init_z_coin_status: https://github.com/KomodoPlatform/atomicDEX-API/blob/28749e38e22137c64a025d348bae22db4e33d3c3/mm2src/common/for_tests.rs#L1333
  2. From init_z_coin_status GUI will get following responses:
{
  "mmrpc":"2.0",
  "result":{
    "status":"InProgress",
    "details":"ActivatingCoin"
  },
  "id":null
}
{
  "mmrpc":"2.0",
  "result":{
    "status":"InProgress",
    "details":"Scanning"
  },
  "id":null
}
{
  "mmrpc":"2.0",
  "result":{
    "status":"Ready",
    "details":{
      "result":{
        "current_block":90728,
        "wallet_balance":{
          "wallet_type":"Iguana",
          "address":"zs1g6z7dcfp5wg085fuzqlauf8d85ct4hke7xmwxe0djnq48909yfsj66hzj0fjgfgzynddud8n04g",
          "balance":{
            "spendable":"1",
            "unspendable":"0"
          }
        }
      }
    }
  },
  "id":null
}

artemii235 avatar May 10 '22 13:05 artemii235

ZOMBIE electrum_servers:

[{"url":"zombie.sirseven.me:10033"}]

ZOMBIE light_wallet_d_servers

["http://zombie.sirseven.me:443"]

PIRATE electrum_servers:

[{"url":"pirate.sirseven.me:10032"}]

PIRATE light_wallet_d_servers

["http://pirate.sirseven.me:443"]

cc @smk762 @tonymorony @SylEze

artemii235 avatar May 10 '22 13:05 artemii235

Error example:

{
  "mmrpc":"2.0",
  "result":{
    "status":"Ready",
    "details":{
      "error":"Error on platform coin ZOMBIE creation: ZCashParamsNotFound",
      "error_path":"lib.z_coin_activation.z_coin",
      "error_trace":"lib:93] z_coin_activation:171] z_coin:685]",
      "error_type":"CoinCreationError",
      "error_data":{
        "ticker":"ZOMBIE",
        "error":"ZCashParamsNotFound"
      }
    }
  },
  "id":null
}

This enum contains all possible error variants: https://github.com/KomodoPlatform/atomicDEX-API/blob/28749e38e22137c64a025d348bae22db4e33d3c3/mm2src/coins_activation/src/standalone_coin/init_standalone_coin_error.rs#L16

artemii235 avatar May 10 '22 13:05 artemii235

UPD MM2 binaries are available for ZOMBIE/ARRR light mode here: http://195.201.0.6/arrr-light-mode-swap/. Please note that native doesn't work there anymore, as it requires some refactoring 🙂

I have also created a new branch for this with a more reasonable name: https://github.com/KomodoPlatform/atomicDEX-API/tree/arrr-light-mode-swap (updated in the initial message).

cc @tonymorony @SylEze @smk762

artemii235 avatar May 11 '22 12:05 artemii235

@artemii235 can we please include the coin in init_z_coin_status response? Existing code in desktop gui looks for that in response when enabling coins.

e.g.

{
   "mmrpc":"2.0",
    "result": {
        "status": "Ready", 
        "details": {
            "result":{
                 "coin": "COIN_TICKER",
                 "current_block": 102320,
                 "wallet_balance": {
                     "wallet_type": "Iguana",
                     "address": "ADDRESS",
                     "balance": {
                         "spendable": "BALANCE",
                          "unspendable":"0"
                      }
                }
            }
       }
   },
   "id":null
}

smk762 avatar May 18 '22 15:05 smk762

@smk762 Please also use orderbook and best orders V2 RPCs. If possible, it's preferred to use them for all coins, not only ARRR/ZOMBIE.

Best orders V2 request structure: https://github.com/KomodoPlatform/atomicDEX-API/blob/4366141c8a7a5d6d3abac87df8827f7cae53d11c/mm2src/mm2_test_helpers/src/for_tests.rs#L1253 Response: https://github.com/KomodoPlatform/atomicDEX-API/blob/4366141c8a7a5d6d3abac87df8827f7cae53d11c/mm2src/mm2_main/src/mm2_tests/structs.rs#L885

Orderbook V2 request https://github.com/KomodoPlatform/atomicDEX-API/blob/4366141c8a7a5d6d3abac87df8827f7cae53d11c/mm2src/mm2_test_helpers/src/for_tests.rs#L1236 Response https://github.com/KomodoPlatform/atomicDEX-API/blob/4366141c8a7a5d6d3abac87df8827f7cae53d11c/mm2src/mm2_main/src/mm2_tests/structs.rs#L868

artemii235 avatar May 26 '22 10:05 artemii235

@smk762 I've refactored init_z_coin_status response, added more info about sync status, the responses are as follows:

{"mmrpc":"2.0","result":{"status":"InProgress","details":"ActivatingCoin"},"id":null}

...

{"mmrpc":"2.0","result":{"status":"InProgress","details":{"UpdatingBlocksCache":{"current_scanned_block":2911,"latest_block":123147}}},"id":null}

...

{"mmrpc":"2.0","result":{"status":"InProgress","details":{"UpdatingBlocksCache":{"current_scanned_block":38935,"latest_block":123147}}},"id":null}

...

{"mmrpc":"2.0","result":{"status":"InProgress","details":"BuildingWalletDb"},"id":null}

...

{"mmrpc":"2.0","result":{"status":"Ready","details":{"result":{"ticker":"ZOMBIE","current_block":123147,"wallet_balance":{"wallet_type":"Iguana","address":"zs1g6z7dcfp5wg085fuzqlauf8d85ct4hke7xmwxe0djnq48909yfsj66hzj0fjgfgzynddud8n04g","balance":{"spendable":"1","unspendable":"0"}}}}},"id":null}

Please note that BuildingWalletDb stage can take several minutes depending on the number of transactions on the address. Due to current librustzcash design, it's not possible to provide a more detailed status of this operation. It's worth showing May take some time/several minutes message to the user when you get this status.

artemii235 avatar Jun 02 '22 04:06 artemii235

@smk762 https://github.com/KomodoPlatform/atomicDEX-API/pull/1302 is merged, you can use dev branch :) The binaries will be uploaded by CI soon.

artemii235 avatar Jun 14 '22 13:06 artemii235

@smk762 tx history is ready, the PR is on the review, but the API won't likely be changed. You can start implementation using builds from http://195.201.0.6/arrr-tx-history-and-native-mode/.

Please note that I had to add a separate z_coin_tx_history RPC method due to a custom structure of PIRATE/Zcash light wallet DB. Examples: https://github.com/KomodoPlatform/atomicDEX-API/blob/37b0fdc2406ba92c7eacb0c81c2658f26c4f44c3/mm2src/mm2_test_helpers/src/for_tests.rs#L1115

Response structure: https://github.com/KomodoPlatform/atomicDEX-API/blob/37b0fdc2406ba92c7eacb0c81c2658f26c4f44c3/mm2src/mm2_main/src/mm2_tests/structs.rs#L828

https://github.com/KomodoPlatform/atomicDEX-API/blob/37b0fdc2406ba92c7eacb0c81c2658f26c4f44c3/mm2src/mm2_main/src/mm2_tests/structs.rs#L802

cc @tonymorony

artemii235 avatar Jul 12 '22 09:07 artemii235

@smk762 Tx history PR is merged to dev. cc @tonymorony

artemii235 avatar Jul 18 '22 07:07 artemii235

I think this will be useful during testing: https://zcash.readthedocs.io/en/latest/rtd_pages/ux_wallet_checklist.html. Official Zcash recommendations on wallet UX :slightly_smiling_face: cc @tonymorony @smk762

artemii235 avatar Aug 08 '22 11:08 artemii235