Skip to main content

SushiLegacyAdapter

The SushiLegacyAdapter is an abstract contract that is inherited to provide functions required by the SushiXSwap contract to swap using the Sushi Classic AMM contracts (V2).

The full contract can be found here here.

Read-Only Functions

State-Changing Functions

_swapExactTokensForTokens

function _swapExactTokensForTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] memory path,
address to,
bool sendTokens
) internal returns (uint256 amountOut);

Swaps an exact amount of input tokens for as many output tokens as possible, along a predefined path.

  • msg.sender should have already given the router an allowance of at least amountIn on the input token.
  • amountOutMin can be used for slippage protection.
  • sendTokens controls whether tokens should be forcibly sent to the first pair if they have not already been sent.

Parameters

NameTypeDescription
amountInuint256amount of input tokens to send
amountOutMinuint256minimum amount of output tokens that must be received for the transaction not to revert
pathaddress[] memorythe path the tokens will take (a list of token addresses). Must be at least 2 elements long, with the input token as the first element
toaddressrecipient of the output tokens
sendTokensboolflag to forcibly send tokens to the first pair if not already sent

Returns

NameTypeDescription
amountOutuint256amount of output tokens that were received

Reverts

This function reverts if the output amount is less than amountOutMin, with the error message "insufficient-amount-out".

Modifiers

This function doesn't use any modifiers.

Functions called

This function calls the getAmountsOut, safeTransfer, and pairFor functions of the UniswapV2Library, and the balanceOf function of the input token.

Security Considerations

This function is marked as internal, which means it can only be called from within the contract or from contracts that inherit from this contract. It should be ensured that the parameters passed are accurate and safe to use. The function uses the contract's balance of the input token, so it should be ensured that this is intended and safe. It also requires the contract to have a sufficient balance of the input token for the swap operation to succeed.