mirror of
				https://github.com/Instadapp/dsa-connectors.git
				synced 2024-07-29 22:37:00 +00:00 
			
		
		
		
	 4800889442
			
		
	
	
		4800889442
		
			
		
	
	
	
	
		
			
			* fixed checks * updated sushi incentive comments * fixed index.ts errors * removed yarn.lock since it is not used anywhere, updated gh actions config and package-lock.json Co-authored-by: Ishan Jain <contact@ishanjain.me> Co-authored-by: Prayuman Verma <pradyumnverma27@gmail.com>
		
			
				
	
	
		
			228 lines
		
	
	
		
			6.0 KiB
		
	
	
	
		
			Solidity
		
	
	
	
	
	
			
		
		
	
	
			228 lines
		
	
	
		
			6.0 KiB
		
	
	
	
		
			Solidity
		
	
	
	
	
	
| // SPDX-License-Identifier: MIT
 | |
| pragma solidity ^0.7.0;
 | |
| pragma experimental ABIEncoderV2;
 | |
| 
 | |
| /**
 | |
|  * @title SushiSwap Double Incentive.
 | |
|  * @dev Decentralized Exchange.
 | |
|  */
 | |
| 
 | |
| import { TokenInterface } from "../../common/interfaces.sol";
 | |
| import { Helpers } from "./helpers.sol";
 | |
| import { Events } from "./events.sol";
 | |
| 
 | |
| abstract contract SushipswapIncentiveResolver is Helpers, Events {
 | |
| 	/**
 | |
| 	 * @dev deposit LP token to masterChef
 | |
| 	 * @notice deposit LP token to masterChef
 | |
| 	 * @param token1 token1 of LP token
 | |
| 	 * @param token2 token2 of LP token
 | |
| 	 * @param amount amount of LP token
 | |
| 	 * @param getId ID to retrieve amount
 | |
| 	 * @param setId ID stores Pool ID
 | |
| 	 * @param data the metadata struct
 | |
| 	 */
 | |
| 	function deposit(
 | |
| 		address token1,
 | |
| 		address token2,
 | |
| 		uint256 amount,
 | |
| 		uint256 getId,
 | |
| 		uint256 setId,
 | |
| 		Metadata memory data
 | |
| 	)
 | |
| 		external
 | |
| 		payable
 | |
| 		returns (string memory _eventName, bytes memory _eventParam)
 | |
| 	{
 | |
| 		token1 = changeEthAddrToWethAddr(token1);
 | |
| 		token2 = changeEthAddrToWethAddr(token2);
 | |
| 		amount = getUint(getId, amount);
 | |
| 		if (
 | |
| 			data.poolId == uint256(-1) ||
 | |
| 			data.version == 0 ||
 | |
| 			data.lpToken == address(0)
 | |
| 		) {
 | |
| 			data = _getPoolId(token1, token2);
 | |
| 		}
 | |
| 		setUint(setId, data.poolId);
 | |
| 		require(data.poolId != uint256(-1), "pool-does-not-exist");
 | |
| 		TokenInterface lpToken = TokenInterface(data.lpToken);
 | |
| 		lpToken.approve(address(masterChef), amount);
 | |
| 		_deposit(data, amount);
 | |
| 		_eventName = "LogDeposit(address,address,uint256,uint256,uint256)";
 | |
| 		_eventParam = abi.encode(
 | |
| 			token1,
 | |
| 			token2,
 | |
| 			data.poolId,
 | |
| 			data.version,
 | |
| 			amount
 | |
| 		);
 | |
| 	}
 | |
| 
 | |
| 	/**
 | |
| 	 * @dev withdraw LP token from masterChef
 | |
| 	 * @notice withdraw LP token from masterChef
 | |
| 	 * @param token1 token1 of LP token
 | |
| 	 * @param token2 token2 of LP token
 | |
| 	 * @param amount amount of LP token
 | |
| 	 * @param getId ID to retrieve amount
 | |
| 	 * @param setId ID stores Pool ID
 | |
| 	 * @param data the metadata struct
 | |
| 	 */
 | |
| 	function withdraw(
 | |
| 		address token1,
 | |
| 		address token2,
 | |
| 		uint256 amount,
 | |
| 		uint256 getId,
 | |
| 		uint256 setId,
 | |
| 		Metadata memory data
 | |
| 	)
 | |
| 		external
 | |
| 		payable
 | |
| 		returns (string memory _eventName, bytes memory _eventParam)
 | |
| 	{
 | |
| 		token1 = changeEthAddrToWethAddr(token1);
 | |
| 		token2 = changeEthAddrToWethAddr(token2);
 | |
| 		amount = getUint(getId, amount);
 | |
| 		if (data.poolId == uint256(-1) || data.version == 0) {
 | |
| 			data = _getPoolId(token1, token2);
 | |
| 		}
 | |
| 		setUint(setId, amount);
 | |
| 		require(data.poolId != uint256(-1), "pool-does-not-exist");
 | |
| 		_withdraw(data, amount);
 | |
| 		_eventName = "LogDeposit(address,address,uint256,uint256,uint256)";
 | |
| 		_eventParam = abi.encode(
 | |
| 			token1,
 | |
| 			token2,
 | |
| 			data.poolId,
 | |
| 			data.version,
 | |
| 			amount
 | |
| 		);
 | |
| 	}
 | |
| 
 | |
| 	/**
 | |
| 	 * @dev harvest from masterChef
 | |
| 	 * @notice harvest from masterChef
 | |
| 	 * @param token1 token1 deposited of LP token
 | |
| 	 * @param token2 token2 deposited LP token
 | |
| 	 * @param setId ID stores Pool ID
 | |
| 	 * @param data the metadata struct
 | |
| 	 */
 | |
| 	function harvest(
 | |
| 		address token1,
 | |
| 		address token2,
 | |
| 		uint256 setId,
 | |
| 		Metadata memory data
 | |
| 	)
 | |
| 		external
 | |
| 		payable
 | |
| 		returns (string memory _eventName, bytes memory _eventParam)
 | |
| 	{
 | |
| 		token1 = changeEthAddrToWethAddr(token1);
 | |
| 		token2 = changeEthAddrToWethAddr(token2);
 | |
| 		if (data.poolId == uint256(-1) || data.version == 0) {
 | |
| 			data = _getPoolId(token1, token2);
 | |
| 		}
 | |
| 		setUint(setId, data.poolId);
 | |
| 		require(data.poolId != uint256(-1), "pool-does-not-exist");
 | |
| 		(, uint256 rewardsAmount) = _getUserInfo(data);
 | |
| 		if (data.version == 2) _harvest(data);
 | |
| 		else _withdraw(data, 0);
 | |
| 		_eventName = "LogDeposit(address,address,uint256,uint256,uint256)";
 | |
| 		_eventParam = abi.encode(
 | |
| 			token1,
 | |
| 			token2,
 | |
| 			data.poolId,
 | |
| 			data.version,
 | |
| 			rewardsAmount
 | |
| 		);
 | |
| 	}
 | |
| 
 | |
| 	/**
 | |
| 	 * @dev withdraw LP token and harvest from masterChef
 | |
| 	 * @notice withdraw LP token and harvest from masterChef
 | |
| 	 * @param token1 token1 of LP token
 | |
| 	 * @param token2 token2 of LP token
 | |
| 	 * @param amount amount of LP token
 | |
| 	 * @param getId ID to retrieve amount
 | |
| 	 * @param setId ID stores Pool ID
 | |
| 	 * @param data the metadata struct
 | |
| 	 */
 | |
| 	function withdrawAndHarvest(
 | |
| 		address token1,
 | |
| 		address token2,
 | |
| 		uint256 amount,
 | |
| 		uint256 getId,
 | |
| 		uint256 setId,
 | |
| 		Metadata memory data
 | |
| 	)
 | |
| 		external
 | |
| 		payable
 | |
| 		returns (string memory _eventName, bytes memory _eventParam)
 | |
| 	{
 | |
| 		token1 = changeEthAddrToWethAddr(token1);
 | |
| 		token2 = changeEthAddrToWethAddr(token2);
 | |
| 		amount = getUint(getId, amount);
 | |
| 		if (data.poolId == uint256(-1) || data.version == 0) {
 | |
| 			data = _getPoolId(token1, token2);
 | |
| 		}
 | |
| 		setUint(setId, data.poolId);
 | |
| 		require(data.poolId != uint256(-1), "pool-does-not-exist");
 | |
| 		(, uint256 rewardsAmount) = _getUserInfo(data);
 | |
| 		_withdrawAndHarvest(data, amount);
 | |
| 		_eventName = "LogWithdrawAndHarvest(address,address,uint256,uint256,uint256,uint256)";
 | |
| 		_eventParam = abi.encode(
 | |
| 			token1,
 | |
| 			token2,
 | |
| 			data.poolId,
 | |
| 			data.version,
 | |
| 			amount,
 | |
| 			rewardsAmount
 | |
| 		);
 | |
| 	}
 | |
| 
 | |
| 	/**
 | |
| 	 * @dev emergency withdraw from masterChef
 | |
| 	 * @notice emergency withdraw from masterChef
 | |
| 	 * @param token1 token1 deposited of LP token
 | |
| 	 * @param token2 token2 deposited LP token
 | |
| 	 * @param setId ID stores Pool ID
 | |
| 	 * @param data the metadata struct
 | |
| 	 */
 | |
| 	function emergencyWithdraw(
 | |
| 		address token1,
 | |
| 		address token2,
 | |
| 		uint256 setId,
 | |
| 		Metadata memory data
 | |
| 	)
 | |
| 		external
 | |
| 		payable
 | |
| 		returns (string memory _eventName, bytes memory _eventParam)
 | |
| 	{
 | |
| 		token1 = changeEthAddrToWethAddr(token1);
 | |
| 		token2 = changeEthAddrToWethAddr(token2);
 | |
| 		if (data.poolId == uint256(-1) || data.version == 0) {
 | |
| 			data = _getPoolId(token1, token2);
 | |
| 		}
 | |
| 		uint256 currentBal = _balance(token1, token2);
 | |
| 		require(data.poolId != uint256(-1), "pool-does-not-exist");
 | |
| 		(uint256 lpAmount, uint256 rewardsAmount) = _getUserInfo(data);
 | |
| 		_emergencyWithdraw(data);
 | |
| 		uint256 finalBal = _balance(token1, token2);
 | |
| 		setUint(setId, uint256(currentBal - finalBal));
 | |
| 		_eventName = "LogEmergencyWithdraw(address,address,uint256,uint256,uint256,uint256)";
 | |
| 		_eventParam = abi.encode(
 | |
| 			token1,
 | |
| 			token2,
 | |
| 			data.poolId,
 | |
| 			data.version,
 | |
| 			lpAmount,
 | |
| 			rewardsAmount
 | |
| 		);
 | |
| 	}
 | |
| }
 | |
| 
 | |
| contract ConnectV2SushiswapIncentive is SushipswapIncentiveResolver {
 | |
| 	string public constant name = "SushipswapIncentive-v1.1";
 | |
| }
 |