Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VAL-118 Make PoolAccessControl and PoolAdminAccessControl upgradeable #137

Merged
merged 8 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions contracts/Loan.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import "./interfaces/IServiceConfiguration.sol";
import "./libraries/LoanLib.sol";
import "./CollateralVault.sol";
import "./FundingVault.sol";
import "./upgrades/interfaces/IBeaconImplementation.sol";
import "./upgrades/BeaconImplementation.sol";

/**
* @title Loan
*
* Empty Loan contract.
*/
contract Loan is ILoan, IBeaconImplementation {
contract Loan is ILoan, BeaconImplementation {
using SafeMath for uint256;
uint256 constant RAY = 10**27;

Expand Down Expand Up @@ -124,14 +124,14 @@ contract Loan is ILoan, IBeaconImplementation {
}

function initialize(
address serviceConfiguration,
address serviceConfiguration_,
address factory_,
address borrower_,
address pool_,
address liquidityAsset_,
ILoanSettings memory settings_
) public virtual initializer {
_serviceConfiguration = IServiceConfiguration(serviceConfiguration);
_serviceConfiguration = IServiceConfiguration(serviceConfiguration_);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable shadowing fix

_factory = factory_;
_borrower = borrower_;
_pool = pool_;
Expand Down
12 changes: 6 additions & 6 deletions contracts/Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import "./libraries/PoolLib.sol";
import "./FeeVault.sol";
import "./FirstLossVault.sol";
import "./upgrades/interfaces/IBeaconImplementation.sol";
import "./upgrades/BeaconImplementation.sol";

/**
* @title Pool
*/
contract Pool is IPool, ERC20Upgradeable, IBeaconImplementation {
contract Pool is IPool, ERC20Upgradeable, BeaconImplementation {
using SafeERC20Upgradeable for IERC20Upgradeable;
using SafeMath for uint256;
using EnumerableSet for EnumerableSet.AddressSet;
Expand Down Expand Up @@ -118,7 +118,7 @@ contract Pool is IPool, ERC20Upgradeable, IBeaconImplementation {
* @dev Initializer for Pool
* @param liquidityAsset asset held by the poo
* @param poolAdmin admin of the pool
* @param serviceConfiguration address of global service configuration
* @param serviceConfiguration_ address of global service configuration
* @param withdrawControllerFactory factory address of the withdraw controller
* @param poolSettings configurable settings for the pool
* @param tokenName Name used for issued pool tokens
Expand All @@ -127,15 +127,15 @@ contract Pool is IPool, ERC20Upgradeable, IBeaconImplementation {
function initialize(
address liquidityAsset,
address poolAdmin,
address serviceConfiguration,
address serviceConfiguration_,
address withdrawControllerFactory,
address poolControllerFactory,
IPoolConfigurableSettings memory poolSettings,
string memory tokenName,
string memory tokenSymbol
) public initializer {
__ERC20_init(tokenName, tokenSymbol);
_serviceConfiguration = IServiceConfiguration(serviceConfiguration);
_serviceConfiguration = IServiceConfiguration(serviceConfiguration_);
_liquidityAsset = IERC20Upgradeable(liquidityAsset);
_feeVault = new FeeVault(address(this));

Expand All @@ -149,7 +149,7 @@ contract Pool is IPool, ERC20Upgradeable, IBeaconImplementation {
poolController = IPoolController(
IPoolControllerFactory(poolControllerFactory).createController(
address(this),
serviceConfiguration,
serviceConfiguration_,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same - shadowing warning

poolAdmin,
liquidityAsset,
poolSettings
Expand Down
4 changes: 2 additions & 2 deletions contracts/controllers/PoolController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet
import {SafeMath} from "@openzeppelin/contracts/utils/math/SafeMath.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "../upgrades/interfaces/IBeaconImplementation.sol";
import "../upgrades/BeaconImplementation.sol";

/**
* @title WithdrawState
*/
contract PoolController is IPoolController, IBeaconImplementation {
contract PoolController is IPoolController, BeaconImplementation {
using SafeERC20 for IERC20;

IPool public pool;
Expand Down
4 changes: 2 additions & 2 deletions contracts/controllers/WithdrawController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import "./interfaces/IPoolController.sol";
import "../libraries/PoolLib.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {SafeMath} from "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "../upgrades/interfaces/IBeaconImplementation.sol";
import "../upgrades/BeaconImplementation.sol";

/**
* @title WithdrawState
*/
contract WithdrawController is IWithdrawController, IBeaconImplementation {
contract WithdrawController is IWithdrawController, BeaconImplementation {
using SafeMath for uint256;
using EnumerableSet for EnumerableSet.AddressSet;

Expand Down
10 changes: 9 additions & 1 deletion contracts/mocks/MockVeriteAccessControl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,13 @@
pragma solidity ^0.8.16;

import {VeriteAccessControl} from "../permissioned/VeriteAccessControl.sol";
import "../upgrades/DeployerUUPSUpgradeable.sol";

contract MockVeriteAccessControl is VeriteAccessControl {}
contract MockVeriteAccessControl is
VeriteAccessControl,
DeployerUUPSUpgradeable
{
function initialize() public initializer {
__VeriteAccessControl__init();
}
}
18 changes: 18 additions & 0 deletions contracts/mocks/upgrades/MockBeaconImplementation.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.16;

import "../../upgrades/BeaconImplementation.sol";

contract MockBeaconImplementation is BeaconImplementation {
function foo() external pure virtual returns (string memory) {
return "bar";
}

function initialize() public initializer {}
}

contract MockBeaconImplementationV2 is MockBeaconImplementation {
function foo() external pure override returns (string memory) {
return "baz";
}
}
24 changes: 24 additions & 0 deletions contracts/mocks/upgrades/MockBeaconProxyFactory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.16;

import "../../upgrades/BeaconProxyFactory.sol";
import "../../interfaces/IServiceConfiguration.sol";
import {BeaconProxy} from "@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol";
import "./MockBeaconImplementation.sol";

contract MockBeaconProxyFactory is BeaconProxyFactory {
event Created(address proxy);

constructor(address serviceConfig) {
_serviceConfiguration = IServiceConfiguration(serviceConfig);
}

function create() external returns (address) {
BeaconProxy proxy = new BeaconProxy(
address(this),
abi.encodeWithSelector(MockBeaconImplementation.initialize.selector)
);
emit Created(address(proxy));
return address(proxy);
}
}
7 changes: 7 additions & 0 deletions contracts/mocks/upgrades/PoolAccessControlMockV2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.16;

import "../../permissioned/PoolAccessControl.sol";
import "./MockUpgrade.sol";

contract PoolAccessControlMockV2 is PoolAccessControl, MockUpgrade {}
7 changes: 7 additions & 0 deletions contracts/mocks/upgrades/PoolAdminAccessControlMockV2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.16;

import "../../permissioned/PoolAdminAccessControl.sol";
import "./MockUpgrade.sol";

contract PoolAdminAccessControlMockV2 is PoolAdminAccessControl, MockUpgrade {}
15 changes: 12 additions & 3 deletions contracts/permissioned/PoolAccessControl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "./interfaces/IPermissionedServiceConfiguration.sol";
import "./interfaces/IToSAcceptanceRegistry.sol";
import "../interfaces/IPool.sol";
import "./VeriteAccessControl.sol";
import "../upgrades/BeaconImplementation.sol";

/**
* @title The PoolAccessControl contract
Expand All @@ -14,7 +15,11 @@ import "./VeriteAccessControl.sol";
* This implementation implements a basic Allow-List of addresses, which can
* be managed only by the Pool Admin.
*/
contract PoolAccessControl is IPoolAccessControl, VeriteAccessControl {
contract PoolAccessControl is
IPoolAccessControl,
BeaconImplementation,
VeriteAccessControl
{
/**
* @dev Reference to the pool
*/
Expand Down Expand Up @@ -66,16 +71,20 @@ contract PoolAccessControl is IPoolAccessControl, VeriteAccessControl {
}

/**
* @dev The constructor for the PoolAccessControl contract
* @dev The initializer for the PoolAccessControl contract
*/
constructor(address pool, address tosAcceptanceRegistry) {
function initialize(address pool, address tosAcceptanceRegistry)
public
initializer
{
require(
tosAcceptanceRegistry != address(0),
"Pool: invalid ToS registry"
);

_pool = IPool(pool);
_tosRegistry = IToSAcceptanceRegistry(tosAcceptanceRegistry);
__VeriteAccessControl__init();
}

/**
Expand Down
33 changes: 22 additions & 11 deletions contracts/permissioned/PoolAccessControlFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,38 @@ import "./interfaces/IPoolAccessControlFactory.sol";
import "./interfaces/IPermissionedServiceConfiguration.sol";
import "../LoanFactory.sol";
import "./PoolAccessControl.sol";
import "../upgrades/BeaconProxyFactory.sol";
import {BeaconProxy} from "@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol";

/**
* @title PoolAccessControlFactory
*/
contract PoolAccessControlFactory is IPoolAccessControlFactory {
/**
* @dev Reference to the ServiceConfig
*/
IPermissionedServiceConfiguration private _config;

contract PoolAccessControlFactory is
IPoolAccessControlFactory,
BeaconProxyFactory
{
constructor(address serviceConfiguration) {
_config = IPermissionedServiceConfiguration(serviceConfiguration);
_serviceConfiguration = IPermissionedServiceConfiguration(
serviceConfiguration
);
}

/**
* @inheritdoc IPoolAccessControlFactory
*/
function create(address pool) external virtual override returns (address) {
return
address(
new PoolAccessControl(pool, _config.tosAcceptanceRegistry())
);
require(
implementation != address(0),
"PoolAccessControlFactory: no impl"
);
BeaconProxy proxy = new BeaconProxy(
address(this),
abi.encodeWithSelector(
PoolAccessControl.initialize.selector,
pool,
_serviceConfiguration.tosAcceptanceRegistry()
)
);
return address(proxy);
}
}
13 changes: 6 additions & 7 deletions contracts/permissioned/PoolAdminAccessControl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "./interfaces/IPoolAdminAccessControl.sol";
import "./interfaces/IPermissionedServiceConfiguration.sol";
import "./interfaces/IToSAcceptanceRegistry.sol";
import "./VeriteAccessControl.sol";
import "../upgrades/DeployerUUPSUpgradeable.sol";

/**
* @title The PoolAdminAccessControl contract
Expand All @@ -15,13 +16,9 @@ import "./VeriteAccessControl.sol";
*/
contract PoolAdminAccessControl is
IPoolAdminAccessControl,
DeployerUUPSUpgradeable,
VeriteAccessControl
{
/**
* @dev Reference to the PermissionedServiceConfiguration contract
*/
IPermissionedServiceConfiguration private _serviceConfiguration;

/**
* @dev Reference to the ToS Acceptance Registry
*/
Expand All @@ -48,9 +45,9 @@ contract PoolAdminAccessControl is
}

/**
* @dev Constructor for the contract, which sets the ServiceConfiguration.
* @dev Initializer for the contract, which sets the ServiceConfiguration.
*/
constructor(address serviceConfiguration) {
function initialize(address serviceConfiguration) public initializer {
_serviceConfiguration = IPermissionedServiceConfiguration(
serviceConfiguration
);
Expand All @@ -59,6 +56,8 @@ contract PoolAdminAccessControl is
);

require(address(_tosRegistry) != address(0), "INVALID_TOS_REGISTRY");

__VeriteAccessControl__init();
}

/**
Expand Down
13 changes: 9 additions & 4 deletions contracts/permissioned/VeriteAccessControl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
pragma solidity ^0.8.16;

import "./interfaces/IVeriteAccessControl.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/utils/cryptography/draft-EIP712.sol";
import "@openzeppelin/contracts-upgradeable/utils/cryptography/ECDSAUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/cryptography/draft-EIP712Upgradeable.sol";

/**
* @title The VeriteAccessControl contract
Expand All @@ -12,9 +12,10 @@ import "@openzeppelin/contracts/utils/cryptography/draft-EIP712.sol";
* Other contracts should inherit this contract to add Verite-specific
* access control logic.
*/

abstract contract VeriteAccessControl is
IVeriteAccessControl,
EIP712("VerificationRegistry", "1.0")
EIP712Upgradeable
{
/**
* @dev A mapping of allowed verifiers
Expand Down Expand Up @@ -101,6 +102,10 @@ abstract contract VeriteAccessControl is
Verification
//////////////////////////////////////////////////////////////*/

function __VeriteAccessControl__init() internal onlyInitializing {
__EIP712_init("VerificationRegistry", "1.0");
}

/**
* @dev Check if an address is verified
*/
Expand Down Expand Up @@ -146,7 +151,7 @@ abstract contract VeriteAccessControl is
);

// recover the public address corresponding to the signature and regenerated hash
address signerAddress = ECDSA.recover(digest, signature);
address signerAddress = ECDSAUpgradeable.recover(digest, signature);

// ensure the verifier is registered
require(_trustedVerifiers[signerAddress], "INVALID_SIGNER");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
pragma solidity ^0.8.16;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "hardhat/console.sol";

/**
* @title BeaconImplementation
* @dev Base contract that
*/
abstract contract IBeaconImplementation is Initializable {
abstract contract BeaconImplementation is Initializable {
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
Expand Down
Loading