In a Sauce program, swap withCommunity-driven fork of Uniswap V2 with additional yield farming features and multi-chain deployment. Identical AMM interface to Uniswap V2 (x*y=k constant product) with broader L2 and alt-chain coverage.@sauce/router’s function for the venue (uniswapV2,uniswapV3,uniswapV4,curve,balancerV2, …; Slipstream, PancakeSwap V3 and Algebra pools throughuniswapV3), with a minimum output and, where the pool takes one, a price limit (the@sauce/routerreference; several pools under one limit, the distributed swap).
When to use it
- A Uniswap V2 fork: constant-product pairs, 0.3% fee, the same Router interface. Use it where its pair is deeper than Uniswap V2’s on the chain.
Pitfalls for a program
- As Uniswap V2:
amountOutMinis the only bound; through the Router, approve exactlyamountInand pass a deadline.
In a Sauce program
Sell the Pot’s USDC for WETH at the pair:uniswapV2 prices the output from the pair’s reserves with its 0.3% fee (3000 ppm), pushes
amountIn to the pair, pays recipient and reverts below minOut. The pair takes the whole input
or the program reverts, so no input is left to return.
What it offers
- swap: Swap exact input tokens through a routing path
- addLiquidity: Deposit two tokens to mint SLP (SushiSwap LP) tokens
- removeLiquidity: Burn SLP tokens to withdraw underlying tokens
Notes
- Interface is identical to Uniswap V2; same 0.3% fee per hop
- Factory and Router addresses are consistent across Arbitrum, Polygon, BSC, Avalanche, and Fantom
- SLP tokens can be staked in SushiSwap’s MasterChef/MiniChef contracts for SUSHI rewards (not in SDK)
- Both tokens must be ERC20-approved to the Router before swap/addLiquidity
- Use SushiSwap when Uniswap V2 is not deployed on the target chain, or when SUSHI farming incentives are active
- From a Pot program,
@sauce/routertrades a SushiSwap V2 pair directly, with no router and no approval:uniswapV2(pair, tokenIn, tokenOut, amountIn, 3000, minOut, recipient)reads the pair’sgetReserves, prices the output in the program with the pair’s fee in parts per million, transfers the input to the pair and callspair.swapwith emptydata, returning the amount out. The direction is the sort order oftokenInandtokenOut(token0is the lower address), so there is no argument to get wrong. The swap consumes its whole input or reverts; there is no refund path.tryUniswapV2takes the same arguments and returns0, moving nothing, when the pair cannot fill the whole input at the floor. TheuniswapV2Swapaction is the same call
Its names in a program
On Ethereum,SushiswapV2 is a namespace: its contracts need no import.
Deployments
ABI
Where a line says what an address it returns is, a program that calls the function through its namespace calls that contract’s methods on the result directly:<Namespace>.<Contract>.<function>(...).<method>(...). A token’s methods are the ERC-20
functions, and its writes are SafeERC20.
SushiSwapV2FactoryABI
import SushiSwapV2FactoryABI from "./protocols/sushiswap-v2/SushiSwapV2FactoryABI.json"; Speaks for: factory.
getPair(address tokenA, address tokenB) view returns (address pair): the address is aSushiswapV2.PaircreatePair(address tokenA, address tokenB) returns (address pair)
SushiSwapV2PairABI
import SushiSwapV2PairABI from "./protocols/sushiswap-v2/SushiSwapV2PairABI.json";
getReserves() view returns (uint112 _reserve0, uint112 _reserve1, uint32 _blockTimestampLast)token0() view returns (address): the address is a tokentoken1() view returns (address): the address is a tokenswap(uint256 amount0Out, uint256 amount1Out, address to, bytes data)
SushiSwapV2RouterABI
import SushiSwapV2RouterABI from "./protocols/sushiswap-v2/SushiSwapV2RouterABI.json"; Speaks for: router.
swapExactTokensForTokens(uint256 amountIn, uint256 amountOutMin, address[] path, address to, uint256 deadline) returns (uint256[] amounts)swapTokensForExactTokens(uint256 amountOut, uint256 amountInMax, address[] path, address to, uint256 deadline) returns (uint256[] amounts)addLiquidity(address tokenA, address tokenB, uint256 amountADesired, uint256 amountBDesired, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline) returns (uint256 amountA, uint256 amountB, uint256 liquidity)removeLiquidity(address tokenA, address tokenB, uint256 liquidity, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline) returns (uint256 amountA, uint256 amountB)getAmountsOut(uint256 amountIn, address[] path) view returns (uint256[] amounts)
Next steps
- Protocols: the other protocols, by what they do.
- Protocols and tokens: calling a contract by its namespace, or through its ABI.
- Glossary: the words these pages use, in plain terms.
