@@ -10,10 +10,10 @@ import {GenericFactory} from "evk/GenericFactory/GenericFactory.sol";
10
10
/// @custom:security-contact [email protected]
11
11
/// @author Euler Labs (https://www.eulerlabs.com/)
12
12
contract EulerSwapFactory is IEulerSwapFactory , EVCUtil {
13
+ /// @dev An array to store all pools addresses.
14
+ address [] private allPools;
13
15
/// @dev Vaults must be deployed by this factory
14
16
address public immutable evkFactory;
15
- /// @dev An array to store all pools addresses.
16
- address [] public allPools;
17
17
/// @dev Mapping between euler account and EulerAccountState
18
18
mapping (address eulerAccount = > EulerAccountState state ) private eulerAccountState;
19
19
mapping (address asset0 = > mapping (address asset1 = > address [])) private poolMap;
@@ -40,6 +40,7 @@ contract EulerSwapFactory is IEulerSwapFactory, EVCUtil {
40
40
error OldOperatorStillInstalled ();
41
41
error OperatorNotInstalled ();
42
42
error InvalidVaultImplementation ();
43
+ error SliceOutOfBounds ();
43
44
44
45
constructor (address evc , address evkFactory_ ) EVCUtil (evc) {
45
46
evkFactory = evkFactory_;
@@ -105,36 +106,48 @@ contract EulerSwapFactory is IEulerSwapFactory, EVCUtil {
105
106
);
106
107
}
107
108
109
+ /// @inheritdoc IEulerSwapFactory
108
110
function EVC () external view override (EVCUtil, IEulerSwapFactory) returns (address ) {
109
111
return address (evc);
110
112
}
111
113
112
114
/// @inheritdoc IEulerSwapFactory
113
- function allPoolsLength () external view returns (uint256 ) {
115
+ function poolByHolder (address who ) external view returns (address ) {
116
+ return eulerAccountState[who].pool;
117
+ }
118
+
119
+ /// @inheritdoc IEulerSwapFactory
120
+ function poolsLength () external view returns (uint256 ) {
114
121
return allPools.length ;
115
122
}
116
123
117
124
/// @inheritdoc IEulerSwapFactory
118
- function getEulerAccountState (address eulerAccount ) external view returns (address , uint48 , uint48 ) {
119
- return (
120
- eulerAccountState[eulerAccount].pool,
121
- eulerAccountState[eulerAccount].allPoolsIndex,
122
- eulerAccountState[eulerAccount].poolMapIndex
123
- );
125
+ function poolsSlice (uint256 start , uint256 end ) external view returns (address [] memory ) {
126
+ return _getSlice (allPools, start, end);
124
127
}
125
128
126
129
/// @inheritdoc IEulerSwapFactory
127
- function getAllPoolsListSlice (uint256 _start , uint256 _end ) external view returns (address [] memory ) {
128
- uint256 length = allPools.length ;
129
- if (_end == type (uint256 ).max) _end = length;
130
- if (_end < _start || _end > length) revert InvalidQuery ();
131
-
132
- address [] memory allPoolsList = new address [](_end - _start);
133
- for (uint256 i; i < _end - _start; ++ i) {
134
- allPoolsList[i] = allPools[_start + i];
135
- }
130
+ function pools () external view returns (address [] memory ) {
131
+ return _getSlice (allPools, 0 , type (uint256 ).max);
132
+ }
133
+
134
+ /// @inheritdoc IEulerSwapFactory
135
+ function poolsByPairLength (address asset0 , address asset1 ) external view returns (uint256 ) {
136
+ return poolMap[asset0][asset1].length ;
137
+ }
136
138
137
- return allPoolsList;
139
+ /// @inheritdoc IEulerSwapFactory
140
+ function poolsByPairSlice (address asset0 , address asset1 , uint256 start , uint256 end )
141
+ external
142
+ view
143
+ returns (address [] memory )
144
+ {
145
+ return _getSlice (poolMap[asset0][asset1], start, end);
146
+ }
147
+
148
+ /// @inheritdoc IEulerSwapFactory
149
+ function poolsByPair (address asset0 , address asset1 ) external view returns (address [] memory ) {
150
+ return _getSlice (poolMap[asset0][asset1], 0 , type (uint256 ).max);
138
151
}
139
152
140
153
/// @notice Validates operator authorization for euler account and update the relevant EulerAccountState.
@@ -218,4 +231,24 @@ contract EulerSwapFactory is IEulerSwapFactory, EVCUtil {
218
231
function _getAssets (address pool ) internal view returns (address , address ) {
219
232
return (EulerSwap (pool).asset0 (), EulerSwap (pool).asset1 ());
220
233
}
234
+
235
+ /// @notice Returns a slice of an array of addresses
236
+ /// @dev Creates a new memory array containing elements from start to end index
237
+ /// If end is type(uint256).max, it will return all elements from start to the end of the array
238
+ /// @param arr The storage array to slice
239
+ /// @param start The starting index of the slice (inclusive)
240
+ /// @param end The ending index of the slice (exclusive)
241
+ /// @return A new memory array containing the requested slice of addresses
242
+ function _getSlice (address [] storage arr , uint256 start , uint256 end ) internal view returns (address [] memory ) {
243
+ uint256 length = arr.length ;
244
+ if (end == type (uint256 ).max) end = length;
245
+ if (end < start || end > length) revert SliceOutOfBounds ();
246
+
247
+ address [] memory slice = new address [](end - start);
248
+ for (uint256 i; i < end - start; ++ i) {
249
+ slice[i] = arr[start + i];
250
+ }
251
+
252
+ return slice;
253
+ }
221
254
}
0 commit comments