-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathPartnerUtilityManager.sol
169 lines (139 loc) · 6.31 KB
/
PartnerUtilityManager.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {SafeTransferLib} from "solady/utils/SafeTransferLib.sol";
import {ERC20Votes, UtilityManager, IUtilityManager} from "@hermes/UtilityManager.sol";
import {IBaseVault} from "./interfaces/IBaseVault.sol";
import {IPartnerUtilityManager} from "./interfaces/IPartnerUtilityManager.sol";
/// @title Partner Utility Tokens Manager Contract
abstract contract PartnerUtilityManager is UtilityManager, IPartnerUtilityManager {
using SafeTransferLib for address;
/*//////////////////////////////////////////////////////////////
UTILITY MANAGER STATE
//////////////////////////////////////////////////////////////*/
/// @inheritdoc IPartnerUtilityManager
address public partnerVault;
/// @inheritdoc IPartnerUtilityManager
ERC20Votes public immutable partnerGovernance;
/// @inheritdoc IPartnerUtilityManager
mapping(address => uint256) public userClaimedPartnerGovernance;
/**
* @notice Constructs the Utility Manager Contract.
* @param _gaugeWeight The address of the weight gauge.
* @param _gaugeBoost The address of the boost gauge.
* @param _governance The address of the governance token.
* @param _partnerGovernance The address of the partner governance token.
* @param _partnerVault The address of the partner vault.
*/
constructor(
address _gaugeWeight,
address _gaugeBoost,
address _governance,
address _partnerGovernance,
address _partnerVault
) UtilityManager(_gaugeWeight, _gaugeBoost, _governance) {
partnerGovernance = ERC20Votes(_partnerGovernance);
partnerVault = _partnerVault;
}
/*///////////////////////////////////////////////////////////////
UTILITY TOKENS LOGIC
//////////////////////////////////////////////////////////////*/
/// @inheritdoc IUtilityManager
function forfeitMultiple(uint256 amount) public virtual override {
forfeitWeight(amount);
forfeitBoost(amount);
forfeitGovernance(amount);
forfeitPartnerGovernance(amount);
}
/// @inheritdoc IPartnerUtilityManager
function forfeitMultipleAmounts(uint256 weight, uint256 boost, uint256 _governance, uint256 _partnerGovernance)
public
virtual
{
forfeitWeight(weight);
forfeitBoost(boost);
forfeitGovernance(_governance);
forfeitPartnerGovernance(_partnerGovernance);
}
/// @inheritdoc IUtilityManager
function forfeitWeight(uint256 amount) public virtual override {
super.forfeitWeight(amount);
/// @dev Vault applies outstanding weight.
if (partnerVault != address(0) && address(gaugeWeight).balanceOf(address(this)) > 0) {
IBaseVault(partnerVault).applyWeight();
}
}
/// @inheritdoc IUtilityManager
function forfeitBoost(uint256 amount) public virtual override {
super.forfeitBoost(amount);
/// @dev Vault applies outstanding boost.
if (partnerVault != address(0) && address(gaugeBoost).balanceOf(address(this)) > 0) {
IBaseVault(partnerVault).applyBoost();
}
}
/// @inheritdoc IUtilityManager
function forfeitGovernance(uint256 amount) public virtual override {
super.forfeitGovernance(amount);
/// @dev Vault applies outstanding governance.
if (partnerVault != address(0) && address(governance).balanceOf(address(this)) > 0) {
IBaseVault(partnerVault).applyGovernance();
}
}
/// @inheritdoc IPartnerUtilityManager
function forfeitPartnerGovernance(uint256 amount) public {
userClaimedPartnerGovernance[msg.sender] -= amount;
/// @dev partnerGovernance is kept in this contract and not sent to vaults to avoid governance attacks.
address(partnerGovernance).safeTransferFrom(msg.sender, address(this), amount);
}
/// @inheritdoc IUtilityManager
function claimMultiple(uint256 amount) public virtual override {
claimWeight(amount);
claimBoost(amount);
claimGovernance(amount);
claimPartnerGovernance(amount);
}
/// @inheritdoc IPartnerUtilityManager
function claimMultipleAmounts(uint256 weight, uint256 boost, uint256 _governance, uint256 _partnerGovernance)
public
virtual
{
claimWeight(weight);
claimBoost(boost);
claimGovernance(_governance);
claimPartnerGovernance(_partnerGovernance);
}
/// @inheritdoc IUtilityManager
function claimWeight(uint256 amount) public virtual override checkWeight(amount) {
uint256 weightAvailable = address(gaugeWeight).balanceOf(address(this));
/// @dev Must transfer weight amount to this manager address.
if (weightAvailable < amount) {
IBaseVault(partnerVault).clearWeight(amount - weightAvailable);
}
super.claimWeight(amount);
}
/// @inheritdoc IUtilityManager
function claimBoost(uint256 amount) public virtual override checkBoost(amount) {
uint256 boostAvailable = address(gaugeBoost).balanceOf(address(this));
/// @dev Must transfer boost amount to this manager address.
if (boostAvailable < amount) IBaseVault(partnerVault).clearBoost(amount - boostAvailable);
super.claimBoost(amount);
}
/// @inheritdoc IUtilityManager
function claimGovernance(uint256 amount) public virtual override checkGovernance(amount) {
uint256 governanceAvailable = address(governance).balanceOf(address(this));
/// @dev Must transfer governance amount to this manager address.
if (governanceAvailable < amount) {
IBaseVault(partnerVault).clearGovernance(amount - governanceAvailable);
}
super.claimGovernance(amount);
}
/// @inheritdoc IPartnerUtilityManager
function claimPartnerGovernance(uint256 amount) public checkPartnerGovernance(amount) {
userClaimedPartnerGovernance[msg.sender] += amount;
address(partnerGovernance).safeTransfer(msg.sender, amount);
}
/*///////////////////////////////////////////////////////////////
MODIFIERS
//////////////////////////////////////////////////////////////*/
/// @dev Checks available governance allows for call.
modifier checkPartnerGovernance(uint256 amount) virtual;
}