Skip to content
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

Gateways are now organized #515

Merged
merged 8 commits into from
Dec 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 7 additions & 6 deletions contracts/gateway/EIP20CoGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pragma solidity ^0.5.0;

import "./UtilityTokenInterface.sol";
import "./GatewayBase.sol";
import "../lib/IsMemberInterface.sol";

/**
* @title EIP20CoGateway Contract
Expand Down Expand Up @@ -194,31 +195,31 @@ contract EIP20CoGateway is GatewayBase {
/* Constructor */

/**
* @notice Initialise the contract by providing the Gateway contract
* @notice Initialize the contract by providing the Gateway contract
* address for which the CoGateway will enable facilitation of
* mint and redeem.
*
* @param _valueToken The value token contract address.
* @param _utilityToken The utility token address that will be used for
* minting the utility token.
* @param _core Core contract address.
* @param _bounty The amount that facilitator will stake to initiate the
* stake process.
* @param _organisation Organisation address.
* @param _bounty The amount that facilitator stakes to initiate the stake
* process.
* @param _membersManager Address of a contract that manages workers.
* @param _gateway Gateway contract address.
*/
constructor(
address _valueToken,
address _utilityToken,
CoreInterface _core,
uint256 _bounty,
address _organisation,
IsMemberInterface _membersManager,
address _gateway
)
GatewayBase(
_core,
_bounty,
_organisation
_membersManager
)
public
{
Expand Down
11 changes: 6 additions & 5 deletions contracts/gateway/EIP20Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pragma solidity ^0.5.0;

import "./SimpleStake.sol";
import "./GatewayBase.sol";
import "../lib/IsMemberInterface.sol";

/**
* @title EIP20Gateway Contract
Expand Down Expand Up @@ -212,19 +213,19 @@ contract EIP20Gateway is GatewayBase {
* @param _core Core contract address.
* @param _bounty The amount that facilitator will stakes to initiate the
* stake process.
* @param _organisation Organisation address.
* @param _membersManager Address of a contract that manages workers.
*/
constructor(
EIP20Interface _token,
EIP20Interface _baseToken,
CoreInterface _core,
uint256 _bounty,
address _organisation
IsMemberInterface _membersManager
)
GatewayBase(
_core,
_bounty,
_organisation
_membersManager
)
public
{
Expand Down Expand Up @@ -973,7 +974,7 @@ contract EIP20Gateway is GatewayBase {
address _coGatewayAddress
)
external
onlyOrganisation
onlyOrganization
returns (bool success_)
{

Expand All @@ -1000,7 +1001,7 @@ contract EIP20Gateway is GatewayBase {
*/
function deactivateGateway()
external
onlyOrganisation
onlyOrganization
returns (bool success_)
{
require(
Expand Down
103 changes: 44 additions & 59 deletions contracts/gateway/GatewayBase.sol
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
pragma solidity ^0.5.0;

import "../lib/GatewayLib.sol";
import "./CoreInterface.sol";
import "../lib/SafeMath.sol";
import "./EIP20Interface.sol";
import "./MessageBus.sol";
import "../StateRootInterface.sol";
import "./EIP20Interface.sol";
import "../lib/GatewayLib.sol";
import "../lib/IsMemberInterface.sol";
import "../lib/Organized.sol";
import "../lib/SafeMath.sol";


/**
* @title GatewayBase contract.
*
* @notice GatewayBase contains general purpose functions shared between
* gateway and co-gateway contract.
* gateway and co-gateway contract.
*/
contract GatewayBase {

contract GatewayBase is Organized {
using SafeMath for uint256;

/**
* Emitted whenever a Gateway/CoGateway contract is proven.
* wasAlreadyProved parameter differentiates between first call and replay
* call of proveGateway method for same block height
* call of proveGateway method for same block height.
*/
event GatewayProven(
address _gateway,
Expand Down Expand Up @@ -54,56 +56,54 @@ contract GatewayBase {

/* constants */

/** Position of message bus in the storage */
/** Position of message bus in the storage. */
uint8 constant MESSAGE_BOX_OFFSET = 1;

/**
* Penalty in bounty amount percentage charged to staker on revert stake
* Penalty in bounty amount percentage charged to staker on revert stake.
*/
uint8 constant REVOCATION_PENALTY = 150;

//todo identify how to get block time for both chains
/** Unlock period for change bounty in block height */
/** Unlock period for change bounty in block height. */
uint256 private constant BOUNTY_CHANGE_UNLOCK_PERIOD = 100;

/**
* Message box.
* @dev keep this is at location 1, in case this is changed then update
* @dev Keep this is at location 1, in case this is changed then update
* constant MESSAGE_BOX_OFFSET accordingly.
*/
MessageBus.MessageBox messageBox;

/** Specifies if the Gateway is activated for any new process. */
bool public activated;

/** Organisation address. */
address public organisation;

/** address of core contract. */
/** Address of core contract. */
CoreInterface public core;

/** path to prove merkle account proof for Gateway/CoGateway contract. */
/** Path to make Merkle account proof for Gateway/CoGateway contract. */
bytes internal encodedGatewayPath;

/**
* Remote gateway contract address. If gateway contract remote gateway
* is CoGateway and vice versa.
* Remote gateway contract address. If this is a gateway contract, then the
* remote gateway is a CoGateway and vice versa.
*/
address public remoteGateway;

/** amount of ERC20 which is staked by facilitator. */
/** Amount of ERC20 which is staked by facilitator. */
uint256 public bounty;

/** Proposed new bounty amount for bounty change. */
uint256 public proposedBounty;
/** bounty proposal block height*/

/** Bounty proposal block height. */
uint256 public proposedBountyUnlockHeight;

/** Maps messageHash to the Message object. */
mapping(bytes32 /*messageHash*/ => MessageBus.Message) messages;
mapping(bytes32 => MessageBus.Message) messages;

/** Mapping to store blockHeight to storageRoot. */
mapping(uint256 /* block height */ => bytes32 /* storageRoot */) internal storageRoots;
/** Maps blockHeight to storageRoot. */
mapping(uint256 => bytes32) internal storageRoots;

/**
* Maps address to message hash.
Expand All @@ -114,7 +114,7 @@ contract GatewayBase {
* for a particular address. This is also used to determine the
* nonce of the particular address. Refer getNonce for the details.
*/
mapping(address /*address*/ => bytes32 /*messageHash*/) inboxActiveProcess;
mapping(address => bytes32) inboxActiveProcess;

/**
* Maps address to message hash.
Expand All @@ -125,18 +125,10 @@ contract GatewayBase {
* for a particular address. This is also used to determine the
* nonce of the particular address. Refer getNonce for the details.
*/
mapping(address /*address*/ => bytes32 /*messageHash*/) outboxActiveProcess;
mapping(address => bytes32) outboxActiveProcess;

/* modifiers */

/** checks that only organisation can call a particular function. */
modifier onlyOrganisation() {
require(
msg.sender == organisation,
"Only organisation can call the function"
);
_;
}
/* Modifiers */

/** checks that contract is activated */
modifier isActive() {
Expand All @@ -150,51 +142,44 @@ contract GatewayBase {
/* Constructor */

/**
* @notice Initialise the contract and set default values.
* @notice Initialize the contract and set default values.
*
* @param _core Core contract address.
* @param _bounty The amount that facilitator will stakes to initiate the
* stake process.
* @param _organisation Organisation address.
* @param _membersManager Address of a contract that manages workers.
*/
constructor(
CoreInterface _core,
uint256 _bounty,
address _organisation
IsMemberInterface _membersManager
)
Organized(_membersManager)
public
{
require(
address(_core) != address(0),
"Core contract address must not be zero."
);
require(
_organisation != address(0),
"Organisation address must not be zero."
);

core = _core;

bounty = _bounty;
organisation = _organisation;

}

/* external functions */
/* External functions */

/**
* @notice External function prove gateway/co-gateway.
*
* @dev proveGateway can be called by anyone to verify merkle proof of
* gateway/co-gateway contract address. Trust factor is brought by
* stateRoots mapping. stateRoot is committed in commitStateRoot
* function by mosaic process which is a trusted decentralized system
* running separately. It's important to note that in replay calls of
* proveGateway bytes _rlpParentNodes variable is not validated. In
* this case input storage root derived from merkle proof account
* nodes is verified with stored storage root of given blockHeight.
* GatewayProven event has parameter wasAlreadyProved to
* differentiate between first call and replay calls.
* @notice proveGateway can be called by anyone to verify merkle proof of
* gateway/co-gateway contract address. Trust factor is brought by
* stateRoots mapping. stateRoot is committed in commitStateRoot
* function by mosaic process which is a trusted decentralized system
* running separately. It's important to note that in replay calls of
* proveGateway bytes _rlpParentNodes variable is not validated. In
* this case input storage root derived from merkle proof account
* nodes is verified with stored storage root of given blockHeight.
* GatewayProven event has parameter wasAlreadyProved to
* differentiate between first call and replay calls.
*
* @param _blockHeight Block height at which Gateway/CoGateway is to be
* proven.
Expand Down Expand Up @@ -294,8 +279,8 @@ contract GatewayBase {
* @return uint256 proposed bounty amount.
*/
function initiateBountyAmountChange(uint256 _proposedBounty)
onlyOrganisation()
external
onlyOrganization
returns(uint256)
{
proposedBounty = _proposedBounty;
Expand All @@ -318,8 +303,8 @@ contract GatewayBase {
* @return previousBountyAmount_ previous bounty amount.
*/
function confirmBountyAmountChange()
onlyOrganisation()
external
onlyOrganization
returns (
uint256 changedBountyAmount_,
uint256 previousBountyAmount_
Expand Down Expand Up @@ -459,7 +444,7 @@ contract GatewayBase {
delete messages[previousMessageHash_];
}

// Update the active proccess.
// Update the active process.
outboxActiveProcess[_account] = _messageHash;

}
Expand Down
2 changes: 1 addition & 1 deletion contracts/gateway/MockMessageBus.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pragma solidity ^0.5.0;
// ----------------------------------------------------------------------------


import "../test/MockMerklePatriciaProof.sol";
import "../test/lib/MockMerklePatriciaProof.sol";
import "../lib/SafeMath.sol";
import "../lib/BytesLib.sol";

Expand Down
12 changes: 6 additions & 6 deletions contracts/gateway/UtilityToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import "./CoGatewayUtilityTokenInterface.sol";
* @title UtilityToken is an EIP20Token and implements UtilityTokenInterface.
*
* @notice This contract has mint and burn functions and can be called only
* by CoGateway. TODO: Add organisation details.
* by CoGateway. TODO: Add organization details.
*
*/
contract UtilityToken is
Expand All @@ -58,7 +58,7 @@ contract UtilityToken is

/* Modifiers */

/** checks that only organisation can call a particular function. */
/** checks that only organization can call a particular function. */
modifier onlyCoGateway() {
require(
msg.sender == coGateway,
Expand All @@ -72,7 +72,7 @@ contract UtilityToken is
/**
* @notice Contract constructor.
*
* @dev TODO: Sets Organisation with msg.sender address.
* @dev TODO: Sets Organization with msg.sender address.
*
* @param _symbol Symbol of token
* @param _name Name of token
Expand All @@ -87,7 +87,7 @@ contract UtilityToken is
)
public
EIP20Token(_symbol, _name, _decimals)
//TODO: add organisation
//TODO: add organization
{
require(
_valueToken != address(0),
Expand All @@ -102,15 +102,15 @@ contract UtilityToken is
/**
* @notice Sets the CoGateway contract address.
*
* @dev This will be set with zero gas. Can be called only by Organisation
* @dev This will be set with zero gas. Can be called only by Organization
*
* @param _coGatewayAddress CoGateway contract address
*
* @return `true` if CoGateway address was set
*/
function setCoGateway(address _coGatewayAddress)
external
//TODO: add organisation
//TODO: add organization
returns (bool)
{
require(
Expand Down
Loading