Refs #40
File: crates/charon-core/src/profit.rs
PR branch: feat/15-profit-calc-and-queue
Problem:
The formula:
slippage_cost = gross * slippage_bps / 10_000
applies slippage to the gross USD collateral-seizure amount. Slippage occurs on the DEX swap of seized collateral -> debt token to repay the flash loan. The correct model:
expected_swap_output_usd = seized_collateral_usd * (collateral_price / debt_price)
realized_swap_output_usd = expected_swap_output_usd * (1 - slippage_fraction)
slippage_cost_usd = expected_swap_output_usd - realized_swap_output_usd
Applying slippage to gross assumes the swap rate is 1:1 (collateral_price == debt_price). For stable:stable this is a reasonable approximation. For BNB collateral repaying BTCB debt (price ratio ~0.003), slippage applied to gross overstates the cost — the bot will skip profitable positions. For the reverse direction (expensive collateral, cheap debt) slippage is understated, and the bot may attempt swaps that lose more than modeled.
Impact: Systematic profit estimate error for all cross-token liquidations on Venus. Some profitable liquidations skipped; some losing swaps attempted.
Fix: Add expected_swap_output_cents: u64 to ProfitInputs (computed from SwapRoute.min_amount_out and current prices in the from_opportunity constructor). Apply slippage_bps to expected_swap_output_cents instead of gross.
Refs #40
File: crates/charon-core/src/profit.rs
PR branch: feat/15-profit-calc-and-queue
Problem:
The formula:
slippage_cost = gross * slippage_bps / 10_000
applies slippage to the gross USD collateral-seizure amount. Slippage occurs on the DEX swap of seized collateral -> debt token to repay the flash loan. The correct model:
expected_swap_output_usd = seized_collateral_usd * (collateral_price / debt_price)
realized_swap_output_usd = expected_swap_output_usd * (1 - slippage_fraction)
slippage_cost_usd = expected_swap_output_usd - realized_swap_output_usd
Applying slippage to gross assumes the swap rate is 1:1 (collateral_price == debt_price). For stable:stable this is a reasonable approximation. For BNB collateral repaying BTCB debt (price ratio ~0.003), slippage applied to gross overstates the cost — the bot will skip profitable positions. For the reverse direction (expensive collateral, cheap debt) slippage is understated, and the bot may attempt swaps that lose more than modeled.
Impact: Systematic profit estimate error for all cross-token liquidations on Venus. Some profitable liquidations skipped; some losing swaps attempted.
Fix: Add expected_swap_output_cents: u64 to ProfitInputs (computed from SwapRoute.min_amount_out and current prices in the from_opportunity constructor). Apply slippage_bps to expected_swap_output_cents instead of gross.