Skip to content

yuyuke84/MerchantPro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

66 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’³ MerchantPro: Autonomous Stablecoin Settlement & B2B Treasury Ledger

MerchantPro is a high-performance B2B payment gateway and treasury engine tailored for modern enterprise operators. By composing modular account abstraction layers (ERC-4337) with next-generation stablecoin rails (Circle and Arc Network), MerchantPro unlocks frictionless business operationsβ€”including gasless payroll distributions, multi-chain invoice bridging, and autonomous AI-agent escrowsβ€”all authenticated via secure hardware biometrics (WebAuthn).


πŸ›οΈ Platform Topology & Execution Flow

MerchantPro decouples complex multi-chain execution from corporate administration through a modular architecture.

Transaction Ingestion & Settlement Path

graph LR
    %% Client & Auth
    Operator["SME Operator"] -.->|WebAuthn Passkey| Client["MerchantPro App (Next.js)"]
    
    %% Session & Ledger Boundaries
    subgraph TreasuryEngine ["Treasury Engine Boundary"]
        Client -->|Secure Sync| SessionCookies[("Session Cookies (httpOnly)")]
        Webhook["Circle Console Event"] -->|POST Callback| WebhookHandler["/api/webhook Handler"]
        WebhookHandler -->|HMAC-SHA256 Auth| SQLiteDB[("SQLite/Postgres Ledger")]
    end

    %% Web3 Execution Pipelines
    subgraph Web3Rails ["On-Chain Settlement Rails"]
        Client -->|Gasless userOp| ModularCore["Circle Modular Wallets Core"]
        ModularCore -->|Submit transaction| Bundler["ERC-4337 Bundler RPC"]
        Paymaster["Circle Gas Station"] -->|Sponsor Gas| Bundler
        Bundler -->|Execute Transfer| ArcChain["Arc Network Testnet"]

        Client -->|Cross-Chain Bridge| CCTP["Circle App-Kit (CCTP)"]
        CCTP -->|Burn Token| SourceChain["Solana / Base"]
        SourceChain -->|Iris Attestation| MintTarget["Arc Mint Event"]
    end

    %% Style Tokens
    style Operator fill:#10B981,stroke:#059669,stroke-width:2px,color:#fff
    style Client fill:#3B82F6,stroke:#2563EB,stroke-width:2px,color:#fff
    style TreasuryEngine fill:#1E293B,stroke:#475569,stroke-width:1px,color:#fff
    style Web3Rails fill:#0F172A,stroke:#334155,stroke-width:1px,color:#fff
    style SQLiteDB fill:#F59E0B,stroke:#D97706,stroke-width:1px,color:#fff
Loading

Technical Design Decisions & Tradeoffs

  • Lazy Contract Deployment: To bypass unnecessary gas costs, smart accounts (MSCA) are derived deterministically using CREATE2 address calculations at signup. The actual contract deployment on-chain is deferred until the first outgoing B2B transaction is executed.
  • HTTP-Only Session Isolation: Rather than exposing wallet configurations or credentials to client-side localStorage (susceptible to XSS attacks), all session state is synced using server-signed HTTP-only cookies with Secure, SameSite=Strict, and Path=/ parameters.
  • Concurrent Execution via 2D Nonces: To prevent sequential transaction queue blockage (where a pending trade halts the entire merchant queue), the platform leverages 2D sequential nonce keys. This enables independent payroll batches, FX swaps, and customer invoices to process concurrently.

πŸ›‘οΈ Trust Boundary & Security Policy

MerchantPro implements rigorous defensive security protocols across both backend APIs and smart contract integration endpoints:

  • Cryptographic Event Reconciliation: The payment webhook endpoint /api/webhook prevents reconciliation spoofing by validating inbound payload signatures via HMAC-SHA256. It processes the raw HTTP request body against the configured CIRCLE_WEBHOOK_SECRET to prevent tampering.
  • Secure Ephemeral Key Derivation: Autonomous agent tools and settlement engines derive keys dynamically at runtime from environment variables. If no EVM credentials are configured, the runner securely generates an ephemeral, one-time execution key in memory, avoiding hardcoded default fallback vectors.
  • Compliance Screening Rails: All outgoing transactions (transfers, bridge actions, swaps) are screened before execution against OFAC / Tornado Cash sanctions lists and heuristic check parameters, generating an immutable audit ledger inside the database.

πŸ’Ž Product Surface & Capabilities

  • 1-Click Biometric Wallet: Register and log in instantly via device-native biometrics (TouchID/FaceID) to derive a secure ERC-4337 smart account without seed phrases or plugins.
  • Gasless Payroll Batches: Upload standard CSV payroll databases to dispatch USDC to employees and vendors simultaneously in a single transaction sponsored by Circle's Gas Station.
  • On-Chain Auto-FX Conversions: Issue multi-currency invoices (USDC/EURC) featuring automated slippage-protected swaps via Circle Swap-Kit pools.
  • Cross-Chain Bridge Engine: Seamlessly accept stablecoin assets from external ecosystems (Solana, Base) and bridge them onto Arc Network via Circle CCTP.
  • Sub-Cent API Gateway (HTTP 402): Restrict premium enterprise APIs behind micro-payment check challenges verified via off-chain EIP-712 signature handshakes.

πŸ“‚ Persistence Layer & Schema

The platform runs a unified relational persistence schema (PostgreSQL for cloud environments, SQLit3 for local development cache) to manage merchant metadata, invoice states, and audit records.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    merchants    │───────<β”‚    invoices     β”‚        β”‚ webhook_events  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€        β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€        β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ id (PK)         β”‚        β”‚ id (PK)         β”‚        β”‚ id (PK)         β”‚
β”‚ credential_id   β”‚        β”‚ merchant_id (FK)β”‚        β”‚ notification_id β”‚
β”‚ msca_address    β”‚        β”‚ client_address  β”‚        β”‚ event_type      β”‚
β”‚ display_name    β”‚        β”‚ amount          β”‚        β”‚ payload (JSON)  β”‚
β”‚ contact_email   β”‚        β”‚ status          β”‚        β”‚ parsed_amount   β”‚
β”‚ fee_settings    β”‚        β”‚ tx_hash         β”‚        β”‚ processed_at    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                          β”‚
         β”‚                          β”‚
         β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”œβ”€<β”‚ payroll_batches β”‚     └─<β”‚ loyalty_tokens  β”‚
         β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€        β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
         β”‚  β”‚ id (PK)         β”‚        β”‚ id (PK)         β”‚
         β”‚  β”‚ merchant_id (FK)β”‚        β”‚ owner_address   β”‚
         β”‚  β”‚ recipients_json β”‚        β”‚ contract_addressβ”‚
         β”‚  β”‚ tx_hash         β”‚        β”‚ status          β”‚
         β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         └─<β”‚ bridge_transactions    β”‚
            β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
            β”‚ id (PK)                β”‚
            β”‚ source_chain           β”‚
            β”‚ burn_hash / mint_hash  β”‚
            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

βš™οΈ Setup & Local Development

System Requirements

  • Node.js: v18.0.0 or higher
  • Database: SQLite (default local cache) or Postgres

Local Installation

  1. Clone the Repository:

    git clone <repository_url>
    cd track-2-MerchantPro
  2. Configure Environment Parameters: Copy the example file and populate it with your API keys:

    cp .env.example .env.local
  3. Install Core Dependencies:

    npm install
  4. Boot Up Development Server:

    npm run dev

    The platform will start immediately at http://localhost:3000.

  5. Verify Production Bundle: Ensure compile integrity before deployment:

    npm run build

πŸ“‚ Source Layout & Directory Map

merchantpro/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”œβ”€β”€ auth/passkey/      # WebAuthn session cookie handlers
β”‚   β”‚   β”œβ”€β”€ webhook/           # HMAC webhook verification endpoint
β”‚   β”‚   └── rpc/               # Arc Testnet Bundler API proxy
β”‚   β”œβ”€β”€ components/            # UI components and global modal system
β”‚   β”œβ”€β”€ globals.css            # Custom design tokens & visual theme
β”‚   β”œβ”€β”€ layout.tsx             # Next.js global layout wrapper
β”‚   └── page.tsx               # SME Treasury & Invoice dashboard portal
β”œβ”€β”€ contracts/
β”‚   └── MerchantProEscrowV2.sol# Solidity escrow invoicing contract
β”œβ”€β”€ lib/
β”‚   β”œβ”€β”€ arc-config.ts          # Arc Network chain specification
β”‚   β”œβ”€β”€ contracts.ts           # ABI definitions and token addresses
β”‚   β”œβ”€β”€ db.ts                  # Database client and SQLite schemas
β”‚   └── web3-provider.tsx      # React Web3 Provider integration
β”œβ”€β”€ scripts/
β”‚   └── deploy-contracts.ts    # Smart contract deployment pipeline
β”œβ”€β”€ CONTRIBUTING.md            # Guidelines for open-source contributions
β”œβ”€β”€ LICENSE                    # MIT open-source license
└── SECURITY.md                # Vulnerability disclosure policy

About

MerchantPro: Autonomous Stablecoin Settlement & B2B Treasury Ledger

Resources

Contributing

Security policy

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages