-
Notifications
You must be signed in to change notification settings - Fork 19
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-114 First cut of adding an upgradeable contract #127
Merged
+1,037
−176
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
100c870
First cut of adding an upgradeable contract
757bdcb
Move service configurable to a dedicated interface
a771ea9
Move constructor to abstract type too
3ea1b69
WIP
1e2d019
Update pool factories to use beacon pattern
2903361
WIP
04d5673
Post rebase fixes. Add more tests for the factory
40f5a3f
Delete unused file
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,6 @@ typechain-types | |
cache | ||
artifacts | ||
|
||
# OpenZeppelin | ||
.openzeppelin/unknown-*.json | ||
.openzeppelin/.session |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,11 +4,13 @@ pragma solidity ^0.8.16; | |
import "./Pool.sol"; | ||
import "./interfaces/IServiceConfiguration.sol"; | ||
import "./interfaces/IPoolFactory.sol"; | ||
import {BeaconProxy} from "@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol"; | ||
import "./upgrades/interfaces/IBeacon.sol"; | ||
|
||
/** | ||
* @title PoolFactory | ||
*/ | ||
contract PoolFactory is IPoolFactory { | ||
contract PoolFactory is IPoolFactory, IBeacon { | ||
/** | ||
* @dev Reference to the ServiceConfiguration contract | ||
*/ | ||
|
@@ -24,6 +26,22 @@ contract PoolFactory is IPoolFactory { | |
*/ | ||
address internal _poolControllerFactory; | ||
|
||
/** | ||
* @inheritdoc IBeacon | ||
*/ | ||
address public implementation; | ||
|
||
/** | ||
* @dev Modifier that requires that the sender is registered as a protocol deployer. | ||
*/ | ||
modifier onlyDeployer() { | ||
require( | ||
IServiceConfiguration(_serviceConfiguration).isDeployer(msg.sender), | ||
"Upgrade: unauthorized" | ||
); | ||
_; | ||
} | ||
|
||
constructor( | ||
address serviceConfiguration, | ||
address withdrawControllerFactory, | ||
|
@@ -34,6 +52,18 @@ contract PoolFactory is IPoolFactory { | |
_poolControllerFactory = poolControllerFactory; | ||
} | ||
|
||
/** | ||
* @inheritdoc IBeacon | ||
*/ | ||
function setImplementation(address newImplementation) | ||
external | ||
override | ||
onlyDeployer | ||
{ | ||
implementation = newImplementation; | ||
emit ImplementationSet(newImplementation); | ||
} | ||
|
||
/** | ||
* @dev Creates a pool | ||
* @dev Emits `PoolCreated` event. | ||
|
@@ -42,6 +72,10 @@ contract PoolFactory is IPoolFactory { | |
address liquidityAsset, | ||
IPoolConfigurableSettings calldata settings | ||
) public virtual returns (address poolAddress) { | ||
require( | ||
implementation != address(0), | ||
"PoolFactory: no implementation set" | ||
); | ||
require( | ||
IServiceConfiguration(_serviceConfiguration).paused() == false, | ||
"PoolFactory: Protocol paused" | ||
|
@@ -95,16 +129,21 @@ contract PoolFactory is IPoolFactory { | |
address liquidityAsset, | ||
IPoolConfigurableSettings calldata settings | ||
) internal virtual returns (address) { | ||
Pool pool = new Pool( | ||
liquidityAsset, | ||
msg.sender, | ||
_serviceConfiguration, | ||
_withdrawControllerFactory, | ||
_poolControllerFactory, | ||
settings, | ||
"PerimeterPoolToken", | ||
"PPT" | ||
// Create beacon proxy | ||
BeaconProxy proxy = new BeaconProxy( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the key bit |
||
address(this), | ||
abi.encodeWithSelector( | ||
Pool.initialize.selector, | ||
liquidityAsset, | ||
msg.sender, | ||
_serviceConfiguration, | ||
_withdrawControllerFactory, | ||
_poolControllerFactory, | ||
settings, | ||
"PerimeterPoolToken", | ||
"PPT" | ||
) | ||
); | ||
return address(pool); | ||
return address(proxy); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,44 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.16; | ||
|
||
import "@openzeppelin/contracts/access/AccessControl.sol"; | ||
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol"; | ||
import "./interfaces/IServiceConfiguration.sol"; | ||
import "./upgrades/DeployerUUPSUpgradeable.sol"; | ||
import "hardhat/console.sol"; | ||
|
||
/** | ||
* @title The ServiceConfiguration contract | ||
* @dev Implementation of the {IServiceConfiguration} interface. | ||
*/ | ||
contract ServiceConfiguration is AccessControl, IServiceConfiguration { | ||
contract ServiceConfiguration is | ||
IServiceConfiguration, | ||
AccessControlUpgradeable, | ||
DeployerUUPSUpgradeable | ||
{ | ||
/** | ||
* @dev The Operator Role | ||
*/ | ||
bytes32 public constant OPERATOR_ROLE = keccak256("OPERATOR_ROLE"); | ||
|
||
/** | ||
* @dev The Operator Role | ||
*/ | ||
bytes32 public constant DEPLOYER_ROLE = keccak256("DEPLOYER_ROLE"); | ||
|
||
/** | ||
* @dev Whether the protocol is paused. | ||
*/ | ||
bool public paused = false; | ||
bool public paused; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All non-constant values should be set in the |
||
|
||
mapping(address => bool) public isLiquidityAsset; | ||
|
||
mapping(address => uint256) public firstLossMinimum; | ||
|
||
uint256 public firstLossFeeBps = 500; | ||
uint256 public firstLossFeeBps; | ||
|
||
address public tosAcceptanceRegistry; | ||
|
||
uint256 public protocolFeeBps = 0; | ||
uint256 public protocolFeeBps; | ||
|
||
/** | ||
* @dev Holds a reference to valid LoanFactories | ||
|
@@ -69,15 +80,6 @@ contract ServiceConfiguration is AccessControl, IServiceConfiguration { | |
*/ | ||
event TermsOfServiceRegistrySet(address indexed registry); | ||
|
||
/** | ||
* @dev Constructor for the contract, which sets up the default roles and | ||
* owners. | ||
*/ | ||
constructor() { | ||
// Grant the contract deployer the Operator role | ||
_setupRole(OPERATOR_ROLE, msg.sender); | ||
} | ||
|
||
/** | ||
* @dev Modifier that checks that the caller account has the Operator role. | ||
*/ | ||
|
@@ -89,6 +91,19 @@ contract ServiceConfiguration is AccessControl, IServiceConfiguration { | |
_; | ||
} | ||
|
||
/** | ||
* @dev Constructor for the contract, which sets up the default roles and | ||
* owners. | ||
*/ | ||
function initialize() public initializer { | ||
// Initialize values | ||
paused = false; | ||
firstLossFeeBps = 500; | ||
protocolFeeBps = 0; | ||
|
||
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender); | ||
} | ||
|
||
/** | ||
* @dev Set a liquidity asset as valid or not. | ||
*/ | ||
|
@@ -116,6 +131,13 @@ contract ServiceConfiguration is AccessControl, IServiceConfiguration { | |
return hasRole(OPERATOR_ROLE, addr); | ||
} | ||
|
||
/** | ||
* @inheritdoc IServiceConfiguration | ||
*/ | ||
function isDeployer(address addr) external view returns (bool) { | ||
return hasRole(DEPLOYER_ROLE, addr); | ||
} | ||
|
||
/** | ||
* @inheritdoc IServiceConfiguration | ||
*/ | ||
|
@@ -159,4 +181,11 @@ contract ServiceConfiguration is AccessControl, IServiceConfiguration { | |
firstLossFeeBps = value; | ||
emit ParameterSet("firstLossFeeBps", value); | ||
} | ||
|
||
/** | ||
* @inheritdoc IServiceConfigurable | ||
*/ | ||
function serviceConfiguration() external view override returns (address) { | ||
return address(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.16; | ||
|
||
/** | ||
* @title IServiceConfigurable | ||
* @dev Interface indicating that the contract is controlled by the protocol service configuration. | ||
*/ | ||
interface IServiceConfigurable { | ||
/** | ||
* @dev Address of the protocol service configuration. | ||
*/ | ||
function serviceConfiguration() external view returns (address); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.16; | ||
|
||
abstract contract MockUpgrade { | ||
function foo() external pure returns (bool) { | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.16; | ||
|
||
import "../../Pool.sol"; | ||
import "./MockUpgrade.sol"; | ||
|
||
/** | ||
* @dev Simulated new Pool implementation | ||
*/ | ||
contract PoolMockV2 is Pool, MockUpgrade { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.16; | ||
|
||
import "../../ServiceConfiguration.sol"; | ||
import "./MockUpgrade.sol"; | ||
|
||
/** | ||
* @dev Simulated new ServiceConfiguration implementation | ||
*/ | ||
contract ServiceConfigurationMockV2 is ServiceConfiguration, MockUpgrade { | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Annoyingly, everything needs to be the
*Upgradeable
OpenZep library