Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ Developers can build new Caveat Enforcers for their own use cases, and the possi

[Read more on "Caveats" ->](/documents/DelegationManager.md#Caveats)

### Delegation Adapters

Delegation Adapters are specialized contracts that bridge the gap between the delegation framework and external protocols that don't natively support delegations.

[Read more on "Delegation Adapters" ->](/documents/Adapters.md)

## Development

### Third Party Developers
Expand Down
17 changes: 17 additions & 0 deletions documents/Adapters.md
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.
96 changes: 92 additions & 4 deletions script/coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,105 @@ cd ..
folder_path="coverage"

if [ ! -d "$folder_path" ]; then
# If not, create the folder
mkdir -p "$folder_path"
echo "Folder created at: $folder_path"
else
echo "Folder already exists at: $folder_path"
fi

# Configuration: Define test files for different EVM versions
declare -a SHANGHAI_TESTS=(
"test/helpers/AaveLending.t.sol"
# Add more shanghai tests here in the future
# "test/helpers/AnotherShanghaiTest.t.sol"
)

declare -a CANCUN_TESTS=(
# Add cancun tests here when needed
# "test/helpers/CancunTest.t.sol"
)

# Generates lcov.info
forge coverage --report lcov --skip scripts --report-file "$folder_path/lcov.info"
# Function to build match patterns for forge coverage
build_match_patterns() {
local tests=("$@")
local patterns=""

for test in "${tests[@]}"; do
if [[ -n "$patterns" ]]; then
patterns="$patterns --match-path *$(basename "$test")"
else
patterns="--match-path *$(basename "$test")"
fi
done

echo "$patterns"
}

# Function to build no-match patterns for forge coverage
build_no_match_patterns() {
local tests=("$@")
local patterns=""

for test in "${tests[@]}"; do
if [[ -n "$patterns" ]]; then
patterns="$patterns --no-match-path *$(basename "$test")"
else
patterns="--no-match-path *$(basename "$test")"
fi
done

echo "$patterns"
}

echo "Running coverage with inline EVM version flags..."
echo "-----------------------------------------------"

# Build list of all special EVM tests to exclude from default London run
ALL_SPECIAL_EVM_TESTS=("${SHANGHAI_TESTS[@]}" "${CANCUN_TESTS[@]}")
LONDON_NO_MATCH_PATTERNS=$(build_no_match_patterns "${ALL_SPECIAL_EVM_TESTS[@]}")

# Generate coverage for London EVM (default) - exclude special EVM tests
if [[ -n "$LONDON_NO_MATCH_PATTERNS" ]]; then
echo "Running coverage for London EVM..."
echo "Excluding: ${ALL_SPECIAL_EVM_TESTS[*]}"
forge coverage --evm-version london --report lcov --skip scripts $LONDON_NO_MATCH_PATTERNS --report-file "$folder_path/lcov-london.info"
else
echo "Running coverage for London EVM - no exclusions..."
forge coverage --evm-version london --report lcov --skip scripts --report-file "$folder_path/lcov-london.info"
fi

# Generate coverage for Shanghai EVM tests if any exist
if [ ${#SHANGHAI_TESTS[@]} -gt 0 ]; then
echo "Running coverage for Shanghai EVM..."
echo "Including: ${SHANGHAI_TESTS[*]}"
SHANGHAI_MATCH_PATTERNS=$(build_match_patterns "${SHANGHAI_TESTS[@]}")
forge coverage --evm-version shanghai --report lcov --skip scripts $SHANGHAI_MATCH_PATTERNS --report-file "$folder_path/lcov-shanghai.info"
fi

# Generate coverage for Cancun EVM tests if any exist
if [ ${#CANCUN_TESTS[@]} -gt 0 ]; then
echo "Running coverage for Cancun EVM..."
echo "Including: ${CANCUN_TESTS[*]}"
CANCUN_MATCH_PATTERNS=$(build_match_patterns "${CANCUN_TESTS[@]}")
forge coverage --evm-version cancun --report lcov --skip scripts $CANCUN_MATCH_PATTERNS --report-file "$folder_path/lcov-cancun.info"
fi

# Build the list of coverage files to merge
COVERAGE_FILES=("$folder_path/lcov-london.info")
if [ ${#SHANGHAI_TESTS[@]} -gt 0 ]; then
COVERAGE_FILES+=("$folder_path/lcov-shanghai.info")
fi
if [ ${#CANCUN_TESTS[@]} -gt 0 ]; then
COVERAGE_FILES+=("$folder_path/lcov-cancun.info")
fi

# Merge the lcov files
echo "Merging coverage reports..."
echo "Files to merge: ${COVERAGE_FILES[*]}"
lcov \
--rc branch_coverage=1 \
$(printf -- "--add-tracefile %s " "${COVERAGE_FILES[@]}") \
--output-file "$folder_path/lcov.info"

# Filter out test, mock, and script files
lcov \
Expand All @@ -39,4 +127,4 @@ then
--output-directory "$folder_path" \
"$folder_path/filtered-lcov.info"
open "$folder_path/index.html"
fi
fi
Loading
Loading