Skip to content

[pipeline] PR #42 enqueues opportunities built on broken profit calculator from PR #40 #168

@obchain

Description

@obchain

Refs #42

PR: feat(cli): wire scanner → router → builder → simulator pipeline (feat/17-cli-e2e-pipeline)
Commit: latest on feat/17-cli-e2e-pipeline
File: crates/charon-cli/src/main.rs (pipeline tick loop), crates/charon-core/src/profit.rs

PRD / invariant violated: CLAUDE.md safety: off-chain gates (profitability) must all run before simulation. A broken gate is equivalent to no gate.

Problem:

PR #42 wires the full pipeline and calls calculate_profit() from PR #40. PR #40 has three unresolved p0 blockers:

  1. ProfitInputs accepts USD cents (u64) but no wei-to-USD conversion exists anywhere in the codebase. The field repay_amount_cents cannot be populated from real LiquidationOpportunity data.
  2. The profit formula gross = repay_cents * bonus_bps / 10_000 drops the collateral/debt price ratio. It is only correct when collateral and debt have the same USD price. For BNB/BTC/ETH debt positions it produces a number unrelated to actual profit.
  3. No wei-to-USD conversion path (Chainlink 8-decimal feed + per-token decimals) exists. ProfitInputs cannot be constructed from on-chain data.

PR #42 adds placeholder shims (repay_to_usd_cents_placeholder, PLACEHOLDER_GAS_USD_CENTS = 50) and still pushes results into OpportunityQueue. The queue is sorted by net_profit_usd_cents. For BNB-collateral or BTC-debt markets (the largest Venus markets on BSC), this value is off by 600x-60,000x. When the broadcast PR (#44) consumes the queue, it will execute liquidations ranked by a fabricated number.

Impact: The profit gate — the primary economic off-chain guard before eth_call simulation — produces meaningless output for all non-stablecoin markets. Unprofitable or net-negative liquidations (after gas) will reach the chain.

Fix: Block merge of PR #42 until PR #40 p0 findings (unit mismatch, formula, wei->USD path) are resolved. Alternatively, strip the profit-calc call from this PR entirely and have the pipeline gate on health factor alone until the calculator is fixed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinglayer:rustRust crates (core / scanner / protocols / executor / cli)pr-reviewFindings from PR review processpriority:p0-blockerBlocks the critical pathstatus:readyScoped and ready to pick up

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions