Refs #40
File: crates/charon-core/src/profit.rs
PR branch: feat/15-profit-calc-and-queue
Problem:
calculate_profit() returns anyhow::Result. The executor consuming this function must distinguish:
- BelowMinThreshold: opportunity rejected on economics; log and skip to next entry.
- InvalidInputs / Overflow / InvalidBps: programming or data error; abort cycle and alert.
With anyhow::Error both cases collapse to a string. The executor cannot match on error variant to decide safe recovery behavior. This is the same defect flagged as p1 in the PR #39 review (FlashLoanProvider) and the pattern established in the PR #28 review (LendingProtocol trait).
Additionally, thiserror is not in [workspace.dependencies] or charon-core/Cargo.toml. Adding it is a required Cargo.toml change not present in this PR.
Fix:
- Add thiserror = "1" to [workspace.dependencies] in root Cargo.toml.
- Add thiserror to charon-core/Cargo.toml [dependencies].
- Define:
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum ProfitError {
#[error("net {net_cents} cents below minimum {min_cents} cents")]
BelowMinThreshold { net_cents: u64, min_cents: u64 },
#[error("invalid bps {bps}: must be <= 10_000")]
InvalidBps { bps: u32 },
#[error("arithmetic overflow")]
Overflow,
#[error("invalid price input: {reason}")]
InvalidPrice { reason: &'static str },
}
- Change calculate_profit signature to -> Result<NetProfit, ProfitError>.
Refs #40
File: crates/charon-core/src/profit.rs
PR branch: feat/15-profit-calc-and-queue
Problem:
calculate_profit() returns anyhow::Result. The executor consuming this function must distinguish:
With anyhow::Error both cases collapse to a string. The executor cannot match on error variant to decide safe recovery behavior. This is the same defect flagged as p1 in the PR #39 review (FlashLoanProvider) and the pattern established in the PR #28 review (LendingProtocol trait).
Additionally, thiserror is not in [workspace.dependencies] or charon-core/Cargo.toml. Adding it is a required Cargo.toml change not present in this PR.
Fix:
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum ProfitError {
#[error("net {net_cents} cents below minimum {min_cents} cents")]
BelowMinThreshold { net_cents: u64, min_cents: u64 },
#[error("invalid bps {bps}: must be <= 10_000")]
InvalidBps { bps: u32 },
#[error("arithmetic overflow")]
Overflow,
#[error("invalid price input: {reason}")]
InvalidPrice { reason: &'static str },
}