Sunlit strategy table with pale stone, greenery, and a calm abstract digital asset risk dashboard.
Protocols

Liquidation Engine Design with Pull Oracles

A technical playbook for DeFi engineers and risk teams on architecting liquidation engines that safely consume Pyth's on-demand pull oracle, addressing keeper incentives, atomic price updates, and front-running mitigations.
introduction
KEEPER INCENTIVE DESIGN

The Pull Oracle Liquidation Problem

How Pyth's on-demand pull model fundamentally alters the risk and mechanics of DeFi liquidations, requiring new keeper strategies to prevent bad debt accumulation.

Liquidation engines in lending protocols are designed around a critical assumption: that the price of collateral can be read atomically during the liquidation transaction. In a push-based oracle model, this is straightforward—the price is already on-chain. Pyth Network's pull model breaks this assumption. A liquidator must now bundle a price update with the liquidation call, paying the gas cost to post the Pyth price on-chain before the protocol can verify that a position is underwater. This introduces a two-step atomicity requirement and a new cost vector that fundamentally changes the profitability calculus for keepers.

The core risk is a liquidation failure cascade. If the gas cost of a updatePriceFeeds call plus the liquidation execution exceeds the liquidation bonus, rational keepers will not liquidate the position. The protocol accrues bad debt while the price is stale. This risk is amplified during periods of high network congestion, where gas prices spike and the Pyth price on-chain is most likely to be outdated. A naive liquidation engine that simply calls getPriceUnsafe() without a recent update will either revert or, worse, use a dangerously stale price, creating a soft-liquidation vector where a position appears healthy but is actually deeply underwater.

Protocol architects must design a just-in-time (JIT) keeper incentive layer that accounts for the pull oracle's cost structure. This involves dynamically adjusting liquidation bonuses based on the gas cost of the required price update, the staleness of the current on-chain price, and the asset's volatility. A robust design often separates the price update from the liquidation in a meta-transaction or flash-loan pattern, allowing a keeper to atomically update the price and execute the liquidation only if the net profit is positive. Chainscore Labs can review this keeper incentive architecture, modeling the game theory of liquidator behavior under various gas and volatility regimes to ensure a protocol does not silently accumulate bad debt during a market crash.

LIQUIDATION ENGINE DESIGN WITH PULL ORACLES

Design Quick Facts

Key architectural risks and operational considerations for protocols building liquidation engines that consume Pyth's on-demand price updates.

AreaWhat changesWho is affectedAction

Price Update Atomicity

Liquidation and price update must occur in a single transaction; no persistent on-chain price exists.

Lending protocol developers, keeper network operators

Design liquidation flow to call updatePriceFeeds and liquidate atomically. Review for front-running vulnerabilities.

Keeper Incentive Design

Keepers must be profitable after paying gas for both the price update and the liquidation call.

Keeper network operators, protocol risk teams

Model gas costs per target chain. Ensure liquidation bonus exceeds worst-case update+execution cost.

Staleness Tolerance

The getPriceNoOlderThan parameter must be set per asset to balance freshness with execution reliability.

DeFi protocol operators, risk managers

Audit staleness thresholds against asset volatility and block times. A too-strict value can halt liquidations.

Confidence Interval Risk

Wide confidence intervals during volatility can make a position appear solvent when it is not, or vice versa.

Lending protocol risk managers, security engineers

Use the conf field to dynamically adjust liquidation thresholds or trigger circuit breakers.

Just-in-Time Price Updates

Keepers can choose to update the price only when a liquidation is profitable, creating a selective update pattern.

Protocol architects, risk teams

Monitor for systematic under-liquidation. Consider fallback mechanisms if keepers fail to update during crashes.

Cross-Chain Latency

Price delivery latency varies by target chain due to Wormhole verification and block times.

Multi-chain protocol architects, bridge integration teams

Benchmark latency per chain. Design liquidation thresholds with chain-specific safety margins.

Fallback Oracle Dependency

A stale or unavailable Pyth feed can freeze liquidations entirely if no fallback is configured.

Lending market developers, DeFi security teams

Implement a fallback oracle with a circuit-breaker proxy. Test failover behavior in forked mainnet environments.

technical-context
CRITICAL LIQUIDATION ENGINE DESIGN

Atomic Update and Liquidate Pattern

The foundational pattern for executing trustless liquidations when using Pyth Network's pull-based oracle, where price updates and state mutations must occur within a single atomic transaction.

The 'Atomic Update and Liquidate' pattern is the canonical design for liquidation engines integrated with Pyth Network's pull oracle. Unlike push oracles that asynchronously deliver price updates to a protocol, Pyth requires the transaction initiator to submit a verified price update alongside the liquidation call. This pattern mandates that both the updatePriceFeeds call and the subsequent liquidation logic (e.g., liquidateCall in a lending market) are bundled into a single, atomic transaction. This atomicity is non-negotiable; it prevents a toxic race condition where a keeper updates a stale price, making a position liquidatable, only to have a front-runner use that fresh price to execute the liquidation first.

For protocol builders and keeper network operators, this pattern introduces specific technical constraints. The keeper must simulate the entire transaction bundle locally to ensure profitability after accounting for the gas cost of the price update, which can be substantial on chains like Ethereum mainnet. The protocol's smart contracts must be designed to accept the price update proof (a VAA from Pythnet via Wormhole) and immediately apply it within the same execution context before the liquidation health check. A failure to enforce this atomicity at the contract level—for instance, by separating the update and liquidation into two distinct, non-atomic steps—introduces a critical vulnerability that directly leads to loss of keeper funds and protocol bad debt.

A rigorous review of this integration is essential. Chainscore Labs can audit the atomic execution path in a protocol's liquidation module to verify that no external calls or state changes can occur between the price update and the solvency check. We also model the gas economics for keeper networks to ensure that the 'update and liquidate' bundle remains profitable under volatile network conditions, preventing a scenario where liquidations stall due to a flawed incentive structure.

LIQUIDATION ENGINE DESIGN WITH PULL ORACLES

Affected Actors and Their Responsibilities

Core Design Responsibility

Protocol developers must architect liquidation functions that are compatible with the pull oracle's on-demand update model. The primary challenge is ensuring that a price update and a liquidation can occur within a single atomic transaction to prevent front-running.

Key Actions

  • Atomicity Design: Implement a updatePriceAndLiquidate function that bundles the Pyth price update with the liquidation logic. Failing to do so creates a window where a stale price is used or a fresh price is front-run.
  • Gas Optimization: Profile the gas cost of the Pyth update fee and verification logic alongside the liquidation logic. Unprofitable liquidations due to high gas costs will lead to a keeper drought and bad debt accumulation.
  • Staleness and Confidence Checks: Do not rely on the keeper to provide a fresh price. The contract must enforce getPriceNoOlderThan and validate the confidence interval to prevent manipulation via a low-confidence or stale update.

Chainscore can review your liquidation engine's atomicity guarantees and gas profile to ensure keepers remain economically incentivized.

implementation-impact
LIQUIDATION INFRASTRUCTURE FOR PULL ORACLES

Keeper Network Design Patterns

Design patterns for keeper networks that must atomically update a Pyth price feed and execute a liquidation in a single transaction, managing gas competition, profitability, and stale-price risk.

03

Staleness-Aware Liquidation Thresholds

A keeper's profitability calculation must account for the protocol's staleness tolerance. If a price feed is near its getPriceNoOlderThan limit, a keeper might successfully update it and liquidate, but the price could be stale enough that the position's true health is marginal. Keepers should implement a buffer: only pursue liquidations where the protocol's health factor is below a keeper-defined threshold that accounts for potential price movement during the staleness window. This prevents unprofitable liquidations where the gas cost exceeds the liquidation bonus after slippage.

04

Confidence Interval as a Profitability Gate

Sophisticated keepers use Pyth's conf field to filter out liquidations with high uncertainty. A wide confidence interval indicates publisher disagreement or volatile market conditions. Before submitting a transaction, the keeper should calculate a worst-case price by subtracting the confidence interval from the reported price and re-evaluate the position's health. If the position is not clearly underwater under this worst-case scenario, the keeper should skip it. This avoids liquidating positions that may become healthy again in the next slot, wasting gas and damaging the protocol's reputation.

06

Fallback and Circuit-Breaker Integration for Keepers

Keeper bots must monitor for Pyth network anomalies that make liquidation unsafe. If the price feed's confidence interval spikes beyond a threshold, the staleness exceeds a critical limit, or the Pyth contract is paused, the keeper should halt operations. More resilient keepers can integrate with a protocol's fallback oracle: if the primary Pyth feed is degraded, the keeper checks if the protocol has switched to a secondary source (like a Chainlink feed or a TWAP) and executes liquidations against that source instead. This requires the keeper to understand the protocol's full oracle architecture.

PULL ORACLE FAILURE MODES IN LIQUIDATION CONTEXTS

Liquidation-Specific Risk Matrix

Maps the unique risks that arise when a liquidation engine depends on a pull oracle for price updates, identifying failure modes, affected actors, and required operational or design actions.

Risk AreaFailure ModeWho is affectedAction

Stale Price Liquidation

Keeper calls updatePriceFeeds but the on-chain price is older than the protocol's staleness threshold, allowing liquidation at an outdated price.

Lending protocol users, risk managers

Enforce a strict getPriceNoOlderThan check in the liquidation function; keepers should simulate the call off-chain to confirm freshness before submitting.

Unprofitable Keeper Execution

The gas cost of calling updatePriceFeeds plus the liquidation exceeds the liquidation bonus, causing keepers to ignore profitable positions.

Keeper network operators, protocol solvency

Design a gas-efficient update pattern (e.g., update a single feed per liquidation); monitor keeper participation rates and adjust liquidation bonuses dynamically.

Front-Running the Price Update

A searcher observes a keeper's pending updatePriceFeeds transaction and front-runs it with their own update and liquidation, extracting the profit.

Keeper network operators

Use Flashbots or similar private transaction relays; implement a commit-reveal scheme or a first-come-first-serve update mechanism in the liquidation contract.

Confidence Interval Spike

During high volatility, the Pyth confidence interval widens significantly, but the liquidation engine uses only the price, ignoring the conf field, leading to liquidations at an uncertain price.

Lending protocol users, risk engineers

Incorporate the confidence interval into the liquidation threshold; pause liquidations or require a higher collateralization ratio when conf/price exceeds a set limit.

Cross-Chain Update Latency

On a non-Solana chain, the Wormhole attestation for the price update is delayed, and the keeper's transaction uses a price that is valid on Pythnet but stale for the target chain's block.

Multi-chain lending protocols, bridge operators

Set a chain-specific staleness threshold that accounts for Wormhole guardian consensus time; monitor VAA delivery latency and alert on degradation.

Incomplete Batch Update

A keeper updates a basket of price feeds but the transaction runs out of gas before all feeds are updated, leaving the protocol with a mix of fresh and stale prices.

Smart contract developers, keepers

Structure the liquidation to require and verify a single, specific price feed update; avoid multi-feed batch updates in the liquidation path.

Publisher Divergence During Liquidation

A minority of publishers report a price that would make a position solvent, but the aggregate price triggers a liquidation, leading to disputes and potential bad debt if the aggregate is wrong.

Protocol governance, risk teams, users

Monitor for publisher divergence off-chain; implement a circuit breaker that pauses liquidations if the inter-quartile range of publisher prices exceeds a governance-set threshold.

PULL ORACLE LIQUIDATION READINESS

Liquidation Engine Implementation Checklist

A technical checklist for engineering and risk teams building or auditing a liquidation engine that relies on Pyth's pull oracle. Each item identifies a critical design consideration, explains the risk of failure, and defines the signal that confirms correct implementation.

What to check: The liquidation function must call pyth.updatePriceFeeds with the required price update data in the same transaction that checks account health and seizes collateral.

Why it matters: Without atomicity, a keeper's transaction can be front-run. An attacker can see the price update in the mempool, execute the same update in a prior transaction, and then perform a risk-free liquidation before the original keeper, stealing the profit. The protocol must enforce that the price used for the health check is the one just posted in the same atomic execution context.

Readiness signal: The smart contract's liquidation entry point accepts bytes[] calldata updateData as a parameter and calls pyth.updatePriceFeeds(updateData) before any getPriceUnsafe or getPriceNoOlderThan call. A fuzz test confirms that a stale on-chain price (from a prior block) cannot be used to validate a new liquidation.

Chains We Build On

Looking to build on a specific blockchain?

We build smart contracts, DeFi applications, wallets, tokenization platforms, and blockchain infrastructure across the major ecosystems teams choose today. That includes Ethereum, Arbitrum, Optimism, Polygon, Avalanche, Solana, Sui, Aptos, Hedera, Stellar, and NEAR, with support for additional EVM and non-EVM networks based on your product requirements.

EVM ecosystems

  • Ethereum logo
    Ethereum
  • Arbitrum logo
    Arbitrum
  • Optimism logo
    Optimism
  • Polygon logo
    Polygon
  • Avalanche logo
    Avalanche
  • Cronos logo
    Cronos

Non-EVM ecosystems

  • Solana logo
    Solana
  • Sui logo
    Sui
  • Aptos logo
    Aptos
  • Hedera logo
    Hedera
  • Stellar logo
    Stellar
  • NEAR logo
    NEAR

Additional ecosystems

  • Polkadot logo
    Polkadot
  • Cosmos logo
    Cosmos
  • TON logo
    TON
  • Cardano logo
    Cardano
  • Algorand logo
    Algorand
  • Tempo logo
    Tempo

Also available for Base, appchains, custom EVM networks, and cross-chain product architecture.

LIQUIDATION ENGINE DESIGN WITH PULL ORACLES

Frequently Asked Questions

Critical questions engineering and risk teams face when building or auditing a liquidation engine that depends on Pyth's on-demand pull oracle model.

In a push oracle model, the price is already on-chain when a keeper calls the liquidation function, making the transaction atomic and predictable. With Pyth's pull model, the price is not on-chain. The keeper must submit a price update payload alongside the liquidation call. This introduces a critical design constraint: the liquidation transaction must atomically update the price and execute the liquidation in a single block. If the price update and liquidation are separated, a front-runner can manipulate the state between calls. Your engine must be designed for this atomic, two-step-in-one-transaction flow, which significantly impacts gas profiling and keeper strategy.

Trusted by Industry Leaders

Delivering blockchain solutions for 5+ years.

We have partnered with 50+ leading DeFi protocols, NFT ecosystems, and fintech innovators to build secure, scalable, and capital-efficient blockchain products.

Selected Partners & Clients

ChainVote logo
Reax logo
Sokail logo
Swapsicle logo
SyntheX logo
Tekika logo
Telos logo
Zexe logo
ChainVote logo
Reax logo
Sokail logo
Swapsicle logo
SyntheX logo
Tekika logo
Telos logo
Zexe logo
ChainVote logo
Reax logo
Sokail logo
Swapsicle logo
SyntheX logo
Tekika logo
Telos logo
Zexe logo
ChainVote logo
Reax logo
Sokail logo
Swapsicle logo
SyntheX logo
Tekika logo
Telos logo
Zexe logo
“I've been working with Chainscore Labs for last 3+ years, they've consistently delivered with strong ownership across multiple projects. The team is reliable and detail-oriented.”
L
Lee Erswell
CEO, Telos Foundation
how to get started

How to get started?

If you're looking for blockchain integration, ChainScore Labs has 5+ years of experience helping teams build and integrate exchanges, wallets, smart contracts, tokenization solutions, and protocol-connected products, we can help you choose the right path, integrate securely, and get to production faster. Our team consists of experienced blockchain developers and architects who can help you with your blockchain integration needs.

01

Exploration & Strategy

Define your product goals and choose the right blockchain architecture for your use case.

02

Architecture & Design

Design the smart contracts, tokenomics, and security parameters of your system.

03

Development & Integration

Build and integrate with wallets, oracles, and front-end dApps for a seamless experience.

04

Security & Launch

Comprehensive audits followed by a risk-managed mainnet deployment to protect your users.

Start a build

Need a blockchain engineering team?

Send the project context and we will respond with next steps, scope questions, and a practical path to delivery.