Smart Contracts

Description: Core decentralized exchange contract handling all trading operations, liquidity management, and cross-chain bridging functionality.

Key Functions:

  • swap_eth_for_usdc(amount: Field) -> Field

  • swap_usdc_for_eth(amount: Field) -> Field

  • add_liquidity(eth_amount: Field, usdc_amount: Field) -> Field

  • remove_liquidity(lp_tokens: Field) -> (Field, Field)

  • get_pool_reserves() -> (Field, Field)

πŸ”— Network Configuration

Aztec Network

{
  "network": "aztec-alpha-testnet",
  "node_url": "https://aztec-alpha-testnet-fullnode.zkv.xyz",
  "chain_id": "31337",
  "contract_address": "0x1330e47d59fdb85ab38240724c960353ed693aae6c6c102e763a656ba4b67321"
}

Ethereum Sepolia Testnet

{
  "network": "sepolia",
  "rpc_url": "https://ethereum-rpc.publicnode.com",
  "chain_id": "11155111",
  "eth_contract": "0x...",
  "usdc_contract": "0x..."
}

πŸ“Š Price Oracle Integration

ETH/USD Feed: 0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419 USDC/USD Feed: 0x8fFfFfd4AfB6115b954Bd326cbe7B4BA576818f6 Network: Ethereum Mainnet (via Sepolia for testing) Update Frequency: Real-time

Implementation:

// Price oracle integration in Noir
struct PriceOracle {
    eth_usd_feed: Field,
    usdc_usd_feed: Field,
    last_update: Field,
}

fn get_exchange_rate(
    oracle: PriceOracle,
    from_token: TokenType,
    to_token: TokenType
) -> Field {
    // Secure price calculation using Chainlink feeds
}

πŸ” Contract Security Features

Access Control

// Admin functions with multi-sig protection
fn update_oracle_feeds(
    new_eth_feed: Field,
    new_usdc_feed: Field,
    admin_proof: AdminProof
) {
    assert(verify_admin_signature(admin_proof));
    // Update oracle feeds
}

Slippage Protection

fn execute_swap_with_slippage(
    input_amount: Field,
    min_output: Field,
    max_slippage: Field
) -> Field {
    let estimated_output = calculate_swap_output(input_amount);
    assert(estimated_output >= min_output);
    // Execute swap with protection
}

πŸŒ‰ Bridge Contracts

Cross-Chain Asset Bridge

Purpose: Secure asset transfers between Ethereum and Aztec networks Security Model: Lock-and-mint with zero-knowledge proofs Supported Assets: ETH, USDC Bridge Workflow:

  1. Lock Phase: Assets locked on source chain with proof generation

  2. Proof Verification: Zero-knowledge proof verified on destination

  3. Mint Phase: Equivalent assets minted on destination chain

  4. Confirmation: Multi-step confirmation process for security

πŸ“ˆ Liquidity Pool Architecture

AMM Implementation

struct LiquidityPool {
    eth_reserve: Field,
    usdc_reserve: Field,
    total_supply: Field,
    fee_rate: Field, // 0.3% = 3000
}

fn constant_product_formula(
    input_amount: Field,
    input_reserve: Field,
    output_reserve: Field
) -> Field {
    // x * y = k implementation with fees
}

βš™οΈ Contract Deployment Info

Parameter
Value

Compiler Version

Noir 0.34.0+

Deployment Date

December 2024

Gas Optimization

βœ… Optimized

Upgradeable

βœ… Proxy Pattern

Multi-Sig

βœ… 3/5 Admin Keys

Emergency Pause

βœ… Implemented

πŸ“ Contract Verification

Source Code

Formal Verification Status

  • βœ… Arithmetic Safety: No overflow/underflow vulnerabilities

  • βœ… Access Control: Proper permission management

  • βœ… State Consistency: All state transitions verified

  • βœ… Economic Security: MEV protection and fair pricing


All contracts are designed with security-first principles and undergo continuous monitoring for optimal performance.

If you have multiple files, GitBook makes it easy to import full repositories too β€” allowing you to keep your GitBook content in sync.

Last updated