feat(core): tighten core types for BSC + profit ranking#308
Merged
Conversation
… SwapRoute
Add the normalized types shared across the workspace:
- ProtocolId: enum naming the lending protocol (Venus only for v1)
- Position: a single borrow position with health_factor and bonus
- FlashLoanSource: Balancer / Aave / Uniswap flash loan providers
- SwapRoute: planned collateral->debt DEX swap with slippage protection
- LiquidationOpportunity: a profitable, ready-to-execute liquidation
All types derive Serialize/Deserialize for config + logging compatibility.
Addresses and amounts use alloy::primitives::{Address, U256}.
- FlashLoanSource::UniswapV3 → PancakeSwapV3 (BSC has no Uniswap V3); note the BSC fee tiers (100/500/2500/10000). - Add #[non_exhaustive] to FlashLoanSource and ProtocolId so new variants are not semver-breaking for downstream exhaustive matches. - Replace LiquidationOpportunity.net_profit_usd_cents: u64 with net_profit_wei: U256 denominated in the debt-token base unit; USD conversion is a reporting-layer concern and must not drive ranking. - Implement Ord / PartialOrd / PartialEq / Eq on LiquidationOpportunity so it can live in a profit-ordered BinaryHeap (max-heap pops the highest net_profit_wei first). - SwapRoute.pool_fee: u32 (sentinel 0) → Option<u32>; None for fee-less routes, Some(bps) otherwise — removes the 0-vs-100-bps ambiguity on PancakeSwap V3. - Rustdoc every public field with units and source-of-truth notes; mark LiquidationOpportunity #[must_use]. Closes #64 #65 #66 #67 #68 #69
# Conflicts: # Cargo.lock # crates/charon-core/Cargo.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Re-open of #27 retargeted to main. Original #27 merged into feat/01-scaffold-workspace due to stacked base. Content: core types (Position, LiquidationOpportunity, LiquidationParams), profit ranking, BSC constants.