Skip to content

Commit ddaf3b0

Browse files
authored
Mutliownable presets (#79)
* added presets * refactored names * versions * scope fix * fix name
1 parent c373d30 commit ddaf3b0

24 files changed

+434
-165
lines changed

contracts/contracts-registry/pools/AbstractPoolContractsRegistry.sol

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ import {ProxyBeacon} from "./proxy/ProxyBeacon.sol";
2020
* The registry uses BeaconProxy pattern to provide upgradeability and Dependant pattern to provide dependency
2121
* injection mechanism into the pools. This module should be used together with the ContractsRegistry module.
2222
*
23-
* The users of this module have to override `_onlyPoolFactory()` method and revert in case a wrong msg.sender is
24-
* trying to add pools into the registry.
25-
*
2623
* The contract is meant to be used behind a proxy itself.
2724
*/
2825
abstract contract AbstractPoolContractsRegistry is Initializable, AbstractDependant {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.4;
3+
4+
import {AbstractPoolContractsRegistry} from "../AbstractPoolContractsRegistry.sol";
5+
import {MultiOwnable} from "../../../access-control/MultiOwnable.sol";
6+
7+
/**
8+
* @notice The MultiOwnable preset of PoolContractsRegistry
9+
*/
10+
abstract contract MultiOwnablePoolContractsRegistry is
11+
AbstractPoolContractsRegistry,
12+
MultiOwnable
13+
{
14+
function __MultiOwnablePoolContractsRegistry_init() public initializer {
15+
__MultiOwnable_init();
16+
__PoolContractsRegistry_init();
17+
}
18+
19+
function setNewImplementations(
20+
string[] calldata names_,
21+
address[] calldata newImplementations_
22+
) external onlyOwner {
23+
_setNewImplementations(names_, newImplementations_);
24+
}
25+
26+
function injectDependenciesToExistingPools(
27+
string calldata name_,
28+
uint256 offset_,
29+
uint256 limit_
30+
) external onlyOwner {
31+
_injectDependenciesToExistingPools(name_, offset_, limit_);
32+
}
33+
34+
function injectDependenciesToExistingPoolsWithData(
35+
string calldata name_,
36+
bytes calldata data_,
37+
uint256 offset_,
38+
uint256 limit_
39+
) external onlyOwner {
40+
_injectDependenciesToExistingPoolsWithData(name_, data_, offset_, limit_);
41+
}
42+
43+
function addProxyPool(string memory name_, address poolAddress_) public virtual;
44+
}

contracts/contracts-registry/pools/presets/OwnablePoolContractsRegistry.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,6 @@ abstract contract OwnablePoolContractsRegistry is
4040
) external onlyOwner {
4141
_injectDependenciesToExistingPoolsWithData(name_, data_, offset_, limit_);
4242
}
43+
44+
function addProxyPool(string memory name_, address poolAddress_) public virtual;
4345
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.4;
3+
4+
import {AbstractContractsRegistry} from "../AbstractContractsRegistry.sol";
5+
import {MultiOwnable} from "../../access-control/MultiOwnable.sol";
6+
7+
/**
8+
* @notice The MultiOwnable preset of ContractsRegistry
9+
*/
10+
contract MultiOwnableContractsRegistry is AbstractContractsRegistry, MultiOwnable {
11+
function __MultiOwnableContractsRegistry_init() public initializer {
12+
__MultiOwnable_init();
13+
__ContractsRegistry_init();
14+
}
15+
16+
function injectDependencies(string calldata name_) external onlyOwner {
17+
_injectDependencies(name_);
18+
}
19+
20+
function injectDependenciesWithData(
21+
string calldata name_,
22+
bytes calldata data_
23+
) external onlyOwner {
24+
_injectDependenciesWithData(name_, data_);
25+
}
26+
27+
function upgradeContract(
28+
string calldata name_,
29+
address newImplementation_
30+
) external onlyOwner {
31+
_upgradeContract(name_, newImplementation_);
32+
}
33+
34+
function upgradeContractAndCall(
35+
string calldata name_,
36+
address newImplementation_,
37+
bytes calldata data_
38+
) external onlyOwner {
39+
_upgradeContractAndCall(name_, newImplementation_, data_);
40+
}
41+
42+
function addContract(string calldata name_, address contractAddress_) external onlyOwner {
43+
_addContract(name_, contractAddress_);
44+
}
45+
46+
function addProxyContract(string calldata name_, address contractAddress_) external onlyOwner {
47+
_addProxyContract(name_, contractAddress_);
48+
}
49+
50+
function addProxyContractAndCall(
51+
string calldata name_,
52+
address contractAddress_,
53+
bytes calldata data_
54+
) external onlyOwner {
55+
_addProxyContractAndCall(name_, contractAddress_, data_);
56+
}
57+
58+
function justAddProxyContract(
59+
string calldata name_,
60+
address contractAddress_
61+
) external onlyOwner {
62+
_justAddProxyContract(name_, contractAddress_);
63+
}
64+
65+
function removeContract(string calldata name_) external onlyOwner {
66+
_removeContract(name_);
67+
}
68+
}

contracts/mock/contracts-registry/ContractsRegistry1.sol renamed to contracts/mock/contracts-registry/ContractsRegistryMock.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ pragma solidity ^0.8.4;
33

44
import {OwnableContractsRegistry} from "../../contracts-registry/presets/OwnableContractsRegistry.sol";
55

6-
contract ContractsRegistry1 is OwnableContractsRegistry {
7-
string public constant CRDEPENDANT_NAME = "CRDEPENDANT";
6+
contract ContractsRegistryMock is OwnableContractsRegistry {
7+
string public constant DEPENDANT_NAME = "DEPENDANT";
88
string public constant TOKEN_NAME = "TOKEN";
99

1010
function mockInit() external {
1111
__ContractsRegistry_init();
1212
}
1313

14-
function getCRDependantContract() external view returns (address) {
15-
return getContract(CRDEPENDANT_NAME);
14+
function getDependantContract() external view returns (address) {
15+
return getContract(DEPENDANT_NAME);
1616
}
1717

1818
function getTokenContract() external view returns (address) {

contracts/mock/contracts-registry/CRDependant.sol renamed to contracts/mock/contracts-registry/DependantMock.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ pragma solidity ^0.8.4;
33

44
import {AbstractDependant} from "../../contracts-registry/AbstractDependant.sol";
55

6-
import {ContractsRegistry1} from "./ContractsRegistry1.sol";
6+
import {ContractsRegistryMock} from "./ContractsRegistryMock.sol";
77

8-
contract CRDependant is AbstractDependant {
8+
contract DependantMock is AbstractDependant {
99
address public token;
1010

1111
function setDependencies(address contractsRegistry_, bytes memory) public override dependant {
12-
token = ContractsRegistry1(contractsRegistry_).getTokenContract();
12+
token = ContractsRegistryMock(contractsRegistry_).getTokenContract();
1313
}
1414
}

contracts/mock/contracts-registry/CRDependantUpgrade.sol renamed to contracts/mock/contracts-registry/DependantUpgradeMock.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.4;
33

4-
import {CRDependant} from "./CRDependant.sol";
4+
import {DependantMock} from "./DependantMock.sol";
55

6-
contract CRDependantUpgrade is CRDependant {
6+
contract DependantUpgradeMock is DependantMock {
77
uint256 public dummyValue;
88

99
function doUpgrade(uint256 value_) external {

contracts/mock/contracts-registry/pools/ContractsRegistry2.sol renamed to contracts/mock/contracts-registry/pools/ContractsRegistryPoolMock.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pragma solidity ^0.8.4;
33

44
import {OwnableContractsRegistry} from "../../../contracts-registry/presets/OwnableContractsRegistry.sol";
55

6-
contract ContractsRegistry2 is OwnableContractsRegistry {
6+
contract ContractsRegistryPoolMock is OwnableContractsRegistry {
77
string public constant POOL_CONTRACTS_REGISTRY_NAME = "POOL_CONTRACTS_REGISTRY";
88
string public constant POOL_FACTORY_NAME = "POOL_FACTORY";
99
string public constant TOKEN_NAME = "TOKEN";

contracts/mock/contracts-registry/pools/PoolContractsRegistry.sol renamed to contracts/mock/contracts-registry/pools/PoolContractsRegistryMock.sol

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.4;
33

4-
import {ContractsRegistry2} from "./ContractsRegistry2.sol";
4+
import {ContractsRegistryPoolMock} from "./ContractsRegistryPoolMock.sol";
55

66
import {OwnablePoolContractsRegistry} from "../../../contracts-registry/pools/presets/OwnablePoolContractsRegistry.sol";
77

8-
contract PoolContractsRegistry is OwnablePoolContractsRegistry {
8+
contract PoolContractsRegistryMock is OwnablePoolContractsRegistry {
99
string public constant POOL_1_NAME = "POOL_1";
1010
string public constant POOL_2_NAME = "POOL_2";
1111

@@ -23,10 +23,13 @@ contract PoolContractsRegistry is OwnablePoolContractsRegistry {
2323
function setDependencies(address contractsRegistry_, bytes memory data_) public override {
2424
super.setDependencies(contractsRegistry_, data_);
2525

26-
_poolFactory = ContractsRegistry2(contractsRegistry_).getPoolFactoryContract();
26+
_poolFactory = ContractsRegistryPoolMock(contractsRegistry_).getPoolFactoryContract();
2727
}
2828

29-
function addProxyPool(string calldata name_, address poolAddress_) external onlyPoolFactory {
29+
function addProxyPool(
30+
string memory name_,
31+
address poolAddress_
32+
) public override onlyPoolFactory {
3033
_addProxyPool(name_, poolAddress_);
3134
}
3235
}

contracts/mock/contracts-registry/pools/Pool.sol renamed to contracts/mock/contracts-registry/pools/PoolMock.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ pragma solidity ^0.8.4;
33

44
import {AbstractDependant} from "../../../contracts-registry/AbstractDependant.sol";
55

6-
import {ContractsRegistry2} from "./ContractsRegistry2.sol";
6+
import {ContractsRegistryPoolMock} from "./ContractsRegistryPoolMock.sol";
77

8-
contract Pool is AbstractDependant {
8+
contract PoolMock is AbstractDependant {
99
address public token;
1010

1111
function setDependencies(address contractsRegistry_, bytes memory) public override dependant {
12-
token = ContractsRegistry2(contractsRegistry_).getTokenContract();
12+
token = ContractsRegistryPoolMock(contractsRegistry_).getTokenContract();
1313
}
1414
}

0 commit comments

Comments
 (0)