-
-
Notifications
You must be signed in to change notification settings - Fork 96
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
Open
MoMannn
wants to merge
13
commits into
main
Choose a base branch
from
feat/aave-staking
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
90fcd86
add aave lending deposit and withdrawal with delegation
MoMannn 982b583
Add test for single delegation with logicalOrEnforcer
MoMannn a0a7499
Add AaveAdapter POC and descriptions
MoMannn d49a1f6
Add open ended supply option to aave adapter and description
MoMannn 1a70cc6
test: moved aave poc folder, added withdrawals
hanzel98 8de9138
chore: added tests, docs, coverage fix
hanzel98 67a37fb
chore: docs for contract, more test coverage
hanzel98 0099673
Merge branch 'main' of https://github.com/MetaMask/delegation-framewo…
MoMannn 75edd7c
Update aave adapter to support redelegation flow
MoMannn 4e28e7f
add test with logical or wtappet via adapter
MoMannn bb18d97
basic morhpo adapter
MoMannn 1ed69ec
allow redelegations
MoMannn 56357fb
Optimize aave adapter without selfdelegation.
MoMannn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Delegation Adapters | ||
|
|
||
| Delegation adapters are specialized contracts that simplify integration between the delegation framework and external protocols that don't natively support delegations. Many DeFi protocols require users to perform multi-step operations—typically providing ERC-20 approvals followed by specific function calls—which adapters combine into single, atomic, delegatable executions. This enables users to delegate complex protocol interactions while ensuring outputs are delivered to the root delegator or their specified recipients. Adapters are particularly valuable for enabling non-DeleGator accounts to redeem delegations and meet delegator-specified requirements. Since most existing protocols haven't yet implemented native delegation support, adapters serve as an essential bridge layer that converts delegation-based permissions into protocol-compatible interactions while enforcing proper restrictions and safeguards during redemption. | ||
|
|
||
| ## Current Adapters | ||
|
|
||
| ### DelegationMetaSwapAdapter | ||
|
|
||
| Facilitates token swaps through DEX aggregators by leveraging ERC-20 delegations with enforced outcome validation. This adapter integrates with the MetaSwap aggregator to execute optimal token swaps while maintaining delegation-based access control. It enables users to delegate ERC-20 token permissions and add conditions for enforced outcomes by the end of redemption. The adapter creates a self-redemption mechanism that atomically executes both the ERC-20 transfer and swap during the execution phase, followed by outcome validation in the afterAllHooks phase. It supports configurable token whitelisting through caveat enforcers and includes signature validation with expiration timestamps for secure API integration. | ||
|
|
||
| ### LiquidStakingAdapter | ||
|
|
||
| Manages stETH withdrawal operations through Lido's withdrawal queue using delegation-based permissions. This adapter specifically focuses on withdrawal functions that require ERC-20 approvals, while deposit operations are excluded since they only require ETH and do not need ERC-20 approval mechanisms. The adapter facilitates stETH withdrawal requests by using delegations to transfer stETH tokens and supports both delegation-based transfers and ERC-20 permit signatures for gasless approvals. It has been designed to enhance the delegation experience by allowing users to enforce stricter delegation restrictions related to the Lido protocol, ensuring that redeemers must send withdrawal request ownership and any resulting tokens directly to the root delegator. | ||
|
|
||
| ### AaveAdapter | ||
|
|
||
| Enables delegation-based lending and borrowing operations on the Aave protocol through secure token transfer delegations. This adapter facilitates both supply and withdrawal operations while maintaining full delegator control over asset custody and destination. The adapter supports flexible execution models including delegator-only operations for maximum control and open-ended execution where authorized delegates can perform operations on behalf of the delegator. Supply operations use ERC-20 token delegations to transfer underlying tokens to the adapter, which then supplies them to Aave with aTokens always being credited to the original delegator. Withdrawal operations leverage aToken delegations to transfer yield-bearing tokens to the adapter, which then redeems them from Aave with underlying tokens always being sent back to the delegator. The adapter eliminates the need for traditional ERC-20 approvals by using delegation-based token transfers, providing more granular control and enhanced security for DeFi lending interactions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // SPDX-License-Identifier: MIT AND Apache-2.0 | ||
| pragma solidity 0.8.23; | ||
|
|
||
| import "forge-std/Script.sol"; | ||
| import { console2 } from "forge-std/console2.sol"; | ||
|
|
||
| import { AaveAdapter } from "../src/helpers/AaveAdapter.sol"; | ||
|
|
||
| /** | ||
| * @title DeployAaveAdapter | ||
| * @notice Deploys the AaveAdapter contract. | ||
| * @dev These contracts are likely already deployed on a testnet or mainnet as many are singletons. | ||
| * @dev Update the hardcoded addresses below before deploying. | ||
| * @dev Fill the SALT variable in the .env file | ||
| * @dev run the script with: | ||
| * forge script script/DeployAaveAdapter.s.sol --rpc-url <your_rpc_url> --private-key $PRIVATE_KEY --broadcast | ||
| */ | ||
| contract DeployAaveAdapter is Script { | ||
| // Hardcoded constructor parameters - update these before deploying | ||
| address constant OWNER = address(0x76A60394EF70c8FE78999AB1C441278fD02C4093); | ||
| address constant DELEGATION_MANAGER = address(0xdb9B1e94B5b69Df7e401DDbedE43491141047dB3); | ||
| address constant AAVE_POOL = address(0x8bAB6d1b75f19e9eD9fCe8b9BD338844fF79aE27); | ||
|
|
||
| bytes32 salt; | ||
| address deployer; | ||
|
|
||
| function setUp() public { | ||
| salt = bytes32(abi.encodePacked(vm.envString("SALT"))); | ||
| deployer = msg.sender; | ||
| console2.log("~~~"); | ||
| console2.log("Owner: %s", OWNER); | ||
| console2.log("DelegationManager: %s", DELEGATION_MANAGER); | ||
| console2.log("AavePool: %s", AAVE_POOL); | ||
| console2.log("Deployer: %s", deployer); | ||
| console2.log("Salt:"); | ||
| console2.logBytes32(salt); | ||
| } | ||
|
|
||
| function run() public { | ||
| console2.log("~~~"); | ||
| vm.startBroadcast(); | ||
|
|
||
| address aaveAdapter = address(new AaveAdapter{ salt: salt }(OWNER, DELEGATION_MANAGER, AAVE_POOL)); | ||
| console2.log("AaveAdapter: %s", aaveAdapter); | ||
|
|
||
| vm.stopBroadcast(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
MorphoLending test missing from Shanghai coverage configuration
Low Severity
MorphoLending.t.soldeclaresforge-config: default.evm_version = "shanghai"but is not listed in theSHANGHAI_TESTSarray incoverage.sh. OnlyAaveLending.t.solis listed. This meansMorphoLending.t.solwon't be excluded from the London EVM coverage run and won't be included in the Shanghai run, potentially causing coverage failures or incorrect coverage data.Additional Locations (1)
test/helpers/MorphoLending.t.sol#L28-L29