This repository has been archived by the owner on Mar 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
MaverickStakingAdapter.sol
84 lines (69 loc) · 2.95 KB
/
MaverickStakingAdapter.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// SPDX-License-Identifier: UNLICENSED
// Copyright (c) 2023 Tokemak Foundation. All rights reserved.
pragma solidity 0.8.17;
import { IERC20 } from "openzeppelin-contracts/token/ERC20/IERC20.sol";
import { IReward } from "src/interfaces/external/maverick/IReward.sol";
import { LibAdapter } from "src/libs/LibAdapter.sol";
import { Errors } from "src/utils/Errors.sol";
library MaverickStakingAdapter {
event DeployLiquidity(
address stakingToken,
// 0 - lpStakeAmount
// 1 - lpShare
// 2 - lpTotalSupply
uint256[3] lpAmounts,
address rewarder
);
event WithdrawLiquidity(
address stakingToken,
// 0 - lpUnstakeAmount
// 1 - lpShare
// 2 - lpTotalSupply
uint256[3] lpAmounts,
address rewarder
);
error InvalidBalanceChange();
/**
* @notice Stakes tokens from Maverick Reward contract
* @dev Calls to external contract. Should be guarded with
* non-reentrant flags in a used contract
* @param rewarder Maverick Reward contract
* @param amount quantity of staking token to deposit
*/
function stakeLPs(IReward rewarder, uint256 amount) public {
//slither-disable-start reentrancy-events
Errors.verifyNotZero(address(rewarder), "rewarder");
Errors.verifyNotZero(amount, "amount");
uint256 lpTokensBefore = rewarder.balanceOf(address(this));
address stakingToken = rewarder.stakingToken();
LibAdapter._approve(IERC20(stakingToken), address(rewarder), amount);
rewarder.stake(amount, address(this));
uint256 lpTokensAfter = rewarder.balanceOf(address(this));
if (lpTokensAfter - lpTokensBefore != amount) revert InvalidBalanceChange();
emit DeployLiquidity(
stakingToken, [amount, lpTokensAfter, IERC20(stakingToken).totalSupply()], address(rewarder)
);
//slither-disable-end reentrancy-events
}
/**
* @notice Unstakes tokens from Maverick Reward contract
* @dev Calls to external contract. Should be guarded with
* non-reentrant flags in a used contract
* @param rewarder Maverick Reward contract
* @param amount quantity of staking token to deposit
*/
function unstakeLPs(IReward rewarder, uint256 amount) public {
//slither-disable-start reentrancy-events
Errors.verifyNotZero(address(rewarder), "rewarder");
Errors.verifyNotZero(amount, "amount");
uint256 lpTokensBefore = rewarder.balanceOf(address(this));
address stakingToken = rewarder.stakingToken();
rewarder.unstake(amount, address(this));
uint256 lpTokensAfter = rewarder.balanceOf(address(this));
if (lpTokensBefore - lpTokensAfter != amount) revert InvalidBalanceChange();
emit WithdrawLiquidity(
stakingToken, [amount, lpTokensAfter, IERC20(stakingToken).totalSupply()], address(rewarder)
);
//slither-disable-end reentrancy-events
}
}