Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add common interface for viewing pending rewards. Minor warnings and … #20

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions VampireAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ library VampireAdapter {
return abi.decode(result, (uint256));
}

function pendingReward(Victim victim, uint256 poolId) external view returns (uint256) {
// note the impersonation
(bool success, bytes memory result) = address(victim).staticcall(abi.encodeWithSignature("pendingReward(uint256)", poolId));
require(success, "pendingReward(uint256 poolId) staticcall failed.");
return abi.decode(result, (uint256));
}

// Pool actions
function deposit(Victim victim, uint256 poolId, uint256 amount) external {
(bool success,) = address(victim).delegatecall(abi.encodeWithSignature("deposit(address,uint256,uint256)", address(victim), poolId, amount));
Expand All @@ -57,17 +64,17 @@ library VampireAdapter {
(bool success,) = address(victim).delegatecall(abi.encodeWithSignature("withdraw(address,uint256,uint256)", address(victim), poolId, amount));
require(success, "withdraw(uint256 poolId, uint256 amount) delegatecall failed.");
}

function claimReward(Victim victim, uint256 poolId) external {
(bool success,) = address(victim).delegatecall(abi.encodeWithSignature("claimReward(address,uint256)", address(victim), poolId));
require(success, "claimReward(uint256 poolId) delegatecall failed.");
}

function emergencyWithdraw(Victim victim, uint256 poolId) external {
(bool success,) = address(victim).delegatecall(abi.encodeWithSignature("emergencyWithdraw(address,uint256)", address(victim), poolId));
require(success, "emergencyWithdraw(uint256 poolId) delegatecall failed.");
}

// Service methods
function poolAddress(Victim victim, uint256 poolId) external view returns (address) {
(bool success, bytes memory result) = address(victim).staticcall(abi.encodeWithSignature("poolAddress(uint256)", poolId));
Expand All @@ -80,4 +87,4 @@ library VampireAdapter {
require(success, "rewardToWethPool() staticcall failed.");
return abi.decode(result, (address));
}
}
}
6 changes: 6 additions & 0 deletions adapters/dodo/DODOAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ contract DODOAdapter is IVampireAdapter {
using SafeERC20 for IERC20;

IDrainController constant DRAIN_CONTROLLER = IDrainController(0x2e813f2e524dB699d279E631B0F2117856eb902C);
address constant MASTER_VAMPIRE = 0xD12d68Fd52b54908547ebC2Cd77Ec6EbbEfd3099;
IUniswapV2Pair constant WETH_USDT_PAIR = IUniswapV2Pair(0x0d4a11d5EEaaC28EC3F61d100daF4d40471f1852);
IDODOMine constant DODO_MINE = IDODOMine(0xaeD7384F03844Af886b830862FF0a7AFce0a632C);
IDODO constant DODO_USDT = IDODO(0x8876819535b48b551C9e97EBc07332C7482b4b2d);
Expand Down Expand Up @@ -66,6 +67,11 @@ contract DODOAdapter is IVampireAdapter {
return amount;
}

function pendingReward(uint256 poolId) external view override returns (uint256) {
(address lpToken,,,) = DODO_MINE.poolInfos(poolId);
return DODO_MINE.getPendingReward(lpToken, MASTER_VAMPIRE);
}

// Pool actions, requires impersonation via delegatecall
function deposit(address _adapter, uint256 poolId, uint256 amount) external override {
IVampireAdapter adapter = IVampireAdapter(_adapter);
Expand Down
1 change: 1 addition & 0 deletions adapters/lua/ILuaMasterFarmer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ interface ILuaMasterFarmer{
function withdraw(uint256 _pid, uint256 _amount) external;
function claimReward(uint256 _pid) external;
function emergencyWithdraw(uint256 _pid) external;
function pendingReward(uint256 _pid, address _user) external view returns (uint256);
}
11 changes: 7 additions & 4 deletions adapters/lua/LuaAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ import "./ILuaMasterFarmer.sol";
contract LuaAdapter is IVampireAdapter {
IDrainController constant drainController = IDrainController(0x2e813f2e524dB699d279E631B0F2117856eb902C);
ILuaMasterFarmer constant luaMasterFarmer = ILuaMasterFarmer(0xb67D7a6644d9E191Cac4DA2B88D6817351C7fF62);
address constant MASTER_VAMPIRE = 0xD12d68Fd52b54908547ebC2Cd77Ec6EbbEfd3099;
IUniswapV2Router02 constant router = IUniswapV2Router02(0x1d5C6F1607A171Ad52EFB270121331b3039dD83e);
IERC20 constant lua = IERC20(0xB1f66997A5760428D3a87D68b90BfE0aE64121cC);
IERC20 constant weth = IERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);

constructor() public {}

// Victim info
function rewardToken() external override view returns (IERC20) {
return lua;
Expand All @@ -45,7 +44,7 @@ contract LuaAdapter is IVampireAdapter {
path[1] = address(weth);
uint[] memory amounts = router.getAmountsOut(rewardAmount, path);
lua.approve(address(router), uint256(-1));
amounts = router.swapExactTokensForTokens(rewardAmount, amounts[amounts.length - 1], path, to, block.timestamp );
amounts = router.swapExactTokensForTokens(rewardAmount, amounts[amounts.length - 1], path, to, block.timestamp);
return amounts[amounts.length - 1];
}

Expand All @@ -70,6 +69,10 @@ contract LuaAdapter is IVampireAdapter {
return amount;
}

function pendingReward(uint256 poolId) external view override returns (uint256) {
return luaMasterFarmer.pendingReward(poolId, MASTER_VAMPIRE);
}

// Pool actions, requires impersonation via delegatecall
function deposit(
address _adapter,
Expand Down Expand Up @@ -111,7 +114,7 @@ contract LuaAdapter is IVampireAdapter {
}

function totalLockedValue(uint256) external override view returns (uint256) {
require(false, "not implemented");
require(false, "not implemented");
}

function normalizedAPY(uint256) external override view returns (uint256) {
Expand Down
2 changes: 1 addition & 1 deletion adapters/pickle/IMasterChef.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface IMasterChef{
function poolInfo(uint256) external view returns (IERC20,uint256,uint256,uint256);
function userInfo(uint256, address) external view returns (uint256,uint256);
function poolLength() external view returns (uint256);
function pendingSushi(uint256 _pid, address _user) external view returns (uint256);
function pendingPickle(uint256 _pid, address _user) external view returns (uint256);
function deposit(uint256 _pid, uint256 _amount) external;
function withdraw(uint256 _pid, uint256 _amount) external;
function emergencyWithdraw(uint256 _pid) external;
Expand Down
30 changes: 16 additions & 14 deletions adapters/pickle/PickleAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ import "./IMasterChef.sol";
contract PickleAdapter is IVampireAdapter {
IDrainController constant drainController = IDrainController(0x2e813f2e524dB699d279E631B0F2117856eb902C);
IMasterChef constant pickleMasterChef = IMasterChef(0xbD17B1ce622d73bD438b9E658acA5996dc394b0d);
address constant MASTER_VAMPIRE = 0xD12d68Fd52b54908547ebC2Cd77Ec6EbbEfd3099;
IERC20 constant pickle = IERC20(0x429881672B9AE42b8EbA0E26cD9C73711b891Ca5);
IERC20 constant weth = IERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
IUniswapV2Pair constant pickleWethPair = IUniswapV2Pair(0xdc98556Ce24f007A5eF6dC1CE96322d65832A819);
// token 0 - pickle
// token 1 - weth

constructor() public {
}

// Victim info
function rewardToken() external view override returns (IERC20) {
return pickle;
Expand All @@ -34,7 +32,7 @@ contract PickleAdapter is IVampireAdapter {
function sellableRewardAmount() external view override returns (uint256) {
return uint256(-1);
}

// Victim actions, requires impersonation via delegatecall
function sellRewardForWeth(address, uint256 rewardAmount, address to) external override returns(uint256) {
require(drainController.priceIsUnderRejectionTreshold(), "Possible price manipulation, drain rejected");
Expand All @@ -44,7 +42,7 @@ contract PickleAdapter is IVampireAdapter {
pickleWethPair.swap(uint(0), amountOutput, to, new bytes(0));
return amountOutput;
}

// Pool info
function lockableToken(uint256 poolId) external view override returns (IERC20) {
(IERC20 lpToken,,,) = pickleMasterChef.poolInfo(poolId);
Expand All @@ -55,26 +53,30 @@ contract PickleAdapter is IVampireAdapter {
(uint256 amount,) = pickleMasterChef.userInfo(poolId, user);
return amount;
}


function pendingReward(uint256 poolId) external view override returns (uint256) {
return pickleMasterChef.pendingPickle(poolId, MASTER_VAMPIRE);
}

// Pool actions, requires impersonation via delegatecall
function deposit(address _adapter, uint256 poolId, uint256 amount) external override {
IVampireAdapter adapter = IVampireAdapter(_adapter);
adapter.lockableToken(poolId).approve(address(pickleMasterChef), uint256(-1));
pickleMasterChef.deposit( poolId, amount);
pickleMasterChef.deposit(poolId, amount);
}

function withdraw(address, uint256 poolId, uint256 amount) external override {
pickleMasterChef.withdraw( poolId, amount);
pickleMasterChef.withdraw(poolId, amount);
}

function claimReward(address, uint256 poolId) external override {
pickleMasterChef.deposit( poolId, 0);
pickleMasterChef.deposit(poolId, 0);
}

function emergencyWithdraw(address, uint256 poolId) external override {
pickleMasterChef.emergencyWithdraw(poolId);
}

// Service methods
function poolAddress(uint256) external view override returns (address) {
return address(pickleMasterChef);
Expand All @@ -83,13 +85,13 @@ contract PickleAdapter is IVampireAdapter {
function rewardToWethPool() external view override returns (address) {
return address(pickleWethPair);
}

function lockedValue(address, uint256) external override view returns (uint256) {
require(false, "not implemented");
}
}

function totalLockedValue(uint256) external override view returns (uint256) {
require(false, "not implemented");
require(false, "not implemented");
}

function normalizedAPY(uint256) external override view returns (uint256) {
Expand Down
1 change: 1 addition & 0 deletions adapters/sake/ISakeMaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ interface ISakeMaster{
function deposit(uint256 _pid, uint256 _amount) external;
function withdraw(uint256 _pid, uint256 _amount) external;
function emergencyWithdraw(uint256 _pid) external;
function pendingSake(uint256 _pid, address _user) external view returns (uint256);
}
5 changes: 5 additions & 0 deletions adapters/sake/SakeAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import "./ISakeMaster.sol";

contract SakeAdapter is IVampireAdapter {
IDrainController constant DRAIN_CONTROLLER = IDrainController(0x2e813f2e524dB699d279E631B0F2117856eb902C);
address constant MASTER_VAMPIRE = 0xD12d68Fd52b54908547ebC2Cd77Ec6EbbEfd3099;
ISakeMaster constant SAKE_MASTER = ISakeMaster(0x0EC1f1573f3a2dB0Ad396c843E6a079e2a53e557);
IERC20 constant SAKE = IERC20(0x066798d9ef0833ccc719076Dab77199eCbd178b0);
IERC20 constant WETH = IERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
Expand Down Expand Up @@ -52,6 +53,10 @@ contract SakeAdapter is IVampireAdapter {
return amount;
}

function pendingReward(uint256 poolId) external view override returns (uint256) {
return SAKE_MASTER.pendingSake(poolId, MASTER_VAMPIRE);
}

// Pool actions, requires impersonation via delegatecall
function deposit(address _adapter, uint256 poolId, uint256 amount) external override {
IVampireAdapter adapter = IVampireAdapter(_adapter);
Expand Down
1 change: 1 addition & 0 deletions adapters/sashimi/IMasterChef.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ interface IMasterChef{
function deposit(uint256 _pid, uint256 _amount) external;
function withdraw(uint256 _pid, uint256 _amount) external;
function emergencyWithdraw(uint256 _pid) external;
function pendingSashimi(uint256 _pid, address _user) external view returns (uint256);
}
5 changes: 5 additions & 0 deletions adapters/sashimi/SashimiAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import "./IMasterChef.sol";

contract SashimiAdapter is IVampireAdapter {
IDrainController constant DRAIN_CONTROLLER = IDrainController(0x2e813f2e524dB699d279E631B0F2117856eb902C);
address constant MASTER_VAMPIRE = 0xD12d68Fd52b54908547ebC2Cd77Ec6EbbEfd3099;
IMasterChef constant SASHIMI_MASTERCHEF = IMasterChef(0x1DaeD74ed1dD7C9Dabbe51361ac90A69d851234D);
IUniswapV2Router02 constant router = IUniswapV2Router02(0xe4FE6a45f354E845F954CdDeE6084603CEDB9410);
IERC20 constant SASHIMI = IERC20(0xC28E27870558cF22ADD83540d2126da2e4b464c2);
Expand Down Expand Up @@ -51,6 +52,10 @@ contract SashimiAdapter is IVampireAdapter {
return amount;
}

function pendingReward(uint256 poolId) external view override returns (uint256) {
return SASHIMI_MASTERCHEF.pendingSashimi(poolId, MASTER_VAMPIRE);
}

// Pool actions, requires impersonation via delegatecall
function deposit(address _adapter, uint256 poolId, uint256 amount) external override {
IVampireAdapter adapter = IVampireAdapter(_adapter);
Expand Down
1 change: 1 addition & 0 deletions adapters/strudel/ITorchShip.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ interface ITorchShip{
function getMultiplier(uint256 _from, uint256 _to) external view returns (uint256);
function strudelPerBlock() external view returns (uint256);
function totalAllocPoint() external view returns (uint256);
function pendingStrudel(uint256 _pid, address _user) external view returns (uint256);
}
20 changes: 11 additions & 9 deletions adapters/strudel/StrudelAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import "./ITorchShip.sol";
contract StrudelAdapter is IVampireAdapter {
using SafeMath for uint256;
IDrainController constant drainController = IDrainController(0x2e813f2e524dB699d279E631B0F2117856eb902C);
address constant MASTER_VAMPIRE = 0xD12d68Fd52b54908547ebC2Cd77Ec6EbbEfd3099;
ITorchShip constant strudelTorchShip = ITorchShip(0x517b091FdB87A42c879BbB849444E76A324D53c8);
IERC20 constant strudel = IERC20(0x297D33e17e61C2Ddd812389C2105193f8348188a);
IERC20 constant weth = IERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
Expand All @@ -22,9 +23,6 @@ contract StrudelAdapter is IVampireAdapter {
// token 0 - strudel
// token 1 - weth

constructor() public {
}

// Victim info
function rewardToken() external view override returns (IERC20) {
return strudel;
Expand Down Expand Up @@ -59,6 +57,10 @@ contract StrudelAdapter is IVampireAdapter {
return amount;
}

function pendingReward(uint256 poolId) external view override returns (uint256) {
return strudelTorchShip.pendingStrudel(poolId, MASTER_VAMPIRE);
}

// Pool actions, requires impersonation via delegatecall
function deposit(address _adapter, uint256 poolId, uint256 amount) external override {
IVampireAdapter adapter = IVampireAdapter(_adapter);
Expand All @@ -67,11 +69,11 @@ contract StrudelAdapter is IVampireAdapter {
}

function withdraw(address, uint256 poolId, uint256 amount) external override {
strudelTorchShip.withdraw( poolId, amount);
strudelTorchShip.withdraw(poolId, amount);
}

function claimReward(address, uint256 poolId) external override {
strudelTorchShip.deposit( poolId, 0);
strudelTorchShip.deposit(poolId, 0);
}

function emergencyWithdraw(address, uint256 poolId) external override {
Expand All @@ -91,15 +93,15 @@ contract StrudelAdapter is IVampireAdapter {
(uint256 token0Reserve, uint256 token1Reserve,) = lpToken.getReserves();
address token0 = lpToken.token0();
address token1 = lpToken.token1();
if(token0 == address(weth)) {
if (token0 == address(weth)) {
return amount.mul(token0Reserve).mul(2).div(lpToken.totalSupply());
}

if(token1 == address(weth)) {
if (token1 == address(weth)) {
return amount.mul(token1Reserve).mul(2).div(lpToken.totalSupply());
}

if(IUniswapV2Factory(lpToken.factory()).getPair(token0, address(weth)) != address(0)) {
if (IUniswapV2Factory(lpToken.factory()).getPair(token0, address(weth)) != address(0)) {
(uint256 wethReserve, uint256 token0ToWethReserve) = UniswapV2Library.getReserves(lpToken.factory(), address(weth), token0);
uint256 tmp = amount.mul(token0Reserve).mul(wethReserve).mul(2);
return tmp.div(token0ToWethReserve).div(lpToken.totalSupply());
Expand All @@ -120,7 +122,7 @@ contract StrudelAdapter is IVampireAdapter {

function totalLockedValue(uint256 poolId) external override view returns (uint256) {
StrudelAdapter adapter = StrudelAdapter(this);
IUniswapV2Pair lockedToken = IUniswapV2Pair(address(adapter.lockableToken(poolId))) ;
IUniswapV2Pair lockedToken = IUniswapV2Pair(address(adapter.lockableToken(poolId)));
return adapter.lpTokenValue(lockedToken.balanceOf(adapter.poolAddress(poolId)), lockedToken);
}

Expand Down
1 change: 1 addition & 0 deletions adapters/sushi/IMasterChef.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ interface IMasterChef{
function getMultiplier(uint256 _from, uint256 _to) external view returns (uint256);
function sushiPerBlock() external view returns (uint256);
function totalAllocPoint() external view returns (uint256);
function pendingSushi(uint256 _pid, address _user) external view returns (uint256);
}
Loading