Skip to content

Commit

Permalink
Add remaining documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
hobofan committed Feb 11, 2019
1 parent 2c851f2 commit 2e480b3
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 53 deletions.
2 changes: 1 addition & 1 deletion src/ContractInteract/Anchor.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class Anchor {
* @param {Object} txOptions Transaction options.
*
* @returns {Promise<Anchor>} Promise containing the Anchor instance that
* has been deployed.
* has been deployed.
*/
static async deploy(
web3,
Expand Down
89 changes: 84 additions & 5 deletions src/ContractInteract/EIP20CoGateway.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
/**
* @typedef EIP20CoGatewaySetupConfig
*
* @property {string} valueToken The value token contract address.
* @property {string} utilityToken The utility token address that will be used for
* minting the utility token.
* @property {string} anchor Address of anchor to use for getting the state root of
* the auxiliary chain.
* @property {string} bounty The amount that facilitator will stakes to initiate the
* stake process.
* @property {string} organization Address of an organization contract.
* @property {string} gateway Address of EIP20Gateway on Origin.
* @property {string} burner Address where tokens will be burned.
* @property {string} messageBus Address of MessageBus contract
* to link into the contract bytecode.
* @property {string} gatewayLib Address of GatewayLib contract
* to link into the contract bytecode.
* @property {string} deployer Address to be used to send deployment
* transactions.
*/

'use strict';

const Web3 = require('web3');
Expand Down Expand Up @@ -74,7 +95,16 @@ class EIP20CoGateway {
this._redeemRawTx = this._redeemRawTx.bind(this);
}

// TODO: docs
/**
* Setup for EIP20CoGateway. Deploys EIP20CoGateway.
*
* @param {Object} web3 Web3 object.
* @param {EIP20CoGatewaySetupConfig} config EIP20CoGateway setup configuration.
* @param {Object} txOptions Transaction options.
*
* @returns {Promise<EIP20CoGateway>} Promise containing the EIP20CoGateway instance that
* has been set up.
*/
static setup(web3, config, txOptions = {}) {
EIP20CoGateway.validateSetupConfig(config);
validateConfigKeyExists(config, 'gateway', 'config');
Expand All @@ -84,7 +114,7 @@ class EIP20CoGateway {

return EIP20CoGateway.deploy(
web3,
config.valueToken, // TODO: valueToken -> baseToken
config.valueToken,
config.utilityToken,
config.anchor,
config.bounty,
Expand All @@ -97,7 +127,13 @@ class EIP20CoGateway {
);
}

// TODO: docs
/**
* Validate the setup configuration.
*
* @param {EIP20CoGatewaySetupConfig} config EIP20CoGateway setup configuration.
*
* @throws Will throw an error if setup configuration is incomplete.
*/
static validateSetupConfig(config) {
validateConfigExists(config);
validateConfigKeyExists(config, 'deployer', 'config');
Expand All @@ -111,7 +147,29 @@ class EIP20CoGateway {
validateConfigKeyExists(config, 'burner', 'config');
}

// TODO: docs
/**
* Deploys an EIP20CoGateway contract.
*
* @param {Object} web3 Web3 object.
* @param {string} valueToken The value token contract address.
* @param {string} utilityToken The utility token address that will be used for
* minting the utility token.
* @param {string} anchor Address of anchor to use for getting the state root of
* the auxiliary chain.
* @param {string} bounty The amount that facilitator will stakes to initiate the
* stake process.
* @param {string} organization Address of an organization contract.
* @param {string} gateway Address of EIP20Gateway on Origin.
* @param {string} burner Address where tokens will be burned.
* @param {string} messageBus Address of MessageBus contract
* to link into the contract bytecode.
* @param {string} gatewayLib Address of GatewayLib contract
* to link into the contract bytecode.
* @param {Object} txOptions Transaction options.
*
* @returns {Promise<EIP20CoGateway>} Promise containing the EIP20CoGateway instance that
* has been deployed.
*/
static async deploy(
web3,
valueToken,
Expand Down Expand Up @@ -149,7 +207,28 @@ class EIP20CoGateway {
});
}

// TODO: docs
/**
* Raw transaction object for {@link EIP20CoGateway#deploy}
*
* @param {Object} web3 Web3 object.
* @param {string} valueToken The value token contract address.
* @param {string} utilityToken The utility token address that will be used for
* minting the utility token.
* @param {string} anchor Address of anchor to use for getting the state root of
* the auxiliary chain.
* @param {string} bounty The amount that facilitator will stakes to initiate the
* stake process.
* @param {string} organization Address of an organization contract.
* @param {string} gateway Address of EIP20Gateway on Origin.
* @param {string} burner Address where tokens will be burned.
* @param {string} messageBus Address of MessageBus contract
* to link into the contract bytecode.
* @param {string} gatewayLib Address of GatewayLib contract
* to link into the contract bytecode.
* @param {Object} txOptions Transaction options.
*
* @returns {Promise<Object>} Promise that resolves to raw transaction object.
*/
static deployRawTx(
web3,
valueToken,
Expand Down
146 changes: 103 additions & 43 deletions src/ContractInteract/EIP20Gateway.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
/**
* @typedef EIP20GatewaySetupConfig
*
* @property {string} token The ERC20 token contract address that will be
* staked and corresponding utility tokens will be minted
* in auxiliary chain.
* @property {string} baseToken The ERC20 token address that will be used for
* staking bounty from the facilitators.
* @property {string} anchor Address of anchor to use for getting the state root of
* the auxiliary chain.
* @property {string} bounty The amount that facilitator will stakes to initiate the
* stake process.
* @property {string} organization Address of an organization contract.
* @property {string} burner Address where tokens will be burned.
* @property {string} messageBus Address of MessageBus contract
* to link into the contract bytecode.
* @property {string} gatewayLib Address of GatewayLib contract
* to link into the contract bytecode.
* @property {string} deployer Address to be used to send deployment
* transactions.
* @property {string} organizationOwner Address of owner of `organization`.
*/

'use strict';

const Web3 = require('web3');
Expand Down Expand Up @@ -79,40 +102,27 @@ class EIP20Gateway {
this.activateGatewayRawTx = this.activateGatewayRawTx.bind(this);
}

/*
//gatewayConfig
{
"deployer": "0x...",
"organization": "0x...",
"anchor": "0x....",
"bounty": "123456",
"messageBus": "0x....",
"gatewayLib": "0x....",
"simpleToken": "0x....",
"organizationOwner": "0x....",
}
//coGatewayConfig
{
"deployer": "0x...",
"token": "0x...",
"baseToken": "0x...",
"organization": "0x...",
"anchor": "0x....",
"bounty": "123456",
"messageBus": "0x....",
"gatewayLib": "0x....",
"ostPrime": "0x...."
}
*/

// TODO: docs
/**
* Setup for EIP20Gateway. Deploys EIP20Gateway and EIP20CoGateway,
* and links them.
*
* @param {Object} originWeb3 Web3 object.
* @param {Object} auxiliaryWeb3 Web3 object.
* @param {EIP20GatewaySetupConfig} gatewayConfig EIP20Gateway setup configuration.
* @param {EIP20CoGatewaySetupConfig} coGatewayConfig EIP20CoGateway setup configuration.
* @param {Object} originTxOptions Transaction options on Origin.
* @param {Object} auxiliaryTxOptions Transaction options on Auxiliary.
*
* @returns {Promise<EIP20Gateway>} Promise containing the EIP20Gateway instance that
* has been set up.
*/
static setup(
originWeb3,
auxiliaryWeb3,
gatewayConfig,
coGatewayConfig,
gatewayTxOptions = {},
coGatewayTxOptions = {},
originTxOptions = {},
auxiliaryTxOptions = {},
) {
if (!gatewayConfig) {
throw new Error('Mandatory parameter "gatewayConfig" missing. ');
Expand Down Expand Up @@ -142,10 +152,10 @@ class EIP20Gateway {
EIP20Gateway.validateSetupConfig(gatewayConfig);
EIP20CoGateway.validateSetupConfig(coGatewayConfig);

const gatewayDeployParams = Object.assign({}, gatewayTxOptions);
const gatewayDeployParams = Object.assign({}, originTxOptions);
gatewayDeployParams.from = gatewayConfig.deployer;

let gatewayDeploy = EIP20Gateway.deploy(
const gatewayDeploy = EIP20Gateway.deploy(
originWeb3,
gatewayConfig.token,
gatewayConfig.baseToken,
Expand All @@ -165,7 +175,7 @@ class EIP20Gateway {
return EIP20CoGateway.setup(
auxiliaryWeb3,
coGatewayConfig,
coGatewayTxOptions,
auxiliaryTxOptions,
);
});

Expand All @@ -186,7 +196,13 @@ class EIP20Gateway {
return gatewayActivation;
}

// TODO: docs
/**
* Validate the setup configuration.
*
* @param {EIP20GatewaySetupConfig} config EIP20Gateway setup configuration.
*
* @throws Will throw an error if setup configuration is incomplete.
*/
static validateSetupConfig(gatewayConfig) {
validateConfigKeyExists(gatewayConfig, 'deployer', 'gatewayConfig');
validateConfigKeyExists(gatewayConfig, 'organization', 'gatewayConfig');
Expand All @@ -203,7 +219,30 @@ class EIP20Gateway {
);
}

// TODO: docs
/**
* Deploys an EIP20Gateway contract.
*
* @param {Object} web3 Web3 object.
* @param {string} token The ERC20 token contract address that will be
* staked and corresponding utility tokens will be minted
* in auxiliary chain.
* @param {string} baseToken The ERC20 token address that will be used for
* staking bounty from the facilitators.
* @param {string} anchor Address of anchor to use for getting the state root of
* the auxiliary chain.
* @param {string} bounty The amount that facilitator will stakes to initiate the
* stake process.
* @param {string} organization Address of an organization contract.
* @param {string} burner Address where tokens will be burned.
* @param {string} messageBus Address of MessageBus contract
* to link into the contract bytecode.
* @param {string} gatewayLib Address of GatewayLib contract
* to link into the contract bytecode.
* @param {Object} txOptions Transaction options.
*
* @returns {Promise<EIP20Gateway>} Promise containing the EIP20Gateway instance that
* has been deployed.
*/
static async deploy(
web3,
token,
Expand All @@ -212,8 +251,8 @@ class EIP20Gateway {
bounty,
organization,
burner,
messageBusAddress,
gatewayLibAddress,
messageBus,
gatewayLib,
txOptions,
) {
const tx = EIP20Gateway.deployRawTx(
Expand All @@ -224,8 +263,8 @@ class EIP20Gateway {
bounty,
organization,
burner,
messageBusAddress,
gatewayLibAddress,
messageBus,
gatewayLib,
);

const _txOptions = txOptions;
Expand All @@ -239,7 +278,28 @@ class EIP20Gateway {
});
}

// TODO: docs
/**
* Raw transaction object for {@link EIP20Gateway#deploy}
*
* @param {Object} web3 Web3 object.
* @param {string} token The ERC20 token contract address that will be
* staked and corresponding utility tokens will be minted
* in auxiliary chain.
* @param {string} baseToken The ERC20 token address that will be used for
* staking bounty from the facilitators.
* @param {string} anchor Address of anchor to use for getting the state root of
* the auxiliary chain.
* @param {string} bounty The amount that facilitator will stakes to initiate the
* stake process.
* @param {string} organization Address of an organization contract.
* @param {string} burner Address where tokens will be burned.
* @param {string} messageBus Address of MessageBus contract
* to link into the contract bytecode.
* @param {string} gatewayLib Address of GatewayLib contract
* to link into the contract bytecode.
*
* @returns {Promise<Object>} Promise that resolves to raw transaction object.
*/
static deployRawTx(
web3,
token,
Expand All @@ -248,15 +308,15 @@ class EIP20Gateway {
bounty,
organization,
burner,
messageBusAddress,
gatewayLibAddress,
messageBus,
gatewayLib,
) {
const messageBusLibInfo = {
address: messageBusAddress,
address: messageBus,
name: 'MessageBus',
};
const gatewayLibInfo = {
address: gatewayLibAddress,
address: gatewayLib,
name: 'GatewayLib',
};

Expand Down
2 changes: 1 addition & 1 deletion src/ContractInteract/OSTPrime.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class OSTPrime {
}

/**
* Raw transaction for {@link OSTPrime#setup}.
* Raw transaction for {@link OSTPrime#deploy}.
*
* @param {Web3} web3 Web3 object.
* @param {string} valueToken Address of EIP20 Token on Origin chain.
Expand Down
Loading

0 comments on commit 2e480b3

Please sign in to comment.