Skip to content

Commit

Permalink
Slight improvements to Registry (#412)
Browse files Browse the repository at this point in the history

Signed-off-by: Roz Stengle <rosalind.stengle@gmail.com>
  • Loading branch information
ptare authored and rosalindstengle committed May 22, 2019
1 parent 1cabec5 commit 5cdc6e2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 12 deletions.
17 changes: 13 additions & 4 deletions v1/contracts/Registry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import "openzeppelin-solidity/contracts/math/SafeMath.sol";
pragma experimental ABIEncoderV2;


/**
* @title Registry for derivatives and approved derivative creators.
* @dev Maintains a whitelist of derivative creators that are allowed to register new derivatives.
*/
contract Registry is RegistryInterface, MultiRole {

using SafeMath for uint;
Expand All @@ -27,8 +31,7 @@ contract Registry is RegistryInterface, MultiRole {
// This enum is required because a WasValid state is required to ensure that derivatives cannot be re-registered.
enum PointerValidity {
Invalid,
Valid,
WasValid
Valid
}

struct Pointer {
Expand All @@ -49,6 +52,10 @@ contract Registry is RegistryInterface, MultiRole {
// Maps from derivative address to the set of parties that are involved in that derivative.
mapping(address => PartiesMap) private derivativesToParties;

// TODO(ptare): Used to make doubly sure that roles are initialized only once. Figure out what's going wrong with
// coverage to necessitate this hack.
bool private rolesInitialized;

constructor() public {
initializeRolesOnce();
}
Expand Down Expand Up @@ -114,10 +121,12 @@ contract Registry is RegistryInterface, MultiRole {

/*
* @notice Do not call this function externally.
* @dev Only called from the constructor, and only extracted to a separate method to make the coverage tool work. If
* called again, the MultiRole checks will cause a revert.
* @dev Only called from the constructor, and only extracted to a separate method to make the coverage tool work.
* Will revert if called again.
*/
function initializeRolesOnce() public {
require(!rolesInitialized, "Only the constructor should call this method");
rolesInitialized = true;
_createExclusiveRole(uint(Roles.Governance), uint(Roles.Governance), msg.sender);
_createExclusiveRole(uint(Roles.Writer), uint(Roles.Governance), msg.sender);
// Start with no derivative creators registered.
Expand Down
24 changes: 16 additions & 8 deletions v1/contracts/RegistryInterface.sol
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
/*
Registry Interface
*/
pragma solidity ^0.5.0;

pragma experimental ABIEncoderV2;


/**
* @title Interface for a registry of derivatives and derivative creators
*/
interface RegistryInterface {
struct RegisteredDerivative {
address derivativeAddress;
address derivativeCreator;
}

// Registers a new derivative. Only authorized derivative creators can call this method.
/**
* @dev Registers a new derivative. Only authorized derivative creators can call this method.
*/
function registerDerivative(address[] calldata counterparties, address derivativeAddress) external;

// Returns whether the derivative has been registered with the registry (and is therefore an authorized participant
// in the UMA system).
/**
* @dev Returns whether the derivative has been registered with the registry (and is therefore an authorized
* participant in the UMA system).
*/
function isDerivativeRegistered(address derivative) external view returns (bool isRegistered);

// Returns a list of all derivatives that are associated with a particular party.
/**
* @dev Returns a list of all derivatives that are associated with a particular party.
*/
function getRegisteredDerivatives(address party) external view returns (RegisteredDerivative[] memory derivatives);

// Returns all registered derivatives.
/**
* @dev Returns all registered derivatives.
*/
function getAllRegisteredDerivatives() external view returns (RegisteredDerivative[] memory derivatives);
}
9 changes: 9 additions & 0 deletions v1/migrations/4_deploy_registry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const Registry = artifacts.require("Registry");
const { getKeysForNetwork, deployAndGet, addToTdr } = require("../../common/MigrationUtils.js");

module.exports = async function(deployer, network, accounts) {
const keys = getKeysForNetwork(network, accounts);

const registry = await deployAndGet(deployer, Registry, { from: keys.deployer });
await addToTdr(registry, network);
};
5 changes: 5 additions & 0 deletions v1/scripts/CheckDeploymentValidity.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const Migrations = artifacts.require("Migrations");
const Registry = artifacts.require("Registry");

const checkDeploymentValidity = async function(callback) {
try {
Expand All @@ -9,6 +10,10 @@ const checkDeploymentValidity = async function(callback) {
const migrations = await Migrations.deployed();
await migrations.last_completed_migration();

// Registry
const registry = await Registry.deployed();
await registry.getAllRegisteredDerivatives();

console.log("Deployment looks good!");
} catch (e) {
// Forces the script to return a nonzero error code so failure can be detected in bash.
Expand Down

0 comments on commit 5cdc6e2

Please sign in to comment.