Middleware
The Middleware is responsible for tying together all the data and logic required to provide a seamless user experience and is composed of multiple components.
Authentication
A user authenticates by proving they control the User Signer. They are then given a JWT to authenticate with the Middleware API. This JWT ensures that only authenticated and authorized users can initiate trades and intents for the associated SmartAccount.
Data Pipeline
Data is sourced and aggregated from every supported chain via blockchain nodes as well as data providers such as Alchemy. Data is queried and streamed to provide information including:
- Token balances
- Price, volume, and other market data
- Trade history and liquidity/order book data
- Event logs
Some data is already decoded and normalized and can be used directly by the Web Service. Some data must be processed via the ETL pipeline and then stored in a database.
Database
Data is stored in a TimescaleDB Postgres database that supports both relational and columnar time series data. The ability to join and query user data combined with real time aggregate market data allows Cexy to efficiently provide advanced order types (such as trailing stops) across any protocol, dynamic bridge routing, and many other features leveraged by the Intent Solver.
Web Service
The Web Service is built with Elysia which is a performant, type safe, HTTP and Websocket framework powered by the Bun runtime. It can handle hundreds of thousands of concurrent connections and is designed to be highly scalable. This asynchronous load capacity as well as high streaming throughput is critical for the Middleware stack. It provides a typed API for the frontend and other services to interact with the Middleware, avoiding common bugs and data misuse. By leveraging the Javascript ecosystem, the Middleware will have access to the largest selection of protocol SDKs for integrations.
Intent Solver
Allowing users to trade without understanding the underlying mechanics of DeFi is the core of the Cexy experience and is powered by the Intent Solver. When a user expresses an intent to buy MATIC, or stake ETH, or lend USDC, the Intent Solver translates this to a set of actions and transactions using logic and market data. These steps might include:
- Finding the best price from the Aggregator
- Bridging assets to the appropriate chain
- Submitting token approvals
- Executing a trade
Each of these steps is a part of the solution to the user's intent. These steps are combined into one or more transactions that are submitted to the Network Signer for execution. The progress is monitored by the Middleware so future steps can be executed as soon as the previous ones are confirmed. Status is streamed to the frontend so the user can see the progress of their intent in real time.
In addition to creating a great user experience, the Intent Solver provides tremendous value to integrated protocols. They can focus on providing the best value and no longer need to compete for users and liquidity because Cexy brings them both in real time.
Aggregator
The Aggregator is a meta service which finds the best price for a given trade regardless of the source. It combines data from multiple DeFi aggregators such as 1inch, Paraswap, and Matcha, as well as multiple RFQ and solver networks such as UniswapX, CowSwap, and 1inch Fusion.