Add Aave Lending Deposit and Withdrawal With Delegation#136
Add Aave Lending Deposit and Withdrawal With Delegation#136
Conversation
|
It is pending to validate if we prefer the simple If we decide that we want both options, then we need to unify the code to avoid code duplication and also apply the same approach to the other adapters. |
There was a problem hiding this comment.
Bug: Withdrawal Events Emit Incorrect Amount
The withdrawByDelegation and withdrawByDelegationOpenEnded functions incorrectly emit the WithdrawExecuted event with the requested _amount parameter. The aavePool.withdraw() function returns the actual amount withdrawn, which can differ from the requested amount (e.g., when type(uint256).max is used for full withdrawal). This leads to inaccurate event data.
src/helpers/AaveAdapter.sol#L186-L189
delegation-framework/src/helpers/AaveAdapter.sol
Lines 186 to 189 in 67a37fb
src/helpers/AaveAdapter.sol#L217-L220
delegation-framework/src/helpers/AaveAdapter.sol
Lines 217 to 220 in 67a37fb
Bug: Allowance Overflow in SafeIncreaseAllowance
The _ensureAllowance function can cause an arithmetic overflow. If the current allowance is non-zero but insufficient, calling safeIncreaseAllowance with type(uint256).max will attempt currentAllowance + type(uint256).max, which overflows uint256 and reverts the transaction (due to Solidity 0.8+ overflow checks). This logical flaw, while unlikely in practice, can be resolved by using safeApprove to set the allowance directly to type(uint256).max or by calculating the precise increase amount.
src/helpers/AaveAdapter.sol#L93-L99
delegation-framework/src/helpers/AaveAdapter.sol
Lines 93 to 99 in 67a37fb
Was this report helpful? Give feedback by reacting with 👍 or 👎
|
This PR needs an RPC URL secret on github to work |
What?
Why?
How?
Notes
Note
High Risk
Introduces a new contract that moves/approves ERC-20s and executes Aave pool calls via delegation redemption, so mistakes could impact fund flow and authorization boundaries. While heavily tested, it’s still new onchain logic interacting with external protocol contracts.
Overview
Adds a new
AaveAdaptercontract to enable Aave v3supply/withdrawvia the delegation framework by redeeming a 2-step delegation chain (token/aToken transfer to adapter, then self-call into Aave), with strict execution-mode gating and an owner-only emergency token recovery path.Introduces a full mainnet-fork Foundry test suite (
AaveLending.t.sol) covering direct vs delegation flows, adapter-based deposit/withdraw across multiple tokens, and extensive event/error/edge-case coverage. Also addsIAavePoolinterface, aDeployAaveAdapterdeployment script, documentation for “Delegation Adapters” (incl. Aave), and updatesscript/coverage.shto run/merge coverage across EVM versions (London + Shanghai/Cancun-specific test selection).Written by Cursor Bugbot for commit 4e28e7f. This will update automatically on new commits. Configure here.