-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMoeStaking.sol
122 lines (103 loc) · 3.63 KB
/
MoeStaking.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {Math} from "./libraries/Math.sol";
import {Amounts} from "./libraries/Amounts.sol";
import {IMoe, IVeMoe, IStableMoe, IMoeStaking} from "./interfaces/IMoeStaking.sol";
/**
* @title Moe Staking Contract
* @dev The Moe Staking Contract allows users to stake MOE tokens to sMoe and veMoe.
* veMoe will allow users to vote on pool weights in the MasterChef contract.
* sMOE will allow users to receive rewards from the volume of the DEX.
*/
contract MoeStaking is IMoeStaking {
using SafeERC20 for IMoe;
using Math for uint256;
using Amounts for Amounts.Parameter;
IMoe private immutable _moe;
IVeMoe private immutable _veMoe;
IStableMoe private immutable _sMoe;
Amounts.Parameter private _amounts;
/**
* @dev Constructor for MoeStaking contract.
* @param moe The MOE token.
* @param veMoe The veMOE token.
* @param sMoe The sMOE token.
*/
constructor(IMoe moe, IVeMoe veMoe, IStableMoe sMoe) {
_moe = moe;
_veMoe = veMoe;
_sMoe = sMoe;
}
/**
* @dev Returns the MOE token.
* @return The MOE token.
*/
function getMoe() external view override returns (IMoe) {
return _moe;
}
/**
* @dev Returns the veMOE token.
* @return The veMOE token.
*/
function getVeMoe() external view override returns (IVeMoe) {
return _veMoe;
}
/**
* @dev Returns the sMOE token.
* @return The sMOE token.
*/
function getSMoe() external view override returns (IStableMoe) {
return _sMoe;
}
/**
* @dev Returns the amount of MOE tokens staked by an account.
* @param account The account to check.
* @return The amount of MOE tokens staked by the account.
*/
function getDeposit(address account) external view override returns (uint256) {
return _amounts.getAmountOf(account);
}
/**
* @dev Returns the total amount of MOE tokens staked.
* @return The total amount of MOE tokens staked.
*/
function getTotalDeposit() external view override returns (uint256) {
return _amounts.getTotalAmount();
}
/**
* @dev Stakes MOE tokens.
* @param amount The amount of MOE tokens to stake.
*/
function stake(uint256 amount) external override {
_modify(msg.sender, amount.toInt256());
if (amount > 0) _moe.safeTransferFrom(msg.sender, address(this), amount);
}
/**
* @dev Unstakes MOE tokens.
* @param amount The amount of MOE tokens to unstake.
*/
function unstake(uint256 amount) external override {
_modify(msg.sender, -amount.toInt256());
if (amount > 0) _moe.safeTransfer(msg.sender, amount);
}
/**
* @dev Claims rewards from veMOE and sMOE.
*/
function claim() external override {
_modify(msg.sender, 0);
}
/**
* @dev Modifies the staking position of an account.
* Will update the veMOE and sMOE positions of the account.
* @param account The account to modify.
* @param deltaAmount The delta amount to modify.
*/
function _modify(address account, int256 deltaAmount) private {
(uint256 oldBalance, uint256 newBalance, uint256 oldTotalSupply, uint256 newTotalSupply) =
_amounts.update(account, deltaAmount);
_veMoe.onModify(account, oldBalance, newBalance, oldTotalSupply, newTotalSupply);
_sMoe.onModify(account, oldBalance, newBalance, oldTotalSupply, newTotalSupply);
emit PositionModified(account, deltaAmount);
}
}