mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
minor fixes
This commit is contained in:
parent
650009f45e
commit
627e839c70
|
@ -41,6 +41,10 @@ abstract contract Basic is DSMath, Stores {
|
|||
_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 {
|
||||
if(isEth) token.deposit{value: amount}();
|
||||
}
|
||||
|
|
|
@ -2,32 +2,27 @@ pragma solidity ^0.7.0;
|
|||
|
||||
contract Events {
|
||||
event LogDeposit(
|
||||
address indexed user,
|
||||
uint256 indexed pid,
|
||||
uint256 indexed version,
|
||||
uint256 amount
|
||||
);
|
||||
event LogWithdraw(
|
||||
address indexed user,
|
||||
uint256 indexed pid,
|
||||
uint256 indexed version,
|
||||
uint256 amount
|
||||
);
|
||||
event LogEmergencyWithdraw(
|
||||
address indexed user,
|
||||
uint256 indexed pid,
|
||||
uint256 indexed version,
|
||||
uint256 lpAmount,
|
||||
uint256 rewardsAmount
|
||||
);
|
||||
event LogHarvest(
|
||||
address indexed user,
|
||||
uint256 indexed pid,
|
||||
uint256 indexed version,
|
||||
uint256 amount
|
||||
);
|
||||
event LogWithdrawAndHarvest(
|
||||
address indexed user,
|
||||
uint256 indexed pid,
|
||||
uint256 indexed version,
|
||||
uint256 widrawAmount,
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
pragma solidity ^0.7.0;
|
||||
pragma experimental ABIEncoderV2;
|
||||
import "./libraries/IERC20.sol";
|
||||
|
||||
struct UserInfo {
|
||||
uint256 amount;
|
||||
|
@ -14,6 +13,30 @@ struct PoolInfo {
|
|||
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 {
|
||||
function poolLength() external view returns (uint256);
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ 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
|
||||
|
@ -25,7 +26,13 @@ abstract contract SushipswapIncentiveResolver is Helpers, Events {
|
|||
uint256 amount,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external {
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
token1 = changeEthAddrToWethAddr(token1);
|
||||
token2 = changeEthAddrToWethAddr(token2);
|
||||
amount = getUint(getId, amount);
|
||||
(uint256 _pid, uint256 _version, address lpTokenAddr) = _getPoolId(
|
||||
token1,
|
||||
|
@ -36,11 +43,13 @@ abstract contract SushipswapIncentiveResolver is Helpers, Events {
|
|||
TokenInterface lpToken = TokenInterface(lpTokenAddr);
|
||||
lpToken.approve(address(masterChef), amount);
|
||||
_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
|
||||
* @notice withdraw LP token from masterChef
|
||||
* @param token1 token1 of LP token
|
||||
* @param token2 token2 of LP token
|
||||
* @param amount amount of LP token
|
||||
|
@ -53,17 +62,25 @@ abstract contract SushipswapIncentiveResolver is Helpers, Events {
|
|||
uint256 amount,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external {
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
token1 = changeEthAddrToWethAddr(token1);
|
||||
token2 = changeEthAddrToWethAddr(token2);
|
||||
amount = getUint(getId, amount);
|
||||
(uint256 _pid, uint256 _version, ) = _getPoolId(token1, token2);
|
||||
setUint(setId, _pid);
|
||||
require(_pid != uint256(-1), "pool-does-not-exist");
|
||||
_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
|
||||
* @notice harvest from masterChef
|
||||
* @param token1 token1 deposited of LP token
|
||||
* @param token2 token2 deposited LP token
|
||||
* @param setId ID stores Pool ID
|
||||
|
@ -72,18 +89,26 @@ abstract contract SushipswapIncentiveResolver is Helpers, Events {
|
|||
address token1,
|
||||
address token2,
|
||||
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);
|
||||
setUint(setId, _pid);
|
||||
require(_pid != uint256(-1), "pool-does-not-exist");
|
||||
(, uint256 rewardsAmount) = _getUserInfo(_pid, _version);
|
||||
if (_version == 2) _harvest(_pid);
|
||||
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
|
||||
* @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
|
||||
|
@ -96,24 +121,26 @@ abstract contract SushipswapIncentiveResolver is Helpers, Events {
|
|||
uint256 amount,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
) external {
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
token1 = changeEthAddrToWethAddr(token1);
|
||||
token2 = changeEthAddrToWethAddr(token2);
|
||||
amount = getUint(getId, amount);
|
||||
(uint256 _pid, uint256 _version, ) = _getPoolId(token1, token2);
|
||||
setUint(setId, _pid);
|
||||
require(_pid != uint256(-1), "pool-does-not-exist");
|
||||
(, uint256 rewardsAmount) = _getUserInfo(_pid, _version);
|
||||
_withdrawAndHarvest(_pid, amount, _version);
|
||||
emit LogWithdrawAndHarvest(
|
||||
address(this),
|
||||
_pid,
|
||||
_version,
|
||||
amount,
|
||||
rewardsAmount
|
||||
);
|
||||
_eventName = "LogWithdrawAndHarvest(uint256,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(_pid, _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
|
||||
|
@ -122,7 +149,13 @@ abstract contract SushipswapIncentiveResolver is Helpers, Events {
|
|||
address token1,
|
||||
address token2,
|
||||
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);
|
||||
setUint(setId, _pid);
|
||||
require(_pid != uint256(-1), "pool-does-not-exist");
|
||||
|
@ -131,13 +164,8 @@ abstract contract SushipswapIncentiveResolver is Helpers, Events {
|
|||
_version
|
||||
);
|
||||
_emergencyWithdraw(_pid, _version);
|
||||
emit LogEmergencyWithdraw(
|
||||
address(this),
|
||||
_pid,
|
||||
_version,
|
||||
lpAmount,
|
||||
rewardsAmount
|
||||
);
|
||||
_eventName = "LogEmergencyWithdraw(uint256,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(_pid, _version, lpAmount, rewardsAmount);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user