-
-
Notifications
You must be signed in to change notification settings - Fork 85
Add Aave Lending Deposit and Withdrawal With Delegation #136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
| // Withdraw from Aave directly to the delegator | |
| aavePool.withdraw(_token, _amount, msg.sender); | |
| emit WithdrawExecuted(msg.sender, msg.sender, _token, _amount); |
src/helpers/AaveAdapter.sol#L217-L220
delegation-framework/src/helpers/AaveAdapter.sol
Lines 217 to 220 in 67a37fb
| // Withdraw from Aave directly to the delegator | |
| aavePool.withdraw(_token, _amount, _delegations[0].delegator); | |
| emit WithdrawExecuted(_delegations[0].delegator, msg.sender, _token, _amount); |
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
| /// @param _amount Amount needed for the operation | |
| function _ensureAllowance(IERC20 _token, uint256 _amount) private { | |
| uint256 allowance_ = _token.allowance(address(this), address(aavePool)); | |
| if (allowance_ < _amount) { | |
| _token.safeIncreaseAllowance(address(aavePool), type(uint256).max); | |
| } | |
| } |
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