How rafapolo/celohuobihack works
Project Type & Purpose
• This is a hybrid full-stack Web3 application (“VERAΞFIKO”) combining:
• A smart-contract layer (MoΞDAO) on the Celo blockchain
• A serverless/progressive decentralized frontend (dApp) served over IPFS/IPNS
• An off-chain “Agent” service in Ruby that bridges Celo and Huobi Exchange
• Purpose: provide Brazilians a private fiat→crypto on-ramp using PIX, mint 1:1 cReal (Celo Real), trade on Huobi, and channel fees into carbon-impact DAO (cMCO2).
File Structure Analysis
• Top-level directories:
• veraefiko/moedao → smart contracts (Truffle), migrations, tests, DAO vault logic
• veraefiko/dapp → static HTML/CSS/JS + PWA manifest + service worker, ABI JSON, dApp logic
• veraefiko/agente → Ruby CLI, Celo CLI wrappers, Huobi integration, IPFS metadata publisher
• Config & tooling: truffle-config.js, package.json (TypeScript scripts & tests), Gemfile (Ruby deps)
• Patterns: on-chain (contracts, migrations), off-chain agent (event monitoring, API calls), client (progressive frontend).
Architectural Components
a. Frontend dApp
• Served via IPFS/IPNS; PWA (index.html, sw.js)
• Reads oracle metadata from IPFS (HybridEx_abi.json)
• Connects to user’s Celo wallet (WalletConnect/MetaMask-Celo)
• Posts Order transactions to Celo smart contract
• Integrates PIX on-ramp (external Moedax provider)
b. Smart Contracts (MoΞDAO + HybridEx)
• Deployed on Celo; store order structs (token, chain, amount, user address, status)
• Expose on-chain oracle pointer (ipns:// metadata path)
• Govern cMCO2 vault and DAO proposals
c. Agent Service
• Ruby CLI daemon invoking celo-cli & Celo JSON-RPC
• Subscribes to chain events (new orders, cReal deposits)
• Listens to Huobi WebSocket market streams
• Calculates prices + fees off-chain, publishes metadata.json to IPFS & updates IPNS
• Executes centralized trades on Huobi via REST/WebSocket API, withdraws tokens
• Converts cReal fees → cMCO2; transfers half fees to ImpactMarket, half to DAO vault
d. External Services & Infrastructure
• IPFS/IPNS for decentralized asset hosting & metadata updates
• Huobi Exchange (REST + WSS) for market data & order execution
• Brazilian PIX rails via Moedax on-ramp (third-party KYC & QR code)
• Celo full node or light client via celo-cli for on-chain interactions
• User’s crypto wallet extension/app
Component Relationships & Data-flow
• Agent ↔ Huobi: market ticks & order execution
• Agent → IPFS/IPNS: metadata publish (token prices + fees)
• dApp → IPFS/IPNS: fetch metadata
• User Wallet → dApp: connect & sign txns
• dApp → Smart Contract: post_order() (on-chain)
• Smart Contract → Agent: emits events for new orders/deposits
• Agent → Smart Contract: update order status, record vault transfers
• Agent → Celo Node: call Mento swap, transfer cReal ↔ Celo, mint cMCO2
• Agent ↔ ImpactMarket & DAO vault (automated nightly transfers)
Architectural Patterns & Principles
• On-chain/off-chain hybrid orchestration
• Event-driven design: smart contract events trigger off-chain logic
• Decentralized hosting: IPFS/IPNS for dApp & price oracle
• Progressive Web App for trustless UX (no servers, no cookies)
• Separation of concerns:
– dApp: UX & user-initiated txns
– Agent: data ingestion, off-chain compute, trade execution
– Contracts: immutable order ledger & vault governance