Skip to content

Add MEV protection for liquidations and large transactions#403

Open
TUPM96 wants to merge 1 commit into
Smartdevs17:mainfrom
TUPM96:codex/mev-protection-383
Open

Add MEV protection for liquidations and large transactions#403
TUPM96 wants to merge 1 commit into
Smartdevs17:mainfrom
TUPM96:codex/mev-protection-383

Conversation

@TUPM96
Copy link
Copy Markdown

@TUPM96 TUPM96 commented May 25, 2026

Summary

  • Adds guarded commit/reveal intents with slippage floors and deadlines for large borrow/withdraw/liquidation flows.
  • Adds liquidation batch auctions with bid ranking, settlement, winner-only protected commits, and auction execution stats.
  • Adds private mempool route registration plus per-commit execution receipts, MEV dashboard stats, and gas bid analysis.
  • Adds lightweight lending-contract MEV guard primitives for the contracts/lending/src scope.

Acceptance coverage

  • Batch auction for liquidation opportunities: open_liq_batch_auction, submit_liq_batch_bid, settle_liq_batch_auction, commit_liq_batch_winner.
  • Commit-reveal for large transactions: existing protected commit flow plus
    equires_mev_commit and guarded commits.
  • Slippage/deadline protection: ExecutionGuard and guarded reveal paths.
  • Private mempool integration: private route registration and execution receipts.
  • Monitoring/dashboard: ordering, auction, private route, and gas bid dashboard.
  • Gas bidding analysis: rolling gas bid stats for hello-world and lending contracts.

Validation

  • git diff --check passes.
  • cargo test -p hello-world mev_protection -- --nocapture is currently blocked by existing unrelated compile issues on main, including duplicate cross_asset_borrow, duplicate DataKey, duplicate get_reserve_balance, and unresolved legacy test imports.
  • cargo check -p stellarlend-lending --lib is currently blocked by existing unrelated crate::interest_rate / crate::risk_monitor wiring errors.

Closes #383

Copilot AI review requested due to automatic review settings May 25, 2026 12:14
@vercel
Copy link
Copy Markdown

vercel Bot commented May 25, 2026

@TUPM96 is attempting to deploy a commit to the smartdevs17's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds MEV-protection primitives across the lending and hello-world contracts, including guarded commit/reveal with slippage/deadline checks, private mempool route receipts, gas-bid monitoring, and a liquidation batch auction flow.

Changes:

  • Introduces a lightweight MEV guard module in lending (commit/reveal + gas bid stats) and exposes it via the lending contract API.
  • Extends hello-world MEV protection with execution guards, private route registration/receipts, gas bid analytics, and liquidation batch auction lifecycle.
  • Adds new tests and updates error mappings + README API listing.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
stellar-lend/contracts/lending/src/mev_protection.rs New lightweight commit/reveal + gas-bid tracking for large tx MEV protection.
stellar-lend/contracts/lending/src/lib.rs Exposes MEV guard entrypoints from the lending contract.
stellar-lend/contracts/hello-world/src/mev_protection.rs Adds guarded commits, private routes/receipts, batch auctions, gas bid stats, and dashboard APIs.
stellar-lend/contracts/hello-world/src/lib.rs Exposes new MEV APIs (guarded commits, auctions, private routes, dashboard) at contract level.
stellar-lend/contracts/hello-world/src/tests/mev_protection_test.rs Adds coverage for guarded liquidation, private route receipts, auctions, and gas bid dashboard.
stellar-lend/contracts/hello-world/src/errors.rs Maps newly added MEV protection errors into LendingError.
stellar-lend/contracts/hello-world/README.md Documents new MEV protection-related public APIs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

if let Some(ref execution_guard) = guard {
validate_guard_config(env, execution_guard)?;
}
if let Some(ref route_id) = private_route {
Comment on lines +66 to +74
if amount <= 0
|| quoted_output <= 0
|| min_output < 0
|| min_output > quoted_output
|| !(0..=MAX_BPS).contains(&max_slippage_bps)
|| deadline <= env.ledger().timestamp()
{
return Err(MevGuardError::BadConfig);
}
Comment on lines +1222 to +1232
fn validate_guard_config(env: &Env, guard: &ExecutionGuard) -> Result<(), MevProtectionError> {
if guard.quoted_output_amount <= 0
|| guard.min_output_amount < 0
|| guard.min_output_amount > guard.quoted_output_amount
|| !(0..=MAX_BPS).contains(&guard.max_slippage_bps)
|| guard.deadline <= env.ledger().timestamp()
{
return Err(MevProtectionError::InvalidConfig);
}
Ok(())
}
);
env.storage()
.persistent()
.remove(&MevDataKey::Commit(commit_id));
Comment on lines +620 to +642
let existed: Option<PrivateMempoolRoute> = env
.storage()
.persistent()
.get(&MevDataKey::PrivateRoute(route_id.clone()));
let route = PrivateMempoolRoute {
route_id: route_id.clone(),
relay,
registered_by: caller,
registered_at: now,
expires_at: now.saturating_add(ttl_secs),
active: true,
};
env.storage()
.persistent()
.set(&MevDataKey::PrivateRoute(route_id), &route);

if existed.is_none() {
let mut stats = get_private_route_stats(env);
stats.active_routes = stats.active_routes.saturating_add(1);
env.storage()
.persistent()
.set(&MevDataKey::PrivateStats, &stats);
}
Comment on lines +300 to +303
fn test_private_route_receipt_required_for_private_commit() {
let env = Env::default();
env.mock_all_auths();
let contract_id = setup_contract(&env);
@TUPM96 TUPM96 force-pushed the codex/mev-protection-383 branch from c5ffaf1 to 041858a Compare May 25, 2026 14:01
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.

Add MEV protection for liquidations and large transactions

2 participants