Skip to content

[profit] ProfitInputs.flash_fee denomination undocumented — mixed-unit subtraction risk #152

@obchain

Description

@obchain

Refs #40

File: crates/charon-core/src/profit.rs

PR branch: feat/15-profit-calc-and-queue

Problem:
The net profit formula subtracts flash_fee in the same unit as gross (USD cents). Aave V3 flash loan fee = 0.05% of the borrowed amount denominated in debt-token wei (U256). Converting to USD cents:
flash_fee_wei = borrow_wei * 5 / 10_000
flash_fee_cents = (flash_fee_wei / 10^decimals) * debt_price_1e8 / 1e8 * 100

This conversion is not implemented or tested. ProfitInputs.flash_fee has no rustdoc comment specifying its unit. A caller that passes flash_fee in wei (e.g., 5e14 for a 1 BNB loan at 0.05%) will cause the net profit calculation to silently understate the fee by a factor of ~1e16 (since 5e14 cents = trillion). Conversely, a caller that passes 0 thinking the fee is handled elsewhere will overstate net profit.

The workspace CLAUDE.md requires NatSpec/rustdoc completeness on all public types.

Fix: Add rustdoc to every ProfitInputs field specifying unit and scale (e.g., /// Flash loan fee in USD cents (100 = .00)). Add the wei-to-cents conversion for flash fees in the from_opportunity constructor (Issue #N). Add a unit test with a realistic Aave fee: borrow 1 BNB (~00), fee = 0.05% = /tmp/pr40-cmds.sh.30 = 30 cents.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinglayer:rustRust crates (core / scanner / protocols / executor / cli)pr-reviewFindings from PR review processpriority:p1-coreCore MVP scopestatus:readyScoped and ready to pick up

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions