You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/libs/contracts-sdk/contracts/fees/README.md
+65-3Lines changed: 65 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,12 +4,14 @@ The Fee Diamond is a sophisticated smart contract system built using the Diamond
4
4
5
5
## Overview
6
6
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.
8
8
9
9
### Key Features
10
10
11
11
-**Multi-Protocol Support**: Currently supports Morpho and Aave protocols
12
+
-**DEX Integration**: Supports token swaps on Aerodrome DEX with automatic fee collection
12
13
-**Performance Fee Collection**: Automatically calculates and collects fees only on profits
14
+
-**Swap Fee Collection**: Automatically collects fees from input tokens during swaps
13
15
-**Full Withdrawal Only**: Simplified implementation that only supports full withdrawals
14
16
-**Deterministic Deployment**: Uses Create2 for consistent addresses across EVM chains
15
17
-**Admin Controls**: Owner can adjust fee percentages and withdraw collected fees
@@ -56,9 +58,19 @@ Administrative functions for managing the fee system.
56
58
-`setPerformanceFeePercentage(uint256 newPercentage)`: Sets the performance fee percentage (in basis points)
57
59
-`withdrawTokens(address tokenAddress)`: Withdraws collected fees for a specific token
58
60
-`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
59
63
-`tokensWithCollectedFees()`: Returns list of tokens that have collected fees
60
64
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
62
74
63
75
Read-only functions for querying deposit information.
64
76
@@ -87,8 +99,21 @@ Read-only functions for querying deposit information.
87
99
- Remaining amount (original deposit + user's share of profit) goes to user
88
100
5.**Cleanup**: Deposit records are cleared and user's vault list is updated
89
101
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
+
90
113
### Fee Calculation
91
114
115
+
#### Performance Fees (Morpho/Aave)
116
+
92
117
The performance fee is calculated as:
93
118
94
119
```
@@ -101,15 +126,28 @@ if (withdrawalAmount > originalDepositAmount) {
101
126
102
127
Where `performanceFeePercentage` is expressed in basis points (1000 = 10%).
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
+
104
141
## Storage Structure
105
142
106
143
The system uses a sophisticated storage structure to track:
0 commit comments