@@ -24,7 +24,7 @@ contract EulerSwapPeriphery is IEulerSwapPeriphery {
24
24
25
25
require (amountOut >= amountOutMin, AmountOutLessThanMin ());
26
26
27
- _swap (eulerSwap, tokenIn, tokenOut, amountIn, amountOut);
27
+ swap (eulerSwap, tokenIn, tokenOut, amountIn, amountOut);
28
28
}
29
29
30
30
/// @inheritdoc IEulerSwapPeriphery
@@ -35,7 +35,7 @@ contract EulerSwapPeriphery is IEulerSwapPeriphery {
35
35
36
36
require (amountIn <= amountInMax, AmountInMoreThanMax ());
37
37
38
- _swap (eulerSwap, tokenIn, tokenOut, amountIn, amountOut);
38
+ swap (eulerSwap, tokenIn, tokenOut, amountIn, amountOut);
39
39
}
40
40
41
41
/// @inheritdoc IEulerSwapPeriphery
@@ -56,9 +56,13 @@ contract EulerSwapPeriphery is IEulerSwapPeriphery {
56
56
return computeQuote (IEulerSwap (eulerSwap), tokenIn, tokenOut, amountOut, false );
57
57
}
58
58
59
- function _swap (address eulerSwap , address tokenIn , address tokenOut , uint256 amountIn , uint256 amountOut )
60
- internal
61
- {
59
+ /// @dev Internal function to execute a token swap through EulerSwap
60
+ /// @param eulerSwap The EulerSwap contract address to execute the swap through
61
+ /// @param tokenIn The address of the input token being swapped
62
+ /// @param tokenOut The address of the output token being received
63
+ /// @param amountIn The amount of input tokens to swap
64
+ /// @param amountOut The amount of output tokens to receive
65
+ function swap (address eulerSwap , address tokenIn , address tokenOut , uint256 amountIn , uint256 amountOut ) internal {
62
66
IERC20 (tokenIn).safeTransferFrom (msg .sender , eulerSwap, amountIn);
63
67
64
68
bool isAsset0In = tokenIn < tokenOut;
@@ -67,8 +71,18 @@ contract EulerSwapPeriphery is IEulerSwapPeriphery {
67
71
: IEulerSwap (eulerSwap).swap (amountOut, 0 , msg .sender , "" );
68
72
}
69
73
70
- /// @dev High-level quoting function. It handles fees and performs
71
- /// state validation, for example that there is sufficient cash available.
74
+ /// @dev Computes the quote for a swap by applying fees and validating state conditions
75
+ /// @param eulerSwap The EulerSwap contract to quote from
76
+ /// @param tokenIn The input token address
77
+ /// @param tokenOut The output token address
78
+ /// @param amount The amount to quote (input amount if exactIn=true, output amount if exactIn=false)
79
+ /// @param exactIn True if quoting for exact input amount, false if quoting for exact output amount
80
+ /// @return The quoted amount (output amount if exactIn=true, input amount if exactIn=false)
81
+ /// @dev Validates:
82
+ /// - EulerSwap operator is installed
83
+ /// - Token pair is supported
84
+ /// - Sufficient reserves exist
85
+ /// - Sufficient cash is available
72
86
function computeQuote (IEulerSwap eulerSwap , address tokenIn , address tokenOut , uint256 amount , bool exactIn )
73
87
internal
74
88
view
@@ -115,9 +129,17 @@ contract EulerSwapPeriphery is IEulerSwapPeriphery {
115
129
return quote;
116
130
}
117
131
132
+ /// @notice Binary searches for the output amount along a swap curve given input parameters
118
133
/// @dev General-purpose routine for binary searching swapping curves.
119
134
/// Although some curves may have more efficient closed-form solutions,
120
135
/// this works with any monotonic curve.
136
+ /// @param eulerSwap The EulerSwap contract to search the curve for
137
+ /// @param reserve0 Current reserve of asset0 in the pool
138
+ /// @param reserve1 Current reserve of asset1 in the pool
139
+ /// @param amount The input or output amount depending on exactIn
140
+ /// @param exactIn True if amount is input amount, false if amount is output amount
141
+ /// @param asset0IsInput True if asset0 is being input, false if asset1 is being input
142
+ /// @return output The calculated output amount from the binary search
121
143
function binarySearch (
122
144
IEulerSwap eulerSwap ,
123
145
uint112 reserve0 ,
0 commit comments