Skip to content

Commit

Permalink
📚 Document internal function
Browse files Browse the repository at this point in the history
  • Loading branch information
JaredBorders committed Jul 9, 2023
1 parent 992740f commit 3a22939
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions src/Account.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,29 @@ contract Account is IAccount, Auth, OpsReady {
});
}

/// @notice decode and return tokens encoded in the provided path
/// @param _path: path of tokens to swap (token0 - fee - token1)
/// @return tokenIn token swapped into the respective pool
/// @return tokenOut token swapped out of the respective pool
function _getTokenInTokenOut(bytes calldata _path)
internal
pure
returns (address tokenIn, address tokenOut)
{
tokenIn = _path.decodeFirstToken();
while (true) {
bool hasMultiplePools = _path.hasMultiplePools();

// decide whether to continue or terminate
if (hasMultiplePools) {
_path = _path.skipToken();
} else {
(,, tokenOut) = _path.toPool();
break;
}
}
}

/// @notice call Uniswap's Universal Router to execute a swap
/// @param _recipient: address to receive swapped tokens
/// @param _amountIn: amount of token to swap
Expand All @@ -1058,25 +1081,6 @@ contract Account is IAccount, Auth, OpsReady {
});
}

function _getTokenInTokenOut(bytes calldata _path)
internal
pure
returns (address tokenIn, address tokenOut)
{
tokenIn = _path.decodeFirstToken();
while (true) {
bool hasMultiplePools = _path.hasMultiplePools();

// decide whether to continue or terminate
if (hasMultiplePools) {
_path = _path.skipToken();
} else {
(,, tokenOut) = _path.toPool();
break;
}
}
}

/*//////////////////////////////////////////////////////////////
MARGIN UTILITIES
//////////////////////////////////////////////////////////////*/
Expand Down

0 comments on commit 3a22939

Please sign in to comment.