Settlement Triggers

Settlement Triggers

Preimage Research uses a multi-trigger settlement system that automatically optimizes for different usage patterns. Understanding these triggers helps you predict cash flow and verify system economics.

The Four Triggers

Every 60 seconds, the settlement worker checks if any of these conditions are met:

fn should_settle(queue: &SettlementQueue) -> bool {
    queue.accumulated_usdc >= $1.00 ||      // Amount trigger
    queue.payment_count >= 100 ||            // Count trigger
    queue.age_secs() >= 3600 ||              // Time trigger (1 hour)
    queue.accumulated_usdc >= $10.00         // High-value trigger
}

When ANY trigger fires, the entire batch settles immediately.


Trigger 1: Amount Threshold ($1.00)

Purpose

Ensures gas overhead remains ≤1% regardless of payment size.

Rationale

Gas Economics Math:

Base network gas cost: ~$0.01 per batch transaction
Target gas overhead: ≤1%
Required batch value: $0.01 / 0.01 = $1.00 minimum

Therefore: $1.00 threshold ensures gas overhead ≤1%

Why $1.00 Specifically?

AlternativeGas OverheadCash FlowDecision
$0.502%FasterAcceptable but not optimal
$1.001%Balanced✅ Optimal sweet spot
$2.000.5%SlowerToo long for providers

Real-World Validation:

  • 80% of API calls are $0.01-$0.10
  • At $0.05/call, $1.00 = 20 payments (settles in ~30-60 minutes)
  • Balances gas efficiency with reasonable settlement frequency

Example

Medium-frequency Image API ($0.05/call):
10:00 - Start: $0.00
10:15 - 10 calls: $0.50
10:30 - 20 calls: $1.00
10:35 - 21 calls: $1.05 ⚡ AMOUNT TRIGGER
      → Batch settles 21 payments

Economics:
- Gas: $0.01 / $1.05 = 0.95% overhead ✅

Trigger 2: Count Threshold (100 Payments)

Purpose

Optimizes gas efficiency for high-frequency users (AI agents, bots).

Rationale

Batch Size Analysis:

Batch SizeGas CostGas/PaymentOverhead @ $0.01Overhead @ $0.10
10$0.01$0.00110% 😐1% ✅
50$0.01$0.00022% 😊0.2% ✅
100$0.01$0.00011% ✅0.1% ✅
200$0.02$0.00011% ✅0.1% ✅
1000$0.10$0.00011% ✅0.1% ✅

Why 100?

  • Below 50: Gas overhead >2% for micropayments (not competitive)
  • 50-100: Optimal range (1-2% overhead)
  • Above 100: Diminishing returns + time trigger likely hits first

Real-World Validation:

  • High-frequency users (AI agents) make 100 calls in 5-10 minutes
  • Provides optimal gas efficiency (1%) while settling frequently
  • Larger batches (200+) rarely form before time trigger hits

Example

High-frequency AI Agent API ($0.01/call):
14:00 - 50 calls in 3 minutes: $0.50
14:03 - 100 calls total: $1.00
      ⚡ COUNT TRIGGER (100 payments) + AMOUNT TRIGGER
      → Batch settles immediately

14:06 - Another 100 calls → Another batch
14:09 - Another 100 calls → Another batch

Economics per batch:
- Payments: 100 × $0.01 = $1.00
- Gas: $0.01
- Overhead: 1.0% ✅
- Net per call: $0.0099
- Batches per hour: ~10 (every 6 minutes)
- Hourly net revenue: $9.90

Trigger 3: Time Threshold (1 Hour)

Purpose

Safety net ensuring no payment waits indefinitely. Supports low-frequency users.

Rationale

User Experience Considerations:

Maximum acceptable settlement delay: 1 hour

Too short (under 30 min): Inefficient for low-frequency users
Too long (>2 hours): Poor provider cash flow, risk accumulation
1 hour: Balances all concerns ✅

Why 1 Hour?

  • Safety net: Ensures no payment waits indefinitely
  • Low-frequency support: Enables batching even for 1-5 calls/hour
  • Cash flow: Hourly settlements acceptable for most providers
  • Risk management: Limits unsettled payment accumulation

Real-World Validation:

  • 70% of users trigger time threshold (low-medium frequency)
  • Providers comfortable with hourly settlements
  • Aligns with industry standards (Stripe batches hourly)

Example

Low-frequency Blogger API ($0.10/call):
00:00 - Call #1: $0.10 → Added to queue
00:15 - Call #2: $0.10 → Queue: $0.20
00:45 - Call #3: $0.10 → Queue: $0.30
01:00 - ⚡ TIME TRIGGER (1 hour elapsed)
      → Batch settles 3 payments

Economics:
- Payments: 3 × $0.10 = $0.30
- Gas: $0.005
- Overhead: 1.7%
- Net per call: $0.0983
💡

Even with only 3 payments, the time trigger ensures settlement within 1 hour. Gas overhead (1.7%) is still acceptable for small batches.


Trigger 4: High-Value Threshold ($10+)

Purpose

Immediate settlement for large payments where gas is negligible.

Rationale

Immediate Settlement Math:

For `$10+` payments:
Gas overhead: $0.005 / $10 = 0.05% (negligible)

Worth settling immediately because:
1. Gas is insignificant percentage
2. Provider gets paid faster
3. Reduces unsettled amount risk

Why $10?

ThresholdGas OverheadDecision
$50.1-0.2%Can still wait for batch
$10under 0.1%✅ Immediate justified
$20under 0.05%Immediate but unnecessary distinction

Real-World Validation:

  • High-value calls are rare (under 5% of total)
  • Providers appreciate immediate settlement for large payments
  • Reduces need for credit checks on high-value transactions

Example

Enterprise Financial Data API ($15/call):
09:00 - First API call: $15.00
      ⚡ HIGH-VALUE TRIGGER ($15 > $10)
      → Immediate settlement (1 payment in 1 transaction)
      (Don't wait for batch - worth settling now)

Economics:
- Payment: $15.00
- Gas: $0.005 (individual tx, not batched)
- Overhead: 0.03% (negligible)
- Net: $14.995

Trigger: High-value (immediate settlement justified)

Settlement Flow Diagram

┌─────────────────────────────────────────────────────────┐
│  API Call → Payment Verification → Service Granted      │
└────────────┬────────────────────────────────────────────┘


┌─────────────────────────────────────────────────────────┐
│  Settlement Queue (per wallet)                           │
│  • accumulated_usdc                                      │
│  • payment_count                                         │
│  • first_payment_at                                      │
│  • pending_signatures[]                                  │
└────────────┬────────────────────────────────────────────┘

             ▼ (checked every 60 seconds)
┌─────────────────────────────────────────────────────────┐
│  Settlement Triggers                                     │
│                                                          │
│  ┌──────────┐  ┌──────────┐  ┌──────────┐  ┌─────────┐│
│  │ Amount   │  │  Count   │  │   Time   │  │High-Val ││
│  │  ≥$1.00  │  │  ≥100    │  │  ≥1 hr   │  │  ≥$10   ││
│  └────┬─────┘  └────┬─────┘  └────┬─────┘  └────┬────┘│
│       │             │             │             │      │
│       └─────────────┴─────────────┴─────────────┘      │
│                     │ (ANY trigger)                     │
└─────────────────────┼─────────────────────────────────┘


┌─────────────────────────────────────────────────────────┐
│  Multicall Smart Contract                                │
│  • Submit all pending signatures in ONE transaction     │
│  • Gas: $0.01 ÷ batch size                             │
└─────────────────────────────────────────────────────────┘

Database Schema

The settlement queue is stored per wallet:

CREATE TABLE settlement_queue (
    -- Identity
    wallet_address TEXT PRIMARY KEY,
    
    -- Accumulated data
    accumulated_usdc NUMERIC DEFAULT 0,
    payment_count INTEGER DEFAULT 0,
    
    -- Timing (for time trigger)
    first_payment_at TIMESTAMP,
    last_payment_at TIMESTAMP,
    
    -- Pending payments (for batch submission)
    pending_payment_ids UUID[] DEFAULT '{}',
    pending_signatures JSONB[] DEFAULT '{}',
    
    -- Settlement history
    last_settlement_at TIMESTAMP,
    total_settled_usdc NUMERIC DEFAULT 0,
    total_batches_settled INTEGER DEFAULT 0
);
 
-- Indexes for trigger checks
CREATE INDEX idx_settlement_queue_amount ON settlement_queue(accumulated_usdc DESC);
CREATE INDEX idx_settlement_queue_count ON settlement_queue(payment_count DESC);
CREATE INDEX idx_settlement_queue_age ON settlement_queue(first_payment_at ASC);

Network-Specific Considerations

Base (L2) - Current Configuration

SETTLEMENT_CONFIG = {
    amount: $1.00,       // Gas ~$0.01
    count: 100,
    time: 3600s,         // 1 hour
    high_value: $10.00
}

Why this works:

  • Base has low gas fees (~$0.01)
  • Supports micropayments down to $0.001
  • Optimal for AI agents and high-frequency APIs

Ethereum Mainnet (Future)

// Would need adjustment for higher gas
SETTLEMENT_CONFIG = {
    amount: $50.00,      // Gas ~$5
    count: 500,          // Larger batches needed
    time: 86400s,        // 24 hours
    high_value: $500.00
}

Why different:

  • Higher gas requires larger batches to maintain profitability
  • Less suitable for micropayments (under $0.10)
  • Better for high-value B2B APIs

Polygon (Future)

// Similar to Base (low gas)
SETTLEMENT_CONFIG = {
    amount: $1.00,
    count: 100,
    time: 3600s,
    high_value: $10.00
}

Trigger Distribution in Production

Based on usage patterns, we observe:

Trigger% of SettlementsTypical Users
Time (1 hour)70%Blogs, personal APIs, low-medium frequency
Amount ($1)20%Medium-frequency APIs (image processing, data APIs)
Count (100)8%AI agents, bots, high-frequency automation
High-Value ($10+)2%Enterprise APIs, financial data, B2B services

Key Insight: The multi-trigger system ensures every usage pattern is optimized. Most users (70%) trigger on time, ensuring consistent hourly settlements. High-frequency users (8%) get optimal gas efficiency with count triggers.


Predictable Cash Flow

User TypeSettlement FrequencyTypical WaitGas Overhead
Low-frequencyHourly (time)under 1 hour1-2%
Medium-frequencyEvery 45-60 min (amount)under 1 hour0.5-1%
High-frequencyEvery 5-10 min (count)under 10 min1%
EnterpriseImmediate (high-value)0 minunder 0.1%

Universal Guarantee: No payment waits longer than 1 hour.


Verification

You can check your pending settlements via the API (optional):

GET /settlements/status?wallet=0xYourWallet
 
Response:
{
  "wallet_address": "0xYourWallet",
  "accumulated_usdc": "0.50",
  "payment_count": 50,
  "first_payment_at": "2024-01-15T10:00:00Z",
  "age_seconds": 1800,
  "triggers": {
    "amount": false,    // $0.50 < $1.00
    "count": false,     // 50 < 100
    "time": false,      // 30 min < 1 hour
    "high_value": false // $0.50 < $10
  },
  "estimated_settlement": "2024-01-15T11:00:00Z"
}

Design Philosophy

"No payment waits longer than 1 hour, and high-frequency users get optimal gas efficiency automatically."

The four-trigger system achieves:

  • Universal Coverage: All usage patterns optimized
  • Predictable Economics: Gas overhead 0.5-2% (typically ~1%)
  • No Configuration: Automatic optimization based on usage
  • Cash Flow: Hourly settlements guaranteed
  • Scalability: Supports 1 call/hour to 1000 calls/hour

Next Steps