How to Build Your Own SCP App: A Prototype for Next-generation Blockchainless DEXs
Decentralized applications do not have to be built on a public blockchain like Ethereum. When we are talking about DEXs, we generally refer to smart contract programs that run on Ethereum like Uniswap. This post will describe how to build a DEX in a new way that combines the automated market-making capabilities of Uniswap and the same security properties as blockchains. Even better, the new DEX model provides nearly infinite scalability without the risk of MEV.
How Uniswap Works
The concept of automated market-making originates from Uniswap. Hence, a new type of DEXs cannot be built in isolation from the design philosophy behind Uniswap, that is, using the simplest algorithm in combination with a blockchain to allow every user to be a market maker in place of specialized agencies.
The overall architecture of Uniswap v3 is shown in the figure above. The smart contracts of Uniswap v3 are executed in the EVM, which is run by every geth node. Hence, the computation process of v3 is performed by thousands of nodes, which reach a consensus via the PoW mechanism.
Take a closer look at the smart contracts of Uniswap v3. What Uniswap v3 essentially does is aggregate NFTs by using the Router. Behind each of the NFTs is a liquidity pool provided by an individual user who sets a specific bonding curve and a price range for market-making.
When a user sends a quote request to a v3 smart contract, the Router will generate the current best price by performing an aggregation computation. The user will sign a transaction at that price and send it to the Uniswap contract for execution. The transaction will lead to synchronous update of multiple NFTs, ensuring that the swap functionality of Uniswap is secure and reliable for users.
The Prototype of the Next-generation DEXs
Before creating a prototype, you need to learn about everPay and its bundle transaction. everPay is a blockchain-based financial infrastructure that combines Arweave and SCP. By offering real-time transfers and a verifiable ledger, everPay allows users and developers to conduct token settlement in real time.
In everPay, a bundle transaction is a type of opAction. It allows a many-to-many transfer that requires the signatures of all transfer parties. If any of the subtransactions in a bundle transaction fails, the entire bundle transaction will be rolled back. Generally speaking, a bundle transaction is a many-to-many transactional transfer functionality.
Now that you have learnt about how Uniswap v3 works, you can build a new generation of DEXs on top of the SCP basics and everPay’s bundle transactions.
Firstly, the Router Contract in Uniswap v3 can be replaced by router nodes. A router node is a routing gateway node that can be deployed by anyone to collect the information of liquidity providers (LPs). Similar to the Router in v3, a router node can obtain the best price and swap path by performing aggregation computations when receiving a quote request.
Secondly, the NFTs in Uniswap v3 can be replaced by LP nodes, which are in control of a private key and an automated signature program. The LP node program will make quotations and sign bundle transactions according to the user-defined curve and price range.
When an LP node starts, it will connect with router nodes and submit quote information to them. Router nodes will send valid bundle transactions to LP nodes, which will sign the ones in compliance with their own market-making rules. The successfully signed transactions will be sent back to router nodes.
Transaction process:
- A user sends a quote request to a router node.
- The router node generates the best quote and swap path with information gathered from multiple liquidity providers.
- An instance of a bundle swap path: UserA transfers tokenA to lpB, lpB transfers tokenB to lpC, lpC transfers tokenC to userA.
- If the user agrees with the quote, he will sign the transaction. And then the route node will ask all the LP nodes involved to sign it. The quote also needs to be confirmed by the LP nodes.
- The router node will submit the bundle transaction to everPay for execution after it gathers all the signatures required.
Benefits of the Next Generation of DEXs:
- A fully distributed P2P network that cannot be disrupted or shut down. Anyone can deploy a router node or an LP node in the network;
- Infinite scalability. Every router node can connect with hundreds of LP nodes and provide aggregation services for tens of thousands of users. An unlimited number of router nodes can be deployed in the network.
- No MEV. A user will be paid exactly the same price at which he signs the bundle transaction. If any of the LP nodes fails to pay the corresponding tokens, the entire bundle transaction will be rolled back, which means it does not happen at all.
- Ultrahigh asset security. Since LP nodes have their own private key and assets in hand, hackers have to attack them one by one to steal their assets, which means the attack vectors are highly distributed.
Such a network offers an optimal user experience. You only need to access the UI that connects to a router node and then sign your transaction at the price provided by the router node. Since the router node communicates with all the LP nodes that connect to it by using WebSocket, the transaction can be signed in seconds and then executed by everPay in real-time. In addition to the high-speed transaction processing, you can also benefit from no slippage because the quote you are offered is what you finally get. This way, you do not need to worry about any MEV extraction conducted by flashbots, which is commonly seen on Ethereum.
The only drawback is that becoming an LP needs to run a node, but there are workarounds. For example, your mobile wallet can be an LP node. As long as you set a price range and select a market-making curve on your phone, you can utilize the idle assets in your wallet for automated arbitrage. You can participate in the DEX’s swap network as if you were playing online games, and the program on your phone will stay online and conduct automated market-making according to your custom rules.
Conclusion
As is shown in the prototype above, we can build a decentralized application without any on-chain smart contract at an extremely low cost. Such a development mode conforms to the mindset of Web2 developers. We can expect that the rise of the Web3 era will go beyond blockchains and EVM and bring out more paradigms for building Web3 applications. The SCP proves to be an excellent option for Web3 development by providing applications with the immutability and traceability of blockchains as well as the scalability of large-scale systems.
Join our