minor fixes

This commit is contained in:
cryptoDev222 2021-11-15 08:58:14 -06:00 committed by pradyuman-verma
parent 650009f45e
commit 627e839c70
4 changed files with 78 additions and 28 deletions

View File

@ -41,6 +41,10 @@ abstract contract Basic is DSMath, Stores {
_sell = sell == ethAddr ? TokenInterface(wethAddr) : TokenInterface(sell); _sell = sell == ethAddr ? TokenInterface(wethAddr) : TokenInterface(sell);
} }
function changeEthAddrToWethAddr(address token) internal pure returns(address tokenAddr){
tokenAddr = token == ethAddr ? wethAddr : token;
}
function convertEthToWeth(bool isEth, TokenInterface token, uint amount) internal { function convertEthToWeth(bool isEth, TokenInterface token, uint amount) internal {
if(isEth) token.deposit{value: amount}(); if(isEth) token.deposit{value: amount}();
} }

View File

@ -2,32 +2,27 @@ pragma solidity ^0.7.0;
contract Events { contract Events {
event LogDeposit( event LogDeposit(
address indexed user,
uint256 indexed pid, uint256 indexed pid,
uint256 indexed version, uint256 indexed version,
uint256 amount uint256 amount
); );
event LogWithdraw( event LogWithdraw(
address indexed user,
uint256 indexed pid, uint256 indexed pid,
uint256 indexed version, uint256 indexed version,
uint256 amount uint256 amount
); );
event LogEmergencyWithdraw( event LogEmergencyWithdraw(
address indexed user,
uint256 indexed pid, uint256 indexed pid,
uint256 indexed version, uint256 indexed version,
uint256 lpAmount, uint256 lpAmount,
uint256 rewardsAmount uint256 rewardsAmount
); );
event LogHarvest( event LogHarvest(
address indexed user,
uint256 indexed pid, uint256 indexed pid,
uint256 indexed version, uint256 indexed version,
uint256 amount uint256 amount
); );
event LogWithdrawAndHarvest( event LogWithdrawAndHarvest(
address indexed user,
uint256 indexed pid, uint256 indexed pid,
uint256 indexed version, uint256 indexed version,
uint256 widrawAmount, uint256 widrawAmount,

View File

@ -1,6 +1,5 @@
pragma solidity ^0.7.0; pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
import "./libraries/IERC20.sol";
struct UserInfo { struct UserInfo {
uint256 amount; uint256 amount;
@ -14,6 +13,30 @@ struct PoolInfo {
uint256 accSushiPerShare; // Accumulated SUSHIs per share, times 1e12. See below. uint256 accSushiPerShare; // Accumulated SUSHIs per share, times 1e12. See below.
} }
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
/// @notice EIP 2612
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
}
interface IMasterChef { interface IMasterChef {
function poolLength() external view returns (uint256); function poolLength() external view returns (uint256);

View File

@ -13,6 +13,7 @@ import {Events} from "./events.sol";
abstract contract SushipswapIncentiveResolver is Helpers, Events { abstract contract SushipswapIncentiveResolver is Helpers, Events {
/** /**
* @dev deposit LP token to masterChef * @dev deposit LP token to masterChef
* @notice deposit LP token to masterChef
* @param token1 token1 of LP token * @param token1 token1 of LP token
* @param token2 token2 of LP token * @param token2 token2 of LP token
* @param amount amount of LP token * @param amount amount of LP token
@ -25,7 +26,13 @@ abstract contract SushipswapIncentiveResolver is Helpers, Events {
uint256 amount, uint256 amount,
uint256 getId, uint256 getId,
uint256 setId uint256 setId
) external { )
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
token1 = changeEthAddrToWethAddr(token1);
token2 = changeEthAddrToWethAddr(token2);
amount = getUint(getId, amount); amount = getUint(getId, amount);
(uint256 _pid, uint256 _version, address lpTokenAddr) = _getPoolId( (uint256 _pid, uint256 _version, address lpTokenAddr) = _getPoolId(
token1, token1,
@ -36,11 +43,13 @@ abstract contract SushipswapIncentiveResolver is Helpers, Events {
TokenInterface lpToken = TokenInterface(lpTokenAddr); TokenInterface lpToken = TokenInterface(lpTokenAddr);
lpToken.approve(address(masterChef), amount); lpToken.approve(address(masterChef), amount);
_deposit(_pid, amount, _version); _deposit(_pid, amount, _version);
emit LogDeposit(address(this), _pid, _version, amount); _eventName = "LogDeposit(uint256,uint256,uint256)";
_eventParam = abi.encode(_pid, _version, amount);
} }
/** /**
* @dev withdraw LP token from masterChef * @dev withdraw LP token from masterChef
* @notice withdraw LP token from masterChef
* @param token1 token1 of LP token * @param token1 token1 of LP token
* @param token2 token2 of LP token * @param token2 token2 of LP token
* @param amount amount of LP token * @param amount amount of LP token
@ -53,17 +62,25 @@ abstract contract SushipswapIncentiveResolver is Helpers, Events {
uint256 amount, uint256 amount,
uint256 getId, uint256 getId,
uint256 setId uint256 setId
) external { )
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
token1 = changeEthAddrToWethAddr(token1);
token2 = changeEthAddrToWethAddr(token2);
amount = getUint(getId, amount); amount = getUint(getId, amount);
(uint256 _pid, uint256 _version, ) = _getPoolId(token1, token2); (uint256 _pid, uint256 _version, ) = _getPoolId(token1, token2);
setUint(setId, _pid); setUint(setId, _pid);
require(_pid != uint256(-1), "pool-does-not-exist"); require(_pid != uint256(-1), "pool-does-not-exist");
_withdraw(_pid, amount, _version); _withdraw(_pid, amount, _version);
emit LogWithdraw(address(this), _pid, _version, amount); _eventName = "LogWithdraw(uint256,uint256,uint256)";
_eventParam = abi.encode(_pid, _version, amount);
} }
/** /**
* @dev harvest from masterChef * @dev harvest from masterChef
* @notice harvest from masterChef
* @param token1 token1 deposited of LP token * @param token1 token1 deposited of LP token
* @param token2 token2 deposited LP token * @param token2 token2 deposited LP token
* @param setId ID stores Pool ID * @param setId ID stores Pool ID
@ -72,18 +89,26 @@ abstract contract SushipswapIncentiveResolver is Helpers, Events {
address token1, address token1,
address token2, address token2,
uint256 setId uint256 setId
) external { )
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
token1 = changeEthAddrToWethAddr(token1);
token2 = changeEthAddrToWethAddr(token2);
(uint256 _pid, uint256 _version, ) = _getPoolId(token1, token2); (uint256 _pid, uint256 _version, ) = _getPoolId(token1, token2);
setUint(setId, _pid); setUint(setId, _pid);
require(_pid != uint256(-1), "pool-does-not-exist"); require(_pid != uint256(-1), "pool-does-not-exist");
(, uint256 rewardsAmount) = _getUserInfo(_pid, _version); (, uint256 rewardsAmount) = _getUserInfo(_pid, _version);
if (_version == 2) _harvest(_pid); if (_version == 2) _harvest(_pid);
else _withdraw(_pid, 0, _version); else _withdraw(_pid, 0, _version);
emit LogHarvest(address(this), _pid, _version, rewardsAmount); _eventName = "LogHarvest(uint256,uint256,uint256)";
_eventParam = abi.encode(_pid, _version, rewardsAmount);
} }
/** /**
* @dev withdraw LP token and harvest from masterChef * @dev withdraw LP token and harvest from masterChef
* @notice withdraw LP token and harvest from masterChef
* @param token1 token1 of LP token * @param token1 token1 of LP token
* @param token2 token2 of LP token * @param token2 token2 of LP token
* @param amount amount of LP token * @param amount amount of LP token
@ -96,24 +121,26 @@ abstract contract SushipswapIncentiveResolver is Helpers, Events {
uint256 amount, uint256 amount,
uint256 getId, uint256 getId,
uint256 setId uint256 setId
) external { )
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
token1 = changeEthAddrToWethAddr(token1);
token2 = changeEthAddrToWethAddr(token2);
amount = getUint(getId, amount); amount = getUint(getId, amount);
(uint256 _pid, uint256 _version, ) = _getPoolId(token1, token2); (uint256 _pid, uint256 _version, ) = _getPoolId(token1, token2);
setUint(setId, _pid); setUint(setId, _pid);
require(_pid != uint256(-1), "pool-does-not-exist"); require(_pid != uint256(-1), "pool-does-not-exist");
(, uint256 rewardsAmount) = _getUserInfo(_pid, _version); (, uint256 rewardsAmount) = _getUserInfo(_pid, _version);
_withdrawAndHarvest(_pid, amount, _version); _withdrawAndHarvest(_pid, amount, _version);
emit LogWithdrawAndHarvest( _eventName = "LogWithdrawAndHarvest(uint256,uint256,uint256,uint256)";
address(this), _eventParam = abi.encode(_pid, _version, amount, rewardsAmount);
_pid,
_version,
amount,
rewardsAmount
);
} }
/** /**
* @dev emergency withdraw from masterChef * @dev emergency withdraw from masterChef
* @notice emergency withdraw from masterChef
* @param token1 token1 deposited of LP token * @param token1 token1 deposited of LP token
* @param token2 token2 deposited LP token * @param token2 token2 deposited LP token
* @param setId ID stores Pool ID * @param setId ID stores Pool ID
@ -122,7 +149,13 @@ abstract contract SushipswapIncentiveResolver is Helpers, Events {
address token1, address token1,
address token2, address token2,
uint256 setId uint256 setId
) external { )
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
token1 = changeEthAddrToWethAddr(token1);
token2 = changeEthAddrToWethAddr(token2);
(uint256 _pid, uint256 _version, ) = _getPoolId(token1, token2); (uint256 _pid, uint256 _version, ) = _getPoolId(token1, token2);
setUint(setId, _pid); setUint(setId, _pid);
require(_pid != uint256(-1), "pool-does-not-exist"); require(_pid != uint256(-1), "pool-does-not-exist");
@ -131,13 +164,8 @@ abstract contract SushipswapIncentiveResolver is Helpers, Events {
_version _version
); );
_emergencyWithdraw(_pid, _version); _emergencyWithdraw(_pid, _version);
emit LogEmergencyWithdraw( _eventName = "LogEmergencyWithdraw(uint256,uint256,uint256,uint256)";
address(this), _eventParam = abi.encode(_pid, _version, lpAmount, rewardsAmount);
_pid,
_version,
lpAmount,
rewardsAmount
);
} }
} }