Skip to content

feat(core): tighten core types for BSC + profit ranking#308

Merged
obchain merged 3 commits intomainfrom
feat/02-core-types
Apr 24, 2026
Merged

feat(core): tighten core types for BSC + profit ranking#308
obchain merged 3 commits intomainfrom
feat/02-core-types

Conversation

@obchain
Copy link
Copy Markdown
Owner

@obchain obchain commented Apr 24, 2026

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.

obchain added 3 commits April 21, 2026 17:47
… 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
@obchain obchain merged commit c8a8ea5 into main Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant