generated from foundry-rs/forge-template
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathPufferOracleV2.sol
151 lines (133 loc) · 4.59 KB
/
PufferOracleV2.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
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.0 <0.9.0;
import { IGuardianModule } from "puffer/interface/IGuardianModule.sol";
import { IPufferOracleV2 } from "puffer/interface/IPufferOracleV2.sol";
import { IPufferOracle } from "pufETH/interface/IPufferOracle.sol";
import { AccessManaged } from "@openzeppelin/contracts/access/manager/AccessManaged.sol";
/**
* @title PufferOracle
* @author Puffer Finance
* @custom:security-contact security@puffer.fi
*/
contract PufferOracleV2 is IPufferOracleV2, AccessManaged {
/**
* @dev Burst threshold
*/
uint256 internal constant _BURST_THRESHOLD = 22;
/**
* @notice Guardian Module
*/
IGuardianModule public immutable GUARDIAN_MODULE;
/**
* @notice Puffer Vault
*/
address payable public immutable PUFFER_VAULT;
/**
* @dev Number of active Puffer validators
* Slot 0
*/
uint256 internal _numberOfActivePufferValidators;
/**
* @dev Total number of Validators
* Slot 1
*/
uint256 internal _totalNumberOfValidators;
/**
* @dev Epoch number of the update
* Slot 2
*/
uint256 internal _epochNumber;
/**
* @dev Price in wei to mint one Validator Ticket
* Slot 3
*/
uint256 internal _validatorTicketPrice;
constructor(IGuardianModule guardianModule, address payable vault, address accessManager)
AccessManaged(accessManager)
{
GUARDIAN_MODULE = guardianModule;
PUFFER_VAULT = vault;
_totalNumberOfValidators = 927122; // Oracle will be updated with the correct value
_epochNumber = 268828; // Oracle will be updated with the correct value
_setMintPrice(0.01 ether);
}
/**
* @notice Exits the validator from the Beacon chain
* @dev Restricted to PufferProtocol contract
*/
function exitValidators(uint256 numberOfExits) public restricted {
_numberOfActivePufferValidators -= numberOfExits;
emit NumberOfActiveValidators(_numberOfActivePufferValidators);
}
/**
* @notice Increases the locked eth amount amount on the Oracle by 32 ETH
* It is called when the Beacon chain receives a new deposit from PufferProtocol
* The PufferVault balance is decreased by the same amount
* @dev Restricted to PufferProtocol contract
*/
function provisionNode() external restricted {
unchecked {
++_numberOfActivePufferValidators;
}
emit NumberOfActiveValidators(_numberOfActivePufferValidators);
}
/**
* @notice Updates the price to mint VT
* @param newPrice The new price to set for minting VT
* @dev Restricted to the DAO
*/
function setMintPrice(uint256 newPrice) external restricted {
_setMintPrice(newPrice);
}
/**
* @notice Updates the total number of validators
* @param newTotalNumberOfValidators The new number of validators
*/
function setTotalNumberOfValidators(
uint256 newTotalNumberOfValidators,
uint256 epochNumber,
bytes[] calldata guardianEOASignatures
) external restricted {
if (epochNumber <= _epochNumber) {
revert InvalidUpdate();
}
GUARDIAN_MODULE.validateTotalNumberOfValidators(newTotalNumberOfValidators, epochNumber, guardianEOASignatures);
emit TotalNumberOfValidatorsUpdated(_totalNumberOfValidators, newTotalNumberOfValidators, epochNumber);
_totalNumberOfValidators = newTotalNumberOfValidators;
_epochNumber = epochNumber;
}
/**
* @inheritdoc IPufferOracle
*/
function getLockedEthAmount() external view returns (uint256) {
return _numberOfActivePufferValidators * 32 ether;
}
/**
* @inheritdoc IPufferOracleV2
*/
function getTotalNumberOfValidators() external view returns (uint256) {
return _totalNumberOfValidators;
}
/**
* @inheritdoc IPufferOracle
*/
function isOverBurstThreshold() external view returns (bool) {
return ((_numberOfActivePufferValidators * 100 / _totalNumberOfValidators) > _BURST_THRESHOLD);
}
/**
* @inheritdoc IPufferOracle
*/
function getValidatorTicketPrice() external view returns (uint256) {
return _validatorTicketPrice;
}
/**
* @inheritdoc IPufferOracleV2
*/
function getNumberOfActiveValidators() external view returns (uint256) {
return _numberOfActivePufferValidators;
}
function _setMintPrice(uint256 newPrice) internal {
emit ValidatorTicketMintPriceUpdated(_validatorTicketPrice, newPrice);
_validatorTicketPrice = newPrice;
}
}