Refs #40
File: crates/charon-core/src/types.rs line 94, crates/charon-core/src/profit.rs
PR branch: feat/15-profit-calc-and-queue
Problem:
LiquidationOpportunity (types.rs:94) has net_profit_usd_cents: u64. NetProfit from this PR also has net_profit_usd_cents: u64. The executor must copy NetProfit.net_profit_usd_cents into LiquidationOpportunity.net_profit_usd_cents when building the opportunity — a dual representation with no canonical owner.
OpportunityQueue orders by LiquidationOpportunity.net_profit_usd_cents. If the executor re-scores an opportunity (prices moved since enqueue) and the re-scored NetProfit is not written back to LiquidationOpportunity before re-enqueueing, the queue ordering reflects stale profit. The bot would then execute the wrong opportunity first.
Fix: One of: (a) remove the raw u64 field from LiquidationOpportunity and embed NetProfit directly; (b) keep the u64 field but add a LiquidationOpportunity::with_profit(opp, net_profit) constructor that enforces the copy; (c) document explicitly that net_profit_usd_cents on LiquidationOpportunity is always set from the most recent calculate_profit() call and add a test that verifies re-scoring updates the queue ordering correctly.
Refs #40
File: crates/charon-core/src/types.rs line 94, crates/charon-core/src/profit.rs
PR branch: feat/15-profit-calc-and-queue
Problem:
LiquidationOpportunity (types.rs:94) has net_profit_usd_cents: u64. NetProfit from this PR also has net_profit_usd_cents: u64. The executor must copy NetProfit.net_profit_usd_cents into LiquidationOpportunity.net_profit_usd_cents when building the opportunity — a dual representation with no canonical owner.
OpportunityQueue orders by LiquidationOpportunity.net_profit_usd_cents. If the executor re-scores an opportunity (prices moved since enqueue) and the re-scored NetProfit is not written back to LiquidationOpportunity before re-enqueueing, the queue ordering reflects stale profit. The bot would then execute the wrong opportunity first.
Fix: One of: (a) remove the raw u64 field from LiquidationOpportunity and embed NetProfit directly; (b) keep the u64 field but add a LiquidationOpportunity::with_profit(opp, net_profit) constructor that enforces the copy; (c) document explicitly that net_profit_usd_cents on LiquidationOpportunity is always set from the most recent calculate_profit() call and add a test that verifies re-scoring updates the queue ordering correctly.