Skip to content

Commit d055951

Browse files
committed
feat: update fees/README.md to include info on aerodrome swap fee
1 parent d58433c commit d055951

File tree

1 file changed

+65
-3
lines changed
  • packages/libs/contracts-sdk/contracts/fees

1 file changed

+65
-3
lines changed

packages/libs/contracts-sdk/contracts/fees/README.md

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ The Fee Diamond is a sophisticated smart contract system built using the Diamond
44

55
## Overview
66

7-
The Fee Diamond system allows Vincent's abilities to deposit user funds into DeFi protocols (currently Morpho and Aave) and automatically collect performance fees when users withdraw their funds. The system tracks user deposits, calculates profits, and takes a configurable percentage of the profit as a fee.
7+
The Fee Diamond system allows Vincent's abilities to deposit user funds into DeFi protocols (currently Morpho and Aave) and automatically collect performance fees when users withdraw their funds. The system also supports token swaps on Aerodrome DEX with automatic fee collection from input tokens. The system tracks user deposits, calculates profits, and takes a configurable percentage of the profit as a fee.
88

99
### Key Features
1010

1111
- **Multi-Protocol Support**: Currently supports Morpho and Aave protocols
12+
- **DEX Integration**: Supports token swaps on Aerodrome DEX with automatic fee collection
1213
- **Performance Fee Collection**: Automatically calculates and collects fees only on profits
14+
- **Swap Fee Collection**: Automatically collects fees from input tokens during swaps
1315
- **Full Withdrawal Only**: Simplified implementation that only supports full withdrawals
1416
- **Deterministic Deployment**: Uses Create2 for consistent addresses across EVM chains
1517
- **Admin Controls**: Owner can adjust fee percentages and withdraw collected fees
@@ -56,9 +58,19 @@ Administrative functions for managing the fee system.
5658
- `setPerformanceFeePercentage(uint256 newPercentage)`: Sets the performance fee percentage (in basis points)
5759
- `withdrawTokens(address tokenAddress)`: Withdraws collected fees for a specific token
5860
- `setAavePool(address newAavePool)`: Sets the Aave pool contract address
61+
- `setAerodromeRouter(address newAerodromeRouter)`: Sets the Aerodrome router contract address
62+
- `aerodromeRouter()`: Returns the current Aerodrome router address
5963
- `tokensWithCollectedFees()`: Returns list of tokens that have collected fees
6064

61-
#### 4. FeeViewsFacet
65+
#### 4. AerodromeSwapFeeFacet
66+
67+
Handles token swaps on Aerodrome DEX with automatic fee collection from input tokens.
68+
69+
**Key Functions:**
70+
71+
- `swapExactTokensForTokensOnAerodrome(uint256 amountIn, uint256 amountOutMin, IRouter.Route[] calldata routes, address to, uint256 deadline)`: Executes token swaps on Aerodrome and collects fees from input tokens
72+
73+
#### 5. FeeViewsFacet
6274

6375
Read-only functions for querying deposit information.
6476

@@ -87,8 +99,21 @@ Read-only functions for querying deposit information.
8799
- Remaining amount (original deposit + user's share of profit) goes to user
88100
5. **Cleanup**: Deposit records are cleared and user's vault list is updated
89101

102+
### Aerodrome Swap Process
103+
104+
1. **User Authorization**: User approves the Fee Diamond to spend their input tokens
105+
2. **Fee Calculation**: Contract calculates swap fee from the input amount (percentage of input tokens)
106+
3. **Token Transfer**: Input tokens are transferred from user to the Fee Diamond contract
107+
4. **Fee Deduction**: Swap fee is deducted from the input amount before executing the swap
108+
5. **Swap Execution**: Contract executes the swap on Aerodrome DEX with the reduced input amount
109+
6. **Fee Collection**: The calculated fee remains in the contract and is added to the collected fees tracking
110+
7. **Token Distribution**: Swapped output tokens are transferred to the user
111+
8. **Fee Tracking**: Input token address is added to the set of tokens with collected fees
112+
90113
### Fee Calculation
91114

115+
#### Performance Fees (Morpho/Aave)
116+
92117
The performance fee is calculated as:
93118

94119
```
@@ -101,15 +126,28 @@ if (withdrawalAmount > originalDepositAmount) {
101126

102127
Where `performanceFeePercentage` is expressed in basis points (1000 = 10%).
103128

129+
#### Swap Fees (Aerodrome)
130+
131+
The swap fee is calculated as:
132+
133+
```
134+
swapFee = amountIn * swapFeePercentage / 10000
135+
actualAmountIn = amountIn - swapFee
136+
amountOutMin = amountOutMin - (amountOutMin * swapFeePercentage / 10000)
137+
```
138+
139+
Where `swapFeePercentage` is expressed in basis points (e.g., 50 = 0.5%). The fee is collected from the input token and accumulates in the contract for later withdrawal by the owner.
140+
104141
## Storage Structure
105142

106143
The system uses a sophisticated storage structure to track:
107144

108145
- **User Deposits**: Maps user address → vault address → deposit details
109146
- **Performance Fee Percentage**: Configurable fee rate in basis points
147+
- **Swap Fee Percentage**: Configurable swap fee rate in basis points
110148
- **Collected Fees Tracking**: Set of token addresses that have collected fees
111149
- **User Vault Tracking**: Set of vault/pool addresses per user for recovery
112-
- **Protocol Configuration**: Aave pool contract address
150+
- **Protocol Configuration**: Aave pool contract address and Aerodrome router address
113151

114152
## Example Usage
115153

@@ -125,12 +163,35 @@ morphoPerfFeeFacet.depositToMorpho(morphoVaultAddress, 1000e6);
125163
morphoPerfFeeFacet.withdrawFromMorpho(morphoVaultAddress);
126164
```
127165

166+
### Aerodrome Token Swaps
167+
168+
```solidity
169+
// Create swap route (USDC to WETH)
170+
IRouter.Route[] memory routes = new IRouter.Route[](1);
171+
routes[0] = IRouter.Route(usdcAddress, wethAddress, false, address(0));
172+
173+
// Execute swap with fee collection
174+
aerodromeSwapFeeFacet.swapExactTokensForTokensOnAerodrome(
175+
1000e6, // 1000 USDC input
176+
0, // minimum output (adjusted internally for fees)
177+
routes, // swap route
178+
userAddress, // recipient
179+
block.timestamp + 1 hours // deadline
180+
);
181+
```
182+
128183
### Admin Operations
129184

130185
```solidity
131186
// Set performance fee to 5% (500 basis points)
132187
feeAdminFacet.setPerformanceFeePercentage(500);
133188
189+
// Set swap fee to 0.5% (50 basis points)
190+
feeAdminFacet.setSwapFeePercentage(50);
191+
192+
// Set Aerodrome router address
193+
feeAdminFacet.setAerodromeRouter(aerodromeRouterAddress);
194+
134195
// Withdraw collected USDC fees
135196
feeAdminFacet.withdrawTokens(usdcAddress);
136197
@@ -175,6 +236,7 @@ Comprehensive test suites are available in `test/fees/`:
175236
- `MorphoFee.t.sol`: Unit tests for Morpho functionality
176237
- `AaveFeeForkTest.t.sol`: Fork tests for Aave integration
177238
- `MorphoFeeForkTest.t.sol`: Fork tests for Morpho integration
239+
- `AerodromeFeeForkTest.t.sol`: Fork tests for Aerodrome swap integration
178240

179241
## Future Enhancements
180242

0 commit comments

Comments
 (0)