Skip to content

Commit 8c4a3d7

Browse files
committed
pod abstract code
1 parent 9950088 commit 8c4a3d7

14 files changed

+492
-508
lines changed

script/deployOracle.s.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ contract deployOracleScript is Script {
4949
BLSApkRegistry.initialize.selector,
5050
deployerAddress,
5151
relayerManagerAddr,
52-
proxyOracleManager
52+
address(proxyOracleManager)
5353
)
5454
);
5555

script/deployOraclePod.s.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.so
88

99
import { EmptyContract } from "../src/utils/EmptyContract.sol";
1010
import { OraclePod } from "../src/pod/OraclePod.sol";
11+
import { OracleManager } from "../src/core/OracleManager.sol";
12+
1113
import { IOracleManager } from "../src/interfaces/IOracleManager.sol";
1214
import { IOraclePod } from "../src/interfaces/IOraclePod.sol";
1315

@@ -45,7 +47,7 @@ contract deployOraclePodScript is Script {
4547
)
4648
);
4749

48-
IOracleManager(oracleManagerAddr).addOraclePodToFillWhitelist(IOraclePod(address(proxyOraclePod)));
50+
// OracleManager(oracleManagerAddr).addOraclePodToFillWhitelist(proxyOraclePod);
4951

5052

5153
console.log("deploy proxyOraclePod:", address(proxyOraclePod));

src/core/EventManager.sol

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,37 @@ import "../interfaces/IBLSApkRegistry.sol";
99
import "../interfaces/IEventPod.sol";
1010

1111
import "./EventManagerStorage.sol";
12+
import "./PodManager.sol";
1213

13-
contract EventManager is OwnableUpgradeable, EventManagerStorage {
14-
constructor(){
1514

15+
contract EventManager is OwnableUpgradeable, PodManager, EventManagerStorage {
16+
constructor() {
17+
_disableInitializers();
18+
}
19+
20+
function initialize(
21+
address _initialOwner,
22+
address _blsApkRegistry,
23+
address _aggregatorAddress
24+
) external initializer {
25+
__Ownable_init(_initialOwner);
26+
__PodManager_init(_blsApkRegistry, _aggregatorAddress);
27+
}
28+
29+
function fillEventResultWithSignature(
30+
IEventPod eventPod,
31+
PredictEvents calldata predictEvents,
32+
IBLSApkRegistry.OracleNonSignerAndSignature memory oracleNonSignerAndSignature
33+
) external onlyAggregatorManager onlyPodWhitelistedForFill(address(eventPod)) {
34+
(
35+
uint256 totalStaking,
36+
bytes32 signatoryRecordHash
37+
) = blsApkRegistry.checkSignatures(predictEvents.msgHash, predictEvents.blockNumber, oracleNonSignerAndSignature);
38+
39+
string memory winner = predictEvents.winner;
40+
41+
eventPod.submitEventResult(predictEvents.requestId, predictEvents.winner);
42+
43+
emit VerifyPredictEventSig(predictEvents.requestId, totalStaking, signatoryRecordHash, winner);
1644
}
1745
}

src/core/OracleManager.sol

Lines changed: 4 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,9 @@ import "../interfaces/IBLSApkRegistry.sol";
99
import "../interfaces/IOraclePod.sol";
1010

1111
import "./OracleManagerStorage.sol";
12+
import "./PodManager.sol";
1213

13-
contract OracleManager is OwnableUpgradeable, OracleManagerStorage, IOracleManager {
14-
modifier onlyAggregatorManager() {
15-
require(
16-
msg.sender == aggregatorAddress,
17-
"OracleManager.onlyOracleWhiteListManager: not the aggregator address"
18-
);
19-
_;
20-
}
21-
22-
modifier onlyPodWhitelistedForFill(IOraclePod oraclePod) {
23-
require(
24-
podIsWhitelistedForFill[oraclePod],
25-
"OracleManager.onlyPodWhitelistedForFill: oraclePod not whitelisted"
26-
);
27-
_;
28-
}
29-
14+
contract OracleManager is OwnableUpgradeable, PodManager, OracleManagerStorage, IOracleManager {
3015
constructor() {
3116
_disableInitializers();
3217
}
@@ -37,34 +22,15 @@ contract OracleManager is OwnableUpgradeable, OracleManagerStorage, IOracleManag
3722
address _aggregatorAddress
3823
) external initializer {
3924
__Ownable_init(_initialOwner);
40-
blsApkRegistry = IBLSApkRegistry(_blsApkRegistry);
41-
aggregatorAddress = _aggregatorAddress;
25+
__PodManager_init(_blsApkRegistry, _aggregatorAddress);
4226
confirmBatchId = 0;
4327
}
4428

45-
function registerOperator(string calldata nodeUrl) external {
46-
require(
47-
operatorWhitelist[msg.sender],
48-
"OracleManager.registerOperator: this address have not permission to register "
49-
);
50-
blsApkRegistry.registerOperator(msg.sender);
51-
emit OperatorRegistered(msg.sender, nodeUrl);
52-
}
53-
54-
function deRegisterOperator() external {
55-
require(
56-
operatorWhitelist[msg.sender],
57-
"OracleManager.registerOperator: this address have not permission to register "
58-
);
59-
blsApkRegistry.deregisterOperator(msg.sender);
60-
emit OperatorDeRegistered(msg.sender);
61-
}
62-
6329
function fillSymbolPriceWithSignature(
6430
IOraclePod oraclePod,
6531
OracleBatch calldata oracleBatch,
6632
IBLSApkRegistry.OracleNonSignerAndSignature memory oracleNonSignerAndSignature
67-
) external onlyAggregatorManager onlyPodWhitelistedForFill(oraclePod) {
33+
) external onlyAggregatorManager onlyPodWhitelistedForFill(address(oraclePod)) {
6834
(
6935
uint256 totalStaking,
7036
bytes32 signatoryRecordHash
@@ -76,30 +42,4 @@ contract OracleManager is OwnableUpgradeable, OracleManagerStorage, IOracleManag
7642

7743
emit VerifyOracleSig(confirmBatchId++, totalStaking, signatoryRecordHash, symbolPrice);
7844
}
79-
80-
function addOrRemoveOperatorWhitelist(address operator, bool isAdd) external onlyAggregatorManager {
81-
require(
82-
operator != address (0),
83-
"OracleManager.addOperatorWhitelist: operator address is zero"
84-
);
85-
operatorWhitelist[operator] = isAdd;
86-
}
87-
88-
function setAggregatorAddress(address _aggregatorAddress) external onlyOwner {
89-
require(
90-
_aggregatorAddress != address (0),
91-
"OracleManager.addAggregator: aggregatorAddress address is zero"
92-
);
93-
aggregatorAddress = _aggregatorAddress;
94-
}
95-
96-
function addOraclePodToFillWhitelist(IOraclePod oraclePod) external onlyAggregatorManager {
97-
podIsWhitelistedForFill[oraclePod] = true;
98-
emit OraclePodAddedToFillWhitelist(oraclePod);
99-
}
100-
101-
function removeOraclePodToFillWhitelist(IOraclePod oraclePod) external onlyAggregatorManager {
102-
podIsWhitelistedForFill[oraclePod] = false;
103-
emit OraclePodRemoveToFillWhitelist(oraclePod);
104-
}
10545
}

src/core/OracleManagerStorage.sol

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,5 @@ import "../interfaces/IOraclePod.sol";
88

99

1010
abstract contract OracleManagerStorage is Initializable {
11-
IBLSApkRegistry public blsApkRegistry;
12-
1311
uint256 public confirmBatchId;
14-
15-
address public aggregatorAddress;
16-
17-
mapping(IOraclePod => bool) public podIsWhitelistedForFill;
18-
mapping(address => bool) public operatorWhitelist;
1912
}

src/core/PodManager.sol

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.0;
3+
4+
import "@openzeppelin-upgrades/contracts/proxy/utils/Initializable.sol";
5+
import "@openzeppelin-upgrades/contracts/access/OwnableUpgradeable.sol";
6+
7+
import "../interfaces/IBLSApkRegistry.sol";
8+
9+
10+
abstract contract PodManager is Initializable, OwnableUpgradeable {
11+
IBLSApkRegistry public blsApkRegistry;
12+
13+
address public aggregatorAddress;
14+
15+
mapping(address => bool) public podIsWhitelistedForFill;
16+
mapping(address => bool) public operatorWhitelist;
17+
18+
event OperatorRegistered(address indexed operator, string nodeUrl);
19+
event OperatorDeRegistered(address operator);
20+
event PodAddedToFillWhitelist(address pod);
21+
event PodRemoveToFillWhitelist(address pod);
22+
23+
modifier onlyAggregatorManager() {
24+
require(
25+
msg.sender == aggregatorAddress,
26+
"PodManager.onlyAggregatorManager: not the aggregator address"
27+
);
28+
_;
29+
}
30+
31+
modifier onlyPodWhitelistedForFill(address pod) {
32+
require(
33+
podIsWhitelistedForFill[pod],
34+
"PodManager.onlyPodWhitelistedForFill: pod not whitelisted"
35+
);
36+
_;
37+
}
38+
39+
function __PodManager_init(
40+
address _blsApkRegistry,
41+
address _aggregatorAddress
42+
) internal {
43+
blsApkRegistry = IBLSApkRegistry(_blsApkRegistry);
44+
aggregatorAddress = _aggregatorAddress;
45+
}
46+
47+
function registerOperator(string calldata nodeUrl) external {
48+
require(
49+
operatorWhitelist[msg.sender],
50+
"PodManager.registerOperator: this address have not permission to register "
51+
);
52+
blsApkRegistry.registerOperator(msg.sender);
53+
emit OperatorRegistered(msg.sender, nodeUrl);
54+
}
55+
56+
function deRegisterOperator() external {
57+
require(
58+
operatorWhitelist[msg.sender],
59+
"PodManager.registerOperator: this address have not permission to register "
60+
);
61+
blsApkRegistry.deregisterOperator(msg.sender);
62+
emit OperatorDeRegistered(msg.sender);
63+
}
64+
65+
function addOrRemoveOperatorWhitelist(address operator, bool isAdd) external onlyAggregatorManager {
66+
require(
67+
operator != address (0),
68+
"PodManager.addOperatorWhitelist: operator address is zero"
69+
);
70+
operatorWhitelist[operator] = isAdd;
71+
}
72+
73+
function setAggregatorAddress(address _aggregatorAddress) external onlyOwner {
74+
require(
75+
_aggregatorAddress != address (0),
76+
"PodManager.addAggregator: aggregatorAddress address is zero"
77+
);
78+
aggregatorAddress = _aggregatorAddress;
79+
}
80+
81+
function addOraclePodToFillWhitelist(address pod) external onlyAggregatorManager {
82+
podIsWhitelistedForFill[pod] = true;
83+
emit PodAddedToFillWhitelist(pod);
84+
}
85+
86+
function removeOraclePodToFillWhitelist(address pod) external onlyAggregatorManager {
87+
podIsWhitelistedForFill[pod] = false;
88+
emit PodRemoveToFillWhitelist(pod);
89+
}
90+
}

src/core/VrfManager.sol

Lines changed: 4 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,11 @@ import "../interfaces/IVrfManager.sol";
88
import "../interfaces/IBLSApkRegistry.sol";
99
import "../interfaces/IVrfPod.sol";
1010

11+
import "./PodManager.sol";
1112
import "./VrfManagerStorage.sol";
1213

13-
contract VrfManager is OwnableUpgradeable, VrfManagerStorage {
14-
modifier onlyAggregatorManager() {
15-
require(
16-
msg.sender == aggregatorAddress,
17-
"VrfManager.onlyAggregatorManager: not the aggregator address"
18-
);
19-
_;
20-
}
21-
22-
modifier onlyPodWhitelistedForFill(IVrfPod vrfPod) {
23-
require(
24-
podIsWhitelistedForFill[vrfPod],
25-
"VrfManager.onlyPodWhitelistedForFill: vrfPod not whitelisted"
26-
);
27-
_;
28-
}
2914

15+
contract VrfManager is OwnableUpgradeable, PodManager, VrfManagerStorage {
3016
constructor() {
3117
_disableInitializers();
3218
}
@@ -37,33 +23,14 @@ contract VrfManager is OwnableUpgradeable, VrfManagerStorage {
3723
address _aggregatorAddress
3824
) external initializer {
3925
__Ownable_init(_initialOwner);
40-
blsApkRegistry = IBLSApkRegistry(_blsApkRegistry);
41-
aggregatorAddress = _aggregatorAddress;
42-
}
43-
44-
function registerOperator(string calldata nodeUrl) external {
45-
require(
46-
operatorWhitelist[msg.sender],
47-
"VrfManager.registerOperator: this address have not permission to register "
48-
);
49-
blsApkRegistry.registerOperator(msg.sender);
50-
emit OperatorRegistered(msg.sender, nodeUrl);
51-
}
52-
53-
function deRegisterOperator() external {
54-
require(
55-
operatorWhitelist[msg.sender],
56-
"VrfManager.registerOperator: this address have not permission to register "
57-
);
58-
blsApkRegistry.deregisterOperator(msg.sender);
59-
emit OperatorDeRegistered(msg.sender);
26+
__PodManager_init(_blsApkRegistry, _aggregatorAddress);
6027
}
6128

6229
function fillRandWordsWithSignature(
6330
IVrfPod vrfPod,
6431
VrfRandomWords calldata vrfRandomWords,
6532
IBLSApkRegistry.OracleNonSignerAndSignature memory oracleNonSignerAndSignature
66-
) external onlyAggregatorManager onlyPodWhitelistedForFill(vrfPod) {
33+
) external onlyAggregatorManager onlyPodWhitelistedForFill(address(vrfPod)) {
6734
(
6835
uint256 totalStaking,
6936
bytes32 signatoryRecordHash
@@ -73,30 +40,4 @@ contract VrfManager is OwnableUpgradeable, VrfManagerStorage {
7340

7441
emit VerifyVrfSig(vrfRandomWords.requestId, totalStaking, signatoryRecordHash, vrfRandomWords._randomWords);
7542
}
76-
77-
function addOrRemoveOperatorWhitelist(address operator, bool isAdd) external onlyAggregatorManager {
78-
require(
79-
operator != address (0),
80-
"OracleManager.addOperatorWhitelist: operator address is zero"
81-
);
82-
operatorWhitelist[operator] = isAdd;
83-
}
84-
85-
function setAggregatorAddress(address _aggregatorAddress) external onlyOwner {
86-
require(
87-
_aggregatorAddress != address (0),
88-
"OracleManager.addAggregator: aggregatorAddress address is zero"
89-
);
90-
aggregatorAddress = _aggregatorAddress;
91-
}
92-
93-
function addVrfPodToFillWhitelist(IVrfPod vrfPod) external onlyAggregatorManager {
94-
podIsWhitelistedForFill[vrfPod] = true;
95-
emit VrfPodAddedToFillWhitelist(vrfPod);
96-
}
97-
98-
function removeVrfPodToFillWhitelist(IVrfPod vrfPod) external onlyAggregatorManager {
99-
podIsWhitelistedForFill[vrfPod] = false;
100-
emit VrfPodRemoveToFillWhitelist(vrfPod);
101-
}
10243
}

src/core/VrfManagerStorage.sol

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,5 @@ import "../interfaces/IVrfManager.sol";
99

1010

1111
abstract contract VrfManagerStorage is Initializable, IVrfManager{
12-
IBLSApkRegistry public blsApkRegistry;
1312

14-
address public aggregatorAddress;
15-
16-
mapping(IVrfPod => bool) public podIsWhitelistedForFill;
17-
mapping(address => bool) public operatorWhitelist;
1813
}

src/interfaces/IEventManager.sol

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,18 @@
22
pragma solidity ^0.8.20;
33

44
interface IEventManager {
5+
event VerifyPredictEventSig(
6+
uint256 requestId,
7+
uint256 totalStaking,
8+
bytes32 signatoryRecordHash,
9+
string winner
10+
);
511

12+
struct PredictEvents{
13+
uint256 requestId;
14+
string winner;
15+
bytes32 blockHash;
16+
uint256 blockNumber;
17+
bytes32 msgHash;
18+
}
619
}

0 commit comments

Comments
 (0)