Backend & API architecture
How Socket's off-chain components work
The backend has the following key components :
- Quoting engine
- Transaction builder
- On-chain Indexer
- API Gateway
Socket’s quoting engine identifies best possible routes between chains for given tokens. It taps into liquidity data of DEXes and bridges to identify best possible trades. Bridges only support a limited number of tokens to bridge, requiring swaps from user-token to a bridge-supported token. The quoting engine automatically identifies which token to swap to for maximum capital efficiency.
Every DEX and bridge integrated has its own layer in the quoting engine which returns the best trade possible and Socket’s main quoting engine compiles these into routes with different combinations of DEX and Bridge quotes.
The quoting engine is exposed via the
/quoteAPI. Quotes can be customised based on various flags such as :
- Unique Routes for bridge : Multiple combinations of DEXes and Bridges can exist in a route. Setting this flag to
truereturns the best possible combination for a given pair.
- Whitelisting : Includes or excludes specific DEXes and Bridges from the quote
- Recipient Address : Setting a recipient address on the destination chain
- Smart contract integration : Fetches quotes only for bridges that support a smart contract as sender of transaction
- Sort : Sorts routes based on highest output, least bridging time & lowest fees.
Socket APIs feature endpoints for generating transaction data to interact with Socket contracts.
In the response of
/quote, for a given route returned, a userTxs array exists that contains meta data of all steps involved in the route. The
/route/start[Multi & Single Transaction Bridging] and
/Build-tx[Single Transaction Bridging] endpoint takes this as input and generates the transaction data for each tx involved.
Socket’s Indexer indexes cross-chain transaction data and exposes that data via our
bridge-statusAPI. When a cross-chain transaction is initiated, the indexer catches the
depositevent for a given bridge on the source chain, decodes necessary data and checks for the transaction’s completion on the destination chain.
The Socket API acts an interface to fetch quotes from the engine as described above. It also generates the transaction data to interact with Socket contracts. In addition to this, the API also supports
- Checking token approvals for Socket contracts
- Token Lists
- Bridging Transaction Status