Skip to content

Commit

Permalink
added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sarangparikh22 committed Jul 16, 2022
1 parent af382f3 commit 89b1cb6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
18 changes: 18 additions & 0 deletions contracts/TridentRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ contract TridentRouter is ITridentRouter, SelfPermit, Multicall {
if (amountOut < params.amountOutMinimum) revert TooLittleReceived();
}

/// @notice Swaps token B to token A directly. Swaps are done on `bento` tokens.
/// @param params This includes the address of token B, pool, amount of token B to swap,
/// maximum amount of token A for the swap and data required by the pool for the swap.
/// @dev Ensure that the pool is trusted before calling this function. The pool can steal users' tokens.
function exactOutputSingle(ExactOutputSingleParams calldata params) public payable returns (uint256 amountIn) {
amountIn = TridentRouterLibrary.getAmountIn(params.pool, params.amountOut, params.tokenOut);

Expand Down Expand Up @@ -97,6 +101,10 @@ contract TridentRouter is ITridentRouter, SelfPermit, Multicall {
if (amountOut < params.amountOutMinimum) revert TooLittleReceived();
}

/// @notice Swaps token B to token A indirectly by using multiple hops.
/// @param params This includes the addresses of the tokens, pools, amount of token B to swap,
/// maximum amount of token A for the swap and data required by the pools for the swaps.
/// @dev Ensure that the pools are trusted before calling this function. The pools can steal users' tokens.
function exactOutput(ExactOutputParams calldata params) public payable returns (uint256 amountIn) {
amountIn = TridentRouterLibrary.getAmountsIn(params.path, params.tokenOut, params.amountOut)[0];

Expand Down Expand Up @@ -127,6 +135,11 @@ contract TridentRouter is ITridentRouter, SelfPermit, Multicall {
if (amountOut < params.amountOutMinimum) revert TooLittleReceived();
}

/// @notice Swaps token B to token A directly. It's the same as `exactOutputSingle` except
/// it takes raw ERC-20 tokens from the users and deposits them into `bento`.
/// @param params This includes the address of token B, pool, amount of token B to swap,
/// minimum amount of token A for the swap and data required by the pool for the swap.
/// @dev Ensure that the pool is trusted before calling this function. The pool can steal users' tokens.
function exactOutputSingleWithNativeTokens(ExactOutputSingleParams calldata params) public payable returns (uint256 amountIn) {
amountIn = TridentRouterLibrary.getAmountIn(params.pool, params.amountOut, params.tokenOut);

Expand Down Expand Up @@ -158,6 +171,11 @@ contract TridentRouter is ITridentRouter, SelfPermit, Multicall {
if (amountOut < params.amountOutMinimum) revert TooLittleReceived();
}

/// @notice Swaps token B to token A indirectly by using multiple hops. It's the same as `exactOutput` except
/// it takes raw ERC-20 tokens from the users and deposits them into `bento`.
/// @param params This includes the addresses of the tokens, pools, amount of token B to swap,
/// maximum amount of token A for the swap and data required by the pools for the swaps.
/// @dev Ensure that the pools are trusted before calling this function. The pools can steal users' tokens.
function exactOutputWithNativeToken(ExactOutputParams calldata params) public payable returns (uint256 amountIn) {
amountIn = TridentRouterLibrary.getAmountsIn(params.path, params.tokenOut, params.amountOut)[0];

Expand Down
8 changes: 8 additions & 0 deletions contracts/libraries/TridentRouterLibrary.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import "../interfaces/ITridentRouter.sol";
import "../interfaces/IPool.sol";

library TridentRouterLibrary {
/// @notice Get Amount In from the pool
/// @param pool Pool address
/// @param amountOut Amount out required
/// @param tokenOut Token out required
function getAmountIn(
address pool,
uint256 amountOut,
Expand All @@ -15,6 +19,10 @@ library TridentRouterLibrary {
amountIn = IPool(pool).getAmountIn(data);
}

/// @notice Get Amount In multihop
/// @param path Path for the hops (pool addresses)
/// @param tokenOut Token out required
/// @param amountOut Amount out required
function getAmountsIn(
ITridentRouter.Path[] memory path,
address tokenOut,
Expand Down

0 comments on commit 89b1cb6

Please sign in to comment.