Skip to content

Commit 2a066ad

Browse files
authored
fix Felix comments (#105)
1 parent 7904b16 commit 2a066ad

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

contracts/product/AMMSplitter.sol

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ contract AMMSplitter {
108108
/* ============ External Functions ============= */
109109

110110
/**
111-
* Executes an exact input trade. Splits trade efficiently between Uniswap and Sushiswap
111+
* Executes an exact input trade split between Uniswap and Sushiswap. This function is for when one wants to trade with the optimal split between Uniswap
112+
* and Sushiswap. This function's interface matches the Uniswap V2 swapExactTokensForTokens function. Input/output tokens are inferred implicitly from
113+
* the trade path with first token as input and last as output.
112114
*
113115
* @param _amountIn the exact input amount
114116
* @param _amountOutMin the minimum output amount that must be received
@@ -128,7 +130,7 @@ contract AMMSplitter {
128130
external
129131
returns (uint256 totalOutput)
130132
{
131-
require(_path.length <= 3 && _path.length != 0, "AMMSplitter: incorrect path length");
133+
_checkPath(_path);
132134

133135
IERC20 inputToken = IERC20(_path[0]);
134136
inputToken.transferFrom(msg.sender, address(this), _amountIn);
@@ -155,7 +157,9 @@ contract AMMSplitter {
155157
}
156158

157159
/**
158-
* Executes an exact output trade. Splits trade efficiently between Uniswap and Sushiswap
160+
* Executes an exact output trade split between Uniswap and Sushiswap. This function is for when one wants to trade with the optimal split between Uniswap
161+
* and Sushiswap. This function's interface matches the Uniswap V2 swapTokensForExactTokens function. Input/output tokens are inferred implicitly from
162+
* the trade path with first token as input and last as output.
159163
*
160164
* @param _amountOut the exact output amount
161165
* @param _amountInMax the maximum input amount that can be spent
@@ -175,7 +179,7 @@ contract AMMSplitter {
175179
external
176180
returns (uint256 totalInput)
177181
{
178-
require(_path.length <= 3 && _path.length != 0, "AMMSplitter: incorrect path length");
182+
_checkPath(_path);
179183

180184
TradeInfo memory tradeInfo = _getTradeSizes(_path, _amountOut);
181185

@@ -214,7 +218,7 @@ contract AMMSplitter {
214218
* @param _amountIn input amount
215219
* @param _path the trade path to use
216220
*
217-
* @return uint256[] array of input amounts, intermiary amounts, and output amounts
221+
* @return uint256[] array of input amounts, intermediary amounts, and output amounts
218222
*/
219223
function getAmountsOut(uint256 _amountIn, address[] calldata _path) external view returns (uint256[] memory) {
220224
return _getAmounts(_amountIn, _path, true);
@@ -245,7 +249,7 @@ contract AMMSplitter {
245249
*/
246250
function _getAmounts(uint256 _size, address[] calldata _path, bool _isExactInput) internal view returns (uint256[] memory amounts) {
247251

248-
require(_path.length <= 3 && _path.length != 0, "AMMSplitter: incorrect path length");
252+
_checkPath(_path);
249253

250254
TradeInfo memory tradeInfo = _getTradeSizes(_path, _size);
251255

@@ -259,8 +263,8 @@ contract AMMSplitter {
259263
}
260264

261265
/**
262-
* Calculates the optimal trade sizes for Uniswap and Sushiswap. Pool vaules must be measured in the same token. For single hop trades
263-
* this is the balance of the output token. For two hop trades, it is measured as the balance of the intermidiary token. The equation to
266+
* Calculates the optimal trade sizes for Uniswap and Sushiswap. Pool values must be measured in the same token. For single hop trades
267+
* this is the balance of the output token. For two hop trades, it is measured as the balance of the intermediary token. The equation to
264268
* calculate the ratio for two hop trades is documented under _calculateTwoHopRatio. For single hop trades, this equation is:
265269
*
266270
* Tu/Ts = Pu / Ps
@@ -273,7 +277,7 @@ contract AMMSplitter {
273277
* @param _path the trade path that will be used
274278
* @param _size the total size of the trade
275279
*
276-
* @return tradeInfo TradeInfo struct containing Uniswap and Sushiswap tarde sizes
280+
* @return tradeInfo TradeInfo struct containing Uniswap and Sushiswap trade sizes
277281
*/
278282
function _getTradeSizes(address[] calldata _path, uint256 _size) internal view returns (TradeInfo memory tradeInfo) {
279283

@@ -369,6 +373,16 @@ contract AMMSplitter {
369373
}
370374
}
371375

376+
/**
377+
* Confirms that the path length is either two or three. Reverts if it does not fall within these bounds. When paths are greater than three in
378+
* length, the calculation for the optimal split between Uniswap and Sushiswap becomes much more difficult, so it is disallowed.
379+
*
380+
* @param _path trade path to check
381+
*/
382+
function _checkPath(address[] calldata _path) internal pure {
383+
require(_path.length == 2 || _path.length == 3, "AMMSplitter: incorrect path length");
384+
}
385+
372386
/**
373387
* Gets the balance of a component token in a Uniswap / Sushiswap pool
374388
*
@@ -392,7 +406,7 @@ contract AMMSplitter {
392406
* @param _path Path for the trade
393407
* @param _to Address to redirect trade output to
394408
* @param _deadline Timestamp that trade must execute before
395-
* @param _isExactInput Whether to perfrom an exact input or exact output swap
409+
* @param _isExactInput Whether to perform an exact input or exact output swap
396410
*
397411
* @return uint256 the actual input / output amount of the trade
398412
*/

0 commit comments

Comments
 (0)