-
Notifications
You must be signed in to change notification settings - Fork 0
/
VStakerFactory.sol
109 lines (90 loc) · 3.05 KB
/
VStakerFactory.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
// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;
import "./VStaker.sol";
import "./interfaces/IVStakerFactory.sol";
contract VStakerFactory is IVStakerFactory {
// mapping of lp tokens to the corresponding staker
mapping(address => address) public stakers;
// list of all created stakers
address[] public allStakers;
// staker factory admin
address public override admin;
// staker factory pending admin
address public override pendingAdmin;
// VRSW token address
address public immutable vrswToken;
// chain minter address
address public immutable minter;
// tokenomics params address
address public immutable tokenomicsParams;
modifier onlyAdmin() {
require(msg.sender == admin, "OA");
_;
}
constructor(
address _vrswToken,
address _minter,
address _tokenomicsParams
) {
require(_minter != address(0), "minter zero address");
require(_vrswToken != address(0), "vrswToken zero address");
require(
_tokenomicsParams != address(0),
"tokenomicsParams zero address"
);
admin = msg.sender;
vrswToken = _vrswToken;
minter = _minter;
tokenomicsParams = _tokenomicsParams;
// create staker for VRSW staking (without lp tokens)
address staker = address(
new VStaker(address(0), vrswToken, minter, tokenomicsParams)
);
stakers[address(0)] = staker;
allStakers.push(staker);
}
/// @inheritdoc IVStakerFactory
function createPoolStaker(
address _lpToken
) external override onlyAdmin returns (address staker) {
require(_lpToken != address(0), "zero address");
require(stakers[_lpToken] == address(0), "staker exists");
staker = address(
new VStaker(_lpToken, vrswToken, minter, tokenomicsParams)
);
stakers[_lpToken] = staker;
allStakers.push(staker);
emit StakerCreated(staker, address(this), _lpToken);
}
/// @inheritdoc IVStakerFactory
function setPendingAdmin(
address newPendingAdmin
) external override onlyAdmin {
pendingAdmin = newPendingAdmin;
emit StakerFactoryNewPendingAdmin(newPendingAdmin);
}
/// @inheritdoc IVStakerFactory
function acceptAdmin() external override {
require(
msg.sender != address(0) && msg.sender == pendingAdmin,
"Only for pending admin"
);
admin = pendingAdmin;
pendingAdmin = address(0);
emit StakerFactoryNewAdmin(admin);
}
/// @inheritdoc IVStakerFactory
function getVRSWPoolStaker() external view override returns (address) {
return stakers[address(0)];
}
/// @inheritdoc IVStakerFactory
function getPoolStaker(
address _lpToken
) external view override returns (address) {
return stakers[_lpToken];
}
/// @inheritdoc IVStakerFactory
function getAllStakers() external view override returns (address[] memory) {
return allStakers;
}
}