Zex Finance
  • Introduction
  • Zex Overview
    • Traditional DEXs
      • Zex vs. DEX
        • Synchronization
        • Verification
    • How CEXs Works
      • Zex vs. CEX
        • TXs Verification
        • On-chain Intraction
        • Custody and Transparency
  • Tech Architecture
    • High-level Architecture
    • Smart Contacts
    • ZexPorta
      • Deposit
      • Withdraw
      • Validators
    • ZexCora
Powered by GitBook
On this page
  • Services within the Deposit Component
  • Deposit Transaction Workflow
Export as PDF
  1. Tech Architecture
  2. ZexPorta

Deposit

The primary goal of the Deposit Component is to ensure that all user deposits are accurately observed, processed, and passed on to the ZexCora. Below is a detailed breakdown of the deposit component services and workflow:

Services within the Deposit Component

The Deposit Component is composed of five specialized services:

1. Database

  • Functionality: Manages the lifecycle of deposit transactions by maintaining their status. Transactions are tracked with one of the following states: pending, finalised, verified, successful, reorg, or rejected.

  • Technology: A MongoDB database is used to store and update deposit transaction records.

2. Observer

  • Functionality: Continuously monitors new blockchain blocks to extract ERC20 transfer transactions. Identifies and inserts transactions directed to Zex user deposit addresses into the database with a status of pending.

3. Finaliser

  • Functionality: Monitors finality of blocks and validates pending deposits against finalised blocks.

  • Reorg Handling: If a transaction is not included in a finalised block, it marks the deposit status as reorg.

4. Signature Aggregator (SA)

  • Functionality: Sends finalised deposit transactions to Validators for verification. Then aggregates the signature shares issued by Validators. Furthermore, issues an additional ECDSA signature for further security.

  • Technology: Implements the Signature Aggregator component of the PyFrost library.

5. Vault Depositor

  • Task: Processes verified deposit transactions to transfer funds to the Vault.

  • Additional Functionality: Deploys user deposit contracts through the factory if they are not already deployed, ensuring seamless fund transfers.

Deposit Transaction Workflow

The deposit transaction process follows the flow illustrated in the diagram above. Each step ensures that user deposits are securely processed and efficiently transferred to the Zex Vault. Below is a detailed explanation of each step:

  1. Observer Reads Blockchain Blocks

    • The Observer continuously monitors blockchain activity, extracting ERC20 token transfer transactions from each block.

  2. Insert New Deposit Transactions into the Database

    • The Observer identifies transfers where the recipient matches a Zex user’s deposit address.

    • These transactions are marked as deposits and inserted into the database with a pending status.

  3. Retrieve Pending Transactions

    • The Finaliser retrieves pending deposits from the database for further validation.

  4. Finalise Pending Transactions

    • The Finaliser checks if pending transactions are included in a finalised block.

    • If the transaction is included, its status is updated to finalised.

    • If not, the transaction is marked as a reorg.

  5. SA Fetches New Finalised Transactions

    • The Signature Aggregator (SA) retrieves finalised transactions from the database to initiate the signature process.

  6. Send Deposit Transaction Hash to Validators for Verification

    • The SA sends the hash of finalised transactions to Validators for validation.

  7. Validators Retrieve Transaction Data

    • Validators independently fetch transaction data from the blockchain and verify the finality of the block containing the transaction.

  8. Validators Verify and Send Signature Shares

    • Validators validate the deposit transaction and issue partial signatures, which are sent back to the SA.

  9. Send Deposit and Signatures to ZexCora

    • The SA aggregates the signature shares from Validators and creates an additional ECDSA signature for security.

    • The finalised deposit data, along with the aggregated signatures, is sent to the ZexCora.

    • ZexCora verifies the data and updates the user’s balance.

  10. Update Transaction Status to Verified

    • The SA updates the deposit transaction status in the database to verified.

  11. Vault Depositor Fetches Verified Transactions

    • The Vault Depositor retrieves verified transactions from the database for further processing.

  12. Transfer Funds to the Vault

    • The Vault Depositor transfers the deposited tokens to the Zex Vault.

    • If the user’s deposit contract is not yet deployed, the Vault Depositor deploys the contract using the factory before completing the transfer.

PreviousZexPortaNextWithdraw
The data flow for depositing on the Zex