Skip to content

Add USDC crypto deposit funding for OpenClaw credits#1

Open
davidlsneider wants to merge 1 commit intomainfrom
feature/crypto-deposit-credits
Open

Add USDC crypto deposit funding for OpenClaw credits#1
davidlsneider wants to merge 1 commit intomainfrom
feature/crypto-deposit-credits

Conversation

@davidlsneider
Copy link
Owner

Summary

  • Agents can send USDC on Base to a single deposit address to top up their OpenClaw deployment LLM credit balance
  • Auto-detects deposits via a background poller monitoring ERC-20 Transfer events on Base chain
  • Credits the same creditBalanceUsd balance that Stripe already tops up, and updates the OpenRouter key spending limit
  • Users register sender wallet addresses for deposit attribution via new API endpoints

Changes

  • 3 new Prisma models: DepositWallet (sender address registration), CryptoDeposit (deposit records), PollerState (block tracking)
  • 2 new services: depositPoller.service.ts (background worker using viem), depositWallet.service.ts (wallet CRUD)
  • addCryptoCredit() in openclaw.service.ts — mirrors addCredits() but skips Stripe (idempotent via txHash unique constraint)
  • 5 new endpoints on /api/openclaw/deployments/:id/:
    • POST /deposit-wallets — register sender address
    • GET /deposit-wallets — list registered wallets
    • DELETE /deposit-wallets/:wid — revoke a wallet
    • GET /deposit-info — returns deposit address + chain info
    • GET /deposits — list crypto deposit history
  • 2 new env vars: USDC_DEPOSIT_ADDRESS, USDC_DEPOSIT_POLL_INTERVAL_MS

Test plan

  • Run npx prisma migrate dev --name add-crypto-deposits
  • Set USDC_DEPOSIT_ADDRESS env var and verify poller starts on boot
  • Register a wallet via POST /deposit-wallets and verify it appears in GET /deposit-wallets
  • Send USDC on Base to deposit address from registered wallet
  • Verify poller auto-credits the deployment and GET /usage shows increased balance
  • Verify GET /deposits shows the deposit record
  • Verify duplicate deposits are handled idempotently (no double-credit)

🤖 Generated with Claude Code

Agents can now send USDC on Base to a deposit address to top up their
OpenClaw deployment LLM credit balance, alongside the existing Stripe
payment method.

- Add DepositWallet, CryptoDeposit, and PollerState Prisma models
- Add deposit poller background worker monitoring Base chain for USDC
  Transfer events to the configured deposit address
- Add addCryptoCredit() to openclaw.service.ts (mirrors addCredits but
  skips Stripe since payment is onchain)
- Add wallet registration, deposit info, and deposit history endpoints
  on /api/openclaw/deployments/:id/
- Add USDC_DEPOSIT_ADDRESS and USDC_DEPOSIT_POLL_INTERVAL_MS env vars

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@davidlsneider
Copy link
Owner Author

Deployment Note

Before deploying, set the USDC_DEPOSIT_ADDRESS environment variable to the Base chain address that will receive USDC deposits. Without this, the deposit poller won't start and the /deposit-info endpoint will return null for the address.

USDC_DEPOSIT_ADDRESS=0x...your_deposit_address_here

Also run the Prisma migration:

npx prisma migrate deploy

TODO (follow-up): The deposit address should also be surfaced in the webapp UI so users can see where to send USDC. Currently it's only available via the GET /api/openclaw/deployments/:id/deposit-info API endpoint.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant