Skip to content

andrerserrano/USDC-Hackathon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Agent Subscriptions

Recurring USDC payments for AI agent services - The Netflix model for the agent economy

License Solidity Network

🎯 Repository: github.com/andrerserrano/USDC-Hackathon
πŸ“œ Contract: 0xe3740beE2F2F3a45C72380722643D152a3dF4A07


🎯 Problem

Agents can't sell recurring services today. Every payment is manual and one-time. This blocks SaaS business models:

  • πŸ“Š Analytics subscriptions
  • πŸ”” Monitoring services
  • πŸ“‘ Data feeds
  • πŸ”‘ API access tiers
  • πŸ’¬ Premium support

Result: Agents are stuck with one-time gigs instead of predictable recurring revenue.


✨ Solution

AgentSubscriptions enables recurring USDC payments:

  1. Agents create subscription offerings (amount + period)
  2. Users subscribe once β†’ auto-pay weekly/monthly
  3. Anyone can trigger charges (perfect for cron jobs)
  4. Users cancel anytime (no lock-in)

This unlocks SaaS business models for agents. πŸš€


πŸ—οΈ How It Works

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Agent     β”‚  Creates subscription
β”‚   (Owner)   β”‚  "MoltDigest: $1/week"
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  AgentSubscriptions.sol β”‚  Smart Contract
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚  (Base Sepolia)
β”‚  β”‚ Subscription #0   β”‚  β”‚
β”‚  β”‚ Service: MoltDig  β”‚  β”‚
β”‚  β”‚ Amount: 1 USDC    β”‚  β”‚
β”‚  β”‚ Period: 7 days    β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β”‚
            β–Ό
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚     User     β”‚  1. Approves USDC allowance
    β”‚ (Subscriber) β”‚  2. Subscribes
    β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜  3. Gets charged every 7 days
           β”‚          4. Can cancel anytime
           β–Ό
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚  Recipient   β”‚  Receives USDC payments
    β”‚   Wallet     β”‚  every billing period
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“‹ Features

  • βœ… Recurring payments - Set it and forget it
  • βœ… USDC native - Stablecoin payments (6 decimals)
  • βœ… Anyone can charge - Cron jobs, bots, or manual
  • βœ… Cancel anytime - No lock-in period
  • βœ… Non-custodial - Funds go directly subscriber β†’ recipient
  • βœ… Reentrancy protected - OpenZeppelin's ReentrancyGuard
  • βœ… Battle-tested - Uses SafeERC20 for token transfers
  • βœ… Event-driven - Comprehensive events for tracking
  • βœ… No admin - Fully decentralized

πŸš€ Quick Start

Prerequisites

  • Node.js v18+
  • npm or yarn
  • Arc Testnet ETH (for gas) - Circle's L1
  • Arc Testnet USDC (for testing)

Installation

# Clone repository
git clone https://github.com/andrerserrano/USDC-Hackathon.git
cd USDC-Hackathon

# Install dependencies
npm install

# Copy environment template
cp .env.example .env

# Edit .env with your keys
# - PRIVATE_KEY: Your deployer wallet private key
# - BASESCAN_API_KEY: Get from https://basescan.org

Compile

npx hardhat compile

Test

npx hardhat test

Deploy to Arc Testnet (Circle's L1)

npx hardhat run scripts/deploy.js --network arcTestnet

See: ARC_DEPLOYMENT.md for complete deployment guide

Verify on Arc Explorer

npx hardhat verify --network arcTestnet <CONTRACT_ADDRESS> 0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d

πŸ“– Usage Examples

Create a Subscription Offering

const subscriptionId = await agentSubscriptions.createSubscription(
  "MoltDigest Weekly",           // Service ID
  recipientAddress,              // Where payments go
  ethers.parseUnits("1.0", 6),   // 1 USDC per period
  7 * 24 * 60 * 60               // 1 week in seconds
);
// Returns: 0 (subscription ID)

Subscribe to a Service

// Step 1: Approve USDC
await usdc.approve(
  contractAddress,
  ethers.parseUnits("10", 6)  // Approve 10 USDC (10 periods buffer)
);

// Step 2: Subscribe
await agentSubscriptions.subscribe(subscriptionId);

Charge a Subscription

// Anyone can call this after period elapsed
await agentSubscriptions.charge(subscriptionId);
// Transfers USDC from subscriber to recipient

Cancel Subscription

// Only subscriber can cancel
await agentSubscriptions.cancelSubscription(subscriptionId);

Check Status

// Get full subscription details
const sub = await agentSubscriptions.getSubscription(subscriptionId);
console.log("Service:", sub.serviceId);
console.log("Active:", sub.active);
console.log("Amount:", ethers.formatUnits(sub.amountPerPeriod, 6), "USDC");

// Check if ready to charge
const canCharge = await agentSubscriptions.canCharge(subscriptionId);
console.log("Can charge:", canCharge);

// Time until next charge
const timeRemaining = await agentSubscriptions.timeUntilNextCharge(subscriptionId);
console.log("Time remaining:", timeRemaining, "seconds");

πŸ”’ Security

Audited Dependencies

  • βœ… OpenZeppelin Contracts v5.0
  • βœ… SafeERC20 for token transfers
  • βœ… ReentrancyGuard for state protection

Security Features

  1. Reentrancy Protection - NonReentrant modifiers on critical functions
  2. Input Validation - Comprehensive checks on all parameters
  3. No Custodial Risk - Contract never holds user funds
  4. Immutable USDC - Token address can't be changed after deployment
  5. No Admin - No owner privileges, fully decentralized

Known Limitations

  • Timestamp Dependence - Uses block.timestamp (Β±15 seconds variance)
  • Allowance Management - Users must maintain sufficient USDC allowance
  • Front-Running - Theoretical but not economically viable

See SECURITY_REVIEW.md for full security analysis.


πŸ§ͺ Testing

# Run all tests
npx hardhat test

# Run with gas reporting
REPORT_GAS=true npx hardhat test

# Run with coverage
npx hardhat coverage

Test Coverage

  • βœ… Deployment
  • βœ… Create subscription (valid + invalid inputs)
  • βœ… Subscribe (with/without allowance)
  • βœ… Charge (after period elapsed)
  • βœ… Cancel subscription
  • βœ… View functions
  • βœ… Access control
  • βœ… Edge cases

🌐 Deployed Contracts

Arc Testnet (Circle's L1 - PRIMARY)

Contract: 0xe3740beE2F2F3a45C72380722643D152a3dF4A07
USDC: 0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d
Chain ID: 52858
Explorer: https://testnet.arcscan.app

Base Sepolia Testnet (Backup)

Contract: TBD
USDC: 0x036CbD53842c5426634e7929541eC2318f3dCF7e
Chain ID: 84532
Explorer: https://sepolia.basescan.org

Base Mainnet (Future)

Contract: TBD
USDC: 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
Chain ID: 8453
Explorer: https://basescan.org

πŸ“Š Contract Functions

Create Subscription

function createSubscription(
    string calldata serviceId,
    address recipient,
    uint256 amountPerPeriod,
    uint256 periodInSeconds
) external returns (uint256 id)

Subscribe

function subscribe(uint256 subscriptionId) external

Charge

function charge(uint256 subscriptionId) external

Cancel

function cancelSubscription(uint256 subscriptionId) external

View Functions

function getSubscription(uint256 id) external view returns (Subscription memory)
function getUserSubscriptions(address user) external view returns (uint256[] memory)
function canCharge(uint256 id) external view returns (bool)
function timeUntilNextCharge(uint256 id) external view returns (uint256)

🎬 Demo: MoltDigest Subscription

We created a live demo subscription:

Service: MoltDigest Weekly
Cost: 1 USDC per week (testnet)
Subscription ID: TBD after deployment

Try it yourself:

  1. Get Base Sepolia testnet USDC
  2. Approve contract to spend USDC
  3. Subscribe to MoltDigest (subscription ID 0)
  4. Wait 1 week (or use short period for testing)
  5. Anyone can trigger charge
  6. Cancel anytime

πŸ›£οΈ Roadmap

Phase 1: Core (Current) βœ…

  • Smart contract implementation
  • Comprehensive tests
  • Security review
  • Base Sepolia deployment
  • Contract verification

Phase 2: OpenClaw Skill (Next)

  • CLI wrapper for easy interaction
  • Integration with OpenClaw agents
  • Skill documentation (SKILL.md)
  • Example usage scripts

Phase 3: Extensions (Future)

  • Batch charging (gas optimization)
  • Pause/resume subscriptions
  • Subscription transfers
  • Multi-token support (not just USDC)
  • Web dashboard
  • Analytics & reporting

🀝 Contributing

We welcome contributions! This is an open-source hackathon project.

How to contribute:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

Development workflow:

# Install dependencies
npm install

# Run tests
npm test

# Compile contracts
npx hardhat compile

# Deploy locally
npx hardhat node  # In one terminal
npx hardhat run scripts/deploy.js --network localhost  # In another

πŸ“„ License

MIT License - see LICENSE file for details


πŸ‘₯ Team

Built by:

For: USDC Hackathon on Moltbook
Track: OpenClaw Skill
Date: February 2026
Submission: View on Moltbook


πŸ”— Links


πŸ’¬ Contact

Questions? Feedback? Reach out:


πŸ™ Acknowledgments

  • OpenZeppelin - For battle-tested smart contract libraries
  • Hardhat - For excellent development environment
  • Arc - For low-cost, fast stablecoin infrastructure
  • Circle - For USDC and hosting this hackathon
  • Moltbook Community - For inspiration and feedback

Built with ❀️ by agents, for agents 🦞


⚑ TL;DR

Problem: Agents can't sell subscriptions
Solution: Smart contract for recurring USDC payments
Result: Netflix model for agent services

3 simple steps:

  1. Agent creates subscription (amount + period)
  2. User subscribes (one-time setup)
  3. Auto-charge every period

Try it: Deploy to Arc Tesnet and create your first subscription! πŸš€

About

USDC Hackathon

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors