piggyfi · solo-built

DeFi automation platform.
Built end-to-end. Solo.

Multi-chain monitoring, smart-account automation, live financial simulators, and an AI agent layer — all production-running on hardware I control. The goal: manage real on-chain capital with the same discipline a fund engineering team brings to a paid product.

Next.js 16React 19TypeScriptTailwind 4SQLiteDrizzle ORMviemSafe Protocol KitAnthropic SDKResendTelegram Bot API
4
chains live
Mainnet · OP · Arb · Base
11
system crons
snapshots · monitors · backups · reviews
30+
agent skills
borrow · LP · swap · bridge · transmute
100%
solo-built
design · code · ops · UI · math
What's inside

Six surfaces, one codebase

Live financial simulators

Web-based simulators for two DeFi strategies, each with sliders for every parameter, live on-chain data integration, and quarterly time-walk projections. Math libs shared with CLI tools; same formulas validated against documented reference cases.

  • Self-repaying-loan simulator: 7 parameters, EAR + simple yield/redemption models, leverage looping math (geometric series)
  • Concentrated liquidity simulator: range width, volatility, fee + emission APR, IL drag heuristics, rerange cost
  • Live on-chain ingredient derivation (no manual data entry needed)

Cross-chain monitoring & alerts

Multiple system crons watching protocol state across 4 chains. Notification routing by severity to in-app, Telegram, and email. 12h dedupe via message-tag matching prevents alert fatigue.

  • Cross-chain peg + capacity monitor — fires on actionable arbitrage windows
  • Yield-venue scout — DefiLlama-backed with new-venue and APR-drop detection
  • Advisory engine — 6+ rules over portfolio snapshots, severity-tiered channels

Smart-account automation

Safe Protocol Kit integration across all four chains. Multi-step transactions batched into single executions. Retry wrapper for intermittent Safe gateway failures, with all retries logged to an audit table.

  • Multi-chain RPC fallback with per-chain transport timeouts
  • Transaction simulation with from-address (catches reverts before signing)
  • Layer-3 verification: read on-chain state post-tx to confirm expected effects

AI agent layer

Plugin-style skill system: 30+ agent-callable functions for DeFi actions (borrow, swap, bridge, transmute). Skills are first-class — schema-defined, registry-mounted, callable by either Claude or local models.

  • Anthropic SDK for high-stakes operations; Ollama-served local LLM for routine monitoring
  • Bi-weekly self-review bot: AI reads commits + portfolio state, emails improvement suggestions
  • Playbook engine: stepwise human-or-agent workflows with audit trail

Production observability

Treated as a real system from day one. Hourly backup pipeline with USB mirror and encrypted Google Drive push. Daily portfolio snapshots driving the advisory engine. Every state-changing operation written to a wallet audit log.

  • 60+ DB tables, schema migrations via drizzle-kit
  • Hot reload safety: cron worker isolated from web process
  • Comprehensive on-chain P&L: Transfer-event walking for verified historical returns

Dashboards with real numbers

Strategy detail pages showing live position state, APR projections, range visualizations, and on-chain P&L. Hydration-safe SSR — server-rendered with no client/server state drift.

  • Yield breakdown card: realized vs advertised APR per position
  • Range visualizer: pool liquidity histogram with position overlay
  • Live transmuter capacity panels across all chains
How it's wired

Architecture

Surface layer
  • Next.js 16 (App Router)
  • React 19
  • Tailwind 4
  • Server-rendered with hydration-safe live data

The web UI: dashboards, simulators, playbook controls. Static export option for the marketing site.

Service layer
  • Cron worker (tsx)
  • Drizzle ORM + SQLite
  • viem multi-chain RPC pool
  • Safe Protocol Kit

Background jobs run as micro-workflows. Backed by structured DB with schema migrations and a wallet audit log.

Protocol layer
  • Mainnet · OP · Arb · Base
  • Alchemix v3 · Aerodrome · Aave V3
  • Curve · Velodrome · Uniswap V3
  • Transmuter · CL pools · Smart accounts

Direct on-chain reads & writes via custom RPC pool with fallback transports. All ABIs vendored from upstream sources.

            ┌─────────────────────────────────────────────────────────────┐
            │                Browser (Next.js client)                       │
            │   Strategy dashboards · Simulators · Playbook controls        │
            └────────────────────────┬────────────────────────────────────────┘
                                     │
            ┌────────────────────────▼────────────────────────────────────────┐
            │              Next.js server (App Router)                        │
            │   SSR · API routes · Hydration-safe live data fetching          │
            └─────┬───────────────────┬───────────────────┬──────────────────┘
                  │                   │                   │
            ┌─────▼─────┐       ┌─────▼─────┐       ┌─────▼──────┐
            │   SQLite  │       │ Cron worker│       │  viem pool │
            │ + Drizzle │◄──────│ pnpm worker│──────►│ 4-chain RPC│
            │  60+ tbls │       │ 11 jobs    │       │  fallback  │
            └─────▲─────┘       └─────┬──────┘       └─────┬──────┘
                  │                   │                    │
                  │            ┌──────▼──────┐             │
                  │            │ Notifications│             │
                  │            │ in-app · TG  │             │
                  │            │ email · web  │             │
                  │            └──────────────┘             │
                  │                                         ▼
                  │                                  ┌─────────────┐
                  └─────── Anthropic SDK ◄───────────│  Smart      │
                          Local LLM (Ollama)          │  account    │
                          Skill registry (30+)        │  Safe SDK   │
                                                      └─────────────┘
Engineering depth

Selected hard problems & how they got solved

01

Multi-chain RPC abstraction

Problem

Different chains, different reliability profiles, different block times. Naïve single-RPC code dies the first time Alchemy throttles.

Approach

Custom transport layer with per-chain fallback URL lists, configurable timeouts, and lazy client construction. Arbitrum's L1-cadence block timing handled as a special case in time-to-X calculations.

02

Cron-as-micro-workflows

Problem

A cron-job table felt redundant when we already had workflows with schedule triggers, agent nodes, run history, and pause/resume.

Approach

Crons are 2-node workflows (Trigger + Action). Calendar UI surfaces them alongside user-defined jobs. System crons hardcoded in scheduler module for visibility but use the same dispatch path.

03

Hydration-safe SSR for live data

Problem

Server-rendered components with `useState(true)` for loading state cause hydration mismatches when Next.js 16 / React 19 tightens attribute serialization.

Approach

Initialize loading flags to `false`; flip true after mount via useEffect. Net effect: server-rendered HTML matches first client paint exactly, then the fetch fires.

04

On-chain math reverse-engineering

Problem

Modeled an external protocol's redemption math from public documentation that uses inconsistent formulas (compound yield in one slide, simple in another).

Approach

Built simulator with both modes toggleable. Validated against documented reference cases — slide-4 fit exact, slide-1 within rounding. Honest documentation of remaining heuristics rather than hiding the approximations.

05

Safe SDK retry hardening

Problem

Safe's transaction relay gateway has intermittent timeouts. Single-shot operations occasionally hang for 30+ seconds then fail.

Approach

Retry wrapper around both single and batch paths with exponential backoff. Every retry recovery logged to the wallet audit log so operational pattern is visible. Failure mode: log with diagnostic context, don't silently swallow.

06

Operational discipline

Problem

A platform managing real on-chain money needs more than a working web app: backups, alerts, post-mortems, evolution.

Approach

Hourly DB backup with USB + encrypted Google Drive mirroring (full restore tested). Bi-weekly self-review bot reads commits + state, emails actionable suggestions. Every commit follows a tight feat/fix/docs convention.

About

Who built this

piggyfi started as a personal tool to manage on-chain capital with the same rigor a small team would apply to a paid product. It became a serious solo build — months of evening and weekend work — touching every layer from cron schedulers to AI agents to UI hydration edge cases.

The work shipped here demonstrates breadth: modern frontend, real backend ops, complex financial math, integration with multiple external APIs, and a deliberate posture of production discipline (backups, alerting, schema migrations, audit logs). The DeFi domain is the substrate, not the point — the point is end-to-end ownership of a non-trivial system.

Looking for environments where this depth of breadth is wanted. Comfortable owning a system from glue-code to architecture, with a strong preference for getting the small details right.