diff --git a/lib/addresses/KreditsKit.json b/lib/addresses/KreditsKit.json index d084ba4..22f8d67 100644 --- a/lib/addresses/KreditsKit.json +++ b/lib/addresses/KreditsKit.json @@ -1,4 +1,5 @@ { "4": "0x76e069b47b79442657eaf0555a32c6b16fa1b8b4", - "18335577": "0xeE10a87d8D758B563E301F5C5d029bDD21166DCC" + "18335577": "0xeE10a87d8D758B563E301F5C5d029bDD21166DCC", + "63732251": "0x644F88812006C631a08f786E484A21e652Bb69cc" } \ No newline at end of file diff --git a/lib/addresses/dao.json b/lib/addresses/dao.json index 012512b..3221202 100644 --- a/lib/addresses/dao.json +++ b/lib/addresses/dao.json @@ -1,4 +1,5 @@ { "4": "0xc34edf7d11b7f8433d597f0bb0697acdff55ef14", - "18335577": "0x29E33B66108fa2DC3a018f3DdE41D295eB0922D5" + "18335577": "0x29E33B66108fa2DC3a018f3DdE41D295eB0922D5", + "63732251": "0xd604112A1b9E3D83414694C778b49e664e59c19e" } \ No newline at end of file diff --git a/lib/contracts/acl.js b/lib/contracts/acl.js index d290b0b..254e7a2 100644 --- a/lib/contracts/acl.js +++ b/lib/contracts/acl.js @@ -5,7 +5,7 @@ class Acl extends Base { hasPermission (fromAddress, contractAddress, roleID, params = null) { let roleHash = EthersUtils.keccak256(EthersUtils.toUtf8Bytes(roleID)); - return this.functions.hasPermission( + return this.hasPermission( fromAddress, contractAddress, roleHash, diff --git a/lib/contracts/base.js b/lib/contracts/base.js index 9cbcb7a..3a1e846 100644 --- a/lib/contracts/base.js +++ b/lib/contracts/base.js @@ -1,10 +1,13 @@ +const deprecate = require('../utils/deprecate'); + class Base { constructor (contract) { this.contract = contract; } get functions () { - return this.contract.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; } get address () { diff --git a/lib/contracts/contribution.js b/lib/contracts/contribution.js index 2856949..0f2bbb7 100644 --- a/lib/contracts/contribution.js +++ b/lib/contracts/contribution.js @@ -4,33 +4,33 @@ const deprecate = require('../utils/deprecate'); class Contribution extends Record { get count () { - return this.functions.contributionsCount(); + return this.contract.contributionsCount(); } getById (id) { - return this.functions.getContribution(id) + return this.contract.getContribution(id) .then(data => { return this.ipfs.catAndMerge(data, ContributionSerializer.deserialize); }); } getData (id) { - return this.functions.getContribution(id); + return this.contract.getContribution(id); } getByContributorId (contributorId) { - return this.functions.getContributorAddressById(contributorId) + return this.contract.getContributorAddressById(contributorId) .then(address => this.getByContributorAddress(address)); } getByContributorAddress (address) { - return this.functions.balanceOf(address) + return this.contract.balanceOf(address) .then(async (balance) => { const count = balance.toNumber(); const contributions = []; for (let index = 0; index < count; index++) { - const id = await this.functions.tokenOfOwnerByIndex(address, index); + const id = await this.contract.tokenOfOwnerByIndex(address, index); const contribution = await this.getById(id); contributions.push(contribution); } @@ -58,7 +58,7 @@ class Contribution extends Record { ipfsHashAttr.hashSize, ]; - return this.functions.add(...contribution, callOptions); + return this.contract.add(...contribution, callOptions); }); } diff --git a/lib/contracts/contributor.js b/lib/contracts/contributor.js index 218e21e..5edbfa9 100644 --- a/lib/contracts/contributor.js +++ b/lib/contracts/contributor.js @@ -4,11 +4,11 @@ const formatKredits = require('../utils/format-kredits'); class Contributor extends Record { get count () { - return this.functions.contributorsCount(); + return this.contract.contributorsCount(); } getById (id) { - return this.functions.getContributorById(id) + return this.contract.getContributorById(id) .then(contractData => { let data = {...contractData}; data.balanceInt = formatKredits(data.balance); @@ -17,7 +17,7 @@ class Contributor extends Record { } getData (id) { - return this.functions.getContributorById(id); + return this.contract.getContributorById(id); } filterByAccount (search) { @@ -62,7 +62,7 @@ class Contributor extends Record { ipfsHashAttr.hashSize, ]; - return this.functions.addContributor(...contributor, callOptions); + return this.contract.addContributor(...contributor, callOptions); }); } @@ -79,7 +79,7 @@ class Contributor extends Record { return this.ipfs .add(jsonStr) .then(ipfsHashAttr => { - return this.functions.updateContributorProfileHash( + return this.contract.updateContributorProfileHash( contributorId, ipfsHashAttr.hashDigest, ipfsHashAttr.hashFunction, diff --git a/lib/contracts/kernel.js b/lib/contracts/kernel.js index 630736a..90d6e0b 100644 --- a/lib/contracts/kernel.js +++ b/lib/contracts/kernel.js @@ -11,9 +11,9 @@ class Kernel extends Base { getApp (appName) { if (appName === 'Acl') { - return this.functions.acl(); + return this.contract.acl(); } - return this.functions.getApp(KERNEL_APP_ADDR_NAMESPACE, this.appNamehash(appName)); + return this.contract.getApp(KERNEL_APP_ADDR_NAMESPACE, this.appNamehash(appName)); } appNamehash (appName) { diff --git a/lib/contracts/proposal.js b/lib/contracts/proposal.js index e36d3ef..307ef58 100644 --- a/lib/contracts/proposal.js +++ b/lib/contracts/proposal.js @@ -4,11 +4,11 @@ const deprecate = require('../utils/deprecate'); class Proposal extends Record { get count () { - return this.functions.proposalsCount(); + return this.contract.proposalsCount(); } getById (id) { - return this.functions.getProposal(id) + return this.contract.getProposal(id) .then(data => { return this.ipfs.catAndMerge(data, ContributionSerializer.deserialize); }); @@ -33,7 +33,7 @@ class Proposal extends Record { ipfsHashAttr.hashSize, ]; - return this.functions.addProposal(...proposal, callOptions); + return this.contract.addProposal(...proposal, callOptions); }); } diff --git a/lib/kredits.js b/lib/kredits.js index e63dda5..caa654b 100644 --- a/lib/kredits.js +++ b/lib/kredits.js @@ -49,7 +49,7 @@ class Kredits { this.addresses['Kernel'] = this.addresses['Kernel'] || DaoAddresses[network.chainId.toString()]; let addressPromises = contractsToLoad.map((contractName) => { return this.Kernel.getApp(contractName).then((address) => { - this.addresses[contractName] = address[0]; // we get an array from the getApp response + this.addresses[contractName] = address; }).catch((error) => { throw new Error(`Failed to get address for ${contractName} from DAO at ${this.Kernel.contract.address} - ${error.message}` diff --git a/lib/kreditskit.js b/lib/kreditskit.js index bc08763..0a31258 100644 --- a/lib/kreditskit.js +++ b/lib/kreditskit.js @@ -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.functions.appIds(knownContracts.indexOf(contractName)); + return this.contract.appIds(knownContracts.indexOf(contractName)); } newDAO (options = {}) { - return this.contract.functions.newInstance(options).then(transaction => { + return this.contract.newInstance(options).then(transaction => { return transaction.wait().then(result => { const deployEvent = result.events.find(e => e.event === 'DeployInstance'); return { diff --git a/package-lock.json b/package-lock.json index 74be5fa..80df298 100644 --- a/package-lock.json +++ b/package-lock.json @@ -473,6 +473,12 @@ "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" }, + "await-semaphore": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/await-semaphore/-/await-semaphore-0.1.3.tgz", + "integrity": "sha512-d1W2aNSYcz/sxYO4pMGX9vq65qOTu0P800epMud+6cYYX0QcT7zyqcxec3VWzpgvdXo57UWmVbZpLMjX2m1I7Q==", + "dev": true + }, "aws-sign2": { "version": "0.7.0", "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz", @@ -1408,6 +1414,12 @@ "safe-buffer": "^5.1.2" } }, + "btoa": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/btoa/-/btoa-1.2.1.tgz", + "integrity": "sha512-SB4/MIGlsiVkMcHmT+pSmIPoNDoHg+7cMzmt3Uxt628MTz2487DKSqK/fuhFBrkuqrYv5UCEnACpF4dTFNKc/g==", + "dev": true + }, "buffer": { "version": "5.4.3", "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.4.3.tgz", @@ -2900,6 +2912,97 @@ "js-sha3": "^0.5.7" } }, + "eth-json-rpc-errors": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/eth-json-rpc-errors/-/eth-json-rpc-errors-1.1.1.tgz", + "integrity": "sha512-WT5shJ5KfNqHi9jOZD+ID8I1kuYWNrigtZat7GOQkvwo99f8SzAVaEcWhJUv656WiZOAg3P1RiJQANtUmDmbIg==", + "dev": true, + "requires": { + "fast-safe-stringify": "^2.0.6" + } + }, + "eth-json-rpc-filters": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/eth-json-rpc-filters/-/eth-json-rpc-filters-4.1.1.tgz", + "integrity": "sha512-GkXb2h6STznD+AmMzblwXgm1JMvjdK9PTIXG7BvIkTlXQ9g0QOxuU1iQRYHoslF9S30BYBSoLSisAYPdLggW+A==", + "dev": true, + "requires": { + "await-semaphore": "^0.1.3", + "eth-json-rpc-middleware": "^4.1.4", + "eth-query": "^2.1.2", + "json-rpc-engine": "^5.1.3", + "lodash.flatmap": "^4.5.0", + "safe-event-emitter": "^1.0.1" + }, + "dependencies": { + "eth-json-rpc-middleware": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/eth-json-rpc-middleware/-/eth-json-rpc-middleware-4.4.1.tgz", + "integrity": "sha512-yoSuRgEYYGFdVeZg3poWOwAlRI+MoBIltmOB86MtpoZjvLbou9EB/qWMOWSmH2ryCWLW97VYY6NWsmWm3OAA7A==", + "dev": true, + "requires": { + "btoa": "^1.2.1", + "clone": "^2.1.1", + "eth-json-rpc-errors": "^1.0.1", + "eth-query": "^2.1.2", + "eth-sig-util": "^1.4.2", + "ethereumjs-block": "^1.6.0", + "ethereumjs-tx": "^1.3.7", + "ethereumjs-util": "^5.1.2", + "ethereumjs-vm": "^2.6.0", + "fetch-ponyfill": "^4.0.0", + "json-rpc-engine": "^5.1.3", + "json-stable-stringify": "^1.0.1", + "pify": "^3.0.0", + "safe-event-emitter": "^1.0.1" + } + }, + "ethereumjs-util": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-5.2.0.tgz", + "integrity": "sha512-CJAKdI0wgMbQFLlLRtZKGcy/L6pzVRgelIZqRqNbuVFM3K9VEnyfbcvz0ncWMRNCe4kaHWjwRYQcYMucmwsnWA==", + "dev": true, + "requires": { + "bn.js": "^4.11.0", + "create-hash": "^1.1.2", + "ethjs-util": "^0.1.3", + "keccak": "^1.0.2", + "rlp": "^2.0.0", + "safe-buffer": "^5.1.1", + "secp256k1": "^3.0.1" + } + }, + "json-rpc-engine": { + "version": "5.1.8", + "resolved": "https://registry.npmjs.org/json-rpc-engine/-/json-rpc-engine-5.1.8.tgz", + "integrity": "sha512-vTBSDEPJV1fPAsbm2g5sEuPjsgLdiab2f1CTn2PyRr8nxggUpA996PDlNQDsM0gnrA99F8KIBLq2nIKrOFl1Mg==", + "dev": true, + "requires": { + "async": "^2.0.1", + "eth-json-rpc-errors": "^2.0.1", + "promise-to-callback": "^1.0.0", + "safe-event-emitter": "^1.0.1" + }, + "dependencies": { + "eth-json-rpc-errors": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/eth-json-rpc-errors/-/eth-json-rpc-errors-2.0.2.tgz", + "integrity": "sha512-uBCRM2w2ewusRHGxN8JhcuOb2RN3ueAOYH/0BhqdFmQkZx5lj5+fLKTz0mIVOzd4FG5/kUksCzCD7eTEim6gaA==", + "dev": true, + "requires": { + "fast-safe-stringify": "^2.0.6" + } + } + } + }, + "pify": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz", + "integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY=", + "dev": true + } + } + }, "eth-json-rpc-infura": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/eth-json-rpc-infura/-/eth-json-rpc-infura-3.2.1.tgz", @@ -3532,6 +3635,12 @@ "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=", "dev": true }, + "fast-safe-stringify": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.0.7.tgz", + "integrity": "sha512-Utm6CdzT+6xsDk2m8S6uL8VHxNwI6Jub+e9NYTcAms28T84pTa25GJQV9j0CY0N1rM8hK4x6grpF2BQf+2qwVA==", + "dev": true + }, "fd-slicer": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz", @@ -5156,6 +5265,12 @@ "integrity": "sha1-DZnzzNem0mHRm9rrkkUAXShYCOc=", "dev": true }, + "lodash.flatmap": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/lodash.flatmap/-/lodash.flatmap-4.5.0.tgz", + "integrity": "sha1-74y/QI9uSCaGYzRTBcaswLd4cC4=", + "dev": true + }, "loose-envify": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", @@ -8716,8 +8831,10 @@ "backoff": "^2.5.0", "clone": "^2.0.0", "cross-fetch": "^2.1.0", - "eth-block-tracker": "^3.0.0", + "eth-block-tracker": "^4.2.0", + "eth-json-rpc-filters": "^4.0.2", "eth-json-rpc-infura": "^3.1.0", + "eth-json-rpc-middleware": "^4.1.1", "eth-sig-util": "^1.4.2", "ethereumjs-block": "^1.2.2", "ethereumjs-tx": "^1.2.0", @@ -8734,6 +8851,28 @@ "xtend": "^4.0.1" }, "dependencies": { + "eth-json-rpc-middleware": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/eth-json-rpc-middleware/-/eth-json-rpc-middleware-4.4.1.tgz", + "integrity": "sha512-yoSuRgEYYGFdVeZg3poWOwAlRI+MoBIltmOB86MtpoZjvLbou9EB/qWMOWSmH2ryCWLW97VYY6NWsmWm3OAA7A==", + "dev": true, + "requires": { + "btoa": "^1.2.1", + "clone": "^2.1.1", + "eth-json-rpc-errors": "^1.0.1", + "eth-query": "^2.1.2", + "eth-sig-util": "^1.4.2", + "ethereumjs-block": "^1.6.0", + "ethereumjs-tx": "^1.3.7", + "ethereumjs-util": "^5.1.2", + "ethereumjs-vm": "^2.6.0", + "fetch-ponyfill": "^4.0.0", + "json-rpc-engine": "^5.1.3", + "json-stable-stringify": "^1.0.1", + "pify": "^3.0.0", + "safe-event-emitter": "^1.0.1" + } + }, "ethereumjs-util": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-5.2.0.tgz", @@ -8749,6 +8888,35 @@ "secp256k1": "^3.0.1" } }, + "json-rpc-engine": { + "version": "5.1.8", + "resolved": "https://registry.npmjs.org/json-rpc-engine/-/json-rpc-engine-5.1.8.tgz", + "integrity": "sha512-vTBSDEPJV1fPAsbm2g5sEuPjsgLdiab2f1CTn2PyRr8nxggUpA996PDlNQDsM0gnrA99F8KIBLq2nIKrOFl1Mg==", + "dev": true, + "requires": { + "async": "^2.0.1", + "eth-json-rpc-errors": "^2.0.1", + "promise-to-callback": "^1.0.0", + "safe-event-emitter": "^1.0.1" + }, + "dependencies": { + "eth-json-rpc-errors": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/eth-json-rpc-errors/-/eth-json-rpc-errors-2.0.2.tgz", + "integrity": "sha512-uBCRM2w2ewusRHGxN8JhcuOb2RN3ueAOYH/0BhqdFmQkZx5lj5+fLKTz0mIVOzd4FG5/kUksCzCD7eTEim6gaA==", + "dev": true, + "requires": { + "fast-safe-stringify": "^2.0.6" + } + } + } + }, + "pify": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz", + "integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY=", + "dev": true + }, "readable-stream": { "version": "2.3.7", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", diff --git a/scripts/add-contribution.js b/scripts/add-contribution.js index 78b1b03..e6f79f2 100644 --- a/scripts/add-contribution.js +++ b/scripts/add-contribution.js @@ -19,10 +19,10 @@ module.exports = async function(callback) { let contributorAccount; if (contributor.length < 5) { contributorId = contributor; - contributorAccount = await kredits.Contributor.functions.getContributorAddressById(contributor); + contributorAccount = await kredits.Contributor.contract.getContributorAddressById(contributor); } else { contributorAccount = contributor; - contributorId = await kredits.Contributor.functions.getContributorIdByAddress(contributor); + contributorId = await kredits.Contributor.contract.getContributorIdByAddress(contributor); } console.log(`Creating a contribution for contributor account ${contributorAccount} ID: ${contributorId}`); diff --git a/scripts/add-proposal.js b/scripts/add-proposal.js index c99fecf..e4b9bc0 100644 --- a/scripts/add-proposal.js +++ b/scripts/add-proposal.js @@ -19,10 +19,10 @@ module.exports = async function(callback) { let contributorAccount; if (contributor.length < 5) { contributorId = contributor; - contributorAccount = await kredits.Contributor.functions.getContributorAddressById(contributor); + contributorAccount = await kredits.Contributor.contract.getContributorAddressById(contributor); } else { contributorAccount = contributor; - contributorId = await kredits.Contributor.functions.getContributorIdByAddress(contributor); + contributorId = await kredits.Contributor.contract.getContributorIdByAddress(contributor); } console.log(`Creating a proposal for contributor ID #${contributorId} account: ${contributorAccount}`); diff --git a/scripts/claim-contributions.js b/scripts/claim-contributions.js index 24598fb..2b644eb 100644 --- a/scripts/claim-contributions.js +++ b/scripts/claim-contributions.js @@ -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.functions.claim(c.id, { gasLimit: 500000 }).then(tx => { + return kredits.Contribution.contract.claim(c.id, { gasLimit: 500000 }).then(tx => { table.push([ c.id.toString(), `${c.description}`, diff --git a/scripts/cli.js b/scripts/cli.js index 0d6753f..33f1476 100644 --- a/scripts/cli.js +++ b/scripts/cli.js @@ -17,7 +17,7 @@ module.exports = async function(callback) { method = await promptly.prompt('Function: '); } - if (!contractWrapper[method] && !contractWrapper.functions[method]) { + if (!contractWrapper[method] && !contractWrapper.contract[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.functions[method]; + func = contractWrapper.contract[method]; } func.apply(contractWrapper, args).then((result) => { console.log("\nResult:"); diff --git a/scripts/list-contributions.js b/scripts/list-contributions.js index bfdc958..3cb582e 100644 --- a/scripts/list-contributions.js +++ b/scripts/list-contributions.js @@ -41,8 +41,8 @@ module.exports = async function(callback) { console.log(table.toString()); - let totalKreditsEarnedUnConfirmed = await kredits.Contribution.functions.totalKreditsEarned(false); - let totalKreditsEarnedConfirmed = await kredits.Contribution.functions.totalKreditsEarned(true); + let totalKreditsEarnedUnConfirmed = await kredits.Contribution.contract.totalKreditsEarned(false); + let totalKreditsEarnedConfirmed = await kredits.Contribution.contract.totalKreditsEarned(true); console.log(`Total Kredits: ${totalKreditsEarnedConfirmed} (confirmed) | ${totalKreditsEarnedUnConfirmed} (including unconfirmed)`); } catch (err) { console.log(err); diff --git a/scripts/seeds.js b/scripts/seeds.js index 8928419..7f628e4 100644 --- a/scripts/seeds.js +++ b/scripts/seeds.js @@ -38,7 +38,7 @@ module.exports = async function(callback) { if (contractWrapper[method]) { func = contractWrapper[method]; } else { - func = contractWrapper.functions[method]; + func = contractWrapper.contract[method]; } func.apply(contractWrapper, args).then((result) => { console.log(`[OK] kredits.${contractName}.${method}(${JSON.stringify(args)}) => ${result.hash}`); diff --git a/scripts/veto-contribution.js b/scripts/veto-contribution.js index cad4617..a66fe48 100644 --- a/scripts/veto-contribution.js +++ b/scripts/veto-contribution.js @@ -15,7 +15,7 @@ module.exports = async function(callback) { console.log(`Recording a veto for contribution #${contributionId}`); try { - kredits.Contribution.functions.veto(contributionId, { gasLimit: 300000 }) + kredits.Contribution.contract.veto(contributionId, { gasLimit: 300000 }) .then(result => { console.log("\n\nResult:"); console.log(result);