Skip to content

fix: make Lend supply and collateral atomic#225

Merged
nikkaroraa merged 3 commits into
feat/lendfrom
nik/atomic-lend-supply
Jul 22, 2026
Merged

fix: make Lend supply and collateral atomic#225
nikkaroraa merged 3 commits into
feat/lendfrom
nik/atomic-lend-supply

Conversation

@nikkaroraa

@nikkaroraa nikkaroraa commented Jul 22, 2026

Copy link
Copy Markdown

Summary

  • make each Lend gateway supply atomically enable the reserve as collateral
  • remove redundant caller-side collateral enablement from production paths and test fixtures
  • emit raw revert data when best-effort sweep, sandwich, or top-up supply fails while allowing later assets to continue

Test plan

  • forge fmt --check on all changed Solidity files
  • focused and post-review Lend suites: 108 tests passed
  • full Lend directory: 255 tests passed; remaining failures were environment-only (missing OPENOCEAN_API_KEY and transient Optimism RPC errors), with affected RPC suites passing on rerun
  • forge lint compiled successfully, then hit the repository's existing Solar import-resolution issue in vendored Aave V4 sources

Note

Medium Risk
Changes core Aave supply semantics and several production paths (migration, sweeps, top-ups, module sandwiches); behavior is safer against supplied-but-not-collateral states, but any gateway supply failure handling now depends on full-call revert atomicity.

Overview
Lend gateway supply is now one atomic step: after pulling from the safe and calling the Spoke, the gateway also enables the reserve as collateral and emits CollateralUsageSet. ILendGateway documents that supply and collateral enablement succeed or revert together.

Call sites no longer double-enable collateral: migration (DebtManagerCore), credit resupply (CashLendLib), top-up auto-lend (TopUpDest), and sandwich resupply (ModuleLendGatewaySandwich) only call supply. The mock gateway sets usingAsCollateral inside supply to match.

Observability on best-effort paths: auto-sweep, sandwich resupply, and top-up catch supply failures and emit LendSupplyFailed (token, amount, raw revert bytes) via CashEventEmitter / module events, replacing LendSupplied. Batches can continue after a failed asset.

Tests expect gateway Supplied events for successful sweeps/borrows and cover collateral-enable failures rolling back that token while other tokens still sweep.

Reviewed by Cursor Bugbot for commit b6363a1. Bugbot is set up for automated code reviews on this repo. Configure here.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@nikkaroraa
nikkaroraa requested a review from shivam-ef July 22, 2026 13:31
Comment thread src/debt-manager/DebtManagerCore.sol
@nikkaroraa
nikkaroraa merged commit 4b416ff into feat/lend Jul 22, 2026
2 checks passed
@nikkaroraa
nikkaroraa deleted the nik/atomic-lend-supply branch July 22, 2026 13:41
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.

2 participants