diff --git a/src/CypherRegistry.sol b/src/CypherRegistry.sol index fbcf8b1..d6e63c9 100644 --- a/src/CypherRegistry.sol +++ b/src/CypherRegistry.sol @@ -21,26 +21,36 @@ contract CypherRegistry { event EscrowCreated( address indexed escrow, - address indexed protocol, + address[] indexed protocols, address token, uint256 tokenThreshold, uint256 timeLimit, address[] oracles ); - event EscrowAttached(address indexed escrow, address indexed protocol); + event EscrowAttached(address indexed escrow, address[] indexed protocol); /*////////////////////////////////////////////////////////////// ERRORS //////////////////////////////////////////////////////////////*/ error ProtocolAlreadyRegistered(); + error NotAnArchitect(); /*////////////////////////////////////////////////////////////// MODIFIERS //////////////////////////////////////////////////////////////*/ - modifier architectOnly(address protocol) { - require(ICypherProtocol(protocol).getArchitect() == msg.sender, "ok"); + modifier architectOnly(address[] memory protocols) { + for (uint256 i = 0; i < protocols.length; i++) { + if (ICypherProtocol(protocols[i]).getArchitect() != msg.sender) revert NotAnArchitect(); + } + _; + } + + modifier notRegistered(address[] memory protocols) { + for (uint256 i = 0; i < protocols.length; i++) { + if (address(getEscrowForProtocol[protocols[i]]) != address(0)) revert ProtocolAlreadyRegistered(); + } _; } @@ -55,31 +65,35 @@ contract CypherRegistry { //////////////////////////////////////////////////////////////*/ /// @dev Creates a new escrow for a protocol - /// @param protocol The address of the contract to protect + /// @param protocols The set of contracts to protect /// @param token The address of the token that is being stored in the protocols smart contracts /// @param tokenThreshold The amount per tx to limit on withdraw /// @param timeLimit How long the funds should stay locked up until release (if the team does not respond) /// @param oracles The addresses of the signers who can release the funds function createEscrow( - address protocol, + address[] memory protocols, address token, uint256 tokenThreshold, uint256 timeLimit, address[] memory oracles - ) public architectOnly(protocol) returns (address) { - if (getEscrowForProtocol[protocol] != CypherEscrow(address(0))) revert ProtocolAlreadyRegistered(); + ) public architectOnly(protocols) notRegistered(protocols) returns (address) { CypherEscrow escrow = new CypherEscrow(token, tokenThreshold, timeLimit, oracles); - getEscrowForProtocol[protocol] = escrow; - emit EscrowCreated(address(escrow), protocol, token, tokenThreshold, timeLimit, oracles); + for (uint256 i = 0; i < protocols.length; i++) { + getEscrowForProtocol[protocols[i]] = escrow; + } + + emit EscrowCreated(address(escrow), protocols, token, tokenThreshold, timeLimit, oracles); return address(escrow); } - /// @dev Assigns an existing escrow to a protocol - function attachEscrow(address escrow, address protocol) public architectOnly(protocol) { - getEscrowForProtocol[protocol] = CypherEscrow(escrow); + /// @dev Assigns an existing escrow to a set of protocols + function attachEscrow(address escrow, address[] memory protocols) public architectOnly(protocols) { + for (uint256 i = 0; i < protocols.length; i++) { + getEscrowForProtocol[protocols[i]] = CypherEscrow(escrow); + } - emit EscrowAttached(escrow, protocol); + emit EscrowAttached(escrow, protocols); } }