Comment on page


High-level overview of the system architecture of YAD Finance
YAD's architecture is centered around smart contracts, which serve to aggregate liquidity and execute transactions. Our design maximizes security and trust by using flash wallets, and a proxy contract is used as the entry point into the system, which then delegate-calls into features and transformers.
  1. 1.
    Proxy The central point of system interaction, handling all entry points. It operates by delegating specific functions to Features, managing the flow and exchange of assets. Each function is handled by a unique implementation contract or 'feature'. The Proxy's main job is to maintain a map of features and their corresponding contracts, rerouting calls to these through its fallback system.
  2. 2.
    Features These are the essential building blocks of the YAD smart contracts, trusted with user allowances. They are executed in the Proxy context via a delegate-call.
  3. 3.
    Flash Wallets Acting as secure escrow accounts, Flash Wallets hold funds for Transformers to work with. Features transfer tokens to these wallets, which in turn delegate calls to Transformers. This secure system ensures Transformers only have access to funds in the Flash Wallet, not user allowances. This type of interaction (with the flash wallet between internal smart-contract and trustless transformers) helps to increase security while internal smart contracts interact with transformers.
  4. 4.
    Transformers These contracts extend the core YAD smart contracts. Operating as trustless extensions, Transformers are approved by the Transformer Deployer. Each Transformer is tied to a specific nonce from the Transformer Deployer. Transformers execute their tasks in the context of the Flash Wallet via delegate-call, improving security during interactions.
Simplified architecture of YAD Finance
Our implementation builds upon the proven and audited architecture of the 0x protocol. We opted to retain the transformer components within this structure due to their inherent modularity, offering flexibility in extending the core smart contracts. Importantly, transformers are invoked from the flash wallet, a design choice that reinforces the security of the system by compartmentalizing operations and maintaining strict access controls.
DEX Scraping and Swap Routing
YAD's frontend sends API requests to the backend roughly every 10 seconds, and when a user enters the "amount in" into the swap form or changes some parameters in the swap settings, the frontend asks the backend for the best price and route.
Five route options are considered, including the 0x router, the 1inch router, the Odos router, and our own router and RFQ. Our router splits the "amount in" into 5% partitions and then calculates the best route for every partition. The final route takes into account the "amount out" and the gas used for the transaction.