Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.
Open
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
52 changes: 52 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"extends" : [
"standard",
"plugin:promise/recommended",
"plugin:react/recommended"
],
"plugins": [
"promise"
],
"env": {
"browser" : true,
"node" : true,
"mocha" : true,
"jest" : true
},
"globals" : {
"artifacts": false,
"contract": false,
"assert": false,
"web3": false
},
"rules": {

// Strict mode
"strict": [2, "global"],

// Code style
"indent": [2, 2],
"quotes": [2, "single"],
"semi": ["error", "always"],
"space-before-function-paren": ["error", "always"],
"no-use-before-define": 0,
"eqeqeq": [2, "smart"],
"dot-notation": [2, {"allowKeywords": true, "allowPattern": ""}],
"no-redeclare": [2, {"builtinGlobals": true}],
"no-trailing-spaces": [2, { "skipBlankLines": true }],
"eol-last": 1,
"comma-spacing": [2, {"before": false, "after": true}],
"camelcase": [2, {"properties": "always"}],
"no-mixed-spaces-and-tabs": [2, "smart-tabs"],
"comma-dangle": [1, "always-multiline"],
"no-dupe-args": 2,
"no-dupe-keys": 2,
"no-debugger": 0,
"no-undef": 2,
"object-curly-spacing": [2, "always"],
"max-len": [2, 120, 2],
"generator-star-spacing": ["error", "before"],
"promise/avoid-new": 0,
"promise/always-return": 0
}
}
51 changes: 22 additions & 29 deletions deploy/deploy.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import DeployData from './deploy_data_util.js';
import Deployer from 'kernel/deploy/objects/Deployer';

const Basil = artifacts.require("./Basil.sol");
const BasilERC721 = artifacts.require("./BasilERC721.sol");
const Basil = artifacts.require('./Basil.sol');
const BasilERC721 = artifacts.require('./BasilERC721.sol');
const ProjectController = artifacts.require('ProjectController');

const PROJECT_OWNER = web3.eth.accounts[0];
Expand All @@ -16,31 +16,30 @@ let basilProxy;
const FORCE_RE_DEPLOY_ON_DEVELOPMENT = true;
const ZOS_ADDRESS = {
development: 0x212fbf392206bca0a478b9ed3253b08559b35903,
ropsten: 0x0
ropsten: 0x0,
};

async function deploy() {
async function deploy () {
data = DeployData.read(network);
await deployController();
await deployBasil();
await deployBasilERC721();
}

async function deployVersion(version, contractName, ContractKlazz) {
async function deployVersion (version, contractName, ContractKlazz) {
console.log(`deploying and registering version ${version} of ${contractName}...`);
const implementation = await Deployer.deployAndRegister(controller, ContractKlazz, contractName, version);
console.log(`implementation deployed, version: ${version}, at: ${implementation.address}`);
return implementation;
}

function forceReDeploy() {
return FORCE_RE_DEPLOY_ON_DEVELOPMENT && network === "development";
function forceReDeploy () {
return FORCE_RE_DEPLOY_ON_DEVELOPMENT && network === 'development';
}

async function deployBasil() {
async function deployBasil () {
const version = '0';
if(forceReDeploy() || !data.contracts || !data.contracts[BASIL_CONTRACT_NAME]) {

if (forceReDeploy() || !data.contracts || !data.contracts[BASIL_CONTRACT_NAME]) {
// Deploy and register implementation.
const implementation = await deployVersion(version, BASIL_CONTRACT_NAME, Basil);

Expand All @@ -54,25 +53,23 @@ async function deployBasil() {
PROJECT_NAME,
version,
['address'],
[PROJECT_OWNER]
[PROJECT_OWNER],
);
console.log(`deployed proxy: ${basilProxy.address}`);

// Save to disk.
data = DeployData.saveContractProxy(data, BASIL_CONTRACT_NAME, basilProxy.address, network);
data = DeployData.appendContractVersion(data, BASIL_CONTRACT_NAME, version, implementation.address, network);
}
else {
} else {
// TODO: the fact that the version is not found in the json does not necessarily mean it is not
// in the registry, which probably needs to be accounted for.
console.log('found Basil version 0, no need to deploy it.');
}
}

async function deployBasilERC721() {
async function deployBasilERC721 () {
const version = '1';
if(forceReDeploy() || !data.contracts.Basil.versions[version]) {

if (forceReDeploy() || !data.contracts.Basil.versions[version]) {
// Deploy and register implementation.
const implementation = await deployVersion(version, BASIL_CONTRACT_NAME, BasilERC721);

Expand All @@ -82,36 +79,32 @@ async function deployBasilERC721() {

// Save to disk.
DeployData.appendContractVersion(data, BASIL_CONTRACT_NAME, version, implementation.address, network);
}
else {
} else {
console.log('found Basil version 1, no need to deploy it.');
}
}

async function deployController() {
if(forceReDeploy() || !data.controllerAddress) {

async function deployController () {
if (forceReDeploy() || !data.controllerAddress) {
// Deploy a new project controller.
console.log(`did not find a project controller, deploying a new one...`);
console.log('did not find a project controller, deploying a new one...');
controller = await Deployer.projectController(
PROJECT_OWNER,
PROJECT_NAME,
ZOS_ADDRESS[network]
ZOS_ADDRESS[network],
);
console.log(`deployed new project controller: ${controller.address}`);

// Save to disk.
data = DeployData.saveController(data, network, controller.address);
}
else {

} else {
// Retrieve project controller.
console.log(`found project controller, reusing it...`);
console.log('found project controller, reusing it...');
controller = await ProjectController.at(data.controllerAddress);
console.log(`retrieved project controller: ${controller.address}`);
}
}

module.exports = function(cb) {
module.exports = function (cb) {
deploy().then(cb).catch(cb);
}
};
29 changes: 14 additions & 15 deletions deploy/deploy_data_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,60 @@ const fs = require('fs');

const DeployData = {

deployPath(network) {
deployPath (network) {
return `./deploy/deploy_data.${network}.json`;
},

read(network) {
read (network) {
let data;
const path = this.deployPath(network);
try {
const raw = fs.readFileSync(path, 'utf8');
data = JSON.parse(raw);
}
catch(err) {
} catch (err) {
data = {
controllerAddress: undefined,
contracts: {}
contracts: {},
};
};
return data;
},

write(data, network) {
write (data, network) {
const writeData = JSON.stringify(data, null, 2);
const path = this.deployPath(network);
fs.writeFileSync(path, writeData, 'utf8');
},

saveController(data, network, controllerAddress) {
saveController (data, network, controllerAddress) {
data.controllerAddress = controllerAddress;
this.write(data, network);
return data;
},

saveContractProxy(data, contractName, proxyAddress, network) {
saveContractProxy (data, contractName, proxyAddress, network) {
data = this.prepareContractEntry(data, contractName);
data.contracts[contractName].proxyAddress = proxyAddress;
this.write(data, network);
return data;
},

appendContractVersion(data, contractName, version, implementation, network) {
appendContractVersion (data, contractName, version, implementation, network) {
data = this.prepareContractEntry(data, contractName);
data.contracts[contractName].versions[version] = implementation;
this.write(data, network);
return data;
},

prepareContractEntry(data, contractName) {
if(!data.contracts) data.contracts = {};
if(data.contracts[contractName]) return data;
prepareContractEntry (data, contractName) {
if (!data.contracts) data.contracts = {};
if (data.contracts[contractName]) return data;
data.contracts[contractName] = {
proxyAddress: undefined,
versions: {}
versions: {},
};
return data;
}
}
},
};

export default DeployData;
4 changes: 2 additions & 2 deletions migrations/1_initial_migration.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Migrations = artifacts.require("Migrations");
var Migrations = artifacts.require('./Migrations.sol');

module.exports = function(deployer) {
module.exports = function (deployer) {
deployer.deploy(Migrations);
};
Loading