Apollos Docs
Dev

Chainlink Workflow

The Autonomous Hedge Fund System

Apollos Finance is not a static DeFi protocol that waits for user interaction.
With Chainlink CRE (Chainlink Runtime Environment), Apollos operates as a 24/7 autonomous system with seven parallel workflows designed to:

  • Protect LPs from real-time market risk.
  • Keep leveraged positions healthy.
  • Verify credit-source solvency.
  • Compute and publish NAV efficiently.
  • Optimize cross-chain deposits.
  • Publish transparent machine decisions through AI logs.
  • Compute and publish VaR risk feeds for each vault.

This architecture functions as the Central Nervous System of Apollos.

Workflow Map

  1. The Reactive Defender
  2. The Strategist
  3. The Solvency Auditor
  4. The Accountant
  5. The Cross-Chain Manager
  6. The Reporter
  7. The VaR Calculator

Template Mapping

  1. Defender
    Template: building-blocks/indexer-block-trigger
  2. Strategist
    Template: starter-templates/custom-data-feed/cre-custom-data-feed-ts
  3. Auditor
    Template: starter-templates/custom-data-feed/cre-custom-data-feed-ts
  4. Accountant (NAV)
    Template: starter-templates/bring-your-own-data/workflow-ts/nav
  5. Cross-Chain Manager
    Template: starter-templates/multi-chain-token-manager
  6. Reporter
    Template: starter-templates/tokenized-asset-servicing
  7. VaR Calculator (Hybrid)
    Primary: starter-templates/bring-your-own-data/workflow-ts/nav
    Secondary: building-blocks/read-data-feeds

1) The Reactive Defender

Reactive Defender Diagram

Core feature: Event-driven LVR protection and anti-JIT defense
Template: building-blocks/indexer-block-trigger

Problem

Arbitrage bots can attack pools within seconds during volatility spikes, reducing LP profit through LVR loss.

How It Works

  1. Listen: receive indexer payload through HTTP trigger.
  2. Detect: parse swaps and identify whale activity.
  3. Analyze: combine Chainlink/Uniswap divergence, optional Binance volatility, and optional Gemini vote.
  4. Consensus: aggregate signals.
  5. Chainwrite: send writeReport through CRE Forwarder and GenericWorkflowReceiver to update LVRHook.setDynamicFeeWithReason(...).

Value

Fast, event-driven LP protection without waiting for long cron intervals.

2) The Strategist

Strategist Diagram

Core feature: Health Factor rebalancing and yield optimization
Template: starter-templates/custom-data-feed/cre-custom-data-feed-ts

Problem

If collateral drops sharply, the position risks liquidation. If too safe, capital becomes underutilized.

How It Works

  1. Monitor: cron runs every configured interval to read getHealthFactor() per vault.
  2. Compute: compare HF against configured band (hfMin, hfMax).
  3. Decision:
    • HF < hfMin -> defensive rebalance.
    • HF > hfMax -> capital-efficiency rebalance.
  4. Chainwrite: trigger rebalance() via writeReport path (Forwarder -> GenericWorkflowReceiver -> Vault).
  5. Optional AI: attach Gemini reason log for operator visibility.

Value

Set-and-forget operation: positions are managed automatically 24/7.

3) The Solvency Auditor

Solvency Auditor Diagram

Core feature: Lender-liquidity verification (whale monitoring)
Template: starter-templates/custom-data-feed/cre-custom-data-feed-ts

Problem

If a delegator/whale suddenly withdraws liquidity, vault credit capacity can collapse and create repayment risk.

How It Works

  1. Check: cron reads delegator collateral and vault debt from Aave state.
  2. Verify: compute collateral/debt ratio in bps.
  3. Classify severity:
    • OK
    • WARN
    • CRITICAL
    • EMERGENCY
  4. Chainwrite:
    • WARN/CRITICAL -> setBorrowPaused(true) when needed.
    • EMERGENCY -> setPaused(true) when configured.
  5. Optional offchain alert: POST emergency payload to reporter backend.

Value

Prevents systemic failure from credit-line dependency.

4) The Accountant

Accountant Diagram

Core feature: Off-chain NAV/share-price computation and feed publication
Template: starter-templates/bring-your-own-data/workflow-ts/nav

Problem

Full NAV computation in Solidity is expensive for user deposit/withdraw transactions.

How It Works

  1. Collect: read vault state (totalAssets) and optional decomposed sources.
  2. Compute off-chain:
    • fast mode: totalAssets.
    • decomposed mode: NAV = (Idle + LP Value) - Debt.
  3. Consensus on computed NAV.
  4. Chainwrite publish:
    • Forwarder -> GenericWorkflowReceiver -> DataFeedsCache.updateRoundData(dataId, answer, updatedAt).
  5. Consumer integration:
    • Vault/oracle readers consume NAV through latestRoundData(bytes32 dataId).

Value

Significant gas savings for users and stronger Chainlink-native design.

5) The Cross-Chain Manager (Bridge Optimizer)

Cross-Chain Manager Diagram

Core feature: Cross-chain deposit aggregation (batching)
Template: starter-templates/multi-chain-token-manager

Problem

Bridging every small deposit through CCIP is cost-inefficient.

How It Works

  1. Buffer: keep deposits in source-chain adapter/router.
  2. Monitor: cron reads adapter token balance.
  3. Threshold policy: if balance >= batchThreshold, execute bridge.
  4. Chainwrite path:
    • Forwarder (source chain) -> GenericWorkflowReceiver -> SourceRouter.bridgeToArbitrum(...).
  5. CCIP delivery:
    • message and token transfer reach receiver on destination chain.

Value

Substantially lower bridge cost for retail users through batching.

6) The Reporter

Reporter Diagram

Core feature: Activity logs and AI-readable explanations for users
Template: starter-templates/tokenized-asset-servicing

Problem

DeFi systems often look like black boxes: users cannot see why fees changed or why rebalances happened.

How It Works

  1. Capture: EVM LogTrigger listens to configured contracts (Vaults, Hook, DataFeedsCache, CCIP contracts).
  2. Decode: parse event payload and normalize metadata.
  3. Explain:
    • base deterministic reason builder from event type.
    • optional Gemini rewrite for user-facing explanation.
  4. Publish: send normalized JSON via HTTP POST to backend endpoint.
  5. FE display: logs appear in AI Guardian Logs.

Value

Machine-decision transparency, higher user trust, and clearer audit trails.

7) The VaR Calculator

VaR Calculator Diagram

Core feature: Off-chain VaR computation and risk-feed publication
Template: Hybrid
Primary: starter-templates/bring-your-own-data/workflow-ts/nav
Secondary: building-blocks/read-data-feeds

Problem

A leverage vault needs a machine-readable risk signal, not just NAV, to drive monitoring and front-end risk transparency.

How It Works

  1. Read vault state:
    • totalAssets
    • getCurrentLeverage
  2. Fetch historical Chainlink rounds (lookback window, configurable).
  3. Compute returns distribution and confidenceLevel VaR in bps.
  4. Apply safety floor (minVarBps) when tail is too flat.
  5. Chainwrite publish:
    • Forwarder -> GenericWorkflowReceiver -> DataFeedsCache.updateRoundData(VAR_ID, bps, updatedAt).

Value

Adds quantitative risk telemetry per market (afWETH, afWBTC, afLINK) and enables risk-aware UX.

Simulation and Broadcast (Current)

All workflows are modular and can be simulated independently:

cre workflow simulate workflows/strategist --target=staging-settings --broadcast
cre workflow simulate workflows/auditor --target=staging-settings --broadcast
cre workflow simulate workflows/accountant --target=staging-settings --broadcast
cre workflow simulate workflows/bridge-manager --target=staging-settings --broadcast
cre workflow simulate workflows/var-calculator --target=staging-settings --broadcast

Defender (HTTP trigger):

cre workflow simulate workflows/defender --target=staging-settings --trigger-index 0 --http-payload @workflows/defender/payload.json --non-interactive --broadcast

Reporter (EVM log trigger):

cre workflow simulate workflows/reporter --target=staging-settings --trigger-index 0 --evm-tx-hash <TX_HASH> --evm-event-index <EVENT_INDEX> --non-interactive --broadcast

Implementation Notes

  • Chainwrite workflows use a standardized route:
    • CRE Workflow -> CRE Forwarder -> GenericWorkflowReceiver -> target contract.
  • Reporter is primarily offchain publish (HTTP) and does not require chainwrite for log delivery.
  • Chainlink Price Feeds are the baseline oracle reference for market-aware logic.
  • runtime.now() is used for deterministic timestamping in workflow execution context.