Crypto Trading

Atomic Arbitrage Between Decentralized Exchanges

Atomic Arbitrage has long been the holy grail of traders - a trading strategy that by definition is guaranteed to be profitable. With decentralized exchanges and smart contracts, it is possible.

Atomic Arbitrage Between Decentralized Exchanges

Price arbitrage is a strategy where a trader finds the same financial instrument being traded at different prices on two different exchanges and makes a profit from that. If you can buy BTC for $10,000 on Coinbase and then immediately sell it for $11,000 on Binance - that's just easy 10% profit.

ArbitrageSuccess

In practice, however, one needs to account for delays that exist when you move funds between centralized exchanges. What if you bought BTC for $10,000, but by the time the transfer between Coinbase and Binance completes Binance price has dropped to $9,000? Instead of making 10%, you just lost 10%! This price movement between the price that you intended to use for the trade and the price you really got is called slippage and it has historically been the bane of many a trader.

ArbitrageFail

In the world of decentralized exchanges (we will focus on Ethereum in this blog post, but the same ideas can trivially be applied to any other token-capable blockchain) we are blessed with not having to wait for the transfers to complete, since all decentralized exchanges exist on the same platform! In this case, the only bottleneck for successful arbitrage strategies is the deposit/withdrawal transaction times on DEXs such as EtherDelta, IDEX, and Saturn Network.

The new generation of DEXs, such as 0x, Kyber Network and Saturn Protocol, enable 1-click wallet to wallet trading and that makes the holy grail of arbitrage, the atomic arbitrage possible. What does it mean?

An atomic arbitrage is a strategy that executes both trades (i.e. buy 1 ETH for 50,000 SATURN and immediately sell back for 55,000 SATURN) in the same transaction, without any possibility for slippage to occur. The transaction either completes and you make a guaranteed profit, or fails entirely and you simply wait for the next arbitrage opportunity.

This sounds amazing! But how does it work?

AAcontract

Naturally, with the power of smart contracts. Smart contracts allow us to automate certain actions and bundle them into one transaction. Which means that we can write a smart contract that will execute both trades in one transaction (hence called atomic arbitrage, as for the longest time atom was considered to be the smallest indivisible part of a molecule), without letting any other trader intervene, take the profitable trade that you have found, and cause the dreadful slippage.

In pseudo-code, such smart contract would look like this.

function saturn_zrx_arbitrage(
  address tokenAddress,  // what token are we selling
  uint256 saturnOrderID, // ID of SaturnProtocol order we are arbitraging
  address[5] orderAddresses,  // 0x order we are arbitraging
  uint256[6] orderValues, // 0x order we are arbitraging
  uint256 fillTakerTokenAmount, // rest of 0x specific params
  uint8 v,
  bytes32 r,
  bytes32 s
) public payable {
  // First, execute a trade against SaturnProtocol ERC20 order book
  // and exchange, let's say, ETH for ZRX
  // Note: SaturnProtocol uses '0x0' to indicate that we trade ETH instead of a token
  SaturnProtocolERC20.trade('0x0', msg.value, saturnOrderID);
  // Then if the previous trade succeeds, we have enough ZRX to sell them on
  // 0x protocol back to ETH for a guaranteed profit
  ZRX.fillOrKillOrder(orderAddresses, orderValues, fillTakerTokenAmount, v, r, s);
  // And finally, transfer ETH back to the trader's wallet
  msg.sender.transfer(address(this).balance);
}

Executing this smart contract function will either succeed and provide you with a guaranteed profit, or fail entirely, and the initial trade on Saturn Protocol will simply be reverted. This idea can further be improved upon to integrate decentralized exchanges with deposit as well, by doing

  1. Deposit token1
  2. Trade token1 for token2
  3. Withdraw token2
  4. Exchange token2 back to token1 at a better price on Saturn Protocol

all in one atomic smart contract function call.

Something like this would have never been possible on centralized crypto exchanges or stock exchanges. Atomic Arbitrage is only possible on decentralized exchanges that exist on the same blockchain. Which is why we think that decentralized exchanges not necessarily compete with each other, but provide different user experience and different privacy/speed tradeoffs, ultimately seamlessly sharing liquidity with each other and forming one large liquidity pool for traders.

Writing such trading bots to bridge 0x, EtherDelta (neé ForkDelta), IDEX, Kyber, Bancor and other decentralized exchanges with Saturn Protocol is an important project on our roadmap, and we will open source these bots and teach you how to set up atomic arbitrage smart contracts as soon as they are ready. If this sounds interesting to you, please check out Saturn Protocol's website to learn more about this exciting technology.

Looking for more great content? Please follow us on social media and subscribe to our newsletter to never miss a Saturn Network announcement!

Comments 0 Comments 0 Comments
0 Comments 0 Comments