Refs #40
File: crates/charon-core/src/profit.rs, crates/charon-core/src/types.rs
PR branch: feat/15-profit-calc-and-queue
Problem:
LiquidationOpportunity.debt_to_repay is U256 (token wei). Token decimals on BSC/Venus vary: BNB=18, BTCB=8, USDT=18. Chainlink prices are 8-decimal fixed-point USD. ProfitInputs.repay_amount_cents is u64.
To populate repay_amount_cents from real data:
- Fetch token decimal exponent for the debt token.
- Read Chainlink latest answer (i256, 8 decimal places).
- Compute: (debt_wei / 10^decimals) * price_usd_1e8 / 1e8 * 100 -> u64
This conversion is not implemented, not tested, and not documented anywhere in the PR. The 5 unit tests pass hardcoded cent values and never exercise a wei->cents path.
The same gap applies to gas_cost_cents (gas in wei * BNB price -> cents) and flash_fee (fee in wei * debt price -> cents). Every ProfitInputs field requires this conversion.
PRD clause: PRD requirement — profit calculation uses live Chainlink prices and is denominated correctly.
Impact: PR is functionally incomplete. No existing crate can safely populate ProfitInputs from real LiquidationOpportunity data without independently implementing this conversion, risking divergent rounding behavior across callers.
Fix: Add pub fn ProfitInputs::from_opportunity(opp: &LiquidationOpportunity, collateral_price: Price, debt_price: Price, gas_price_wei: U256, bnb_price: Price) -> Result<Self, ProfitError> where Price holds (answer: i256, decimals: u8). Include tests with realistic BSC values (1 BNB at current price, 0.001 BTCB repay, etc.).
Refs #40
File: crates/charon-core/src/profit.rs, crates/charon-core/src/types.rs
PR branch: feat/15-profit-calc-and-queue
Problem:
LiquidationOpportunity.debt_to_repay is U256 (token wei). Token decimals on BSC/Venus vary: BNB=18, BTCB=8, USDT=18. Chainlink prices are 8-decimal fixed-point USD. ProfitInputs.repay_amount_cents is u64.
To populate repay_amount_cents from real data:
This conversion is not implemented, not tested, and not documented anywhere in the PR. The 5 unit tests pass hardcoded cent values and never exercise a wei->cents path.
The same gap applies to gas_cost_cents (gas in wei * BNB price -> cents) and flash_fee (fee in wei * debt price -> cents). Every ProfitInputs field requires this conversion.
PRD clause: PRD requirement — profit calculation uses live Chainlink prices and is denominated correctly.
Impact: PR is functionally incomplete. No existing crate can safely populate ProfitInputs from real LiquidationOpportunity data without independently implementing this conversion, risking divergent rounding behavior across callers.
Fix: Add pub fn ProfitInputs::from_opportunity(opp: &LiquidationOpportunity, collateral_price: Price, debt_price: Price, gas_price_wei: U256, bnb_price: Price) -> Result<Self, ProfitError> where Price holds (answer: i256, decimals: u8). Include tests with realistic BSC values (1 BNB at current price, 0.001 BTCB repay, etc.).