refactor contrats with aragonos
This commit is contained in:
43
scripts/add-contribution.js
Normal file
43
scripts/add-contribution.js
Normal file
@@ -0,0 +1,43 @@
|
||||
const promptly = require('promptly');
|
||||
|
||||
const ethers = require('ethers');
|
||||
const Kredits = require('../lib/kredits');
|
||||
|
||||
module.exports = async function(callback) {
|
||||
const networkId = parseInt(web3.version.network);
|
||||
const provider = new ethers.providers.Web3Provider(
|
||||
web3.currentProvider, { chainId: networkId }
|
||||
);
|
||||
const kredits = await new Kredits(provider, provider.getSigner()).init();
|
||||
|
||||
console.log(`Using Contributions at: ${kredits.Contribution.contract.address}`);
|
||||
|
||||
let contributor = await promptly.prompt('Contributor (address or id): ');
|
||||
let contributorId;
|
||||
if (contributor.length < 5) {
|
||||
contributorAccount = await kredits.Contributor.functions.getContributorAddressById(contributor);
|
||||
} else {
|
||||
contributorAccount = contributor;
|
||||
}
|
||||
console.log(`Creating a contribution for contributor Account #${contributorAccount}`);
|
||||
|
||||
let contributionAttributes = {
|
||||
contributorAccount,
|
||||
amount: await promptly.prompt('Amount: '),
|
||||
description: await promptly.prompt('Description: '),
|
||||
kind: await promptly.prompt('Kind: ', { default: 'dev' }),
|
||||
url: await promptly.prompt('URL: ', { default: '' })
|
||||
}
|
||||
|
||||
console.log("\nAdding contribution:");
|
||||
console.log(contributionAttributes);
|
||||
|
||||
kredits.Contribution.addContribution(contributionAttributes, { gasLimit: 300000 }).then((result) => {
|
||||
console.log("\n\nResult:");
|
||||
console.log(result);
|
||||
callback();
|
||||
}).catch((error) => {
|
||||
console.log('Failed to create contribution');
|
||||
callback(error);
|
||||
});
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
const Registry = artifacts.require('./Registry.sol');
|
||||
const promptly = require('promptly');
|
||||
|
||||
const ethers = require('ethers');
|
||||
@@ -11,39 +10,35 @@ async function prompt(message, options) {
|
||||
return await promptly.prompt(message, options);
|
||||
}
|
||||
|
||||
module.exports = function(callback) {
|
||||
Registry.deployed().then(async (registry) => {
|
||||
module.exports = async function(callback) {
|
||||
const networkId = parseInt(web3.version.network);
|
||||
const provider = new ethers.providers.Web3Provider(
|
||||
web3.currentProvider, { chainId: networkId }
|
||||
);
|
||||
const kredits = await new Kredits(provider, provider.getSigner()).init();
|
||||
|
||||
const networkId = parseInt(web3.version.network);
|
||||
const provider = new ethers.providers.Web3Provider(
|
||||
web3.currentProvider, { chainId: networkId }
|
||||
);
|
||||
const kredits = await Kredits.setup(provider, provider.getSigner());
|
||||
console.log(`Using contributors at: ${kredits.Contributor.contract.address}`);
|
||||
|
||||
console.log(`Using contributors at: ${kredits.Contributor.contract.address}`);
|
||||
let contributorAttributes = {
|
||||
account: await prompt('Contributor address: ', {}),
|
||||
name: await prompt('Name: '),
|
||||
isCore: await prompt('core? y/n') === 'y',
|
||||
kind: await prompt('Kind (default person): ', {default: 'person'}),
|
||||
url: await prompt('URL: '),
|
||||
github_username: await prompt('GitHub username: '),
|
||||
github_uid: await prompt('GitHub UID: '),
|
||||
wiki_username: await prompt('Wiki username: '),
|
||||
};
|
||||
|
||||
let contributorAttributes = {
|
||||
account: await prompt('Contributor address: ', {}),
|
||||
name: await prompt('Name: '),
|
||||
isCore: await prompt('core? y/n') === 'y',
|
||||
kind: await prompt('Kind (default person): ', {default: 'person'}),
|
||||
url: await prompt('URL: '),
|
||||
github_username: await prompt('GitHub username: '),
|
||||
github_uid: await prompt('GitHub UID: '),
|
||||
wiki_username: await prompt('Wiki username: '),
|
||||
};
|
||||
|
||||
console.log("\nAdding contributor:");
|
||||
console.log(contributorAttributes);
|
||||
|
||||
kredits.Contributor.add(contributorAttributes, { gasLimit: 250000 }).then((result) => {
|
||||
console.log("\n\nResult:");
|
||||
console.log(result);
|
||||
callback();
|
||||
}).catch((error) => {
|
||||
console.log('Failed to create contributor');
|
||||
callback(error);
|
||||
});
|
||||
console.log("\nAdding contributor:");
|
||||
console.log(contributorAttributes);
|
||||
|
||||
kredits.Contributor.add(contributorAttributes, { gasLimit: 250000 }).then((result) => {
|
||||
console.log("\n\nResult:");
|
||||
console.log(result);
|
||||
callback();
|
||||
}).catch((error) => {
|
||||
console.log('Failed to create contributor');
|
||||
callback(error);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,46 +1,43 @@
|
||||
const Registry = artifacts.require('./Registry.sol');
|
||||
const promptly = require('promptly');
|
||||
|
||||
const ethers = require('ethers');
|
||||
const Kredits = require('../lib/kredits');
|
||||
|
||||
module.exports = function(callback) {
|
||||
Registry.deployed().then(async (registry) => {
|
||||
const networkId = parseInt(web3.version.network);
|
||||
const provider = new ethers.providers.Web3Provider(
|
||||
web3.currentProvider, { chainId: networkId }
|
||||
);
|
||||
const kredits = await Kredits.setup(provider, provider.getSigner());
|
||||
module.exports = async function(callback) {
|
||||
const networkId = parseInt(web3.version.network);
|
||||
const provider = new ethers.providers.Web3Provider(
|
||||
web3.currentProvider, { chainId: networkId }
|
||||
);
|
||||
const kredits = await new Kredits(provider, provider.getSigner()).init();
|
||||
|
||||
console.log(`Using operator at: ${kredits.Operator.contract.address}`);
|
||||
console.log(`Using Proposal at: ${kredits.Proposal.contract.address}`);
|
||||
|
||||
let contributor = await promptly.prompt('Contributor (address or id): ');
|
||||
let contributorId;
|
||||
if (contributor.length < 5) {
|
||||
contributorId = contributor;
|
||||
} else {
|
||||
contributorId = await kredits.Contributor.functions.getContributorIdByAddress(contributor);
|
||||
}
|
||||
console.log(`Creating a proposal for contributor ID #${contributorId}`);
|
||||
let contributor = await promptly.prompt('Contributor (address or id): ');
|
||||
let contributorId;
|
||||
if (contributor.length < 5) {
|
||||
contributorId = contributor;
|
||||
} else {
|
||||
contributorId = await kredits.Contributor.functions.getContributorIdByAddress(contributor);
|
||||
}
|
||||
console.log(`Creating a proposal for contributor ID #${contributorId}`);
|
||||
|
||||
let contributionAttributes = {
|
||||
contributorId,
|
||||
amount: await promptly.prompt('Amount: '),
|
||||
description: await promptly.prompt('Description: '),
|
||||
kind: await promptly.prompt('Kind: ', { default: 'dev' }),
|
||||
url: await promptly.prompt('URL: ', { default: '' })
|
||||
}
|
||||
let contributionAttributes = {
|
||||
contributorId,
|
||||
amount: await promptly.prompt('Amount: '),
|
||||
description: await promptly.prompt('Description: '),
|
||||
kind: await promptly.prompt('Kind: ', { default: 'dev' }),
|
||||
url: await promptly.prompt('URL: ', { default: '' })
|
||||
}
|
||||
|
||||
console.log("\nAdding proposal:");
|
||||
console.log(contributionAttributes);
|
||||
console.log("\nAdding proposal:");
|
||||
console.log(contributionAttributes);
|
||||
|
||||
kredits.Operator.addProposal(contributionAttributes, { gasLimit: 300000 }).then((result) => {
|
||||
console.log("\n\nResult:");
|
||||
console.log(result);
|
||||
callback();
|
||||
}).catch((error) => {
|
||||
console.log('Failed to create proposal');
|
||||
console.log(error);
|
||||
});
|
||||
kredits.Proposal.addProposal(contributionAttributes, { gasLimit: 300000 }).then((result) => {
|
||||
console.log("\n\nResult:");
|
||||
console.log(result);
|
||||
callback();
|
||||
}).catch((error) => {
|
||||
console.log('Failed to create proposal');
|
||||
callback(error);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -4,13 +4,12 @@ const path = require('path');
|
||||
const contractsPath = path.join(__dirname, '..', 'build', 'contracts');
|
||||
const libPath = path.join(__dirname, '..', 'lib');
|
||||
const abisPath = path.join(libPath, 'abis');
|
||||
const addressesPath = path.join(libPath, 'addresses');
|
||||
|
||||
const files = [
|
||||
'Contributors',
|
||||
'Contributor',
|
||||
'Contribution',
|
||||
'Operator',
|
||||
'Registry',
|
||||
'Kernel',
|
||||
'Proposal',
|
||||
'Token'
|
||||
];
|
||||
|
||||
@@ -18,17 +17,6 @@ files.forEach((fileName) => {
|
||||
let file = require(`${contractsPath}/${fileName}.json`);
|
||||
let abiFile = path.join(abisPath, `${fileName}.json`);
|
||||
fs.writeFileSync(abiFile, JSON.stringify(file.abi));
|
||||
|
||||
if (fileName === 'Registry') {
|
||||
let addresseFile = path.join(addressesPath, `${fileName}.json`);
|
||||
let content = fs.readFileSync(addresseFile);
|
||||
let addresses = Object.keys(file.networks)
|
||||
.reduce((addresses, key) => {
|
||||
addresses[key] = file.networks[key].address;
|
||||
return addresses;
|
||||
}, JSON.parse(content));
|
||||
fs.writeFileSync(addresseFile, JSON.stringify(addresses));
|
||||
}
|
||||
});
|
||||
|
||||
console.log("Don't forget to reaload the JSON files from your application; i.e. restart kredits-web");
|
||||
|
||||
@@ -5,14 +5,12 @@ const ethers = require('ethers');
|
||||
const Kredits = require('../lib/kredits');
|
||||
|
||||
module.exports = function(callback) {
|
||||
const Registry = artifacts.require('./Registry.sol');
|
||||
Registry.deployed().then(async (registry) => {
|
||||
const networkId = parseInt(web3.version.network);
|
||||
const provider = new ethers.providers.Web3Provider(
|
||||
web3.currentProvider, { chainId: networkId }
|
||||
);
|
||||
const kredits = await Kredits.setup(provider, provider.getSigner());
|
||||
const networkId = parseInt(web3.version.network);
|
||||
const provider = new ethers.providers.Web3Provider(
|
||||
web3.currentProvider, { chainId: networkId }
|
||||
);
|
||||
|
||||
new Kredits(provider, provider.getSigner()).init().then(async function(kredits) {
|
||||
let contractName = await promptly.prompt('Contract Name: ');
|
||||
const contractWrapper = kredits[contractName];
|
||||
|
||||
|
||||
49
scripts/deploy-kit.js
Normal file
49
scripts/deploy-kit.js
Normal file
@@ -0,0 +1,49 @@
|
||||
const deployDAOFactory = require('@aragon/os/scripts/deploy-daofactory.js')
|
||||
const KreditsKit = artifacts.require('KreditsKit')
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const libPath = path.join(__dirname, '..', 'lib');
|
||||
const addressesPath = path.join(libPath, 'addresses');
|
||||
|
||||
const ensAddr = process.env.ENS
|
||||
|
||||
module.exports = async (callback) => {
|
||||
if (!ensAddr) {
|
||||
callback(new Error("ENS address not found in environment variable ENS"))
|
||||
}
|
||||
|
||||
deployDAOFactory(null, { artifacts, verbose: false })
|
||||
.catch(console.log)
|
||||
.then((result) => {
|
||||
const daoFactory = result.daoFactory
|
||||
|
||||
KreditsKit.new(daoFactory.address, ensAddr)
|
||||
.catch(console.log)
|
||||
.then((kreditsKit) => {
|
||||
console.log(kreditsKit.address)
|
||||
|
||||
kreditsKit.newInstance().then((ret) => {
|
||||
console.log(ret.logs);
|
||||
const installedEvents = ret.logs.filter(log => log.event === 'InstalledApp').map(log => log.args)
|
||||
const deployEvents = ret.logs.filter(log => log.event === 'DeployInstance').map(log => log.args)
|
||||
|
||||
if (deployEvents.length > 1) {
|
||||
callback(new Error("More than one DAO was deployed. Something is wrong"))
|
||||
}
|
||||
const daoAddress = deployEvents[0].dao;
|
||||
const networkId = parseInt(web3.version.network);
|
||||
|
||||
let addresseFile = path.join(addressesPath, `dao.json`);
|
||||
let addresses = JSON.parse(fs.readFileSync(addresseFile));
|
||||
|
||||
addresses[networkId] = daoAddress;
|
||||
fs.writeFileSync(addresseFile, JSON.stringify(addresses));
|
||||
|
||||
callback();
|
||||
}).catch((e) => {
|
||||
console.log(e);
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -1,18 +1,16 @@
|
||||
const REPL = require('repl');
|
||||
const promptly = require('promptly');
|
||||
|
||||
const ethers = require('ethers');
|
||||
const Kredits = require('../lib/kredits');
|
||||
|
||||
module.exports = function(callback) {
|
||||
const Registry = artifacts.require('./Registry.sol');
|
||||
Registry.deployed().then(async (registry) => {
|
||||
const networkId = parseInt(web3.version.network);
|
||||
const provider = new ethers.providers.Web3Provider(
|
||||
web3.currentProvider, { chainId: networkId }
|
||||
);
|
||||
const kredits = await Kredits.setup(provider, provider.getSigner());
|
||||
console.log(`defined variables: kredits, web3`);
|
||||
const networkId = parseInt(web3.version.network);
|
||||
const provider = new ethers.providers.Web3Provider(
|
||||
web3.currentProvider, { chainId: networkId }
|
||||
);
|
||||
|
||||
new Kredits(provider, provider.getSigner()).init().then((kredits) => {
|
||||
console.log(`Defined variables: kredits, web3`);
|
||||
let r = REPL.start();
|
||||
r.context.kredits = kredits;
|
||||
r.context.web3 = web3;
|
||||
|
||||
Reference in New Issue
Block a user