Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.

Update design to Factory/Vendor #43

Merged
merged 35 commits into from
Jul 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
96bcd46
Introduce Keep Vendor contract
nkuba Jul 15, 2019
69a2786
Redesign Keep Registry to register vendors
nkuba Jul 15, 2019
3e3d628
Rename createNewKeep to openKeep
nkuba Jul 16, 2019
3f2a191
npm clean command
nkuba Jul 16, 2019
ddb30e7
npm package lock file update
nkuba Jul 16, 2019
c057f2d
Update keep factory unit test
nkuba Jul 16, 2019
182d5fc
Update truffle contract deployment script
nkuba Jul 16, 2019
25c6fbe
Upgrade openzeppelin version
nkuba Jul 16, 2019
27da1ca
Add unit tests
nkuba Jul 16, 2019
03ab1d5
ECDSAKeepFactory stub for testing
nkuba Jul 16, 2019
c20716e
Remove empty line
nkuba Jul 16, 2019
ad78b91
create new keep -> open keep
nkuba Jul 16, 2019
8fb1f57
Merge remote-tracking branch 'origin/master' into vendor
nkuba Jul 16, 2019
1999183
Update name of getKeepTypeVendor func
nkuba Jul 16, 2019
7600be6
Remove unnecessary error catches
nkuba Jul 16, 2019
7f77147
Simplify truffle deploy scripts
nkuba Jul 16, 2019
e97c213
Rename set/get vendor for keep type functions
nkuba Jul 18, 2019
98d65ef
Remove address 0 validation from Keep Registry
nkuba Jul 22, 2019
c0897a0
Delete vendor removal function
nkuba Jul 22, 2019
847bb3c
Delete removeFactory and address(0) check
nkuba Jul 22, 2019
cdf427b
Make selectFactory internal
nkuba Jul 22, 2019
cfad47c
Rename get/set vendor functions
nkuba Jul 22, 2019
bc6338c
ECDSA keep vendor stub contract
nkuba Jul 22, 2019
ca5dd06
Update deployment script
nkuba Jul 22, 2019
f736128
Tests updates
nkuba Jul 22, 2019
43e8777
Merge remote-tracking branch 'origin/master' into vendor
nkuba Jul 22, 2019
99e1529
Rename ECDSA Keep to TECDSA Keep
nkuba Jul 24, 2019
68c6abc
Select latest registered factory
nkuba Jul 24, 2019
634cc77
Move afterEach assertion to a function
nkuba Jul 24, 2019
e076809
Await in deploy contracts
nkuba Jul 24, 2019
80a23de
Deleted removeAddress from array utils
nkuba Jul 24, 2019
86525c9
Documentation update
nkuba Jul 24, 2019
130252d
Revert "Rename ECDSA Keep to TECDSA Keep"
nkuba Jul 24, 2019
86eefbe
Fix failing vendor test
nkuba Jul 24, 2019
5b7ca78
Remove zero address and duplicate test cases
nkuba Jul 24, 2019
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
2 changes: 1 addition & 1 deletion configs/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# Connection details of ethereum blockchain.
[ethereum]
URL = "ws://127.0.0.1:8545"
PrivateKey = "bd03a0aa0b96c5cff1accafdc806aa7f655b6a9a13aeb79f4669c9cfad1eb265"
PrivateKey = "0789df7d07e6947a93576b9ef60b97aed9adb944fb3ff6bae5215fd3ab0ad0dd" # ethereum address: 0x1C25f178599d00b3887BF6D9084cf0C6d49a3097

# Addresses of contracts deployed on ethereum blockchain.
[ethereum.ContractAddresses]
Expand Down
16 changes: 7 additions & 9 deletions solidity/contracts/ECDSAKeepFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ contract ECDSAKeepFactory {
address keepAddress
);

/// @notice Create a new ECDSA keep.
/// @notice Open a new ECDSA keep.
/// @dev Selects a list of members for the keep based on provided parameters.
/// @param _groupSize Number of members in the keep.
/// @param _honestThreshold Minimum number of honest keep members.
/// @param _owner Owner of the keep.
/// @return Created keep.
function createNewKeep(
/// @param _owner Address of the keep owner.
/// @return Created keep address.
function openKeep(
uint256 _groupSize,
uint256 _honestThreshold,
address _owner
Expand All @@ -30,7 +30,7 @@ contract ECDSAKeepFactory {
ECDSAKeep keep = new ECDSAKeep(
_owner,
_members,
_honestThreshold
_honestThreshold
);
keeps.push(keep);

Expand All @@ -44,14 +44,12 @@ contract ECDSAKeepFactory {
/// @param _groupSize Number of members to be selected.
/// @return List of selected members addresses.
function selectECDSAKeepMembers(
uint256 _groupSize
uint256 _groupSize
) internal pure returns (address[] memory members){
// TODO: Implement
_groupSize;

members = new address[](1);
members[0] = 0xE1d6c440DC87476242F313aA1179196fAE89B93e;

// TODO: Currently it assumes members are identified by ID, we should
// consider changing it to an account address or other unique identfier.
}
}
58 changes: 58 additions & 0 deletions solidity/contracts/ECDSAKeepVendor.sol
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
pdyraga marked this conversation as resolved.
Show resolved Hide resolved
/// @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 {
pdyraga marked this conversation as resolved.
Show resolved Hide resolved
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
);
}
}
62 changes: 18 additions & 44 deletions solidity/contracts/KeepRegistry.sol
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;
pdyraga marked this conversation as resolved.
Show resolved Hide resolved
}

/// @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];
}
}
16 changes: 16 additions & 0 deletions solidity/contracts/utils/AddressArrayUtils.sol
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)
pdyraga marked this conversation as resolved.
Show resolved Hide resolved
internal
pure
returns (bool)
{
for (uint i = 0; i < self.length; i++) {
if (_address == self[i]) {
return true;
}
}
return false;
}
}
13 changes: 10 additions & 3 deletions solidity/migrations/2_deploy_contracts.js
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)
}
Loading