This repository has been archived by the owner on May 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from keep-network/vendor
Update design to Factory/Vendor Updated architecture to reflect proposal from RFC 12. Introduced vendor contract to hold references to the factory. Updated keep registry to hold references to vendors for given keep types.
- Loading branch information
Showing
16 changed files
with
4,296 additions
and
202 deletions.
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
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,58 @@ | ||
pragma solidity ^0.5.4; | ||
|
||
import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; | ||
import "./utils/AddressArrayUtils.sol"; | ||
import "./ECDSAKeepFactory.sol"; | ||
|
||
/// @title ECDSA Keep Vendor | ||
/// @notice The contract can be used to obtain a new ECDSA keep. | ||
/// @dev Interacts with ECDSA keep factory to obtain a new instance of the ECDSA | ||
/// keep. Several versions of ECDSA keep factories can be registered for the vendor. | ||
/// TODO: This is a stub contract - needs to be implemented. | ||
/// TODO: When more keep types are added consider extracting registration and | ||
/// selection to a separate inheritable contract. | ||
contract ECDSAKeepVendor is Ownable { | ||
using AddressArrayUtils for address[]; | ||
|
||
// List of ECDSA keep factories. | ||
address[] public factories; | ||
|
||
/// @notice Register new ECDSA keep factory. | ||
/// @dev Adds a factory address to the list of registered factories. Address | ||
/// cannot be zero and cannot be already registered. | ||
/// @param _factory ECDSA keep factory address. | ||
function registerFactory(address _factory) public onlyOwner { | ||
require(!factories.contains(_factory), "Factory address already registered"); | ||
|
||
factories.push(_factory); | ||
} | ||
|
||
/// @notice Select a recommended ECDSA keep factory from all registered | ||
/// ECDSA keep factories. | ||
/// @dev This is a stub implementation returning first factory on the list. | ||
/// @return Selected ECDSA keep factory address. | ||
function selectFactory() internal view returns (address) { | ||
// TODO: Implement factory selection mechanism. | ||
return factories[factories.length - 1]; | ||
} | ||
|
||
/// @notice Open a new ECDSA keep. | ||
/// @dev Calls a recommended ECDSA keep factory to open a new keep. | ||
/// @param _groupSize Number of members in the keep. | ||
/// @param _honestThreshold Minimum number of honest keep members. | ||
/// @param _owner Address of the keep owner. | ||
/// @return Opened keep address. | ||
function openKeep( | ||
uint256 _groupSize, | ||
uint256 _honestThreshold, | ||
address _owner | ||
) public payable returns (address keepAddress) { | ||
address factory = selectFactory(); | ||
|
||
return ECDSAKeepFactory(factory).openKeep( | ||
_groupSize, | ||
_honestThreshold, | ||
_owner | ||
); | ||
} | ||
} |
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,55 +1,29 @@ | ||
pragma solidity ^0.5.4; | ||
|
||
import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; | ||
// TODO: For simplification we use import for the other contracts. `ECDSAKeepFactory.sol` | ||
// and `KeepRegistry.sol` will be kept in different repos in the future so a better | ||
// way of calling another contract from this contract should be introduced. | ||
import "./ECDSAKeepFactory.sol"; | ||
|
||
/// @title Keep Registry | ||
/// @notice Contract handling keeps registry. | ||
/// @dev TODO: This is a stub contract - needs to be implemented. | ||
/// @dev The keep registry serves the role of the master list and tracks sanctioned | ||
/// vendors. It ensures that only approved contracts are used. | ||
/// TODO: This is a stub contract - needs to be implemented. | ||
contract KeepRegistry is Ownable { | ||
// Enumeration of supported keeps types. | ||
enum KeepTypes {ECDSA, BondedECDSA} | ||
|
||
// Structure holding keep details. | ||
struct Keep { | ||
address owner; // owner of the keep | ||
address keepAddress; // address of the keep contract | ||
KeepTypes keepType; // type of the keep | ||
} | ||
|
||
// Factory handling ECDSA keeps. | ||
address internal ecdsaKeepFactory; | ||
|
||
// List of created keeps. | ||
Keep[] keeps; | ||
|
||
constructor(address _ecdsaKeepFactory) public { | ||
require(_ecdsaKeepFactory != address(0), "Implementation address can't be zero."); | ||
setECDSAKeepFactory(_ecdsaKeepFactory); | ||
} | ||
|
||
function setECDSAKeepFactory(address _ecdsaKeepFactory) public onlyOwner { | ||
ecdsaKeepFactory = _ecdsaKeepFactory; | ||
// Registered keep vendors. Mapping of a keep type to a keep vendor address. | ||
mapping (string => address) internal keepVendors; | ||
|
||
/// @notice Set a keep vendor contract address for a keep type. | ||
/// @dev Only contract owner can call this function. | ||
/// @param _keepType Keep type. | ||
/// @param _vendorAddress Keep Vendor contract address. | ||
function setVendor(string memory _keepType, address _vendorAddress) public onlyOwner { | ||
keepVendors[_keepType] = _vendorAddress; | ||
} | ||
|
||
/// @notice Create a new ECDSA keep. | ||
/// @dev Calls ECDSA Keep Factory to create a keep. | ||
/// @param _groupSize Number of members in the keep. | ||
/// @param _honestThreshold Minimum number of honest keep members. | ||
/// @return Created keep address. | ||
function createECDSAKeep( | ||
uint256 _groupSize, | ||
uint256 _honestThreshold | ||
) public payable returns (address keep) { | ||
keep = ECDSAKeepFactory(ecdsaKeepFactory).createNewKeep( | ||
_groupSize, | ||
_honestThreshold, | ||
msg.sender | ||
); | ||
|
||
keeps.push(Keep(msg.sender, keep, KeepTypes.ECDSA)); | ||
/// @notice Get a keep vendor contract address for a keep type. | ||
/// @param _keepType Keep type. | ||
/// @return Keep vendor contract address. | ||
function getVendor(string memory _keepType) public view returns (address) { | ||
// TODO: We should probably refer to vendor via proxy - https://github.com/keep-network/keep-tecdsa/pull/43#discussion_r306207111 | ||
return keepVendors[_keepType]; | ||
} | ||
} |
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,16 @@ | ||
pragma solidity ^0.5.4; | ||
|
||
library AddressArrayUtils { | ||
function contains(address[] memory self, address _address) | ||
internal | ||
pure | ||
returns (bool) | ||
{ | ||
for (uint i = 0; i < self.length; i++) { | ||
if (_address == self[i]) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
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,7 +1,14 @@ | ||
const ECDSAKeepFactory = artifacts.require("./ECDSAKeepFactory.sol"); | ||
const ECDSAKeepVendor = artifacts.require("./ECDSAKeepVendor.sol"); | ||
const KeepRegistry = artifacts.require("./KeepRegistry.sol"); | ||
|
||
module.exports = async function (deployer) { | ||
await deployer.deploy(ECDSAKeepFactory); | ||
await deployer.deploy(KeepRegistry, ECDSAKeepFactory.address); | ||
}; | ||
await deployer.deploy(ECDSAKeepFactory) | ||
const ecdsaKeepFactory = await ECDSAKeepFactory.deployed() | ||
|
||
const ecdsaKeepVendor = await deployer.deploy(ECDSAKeepVendor) | ||
await ecdsaKeepVendor.registerFactory(ecdsaKeepFactory.address) | ||
|
||
const keepRegistry = await deployer.deploy(KeepRegistry) | ||
await keepRegistry.setVendor('ECDSAKeep', ecdsaKeepVendor.address) | ||
} |
Oops, something went wrong.