How Switcheo Exchange Works Part 1
The drawbacks of today’s centralized financial system have led to the emergence of Decentralized Finance, or “DeFi” for short. DeFi applications are built on blockchains to increase transparency in financial markets by removing the control of a central authority. One such type of DeFi applications is decentralized cryptocurrency exchanges (DEXs) like Switcheo.
Decentralized exchanges enable peer-to-peer (p2p) trades on the blockchain using smart contracts, allowing users to trade cryptocurrencies without being exposed to custodial risks inherent with centralized exchanges (e.g. the infamous Mt Gox hack where over 850,000 BTCs, valued at US$3 billion today, had been stolen, also Binance’s loss of US$40 million from a large security breach earlier this year). Truly decentralized exchanges are therefore non-custodial such that even the exchange owners (or any other 3rd-party) have no access to users’ tokens.
However, first-generation decentralized exchanges like EtherDelta turned out to be slow and cumbersome to use. Since everything from order matching and trade settlement are performed fully on the blockchain, users of EtherDelta had to wait for their trade transactions to be mined and confirmed on the blockchain (which could take a few seconds to several minutes) before making their next order. This performance-limiting dependency resulted in traders being incapable of executing swing trades rapidly, ultimately giving a poor user experience.
At Switcheo, our users’ trading experience is very important to us. This is why Switcheo Exchange is built upon a unique infrastructure that supports instant trade confirmations, freeing our users from waiting for transactions to be mined.
In this two-part series, we will first explore how Switcheo Exchange works on the NEO and Ethereum blockchains, such that it supports instant trading while remaining non-custodial. In the next part, we will continue by examining how Switcheo works on the EOS blockchain.
A first-generation decentralized exchange is usually made up of just two components: the first being its smart contract that is deployed on the blockchain to process trades, and the second being the user interface, which acts as a direct gateway between the trader and the smart contract.
Unlike first-generation decentralized exchanges, the infrastructure of Switcheo Exchange comprises of three layers which include a user interface, a smart contract, and the Switcheo Matching Engine.
The interaction between these three components allows Switcheo Exchange to be performant while still being non-custodial.
The Switcheo Smart Contract is a self-executing computer program deployed on the blockchain. It automatically tracks data such as the amount of each users’ digital assets that are deposited into Switcheo Exchange. But distinct from depositing into a centralized exchange, users retain sole ownership of their funds on Switcheo Exchange.
This is because tokens are deposited directly into the smart contract rather than the exchange’s wallet, and the smart contract only allows tokens to be traded or withdrawn only with the correct authorization from the user’s private keys. Since Switcheo does not acquire or store users’ passwords or private keys, the exchange is never able to access users’ funds directly. This is similar to how a first-generation DEX would work.
However, the reason why users can trade instantly and continuously on Switcheo Exchange lies within the Switcheo’s Matching Engine.
The Switcheo Matching Engine — is the key component that grants Switcheo Exchange its robustness and performance. The matching engine is an off-chain order matching system that accepts user trade requests. The matching engine then matches the order against the current order book on a price-time priority basis, and responds with the appropriate messages for the user to authorize their trade. Once authorized, these trades are then broadcasted to the blockchain for settlement. We will examine further how this is done safely in a short while.
The key benefit for executing order matching off-chain allows the order book on Switcheo Exchange to be updated in real-time instead of only after each block is produced. This allows users to have their orders instantaneously confirmed in the same way as a centralized exchange, allowing users to make a large number of orders rapidly. Of course, this also means that order cancellations are instantaneous on Switcheo Exchange, and it is impossible to have failed transactions wasting network fees due to being front-runned.
Below, we illustrate what happens within Switcheo Exchange when a user makes an order, and when the order is matched.
Published at Fri, 26 Jul 2019 05:00:16 +0000
Bitcoin Pic Of The Moment
If you appreciate my photos, you can show your support by donating some BTC to me through the link below:
tippin.me/@BWCKPhotography
Please also visit my facebook pages:
www.facebook.com/BWCKPhotography
www.facebook.com/KafiDig
By BWCK Photography on 2017-05-17 19:50:43
