Skip to content

Version 1.0.0

Compare
Choose a tag to compare
@vsuharnikov vsuharnikov released this 08 Jul 14:53
· 750 commits to master since this release

Separation from NODE!

Previously, we have to develop new features in the old NODE's branch. All this time we made changes in 0.16 branch.

Now DEX is a separate project on GitHub and we are able to develop new features for any NODE's version (with some limitations). We still depend on NODE, but this will help us to avoid a lot of problems during development.

Snapshot migration

In the latest 0.16 and 0.17 NODE's versions, we changed storage format for order books and the list of all available markets. To migrate make the following steps:

  1. Get the oldest snapshot offset from the running DEX:

    curl --header 'X-API-Key: your-api-key' 'https://dex-host[:dex-port]/matcher/debug/oldestSnapshotOffset'
  2. Stop the NODE with DEX;

  3. Backup /var/lib/waves/matcher or /var/lib/waves-testnet/matcher for mainnet or testnet respectively;

  4. Upgrade the DEX, don't yet run the service;

  5. Run the migration tool to covert a list of available markets:

    For mainnet:

    sudo -u waves waves -main com.wavesplatform.dex.MatcherTool /usr/share/waves/conf/waves.conf ma-migrate

    For testnet:

    sudo -u waves-testnet waves-testnet -main com.wavesplatform.dex.MatcherTool /usr/share/waves-testnet/conf/waves.conf ma-migrate

    You will see

    Asset pairs migrated

    in the end.

  6. Check all pairs are migrated:

    For mainnet:

    sudo -u waves waves -main com.wavesplatform.dex.MatcherTool /usr/share/waves/conf/waves.conf ma-inspect

    For testnet:

    sudo -u waves-testnet waves-testnet -main com.wavesplatform.dex.MatcherTool /usr/share/waves-testnet/conf/waves.conf ma-inspect

    You will see

    Known asset pairs

    and the list of migrated pairs.

  7. Run the migration tool to covert order books:

    For mainnet:

    sudo -u waves waves -main com.wavesplatform.dex.MatcherTool /usr/share/waves/conf/waves.conf ob-migrate <paste-oldest-snapshot-offset-from-p.1-here>

    For testnet:

    sudo -u waves-testnet waves-testnet -main com.wavesplatform.dex.MatcherTool /usr/share/waves-testnet/conf/waves.conf ob-migrate <paste-oldest-snapshot-offset-from-p.1-here>

    Probably you will see

    Can't migrate order books

    with

    The default offset for these order books is

    It's okay.

  8. Delete folders old snapshots and journal:

    For mainnet:

    sudo -u waves rm -rf /var/lib/waves/matcher/{snapshots,journal}

    For testnet:

    sudo -u waves-testnet rm -rf /var/lib/waves-testnet/matcher/{snapshots,journal}

Settings migration

  1. We changed the main section in settings. It was waves.matcher, now it is waves.dex

  2. Also, the DEX is activated after this setting:

    waves.extensions = [
      // Other extensions
      "com.wavesplatform.dex.Matcher"
    ]

    Don't forget it.

  3. order-match-tx-fee now is exchange-tx-base-fee

  4. If you used allowed-asset-pairs before, add the setting:

    waves {
      //
      dex {
        //
        white-list-only = yes
      }
    }

    Now:

    • whitelist works only if this flag is provided;
    • allowed-asset-pairs functionality doesn't affect allowed-asset-pairs, aren't validated against blacklist rules only.
  5. Kafka:

    1. The server now is specified in a user's section;
    2. Same for the topic.

New functionality

Some of new functionality are marked as Experimental.
This means that the feature is implemented and tested, but currently isn't used in our DEX.

Allowed order versions

Now you can specify allowed order version in the waves.dex.allowed-order-versions section.
Notice, the DEX still checks the version is supported in the blockchain and deny orders of unsupported versions.
The current supported versions (with blockchain's checks) can be obtained through GET /matcher/settings, for example:

{
  "priceAssets": [],
  "orderFee": {
    "dynamic": {
      "baseFee": 300000,
      "rates": {
        "BrmjyAWT5jjr3Wpsiyivyvg5vDuzoX2s93WgiexXetB3": 0.0097,
        "DWgwcZTMhSvnyYCoWLRUXXSH1RSkzThXLJhww9gwkqdn": 0.0003,
        "WAVES": 1
      }
    }
  },
  "orderVersions": [
    1,
    2
  ]
}

Charging fee's modes

  • Default: dynamic requires an additional fee for scripted entities (DEX's account, scripted assets in pair and fee);
  • fixed requires a fixed amount of fee;
  • Experimental: percent requires a percent fee of one of pair's asset;

Our DEX uses a dynamic as usual. See waves.dex.order-fee for more information and all available settings.

Fee rates

This feature allows clients to pay fee both in Waves and assets.
We don't specify the absolute values, but instead specify a waves-to-asset conversion rate, because it's hard to rely on absolute values in some fee's modes.

To enable the feature make sure:

  1. Order Version 3 (id is 12) is activated on blockchain. See GET https://node-host[:node-rest-api-port]/activation/status for activation status.
  2. waves.dex.allowed-order-versions contains 3.

REST API

  • Getting current rates: GET /settings/rates.

    Sample response:

    {
      "BrmjyAWT5jjr3Wpsiyivyvg5vDuzoX2s93WgiexXetB3": 0.0097,
      "DWgwcZTMhSvnyYCoWLRUXXSH1RSkzThXLJhww9gwkqdn": 0.0003,
      "WAVES": 1
    }
  • Add or update rate for the specified asset: PUT /settings/rates/{assetId}. The request's body must contain a rate in units: 1.5 means that the rate is 150%. The method requires the API key.

  • Delete the rate for the specified asset: DELETE /settings/rates/{assetId}. Clients won't be able to pay a fee in {assetId} after deletion. The method requires the API key.

Order restrictions

It's an additional and configurable layer of order's validation.

The sample configuration:

waves.dex.order-restrictions = {
  "WAVES-DWgwcZTMhSvnyYCoWLRUXXSH1RSkzThXLJhww9gwkqdn": {
    step-amount = 0.00000001
    min-amount  = 0.001
    max-amount  = 1000000
    step-price  = 0.00000001
    min-price   = 0.001
    max-price   = 100000
  }
}

REST API

Getting order info for a pair: GET /matcher/orderbook/WAVES/DWgwcZTMhSvnyYCoWLRUXXSH1RSkzThXLJhww9gwkqdn/info
Sample response:

{
  "restrictions": {
    "stepAmount": "0.00000001",
    "minAmount": "0.01",
    "maxAmount": "100000",
    "stepPrice": "0.00000001",
    "minPrice": "0.000003",
    "maxPrice": "100"
  },
  "matchingRules": {
    "tickSize": "0.00000001"
  }
}

Getting order books GET /orderbook now returns matchingRules too.

Matching rules

Matching rules is the way to change how the DEX's algorithm works for specified pair. The rules are changed when a pair processes a message with offset (kafka or local) >= specified.
Rules can be changed at specified offset. See waves.dex.matching-rules for more information.

The current queue offset could be determined through GET /matcher/debug/currentOffset (an authentication key is required).

Merge prices rule

At this moment we have only the one rule: to merge prices with a given step or not. By default this rule is not applied.

For example we defined rules:

waves.dex.matching-rules = {
  "WAVES-DWgwcZTMhSvnyYCoWLRUXXSH1RSkzThXLJhww9gwkqdn": [
    {
      start-offset = 10000
      merge-prices = yes
      tick-size    = 0.002
    },
    {
      start-offset = 55000
      merge-prices = no
    }
  ]
}

This means:

  1. At start prices are not merged.

  2. When the offset becomes 10000, we align incoming orders at prices multiple of 0.002:

    1. A sell (ask) order with price 0.005 will be aligned at 0.006 level and will be added to the end of the queue of this level.
    2. A buy (bid) order with price 0.003 will be aligned at 0.002 level and will be added to the end of the queue of this level.

    Note, the we doesn't align existent orders in the order book. An ask order that was placed with the 0.007 price before will not be merged into 0.008. Same for bid orders.

  3. The merging is disabled, when the offset becomes 55000. The existent orders will not be un-aligned too.

Max price deviation (Experimental)

Defines an additional order's validation against current market;

# Price and fee deviations (in percents)
waves.dex.max-price-deviations {
  # Enable/disable deviations checks
  enable = no
  # Max price deviation IN FAVOR of the client
  profit = 50
  # Max price deviation AGAINST the client
  loss = 40
  # Max fee deviation from the market price
  fee = 30
}

This means if a user tries to submit an order with the price outside of specified bounds:

  • the price is better by more than 50% than the current market price
  • the price is worse by more than 40% than the current market price
  • the specified fee is lower by more than 30%, that otherwise, the user pays as a fee by executing the order at market price (applicable for percent fee type)

In all those cases the order will be rejected with an error.

History database (Experimental)

Now we are able to write a historical data: when an order was added and what happened with it.
Currently we doesn't provide an API for fetching this information, we are only able to write it to the PostgreSQL.

PostgreSQL connection settings are specified in the waves.dex.postgres section.
How to write a historical data to the PostgreSQL are specified in the waves.dex.order-history section.

Guaranteed exchange transaction broadcasting

DEX periodically checks, is the transaction added to the blockchain. If not - DEX rebroadcasts the transaction.
To enable this, add settings:

waves.dex.exchange-transaction-broadcast {
  broadcast-until-confirmed = yes
  // see the docs about "interval" and "max-pending-time"
}

See application.conf for more information and all available settings.

SHA256 Checksums

c6b3a3f5c131bdec27c4e75baa229ac6b7ac9ddf8bf72be29cca04728d1b69c2 dex_1.0.0_all.deb
54eca45b95981c231069bb1ed6bc7b2d390ca7e35e6c7f19b6e2ab280a192791 dex_1.0.0.tgz
2df9a7b33e723ae0f461f3505a3a0cf974cc8d1eb48ef66bc918eae14d829804 dex-testnet_1.0.0_all.deb
aafe85e764502702e41819f24605279ad6bf51ee031a9dfe993a114b5a939dcf dex-testnet-1.0.0.tgz