Chainlink Automation

Deep dive into the automated snapshot and yield distribution system powered by Chainlink Automation.


Traditional smart contracts cannot execute themselves. They require external transactions to trigger functions. This creates problems:

Without Automation:

  • ❌ Property owner must manually trigger snapshot at exact maturity time

  • ❌ Risk of delayed/missed snapshots

  • ❌ Users must manually claim yield (poor UX)

  • ❌ Gas costs for hundreds of individual claim transactions

  • ❌ No guarantee of fair simultaneous distribution

With Chainlink Automation:

  • ✅ Automatic snapshot trigger at maturity date

  • ✅ Zero-touch for property owners

  • ✅ Automatic yield delivery to all holders

  • ✅ Single batch distribution (gas efficient)

  • ✅ Guaranteed fair distribution


Architecture


How It Works

1. Upkeep Registration

When deploying AutoDistributor, we register an "Upkeep" with Chainlink:

Deployed Upkeep:

  • Network: Base Sepolia

  • Upkeep ID: 93020392068544314578722444806384967116734687134361189041908582162518677744524

  • Status: ✅ Active

2. Continuous Monitoring (checkUpkeep)

Chainlink Keeper nodes call checkUpkeep() every block to check if work is needed:

What it checks:

  1. Is period active?

  2. Has maturity date been reached?

  3. Is snapshot not taken yet?

  4. Has yield been deposited?

If ALL conditions true → upkeepNeeded = true

3. Automatic Execution (performUpkeep)

When upkeepNeeded = true, Chainlink calls performUpkeep():

What happens:

  1. Decodes seriesId and periodId from performData

  2. Validates conditions

  3. Calls factory.triggerSnapshotForPeriod()

  4. Snapshot taken automatically! 📸

4. Manual Distribution (After Snapshot)

After snapshot, property owner calls distributeToAllHolders():

Result: USDC sent to all holders automatically!


Complete Flow Example

Timeline: Period 1 (90 Days)


Gas Costs & Economics

Upkeep Funding

Chainlink Automation requires LINK token funding:

Extremely cost-effective compared to manual operations!

Distribution Gas Costs

Batch distribution saves 3x gas!


Monitoring & Debugging

Check Upkeep Status

Get Pending Distributions

Check Distribution Status


Advanced Features

Batch Distribution

For large holder counts, distribute in batches to avoid gas limits:

Usage:

Manual Single Holder Distribution

For edge cases, distribute to single holder:


Security & Access Control

Roles

Deployed Roles:

  • DEFAULT_ADMIN_ROLE: 0x77c4a1cD22005b67Eb9CcEaE7E9577188d7Bca82 (Deployer)

  • MANAGER_ROLE: 0x77c4a1cD22005b67Eb9CcEaE7E9577188d7Bca82 (Deployer)

Important: performUpkeep() can be called by anyone!

This is intentional - Chainlink Keepers are permissionless. However:

  • Function only succeeds if conditions met

  • Cannot manipulate snapshot (atomically recorded)

  • Cannot steal funds (distribution to snapshot holders only)

Why it's safe:


Troubleshooting

Problem: Snapshot Not Triggered

Possible causes:

  1. Maturity date not reached

  2. Yield not deposited

  3. Snapshot already taken

  4. Period inactive

  5. Upkeep unfunded

Problem: Distribution Failed

Possible causes:

  1. Snapshot not taken

  2. Insufficient yield balance

  3. Gas limit exceeded (too many holders)

    • Solution: Use batchDistribute() instead


Best Practices

For Property Owners

  1. Deposit yield 1-2 days before maturity

  2. Monitor Chainlink Upkeep

    • Check dashboard: https://automation.chain.link/base-sepolia

    • Ensure LINK balance > 5 LINK

    • Top up if needed

  3. Call distributeToAllHolders() soon after snapshot

For Developers

  1. Listen to events

  2. Implement retry logic



Key Takeaways:

  1. Chainlink Automation provides zero-touch snapshot triggering

  2. checkUpkeep() monitors all periods continuously

  3. performUpkeep() triggers snapshot at maturity automatically

  4. distributeToAllHolders() sends yield to all snapshot holders

  5. Cost-effective: ~$2.40/year for automated operations


Deployed Contracts:

  • AutoDistributor: 0x8C9edAB077038B4f2e74d79663d79f3fc12Ca945

  • Upkeep ID: 93020392068544314578722444806384967116734687134361189041908582162518677744524

  • Network: Base Sepolia


Last Updated: october 2025

Last updated