Skip to content

Commit fbc62db

Browse files
committed
Merge branch 'release/v1.0.0-rc.2'
2 parents b91983a + 6006168 commit fbc62db

19 files changed

+1844
-1113
lines changed

contracts/access/Roles.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity >=0.5.0 <0.9.0;
3+
4+
library Roles {
5+
bytes32 public constant ADMIN = keccak256("ADMIN_ROLE");
6+
7+
bytes32 public constant ORACLE_UPDATER = keccak256("ORACLE_UPDATER_ROLE");
8+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//SPDX-License-Identifier: MIT
2+
pragma solidity =0.8.11;
3+
4+
import "@pythia-oracle/pythia-core/contracts/accumulators/proto/curve/CurveLiquidityAccumulator.sol";
5+
6+
import "@openzeppelin-v4/contracts/access/AccessControl.sol";
7+
8+
import "../../../access/Roles.sol";
9+
10+
contract ManagedCurveLiquidityAccumulator is AccessControl, CurveLiquidityAccumulator {
11+
constructor(
12+
address curvePool_,
13+
uint8 nCoins_,
14+
address quoteToken_,
15+
uint256 updateTheshold_,
16+
uint256 minUpdateDelay_,
17+
uint256 maxUpdateDelay_
18+
) CurveLiquidityAccumulator(curvePool_, nCoins_, quoteToken_, updateTheshold_, minUpdateDelay_, maxUpdateDelay_) {
19+
initializeRoles();
20+
}
21+
22+
/**
23+
* @notice Modifier to make a function callable only by a certain role. In
24+
* addition to checking the sender's role, `address(0)` 's role is also
25+
* considered. Granting a role to `address(0)` is equivalent to enabling
26+
* this role for everyone.
27+
*/
28+
29+
modifier onlyRoleOrOpenRole(bytes32 role) {
30+
if (!hasRole(role, address(0))) {
31+
require(hasRole(role, msg.sender), "ManagedCurveLiquidityAccumulator: MISSING_ROLE");
32+
}
33+
_;
34+
}
35+
36+
function supportsInterface(bytes4 interfaceId)
37+
public
38+
view
39+
virtual
40+
override(AccessControl, LiquidityAccumulator)
41+
returns (bool)
42+
{
43+
return interfaceId == type(IAccessControl).interfaceId || LiquidityAccumulator.supportsInterface(interfaceId);
44+
}
45+
46+
function initializeRoles() internal virtual {
47+
// Setup admin role, setting msg.sender as admin
48+
_setupRole(Roles.ADMIN, msg.sender);
49+
_setRoleAdmin(Roles.ADMIN, Roles.ADMIN);
50+
51+
// Set admin of ORACLE_UPDATER as ADMIN
52+
_setRoleAdmin(Roles.ORACLE_UPDATER, Roles.ADMIN);
53+
}
54+
55+
function _update(address token) internal virtual override onlyRoleOrOpenRole(Roles.ORACLE_UPDATER) returns (bool) {
56+
return super._update(token);
57+
}
58+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//SPDX-License-Identifier: MIT
2+
pragma solidity =0.8.11;
3+
4+
import "@pythia-oracle/pythia-core/contracts/accumulators/proto/curve/CurvePriceAccumulator.sol";
5+
6+
import "@openzeppelin-v4/contracts/access/AccessControl.sol";
7+
8+
import "../../../access/Roles.sol";
9+
10+
contract ManagedCurvePriceAccumulator is AccessControl, CurvePriceAccumulator {
11+
constructor(
12+
address curvePool_,
13+
int8 nCoins_,
14+
address quoteToken_,
15+
uint256 updateTheshold_,
16+
uint256 minUpdateDelay_,
17+
uint256 maxUpdateDelay_
18+
) CurvePriceAccumulator(curvePool_, nCoins_, quoteToken_, updateTheshold_, minUpdateDelay_, maxUpdateDelay_) {
19+
initializeRoles();
20+
}
21+
22+
/**
23+
* @notice Modifier to make a function callable only by a certain role. In
24+
* addition to checking the sender's role, `address(0)` 's role is also
25+
* considered. Granting a role to `address(0)` is equivalent to enabling
26+
* this role for everyone.
27+
*/
28+
29+
modifier onlyRoleOrOpenRole(bytes32 role) {
30+
if (!hasRole(role, address(0))) {
31+
require(hasRole(role, msg.sender), "ManagedCurvePriceAccumulator: MISSING_ROLE");
32+
}
33+
_;
34+
}
35+
36+
function supportsInterface(bytes4 interfaceId)
37+
public
38+
view
39+
virtual
40+
override(AccessControl, PriceAccumulator)
41+
returns (bool)
42+
{
43+
return interfaceId == type(IAccessControl).interfaceId || PriceAccumulator.supportsInterface(interfaceId);
44+
}
45+
46+
function initializeRoles() internal virtual {
47+
// Setup admin role, setting msg.sender as admin
48+
_setupRole(Roles.ADMIN, msg.sender);
49+
_setRoleAdmin(Roles.ADMIN, Roles.ADMIN);
50+
51+
// Set admin of ORACLE_UPDATER as ADMIN
52+
_setRoleAdmin(Roles.ORACLE_UPDATER, Roles.ADMIN);
53+
}
54+
55+
function _update(address token) internal virtual override onlyRoleOrOpenRole(Roles.ORACLE_UPDATER) returns (bool) {
56+
return super._update(token);
57+
}
58+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//SPDX-License-Identifier: MIT
2+
pragma solidity =0.8.11;
3+
4+
import "@pythia-oracle/pythia-core/contracts/accumulators/proto/uniswap/UniswapV2LiquidityAccumulator.sol";
5+
6+
import "@openzeppelin-v4/contracts/access/AccessControl.sol";
7+
8+
import "../../../access/Roles.sol";
9+
10+
contract ManagedUniswapV2LiquidityAccumulator is AccessControl, UniswapV2LiquidityAccumulator {
11+
constructor(
12+
address uniswapFactory_,
13+
bytes32 initCodeHash_,
14+
address quoteToken_,
15+
uint256 updateTheshold_,
16+
uint256 minUpdateDelay_,
17+
uint256 maxUpdateDelay_
18+
)
19+
UniswapV2LiquidityAccumulator(
20+
uniswapFactory_,
21+
initCodeHash_,
22+
quoteToken_,
23+
updateTheshold_,
24+
minUpdateDelay_,
25+
maxUpdateDelay_
26+
)
27+
{
28+
initializeRoles();
29+
}
30+
31+
/**
32+
* @notice Modifier to make a function callable only by a certain role. In
33+
* addition to checking the sender's role, `address(0)` 's role is also
34+
* considered. Granting a role to `address(0)` is equivalent to enabling
35+
* this role for everyone.
36+
*/
37+
38+
modifier onlyRoleOrOpenRole(bytes32 role) {
39+
if (!hasRole(role, address(0))) {
40+
require(hasRole(role, msg.sender), "ManagedUniswapV2LiquidityAccumulator: MISSING_ROLE");
41+
}
42+
_;
43+
}
44+
45+
function supportsInterface(bytes4 interfaceId)
46+
public
47+
view
48+
virtual
49+
override(AccessControl, LiquidityAccumulator)
50+
returns (bool)
51+
{
52+
return interfaceId == type(IAccessControl).interfaceId || LiquidityAccumulator.supportsInterface(interfaceId);
53+
}
54+
55+
function initializeRoles() internal virtual {
56+
// Setup admin role, setting msg.sender as admin
57+
_setupRole(Roles.ADMIN, msg.sender);
58+
_setRoleAdmin(Roles.ADMIN, Roles.ADMIN);
59+
60+
// Set admin of ORACLE_UPDATER as ADMIN
61+
_setRoleAdmin(Roles.ORACLE_UPDATER, Roles.ADMIN);
62+
}
63+
64+
function _update(address token) internal virtual override onlyRoleOrOpenRole(Roles.ORACLE_UPDATER) returns (bool) {
65+
return super._update(token);
66+
}
67+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//SPDX-License-Identifier: MIT
2+
pragma solidity =0.8.11;
3+
4+
import "@pythia-oracle/pythia-core/contracts/accumulators/proto/uniswap/UniswapV3LiquidityAccumulator.sol";
5+
6+
import "@openzeppelin-v4/contracts/access/AccessControl.sol";
7+
8+
import "../../../access/Roles.sol";
9+
10+
contract ManagedUniswapV3LiquidityAccumulator is AccessControl, UniswapV3LiquidityAccumulator {
11+
constructor(
12+
address uniswapFactory_,
13+
bytes32 initCodeHash_,
14+
uint24[] memory poolFees_,
15+
address quoteToken_,
16+
uint256 updateTheshold_,
17+
uint256 minUpdateDelay_,
18+
uint256 maxUpdateDelay_
19+
)
20+
UniswapV3LiquidityAccumulator(
21+
uniswapFactory_,
22+
initCodeHash_,
23+
poolFees_,
24+
quoteToken_,
25+
updateTheshold_,
26+
minUpdateDelay_,
27+
maxUpdateDelay_
28+
)
29+
{
30+
initializeRoles();
31+
}
32+
33+
/**
34+
* @notice Modifier to make a function callable only by a certain role. In
35+
* addition to checking the sender's role, `address(0)` 's role is also
36+
* considered. Granting a role to `address(0)` is equivalent to enabling
37+
* this role for everyone.
38+
*/
39+
40+
modifier onlyRoleOrOpenRole(bytes32 role) {
41+
if (!hasRole(role, address(0))) {
42+
require(hasRole(role, msg.sender), "ManagedUniswapV3LiquidityAccumulator: MISSING_ROLE");
43+
}
44+
_;
45+
}
46+
47+
function supportsInterface(bytes4 interfaceId)
48+
public
49+
view
50+
virtual
51+
override(AccessControl, LiquidityAccumulator)
52+
returns (bool)
53+
{
54+
return interfaceId == type(IAccessControl).interfaceId || LiquidityAccumulator.supportsInterface(interfaceId);
55+
}
56+
57+
function initializeRoles() internal virtual {
58+
// Setup admin role, setting msg.sender as admin
59+
_setupRole(Roles.ADMIN, msg.sender);
60+
_setRoleAdmin(Roles.ADMIN, Roles.ADMIN);
61+
62+
// Set admin of ORACLE_UPDATER as ADMIN
63+
_setRoleAdmin(Roles.ORACLE_UPDATER, Roles.ADMIN);
64+
}
65+
66+
function _update(address token) internal virtual override onlyRoleOrOpenRole(Roles.ORACLE_UPDATER) returns (bool) {
67+
return super._update(token);
68+
}
69+
}

contracts/oracles/ManagedPeriodicAccumulationOracle.sol

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,56 @@ pragma solidity =0.8.11;
33

44
import "@pythia-oracle/pythia-core/contracts/oracles/PeriodicAccumulationOracle.sol";
55

6-
import "@openzeppelin-v4/contracts/access/Ownable.sol";
6+
import "@openzeppelin-v4/contracts/access/AccessControl.sol";
77

8-
contract ManagedPeriodicAccumulationOracle is Ownable, PeriodicAccumulationOracle {
8+
import "../access/Roles.sol";
9+
10+
contract ManagedPeriodicAccumulationOracle is AccessControl, PeriodicAccumulationOracle {
911
constructor(
1012
address liquidityAccumulator_,
1113
address priceAccumulator_,
1214
address quoteToken_,
1315
uint256 period_
14-
) PeriodicAccumulationOracle(liquidityAccumulator_, priceAccumulator_, quoteToken_, period_) {}
16+
) PeriodicAccumulationOracle(liquidityAccumulator_, priceAccumulator_, quoteToken_, period_) {
17+
initializeRoles();
18+
}
19+
20+
/**
21+
* @notice Modifier to make a function callable only by a certain role. In
22+
* addition to checking the sender's role, `address(0)` 's role is also
23+
* considered. Granting a role to `address(0)` is equivalent to enabling
24+
* this role for everyone.
25+
*/
26+
27+
modifier onlyRoleOrOpenRole(bytes32 role) {
28+
if (!hasRole(role, address(0))) {
29+
require(hasRole(role, msg.sender), "ManagedPeriodicAccumulationOracle: MISSING_ROLE");
30+
}
31+
_;
32+
}
33+
34+
function supportsInterface(bytes4 interfaceId)
35+
public
36+
view
37+
virtual
38+
override(AccessControl, PeriodicAccumulationOracle)
39+
returns (bool)
40+
{
41+
return
42+
interfaceId == type(IAccessControl).interfaceId ||
43+
PeriodicAccumulationOracle.supportsInterface(interfaceId);
44+
}
45+
46+
function initializeRoles() internal virtual {
47+
// Setup admin role, setting msg.sender as admin
48+
_setupRole(Roles.ADMIN, msg.sender);
49+
_setRoleAdmin(Roles.ADMIN, Roles.ADMIN);
50+
51+
// Set admin of ORACLE_UPDATER as ADMIN
52+
_setRoleAdmin(Roles.ORACLE_UPDATER, Roles.ADMIN);
53+
}
1554

16-
function _update(address token) internal virtual override onlyOwner returns (bool) {
55+
function _update(address token) internal virtual override onlyRoleOrOpenRole(Roles.ORACLE_UPDATER) returns (bool) {
1756
return super._update(token);
1857
}
1958
}

contracts/oracles/proto/uniswap/ManagedUniswapV2Oracle.sol

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,55 @@ pragma solidity =0.8.11;
33

44
import "@pythia-oracle/pythia-core/contracts/oracles/proto/uniswap/UniswapV2Oracle.sol";
55

6-
import "@openzeppelin-v4/contracts/access/Ownable.sol";
6+
import "@openzeppelin-v4/contracts/access/AccessControl.sol";
77

8-
contract ManagedUniswapV2Oracle is Ownable, UniswapV2Oracle {
8+
import "../../../access/Roles.sol";
9+
10+
contract ManagedUniswapV2Oracle is AccessControl, UniswapV2Oracle {
911
constructor(
1012
address liquidityAccumulator_,
1113
address uniswapFactory_,
1214
bytes32 initCodeHash_,
1315
address quoteToken_,
1416
uint256 period_
15-
) UniswapV2Oracle(liquidityAccumulator_, uniswapFactory_, initCodeHash_, quoteToken_, period_) {}
17+
) UniswapV2Oracle(liquidityAccumulator_, uniswapFactory_, initCodeHash_, quoteToken_, period_) {
18+
initializeRoles();
19+
}
20+
21+
/**
22+
* @notice Modifier to make a function callable only by a certain role. In
23+
* addition to checking the sender's role, `address(0)` 's role is also
24+
* considered. Granting a role to `address(0)` is equivalent to enabling
25+
* this role for everyone.
26+
*/
27+
28+
modifier onlyRoleOrOpenRole(bytes32 role) {
29+
if (!hasRole(role, address(0))) {
30+
require(hasRole(role, msg.sender), "ManagedUniswapV2Oracle: MISSING_ROLE");
31+
}
32+
_;
33+
}
34+
35+
function supportsInterface(bytes4 interfaceId)
36+
public
37+
view
38+
virtual
39+
override(AccessControl, UniswapV2Oracle)
40+
returns (bool)
41+
{
42+
return interfaceId == type(IAccessControl).interfaceId || UniswapV2Oracle.supportsInterface(interfaceId);
43+
}
44+
45+
function initializeRoles() internal virtual {
46+
// Setup admin role, setting msg.sender as admin
47+
_setupRole(Roles.ADMIN, msg.sender);
48+
_setRoleAdmin(Roles.ADMIN, Roles.ADMIN);
49+
50+
// Set admin of ORACLE_UPDATER as ADMIN
51+
_setRoleAdmin(Roles.ORACLE_UPDATER, Roles.ADMIN);
52+
}
1653

17-
function _update(address token) internal virtual override onlyOwner returns (bool) {
54+
function _update(address token) internal virtual override onlyRoleOrOpenRole(Roles.ORACLE_UPDATER) returns (bool) {
1855
return super._update(token);
1956
}
2057
}

0 commit comments

Comments
 (0)