Phala Builders Program Recap: PrivaDEX

Phala Network
4 min readJul 7, 2023

--

Last month the Phala Builders Program (PBP) issued its first grant to Kapil “Kap” Sinha for the successful completion of his cross-chain DEX aggregator PrivaDEX. While this is old news for those of you who’ve been tuning into Phala’s recent Twitter spaces, we wanted to give our community an official high-level recap of Kap’s journey with the PBP. As a companion for this article, Phala’s Growth and Product Manager Stuart recorded an in-depth interview with Kap which you can find here.

The Promise of PrivaDEX

Kapil applied to the PBP as a developer with a strong educational and professional background who had already been building with Phat Contract on his own. His impressive pedigree was complimented by the fact that the proposed product, PrivaDEX, held several points of intrigue for Phala:

  1. PriveDEX sought to solve the acute problem of fractured liquidity in the Polkadot DeFi ecosystem in a way that had yet to be built. Specifically, PrivaDEX’s innovations included creating a UX in which a user only had to sign one transaction to perform a cross-chain swap. Furthermore, the app implemented a smart order routing logic that could split a swap between several liquidity pools to minimize price impact. Successful completion of the project would not only deliver a valuable product to Polkadot DeFi users but also serve as a strong demonstration of Phat Contract’s DeFi applications.
  2. PrivaDEX’s architecture involved a complex Phat Contract-powered executor module that would provide valuable Phat Contract primitives that future DeFi builders could potentially take advantage of.

At the time of his application to the PBP Kap had also already secured funding from the Web3 Foundation’s grant program, corroborating Phala’s perception of the project’s value. Kap’s original application to the w3f grants program offers a detailed overview of PrivaDEX’s design, market fit, and differentiating aspects from other DEX aggregator products.

PrivaDEX and Phat Contract

Phat Contract lays at the core of PrivaDEX’s architecture as the computing component powering the executor module, serving as the engine that selects and automates the swaps and bridges involved in cross-chain trading. The below diagram, taken from Kap’s application to the w3f grant program, provides a high-level overview of the app’s architecture.

To explain this diagram simply, the base layer of PrivaDEX is the Web3 indexer on the left that constantly scrapes prices from various AMM smart contracts across multiple chains, creating a price feed database that can be queried via an HTTP request.

When a user initiates a swap, they input the desired source and destination token and chain e.g. transfer GLMR on Moonbeam to DOT on Astar. This input triggers a series of Phat Contract executions outlined in steps 1 through 4.

First, a Phat Contract would query the price feed via an HTTP request and convert that data to a usable network graph. The smart order algorithm would then use the raw data from the network graph to construct an optimal swap and routing path between the source and destination. In step 3, that optimal path is turned into specific instructions for carrying out the cross-chain swapping and bridging. Finally, a Phat Contract would execute these transactions, automatically performing several cross-chain actions without any user input beyond the initial swap request. The computation powering these operations comes from Phala Network’s distributed compute providers known as Workers.

The PrivaDEX executor module showcases Phat Contract’s dynamic utility and demonstrates that Web3 builders don’t need to rely on centralized providers like AWS Lambda to construct robust backends for their dApps.

If you want to use PrivaDEX for yourself and see this process in action, you can do so on the app. Or for the developers out there who want to see the raw code, check out PrivaDEX’s GitHub.

What’s next for Kap and the Phala Builders Program?

Kap continues to support and add functionality to PrivaDEX, and the contracts he built for the app have provided valuable insights for Phala’s developers. Currently, Kap is launching a one-click cross-chain investing platform called Koingaroo, which allows users to construct a robust DeFi portfolio in minutes. Check out their Closed Beta today!

The PBP is always looking for innovators seeking to develop novel products using Phat Contract. We are currently in the process of onboarding two new teams who we will be officially announcing in the coming weeks. We expect these projects to yield a suite of new Phat Contract primitives, some of which will be integrated into our low-code experience Phat Bricks and become available as quick-deploy Blueprints. We look forward to sharing all the details with our community, and as always if you have an idea you want to see realized we encourage you to apply to the PBP!

--

--