You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

Status
IN PROGRESS
Stakeholders
Outcome
Due date
Owner

Background

DEX is planned to be implemented as Iroha 2.0 module.

Action items

Problem

Decentralized exchange provides an ability to transfer assets between accounts in exchange for other assets. Let's use a simple case as an example:

Peer to Peer Scenario

PlantUML diagram

@startuml
Buyer -> Iroha: Place Exchange Order(20XOR, 100USD)
Seller -> Iroha: Place Exchange Order(100USD, 20XOR)
Iroha -> Iroha: Transfer 20XOR from Seller to Buyer
alt Success:
  Iroha -> Iroha: Transfer 100USD from Buyer to Seller
end
@enduml

So Iroha should secure peer to peer exchanges across the ledger from malicious actions. In this case Iroha does a good job, the only thing it should check is an ability to transfer assets from and to accounts.

But there are more corner cases when we deal with exchanges via bridge:

Peer to Peer across Bridge Scenario

  • Cross blockchain rates should be taken into consideration
  • Iroha should prevent double spent of assets 
  • Additionally to transferring assets, Iroha should mint and de-mint them

Simple scenario:

PlantUML diagram

@startuml
Buyer -> Iroha: Place Exchange Order(20ETH, 1BTC)
Seller -> Iroha: Place Exchange Order(1BTC, 20ETH)
Iroha -> "BTC bridge": Mint 1BTC to Seller
alt Success:
  Iroha -> Iroha: Transfer 1BTC from Seller to Buyer
  alt Success:
    Iroha -> "ETH bridge": Mint 20ETH to Buyer
    alt Success:
      Iroha -> Iroha: Transfer 20ETH from Buyer to Seller
    end
  end
end
@enduml

Liquidity Pool Scenario

Liquidity Pools is another dimension in this set of scenarios for Decentralized Exchanges. Basically it can be used in pair with or without bridges, so let's take a more clean example without them. But let's not stick to an Exchange Pair and work with multi-currency liquidity:

PlantUML diagram

@startuml
Trader -> Iroha: Register Exchange Liquidity [20XOR, 20ETH, 1BTC]
Seller -> Iroha: Place Exchange Order(1BTC, 20ETH)
Iroha -> "BTC bridge": Mint 1BTC to Seller
alt Success:
  Iroha -> Iroha: Transfer 1BTC from Seller to Trader
  alt Success:
    Iroha -> Iroha: Transfer 20ETH from Trader to Seller
  end
end
@enduml

From the high level perspective this scenario looks very similar with two previous because all of them are based on top of two Iroha functions:

  • Assets Transfer
  • Iroha Triggers

Resulting Behavior

Let's write all three scenarios as one feature description according to BDD with more details:

Feature: Decentralized Exchange
  Scenario: Buyer exchanges 20xor for 100usd
    Given: Iroha Peer is up
    And Iroha Bridge module enabled
    And Iroha DEX module enabled
    And Peer has Domain with name exchange
    And Peer has Account with name buyer and domain exchange
    And Peer has Account with name seller and domain exchange
    And Peer has Asset Definition with name xor and domain exchange
    And Peer has Asset Definition with name usd and domain exchange
    And buyer Account in domain exchange has 100 amount of Asset with definition usd in domain exchange
    And seller Account in domain exchange has 20 amount of Asset with definition xor in domain exchange
    When buyer Account places Exchange Order 20xor for 100usd
    And seller Account places Exchange Order 100usd for 20 xor
    Then Iroha transfer 20 amount of Asset with definition xor in domain exchange from seller account in domain exchange to buyer account in domain exchange
    Then Iroha transfer 100 amount of Asset with definition usd in domain exchange from account buyer in domain exchange to seller account in domain exchange
  Scenario: Buyer exchanges 20xor for 100usd
    Given:
    When:
    Then:
  Scenario: Buyer exchanges 20xor for 100usd
    Given:
    When:
    Then:


Solution

Introduce a new module "DEX" with a dependency on "Bridge" module with additional set of Iroha Special Instructions and Queries and new Abstractions like Order (Combination of a Trigger and Asset with a predefined Asset Definition). Implement Triggers.

Decisions

Alternatives

Concerns

Assumptions

Risks

Additional Information


  • No labels