Skip to content

Commit c123c2b

Browse files
authored
Feat/clarity (#81)
* cleaned up PCR * versions * slight refactoring * visibility * typo
1 parent 1036c39 commit c123c2b

File tree

16 files changed

+116
-76
lines changed

16 files changed

+116
-76
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
# Solidity Library for Savvies by Distributed Lab
99

10-
The library consists of modules and utilities that are built with a help of [Openzeppelin Contracts](https://github.com/OpenZeppelin/openzeppelin-contracts) (4.9.2) and **go far beyond mediocre solidity**.
10+
The library consists of modules and utilities that are built with a help of [Openzeppelin Contracts](https://github.com/OpenZeppelin/openzeppelin-contracts) (4.9.5) and **go far beyond mediocre solidity**.
1111

1212
- Implementation of [**Contracts Registry**](https://eips.ethereum.org/EIPS/eip-6224) pattern
1313
- Versatile **RBAC** and **MultiOwnable** smart contracts

contracts/contracts-registry/AbstractContractsRegistry.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pragma solidity ^0.8.4;
44
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
55
import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
66

7-
import {ProxyUpgrader} from "./proxy/ProxyUpgrader.sol";
7+
import {TransparentProxyUpgrader} from "../proxy/transparent/TransparentProxyUpgrader.sol";
88
import {AbstractDependant} from "./AbstractDependant.sol";
99

1010
/**
@@ -36,7 +36,7 @@ import {AbstractDependant} from "./AbstractDependant.sol";
3636
* The management is simplified because all of the contracts are now located in a single place.
3737
*/
3838
abstract contract AbstractContractsRegistry is Initializable {
39-
ProxyUpgrader private _proxyUpgrader;
39+
TransparentProxyUpgrader private _proxyUpgrader;
4040

4141
mapping(string => address) private _contracts;
4242
mapping(address => bool) private _isProxy;
@@ -50,7 +50,7 @@ abstract contract AbstractContractsRegistry is Initializable {
5050
* @notice The proxy initializer function
5151
*/
5252
function __ContractsRegistry_init() internal onlyInitializing {
53-
_proxyUpgrader = new ProxyUpgrader();
53+
_proxyUpgrader = new TransparentProxyUpgrader();
5454
}
5555

5656
/**

contracts/contracts-registry/pools/AbstractPoolContractsRegistry.sol

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {Paginator} from "../../libs/arrays/Paginator.sol";
99

1010
import {AbstractDependant} from "../../contracts-registry/AbstractDependant.sol";
1111

12-
import {ProxyBeacon} from "./proxy/ProxyBeacon.sol";
12+
import {ProxyBeacon} from "../../proxy/beacon/ProxyBeacon.sol";
1313

1414
/**
1515
* @notice The PoolContractsRegistry module
@@ -48,6 +48,16 @@ abstract contract AbstractPoolContractsRegistry is Initializable, AbstractDepend
4848
_contractsRegistry = contractsRegistry_;
4949
}
5050

51+
/**
52+
* @notice The function to add new pools into the registry. Gets called from PoolFactory
53+
*
54+
* Proper only factory access control must be added in descending contracts + `_addProxyPool()` should be called inside.
55+
*
56+
* @param name_ the pool's associated name
57+
* @param poolAddress_ the proxy address of the pool
58+
*/
59+
function addProxyPool(string memory name_, address poolAddress_) public virtual;
60+
5161
/**
5262
* @notice The function to get implementation of the specific pools
5363
* @param name_ the name of the pools

contracts/contracts-registry/pools/pool-factory/AbstractPoolFactory.sol

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {Create2} from "@openzeppelin/contracts/utils/Create2.sol";
66
import {AbstractDependant} from "../../../contracts-registry/AbstractDependant.sol";
77
import {AbstractPoolContractsRegistry} from "../AbstractPoolContractsRegistry.sol";
88

9-
import {PublicBeaconProxy} from "./proxy/PublicBeaconProxy.sol";
9+
import {PublicBeaconProxy} from "../../../proxy/beacon/PublicBeaconProxy.sol";
1010

1111
/**
1212
* @notice The PoolContractsRegistry module
@@ -74,11 +74,7 @@ abstract contract AbstractPoolFactory is AbstractDependant {
7474
string memory poolType_,
7575
address poolProxy_
7676
) internal virtual {
77-
(bool success, ) = poolRegistry_.call(
78-
abi.encodeWithSignature("addProxyPool(string,address)", poolType_, poolProxy_)
79-
);
80-
81-
require(success, "AbstractPoolFactory: failed to register contract");
77+
AbstractPoolContractsRegistry(poolRegistry_).addProxyPool(poolType_, poolProxy_);
8278
}
8379

8480
/**

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,4 @@ abstract contract MultiOwnablePoolContractsRegistry is
3939
) external onlyOwner {
4040
_injectDependenciesToExistingPoolsWithData(name_, data_, offset_, limit_);
4141
}
42-
43-
function addProxyPool(string memory name_, address poolAddress_) public virtual;
4442
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,4 @@ 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;
4543
}

contracts/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@solarity/solidity-lib",
3-
"version": "2.6.11",
3+
"version": "2.6.12",
44
"license": "MIT",
55
"author": "Distributed Lab",
66
"readme": "README.md",
@@ -21,8 +21,8 @@
2121
"!mock/**/*"
2222
],
2323
"dependencies": {
24-
"@openzeppelin/contracts": "4.9.2",
25-
"@openzeppelin/contracts-upgradeable": "4.9.2",
24+
"@openzeppelin/contracts": "4.9.5",
25+
"@openzeppelin/contracts-upgradeable": "4.9.5",
2626
"@uniswap/v2-core": "1.0.1",
2727
"@uniswap/v2-periphery": "1.1.0-beta.0",
2828
"@uniswap/v3-core": "1.0.1",

contracts/contracts-registry/pools/proxy/ProxyBeacon.sol renamed to contracts/proxy/beacon/ProxyBeacon.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import {IBeacon} from "@openzeppelin/contracts/proxy/beacon/IBeacon.sol";
55
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
66

77
/**
8-
* @notice The PoolContractsRegistry module
8+
* @notice The proxies module
99
*
10-
* This is a utility lightweighted ProxyBeacon contract this is used as a beacon that BeaconProxies point to.
10+
* This is a lightweight utility ProxyBeacon contract that may be used as a beacon that BeaconProxies point to.
1111
*/
1212
contract ProxyBeacon is IBeacon {
1313
using Address for address;
@@ -27,15 +27,15 @@ contract ProxyBeacon is IBeacon {
2727
_OWNER = msg.sender;
2828
}
2929

30-
function upgradeTo(address newImplementation_) external onlyOwner {
30+
function upgradeTo(address newImplementation_) external virtual onlyOwner {
3131
require(newImplementation_.isContract(), "ProxyBeacon: not a contract");
3232

3333
_implementation = newImplementation_;
3434

3535
emit Upgraded(newImplementation_);
3636
}
3737

38-
function implementation() public view override returns (address) {
38+
function implementation() public view virtual override returns (address) {
3939
return _implementation;
4040
}
4141
}
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ pragma solidity ^0.8.4;
44
import {BeaconProxy} from "@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol";
55

66
/**
7-
* @notice The PoolContractsRegistry module
7+
* @notice The proxies module
88
*
9-
* The helper BeaconProxy that get deployed by the PoolFactory. Note that the external
10-
* `implementation()` function is added to the contract to provide compatability with the
11-
* Etherscan. This means that the implementation must not have such a function declared.
9+
* The helper BeaconProxy that can be deployed by the factories.
10+
*
11+
* Note that the external `implementation()` function is added to the contract to provide compatability with
12+
* Etherscan. This means that the implementation contract must not have such a function declared.
1213
*/
1314
contract PublicBeaconProxy is BeaconProxy {
1415
constructor(address beacon_, bytes memory data_) payable BeaconProxy(beacon_, data_) {}
@@ -17,7 +18,7 @@ contract PublicBeaconProxy is BeaconProxy {
1718
* @notice The function that returns implementation contract this proxy points to
1819
* @return address the implementation address
1920
*/
20-
function implementation() external view virtual returns (address) {
21+
function implementation() public view virtual returns (address) {
2122
return _implementation();
2223
}
2324
}

contracts/contracts-registry/proxy/ProxyUpgrader.sol renamed to contracts/proxy/transparent/TransparentProxyUpgrader.sol

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,38 @@ import {ITransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transp
55
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
66

77
/**
8-
* @notice The ContractsRegistry module
8+
* @notice The proxies module
99
*
10-
* This is the helper contract that is used by an AbstractContractsRegistry as a proxy admin.
11-
* It is essential to distinguish between the admin and the registry due to the Transparent proxies nature
10+
* This is the lightweight helper contract that may be used as a transparent proxy admin.
1211
*/
13-
contract ProxyUpgrader {
12+
contract TransparentProxyUpgrader {
1413
using Address for address;
1514

1615
address private immutable _OWNER;
1716

1817
modifier onlyOwner() {
19-
_onlyOwner();
18+
require(_OWNER == msg.sender, "TransparentProxyUpgrader: not an owner");
2019
_;
2120
}
2221

2322
constructor() {
2423
_OWNER = msg.sender;
2524
}
2625

27-
function upgrade(address what_, address to_, bytes calldata data_) external onlyOwner {
26+
function upgrade(address what_, address to_, bytes calldata data_) external virtual onlyOwner {
2827
if (data_.length > 0) {
2928
ITransparentUpgradeableProxy(payable(what_)).upgradeToAndCall(to_, data_);
3029
} else {
3130
ITransparentUpgradeableProxy(payable(what_)).upgradeTo(to_);
3231
}
3332
}
3433

35-
function getImplementation(address what_) external view onlyOwner returns (address) {
34+
function getImplementation(address what_) public view virtual returns (address) {
3635
// bytes4(keccak256("implementation()")) == 0x5c60da1b
3736
(bool success_, bytes memory returndata_) = address(what_).staticcall(hex"5c60da1b");
3837

39-
require(success_, "ProxyUpgrader: not a proxy");
38+
require(success_, "TransparentProxyUpgrader: not a proxy");
4039

4140
return abi.decode(returndata_, (address));
4241
}
43-
44-
function _onlyOwner() internal view {
45-
require(_OWNER == msg.sender, "ProxyUpgrader: not an owner");
46-
}
4742
}

0 commit comments

Comments
 (0)