camlCase
5 min readJul 15, 2019

--

Dexter

What a fine day for science.

– Dexter, Dexter’s Laboratory

As Nick Szabo first said, trusted third parties are security holes. Nowhere is this more apparent than in popular centralized digital asset exchanges. Even if you don’t get hacked or robbed, and your customer data doesn’t get leaked, many users are still probably getting fleeced by schemes ranging from front-running to wash trading to founders stealing their own customers’ funds.

The beauty of smart contracts on public blockchains is that this exact kind of behavior in many cases can be mitigated or avoided programmatically. Decentralized exchanges in their current form introduce tradeoffs, such as illiquidity and vulnerability to front-running, but efforts to address and mitigate these challenges are in the works (more on this in a future post).

But we probably don’t have to convince you that DEX’s are the future. We just want to let you know that soon Tezos will have one — and its name is Dexter.

In fact, we already have a Uniswap-inspired prototype ready to try out on the Tezos Alphanet here via our walkthrough tutorial, for those proficient with the command-line interface. In our tutorial, we include a sample asset called “Tezos Gold”. Following in the footsteps of Uniswap, we also intend to develop an open-source front-end that anyone can try out for themselves.

Uniswap Inspiration

Dexter is functionally similar to Uniswap; a simple, elegant, and entirely on-chain decentralized exchange — with no order book! With Uniswap anyone can become a liquidity provider by sending an equivalent value of ETH and an ERC-20 token to that token’s exchange contract. They will be rewarded with fees paid by those who swap tokens using the exchange contract (as of now it’s 0.3%). A very simple formula adjusts the exchange rate with each trade, based on the relative sizes of their respective liquidity pools. Buying a token will push up its price, and selling will lower its price, and this happens automatically, on-chain. As long as your trade size is not a significant proportion of the liquidity pool, the price slippage will be minimal. You can learn the details of how Uniswap works here: Non-technical or Technical

How We Are Building Dexter

Our current prototype uses a token interface similar to ERC-20, but Dexter will use the TZIP fungible asset standard when it’s ready.

We are using the Michelson/Morley/Lorentz stack to write our smart contracts, which you can learn about here:

https://hackage.haskell.org/package/morley

https://gitlab.com/camlcase-dev/michelson-tutorial

https://gitlab.com/camlcase-dev/morley-tutorial

Our frontend will be written in ReasonReact because it’s awesome and functional and based on OCaml. We have a Haskell backend.

Our web UI will integrate with TezBridge. TezBox and other solutions might also come into the picture once they support smart contracts.

Future Work and Ideas

Uniswap is beautiful, but we didn’t want to just build a clone. There’s room for improvement, and some facets of Tezos offer interesting possibilities.

Dynamic (or Market Based) Fees

Hayden Adams, the creator of Uniswap, selected the 0.3% transaction fee to be competitive with other exchanges, but without knowing if it would be a good number for this new type of DEX. It has actually worked out pretty well, and we might stick with it, but we are actively researching different fee structures, some of them dynamic. I will have a lot more to say about this in our next post. As of now it’s all just a research project in Dexter’s Laboratory.

UI/UX

We want to maintain the simplicity and ease of trading that Uniswap is known for, but there’s a lot more information and functionality that could be provided to the traders and liquidity providers to enable more efficient markets. We aim to present a simple interface, but let the user dig in to get the most out of their exchange experience.

Baker DEX

Tezos’ LPOS model creates an interesting scenario not present in Uniswap. The Tez that liquidity providers send to an exchange contract can be delegated, and they can share in the staking rewards. It would be great if each liquidity provider could choose their own delegate, but the nature of this DEX is that all liquidity gets pooled into one contract, and this contract can only choose one delegate. We are looking for how to best select the baker. We might partner with one of the major services, or allow holders of liquidity tokens to vote on their delegate. This means that liquidity providers can earn transaction fees and staking rewards!

Formal Verification

We will not deploy our Dexter contracts on Tezos until we’ve formally verified their correctness. Hopefully millions of dollars in value will be held and exchanged within each of these smart contracts. If there was ever a time to use the full power of Michelson it is here, and we intend to do so. One benefit of using the Morley framework is that not only does it make writing Michelson easier while still sticking close to the low-level code, but it comes with a set of property testing features from the Haskell QuickCheck library, which we will use in addition to formal verification methods such as Coq. And as 0X recently showed it’s hard to be DeFi on the EVM.

This Shit is On the Chain!

0x uses off-chain relayers with order-book. Most other DEX’s rely on off-chain elements, mostly because keeping an order-book on-chain is prohibitively expensive. There are some interesting possibilities that come with an entirely on-chain decentralized exchange, like on-chain price discovery, foregoing the need for a trusted pricing oracle. Derivatives can be built which refer to Dexter’s on-chain prices. Dexter could be a foundational element of Tezos’ DeFi system.

But Where Are All the Tokens?

Many token projects for Tezos are currently in development, but they aren’t a good fit for Dexter. We’ve heard of several really cool gaming dapps in the works, but it doesn’t make sense to trade non-fungible tokens on a Uniswap-type DEX. Security tokens are coming to Tezos! But these are real-world assets which are administered by trusted third parties. So, what then? Build a DEX and the right tokens will come? Tezos has a bright future. We expect to see decentralized stable coins, synthetic assets (e.g. representing cryptocurrencies like BTC or ETH on Tezos), and other tokenized stuff we can’t yet imagine. When tokens come to Tezos, there will be a really cool DEX waiting for them.

Keep an eye out for a future blog post from us. We’ll have a lot to show off in a few months!

--

--