1

I am writing a token swap contract on Ethereum Blockchain to manage ERC 20 token swap in an exchange.

The Questions is that in terms of scalability, which of the following two options would be better considering the exchange will handle up to a Million Users.

Option 1 Create multiple contracts with each responsible for swapping a single pair. This can distribute the workload on a single contract.

Option 2 Create a single contract to manage swapping of all the tokens. This option can be used considering that the blockchain can Handle the processing in a decentralized manner and the smart contract will be able to call multiple methods in parallel without affecting the performance

So which option would be correct and more suitable in case of an Exchange with up to a Million Users

1 Answer 1

1

This is a big design question with many different factors, so there's no one simple answer (e.g. any decentralized exchange like Radar Relay or Fluidity's Airswap have to solve a similar problem, and they probably don't have a million users yet :)

You're discussing the implemention of an on-chain orderbook. It would indeed be more scalable to have a different order book per trading pair, as in your Option 1, rather than having all pairs share a single order book in Option 2, as each new block takes 15 seconds. You don't want the limits of Ethereum to affect your trading volume.

However, keeping the orderbook on-chain at all is not a viable solution in my opinion.

Systems like Loopring attempt to scale trading to about 2000 transactions per second using zero knowledge proofs, where all the trades are batched together, and only the final state is submitted on-chain to update the order book when a sufficient threshold has been reached.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.