The Sushi adapter enables the Yieldinator Facet to integrate with SushiSwap's liquidity pools and SushiBar (xSUSHI) staking, allowing vaults to earn trading fees, SUSHI rewards, and additional yield from staking SUSHI tokens.
Overview
SushiSwap is a decentralized exchange and yield farming platform that allows users to provide liquidity to trading pairs, earn trading fees, and farm SUSHI tokens. The Sushi adapter facilitates deposits into SushiSwap pools, manages SLP (Sushi Liquidity Provider) token balances, stakes in MasterChef farming contracts, and optionally stakes SUSHI rewards in the SushiBar for additional yield.
Implementation Details
Contract: SushiAdapter.sol
The adapter implements the standard YieldinatorAdapter interface with Sushi-specific functionality:
contractSushiAdapterisYieldinatorAdapter{usingSafeERC20forIERC20;// Sushi contractsaddresspublic sushiToken;addresspublic xSushiToken;// SushiBar token IMasterChef public masterChef; ISushiBar public sushiBar;// Pool configurationstructPoolConfig{address pair;// SushiSwap pair addressuint256 pid;// Pool ID in MasterChefaddress token0;// First token in the pairaddress token1;// Second token in the pairbool stakeLp;// Whether to stake LP tokens in MasterChefbool stakeSushi;// Whether to stake SUSHI rewards in SushiBarbool active;// Whether the pool is active}// Mapping from token to pool configurationmapping(address=> PoolConfig)public tokenToPool;// Deposited amounts per tokenmapping(address=>uint256)public depositedAmount;// Constructorconstructor(address_admin,address_sushiToken,address_xSushiToken,address_masterChef,address_sushiBar ) YieldinatorAdapter("SushiSwap", _admin) {require(_sushiToken !=address(0),"SushiAdapter: sushi token cannot be zero address");require(_xSushiToken !=address(0),"SushiAdapter: xSushi token cannot be zero address");require(_masterChef !=address(0),"SushiAdapter: masterChef cannot be zero address");require(_sushiBar !=address(0),"SushiAdapter: sushiBar cannot be zero address"); sushiToken = _sushiToken; xSushiToken = _xSushiToken; masterChef =IMasterChef(_masterChef); sushiBar =ISushiBar(_sushiBar);}}
Key Functions
Pool Registration
Before using the adapter for a specific token, the pool must be registered:
Deposit
The deposit function handles adding liquidity to SushiSwap and optionally staking LP tokens:
Withdraw
The withdraw function handles removing liquidity from SushiSwap and unstaking LP tokens if necessary:
Harvest Yield
The harvestYield function collects SUSHI rewards and optionally stakes them in SushiBar:
Emergency Withdraw
The emergencyWithdraw function provides a safety mechanism to withdraw all funds:
APY Calculation
The getCurrentAPY function calculates the current APY for a token in the SushiSwap pool:
Usage Example
Here's an example of how to use the Sushi adapter with the Yieldinator Facet:
Security Considerations
Impermanent Loss: Users should be aware of impermanent loss risks when providing liquidity to SushiSwap pairs.
Smart Contract Risk: The adapter interacts with multiple external contracts (SushiSwap Router, MasterChef, SushiBar) which may have vulnerabilities.
Price Impact: Large deposits or withdrawals may experience significant price impact, especially for less liquid pairs.
Slippage Protection: The adapter includes slippage protection (5% by default) to prevent excessive value loss during swaps.
Gas Optimization
The adapter minimizes gas usage by batching operations when possible.
For harvesting rewards, users can choose whether to stake SUSHI in SushiBar based on gas costs and expected returns.
The adapter avoids unnecessary approvals by only approving tokens when needed.
Future Improvements
Support for SushiSwap's BentoBox and Kashi lending
Integration with SushiSwap's limit order functionality
Support for concentrated liquidity pools (Trident)
Automated compounding of rewards for maximum yield