Compare commits

..

5 Commits

Author SHA1 Message Date
e2d5d704ce fix typo 2019-09-23 00:47:42 +01:00
e0372d3eb4 add kit test script 2019-09-20 09:38:53 +01:00
42c469bbc6 clean 2019-09-16 12:32:22 +01:00
d4b7dbf99d add unit tests 2019-09-13 15:01:53 +01:00
1fd40dbf84 add aragon vault app to KreditsKit 2019-08-27 15:30:35 +01:00
45 changed files with 99697 additions and 21967 deletions

View File

@@ -1,4 +0,0 @@
template: |
## Changes
$CHANGES

View File

@@ -22,16 +22,11 @@ install:
before_script:
- npm run devchain &
- sleep 10
script:
- npm run lint:wrapper
- npm run lint:contract-tests
# FIXME Fix tests
# - npm run test:token
# - npm run test:contributor
# - npm run test:contribution
# - npm run test:proposal
- npm run test
branches:
only:

View File

@@ -63,26 +63,21 @@ if you want to increase the block time to 10 seconds you can add
$ npm run devchain
$ ipfs daemon
2. Compile contracts
(compiled contracts will be in `/build`)
$ npm run compile-contracts
3. Deploy each app to the devchain
2. Deploy each app to the devchain
(make sure you've run `npm install` for every app - see installation)
$ npm run deploy:apps
4. Deploy a new KreditsKit and create a new DAO with the latest app versions
3. Deploy a new KreditsKit and create a new DAO with the latest app versions
$ npm run deploy:kit
$ npm run deploy:dao
5. Execute seeds to create demo contributors, contributions, etc. (optional)
4. Execute seeds to create demo contributors, contributions, etc. (optional)
$ npm run seeds
**Step 2-5 is also summarized in `npm run bootstrap`**
**Step 2-4 is also summarized in `npm run bootstrap`**
If you want to reset your local setup:
@@ -170,14 +165,8 @@ Deploys a new KreditsKit that allows to create a new DAO
or
$ npm run deploy:kit
#### Kredits configuration options:
Configuration options can be set in an environment specific `kredits` object in the `arapp.json` or using a CLI parameter.
* daoFactory: Ethereum address of the used DAO Factory. On public networks we use [official aragon factories](https://github.com/aragon/deployments/tree/master/environments/)
* apmDomain: the ENS domain of the aragonPM (normally `open.aragonpm.eth`)
(please also see the [arapp.json related configuration options](https://hack.aragon.org/docs/cli-global-confg#the-arappjson-file))
`ENS` address is required as environment variable.
`DAO_FACTORY` can optionally be set as environment variable. (see aragon)
### new-dao.js

View File

@@ -21,8 +21,8 @@ contract Contribution is AragonApp {
bytes32 public constant KERNEL_APP_ADDR_NAMESPACE = 0xd6f028ca0e8edb4a8c9757ca4fdccab25fa1e0317da1188108f7d2dee14902fb;
// ensure alphabetic order
enum Apps { Contribution, Contributor, Proposal, Token }
bytes32[4] public appIds;
enum Apps { Contribution, Contributor, Proposal, Token, Vault }
bytes32[5] public appIds;
struct ContributionData {
uint32 contributorId;
@@ -54,7 +54,7 @@ contract Contribution is AragonApp {
event ContributionClaimed(uint32 id, uint32 indexed contributorId, uint32 amount);
event ContributionVetoed(uint32 id, address vetoedByAccount);
function initialize(bytes32[4] _appIds) public onlyInit {
function initialize(bytes32[5] _appIds) public onlyInit {
appIds = _appIds;
blocksToWait = 40320; // 7 days; 15 seconds block time
initialized();

File diff suppressed because it is too large Load Diff

View File

@@ -3,12 +3,13 @@
"version": "1.0.0",
"description": "",
"dependencies": {
"@aragon/os": "^4.4.0"
"@aragon/os": "^4.2.0",
"@aragon/cli": "^5.9.6"
},
"devDependencies": {
"@aragon/test-helpers": "^2.1.0",
"eth-gas-reporter": "^0.2.17",
"ganache-cli": "^6.9.1",
"@aragon/test-helpers": "^2.0.0",
"eth-gas-reporter": "^0.2.0",
"ganache-cli": "^6.4.3",
"solidity-coverage": "^0.5.11"
},
"scripts": {
@@ -25,7 +26,7 @@
"publish:minor": "aragon apm publish minor",
"publish:major": "aragon apm publish major",
"versions": "aragon apm versions",
"test": "truffle test"
"test": "aragon contracts test"
},
"keywords": []
}

View File

@@ -28,14 +28,14 @@ contract Contributor is AragonApp {
uint32 public contributorsCount;
// ensure alphabetic order
enum Apps { Contribution, Contributor, Proposal, Token }
bytes32[4] public appIds;
enum Apps { Contribution, Contributor, Proposal, Token, Vault }
bytes32[5] public appIds;
event ContributorProfileUpdated(uint32 id, bytes32 oldHashDigest, bytes32 newHashDigest); // what should be logged
event ContributorAccountUpdated(uint32 id, address oldAccount, address newAccount);
event ContributorAdded(uint32 id, address account);
function initialize(address root,bytes32[4] _appIds) public onlyInit {
function initialize(address root, bytes32[5] _appIds) public onlyInit {
appIds = _appIds;
initialized();

File diff suppressed because it is too large Load Diff

View File

@@ -3,13 +3,14 @@
"version": "1.0.0",
"description": "",
"dependencies": {
"@aragon/os": "^4.4.0"
"@aragon/os": "^4.2.0",
"@aragon/cli": "^5.9.6"
},
"devDependencies": {
"@aragon/test-helpers": "^2.1.0",
"eth-gas-reporter": "^0.2.17",
"ganache-cli": "^6.9.1",
"solidity-coverage": "^0.5.11"
"eth-gas-reporter": "^0.2.0",
"ganache-cli": "^6.4.3",
"solidity-coverage": "^0.5.11",
"@aragon/test-helpers": "^2.0.0"
},
"scripts": {
"start": "npm run start:aragon:ipfs",
@@ -25,7 +26,7 @@
"publish:minor": "aragon apm publish minor",
"publish:major": "aragon apm publish major",
"versions": "aragon apm versions",
"test": "truffle test"
"test": "aragon contracts test"
},
"keywords": []
}

View File

@@ -21,8 +21,8 @@ contract('Contributor app', (accounts) => {
aclBase = await getContract('ACL').new();
daoFactory = await getContract('DAOFactory').new(kernelBase.address, aclBase.address, ZERO_ADDR);
r = await daoFactory.newDAO(root);
dao = await getContract('Kernel').at(r.logs.filter(l => l.event == 'DeployDAO')[0].args.dao);
acl = await getContract('ACL').at(await dao.acl());
dao = getContract('Kernel').at(r.logs.filter(l => l.event == 'DeployDAO')[0].args.dao);
acl = getContract('ACL').at(await dao.acl());
//create dao mamnager permission for coin owner
await acl.createPermission(
@@ -63,7 +63,7 @@ contract('Contributor app', (accounts) => {
root,
{ from: root }
);
});
describe("Owner default permissions", async () => {
@@ -71,7 +71,7 @@ contract('Contributor app', (accounts) => {
let manageContributorPermission = await acl.hasPermission(root, contributor.address, await contributor.MANAGE_CONTRIBUTORS_ROLE());
// eslint-disable-next-line no-undef
assert.equal(manageContributorPermission, true);
});
});
});
describe("Add contributor", async () => {

View File

@@ -20,8 +20,8 @@ contract Proposal is AragonApp {
bytes32 public constant KERNEL_APP_ADDR_NAMESPACE = 0xd6f028ca0e8edb4a8c9757ca4fdccab25fa1e0317da1188108f7d2dee14902fb;
// ensure alphabetic order
enum Apps { Contribution, Contributor, Proposal, Token }
bytes32[4] public appIds;
enum Apps { Contribution, Contributor, Proposal, Token, Vault }
bytes32[5] public appIds;
struct Proposal {
address creatorAccount;
@@ -46,7 +46,7 @@ contract Proposal is AragonApp {
event ProposalVoted(uint32 id, uint32 voterId, uint16 totalVotes);
event ProposalExecuted(uint32 id, uint32 contributorId, uint32 amount);
function initialize(bytes32[4] _appIds) public onlyInit {
function initialize(bytes32[5] _appIds) public onlyInit {
appIds = _appIds;
initialized();
}

File diff suppressed because it is too large Load Diff

View File

@@ -3,12 +3,13 @@
"version": "1.0.0",
"description": "",
"dependencies": {
"@aragon/os": "^4.4.0"
"@aragon/os": "^4.2.0",
"@aragon/cli": "^5.9.6"
},
"devDependencies": {
"@aragon/test-helpers": "^2.1.0",
"eth-gas-reporter": "^0.2.17",
"ganache-cli": "^6.9.1",
"@aragon/test-helpers": "^2.0.0",
"eth-gas-reporter": "^0.2.0",
"ganache-cli": "^6.4.3",
"solidity-coverage": "^0.5.11"
},
"scripts": {
@@ -25,7 +26,7 @@
"publish:minor": "aragon apm publish minor",
"publish:major": "aragon apm publish major",
"versions": "aragon apm versions",
"test": "truffle test"
"test": "aragon contracts test"
},
"keywords": []
}

View File

@@ -7,12 +7,12 @@ contract Token is ERC20Token, AragonApp {
bytes32 public constant MINT_TOKEN_ROLE = keccak256("MINT_TOKEN_ROLE");
// ensure alphabetic order
enum Apps { Contribution, Contributor, Proposal, Token }
bytes32[4] public appIds;
enum Apps { Contribution, Contributor, Proposal, Token, Vault }
bytes32[5] public appIds;
event LogMint(address indexed recipient, uint256 amount, uint32 contributionId);
function initialize(bytes32[4] _appIds) public onlyInit {
function initialize(bytes32[5] _appIds) public onlyInit {
appIds = _appIds;
name = 'Kredits';
symbol = '₭S';

File diff suppressed because it is too large Load Diff

View File

@@ -3,12 +3,13 @@
"version": "1.0.0",
"description": "",
"dependencies": {
"@aragon/os": "^4.4.0"
"@aragon/os": "^4.2.0",
"@aragon/cli": "^5.9.6"
},
"devDependencies": {
"@aragon/test-helpers": "^2.1.0",
"eth-gas-reporter": "^0.2.17",
"ganache-cli": "^6.9.1",
"@aragon/test-helpers": "^2.0.0",
"eth-gas-reporter": "^0.2.0",
"ganache-cli": "^6.4.3",
"solidity-coverage": "^0.5.11"
},
"scripts": {
@@ -25,7 +26,7 @@
"publish:minor": "aragon apm publish minor",
"publish:major": "aragon apm publish major",
"versions": "aragon apm versions",
"test": "truffle test"
"test": "aragon contracts test"
},
"keywords": []
}

View File

@@ -21,8 +21,8 @@ contract('Token app', (accounts) => {
aclBase = await getContract('ACL').new();
daoFactory = await getContract('DAOFactory').new(kernelBase.address, aclBase.address, ZERO_ADDR);
r = await daoFactory.newDAO(root);
dao = await getContract('Kernel').at(r.logs.filter(l => l.event == 'DeployDAO')[0].args.dao);
acl = await getContract('ACL').at(await dao.acl());
dao = getContract('Kernel').at(r.logs.filter(l => l.event == 'DeployDAO')[0].args.dao);
acl = getContract('ACL').at(await dao.acl());
//create dao mamnager permission for coin owner
await acl.createPermission(
@@ -63,7 +63,7 @@ contract('Token app', (accounts) => {
root,
{ from: root }
);
});
describe("Owner default space permissions", async () => {
@@ -71,7 +71,7 @@ contract('Token app', (accounts) => {
let tokenIssuerPermission = await acl.hasPermission(root, token.address, await token.MINT_TOKEN_ROLE());
// eslint-disable-next-line no-undef
assert.equal(tokenIssuerPermission, true);
});
});
});
describe("Token issuing", async () => {

View File

@@ -34,6 +34,7 @@
"environments": {
"development": {
"network": "development",
"apm": "open.aragonpm.eth",
"registry": "0x5f6f7e8cc7346a11ca2def8f827b7a0b612c56a1",
"appName": "dummy.open.aragonpm.eth"
},
@@ -41,10 +42,9 @@
"network": "rinkeby",
"registry": "0x98Df287B6C145399Aaa709692c8D308357bC085D",
"wsRPC": "wss://rinkeby.eth.aragon.network/ws",
"daoFactory": "0x2298d27a9b847c681d2b2c2828ab9d79013f5f1d",
"appName": "dummy.open.aragonpm.eth",
"kredits": {
"daoFactory": "0x2298d27a9b847c681d2b2c2828ab9d79013f5f1d"
}
"apm": "open.aragonpm.eth"
},
"kovan": {
"network": "kovan",
@@ -52,7 +52,8 @@
},
"default": {
"network": "development",
"appName": "dummy.aragonpm.eth"
"appName": "dummy.aragonpm.eth",
"apm": "open.aragonpm.eth"
}
},
"path": "contracts/misc/DummyApp.sol"

View File

@@ -6,6 +6,8 @@ import "@aragon/os/contracts/acl/ACL.sol";
import "@aragon/kits-base/contracts/KitBase.sol";
import "@aragon/apps-vault/contracts/Vault.sol";
import "../apps/contribution/contracts/Contribution.sol";
import "../apps/contributor/contracts/Contributor.sol";
import "../apps/token/contracts/Token.sol";
@@ -14,13 +16,13 @@ import "../apps/proposal/contracts/Proposal.sol";
contract KreditsKit is KitBase {
// ensure alphabetic order
enum Apps { Contribution, Contributor, Proposal, Token }
bytes32[4] public appIds;
enum Apps { Contribution, Contributor, Proposal, Token, Vault }
bytes32[5] public appIds;
event DeployInstance(address dao);
event InstalledApp(address dao, address appProxy, bytes32 appId);
constructor (DAOFactory _fac, ENS _ens, bytes32[4] _appIds) public KitBase(_fac, _ens) {
constructor (DAOFactory _fac, ENS _ens, bytes32[5] _appIds) public KitBase(_fac, _ens) {
appIds = _appIds;
}
@@ -44,6 +46,9 @@ contract KreditsKit is KitBase {
Proposal proposal = Proposal(_installApp(dao, appIds[uint8(Apps.Proposal)]));
proposal.initialize(appIds);
Vault vault = Vault(_installApp(dao, appIds[uint8(Apps.Vault)]));
vault.initialize();
acl.createPermission(root, contribution, contribution.ADD_CONTRIBUTION_ROLE(), this);
acl.createPermission(root, contribution, contribution.VETO_CONTRIBUTION_ROLE(), this);
acl.grantPermission(proposal, contribution, contribution.ADD_CONTRIBUTION_ROLE());
@@ -72,6 +77,10 @@ contract KreditsKit is KitBase {
acl.grantPermission(contribution, token, token.MINT_TOKEN_ROLE());
acl.setPermissionManager(root, token, token.MINT_TOKEN_ROLE());
// Vault permissions
acl.createPermission(root, vault, vault.TRANSFER_ROLE(), this);
//TODO: grant rewards app permission to transfer funds
//acl.grantPermission(rewards, vault, vault.TRANSFER_ROLE());
cleanupDAOPermissions(dao, acl, root);

16
contracts/test/Spoof.sol Normal file
View File

@@ -0,0 +1,16 @@
pragma solidity ^0.4.24;
import "@aragon/os/contracts/acl/ACL.sol";
import "@aragon/os/contracts/kernel/Kernel.sol";
import "@aragon/os/contracts/factory/DAOFactory.sol";
// You might think this file is a bit odd, but let me explain.
// We only use for now those imported contracts in our tests, which
// means Truffle will not compile them for us, because they are from
// an external dependency.
// solium-disable-next-line no-empty-blocks
contract Spoof {
// ...
}

View File

@@ -5,7 +5,7 @@ class Acl extends Base {
hasPermission (fromAddress, contractAddress, roleID, params = null) {
let roleHash = EthersUtils.keccak256(EthersUtils.toUtf8Bytes(roleID));
return this.hasPermission(
return this.functions.hasPermission(
fromAddress,
contractAddress,
roleHash,

View File

@@ -1,13 +1,10 @@
const deprecate = require('../utils/deprecate');
class Base {
constructor (contract) {
this.contract = contract;
}
get functions () {
deprecate('The property `functions` is deprecated. contract functions are now directly defined on the ethers contract object. https://github.com/ethers-io/ethers.js/issues/920#issuecomment-650836642');
return this.contract;
return this.contract.functions;
}
get address () {

View File

@@ -4,33 +4,33 @@ const deprecate = require('../utils/deprecate');
class Contribution extends Record {
get count () {
return this.contract.contributionsCount();
return this.functions.contributionsCount();
}
getById (id) {
return this.contract.getContribution(id)
return this.functions.getContribution(id)
.then(data => {
return this.ipfs.catAndMerge(data, ContributionSerializer.deserialize);
});
}
getData (id) {
return this.contract.getContribution(id);
return this.functions.getContribution(id);
}
getByContributorId (contributorId) {
return this.contract.getContributorAddressById(contributorId)
return this.functions.getContributorAddressById(contributorId)
.then(address => this.getByContributorAddress(address));
}
getByContributorAddress (address) {
return this.contract.balanceOf(address)
return this.functions.balanceOf(address)
.then(async (balance) => {
const count = balance.toNumber();
const contributions = [];
for (let index = 0; index < count; index++) {
const id = await this.contract.tokenOfOwnerByIndex(address, index);
const id = await this.functions.tokenOfOwnerByIndex(address, index);
const contribution = await this.getById(id);
contributions.push(contribution);
}
@@ -58,7 +58,7 @@ class Contribution extends Record {
ipfsHashAttr.hashSize,
];
return this.contract.add(...contribution, callOptions);
return this.functions.add(...contribution, callOptions);
});
}

View File

@@ -4,20 +4,19 @@ const formatKredits = require('../utils/format-kredits');
class Contributor extends Record {
get count () {
return this.contract.contributorsCount();
return this.functions.contributorsCount();
}
getById (id) {
return this.contract.getContributorById(id)
.then(contractData => {
let data = {...contractData};
return this.functions.getContributorById(id)
.then(data => {
data.balanceInt = formatKredits(data.balance);
return this.ipfs.catAndMerge(data, ContributorSerializer.deserialize);
});
}
getData (id) {
return this.contract.getContributorById(id);
return this.functions.getContributorById(id);
}
filterByAccount (search) {
@@ -62,7 +61,7 @@ class Contributor extends Record {
ipfsHashAttr.hashSize,
];
return this.contract.addContributor(...contributor, callOptions);
return this.functions.addContributor(...contributor, callOptions);
});
}
@@ -79,7 +78,7 @@ class Contributor extends Record {
return this.ipfs
.add(jsonStr)
.then(ipfsHashAttr => {
return this.contract.updateContributorProfileHash(
return this.functions.updateContributorProfileHash(
contributorId,
ipfsHashAttr.hashDigest,
ipfsHashAttr.hashFunction,

View File

@@ -11,9 +11,9 @@ class Kernel extends Base {
getApp (appName) {
if (appName === 'Acl') {
return this.contract.acl();
return this.functions.acl();
}
return this.contract.getApp(KERNEL_APP_ADDR_NAMESPACE, this.appNamehash(appName));
return this.functions.getApp(KERNEL_APP_ADDR_NAMESPACE, this.appNamehash(appName));
}
appNamehash (appName) {

View File

@@ -4,11 +4,11 @@ const deprecate = require('../utils/deprecate');
class Proposal extends Record {
get count () {
return this.contract.proposalsCount();
return this.functions.proposalsCount();
}
getById (id) {
return this.contract.getProposal(id)
return this.functions.getProposal(id)
.then(data => {
return this.ipfs.catAndMerge(data, ContributionSerializer.deserialize);
});
@@ -33,7 +33,7 @@ class Proposal extends Record {
ipfsHashAttr.hashSize,
];
return this.contract.addProposal(...proposal, callOptions);
return this.functions.addProposal(...proposal, callOptions);
});
}

View File

@@ -30,11 +30,11 @@ class KreditsKit {
appIdFor (contractName) {
// see appIds in KreditsKit.sol for more details
const knownContracts = ['Contribution', 'Contributor', 'Proposal', 'Token'];
return this.contract.appIds(knownContracts.indexOf(contractName));
return this.contract.functions.appIds(knownContracts.indexOf(contractName));
}
newDAO (options = {}) {
return this.contract.newInstance(options).then(transaction => {
return this.contract.functions.newInstance(options).then(transaction => {
return transaction.wait().then(result => {
const deployEvent = result.events.find(e => e.event === 'DeployInstance');
return {

View File

@@ -28,7 +28,7 @@ class Contributor {
github_username,
gitea_username,
wiki_username,
zoom_display_name,
accounts,
} = this;
let data = {
@@ -36,7 +36,7 @@ class Contributor {
'@type': 'Contributor',
kind,
name,
accounts: [],
accounts: accounts || [],
};
if (url) {
@@ -68,13 +68,6 @@ class Contributor {
});
}
if (zoom_display_name) {
data.accounts.push({
'site': 'zoom.us',
'username': zoom_display_name,
});
}
// Write it pretty to ipfs
return JSON.stringify(data, null, 2);
}
@@ -104,11 +97,10 @@ class Contributor {
accounts,
} = JSON.parse(serialized.toString('utf8'));
let github_username, github_uid, gitea_username, wiki_username, zoom_display_name;
let github_username, github_uid, gitea_username, wiki_username;
let github = accounts.find(a => a.site === 'github.com');
let gitea = accounts.find(a => a.site === 'gitea.kosmos.org');
let wiki = accounts.find(a => a.site === 'wiki.kosmos.org');
let zoom = accounts.find(a => a.site === 'zoom.us');
if (github) {
(({ username: github_username, uid: github_uid} = github));
@@ -119,9 +111,6 @@ class Contributor {
if (wiki) {
(({ username: wiki_username } = wiki));
}
if (zoom) {
(({ username: zoom_display_name } = zoom));
}
return {
name,
@@ -132,7 +121,6 @@ class Contributor {
github_username,
gitea_username,
wiki_username,
zoom_display_name,
ipfsData: serialized,
};
}

View File

@@ -11,8 +11,7 @@ class IPFS {
this._ipfsAPI = ipfsClient(config);
}
catAndMerge (contractData, deserialize) {
let data = {...contractData}; // data from ethers.js is not extensible. this copy the attributes in a new object
catAndMerge (data, deserialize) {
// if no hash details are found simply return the data; nothing to merge
if (!data.hashSize || data.hashSize === 0) {
return data;
@@ -37,7 +36,7 @@ class IPFS {
cat (hashData) {
let ipfsHash = hashData; // default - if it is a string
if (Object.prototype.hasOwnProperty.call(hashData, 'hashSize')) {
if (hashData.hasOwnProperty('hashSize')) {
ipfsHash = this.encodeHash(hashData);
}
if (this._config['gatewayUrl']) {
@@ -49,7 +48,7 @@ class IPFS {
pin (hashData) {
let ipfsHash = hashData; // default - if it is a string
if (Object.prototype.hasOwnProperty.call(hashData, 'hashSize')) {
if (hashData.hasOwnProperty('hashSize')) {
ipfsHash = this.encodeHash(hashData);
}
return this._ipfsAPI.pin.add(multihashes.toB58String(ipfsHash));

6575
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "kredits-contracts",
"version": "6.0.0",
"version": "5.4.0",
"description": "Ethereum contracts and npm wrapper for Kredits",
"main": "./lib/kredits.js",
"directories": {
@@ -15,20 +15,21 @@
"compile-contracts": "truffle compile --all",
"bootstrap": "npm run reset:hard && npm run seeds",
"reset": "npm run deploy:kit && npm run deploy:dao",
"reset:hard": "npm run compile-contracts && npm run deploy:apps && npm run reset",
"deploy:kit": "truffle exec scripts/deploy-kit.js",
"deploy:dao": "truffle exec scripts/new-dao.js",
"reset:hard": "npm run deploy:apps && npm run reset",
"deploy:kit": "aragon contracts exec scripts/deploy-kit.js",
"deploy:dao": "aragon contracts exec scripts/new-dao.js",
"deploy:apps": "./scripts/every-app.sh \"aragon apm publish major --propagate-content=false --build=false --prepublish=false --skip-confirmation\"",
"devchain": "aragon devchain --port 7545",
"dao:address": "truffle exec scripts/current-address.js",
"lint:contracts": "solhint \"contracts/**/*.sol\" \"apps/*/contracts/**/*.sol\"",
"lint:contract-tests": "eslint apps/*/test",
"lint:wrapper": "eslint lib/",
"test": "npm run test:token && npm run test:contributor && npm run test:contribution && npm run test:proposal",
"test": "npm run test:token && npm run test:contributor && npm run test:contribution && npm run test:proposal && npm run test:kit",
"test:token": "cd apps/token && npm run test",
"test:contributor": "cd apps/contributor && npm run test",
"test:contribution": "cd apps/contribution && npm run test",
"test:proposal": "cd apps/proposal && npm run test",
"test:kit": "aragon contracts test",
"setup-git-hooks": "sh scripts/git-hooks/install"
},
"repository": {
@@ -43,26 +44,24 @@
"homepage": "https://github.com/67P/truffle-kredits#readme",
"devDependencies": {
"@aragon/kits-base": "^1.0.0",
"@aragon/os": "^4.4.0",
"@aragon/os": "^4.2.0",
"async-each-series": "^1.1.0",
"cli-table": "^0.3.1",
"eslint": "^7.1.0",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eth-provider": "^0.2.5",
"homedir": "^0.6.0",
"eslint": "^5.16.0",
"eslint-plugin-import": "^2.17.3",
"eslint-plugin-node": "^8.0.1",
"eslint-plugin-promise": "^4.1.1",
"eth-provider": "^0.2.2",
"promptly": "^3.0.3",
"solc": "^0.6.8",
"solhint": "^2.3.1",
"truffle-hdwallet-provider": "^1.0.17",
"truffle-hdwallet-provider-privkey": "^0.3.0",
"yargs": "^15.0.0"
"solc": "^0.4.26",
"solhint": "^2.1.0",
"yargs": "^12.0.0"
},
"dependencies": {
"ethers": "^5.0.2",
"ipfs-http-client": "^41.0.1",
"kosmos-schemas": "^2.2.1",
"@aragon/apps-vault": "^4.1.0",
"ethers": "^4.0.29",
"ipfs-http-client": "^30.1.3",
"kosmos-schemas": "^2.1.0",
"node-fetch": "^2.6.0",
"tv4": "^1.3.0"
},

View File

@@ -19,10 +19,10 @@ module.exports = async function(callback) {
let contributorAccount;
if (contributor.length < 5) {
contributorId = contributor;
contributorAccount = await kredits.Contributor.contract.getContributorAddressById(contributor);
contributorAccount = await kredits.Contributor.functions.getContributorAddressById(contributor);
} else {
contributorAccount = contributor;
contributorId = await kredits.Contributor.contract.getContributorIdByAddress(contributor);
contributorId = await kredits.Contributor.functions.getContributorIdByAddress(contributor);
}
console.log(`Creating a contribution for contributor account ${contributorAccount} ID: ${contributorId}`);
@@ -45,7 +45,7 @@ module.exports = async function(callback) {
console.log("\nAdding contribution:");
console.log(contributionAttributes);
kredits.Contribution.add(contributionAttributes, { gasLimit: 300000 })
kredits.Contribution.addContribution(contributionAttributes, { gasLimit: 300000 })
.then(result => {
console.log("\n\nResult:");
console.log(result);

View File

@@ -19,10 +19,10 @@ module.exports = async function(callback) {
let contributorAccount;
if (contributor.length < 5) {
contributorId = contributor;
contributorAccount = await kredits.Contributor.contract.getContributorAddressById(contributor);
contributorAccount = await kredits.Contributor.functions.getContributorAddressById(contributor);
} else {
contributorAccount = contributor;
contributorId = await kredits.Contributor.contract.getContributorIdByAddress(contributor);
contributorId = await kredits.Contributor.functions.getContributorIdByAddress(contributor);
}
console.log(`Creating a proposal for contributor ID #${contributorId} account: ${contributorAccount}`);

View File

@@ -31,7 +31,7 @@ module.exports = async function(callback) {
if (c.contributorId === recipient && confirmed && !c.vetoed && !c.claimed) {
console.log(`Claiming contribution ID=${c.id}`);
return kredits.Contribution.contract.claim(c.id, { gasLimit: 500000 }).then(tx => {
return kredits.Contribution.functions.claim(c.id, { gasLimit: 500000 }).then(tx => {
table.push([
c.id.toString(),
`${c.description}`,

View File

@@ -17,7 +17,7 @@ module.exports = async function(callback) {
method = await promptly.prompt('Function: ');
}
if (!contractWrapper[method] && !contractWrapper.contract[method]) {
if (!contractWrapper[method] && !contractWrapper.functions[method]) {
callback(new Error(`Method ${method} is not defined on ${contractName}`));
return;
}
@@ -33,7 +33,7 @@ module.exports = async function(callback) {
if (contractWrapper[method]) {
func = contractWrapper[method];
} else {
func = contractWrapper.contract[method];
func = contractWrapper.functions[method];
}
func.apply(contractWrapper, args).then((result) => {
console.log("\nResult:");

View File

@@ -1,12 +1,9 @@
const knownDAOAddresses = require('../lib/addresses/dao.json');
const knownKreditsKitAddresses = require('../lib/addresses/KreditsKit.json');
const getNetworkId = require('./helpers/networkid.js')
const ethers = require('ethers');
module.exports = async function(callback) {
const provider = new ethers.providers.Web3Provider(web3.currentProvider);
let network = await provider.getNetwork();
let networkId = network.chainId;
const networkId = await getNetworkId(web3)
console.log('# All known DAO addresses');
Object.keys(knownDAOAddresses).forEach((networkId) => {

View File

@@ -3,33 +3,23 @@ const deployDAOFactory = require('@aragon/os/scripts/deploy-daofactory.js')
const fs = require('fs');
const path = require('path');
const argv = require('yargs').argv
const ethers = require('ethers');
const namehash = ethers.utils.namehash;
const namehash = require('ethers').utils.namehash;
const fileInject = require('./helpers/file_inject.js')
const getNetworkId = require('./helpers/networkid.js')
const DAOFactory = artifacts.require('DAOFactory')
const KreditsKit = artifacts.require('KreditsKit')
const arapp = require('../arapp.json')
const environment = argv['network'] || argv['environment'] || 'development'
const apm = arapp.environments[environment].apm
const ensAddr = arapp.environments[environment].registry || process.env.ENS
const daoFactoryAddress = arapp.environments[environment].daoFactory || process.env.DAO_FACTORY
const kreditsArappConfig = arapp.environments[environment].kredits || {}
// typically we use the open.aragonpm.eth aragonpm.
const apm = kreditsArappConfig.apmDomain || argv['apmDomain'] || 'open.aragonpm.eth'
// daoFactory is environment specific.
// See https://github.com/aragon/deployments/tree/master/environments/ for the official daoFactory
// Locally we deploy our own daoFactory and no daoFactory is required (`daoFactoryAddress` is null).
const daoFactoryAddress = kreditsArappConfig.daoFactory || argv['daoFactory']
const ensAddr = arapp.environments[environment].registry || argv['ensAddress']
module.exports = async function(callback) {
const provider = new ethers.providers.Web3Provider(web3.currentProvider);
const network = await provider.getNetwork();
const networkId = network.chainId;
const networkId = await getNetworkId(web3)
console.log(`Deploying to networkId: ${networkId}`)
if (!ensAddr) {

View File

@@ -1,5 +1,6 @@
const argv = require('yargs').argv;
const ethers = require('ethers');
const getNetworkId = require('./networkid.js');
const Kredits = require('../../lib/kredits');
const arapp = require('../../arapp.json');
@@ -9,7 +10,7 @@ const apm = arapp.environments[environment].apm;
module.exports = async function(web3) {
return new Promise((resolve, reject) => {
const provider = new ethers.providers.Web3Provider(web3.currentProvider);
const signer = provider.getSigner();
let signer = provider.getSigner();
// checking if siner supports signing transactions
signer.getAddress().then(_ => {
new Kredits(provider, signer, { apm }).init().then(kredits => {

View File

@@ -0,0 +1,17 @@
module.exports = function(web3) {
return new Promise((resolve, reject) => {
let func;
if (web3.version.getNetwork) {
func = web3.version.getNetwork;
} else {
func = web3.eth.net.getId;
}
func((err, network) => {
if (err) {
reject(err);
} else {
resolve(network);
}
})
})
}

View File

@@ -1,14 +1,12 @@
const fs = require('fs');
const ethers = require('ethers');
const getNetworkId = require('./networkid.js');
module.exports = async function(callback) {
const daoAddressPath = 'lib/addresses/dao.json';
// TODO maybe do the same for KreditsKit address file
try {
const provider = new ethers.providers.Web3Provider(web3.currentProvider);
const network = await provider.getNetwork();
const networkId = network.chainId;
const networkId = await getNetworkId(web3);
const daoAddresses = JSON.parse(fs.readFileSync(daoAddressPath));
const oldNetworkId = Math.max(...Object.keys(daoAddresses).map(a => parseInt(a)));
const localDaoAddress = daoAddresses[oldNetworkId];

View File

@@ -41,8 +41,8 @@ module.exports = async function(callback) {
console.log(table.toString());
let totalKreditsEarnedUnConfirmed = await kredits.Contribution.contract.totalKreditsEarned(false);
let totalKreditsEarnedConfirmed = await kredits.Contribution.contract.totalKreditsEarned(true);
let totalKreditsEarnedUnConfirmed = await kredits.Contribution.functions.totalKreditsEarned(false);
let totalKreditsEarnedConfirmed = await kredits.Contribution.functions.totalKreditsEarned(true);
console.log(`Total Kredits: ${totalKreditsEarnedConfirmed} (confirmed) | ${totalKreditsEarnedUnConfirmed} (including unconfirmed)`);
} catch (err) {
console.log(err);

View File

@@ -3,15 +3,13 @@ const path = require('path');
const ethers = require('ethers');
const fileInject = require('./helpers/file_inject.js');
const getNetworkId = require('./helpers/networkid.js');
const KreditsKit = require('../lib/kreditskit');
const addressesPath = path.join(__dirname, '..', 'lib/addresses');
module.exports = async function(callback) {
const provider = new ethers.providers.Web3Provider(web3.currentProvider);
const signer = provider.getSigner();
const network = await provider.getNetwork();
const networkId = network.chainId;
const networkId = await getNetworkId(web3)
console.log(`Deploying to networkId: ${networkId}`)
let kitAddresseFile = path.join(addressesPath, 'KreditsKit.json');
@@ -22,6 +20,9 @@ module.exports = async function(callback) {
}
console.log(`Using KreditsKit at: ${kreditsKitAddress}`);
const provider = new ethers.providers.Web3Provider(web3.currentProvider);
let signer = provider.getSigner();
let kit = await new KreditsKit(provider, signer).init()
// TODO: get rid of the hard coded gas limit

View File

@@ -38,7 +38,7 @@ module.exports = async function(callback) {
if (contractWrapper[method]) {
func = contractWrapper[method];
} else {
func = contractWrapper.contract[method];
func = contractWrapper.functions[method];
}
func.apply(contractWrapper, args).then((result) => {
console.log(`[OK] kredits.${contractName}.${method}(${JSON.stringify(args)}) => ${result.hash}`);

View File

@@ -15,7 +15,7 @@ module.exports = async function(callback) {
console.log(`Recording a veto for contribution #${contributionId}`);
try {
kredits.Contribution.contract.veto(contributionId, { gasLimit: 300000 })
kredits.Contribution.functions.veto(contributionId, { gasLimit: 300000 })
.then(result => {
console.log("\n\nResult:");
console.log(result);

95
test/kreditskit.js Normal file
View File

@@ -0,0 +1,95 @@
/* eslint-disable no-undef */
const namehash = require('ethers').utils.namehash;
const KreditsKit = artifacts.require("KreditsKit.sol");
const getContract = name => artifacts.require(name);
const ZERO_ADDR = '0x0000000000000000000000000000000000000000';
const arapp = require('../arapp.json');
const ENS_ADDRESS = arapp.environments.development.registry;
contract('DAO bare kit', (accounts) => {
let kreditsKit;
let address;
let apps;
let kernel;
let contribution;
let contributor;
let proposal;
let token;
let vault;
before(async () => {
//apps id
const appsId = [];
appsId[0] = namehash("kredits-contribution");
appsId[1] = namehash("kredits-contributor");
appsId[2] = namehash("kredits-proposal");
appsId[3] = namehash("kredits-token");
appsId[4] = namehash("vault");
const kernelBase = await getContract('Kernel').new(true); // petrify immediately
const aclBase = await getContract('ACL').new();
const daoFactory = await getContract('DAOFactory').new(kernelBase.address, aclBase.address, ZERO_ADDR);
kreditsKit = await KreditsKit.new(ZERO_ADDR, ENS_ADDRESS, appsId, { from: accounts[0] });
});
describe("New DAO instance", () => {
it("kit should be defined", async () => {
assert.notEqual(kreditsKit, undefined);
});
it('it should deploy DAO', async () => {
const receipt = await kreditsKit.newInstance({ from: accounts[0] });
address = receipt.logs.filter(l => l.event === 'DeployInstance')[0].args.dao;
apps = receipt.logs
.filter(l => l.event === 'InstalledApp')
.map(event => {
return { id: event.args.appId, proxy: event.args.appProxy };
});
address.should.not.equal(ZERO_ADDR);
});
it('it should install apps', async () => {
apps[0].id.should.equal(namehash('kredits-contribution'));
apps[1].id.should.equal(namehash('kredits-contributor'));
apps[0].id.should.equal(namehash('kredits-proposal'));
apps[1].id.should.equal(namehash('kredits-token'));
apps[0].id.should.equal(namehash('vault'));
});
it('it should initialize apps', async () => {
contribution = await getContract('Contribution').at(apps[0].proxy);
contributor = await getContract('Contributor').at(apps[1].proxy);
proposal = await getContract('Proposal').at(apps[2].proxy);
token = await getContract('Token').at(apps[3].proxy);
vault = await getContract('Vault').at(apps[4].proxy);
(await Promise.all([
contribution.hasInitialized(),
contributor.hasInitialized(),
proposal.hasInitialized(),
token.hasInitialized(),
vault.hasInitialized(),
])).should.deep.equal([true, true, true, true, true]);
});
it('it should set permissions', async () => {
kernel = await getContract('Kernel').at(address);
(await Promise.all([
//check contribution app roles
kernel.hasPermission(accounts[0], contribution.address, await space.ADD_CONTRIBUTION_ROLE(), '0x0'),
kernel.hasPermission(accounts[0], contribution.address, await space.VETO_CONTRIBUTION_ROLE(), '0x0'),
kernel.hasPermission(proposal.address, contribution.address, await space.ADD_CONTRIBUTION_ROLE(), '0x0'),
//proposal app roles
kernel.hasPermission(accounts[0], proposal.address, await proposal.VOTE_PROPOSAL_ROLE(), '0x0'),
//token app roles
kernel.hasPermission(accounts[0], token.address, await token.MINT_TOKEN_ROLE(), '0x0'),
kernel.hasPermission(contribution.address, token.address, await token.MINT_TOKEN_ROLE(), '0x0'),
//vaul app roles
kernel.hasPermission(accounts[0], vault.address, await vault.TRANSFER_ROLE(), '0x0'),
])).should.deep.equal([true, true, true, true, true, true, true]);
});
});
});