Skip to content

Instantly share code, notes, and snippets.

@rafapolo
Created July 6, 2026 07:46
Show Gist options
  • Select an option

  • Save rafapolo/29e2a4b1ef108cda31b6982a7e75af1c to your computer and use it in GitHub Desktop.

Select an option

Save rafapolo/29e2a4b1ef108cda31b6982a7e75af1c to your computer and use it in GitHub Desktop.
Moeda.Casa

moeda.casa

The first PIX-to-blockchain bridge in Brazil. Send a PIX (Brazil's instant payment system), receive crypto directly in your own wallet — no exchange account, no custody, no KYC gate. A few minutes end-to-end.

Live prototype: https://moeda.casa

Origin

This project was born from two research grants aimed at bringing Brazil's real-time payment rail into the blockchain world:

  • Celo Community Fund — funded the integration and supported the creation of cREAL, the Brazilian Real–pegged stablecoin on Celo.
  • Zcash Community Grants (ZOMG) — funded exploration of payment privacy through Zero-Knowledge Proofs, integrating PIX with Zcash's shielded pool.

Both grants converged into the same working prototype: moeda.casa, built and operated under Moedax Ltda.

What it does

A user picks a token (a stablecoin, ZEC, or a Celo-native asset), enters the destination wallet, and pays a PIX. The backend:

  1. Validates the destination address against the correct format for the chosen network before anything else happens (Token#which_chain?) — malformed or incompatible addresses are rejected before funds ever move.
  2. Watches the PIX inbound stream in near real time (OrderController.observe_pix), matching each incoming transfer to its order by transaction code and confirmed amount.
  3. Buys the crypto on the market the instant the PIX clears (Order#swap!, via the Binance integration in app/lib/exchange.rb), applying a live cash-back adjustment and network fee before pricing the trade.
  4. Sends the crypto out to the user's wallet (Order#send_cripto!) — either through an exchange withdrawal for standard networks, or directly on-chain for Celo and Zcash, bypassing the exchange entirely for those rails.

Every order carries an expiry, an auditable state machine (waiting_payment → pix_received → sent / error / refunded / expired), and a slippage check between the quoted and executed price so a user is never silently short-changed.

Where the two grants show up in code

  • app/lib/pix.rb — PIX integration with Gerencianet (Efí), using mTLS client certificates and OAuth2 client-credentials to read incoming transfers and, on the outbound side, trigger PIX refunds programmatically.
  • app/lib/celo.rb — direct interaction with the Celo network via celocli: reading the on-chain stablecoin exchange rates (cREAL/cUSD/cEUR) and sending cREAL peer-to-peer with no exchange in the loop, which is what let cREAL settle a PIX purchase in seconds.
  • app/lib/zk.rb — a Ruby wrapper around the full zcash-cli RPC surface (transparent + shielded z_* commands), enabling shielded (zs...) addresses as a first-class withdrawal destination — the ZK-proof side of the ZOMG grant, letting a PIX payment settle into a shielded, privacy-preserving balance.
  • app/models/chain.rb / app/models/token.rb — a small multi-chain registry (regex-validated addresses/memos per network, per-network fees and minimums) that lets the same order pipeline route to a centralized-exchange withdrawal, a Celo direct transfer, or a Zcash shielded transaction without special-casing the checkout flow.

Stack

Ruby (Sinatra) · ActiveRecord + SQLite · Slim templates · Binance API · Gerencianet (PIX/Efí) API · Celo (celocli) · Zcash (zcash-cli) · Puma/Foreman.

Deliberately minimal: no frontend framework, no job queue, no message broker — a single small Ruby service handling payment matching, market execution, and multi-chain settlement in one auditable loop, running lean enough for a self-funded, grant-backed prototype.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment