Compare commits

...

479 Commits

Author SHA1 Message Date
Râu Cao
96a18d3c5c Bundle import txs into blocks, wait for confirmations
All checks were successful
continuous-integration/drone/push Build is passing
2022-10-24 12:41:40 +02:00
Râu Cao
b3dabb41e1 Add RSK testnet contract addresses
All checks were successful
continuous-integration/drone/push Build is passing
2022-10-23 18:46:57 +02:00
1c097f37a6 Merge pull request 'Add export/import functionality' (#224) from feature/export-import into master
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #224
2022-09-02 20:31:27 +00:00
Râu Cao
d3fb1010d5 Merge branch 'master' into feature/export-import
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2022-09-02 09:53:58 +02:00
f390b5dff5 Merge pull request 'Make Kredits undivisible' (#227) from feature/undivisible into master
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #227
2022-09-02 07:49:23 +00:00
hueso
1e4f7be5cf make KS undivisible
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2022-09-01 22:37:21 -03:00
Râu Cao
258c1cc755 Use ethers from correct parent object
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2022-08-31 09:55:26 +02:00
Râu Cao
f29054bc0b Add script for importing contributions
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2022-08-30 12:18:45 +02:00
fd012d5359 Merge pull request 'Remove claims, add withdrawals' (#225) from feature/184-remove_kredits_claims into feature/export-import
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
Reviewed-on: #225
2022-08-30 08:53:54 +00:00
Râu Cao
5da710cc14 Use uint32 for kreditsWithdrawn
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
Same as the properties and functions in the Contribution contract
2022-08-27 10:29:56 +02:00
Râu Cao
e99184b83f Make test complete, add FIXME note
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2022-08-25 11:51:31 +02:00
Râu Cao
2b3fd1241d WIP Remove claims, add withdrawals
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2022-08-25 11:44:38 +02:00
Râu Cao
dc2c8130f3 Add tests for Contributor#add()
Some checks failed
continuous-integration/drone/push Build is failing
2022-08-24 13:33:04 +01:00
Râu Cao
796ccebd84 Add first Contributor contract test
Some checks failed
continuous-integration/drone/pr Build is failing
continuous-integration/drone/push Build is failing
2022-08-24 12:55:50 +01:00
Râu Cao
d72413eb66 Move contract test to its own subdirectory
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2022-08-23 16:34:56 +01:00
Râu Cao
9dd9d298cc Allow setting confirmedAtBlock and vetoed during migration
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2022-08-23 16:20:50 +01:00
Râu Cao
67add71a22 Add tests for Contribution#add()
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2022-08-23 14:41:30 +01:00
Râu Cao
cd07313679 Revert core flag change
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2022-08-23 13:14:19 +01:00
Râu Cao
90172071fa Add test for setting deployer address
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2022-08-23 12:20:42 +01:00
Râu Cao
de1574155c Allow deployer to set a migration-done flag
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
* Save deployer's address on contract initialization
* Add modifier for requiring tx sender to be deployer
* Add migrationDone flag and function to set it to finished status
2022-08-23 12:15:16 +01:00
Râu Cao
0fc4eed09a CI
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2022-08-23 10:55:35 +01:00
Râu Cao
55877897be Formatting
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2022-08-23 10:42:33 +01:00
Râu Cao
59bda71f97 Add mocha, chai, and test for Contribution 2022-08-23 10:42:07 +01:00
Râu Cao
1521e272f9 Finish contributor import script
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2022-08-23 10:01:37 +01:00
Râu Cao
990e2a9649 Also export vetoed contributions
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
2022-08-23 09:50:46 +01:00
Râu Cao
883f9adb96 Fix ignored contributions not resolving their promise
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2022-08-23 09:39:05 +01:00
Râu Cao
550bc2b9f4 Improve console output 2022-08-23 09:38:35 +01:00
2fca436fa8 Added export/import function for contributors
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2022-08-22 18:12:18 +02:00
2b05be1897 Merge pull request 'Add linting and contract builds to CI' (#222) from feature/183-ci_linting into master
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #222
2022-08-10 16:31:31 +00:00
Râu Cao
46b1bbfbf2 Disable contract linting for now
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
So we can continue with actual tests, and fix the linter warnings
separately from other ongoing work.
2022-08-10 11:18:28 +01:00
Râu Cao
98348dc544 Build contracts in CI
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing
2022-08-09 16:18:28 +01:00
Râu Cao
fd93993a1b Nicer step names
Some checks failed
continuous-integration/drone/push Build is failing
2022-08-09 16:00:29 +01:00
Râu Cao
0d6702fd2b Add JS and Solidity linting to CI 2022-08-09 15:56:08 +01:00
Râu Cao
51e50e7c46 CI: Split setup and test steps
All checks were successful
continuous-integration/drone/push Build is passing
2022-08-09 15:52:16 +01:00
793642c238 Merge pull request 'Set up Drone CI' (#221) from feature/ci_setup into master
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #221
2022-08-09 14:39:27 +00:00
Râu Cao
c55593d46f Add Docker image configs
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2022-08-08 18:20:38 +02:00
Râu Cao
2b314556ad Set up Drone CI 2022-08-08 18:20:32 +02:00
53955126ff 7.0.0-beta.0 2022-07-16 16:27:56 +02:00
1d1f2bb4ed Merge pull request #218 from 67P/feature/217-rsk_deployment
Refactor deployment script, add error handling
2022-07-16 11:04:55 +02:00
42a2945692 Merge pull request #219 from 67P/feature/217-rsk_deployment-1
Fix typo and add more logs
2022-07-16 11:04:08 +02:00
12326ce73f Fix typo and add more logs 2022-07-15 18:19:06 +02:00
18da1306b9 Refactor deployment script, add error handling 2022-07-15 13:36:03 +02:00
f6c302dd21 Update package lock 2022-07-15 13:34:56 +02:00
e3a0f0e8d3 Formatting 2022-07-15 13:34:17 +02:00
534f68c5a9 Merge pull request #216 from 67P/hardhat
Add docs on how to deploy to other networks to the README
2022-07-15 13:29:16 +02:00
d0fd1a3971 Merge branch 'master' into hardhat
* master:
  Formatting
2022-07-14 16:00:20 +02:00
a8597bba8e Add docs on how to deploy to other networks to the readme 2022-07-14 15:57:03 +02:00
683ec5b2e9 Merge pull request #213 from 67P/hardhat
Hardhat
2022-07-14 15:31:48 +02:00
d93d736370 Formatting 2022-07-14 14:06:08 +02:00
bcee608920 Typo 2022-07-06 18:07:38 +02:00
643bd01a78 Add rinkeby network and extend some logs/docs 2022-07-06 18:02:42 +02:00
e21fb40661 Add an example script on how to upgrade a contract implementation 2022-07-04 20:01:46 +02:00
fa4583158f Merge pull request #215 from 67P/fix-hardhat-build
Load contract APIs from hardhat artifacts
2022-05-20 12:27:30 +02:00
d46b084e2c Remove obsolete directories from .gitignore 2022-05-20 11:55:09 +02:00
687040791c Cleanup aragon contract leftovers
and use hardhat localhost as default network
2022-05-19 18:40:41 +02:00
936115afb9 Cleanup aragon ABIs 2022-05-19 18:34:09 +02:00
ba52e61d50 Load contract APIs from hardhat artifacts 2022-05-19 18:06:56 +02:00
9d87636fb0 Remove aragon from readme 2022-05-19 17:51:45 +02:00
cc6b6de827 Extend bootstrap and fund script 2022-05-19 17:51:33 +02:00
0d6dc78a58 Roll back node-fetch upgrade 2022-05-19 17:33:32 +02:00
195cd42313 Update dependencies 2022-05-19 01:02:27 +02:00
1721c33620 Update ABIs 2022-05-16 19:18:41 +02:00
96940716bd Update npm scripts, README
Introduce a new `build` script that also builds the ABIs.
2022-05-16 19:16:13 +02:00
ab8f632a30 Recommend node.js 16 via nvm config 2022-05-16 19:07:29 +02:00
9e92fbfa8f Remove obsolete imports, improve syntax/formatting 2022-05-01 18:16:03 +02:00
75bcde4f49 Improve seeds script
* Add colors
* Inform user about failures at the end of the script
2022-04-28 19:21:09 +02:00
53fafc1c78 Update ipfs-http-client (for node >= 14)
Updates the client library and API usage to work with the latest
version, and more importantly, with current node.js LTS.
2022-04-28 19:19:58 +02:00
16d5704173 Remove obsolete import in seeds 2022-04-28 19:19:12 +02:00
23b30b7f8e Fix kredits instance not being returned by init() 2022-04-27 18:06:02 +02:00
50b10dd46c Syntax and linting issues 2022-04-27 18:05:51 +02:00
b80273b308 Update kosmos-schemas 2022-04-27 18:00:56 +02:00
0fde17a4e0 Refactor seeds script 2022-04-25 22:22:54 +02:00
ad8daa8649 Update compiler version
Required by an openzeppelin contract
2022-04-25 22:22:53 +02:00
d1d92c6644 Update dependencies 2022-04-25 22:22:53 +02:00
53dbc1e4ad Update README and npm scripts for hardhat 2022-04-25 10:09:15 -05:00
24990de42a Revert "Recommend node 16 to nvm users"
This reverts commit 22c3a82167.
2022-02-03 20:02:38 -06:00
d52f502fd5 Allow core users to create contributions 2022-02-03 22:07:17 +01:00
04fff0934d Explicit core check for the deployer account
The deployer account has the same rights as a core contributor. This is handled now explicitly in the addressIsCore function.
This allows us to run seeds and such from the deployer account.
2022-02-03 22:06:52 +01:00
22c3a82167 Recommend node 16 to nvm users 2022-01-11 16:24:41 -06:00
f0edfa038f Add dev scripts for hardhat to package.json 2022-01-11 16:20:23 -06:00
8bb3f234c7 Get seeds working on RSK
we need to wait for the transactions to be mined otherwise we get a nonce error
2021-09-28 15:16:26 +02:00
15a08fdaec We need to use tx.origin to get the actual sender of the transaction (not an intermediary contract that talks to the other contract) 2021-09-28 15:10:05 +02:00
0756569dc7 FIx deployment script for RSK
we need to wait a bit more because RSK is slower and transactions must be confirmed
2021-09-28 13:19:50 +02:00
8a7858a0bb Cleanup and default dev deploy key (needed for NON rsk networks) 2021-09-26 19:27:03 +02:00
5e6d066e40 Cleanup 2021-09-26 19:26:03 +02:00
c3bd2b88d4 Update dependencies 2021-09-26 19:25:57 +02:00
ffd4a5aeaf Permissions 2021-09-26 19:25:43 +02:00
623cf6d6da Fix deprecation warninsg 2021-09-25 15:55:11 +02:00
cc9cc53d0b Add RSK network 2021-07-08 11:27:49 +02:00
9bfe131cd5 Update ethers.js to support RSK deployments 2021-07-08 11:09:41 +02:00
8a962aea62 Cleanup package.json 2021-06-08 23:40:20 +02:00
b81fc98740 No aragon app anymore :( 2021-06-08 23:31:25 +02:00
5d4c9ba403 bye truffle migration 2021-06-08 23:30:41 +02:00
f5ca44d779 ByeBye apps 2021-06-08 23:30:27 +02:00
dd70bf77d5 Cleanup scripts 2021-06-08 16:17:56 +02:00
63e8ce1e3f Extend hre with a kredits instance 2021-06-08 16:17:34 +02:00
a626409221 Move contracts to root level for hardhart usage
byebye aragon apps
2021-06-08 15:45:23 +02:00
1425c3664a Hello hardhat 2021-06-02 16:36:49 +02:00
c865c154a4 Merge pull request #198 from 67P/feature/expenses
Add Reimbursement app
2021-06-02 14:25:33 +02:00
a63a37c5d6 Merge pull request #212 from 67P/chore/nvmrc
Add .nvmrc
2021-05-31 11:41:45 +02:00
20879c4c08 Add .nvmrc
Configures node version to what we currently recommend/require.
2021-05-31 10:07:44 +02:00
7ab8e4e52d Merge pull request #211 from 67P/feature/find_block_by_date
Add script for finding block closest to given date
2021-05-29 16:59:38 +02:00
f11c4f7764 Add script for finding block closest to given date
Useful for manual grant cycle management.
2021-05-20 15:09:56 +02:00
44cad2d26e Fix contributorId being used in a reimbursement seed 2021-02-22 15:32:43 +01:00
357698db02 Deployment details 2021-02-19 10:24:54 +01:00
6c80179a3d Re-add veto auth
Accidentally merged during pairing with some minor changes in #210
2021-01-14 15:46:33 +01:00
c471060cfd Merge pull request #210 from 67P/chore/variable_naming
Improve variable name clarity
2021-01-14 15:43:26 +01:00
7418d33e63 Merge pull request #209 from 67P/bugfix/confirmed_at
Fix confirmations being 1 block too late
2021-01-14 15:43:07 +01:00
1cfbc09e4a Merge pull request #208 from 67P/feature/count-contributions
Add script to count contributions between a certain block timeframe
2021-01-14 15:41:41 +01:00
8984ba3802 Improve variable name clarity 2021-01-14 15:39:19 +01:00
2238ccf40e Fix confirmations being 1 block too late
block.number refers to the last mined block, so we need to add +1 to
wait from the current block on (the one in which this function is
executed).
2021-01-14 15:36:55 +01:00
0df7930e06 Get it running 2020-12-22 12:28:34 +01:00
eebc0db02b Add script to count contributions between a certain block timeframe 2020-12-16 17:19:31 +01:00
b22d16e61e We do not need the appIds in the reimbursement app
this might make it easier to deploy?
2020-12-01 13:27:39 +01:00
6bc6bcb7f6 We don't use those helpers right now. but maybe later? 2020-12-01 12:54:28 +01:00
9df58b7f9a Fix seeds 2020-12-01 12:51:33 +01:00
c83a560e3b merge master 2020-12-01 10:39:01 +01:00
eadca6904a Rename contributor to recipient
And remove addedBy entry.
2020-12-01 10:33:09 +01:00
89829ee81f Merge pull request #207 from 67P/docs/update_readme
Lock node.js to 12 on CI, add note for devs to README
2020-11-18 19:09:19 +01:00
32b212f9cf Use legacy node.js in CI
Courtesy of aragon CLI.
2020-11-18 17:31:10 +01:00
e3c03bf4a0 Update README
Add note about having to use node.js 12 for now.
2020-11-17 12:30:09 +01:00
7dba0e4501 Add missing permission assignment
Fixes reimbursement transaction failures.

Co-authored-by: Michael Bumann <hello@michaelbumann.com>
2020-10-20 10:44:29 +02:00
e6349f0594 Some minor improvements of ExpenseSerializer 2020-10-01 16:12:13 +02:00
15b47dbc42 Improve Reimbursement.add validation 2020-10-01 12:15:48 +02:00
8f0d7e5196 6.0.0 2020-07-17 13:22:59 +02:00
4add0c7d96 package-lock 2020-07-17 13:22:24 +02:00
7ad2515b67 Improve seeds 2020-07-10 00:07:06 +02:00
fbd82a442e Merge pull request #200 from 67P/ethers5
Update to ethers 5
2020-07-07 16:59:40 +02:00
c39fe406d0 Fix deprecation 2020-06-29 23:49:46 +02:00
a609d921aa Remove accidentally added local DAO addresses 2020-06-29 23:49:03 +02:00
23d3dd3a80 Adjust API for new ethers v5 API
see issue for details: https://github.com/ethers-io/ethers.js/issues/920#issuecomment-650836642
2020-06-29 17:23:08 +02:00
c63fcc002b Use new schemas release 2020-06-28 00:47:24 +02:00
bc38dcb136 Copy contract data into new object to avoid object is not extensible error
It seems the new ethers.js version returns contract data as a non-
extensible object. We have to clone it before adding the IPFS data.
2020-06-27 20:39:23 +02:00
c4e7e1259e Remove obsolete manual expense schema import 2020-06-27 16:27:11 +02:00
17cc44cb98 Use unreleased kosmos schemas fix 2020-06-27 16:23:15 +02:00
c2dcedfe58 Update to ethers 5 2020-06-24 01:20:04 +02:00
2c567fa71a Use contributorId instead or address for reimbursements 2020-06-12 00:29:59 +02:00
9b4a95f375 use const for not reassigned variable 2020-05-30 14:02:50 +02:00
687f87f43b cleanup address files 2020-05-30 14:02:29 +02:00
7fdeb78617 Support multiple expenses in one reimburesement 2020-05-29 18:47:49 +02:00
19f212f283 Cleanup
we do not support claiming/withdrawal yet.
2020-05-29 17:25:27 +02:00
1f248812a7 Reimbursement.getReimbursement vs. Reimbursement.get 2020-05-29 15:12:57 +02:00
3f8407fa02 Update apps/reimbursement/contracts/Reimbursement.sol
Co-authored-by: Sebastian Kippe <sebastian@kip.pe>
2020-05-29 11:31:51 +02:00
a0b0183beb Add Reimbursement app 2020-05-29 10:46:55 +02:00
2b99593699 Merge pull request #196 from 67P/chore/dependency-updates
Chore/dependency updates
2020-05-27 16:22:40 +02:00
606350eb5e Update solc
our contracts still use an older version, but I guess it is good to have
the latest solc package
2020-05-27 10:53:31 +02:00
a330a8eedf npm upgrade 2020-05-27 10:46:41 +02:00
3c72fa3a8b run npm upgrade in every app
are those package-lock.json there actually used?
2020-05-27 10:31:12 +02:00
a4ef2398be update dependencies 2020-05-27 10:06:06 +02:00
31c29ab6d0 Merge pull request #194 from 67P/updates
Some required dependency updates
2020-05-07 10:08:26 +02:00
ef0c0c0a39 (ci) Disable all tests 2020-05-07 09:59:27 +02:00
844bdbd681 (ci) Disable token tests
They are failing in different ways both locally and on Travis.
2020-05-07 09:51:26 +02:00
9d96824fe9 (ci) Wait a little for the devchain to start up 2020-05-07 09:41:11 +02:00
d246531cfa Update package lockfile 2020-05-07 09:40:58 +02:00
6be06b2e57 Merge branch 'master' into updates 2020-05-07 09:30:29 +02:00
c2220c3654 Fix ESLint error 2020-05-07 09:27:15 +02:00
5044d8fe41 fix syntax error 2020-04-15 20:44:13 +02:00
3c49c688d2 Add missing dev dependencies and update dependencies 2020-04-15 20:43:46 +02:00
47f59126a7 5.5.0 2020-03-01 12:46:22 +01:00
2ce5d925d0 Merge pull request #182 from 67P/chore/update_dependencies
WIP: Fix Aragon breaking changes; update dependencies
2020-02-20 11:42:04 +00:00
3db89b0fa3 Refactor kredits related configuration in arapp.json
we use an environment specific entry for the daoAddress.
Locally we deploy our own, but for rinkeby and other public networks
we use the official entries.
To make deployments easy we store the address in the arapp.json
2020-02-10 15:55:16 +01:00
190d3b77d5 Update tests
getContract now seems to return a Promise
2020-02-10 14:59:22 +01:00
b7eac4202c Adjust deploy script and readme for updates 2020-02-10 14:30:03 +01:00
93aeea69c6 Fix test commands
Aragon CLI does not come with the contracts command anymore.
2020-02-08 17:37:26 -05:00
e7700d5ec7 Remove @aragon/cli from app package configs
We're assuming a global install now.
2020-02-08 17:36:48 -05:00
c3eced5c1d Remove apm app config keys 2020-02-08 17:19:39 -05:00
4c6ed12167 Re-add fixed package lock 2020-02-08 16:41:08 -05:00
9431bc22a6 Re-add package lock fix script
m(
2020-02-08 16:36:29 -05:00
78c8052629 Update dependencies
Dance the update dance with me.
2020-02-08 16:28:13 -05:00
a318fe8374 Add release-drafter config 2019-09-18 12:49:00 +02:00
eded4a811f Merge pull request #175 from 67P/feature/zoom-profile
Add support for zoom profiles
2019-09-18 09:28:19 +02:00
66a37a1e74 Improve property name 2019-09-18 08:44:13 +02:00
aba4a23104 Fixes & linting 2019-09-17 18:30:19 +02:00
13ed02e134 Add support for zoom profils
This adds an accessor for the zoom_name to the contributor profile.
Doing this also removes general support for preserviing the contributor
accounts array as this was buggy and caused accounts to be added
multiple times.
2019-09-17 17:24:35 +02:00
48ff304861 Merge pull request #166 from 67P/dev/remove_yarn_lockfile
Remove yarn lockfiles
2019-08-27 12:34:29 +02:00
1c1a318ae6 Merge pull request #165 from 67P/docs/blocktime
Document how to configure block time for Ganache
2019-08-09 22:10:06 +00:00
580d6e8f51 Remove yarn lockfiles 2019-08-09 19:03:29 +02:00
a572f02b2e Merge pull request #164 from 67P/chore/remove-cached-artifacts
Remove cached artifacts
2019-08-09 19:00:21 +02:00
abd4caa336 Document how to configure block time for Ganache 2019-08-09 18:58:20 +02:00
f1941eb6b8 Remove cached artifacts
Thos should be generated on every contract app deployment and thus don't need to
be in the repo.
We also don't have those for the other contract apps.
2019-08-09 18:46:36 +02:00
ddeeb5ffd7 Merge pull request #162 from 67P/dev/aragon_truffle
Remove Aragon CLI, document system deps
2019-08-09 18:38:40 +02:00
ae71691c5b Install Aragon CLI and Truffle on Travis 2019-08-09 18:26:38 +02:00
819fbc547a Add contract publish options
This removes most of the features we don't need/want and minimizes
prompts during the bootstrap process.
2019-08-09 18:18:36 +02:00
7236b04b4b Remove Aragon CLI, document system deps
In order to prevent regular issues with the notoriously npm-issue-ridden
Aragon CLI module, this removes it as a direct dependency and requires
it to be installed as a system dependency.

Also adds Truffle as a system dependency to the docs (which was missing
before).
2019-08-09 18:04:21 +02:00
f746470cf6 Merge pull request #161 from 67P/fix_typos
Fix a few typos in the README
2019-08-07 16:42:01 +02:00
Greg Karékinian
5452cf2dad Fix a few typos 2019-08-07 15:55:11 +02:00
3c08e3ecfc Merge pull request #160 from 67P/bugfix/packages-install-scripts
Fix package script command deploy:kit
2019-08-04 19:42:42 +02:00
6e8c994a0a Fix package script command deploy:kit 2019-08-04 19:37:31 +02:00
Haythem Sellami
fd844a00fd Test token app (#157)
* test token app
* update travis config
2019-07-31 15:17:38 +00:00
Haythem Sellami
eb4e06edf1 Contributor app tests (#143)
Adds tests for the contributor contract
2019-07-22 06:55:22 +00:00
4ae17aa36f Merge pull request #156 from haythem96/refactor-get-contract
Refactor get apps contract functions
2019-07-22 06:54:05 +00:00
e14cb0a77d refactor get apps contract functions 2019-07-20 15:06:17 +01:00
d92ad83379 Merge pull request #155 from 67P/bugfix/send-for-new-web3
Fix send-funds script to use new web3 API
2019-07-19 09:11:55 +00:00
fa3e99d404 Fix send-funds script to use new web3 API
The API changed with the recent aragon/truffle update.
2019-07-18 16:25:06 +02:00
4aa5f3aa89 Merge pull request #151 from 67P/chore/remove-ipfs-pinner
Remove IPFS pinner
2019-07-03 12:50:59 +02:00
2316e8f15a Remove IPFS pinner
The pinner now lives in its own npm package
2019-07-02 19:09:26 +02:00
87a468bc91 5.4.0 2019-07-02 16:27:26 +02:00
0734acbcbe Merge pull request #149 from 67P/feature/support-ipfs-gateway
Add support to use IPFS gateway to read ipfs data
2019-07-01 15:41:07 +00:00
a45c8d14be Downgrade IPFS package
The new version uses generators which breaks the build on kredits-web.
2019-07-01 16:12:22 +02:00
61fe9add1b Add support to use IPFS gateway to read ipfs data
This makes caching of IPFS documents easier. Browsers should cache those
by default
2019-07-01 15:53:18 +02:00
16141ed482 Merge pull request #136 from 67P/feature/ipfs-pinner
Add IPFS pinning script
2019-07-01 13:06:45 +02:00
01ef37fd39 Merge pull request #147 from 67P/bugfix/compile_all
Fix compile command
2019-07-01 10:30:41 +00:00
03b9f69d22 Fix compile command
The Aragon one is failing now, but just using the underlying Truffle
command works. So it appears to be the passing of the argument in aragon
that's broken.

Co-authored-by: Michael Bumann <hello@michaelbumann.com>
2019-07-01 12:24:56 +02:00
dd76ebdc8d Merge pull request #141 from haythem96/setup-tests
Solidity test setup
2019-06-26 15:05:23 +00:00
e485bd90c0 install packages 2019-06-19 14:34:14 +01:00
1d89759c49 merge 2019-06-19 13:47:58 +01:00
d653b3715f Update package-lock 2019-06-19 14:10:44 +02:00
a05e2c75f3 Merge pull request #142 from 67P/chore/update-dependencies-2
Chore/update aragon-cli dependencies
2019-06-19 08:39:06 +00:00
124287b977 Updated latest package-json 2019-06-19 01:00:53 +02:00
9906fde7ef Use postshrinkwrap instead of postinstall
`postinstall` is executed before package-lock.json is written to disk.

https://github.com/npm/npm/issues/18798
2019-06-19 00:52:48 +02:00
c7e1f118a6 Add postinstall lockfile fix
https://github.com/67P/kredits-contracts/pull/140
2019-06-19 00:52:47 +02:00
1702c22084 Make sure fix lockfile uses the correct file path 2019-06-19 00:52:47 +02:00
32a123a825 Default to open.aragonpm.eth
it is now also available on the devchain
2019-06-19 00:52:47 +02:00
ac83573438 I don't know why this is needed but it fixes an npm issue
if install fails node scripts/fix-package-lock.js might help
2019-06-19 00:52:47 +02:00
77c6c11800 Remove npm cache and use LTS node on travis 2019-06-19 00:52:05 +02:00
ca0a6f6ef9 user 7545 port for tests 2019-06-17 23:35:53 +01:00
4614c454a5 test setup 2019-06-17 12:13:35 +01:00
86bbe49c0b Fix seeds script to support new web3 version 2019-06-13 18:39:25 +02:00
d5322530c3 Update aragon CLI to latest version 2019-06-13 18:37:33 +02:00
011d85447f Merge pull request #138 from 67P/dev/seeds
Various small seed/script improvements
2019-06-13 16:36:38 +00:00
9fd9dbc1b5 Handle errors in IPFS pin script 2019-06-13 18:31:47 +02:00
b7d87cd8f2 Ignore scripts folder in eslint
Lots of undef etc. due to the scripts being piped through truffle
2019-06-13 17:39:03 +02:00
6c8491e67b Handle errors in seed funding 2019-06-13 17:38:34 +02:00
2623e71055 Update deprecated functions in seeds 2019-06-13 17:38:00 +02:00
ed0d420fd5 Fix linter issues in seeds 2019-06-13 17:37:36 +02:00
36666fd417 Update package lockfile 2019-06-12 16:07:38 +02:00
231d6e2477 Merge pull request #135 from 67P/feature/expose-available-networks
Expose available network IDs
2019-06-12 07:57:31 +00:00
6d6c6056f0 Refactor IPFS pinner 2019-06-12 01:08:07 +02:00
b09c2830c8 Make IPFS node configurable 2019-06-11 23:45:27 +02:00
fc5a41123a Add IPFS pinning script
This script loads the IPFS hashes for contributors and contributions and
pins them on the connected IPFS node.

usage:

    $ node script/ipfs-pinner.js

    $ ETH_RPC_URL=http://localhost:7547 APM_DOMAIN=aragonpm.eth node scripts/ipfs.pinner.js
2019-06-11 21:48:50 +02:00
107654ecca Expose available network IDs
This exposes the network IDs on which kredits is deployed. Helpful to
check if the used network is supported.
2019-06-11 15:45:14 +02:00
810a2eb5fd Merge pull request #134 from 67P/chore/update-dependencies
Update dependencies
2019-06-10 13:19:29 +02:00
06a4e2173a Try npm instead of yarn on travis
There is some strange error with yarn: https://travis-ci.org/67P/kredits-contracts/builds/543186831
2019-06-10 12:59:02 +02:00
e55a209343 Merge pull request #133 from 67P/feature/list-totals
Print total unconfirmed and confirmed contribution kredits
2019-06-09 13:58:42 +02:00
17bc4e7d8f Merge pull request #121 from 67P/refactor/amounts_vs_counts
Improve totalKreditsEarned
2019-06-09 13:57:44 +02:00
4919605664 Merge pull request #130 from 67P/feature/kredits-kit-wrapper
Add JS wrapper for Kit contract
2019-06-09 13:56:32 +02:00
f639e3aa19 Add pre-commit hook and setup script (#129)
Add pre-commit hook and setup script

Runs the appropriate linter on staged files before committing.
2019-06-09 13:53:40 +02:00
84b4461ba6 Update dependencies 2019-06-08 19:05:35 +02:00
c4f8e9278e Use consitently uint32 for amounts 2019-06-08 17:56:50 +02:00
00905eb269 Update ABIs 2019-06-08 17:53:26 +02:00
6a64842415 Only count not-vetoed contributions for total balances 2019-06-08 17:49:24 +02:00
055d8bc0ef Print total unconfirmed and confirmed contribution kredits 2019-06-08 17:42:20 +02:00
91779ccd03 Merge pull request #131 from 67P/feature/claim-contribution-script
Add script to claim contributions for one contributor
2019-05-21 11:29:56 +00:00
516b8b31ac Add script to claim contributions for one contributor 2019-05-20 13:48:15 +02:00
ccd52f6ee5 Cleanup 2019-05-17 18:24:55 +02:00
ffff09ab23 Add contract address accessor 2019-05-17 15:56:24 +02:00
3df0831d9b Cleanup whitespace 2019-05-17 15:56:02 +02:00
27a746261c Add JS wrapper for kredits kit
This makes it easier to deploy new DAOs and the deploy script is less
dependent on truffle
2019-05-17 15:54:52 +02:00
345b6bde82 Merge pull request #127 from 67P/feature/allow-setting-contributor-accounts
Allow setting any contributor accounts
2019-05-17 08:42:43 +00:00
a86ea08bdf Merge pull request #128 from 67P/feature/simple-init
Add helper to initialize a new instance with provider
2019-05-17 07:37:10 +00:00
e20bda73fb Remove not needed network check
We default to localhost anyway
2019-05-17 09:17:10 +02:00
4c64aa7c2a linting 2019-05-14 12:03:29 +02:00
cf43bf9487 Linting 2019-05-14 11:32:42 +02:00
1a227ba67c Linting 2019-05-14 11:31:33 +02:00
df7536589d Add helper to initialize a new instance with provider
So far we always had to initialze a provider and signer and pass those
to the kredits constructor.
This helper makes it easier to initialize a default ethers provider and
a default signer.
2019-05-14 11:25:21 +02:00
f0fe62f6d7 Apply suggestions from code review
Co-Authored-By: Sebastian Kippe <sebastian@kip.pe>
2019-05-14 09:18:23 +00:00
66fc992291 Allow setting any contributor accounts
This allows to pass in an account object when creating or updating a
contribtor.
2019-05-14 11:06:49 +02:00
2a675c9417 Merge pull request #126 from 67P/chore/update_schemas
Update kosmos-schemas
2019-05-10 16:08:30 +02:00
a3590d7c16 Update kosmos-schemas
Includes the new "special" contribution kind, as discussed in our last
call.
2019-05-10 13:14:56 +02:00
07a5ca847d Merge pull request #125 from 67P/bugfix/pagination
Fix page number calculation for zero records
2019-05-07 17:12:16 +02:00
37ce2fddde Merge pull request #124 from 67P/bugfix/fix-me-1
Fix util import
2019-05-04 08:40:58 +00:00
3a43284557 Fix page number calculation for zero records
So far it returned 0 because of those in range checks which both
applied because numberOfPages is 0 if we have no record.
2019-05-04 01:34:05 +02:00
572848c04a Fix util import 2019-05-04 01:09:22 +02:00
b6ce9dcfc8 Merge pull request #118 from 67P/deprecate/old-add-methods
Deprecate old add* methods
2019-05-01 18:12:18 +00:00
e7e8744ad2 Update lib/contracts/proposal.js
Co-Authored-By: bumi <hello@michaelbumann.com>
2019-05-01 18:06:55 +00:00
d2198dca61 Update lib/contracts/contribution.js
Co-Authored-By: bumi <hello@michaelbumann.com>
2019-05-01 18:06:43 +00:00
f9f2ef234e Merge pull request #122 from 67P/feature/veto_script
Add script for vetoing via console
2019-05-01 18:05:37 +00:00
a1f51428d0 Add script for vetoing via console 2019-04-28 15:09:18 +01:00
555cb53c78 Improve totalKreditsEarned
* Use a more reasonable size of integer
* Use better variable names (count != amount, balance != count)
2019-04-27 21:01:51 +01:00
ad74d30aa7 Contributor canPerform fix deployment 2019-04-25 22:25:38 +02:00
3568d3c141 Merge pull request #120 from 67P/bugfix/fix-core-permissions
Fix canPerform method
2019-04-25 21:17:37 +01:00
db566a581f Merge pull request #119 from 67P/bugfix/fix-kit-deployment
Fix apps lookup
2019-04-25 21:10:04 +01:00
c69ebd0a62 Fix canPerform method
Even if the variable is not used and the linter might complain we have
to have that parameter in the signature. otherwise the method is not
found and can not be called.
2019-04-25 22:06:40 +02:00
5c375f764f Update scripts/deploy-kit.js
Co-Authored-By: bumi <hello@michaelbumann.com>
2019-04-25 20:05:03 +00:00
b04d572b9a Fix apps lookup
We use the directories in ./apps to load available app names.
For this we need to make sure that we only use directories.
2019-04-25 16:45:39 +02:00
1199b053fe Add missing returns for the deprecated methods 2019-04-24 21:55:10 +02:00
f06b21dfee Deprecate old add* methods 2019-04-24 21:49:27 +02:00
d643e5842c Merge pull request #97 from 67P/chore/linter
Add linter and travis.yml
2019-04-24 18:28:32 +00:00
a87d5326bf Oh my package-lock 2019-04-24 20:17:03 +02:00
c9fed46054 Add contract test linting 2019-04-24 19:56:37 +02:00
6f2097ed46 Fix regex 2019-04-24 19:39:30 +02:00
94d342ce63 Replace console.log by deprecate function 2019-04-24 19:31:26 +02:00
f984dec95a Style fixes 2019-04-24 19:31:04 +02:00
145b3ea766 Merge branch 'master' into chore/linter
# Conflicts:
#	lib/contracts/contribution.js
#	lib/contracts/contributor.js
#	lib/contracts/proposal.js
#	lib/kredits.js
#	lib/serializers/contributor.js
#	yarn.lock
2019-04-24 19:12:18 +02:00
a80dfee5c5 Merge pull request #116 from 67P/deployments/balance-update
Release/deployment notes for latest contract updates on Rinkeby
2019-04-24 17:03:48 +01:00
4649de24c8 Deploy notes for latest contributor and contribution deployment 2019-04-24 17:32:58 +02:00
8539b56a48 5.3.0 2019-04-24 14:22:53 +01:00
f59c37827a Merge pull request #108 from 67P/feature/kredits-formatter
Add kredits-formatter and additionally format balance
2019-04-24 14:20:44 +01:00
58db57ee45 Merge branch 'master' into feature/kredits-formatter 2019-04-24 13:10:48 +00:00
b64a7ca299 Merge pull request #113 from 67P/feature/gitea_site
Add Gitea site/username to serializer and seeds
2019-04-24 12:58:44 +00:00
6f09ca8d13 Merge pull request #114 from 67P/chore/scripts
Improve/fix scripts
2019-04-24 12:57:43 +00:00
6f53c8097e Wrap anything that could break in the try/catch block 2019-04-24 14:55:35 +02:00
6b2ac15f56 Improve error handling for list-contributors script 2019-04-24 13:46:27 +01:00
359989f235 Fix function name for total kredits issued/earned 2019-04-24 13:45:56 +01:00
5894f6323b Add Gitea username to contributor seeds 2019-04-24 13:43:46 +01:00
09b78e1e8f Add Gitea site/username to contributor serializer 2019-04-23 20:28:56 +01:00
48c8f6b9b3 Merge branch 'master' into feature/kredits-formatter 2019-04-23 12:56:55 +00:00
542ebaf3f3 5.2.0 2019-04-23 13:52:46 +01:00
d82ffba75e Update ABI 2019-04-23 13:52:37 +01:00
bdb2cee0c4 Merge pull request #110 from 67P/feature/contribution-balances
Add contract calls for total contribution balances
2019-04-23 13:47:50 +01:00
cd45ce260f Merge pull request #112 from 67P/feature/update-contributor-profile
Update contributor profile
2019-04-20 09:22:31 +00:00
3a97983540 Merge pull request #111 from 67P/feature/contributor-schema-validation
Add Contributor validation against JSON schema
2019-04-20 08:47:49 +01:00
9714926e11 Add function to update contributor profile to wrapper
The function updates the contributor profile,
adds the new profile to IPFS and does the contract call to update
the profile hash
2019-04-20 02:17:38 +02:00
59614201b5 Ups... 2019-04-20 02:15:53 +02:00
e591742e40 Add Contributor validation against JSON schema
based on the Contribution validation.
2019-04-20 01:10:46 +02:00
791190f5e7 Cleanup promise call 2019-04-20 00:30:20 +02:00
24b66daf2a Update ABI 2019-04-19 14:16:40 +02:00
ad034d7712 Naming is hard 2019-04-19 14:15:30 +02:00
375d8f3275 Cleanup 2019-04-19 13:34:39 +02:00
80dc787971 Merge pull request #109 from 67P/dev/list_contributors_error_handling
Handle errors in contributor list script
2019-04-19 11:22:38 +00:00
7967dc26f2 Update ABIs 2019-04-19 13:20:25 +02:00
c248725cc1 Add balances to getContributorById call 2019-04-19 13:19:55 +02:00
59135bf312 Add contract calls for total contribution balances
Those methods return the total kredits amounts of contribtions.
2019-04-19 13:06:36 +02:00
1d771c43e8 Handle errors in contributor list script 2019-04-19 12:02:28 +01:00
3cb94fb660 Add kredits-formatter and additionally format balance
This adds a `balanceInt` value to the contributor data that has the
token balance formatted as full Kredits. (similar to Ether)
2019-04-19 11:57:35 +02:00
5820d71b2c Merge pull request #96 from 67P/feature/pagination
Add pagination for .all methods
2019-04-17 13:53:17 +00:00
4771c0c8a0 Merge branch 'master' into feature/pagination 2019-04-17 13:52:53 +00:00
2a1ae117e8 5.1.1 2019-04-16 12:50:07 +01:00
8abc7ba77f Merge pull request #104 from 67P/chore/update-kosmos-schema
Update kosmos-schema dependency
2019-04-16 11:19:03 +00:00
f696721918 Readme: add note about locally running out of funds 2019-04-16 13:17:54 +02:00
00b58dec66 Update kosmos-schema dependency 2019-04-16 13:16:05 +02:00
560315cbca Merge pull request #102 from 67P/chore/add-yarn-support
Add yarn lock files
2019-04-15 15:54:38 +00:00
24933f31a7 Add yarn lock files 2019-04-15 17:34:48 +02:00
b13bf6e8b0 Readme: add note about locally running out of funds 2019-04-15 15:59:54 +02:00
8dcad88372 Merge pull request #99 from 67P/update-seeds
Update seeds
2019-04-15 10:39:10 +00:00
dc6d2716aa Update seeds 2019-04-15 12:33:51 +02:00
80ad9db630 5.1.0 2019-04-13 12:41:49 +01:00
6f97c905d6 Add count property and DRY 2019-04-13 13:05:47 +02:00
1b5f7ff95d Merge pull request #93 from 67P/deployments/weltempfaenger-release
Production release to rinkeby
2019-04-13 11:07:58 +01:00
b5b12e22ce Readd solhint:default 2019-04-13 01:53:52 +02:00
fe811cdb12 Use solhint:recommended 2019-04-13 01:17:38 +02:00
42df6fe310 Fix solhint invocation 2019-04-13 01:10:40 +02:00
c8805be054 Switch to yarn 2019-04-13 00:19:52 +02:00
764f63fc8c Trigger build 2019-04-13 00:14:23 +02:00
f73ccedf42 Activate linting on travis 2019-04-13 00:10:21 +02:00
a9093c1c40 Fix linter errors
# Conflicts:
#	lib/contracts/contribution.js
#	lib/contracts/contributor.js
#	lib/contracts/proposal.js
#	lib/kredits.js
#	lib/utils/pagination.js
2019-04-13 00:08:12 +02:00
e405644b1d Add eslint and solhint 2019-04-13 00:03:16 +02:00
f6189bf910 Add pagination for .all methods
I removed rsvp as a dependency as we only use Promise.all
2019-04-12 21:21:19 +02:00
b6c06c289c Merge pull request #95 from 67P/cosmetics
Cosmetic cleanups
2019-04-12 18:55:59 +00:00
f405e39c04 Merge pull request #94 from 67P/bugfix/schema_changes
Refactor contribution serializer and validation
2019-04-12 18:54:56 +00:00
1dbf3b5742 Cosmetic cleanups 2019-04-12 20:16:24 +02:00
952b5153fd Validate proposed contributions 2019-04-11 13:46:42 +02:00
d953141f52 Refactor contribution serializer and validation 2019-04-11 13:05:40 +02:00
aa57d7c70b Adjust seeds for new requirements 2019-04-11 11:02:15 +02:00
4c0bb879e8 Show IPFS hash in list script output 2019-04-11 11:01:45 +02:00
9c5a517fb9 5.0.0 2019-04-11 08:45:49 +02:00
b00ddda312 Merge pull request #92 from 67P/feature/contribution_schema
Validate contribution docs against schema
2019-04-11 08:40:38 +02:00
130e2a7797 Validate contribution docs against schema
Currently requires an open PR branch for the schemas, which is adding
date and time for contributions.

refs #30
2019-04-10 18:37:02 +02:00
27e5190e29 Production release to rinkeby
Deployed all apps and created a new Kredits DAO
2019-04-10 18:28:24 +02:00
b9c171884b Merge pull request #91 from 67P/feature/store-balance-as-wei
Store kredits tokens as wei with 18 decimals
2019-04-10 15:51:36 +02:00
4d2e0ea84b Update Token symbol 2019-04-10 15:50:33 +02:00
26d12ba239 Store kredits tokens as wei with 18 decimals
This stores the tokens with 18 decimals as most other tokens and as
assumed by a potential future token standard EIP 777.
2019-04-10 13:59:00 +02:00
1aae62e139 Merge pull request #88 from 67P/bugfix/confirmed-contributions
Fix confirmed contribution check
2019-04-09 22:36:37 +02:00
f21c4cf9de Fix confirmed contribution check
If the blocknumber is higher or equal the contribution.confirmedAt block
number then the contribution is confirmed and can be claimed.
2019-04-09 22:30:17 +02:00
6778b9060f 4.0.2 2019-04-09 12:47:59 +02:00
4d36f78824 4.0.1 2019-04-09 12:47:37 +02:00
98ecf28262 Merge pull request #87 from 67P/dev/dependency_install
Rename postinstall script
2019-04-09 12:45:41 +02:00
f5564fa923 Formatting, whitespace 2019-04-09 12:45:20 +02:00
096a9f3cea Update README for install-all script 2019-04-09 12:45:09 +02:00
3d24835908 Merge pull request #86 from 67P/dev/bootstrap
Don't run `npm install` on bootstrap
2019-04-09 09:50:51 +02:00
8cbef8458d Rename postinstall script
Prevents it being run when contracts are installed as dependency.
2019-04-09 09:48:00 +02:00
9ca0580db6 Merge pull request #85 from 67P/dev/fix_seeds
Fix contributor ID in seeds
2019-04-09 07:33:42 +00:00
dfe38e7d21 Don't run npm install on bootstrap
When one wants to install, they can install. When one wants to
bootstrap, they should be able to only bootstrap.
2019-04-09 08:44:56 +02:00
377560805f Fix contributor ID in seeds
We have one contributor less, after having removed the initial dummy
account recently.
2019-04-09 08:43:13 +02:00
65d9cf2a06 Fix bootstrap
This runs npm install for every app through a postinstall hook.
2019-04-08 18:10:13 +02:00
b35dc2049b Merge pull request #82 from 67P/dev/list_contributions
Improve list-contributions script
2019-04-06 19:40:24 +00:00
26c2710149 Improve list-contributions script
* Improve sort order of table columns
* Print if the contribution is confirmed
* Log error if something goes wrong
2019-04-06 17:56:48 +02:00
cc24c27444 Merge pull request #80 from 67P/chore/rename-ipfshash-1
Rename ipfsHash to hashDigest in Contributor
2019-04-06 13:55:19 +00:00
f717968402 Better function naming to update contributor profiles 2019-04-06 15:42:16 +02:00
14d7fbd75e Rename ipfsHash to hashDigest in Contributor
naming should be consistent with the other contracts and digest is more
correct.
2019-04-06 15:24:44 +02:00
7eb1fedb42 Merge pull request #76 from 67P/features/dynamic-core-flag
Dynamic function to test for core contributor flag
2019-04-06 15:19:01 +02:00
cbfe39f804 Merge pull request #78 from 67P/feature/veto-period
Set contribution veto period to 1 week
2019-04-06 00:30:30 +02:00
a0e4f5410d Set veto period to 1 week
This makes a contribution claimable after roughly 7 days
2019-04-05 20:30:02 +02:00
766463b57b Dynamic function to test for core contributor flag
This removes the isCore flag and allows us to dynamically calculate the
core flag for contributors.

For now this is just us (the first 6 contirbutors)

Also we do not need the default contributor anymore because the deploy
user has the role to manage contributors and can create the first real
contributors.
2019-04-05 18:55:21 +02:00
93e0b30b35 4.0.0 2019-04-05 15:44:51 +02:00
6510dca4b1 Fix provider fallbacks for non dev networks
This now checks if frame or a local node is running and else uses infura
to connect to the ethereum network.
Now you can use all the helpers for the testnets/mainnet without running
anything (in readonly mode)
2019-04-05 13:51:23 +02:00
551edcfa72 Fix init kredits for readonly providers
The apm option was not passed on to kredits
2019-04-05 01:05:16 +02:00
d58e2d560a deploy to rinkeby 2019-04-05 00:38:51 +02:00
99394e7f14 Merge pull request #73 from 67P/feature/contribution_owner
Convert contribution owner to ID, use smaller number formats
2019-04-04 21:40:16 +00:00
8ceab08bfc ups 2019-04-04 23:23:02 +02:00
896db5e047 Update abi 2019-04-04 23:16:23 +02:00
d507d7b562 Enable all seeds again 2019-04-04 23:16:01 +02:00
40c5d2a275 Merge branch 'master' into feature/contribution_owner 2019-04-04 23:12:16 +02:00
a049f2eedb Adjust proposals for format changes 2019-04-04 23:11:43 +02:00
b68b037000 Merge pull request #74 from 67P/chore/npm-scripts
Add some helpers to reset a fresh DAO and upgrade an app
2019-04-04 23:11:12 +02:00
181e6f3c23 Fix/refactor contribution wrapper 2019-04-04 22:56:06 +02:00
19556349f6 Fix syntax error 2019-04-04 22:30:27 +02:00
a1a1c5ef9f Get contributor by ID
Co-Authored-By: skddc <sebastian@kip.pe>
2019-04-04 22:29:37 +02:00
afbd114a36 Add app upgrade helper script
This script deploys a new app version, upgrades the given DAO to the
latest version of that app and builds the ABI files for the wrapper.

usage:

    scripts/upgrade.sh <app name> <dao address>

e.g.

    scripts/upgrade.sh token 0xfoobar

The DAO address can also be set as environment variable
$KREDITS_DAO_ADDRESS
2019-04-04 19:51:38 +02:00
db312dafbf Add some helpers to reset a fresh DAO 2019-04-04 19:27:57 +02:00
e4c3d9a468 Update abi 2019-04-04 16:28:34 +02:00
5b49f82544 Adjust wrapper and scripts for contract changes 2019-04-04 16:24:37 +02:00
6088f30cd8 Use smaller numbers for contributor ID
2.2 billion contributors should be enough.
2019-04-04 16:01:08 +02:00
f1e2c65b9e Use smaller numbers where appropriate 2019-04-04 15:28:18 +02:00
786f38cfb7 Print errors in seed contract calls 2019-04-04 15:25:31 +02:00
197a31b9e1 Remove whitespace 2019-04-04 14:47:25 +02:00
20acfc70e3 Use ID instead of address for contribution owner 2019-04-04 14:43:38 +02:00
732dfe7b29 Merge pull request #71 from 67P/chore/update_seeds
Update seeds
2019-04-04 11:32:58 +00:00
3ce8f41d32 Merge pull request #72 from 67P/chore/whitespace
Remove unnecessary space chars
2019-04-04 11:17:35 +00:00
e0ff29d1c9 Remove unnecessary space chars 2019-04-04 11:38:18 +02:00
0ce62839e9 Update seeds
Use more realistic data, add more contributions
2019-04-04 11:32:46 +02:00
cc2c9a7368 Merge pull request #70 from 67P/feature/claim-contribution-in-seeds
Update seeds
2019-04-03 21:50:43 +02:00
1abfc5a265 Merge pull request #69 from 67P/fix/add-contributor-permissions
Fix permissions to manage contributors
2019-04-03 21:50:19 +02:00
6b9466c348 Update seeds
Claim contribution which issues Kredits to the contributor
2019-04-03 21:40:37 +02:00
9fffdbfb58 Fix permissions to manage contributors
Uses the contributor oracle to decide if somebody has the
MANAGE_CONTRIBUTOR_ROLE
2019-04-03 21:22:53 +02:00
350dadec4d Merge pull request #68 from 67P/update-ipfs-package
Update ipfs package
2019-04-03 21:16:22 +02:00
70b9edbcac Update ipfs package 2019-04-03 21:01:51 +02:00
92da07dca2 Merge pull request #67 from 67P/feature/contributor-balance-1
Add balance when loading contributor
2019-04-03 20:22:50 +02:00
6fed81c0ed Merge pull request #66 from 67P/chore/seeds
Allow seed tx to fail
2019-04-03 17:03:22 +00:00
74e61e1393 Show balance in list-contributors helper script 2019-04-03 14:05:16 +02:00
6351db3057 Add balance when loading contributor
This is a regression introduced by the latest contract updates.
Now we return the balance again when loading contributor data.
2019-04-03 13:56:52 +02:00
ed3e5dd4c4 Allow seed tx to fail
This allows for running seeds multiple times, e.g. after adding new
ones.
2019-04-03 11:41:55 +02:00
bd39d0f126 Use new address for raucao seed 2019-04-03 11:41:45 +02:00
4c8ee69664 Merge pull request #65 from 67P/fix/ethersjs-namehash
Use namehash from ethers.utils
2019-04-03 11:39:35 +02:00
eae8967322 Merge pull request #63 from 67P/fix/contriutor-permissions
Fix contributor oracle permission auth
2019-04-03 11:37:10 +02:00
9984ca66ba Use namehash from ethers.utils
no need for the additional dependency
2019-04-03 10:24:11 +02:00
1b09a30646 Fix contributor oracle permission auth
It seems that the entity is either defined by the permission or if we
want to use the oracle the permission must be defined for any_entity.
In that case the oracle does not get the msg.sender as who/entity thus
we will use tx.origin in that case.
2019-04-03 10:06:00 +02:00
f40cc1d8ff Merge pull request #62 from 67P/aragonos
Build on aragonOS
2019-04-02 21:36:36 +02:00
91135dbc82 Fix deploy-kit helper script
We no longer need the app ids as json. Those are dynamically calculated
now
2019-04-02 18:06:33 +02:00
adb7122a28 Add helper script for updating local address file
Can be run after starting the devchain, so that all local truffle
scripts work with the new network ID.
2019-04-02 17:35:28 +02:00
ce446e530d Set Kreits apm from arapp.json file in helper scripts
different networks might require different apm domains. We set those in
the arapp.json file which we can reuise to init the kredits instance in
the helper scripts.
2019-04-02 09:58:44 +02:00
fedb10c5da Dynamically get app ids from the namehash
This dynamically hashes the app id which makes it easier to manually set
contract addresses. This is useful in development environments with no
default network ids.
The used apm (which is part of the app id hash) is configurable.

usage:

new Kredits(provider, signer, { addresses: { Kernel: '0x...' }, apm: 'aragonpm.eth' })
2019-04-01 22:41:00 +02:00
a24f80d44f Change addresses 2019-04-01 14:04:11 +02:00
61fa26da7a Add more information output to the send funds helper 2019-04-01 11:53:50 +02:00
9512ba4334 Update contract addresses 2019-04-01 11:19:30 +02:00
65c129eafd Update package locks 2019-04-01 11:17:26 +02:00
c2f763bec7 Add missing variable assignment 2019-04-01 11:16:55 +02:00
c93a81808a Update package lock 2019-04-01 10:34:48 +02:00
51e5da414f Update ethers.js to latest version v4
The main change is how ethers loads the networkId which is now async.
Thus the init process had to change a bit
2019-03-29 18:13:51 +01:00
3662f1ae24 Add Operator getter for backwards compatibility 2019-03-29 15:03:37 +01:00
c568263fea update eth-provider to support different providers
Ideally eth-provider checks which connection is available and uses the
available one.
frame => local node => infura

But it seems there is still a bug and it raises an error if frame is not
available.
But at least we can use frame now for testnet/mainnet deployments
2019-03-29 12:08:07 +01:00
38079d07db remove debug console 2019-03-29 12:07:52 +01:00
0cc67c2fad Support getting the network version from different web3
version/providers
2019-03-29 12:07:09 +01:00
a45be0021e Fix old registry reference 2019-03-29 12:06:43 +01:00
4bd1aed197 Refactor kredits init in helper scripts
This now also supports readonly providers like infura
2019-03-29 12:05:51 +01:00
94832d4d07 Add ACL contract wrapper
this mainly allows us to check if an account has a certain role and thus
if the account can call specific contract functions.

At some point we might want to extend that to support the check if an
account can call the function. For that we would need to have a mapping
between function names and roles, which we have not right now.
2019-03-28 12:39:04 +01:00
4f5ae01c5a Add helper funtion to list contract entries 2019-03-28 11:16:20 +01:00
d6f99f57b7 Auto resolve promises in repl 2019-03-28 11:12:32 +01:00
901566d1ff Update network specific addresses and app ids 2019-03-28 11:11:49 +01:00
5d4be8f176 Update ABIs used by wrapper 2019-03-28 11:09:49 +01:00
f9ab8b225a Fix proposal wrapper to support the latest contracts 2019-03-28 11:08:34 +01:00
dfa55516ec Add contribution veto function
Allows anybody with the VETO_CONTRIBUTION_ROLE to veto a contribution
and thus prevent that the contribution can be claimed.
So far like the ADD_CONTRIBUTION_ROLE any contributor is allowed to
veto.
2019-03-28 11:06:19 +01:00
b6f34ac9a5 Pretty print JSON for contract addresses
This makes it easier to read the file and a git diff is more useful
2019-03-27 21:58:19 +01:00
258c6729b6 Cleanup scripts and use helper to get the networkid 2019-03-27 17:06:52 +01:00
b201642485 remove obsolete comment 2019-03-27 16:56:52 +01:00
0686c79998 Print dao address and kreditskit address 2019-03-27 16:56:24 +01:00
7e68dbf8c2 rinkeby deployment 2019-03-27 00:39:00 +01:00
f5973756c8 Dynamically set AppIds
AppIds are used to lookup the actual contract addresses of each app.
Because of different registry names (open.aragonpm.eth vs. aragonpm.eth)
we have to use different ids in the local dev chain and in the
testnet/mainnet. To allow this we need to set the appids dynamically.

There is an open aragon issue to solve this and also allow to use
open.aragonpm.eth in the devchain by default.
https://github.com/aragon/aragen/issues/10
2019-03-27 00:21:06 +01:00
9cc237fbf4 Support web3 providers that do not support sync calls
This is currently the non default web3 provider used for rinkeby etc.
2019-03-26 00:35:22 +01:00
3584a73c08 Set kredits-<name>.open.aragonpm.eth as appid hashes 2019-03-26 00:34:46 +01:00
3c2cdf4376 Deployment hacking while trying to deploy on rinkeby
This currently breaks the local usage because of the different appIds:
<name>.open.aragonpm.eth vs. <name>.aragonpm.eth (local)
2019-03-26 00:18:59 +01:00
fbda45376e cleanup contract debugging and make sure contributions are only once claimable 2019-03-24 22:33:16 +01:00
cd7df3893e readme 2019-03-24 22:18:19 +01:00
e1fea4ed97 refactor DAO deployment 2019-03-24 22:11:24 +01:00
12341d1526 Add script to print current DAO address 2019-03-24 16:09:00 +01:00
14b23ecdf1 move app bootstrap script to scripts 2019-03-24 15:45:48 +01:00
1679afb9b4 formatting 2019-03-24 14:43:43 +00:00
b03095e149 Cleanup and readme
simplify bootstrap
2019-03-24 15:40:46 +01:00
0d9b2d7d58 readme 2019-03-24 11:01:59 +01:00
e7affdb531 updated npm scripts 2019-03-24 00:58:56 +01:00
1594bf0e17 update seeds 2019-03-24 00:39:46 +01:00
203199c268 cleanup 2019-03-24 00:21:36 +01:00
116f69cb12 cleanup 2019-03-24 00:20:48 +01:00
6c569239de refactor contrats with aragonos 2019-03-23 19:15:23 +01:00
d687ff604e Merge branch 'master' into contribution-contract
* master:
  Update truffle and ganache-cli
2018-09-29 19:54:28 +02:00
c9a4b1decc Update truffle and ganache-cli 2018-09-29 19:52:14 +02:00
dae44cac70 Continue Contribution contract and JS wrapper 2018-09-29 19:46:37 +02:00
6b8f718051 Create contribution when proposal gets executed 2018-06-18 18:43:35 +02:00
6d9a54b71c Remove whitespace 2018-06-18 18:42:32 +02:00
75d426f0cc Add Contribution contract
The contribution contract implements an ERC721 interface which
represents any contribution.
The contributions are non-fungible (as opposed to the Kredits tokens)
and can be not be transferred. The contract stores the history of any
contribution.
Contributions can be claimed which will issue the Kredits tokens to the
contributor.

This is an early implementation and misses some access control and
probably more things.
2018-06-18 15:28:50 +02:00
7ce100e819 3.0.2 2018-06-15 09:44:11 +02:00
7216522d83 Update Operator ABI 2018-06-15 09:42:29 +02:00
956f858620 Rename healthcheck to preflight 2018-06-07 16:39:07 +02:00
8a7abba486 Add keywords to package config 2018-05-03 13:31:49 +02:00
c6c48f49d2 Add npm version badge 2018-05-03 13:24:40 +02:00
db2e12c750 3.0.1 2018-05-03 13:20:06 +02:00
7dc75a19b5 Clean your room, kiddo. 2018-05-03 12:40:24 +02:00
926913da50 Update description 2018-05-03 12:40:16 +02:00
a045702937 Use normal Markdown extension
Hardly anyone uses `.mdown`, so let's use what everyone knows and looks
for.
2018-05-03 12:32:36 +02:00
102 changed files with 40153 additions and 6794 deletions

6
.dockerignore Normal file
View File

@@ -0,0 +1,6 @@
.openzeppelin
artifacts
cache
deployments
gitno
node_modules

40
.drone.yml Normal file
View File

@@ -0,0 +1,40 @@
kind: pipeline
type: docker
name: default
steps:
- name: setup
image: gitea.kosmos.org/kredits/docker-ci:latest
commands:
- cp -r /app/node_modules /drone/src/node_modules
- chown -R drone:drone /drone/src
- su drone -c 'npm install'
- name: lint js
image: gitea.kosmos.org/kredits/docker-ci:latest
commands:
- su drone -c 'npm run lint:wrapper'
depends_on:
- setup
# - name: lint contracts
# image: gitea.kosmos.org/kredits/docker-ci:latest
# commands:
# - su drone -c 'npm run lint:contracts'
# depends_on:
# - setup
- name: build contracts
image: gitea.kosmos.org/kredits/docker-ci:latest
commands:
- su drone -c 'npm run devchain -- --silent' &
- sleep 5
- su drone -c 'npm run build'
depends_on:
- setup
- name: test
image: gitea.kosmos.org/kredits/docker-ci:latest
commands:
- su drone -c 'npm run devchain -- --silent' &
- sleep 5
- su drone -c 'npm test'
depends_on:
- setup
- build contracts

2
.eslintignore Normal file
View File

@@ -0,0 +1,2 @@
/scripts/
/test/

33
.eslintrc.js Normal file
View File

@@ -0,0 +1,33 @@
module.exports = {
'env': {
'browser': true,
'es6': true,
'node': true
},
'extends': 'eslint:recommended',
'globals': {
'Atomics': 'readonly',
'SharedArrayBuffer': 'readonly'
},
'parserOptions': {
'ecmaVersion': 2018,
'sourceType': 'module'
},
'rules': {
'comma-dangle': ['error', {
arrays: 'always-multiline',
objects: 'always-multiline',
imports: 'never',
exports: 'never',
functions: 'ignore',
}],
'eol-last': ['error', 'always'],
semi: ['error', 'always'],
'space-before-function-paren': ['error', {
anonymous: 'never',
named: 'always',
asyncArrow: 'always',
}],
'indent': ['error', 2]
}
}

4
.github/release-drafter.yml vendored Normal file
View File

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

10
.gitignore vendored
View File

@@ -1,4 +1,12 @@
build
node_modules
**/node_modules
.ganache-db
.tm_properties
yarn-error.log
.DS_Store
data
cache
artifacts
.openzeppelin

1
.nvmrc Normal file
View File

@@ -0,0 +1 @@
16

9
.solhint.json Normal file
View File

@@ -0,0 +1,9 @@
{
"extends": [
"solhint:default",
"solhint:recommended"
],
"rules": {
"indent": "2"
}
}

13
Dockerfile Normal file
View File

@@ -0,0 +1,13 @@
# syntax=docker/dockerfile:1
FROM node:16.16
#ENV NODE_ENV=production
RUN useradd -ms /bin/bash drone
WORKDIR /app
COPY ["package.json", "package-lock.json*", "./"]
RUN chown -R drone:drone /app
USER drone
RUN npm install
USER root

156
README.md Normal file
View File

@@ -0,0 +1,156 @@
[![npm](https://img.shields.io/npm/v/kredits-contracts.svg)](https://www.npmjs.com/package/kredits-contracts)
# Kredits Contracts
This repository contains the Solidity smart contracts and the JavaScript API
wrapper for [Kosmos Kredits](https://wiki.kosmos.org/Kredits).
## Development
### Installation
#### App dependencies
All requirements are defined in `package.json`.
$ npm install
### Local development chain
We use [hardhat](https://hardhat.org/) as development environment for the
smart contracts.
To run a local development chain run:
$ npm run devchain # or: hardhat node --network hardhat
### Bootstrap
1. Run an Ethereum node and ipfs
$ npm run devchain
$ ipfs daemon
2. Compile contracts and build ABIs
(compiled artifacts will be in `/artifacts`)
$ npm run build
3. Deploy new upgradable contract proxies
$ npm run deploy:dao
4. Execute seeds to create demo contributors, contributions, etc. (optional)
$ npm run seeds
**Step 2-4 is also summarized in `npm run bootstrap`**
5. Show contract addresses
$ cat lib/addresses.json
## Fund a local development account
If you need to fund development accounts with devchain coins:
$ npm run fund # or hardhat fund --network localhost
## Contract architecture
We use the [OpenZeppelin hardhat
proxy](https://www.npmjs.com/package/@openzeppelin/hardhat-upgrades) for
deploying and managing upgradeable contracts. (see `scripts/create-proxy.js`)
Each contract is independent and is connected to its dependencies by storing
the addresses of the other contracts.
## Helper scripts
`scripts/` contains some helper scripts to interact with the contracts from the
CLI. _At some point these should be moved into a real nice CLI._
To run these scripts use `hardhat run`. For example: `hardhat run
scripts/list-contributors.js --network localhost`. (NOTE: add `--network
localhost` or the network you want to use)
Some scripts are also defined as npm script, see `package.json`.
### repl/console
Similar to cli.js but only provides a REPL with an initialized `kredits`
instance.
$ hardhat console --network localhost
### add-{contributor, contribution, proposal}.js
Script to add a new entries to the contracts using the JS wrapper
$ hardhat run scripts/add-{contributor, contribution, proposal}.js --network localhost
### list-{contributors, contributions, proposals}.js
List contract entries
$ hardhat run scripts/list-{contributors, contributions, proposals}.js --network localhost
### seeds.js
Run seeds defined in `config/seeds.js`.
$ npm run seeds
### Get the contract addresses
All contract addresses are stored in `lib/addresses.json`
$ cat lib/addresses.json
## Upgradeable contracts
We use OpenZeppelin for an upgradeable contracts:
[https://www.npmjs.com/package/@openzeppelin/hardhat-upgrades](https://www.npmjs.com/package/@openzeppelin/hardhat-upgrades)
Refer to the OpenZeppelin README and `scripts/create-proxy.js`
[OpenZeppelin Step by Step guide](https://forum.openzeppelin.com/t/openzeppelin-upgrades-step-by-step-tutorial-for-hardhat/3580)
For an upgrade example checkout `scripts/upgrade-example.js`
## Deployment to other networks
Deployable networks are configured in the `hardhat.config.js`.
To deploy to those networks provide the `--network` argument to the hardhat
commands, e.g. `--network rsk`.
Please note that some npm scripts combine multiple hardhat commands. In those
cases the hardhat commands needs to be run manually with the `--network`
argument. (=> don't use `npm run bootstrap`)
Set a `DEPLOY_KEY` environment variable with the private key (HEX) which will
be used as a root/deploy account
Typical deployment flow:
$ npm run build
$ hardhat run scripts/create-proxy.js --network rsk
# OR with deploy key:
$ DEPLOY_KEY=0xsomething hardhat run scripts/create-proxy.js --network rsk
$ # commit the new addresses in the addresses.json file if needed
To run the console on one of the non localhost networks you can also just pass
on the --network argument.
$ hardhat console --network rsk
## Known Issues
When resetting ganache Metamask might have an invalid transaction nonce and
transactions get rejected. Nonces in Ethereum must be incrementing and have no
gap.
To solve this reset the metamask account (Account -> Settings -> Reset Account)

View File

@@ -1,152 +0,0 @@
# Kredits
This repository contains all the contracts for Kredits as a [truffle framework](http://truffleframework.com/) project.
## Development
### Installation
$ npm install
### Requirements
All requirements are defined in `package.json`.
Those can be installed globally for convenience:
* [truffle framework](http://truffleframework.com): `npm install -g truffle`
* [ganache](http://truffleframework.com/ganache): `npm install -g ganache-cli`
We use following solidity contract libraries:
* [Open Zeppelin](https://github.com/OpenZeppelin/zeppelin-solidity)
For local development it is recommended to use [ganache-cli](https://github.com/trufflesuite/ganache-cli) (or the [ganache GUI](http://truffleframework.com/ganache/) to run a local development chain.
Using the ganache simulator no full Ethereum node is required.
We default to:
* port 7545 for development to not get in conflict with the default Ethereum RPC port.
* network ID 100 to stay on the same network id
* store ganache data in .ganache-db to presist the chain data across restarts
* use a fixed Mnemonic code to get the same accounts across restarts
Have a look at `ganache-cli` for more configuration options.
Run your ganache simulator before using Kredits locally:
$ npm run ganache (which is: ganache-cli -p 7545 -i 100 --db=./.ganache-db -m kredits)
### Truffle console
Truffle comes with a simple REPL to interact with the Smart Contracts. Have a look at the [documentation here](http://truffleframework.com/docs/getting_started/console)
NOTE: There are promisses, have a look at the examples:
```javascript
Token.deployed().then(function(token) {
token.totalSupply.call().then(function(value) {
console.log(value.toString());
})
});
```
Also please be aware of the differences between web3.js 0.2x.x and [1.x.x](https://web3js.readthedocs.io/en/1.0/) - [web3 repo](https://github.com/ethereum/web3.js/)
## Contract Deployment
Truffle uses migration scripts to deploy contract to various networks. Have a look at the `migrations` folder for those.
The Ethereum nodes for the different networks need to be configured in `truffle.js`.
Run the truffle migration scripts:
$ truffle deploy
$ truffle deploy --network=<network config from truffle.js>
Truffle keeps track of already executed migration scripts. To reset the migration use the `--reset` option
$ truffle migrate --reset
Migration scripts can also be run from within `truffle console` or `truffle develop`
To initially bootstrap a local development chain in ganache you can use the bootstrap script:
$ npm run bootstrap (= `truffle migrate --reset && truffle exec scripts/seeds.js && npm run build-json`)
## Helper scripts
`scripts/` contains some helper scripts to interact with the contracts from the CLI.
At some point these should be moved into a real nice CLI.
To run these scripts use `truffle exec`. For example: `truffle exec scripts/add-proposal.js`
### cli.js
Call any function on any contract:
$ truffle exec scripts/cli.js
### repl.js
Similar to cli.js but only provides a REPL with an initialized `kredits` instance.
$ truffle exec scripts/repl.js
### add-contributor.js
Adds a new core contributor, creates a proposal for the new contributor and votes for that one.
$ truffle exec scripts/add-contributor.js
### add-proposal.js
Adds a new proposal for an existing contributor
$ truffle exec scripts/add-proposal.js
### send-funds.js
Sends funds to an address. Helpful in development mode to for example fund a metamask account.
$ truffle exec scripts/send-funds.js
### seeds.js
Run seeds defined in `config/seeds.js`.
$ truffle exec scripts/seeds.js
or
$ npm run seeds
## Upgradeable contracts
Some of the contracts use upgradability ideas from [zeppelinos](https://github.com/zeppelinos/labs) (see `contracts/upgradable`).
The basic idea is to have a Registry contract that knows about the current implementations and a Proxy contract that uses `delegatecall` to call the current implementation.
That means the Proxy contract holds the storage and the address of that one does not change but the actuall implemenation is managed through the Registry.
To deploy a new version a new contract is deployed then the version is registered (`addVersion()`) in the Registry and on the Proxy contract is "upgraded" (`upgrade()`) to the new version.
The Registry knows about all the different contracts and implementations. Versions are stored as uint and automatically incremented for every added implementation.
### Example:
Deployment is best done using the [truffle deployer]()
1. Setup
1. deploy the Registry
2. deploy the contract
3. register the contract at the Registry:
`registry.addVersion('Token', Token.address)`
4. create the Proxy:
`registry.createProxy('Token', 1)`
2. Update
1. deploy a new Version of the contract
2. register the new version at the Registry:
`registry.addVersion('Token', NewToken.address)`
3. set the new implementation address on the Proxy contract:
`registry.upgrade('Token', 2)`
## Known Issues
When resetting ganache Metamask might have an invalid transaction nonce and transactions get rejected.
Nonces in Ethereum must be incrementing and have no gap.
To solve this reset the metamask account (Account -> Settings -> Reset Account)

View File

@@ -1,13 +1,54 @@
let contractCalls = [
['Contributor', 'add', [{ account: '0x7e8f313c56f809188313aa274fa67ee58c31515d', name: 'bumi', isCore: true, kind: 'preson', url: '', github_username: 'bumi', github_uid: 318, wiki_username: 'bumi' }, {gasLimit: 200000}]],
['Contributor', 'add', [{ account: '0xa502eb4021f3b9ab62f75b57a94e1cfbf81fd827', name: 'raucau', isCore: true, kind: 'person', url: '', github_username: 'skddc', github_uid: 842, wiki_username: 'raucau' }, {gasLimit: 200000}]],
['Operator', 'addProposal', [{ contributorId: 2, amount: 42, kind: 'code', description: 'runs the seeds', url: '' }, {gasLimit: 350000}]],
['Operator', 'addProposal', [{ contributorId: 3, amount: 23, kind: 'code', description: 'runs the seeds', url: '' }, {gasLimit: 350000}]],
['Operator', 'addProposal', [{contributorId: 3, amount: 100, kind: 'code', description: 'hacks on kredits', url: '' }, {gasLimit: 350000}]],
['Operator', 'vote', ['1', {gasLimit: 250000}]]
const contractCalls = [
['Contributor', 'add', [{
account: '0x7e8f313c56f809188313aa274fa67ee58c31515d',
name: 'bumi',
kind: 'person',
url: '',
github_username: 'bumi',
github_uid: 318,
gitea_username: 'bumi',
wiki_username: 'Bumi',
}, { gasLimit: 200000 }]],
['Contributor', 'add', [{
account: '0x49575f3DD9a0d60aE661BC992f72D837A77f05Bc',
name: 'raucao',
kind: 'person',
url: '',
github_username: 'skddc',
github_uid: 842,
gitea_username: 'raucao',
wiki_username: 'Basti',
}, { gasLimit: 200000 }]],
['Contributor', 'add', [{
account: '0xF722709ECC3B05c19d02E82a2a4A4021B8F48C62',
name: 'Manuel',
kind: 'person',
url: '',
github_username: 'fsmanuel',
github_uid: 54812,
wiki_username: 'Manuel',
}, { gasLimit: 200000 }]],
['Contribution', 'add', [{ contributorId: 1, contributorIpfsHash: 'QmWKCYGr2rSf6abUPaTYqf98urvoZxGrb7dbspFZA6oyVF', date: '2019-04-11', amount: 500, kind: 'dev', description: '[67P/kredits-contracts] Test this thing', url: '' }, { gasLimit: 350000 }]],
['Contribution', 'add', [{ contributorId: 2, contributorIpfsHash: 'QmcHzEeAM26HV2zHTf5HnZrCtCtGdEccL5kUtDakAB7ozB', date: '2019-04-11', amount: 1500, kind: 'dev', description: '[67P/kredits-web] Reviewed stuff', url: '' }, { gasLimit: 350000 }]],
['Contribution', 'add', [{ contributorId: 1, contributorIpfsHash: 'QmWKCYGr2rSf6abUPaTYqf98urvoZxGrb7dbspFZA6oyVF', date: '2019-04-11', amount: 1500, kind: 'dev', description: '[67P/kredits-contracts] Add tests', url: '' }, { gasLimit: 350000 }]],
['Contribution', 'add', [{ contributorId: 1, contributorIpfsHash: 'QmWKCYGr2rSf6abUPaTYqf98urvoZxGrb7dbspFZA6oyVF', date: '2019-04-11', amount: 1500, kind: 'dev', description: '[67P/kredits-contracts] Introduce contribution token', url: '' }, { gasLimit: 350000 }]],
['Contribution', 'add', [{ contributorId: 2, contributorIpfsHash: 'QmcHzEeAM26HV2zHTf5HnZrCtCtGdEccL5kUtDakAB7ozB', date: '2019-04-11', amount: 5000, kind: 'dev', description: '[67P/kredits-web] Expense UI, first draft', url: '' }, { gasLimit: 350000 }]],
['Reimbursement', 'add', [{amount: 1116000, recipientId: 1, token: '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599', expenses: [
{ title: 'Server rent', description: 'Dedicated server: andromeda.kosmos.org, April 2020', amount: 61, currency: 'EUR', date: '2020-05-28' },
{ title: 'Server rent', description: 'Dedicated server: centaurus.kosmos.org, April 2020', amount: 32, currency: 'EUR', date: '2020-05-28' }
]}, { gasLimit: 300000 }]],
['Reimbursement', 'add', [{amount: 166800, recipientId: 2, token: '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599', expenses: [
{ title: 'Domain kosmos.chat', description: 'Yearly registration fee for domain kosmos.chat', amount: 13.90, currency: 'EUR', date: '2020-05-30' }
]}, { gasLimit: 300000 }]],
];
let funds = [
const funds = [
'0x7e8f313c56f809188313aa274fa67ee58c31515d',
'0xa502eb4021f3b9ab62f75b57a94e1cfbf81fd827'
'0xa502eb4021f3b9ab62f75b57a94e1cfbf81fd827',
];
module.exports = { contractCalls, funds };

201
contracts/Contribution.sol Normal file
View File

@@ -0,0 +1,201 @@
pragma solidity ^0.8.0;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
interface ContributorInterface {
function getContributorAddressById(uint32 contributorId) external view returns (address);
function getContributorIdByAddress(address contributorAccount) external view returns (uint32);
function addressIsCore(address sender) external view returns (bool);
// TODO Maybe use for validation
// function exists(uint32 contributorId) public view returns (bool);
}
contract Contribution is Initializable {
ContributorInterface public contributorContract;
struct ContributionData {
uint32 contributorId;
uint32 amount;
bytes32 hashDigest;
uint8 hashFunction;
uint8 hashSize;
string tokenMetadataURL;
uint256 confirmedAtBlock;
bool vetoed;
bool exists;
}
string internal name_;
string internal symbol_;
// map contribution ID to contributor
mapping(uint32 => uint32) public contributionOwner;
// map contributor to contribution IDs
mapping(uint32 => uint32[]) public ownedContributions;
mapping(uint32 => ContributionData) public contributions;
uint32 public contributionsCount;
// Confirmation veto period
uint32 public blocksToWait;
// The address that deployed the contract
address public deployer;
// Data migration flag
bool public migrationDone;
event ContributionAdded(uint32 id, uint32 indexed contributorId, uint32 amount);
event ContributionVetoed(uint32 id, address vetoedByAccount);
modifier onlyCore {
require(contributorContract.addressIsCore(tx.origin), "Core only");
_;
}
modifier onlyDeployer {
require(msg.sender == deployer, "Deployer only");
_;
}
function initialize(uint32 blocksToWait_) public initializer {
deployer = msg.sender;
migrationDone = false;
blocksToWait = blocksToWait_;
}
function finishMigration() public onlyDeployer {
migrationDone = true;
}
function setContributorContract(address contributor) public {
require(address(contributorContract) == address(0) || contributorContract.addressIsCore(msg.sender), "Core only");
contributorContract = ContributorInterface(contributor);
}
function getContributorIdByAddress(address contributorAccount) public view returns (uint32) {
return contributorContract.getContributorIdByAddress(contributorAccount);
}
function getContributorAddressById(uint32 contributorId) public view returns (address) {
return contributorContract.getContributorAddressById(contributorId);
}
//
// Token standard functions (ERC 721)
//
function name() external view returns (string memory) {
return name_;
}
function symbol() external view returns (string memory) {
return symbol_;
}
// Balance is amount of ERC271 tokens, not amount of kredits
function balanceOf(address owner) public view returns (uint256) {
require(owner != address(0));
uint32 contributorId = getContributorIdByAddress(owner);
return ownedContributions[contributorId].length;
}
function ownerOf(uint32 contributionId) public view returns (address) {
require(exists(contributionId));
uint32 contributorId = contributions[contributionId].contributorId;
return getContributorAddressById(contributorId);
}
function tokenOfOwnerByIndex(address owner, uint32 index) public view returns (uint32) {
uint32 contributorId = getContributorIdByAddress(owner);
return ownedContributions[contributorId][index];
}
function tokenMetadata(uint32 contributionId) public view returns (string memory) {
return contributions[contributionId].tokenMetadataURL;
}
//
// Custom functions
//
function totalKreditsEarned(bool confirmedOnly) public view returns (uint32 amount) {
for (uint32 i = 1; i <= contributionsCount; i++) {
ContributionData memory c = contributions[i];
if (!c.vetoed && (block.number >= c.confirmedAtBlock || !confirmedOnly)) {
amount += c.amount; // should use safemath
}
}
}
function totalKreditsEarnedByContributor(uint32 contributorId, bool confirmedOnly) public view returns (uint32 amount) {
uint256 tokenCount = ownedContributions[contributorId].length;
for (uint256 i = 0; i < tokenCount; i++) {
uint32 cId = ownedContributions[contributorId][i];
ContributionData memory c = contributions[cId];
if (!c.vetoed && (block.number >= c.confirmedAtBlock || !confirmedOnly)) {
amount += c.amount; // should use safemath
}
}
}
function getContribution(uint32 contributionId) public view returns (uint32 id, uint32 contributorId, uint32 amount, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize, uint256 confirmedAtBlock, bool exists, bool vetoed) {
id = contributionId;
ContributionData storage c = contributions[id];
return (
id,
c.contributorId,
c.amount,
c.hashDigest,
c.hashFunction,
c.hashSize,
c.confirmedAtBlock,
c.exists,
c.vetoed
);
}
function add(uint32 amount, uint32 contributorId, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize, uint256 confirmedAtBlock, bool vetoed) public {
// require(canPerform(msg.sender, ADD_CONTRIBUTION_ROLE, new uint32[](0)), 'nope');
// TODO hubot neither has kredits nor a core account
require((confirmedAtBlock == 0 && vetoed == false) || migrationDone == false, 'extra arguments during migration only');
require(balanceOf(msg.sender) > 0 || contributorContract.addressIsCore(msg.sender), 'requires kredits or core status');
uint32 contributionId = contributionsCount + 1;
ContributionData storage c = contributions[contributionId];
c.exists = true;
c.amount = amount;
c.contributorId = contributorId;
c.hashDigest = hashDigest;
c.hashFunction = hashFunction;
c.hashSize = hashSize;
if (confirmedAtBlock > 0) {
c.confirmedAtBlock = confirmedAtBlock;
} else {
c.confirmedAtBlock = block.number + 1 + blocksToWait;
}
if (vetoed) { c.vetoed = true; }
contributionsCount++;
contributionOwner[contributionId] = contributorId;
ownedContributions[contributorId].push(contributionId);
emit ContributionAdded(contributionId, contributorId, amount);
}
function veto(uint32 contributionId) public onlyCore {
ContributionData storage c = contributions[contributionId];
require(c.exists, 'NOT_FOUND');
require(block.number < c.confirmedAtBlock, 'VETO_PERIOD_ENDED');
c.vetoed = true;
emit ContributionVetoed(contributionId, msg.sender);
}
function exists(uint32 contributionId) public view returns (bool) {
return contributions[contributionId].exists;
}
}

170
contracts/Contributor.sol Normal file
View File

@@ -0,0 +1,170 @@
pragma solidity ^0.8.0;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
interface IToken {
function mintFor(address contributorAccount, uint256 amount) external;
function balanceOf(address contributorAccount) external view returns (uint256);
}
interface IContributionBalance {
function totalKreditsEarnedByContributor(uint32 contributorId, bool confirmedOnly) external view returns (uint32 amount);
function balanceOf(address owner) external view returns (uint256);
}
contract Contributor is Initializable {
address public deployer;
IContributionBalance public contributionContract;
IToken public tokenContract;
struct Contributor {
address account;
bytes32 hashDigest;
uint8 hashFunction;
uint8 hashSize;
bool exists;
uint32 kreditsWithdrawn;
}
mapping (address => uint32) public contributorIds;
mapping (uint32 => Contributor) public contributors;
uint32 public contributorsCount;
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);
modifier onlyCore {
require(addressIsCore(tx.origin), "Core only");
_;
}
modifier onlyContributors {
require(addressExists(msg.sender) && contributionContract.balanceOf(msg.sender) > 0, "Contributors only");
_;
}
function initialize() public initializer {
deployer = msg.sender;
}
function setContributionContract(address contribution) public onlyCore {
require(address(contributionContract) == address(0) || addressIsCore(msg.sender), "Core only");
contributionContract = IContributionBalance(contribution);
}
function setTokenContract(address token) public onlyCore {
require(address(tokenContract) == address(0) || addressIsCore(msg.sender), "Core only");
tokenContract = IToken(token);
}
function coreContributorsCount() public view returns (uint32) {
uint32 count = 0;
for (uint32 i = 1; i <= contributorsCount; i++) {
if (isCoreTeam(i)) {
count += 1;
}
}
return count;
}
function updateContributorAccount(uint32 id, address oldAccount, address newAccount) public onlyCore {
require(newAccount != address(0), "invalid new account address");
require(getContributorAddressById(id) == oldAccount, "contributor does not exist");
contributorIds[oldAccount] = 0;
contributorIds[newAccount] = id;
contributors[id].account = newAccount;
emit ContributorAccountUpdated(id, oldAccount, newAccount);
}
function updateContributorProfileHash(uint32 id, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize) public onlyCore {
Contributor storage c = contributors[id];
bytes32 oldHashDigest = c.hashDigest;
c.hashDigest = hashDigest;
c.hashFunction = hashFunction;
c.hashSize = hashSize;
ContributorProfileUpdated(id, oldHashDigest, c.hashDigest);
}
function addContributor(address account, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize) public onlyCore {
require(!addressExists(account), "Address already in use");
uint32 _id = contributorsCount + 1;
assert(!contributors[_id].exists); // this can not be acually
Contributor storage c = contributors[_id];
c.exists = true;
c.hashDigest = hashDigest;
c.hashFunction = hashFunction;
c.hashSize = hashSize;
c.account = account;
c.kreditsWithdrawn = 0;
contributorIds[account] = _id;
contributorsCount += 1;
emit ContributorAdded(_id, account);
}
function isCoreTeam(uint32 id) view public returns (bool) {
// TODO: for simplicity we simply define the first contributors as core
// later this needs to be changed to something more dynamic
return id > 0 && id < 7;
}
function exists(uint32 id) view public returns (bool) {
return contributors[id].exists;
}
function addressIsCore(address account) view public returns (bool) {
// the deployer is always core
if(account == deployer) {
return true;
}
uint32 id = getContributorIdByAddress(account);
return isCoreTeam(id);
}
function addressExists(address account) view public returns (bool) {
return getContributorByAddress(account).exists;
}
function getContributorIdByAddress(address account) view public returns (uint32) {
return contributorIds[account];
}
function getContributorAddressById(uint32 id) view public returns (address) {
return contributors[id].account;
}
function getContributorByAddress(address account) internal view returns (Contributor memory) {
uint32 id = contributorIds[account];
return contributors[id];
}
function getContributorById(uint32 _id) view public returns (uint32 id, address account, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize, bool isCore, uint256 balance, uint32 totalKreditsEarned, uint256 contributionsCount, bool exists, uint256 kreditsWithdrawn) {
id = _id;
Contributor storage c = contributors[_id];
account = c.account;
hashDigest = c.hashDigest;
hashFunction = c.hashFunction;
hashSize = c.hashSize;
isCore = isCoreTeam(id);
balance = tokenContract.balanceOf(c.account);
totalKreditsEarned = contributionContract.totalKreditsEarnedByContributor(_id, true);
contributionsCount = contributionContract.balanceOf(c.account);
exists = c.exists;
kreditsWithdrawn = c.kreditsWithdrawn;
}
function withdraw() public onlyContributors {
uint32 id = getContributorIdByAddress(msg.sender);
Contributor storage c = contributors[id];
// TODO check if we need a failsafe for unconfirmed or malicious txs
uint32 confirmedKredits = contributionContract.totalKreditsEarnedByContributor(id, true);
uint32 amountWithdrawable = confirmedKredits - c.kreditsWithdrawn;
require (amountWithdrawable > 0, "No kredits available");
c.kreditsWithdrawn += amountWithdrawable;
tokenContract.mintFor(msg.sender, amountWithdrawable);
}
}

View File

@@ -1,128 +0,0 @@
pragma solidity ^0.4.18;
// import basic ERC20 details to be able to call balanceOf
import 'zeppelin-solidity/contracts/token/ERC20/ERC20Basic.sol';
import './upgradeable/Upgradeable.sol';
contract Contributors is Upgradeable {
struct Contributor {
address account;
bytes32 ipfsHash;
uint8 hashFunction;
uint8 hashSize;
bool isCore;
bool exists;
}
mapping (address => uint) public contributorIds;
mapping (uint => Contributor) public contributors;
uint256 public contributorsCount;
event ContributorProfileUpdated(uint id, bytes32 oldIpfsHash, bytes32 newIpfsHash);
event ContributorAccountUpdated(uint id, address oldAccount, address newAccount);
event ContributorAdded(uint id, address account);
modifier onlyCoreOrOperator() {
require(msg.sender == registry.getProxyFor('Operator') || addressIsCore(msg.sender));
_;
}
function initialize(address sender) public payable {
require(msg.sender == address(registry));
uint _id = 1;
Contributor storage c = contributors[_id];
c.exists = true;
c.isCore = true;
c.account = sender;
contributorIds[sender] = _id;
contributorsCount += 1;
}
function coreContributorsCount() view public returns (uint) {
uint count = 0;
for (uint256 i = 1; i <= contributorsCount; i++) {
if (contributors[i].isCore) {
count += 1;
}
}
return count;
}
function updateContributorAccount(uint id, address oldAccount, address newAccount) public onlyCoreOrOperator {
contributorIds[oldAccount] = 0;
contributorIds[newAccount] = id;
contributors[id].account = newAccount;
ContributorAccountUpdated(id, oldAccount, newAccount);
}
function updateContributorIpfsHash(uint id, bytes32 ipfsHash, uint8 hashFunction, uint8 hashSize) public onlyCoreOrOperator {
Contributor storage c = contributors[id];
bytes32 oldIpfsHash = c.ipfsHash;
c.ipfsHash = ipfsHash;
c.hashFunction = hashFunction;
c.hashSize = hashSize;
ContributorProfileUpdated(id, oldIpfsHash, c.ipfsHash);
}
function addContributor(address account, bytes32 ipfsHash, uint8 hashFunction, uint8 hashSize, bool isCore) public onlyCoreOrOperator {
require(!addressExists(account));
uint _id = contributorsCount + 1;
assert(!contributors[_id].exists); // this can not be acually
Contributor storage c = contributors[_id];
c.exists = true;
c.isCore = isCore;
c.ipfsHash = ipfsHash;
c.hashFunction = hashFunction;
c.hashSize = hashSize;
c.account = account;
contributorIds[account] = _id;
contributorsCount += 1;
ContributorAdded(_id, account);
}
function isCore(uint id) view public returns (bool) {
return contributors[id].isCore;
}
function exists(uint id) view public returns (bool) {
return contributors[id].exists;
}
function addressIsCore(address account) view public returns (bool) {
return getContributorByAddress(account).isCore;
}
function addressExists(address account) view public returns (bool) {
return getContributorByAddress(account).exists;
}
function getContributorIdByAddress(address account) view public returns (uint) {
return contributorIds[account];
}
function getContributorAddressById(uint id) view public returns (address) {
return contributors[id].account;
}
function getContributorByAddress(address account) internal view returns (Contributor) {
uint id = contributorIds[account];
return contributors[id];
}
function getContributorById(uint _id) public view returns (uint id, address account, bytes32 ipfsHash, uint8 hashFunction, uint8 hashSize, bool isCore, uint balance, bool exists ) {
id = _id;
Contributor storage c = contributors[_id];
account = c.account;
ipfsHash = c.ipfsHash;
hashFunction = c.hashFunction;
hashSize = c.hashSize;
isCore = c.isCore;
exists = c.exists;
ERC20Basic token = ERC20Basic(registry.getProxyFor('Token'));
balance = token.balanceOf(account);
}
}

View File

@@ -1,23 +0,0 @@
pragma solidity ^0.4.17;
contract Migrations {
address public owner;
uint public last_completed_migration;
modifier restricted() {
if (msg.sender == owner) _;
}
function Migrations() public {
owner = msg.sender;
}
function setCompleted(uint completed) public restricted {
last_completed_migration = completed;
}
function upgrade(address new_address) public restricted {
Migrations upgraded = Migrations(new_address);
upgraded.setCompleted(last_completed_migration);
}
}

View File

@@ -1,130 +0,0 @@
pragma solidity ^0.4.18;
// ToDo: only load interfaces
import './Token.sol';
import './Contributors.sol';
contract Operator is Upgradeable {
struct Proposal {
address creatorAccount;
uint contributorId;
uint votesCount;
uint votesNeeded;
uint256 amount;
bool executed;
bytes32 ipfsHash;
uint8 hashFunction;
uint8 hashSize;
uint256[] voterIds;
mapping (uint256 => bool) votes;
bool exists;
}
mapping(uint256 => Proposal) public proposals;
uint256 public proposalsCount;
event ProposalCreated(uint256 id, address creatorAccount, uint256 contributorId, uint256 amount);
event ProposalVoted(uint256 id, uint256 voterId, uint256 totalVotes);
event ProposalExecuted(uint256 id, uint256 contributorId, uint256 amount);
modifier coreOnly() {
require(contributorsContract().addressIsCore(msg.sender));
_;
}
modifier contributorOnly() {
require(contributorsContract().addressExists(msg.sender));
_;
}
modifier noEther() {
require(msg.value == 0);
_;
}
function contributorsContract() view public returns (Contributors) {
return Contributors(registry.getProxyFor('Contributors'));
}
function tokenContract() view public returns (Token) {
return Token(registry.getProxyFor('Token'));
}
function contributorsCount() view public returns (uint) {
return contributorsContract().contributorsCount();
}
function coreContributorsCount() view public returns (uint) {
return contributorsContract().coreContributorsCount();
}
function addProposal(uint contributorId, uint256 amount, bytes32 ipfsHash, uint8 hashFunction, uint8 hashSize) public {
require(contributorsContract().exists(contributorId));
uint256 proposalId = proposalsCount + 1;
uint256 _votesNeeded = contributorsContract().coreContributorsCount() / 100 * 75;
var p = proposals[proposalId];
p.creatorAccount = msg.sender;
p.contributorId = contributorId;
p.amount = amount;
p.ipfsHash = ipfsHash;
p.hashFunction = hashFunction;
p.hashSize = hashSize;
p.votesCount = 0;
p.votesNeeded = _votesNeeded;
p.exists = true;
proposalsCount++;
ProposalCreated(proposalId, msg.sender, p.contributorId, p.amount);
}
function getProposal(uint proposalId) public view returns (uint256 id, address creatorAccount, uint256 contributorId, uint256 votesCount, uint256 votesNeeded, uint256 amount, bool executed, bytes32 ipfsHash, uint8 hashFunction, uint8 hashSize, uint256[] voterIds, bool exists) {
id = proposalId;
Proposal storage p = proposals[id];
return (
id,
p.creatorAccount,
p.contributorId,
p.votesCount,
p.votesNeeded,
p.amount,
p.executed,
p.ipfsHash,
p.hashFunction,
p.hashSize,
p.voterIds,
p.exists
);
}
function vote(uint256 proposalId) public coreOnly {
var p = proposals[proposalId];
require(!p.executed);
uint256 voterId = contributorsContract().getContributorIdByAddress(msg.sender);
require(p.votes[voterId] != true);
p.voterIds.push(voterId);
p.votes[voterId] = true;
p.votesCount++;
if (p.votesCount >= p.votesNeeded) {
executeProposal(proposalId);
}
ProposalVoted(proposalId, voterId, p.votesCount);
}
function batchVote(uint256[] _proposalIds) public coreOnly {
for (uint256 i = 0; i < _proposalIds.length; i++) {
vote(_proposalIds[i]);
}
}
function executeProposal(uint proposalId) private {
var p = proposals[proposalId];
require(!p.executed);
require(p.votesCount >= p.votesNeeded);
address recipientAddress = contributorsContract().getContributorAddressById(p.contributorId);
tokenContract().mintFor(recipientAddress, p.amount, proposalId);
p.executed = true;
ProposalExecuted(proposalId, p.contributorId, p.amount);
}
}

113
contracts/Reimbursement.sol Normal file
View File

@@ -0,0 +1,113 @@
pragma solidity ^0.8.0;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
interface ContributorInterface {
function getContributorAddressById(uint32 contributorId) external view returns (address);
function getContributorIdByAddress(address contributorAccount) external view returns (uint32);
function addressIsCore(address sender) external view returns (bool);
// TODO Maybe use for validation
// function exists(uint32 contributorId) public view returns (bool);
}
contract Reimbursement is Initializable {
ContributorInterface public contributorContract;
struct ReimbursementData {
uint32 recipientId;
uint256 amount;
address token;
bytes32 hashDigest;
uint8 hashFunction;
uint8 hashSize;
uint256 confirmedAtBlock;
bool vetoed;
bool exists;
}
mapping(uint32 => ReimbursementData) public reimbursements;
uint32 public reimbursementsCount;
uint32 public blocksToWait;
event ReimbursementAdded(uint32 id, address indexed addedByAccount, uint256 amount);
event ReimbursementVetoed(uint32 id, address vetoedByAccount);
function initialize() public initializer {
blocksToWait = 40320; // 7 days; 15 seconds block time
}
modifier onlyCore {
require(contributorContract.addressIsCore(tx.origin), "Core only");
_;
}
function setContributorContract(address contributor) public {
require(address(contributorContract) == address(0) || contributorContract.addressIsCore(msg.sender), "Core only");
contributorContract = ContributorInterface(contributor);
}
function getContributorIdByAddress(address contributorAccount) public view returns (uint32) {
return contributorContract.getContributorIdByAddress(contributorAccount);
}
function getContributorAddressById(uint32 contributorId) public view returns (address) {
return contributorContract.getContributorAddressById(contributorId);
}
function totalAmount(bool confirmedOnly) public view returns (uint256 amount) {
for (uint32 i = 1; i <= reimbursementsCount; i++) {
ReimbursementData memory r = reimbursements[i];
if (!r.vetoed && (block.number >= r.confirmedAtBlock || !confirmedOnly)) {
amount += r.amount; // should use safemath
}
}
}
function get(uint32 reimbursementId) public view returns (uint32 id, uint32 recipientId, uint256 amount, address token, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize, uint256 confirmedAtBlock, bool exists, bool vetoed) {
id = reimbursementId;
ReimbursementData storage r = reimbursements[id];
return (
id,
r.recipientId,
r.amount,
r.token,
r.hashDigest,
r.hashFunction,
r.hashSize,
r.confirmedAtBlock,
r.exists,
r.vetoed
);
}
function add(uint256 amount, address token, uint32 recipientId, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize) public onlyCore {
uint32 reimbursementId = reimbursementsCount + 1;
ReimbursementData storage r = reimbursements[reimbursementId];
r.exists = true;
r.amount = amount;
r.token = token;
r.recipientId = recipientId;
r.hashDigest = hashDigest;
r.hashFunction = hashFunction;
r.hashSize = hashSize;
r.confirmedAtBlock = block.number + blocksToWait;
reimbursementsCount++;
emit ReimbursementAdded(reimbursementId, msg.sender, amount);
}
function veto(uint32 reimbursementId) public onlyCore {
ReimbursementData storage r = reimbursements[reimbursementId];
require(r.exists, 'NOT_FOUND');
require(block.number < r.confirmedAtBlock, 'VETO_PERIOD_ENDED');
r.vetoed = true;
emit ReimbursementVetoed(reimbursementId, msg.sender);
}
function exists(uint32 reimbursementId) public view returns (bool) {
return reimbursements[reimbursementId].exists;
}
}

View File

@@ -1,27 +1,41 @@
pragma solidity ^0.4.18;
pragma solidity ^0.8.0;
import 'zeppelin-solidity/contracts/token/ERC20/BasicToken.sol';
import './upgradeable/Upgradeable.sol';
contract Token is Upgradeable, BasicToken {
string public name;
string public symbol;
uint8 public decimals;
event LogMint(address indexed recipient, uint256 amount, uint256 proposalId);
function initialize(address sender) public payable {
require(msg.sender == address(registry));
name = 'Kredits';
symbol = 'K';
decimals = 18;
}
function mintFor(address contributorAccount, uint256 amount, uint proposalId) onlyRegistryContractFor('Operator') public {
totalSupply_ = totalSupply_.add(amount);
balances[contributorAccount] = balances[contributorAccount].add(amount);
LogMint(contributorAccount, amount, proposalId);
}
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/math/SafeMathUpgradeable.sol";
interface ContributorInterface {
function getContributorAddressById(uint32 contributorId) external view returns (address);
function getContributorIdByAddress(address contributorAccount) external view returns (uint32);
function addressIsCore(address sender) external view returns (bool);
}
contract Token is Initializable, ERC20Upgradeable {
ContributorInterface public contributorContract;
using SafeMathUpgradeable for uint256;
address public contributorContractAddress;
event KreditsMinted(address indexed recipient, uint256 amount);
function initialize() public virtual initializer {
__ERC20_init("Kredits", "KS");
}
function decimals() public view virtual override returns (uint8) {
return 0;
}
function setContributorContract(address contributor) public {
require(address(contributorContract) == address(0) || contributorContract.addressIsCore(msg.sender), "Core only");
contributorContract = ContributorInterface(contributor);
contributorContractAddress = contributor;
}
function mintFor(address contributorAccount, uint256 amount) public {
require(contributorContractAddress == msg.sender, "Only Contributor");
require(amount > 0, "INVALID_AMOUNT");
_mint(contributorAccount, amount);
emit KreditsMinted(contributorAccount, amount);
}
}

View File

@@ -1,53 +0,0 @@
pragma solidity ^0.4.18;
/**
* @title IRegistry
* @dev This contract represents the interface of a registry contract
*/
interface IRegistry {
/**
* @dev This event will be emitted every time a new proxy is created
* @param name of the contract, as specified in the registry
* @param proxy representing the address of the proxy created
*/
event ProxyCreated(string name, address proxy);
/**
* @dev This event will be emitted every time a new implementation is registered
* @param name of the contract, as specified in the registry
* @param version representing the version name of the registered implementation
* @param implementation representing the address of the registered implementation
*/
event VersionAdded(string name, uint version, address implementation);
/**
* @dev This event will be emitted every time a proxy is upgraded to a new version
* @param name of the contract, as specified in the registry
* @param version representing the version name of the registered implementation
*/
event ProxyImplementationUpgraded(string name, uint version);
/**
* @dev Registers a new version with its implementation address
* @param name of the contract, as specified in the registry
* @param implementation representing the address of the new implementation to be registered
*/
function addVersion(string name, address implementation) public;
/**
* @dev Tells the address of the implementation for a given version
* @param name of the contract, as specified in the registry
* @param version to query the implementation of
* @return address of the implementation registered for the given version
*/
function getVersion(string name, uint version) public view returns (address);
/**
* @dev Tells the latest address of the implementation
* @param name of the contract, as specified in the registry
* @return address of the implementation registered for the latest version
*/
function getLatestVersion(string name) public view returns (address);
function getProxyFor(string name) public view returns (address);
}

View File

@@ -1,23 +0,0 @@
pragma solidity ^0.4.17;
contract Migrations {
address public owner;
uint public last_completed_migration;
modifier restricted() {
if (msg.sender == owner) _;
}
function Migrations() public {
owner = msg.sender;
}
function setCompleted(uint completed) public restricted {
last_completed_migration = completed;
}
function upgrade(address new_address) public restricted {
Migrations upgraded = Migrations(new_address);
upgraded.setCompleted(last_completed_migration);
}
}

View File

@@ -1,36 +0,0 @@
pragma solidity ^0.4.18;
/**
* @title Proxy
* @dev Gives the possibility to delegate any call to a foreign implementation.
*/
contract Proxy {
/**
* @dev Tells the address of the implementation where every call will be delegated.
* @return address of the implementation to which it will be delegated
*/
function implementation() public view returns (address);
/**
* @dev Fallback function allowing to perform a delegatecall to the given implementation.
* This function will return whatever the implementation call returns
*/
function () payable public {
address _impl = implementation();
require(_impl != address(0));
bytes memory data = msg.data;
assembly {
let result := delegatecall(gas, _impl, add(data, 0x20), mload(data), 0, 0)
let size := returndatasize
let ptr := mload(0x40)
returndatacopy(ptr, 0, size)
switch result
case 0 { revert(ptr, size) }
default { return(ptr, size) }
}
}
}

View File

@@ -1,86 +0,0 @@
pragma solidity ^0.4.18;
import './IRegistry.sol';
import './Upgradeable.sol';
import './UpgradeabilityProxy.sol';
/**
* @title Registry
* @dev This contract works as a registry of versions, it holds the implementations for the registered versions.
*/
contract Registry is IRegistry {
// mapping of contract names to versions to implementation
// "Token" => "1.0.0" => "0x123"
mapping(bytes32 => mapping(uint => address)) public versions;
// current version for a certain contract
mapping(bytes32 => uint) public currentVersions;
// mapping of the contract names to the proxy addresses
mapping(bytes32 => address) public proxies;
/**
* @dev Registers a new version with its implementation address
* @param name of the contract
* @param implementation representing the address of the new implementation to be registered
*/
function addVersion(string name, address implementation) public {
bytes32 key = keccak256(name);
currentVersions[key] = currentVersions[key] + 1;
uint version = currentVersions[key];
require(versions[key][version] == 0x0);
versions[key][version] = implementation;
VersionAdded(name, version, implementation);
}
/**
* @dev Tells the address of the implementation for a given version
* @param name of the contract
* @param version to query the implementation of
* @return address of the implementation registered for the given version
*/
function getVersion(string name, uint version) public view returns (address) {
bytes32 key = keccak256(name);
return versions[key][version];
}
function getLatestVersion(string name) public view returns (address) {
bytes32 key = keccak256(name);
uint current = currentVersions[key];
return getVersion(name, current);
}
function getProxyFor(string name) public view returns (address) {
bytes32 key = keccak256(name);
return proxies[key];
}
function upgrade(string name, uint version) public {
bytes32 key = keccak256(name);
UpgradeabilityProxy(proxies[key]).upgradeTo(version);
ProxyImplementationUpgraded(name, version);
}
function upgradeToLatest(string name) public {
bytes32 key = keccak256(name);
uint current = currentVersions[key];
upgrade(name, current);
}
/**
* @dev Creates an upgradeable proxy
* @param name of the contract
* @param version representing the first version to be set for the proxy
* @return address of the new proxy created
*/
function createProxy(string name, uint version) public payable returns (UpgradeabilityProxy) {
bytes32 key = keccak256(name);
require(proxies[key] == 0x0);
UpgradeabilityProxy proxy = new UpgradeabilityProxy(name, version);
proxies[key] = address(proxy);
Upgradeable(proxy).initialize.value(msg.value)(msg.sender);
ProxyCreated(name, proxy);
return proxy;
}
}

View File

@@ -1,28 +0,0 @@
pragma solidity ^0.4.18;
import './Proxy.sol';
import './IRegistry.sol';
import './UpgradeabilityStorage.sol';
/**
* @title UpgradeabilityProxy
* @dev This contract represents a proxy where the implementation address to which it will delegate can be upgraded
*/
contract UpgradeabilityProxy is Proxy, UpgradeabilityStorage {
function UpgradeabilityProxy(string _name, uint _version) public {
_proxiedContractName = _name;
registry = IRegistry(msg.sender);
upgradeTo(_version);
}
/**
* @dev Upgrades the implementation to the requested version
* @param _version representing the version name of the new implementation to be set
*/
function upgradeTo(uint _version) public {
require(msg.sender == address(registry));
_implementation = registry.getVersion(_proxiedContractName, _version);
}
}

View File

@@ -1,37 +0,0 @@
pragma solidity ^0.4.18;
import './IRegistry.sol';
/**
* @title UpgradeabilityStorage
* @dev This contract holds all the necessary state variables to support the upgrade functionality
*/
contract UpgradeabilityStorage {
// Versions registry
IRegistry internal registry;
// Address of the current implementation
address internal _implementation;
// contract name
string public _proxiedContractName;
modifier requireRegistry() {
require(address(registry) != 0x0);
_;
}
modifier onlyRegistryContractFor(string name) {
require(address(registry) != 0x0);
require(msg.sender == registry.getProxyFor(name));
_;
}
/**
* @dev Tells the address of the current implementation
* @return address of the current implementation
*/
function implementation() public view returns (address) {
return _implementation;
}
}

View File

@@ -1,19 +0,0 @@
pragma solidity ^0.4.18;
import './UpgradeabilityStorage.sol';
/**
* @title Upgradeable
* @dev This contract holds all the minimum required functionality for a behavior to be upgradeable.
* This means, required state variables for owned upgradeability purpose and simple initialization validation.
*/
contract Upgradeable is UpgradeabilityStorage {
/**
* @dev Validates the caller is the versions registry.
* THIS FUNCTION SHOULD BE OVERRIDDEN CALLING SUPER
* @param sender representing the address deploying the initial behavior of the contract
*/
function initialize(address sender) public payable {
require(msg.sender == address(registry));
}
}

View File

@@ -0,0 +1,83 @@
# Contribution deployments
aragon apm publish major --environment=rinkeby"
## 20212-01-14
apps/contribution@master » aragon apm publish major --environment=rinkeby
eth-provider | Invalid provider preset/location: "local"
✔ Start IPFS
✔ Applying version bump (major)
↓ Building frontend [skipped]
→ build script not defined in package.json
✔ Deploy contract
✔ Determine contract address for version
✔ Prepare files for publishing
✔ Generate application artifact
✔ Publish intent
⚠ Publishing files from the project's root folder is not recommended. Consider using the distribution folder of your project: "--files <folder>".
The following information will be published:
Contract address: 0x914Da982ef17B56D2e868E3a67E923EbED1aE017
Content (ipfs): QmdVrY2R48NFqwLopd8ix1anAK1d6WafDGauou3ZJrB9gf
? Publish to kredits-contribution.open.aragonpm.eth repo Yes
✔ Publish kredits-contribution.open.aragonpm.eth
Successfully published kredits-contribution.open.aragonpm.eth v7.0.0 :
Transaction hash: 0xb817b2e80e90a6be60b45dd39987498e3132c9962c0501feb7549ad30186c6d5
## 2019-04-24 update balances
✔ Successfully published kredits-contribution.open.aragonpm.eth v6.0.0:
Contract address: 0x2c083EEA83fd3a99C93759D97D0317A43261c758
Content (ipfs): QmULpSqz7BgTFmDu8AL7YZZEz525xkcEzf3dPKtbRdUtFs
Transaction hash: 0x8b01c4c00162e918659d267a2beaf33b578e2aaf9f427f1aa9a43029333c5cd7
## 2019-04-10 - Weltempfänger release
✔ Successfully published kredits-contribution.open.aragonpm.eth v5.0.0:
Contract address: 0xe0f7dB486321b917e3A986Bdb2F2b9d51BA98fa9
Content (ipfs): QmU3XEBb4f5jU8MFFEpwaa95C1mhc82UeYLRWLrKsvcQNw
Transaction hash: 0xd736ff5f79f8142be3fad1a50580fb40aa468838da397f8630285fd91a445af3
## 2019-04-04
✔ Successfully published kredits-contribution.open.aragonpm.eth v4.0.0:
Contract address: 0x7485e8fbde0112C53587079db450Eb002D359372
Content (ipfs): QmZKxYPm8wz4phgL4428Gh7MjmbyFFDMP2st7qhNL9qGDQ
Transaction hash: 0x7d9be7920db675be88e8f60ebf08dc62ee77c4e6e454c5fbf0f91f6ac97e4c26
## 2019-03-26
### v3.0.0 appids
from account: 0x18f6d06de7e6d556b1bbb5875f8cfafb5eaef9c5
✔ Successfully published kredits-contribution.open.aragonpm.eth v3.0.0:
Contract address: 0x9b4954834f070380faf9B6CB3794C7eA92d3B506
Content (ipfs): Qma3yvT5AmBbJHL8WkpXHs7aCFqpGd9ZaMpbiz3cT6Un59
Transaction hash: 0xc2b2d19e1b6d68ba50ed051a35c22eac74c69bd50665aed65488f9209171d382
## 2019-03-25
### v2.0.0 updated appid hashes
from account: 0x18f6d06de7e6d556b1bbb5875f8cfafb5eaef9c5
✔ Successfully published kredits-contribution.open.aragonpm.eth v2.0.0:
Contract address: 0x2765F13d82B83C0C9d770715e1fB376ab01C0361
Content (ipfs): QmYiv1cMh6cj8pcbmaTUAWxf93k4UhN8mPJWeqEo7BEkMx
Transaction hash: 0xe4841a6552527c8fbeb6aa44769f95ce60d99413958c6289f67e8ec83823ee96
### v1.0.0
from account: 0x18f6d06de7e6d556b1bbb5875f8cfafb5eaef9c5
✔ Successfully published kredits-contribution.open.aragonpm.eth v1.0.0:
Contract address: 0x1F460107361047064d982f61002D1BdEb02Ce705
Content (ipfs): QmQ6rTWCGcseCmGb6thYG2kwijHk6W84qaFPeftZ4bUY2k
Transaction hash: 0xeee90c5d18a8cb8ac845f52a4202cd62b27c23b4251b69c3681a854786b6e336

View File

@@ -0,0 +1,51 @@
# Contributor deployments
aragon apm publish major --environment=rinkeby
## 2019-04-25 canPerform fix
✔ Successfully published kredits-contributor.open.aragonpm.eth v6.0.0:
Contract address: 0xA5379D49C718845A1BD7720c6BE3872bA69906cc
Content (ipfs): QmdennNV6s2FNpe6QNYxrUsUXPVdnQGvh1vCi22Tqs8ojq
Transaction hash: 0x51077afeff70a24e87c78bb23ea13bdb9b4445bd43ea7a74a4178fadfeeb6c35
## 2019-04-24 update balances
✔ Successfully published kredits-contributor.open.aragonpm.eth v5.0.0:
Contract address: 0xadefa3b66b68a127Fe38bEa1813b844EE69CFD86
Content (ipfs): QmeygbQgoj2McLWzo9hJayLWuBZqFaK4HTpa5qLeQdkn5K
Transaction hash: 0x4237a9636f6e4a8190e0d5bcfa85a452da097bf654a173a88e0e1de3d078f08d
## 2019-04-10 - Weltempfänger release
✔ Successfully published kredits-contributor.open.aragonpm.eth v4.0.0:
Contract address: 0x08a6D4D915FCAA5524F05F5F715a6C17cB6eeA6B
Content (ipfs): QmR62PWwe1EzommfkhJDYcTvHoZjbXuv9dTG6vCn5dWCsb
Transaction hash: 0xd5317c9e207a413485c55ec3046b09d467d978443680304737a6d7d3db0c90e1
## 2019-04-04
✔ Successfully published kredits-contributor.open.aragonpm.eth v3.0.0:
Contract address: 0x95D8458E28C8de7216279512601A3B9Dc512D70B
Content (ipfs): QmSpHnmsf8FybvqfD49kwxvDixwiBUR7D5yG4BWSnnwCPS
Transaction hash: 0x736f9751b07a91178f453c279ecb57604b3b5686ae5d7115880f3b27fbeb50f2
## 2019-03-26
### v2.0.0 support for appids
from account: 0x18f6d06de7e6d556b1bbb5875f8cfafb5eaef9c5
✔ Successfully published kredits-contributor.open.aragonpm.eth v2.0.0:
Contract address: 0xf8e7B45b3c5A98dbE3D69C6828052dfD9fe2dc69
Content (ipfs): QmTDduMJVUVcqz5SgVEns1xwY9LqYrMoAyYcx3pMrPxn6i
Transaction hash: 0x48b38f32f5dcb52a0a8603743b66a7ca490fec04ccb1888dcfd37106bbd3b886
## 2019-03-25
from account: 0x18f6d06de7e6d556b1bbb5875f8cfafb5eaef9c5
✔ Successfully published kredits-contributor.open.aragonpm.eth v1.0.0:
Contract address: 0x6D80EFEE6F9A40AA86Ef7c4C95c8b2e453d260fb
Content (ipfs): QmbGSQPwi3AXHjDFG2fkMpJrBJLtyuaA6DVPMkFTfMpksn
Transaction hash: 0x26376c59dfdb617c35b740a0f110bf3040cdad0103593cdc788267a84d9847b9

View File

@@ -0,0 +1,68 @@
# Kredits deployment
## 2021-01-14
apps/contribution@master » aragon dao upgrade 0xc34edf7d11b7f8433d597f0bb0697acdff55ef14 kredits-contribution.open.aragonpm.eth --environment=rinkeby
eth-provider | Invalid provider preset/location: "local"
✔ Fetching kredits-contribution.open.aragonpm.eth@latest
✔ Fetching kredits-contribution.open.aragonpm.eth@latest
✔ Upgrading app
✔ Successfully executed: "Upgrade 'kredits-contribution.open.aragonpm.eth' app instances to v7.0.0"
## 2019-04-25 canPerfom fix
aragon dao upgrade 0xc34edf7d11b7f8433d597f0bb0697acdff55ef14 kredits-contributor.open.aragonpm.eth --environment=rinkeby
✔ Fetching kredits-contributor.open.aragonpm.eth@latest
✔ Upgrading app
✔ Successfully executed: "Set the resolving address of 'kredits-contributor.open.aragonpm.eth' in namespace 'App code' to 0xA5379D49C718845A1BD7720c6BE3872bA69906cc"
## 2019-04-24 upgrade contributor and contribution
aragon dao upgrade 0xc34edf7d11b7f8433d597f0bb0697acdff55ef14 kredits-contributor.open.aragonpm.eth --environment=rinkeby
eth-provider | Invalid provider preset/location: "local"
✔ Fetching kredits-contributor.open.aragonpm.eth@latest
✔ Upgrading app
✔ Successfully executed: "Set the resolving address of 'kredits-contributor.open.aragonpm.eth' in namespace 'App code' to 0xadefa3b66b68a127Fe38bEa1813b844EE69CFD86"
aragon dao upgrade 0xc34edf7d11b7f8433d597f0bb0697acdff55ef14 kredits-contribution.open.aragonpm.eth --environment=rinkeby
✔ Fetching kredits-contribution.open.aragonpm.eth@latest
✔ Upgrading app
✔ Successfully executed: "Set the resolving address of 'kredits-contribution.open.aragonpm.eth' in namespace 'App code' to 0x2c083EEA83fd3a99C93759D97D0317A43261c758"
## 2019-04-10 - Weltempfänger release
Using KreditsKit at: 0x76e069b47b79442657eaf0555a32c6b16fa1b8b4
Created new DAO at: 0xc34edf7d11b7f8433d597f0bb0697acdff55ef14
## 2019-04-04
Using KreditsKit at: 0x76e069b47b79442657eaf0555a32c6b16fa1b8b4
Created new DAO at: 0xcd75458fbc4aa2231252d5b21f1391fd031e5cb2
### 2019-03-26
kredits/truffle-kredits@aragonos » truffle exec scripts/new-dao.js --network=rinkeby
Using network 'rinkeby'.
Deploying to networkId: 4
Using KreditsKit at: 0x1d6a9c2146a330575ee860eef9a012b5ff7caa68
Created new DAO at: 0x95a7ce185efc2d1f13efd2a00ee9247c51ea7009"
### 2019-03-25
kredits/truffle-kredits@aragonos » aragon contracts exec scripts/new-dao.js --network=rinkeby
Use of `--network` is deprecated and has been replaced with `--environment`. You may need to update your arapp.json
Passing the command to Truffle
Using network 'rinkeby'.
Deploying to networkId: 4
Using KreditsKit at: 0xf4f3963718e5c2b426dd5c3ef0ab4b31ffb7a318
Created new DAO at: 0x8b7c0bec9476ce08d9769a87d272b03b350712e2
from account: 0x18f6d06de7e6d556b1bbb5875f8cfafb5eaef9c5
https://rinkeby.etherscan.io/tx/0x4deb02b3740b3baa7735097d57c1456a5cb329ee741d123478fdb5114e2c305b

View File

@@ -0,0 +1,62 @@
# KreditsKit deployments
## 2019-04-04
Deploying to networkId: 4
Using ENS at: 0x98Df287B6C145399Aaa709692c8D308357bC085D
Using DAOFactory at: 0x2298d27a9b847c681d2b2c2828ab9d79013f5f1d
Found apps: [contribution,contributor,proposal,token].open.aragonpm.eth
Deployed KreditsKit at: 0x76e069b47b79442657eaf0555a32c6b16fa1b8b4
## 2019-03-26
Using network 'rinkeby'.
Deploying to networkId: 4
Using ENS at: 0x98Df287B6C145399Aaa709692c8D308357bC085D
Using DAOFactory at: 0x2298d27a9b847c681d2b2c2828ab9d79013f5f1d
Found apps: [contribution,contributor,proposal,token].open.aragonpm.eth
Deployed KreditsKit at: 0x1d6a9c2146a330575ee860eef9a012b5ff7caa68
### fails
a few deployments to fix the deploy script
## 2019-03-25
### fixed kit with correct appids
kredits/truffle-kredits@aragonos » aragon contracts exec scripts/deploy-kit.js --debug --network=rinkeby
Use of `--network` is deprecated and has been replaced with `--environment`. You may need to update your arapp.json
Passing the command to Truffle
Using network 'rinkeby'.
Deploying to networkId: 4
Using ENS at: 0x98Df287B6C145399Aaa709692c8D308357bC085D
Using DAOFactory at: 0x2298d27a9b847c681d2b2c2828ab9d79013f5f1d
Found apps: [contribution,contributor,proposal,token].open.aragonpm.eth
Deployed KreditsKit at: 0xf4f3963718e5c2b426dd5c3ef0ab4b31ffb7a318
from account: 0x18f6d06de7e6d556b1bbb5875f8cfafb5eaef9c5
### test with fixed deploy script
kredits/truffle-kredits@aragonos » ENS=0x98df287b6c145399aaa709692c8d308357bc085d DAO_FACTORY=0x2298d27a9b847c681d2b2c2828ab9d79013f5f1d truffle exec scripts/deploy-kit.js --network=rinkeby
Using network 'rinkeby'.
Deploying to networkId: 4
Using ENS at: 0x98df287b6c145399aaa709692c8d308357bc085d
Using DAOFactory at: 0x2298d27a9b847c681d2b2c2828ab9d79013f5f1d
Deployed KreditsKit at: 0x83afd3c99563fc467aec69e0187ffd53fc8faa76
### success
kredits/truffle-kredits@aragonos » ENS=0x98df287b6c145399aaa709692c8d308357bc085d DAO_FACTORY=0x2298d27a9b847c681d2b2c2828ab9d79013f5f1d truffle exec scripts/deploy-kit.js --network=rinkeby
Using network 'rinkeby'.
Using ENS at: 0x98df287b6c145399aaa709692c8d308357bc085d
Using DAOFactory at: 0x2298d27a9b847c681d2b2c2828ab9d79013f5f1d
Deployed KreditsKit at: 0x1fd2f9206addaf86f3ef921a3b7c84400374ba68
### deployment script error:
deployment script failure at: https://rinkeby.etherscan.io/tx/0x3571b889b6b9b2b3f26dd0ee7fb82c7ece90b28d910078f2e06753d878832af4"

View File

@@ -0,0 +1,43 @@
# Proposal deployments
## 2019-04-10 - Weltempfänger release
✔ Successfully published kredits-proposal.open.aragonpm.eth v5.0.0:
Contract address: 0x4ce5b0286483c66b861e5599a199054687434552
Content (ipfs): QmNYXEcmvKTGxYiob7WUf85oZhdmFDCuGiA6TsRrDE9TYb
Transaction hash: 0x0482b58a1ba87d494c6391026399d0ac41b45384330d916f3f99ba70e501584b
## 2019-04-04
✔ Successfully published kredits-proposal.open.aragonpm.eth v4.0.0:
Contract address: 0x4993275362Ba50D76f349A262B7b842e7FbD7490
Content (ipfs): QmesCPKLapASPTB3rnPpSdD7ULkg8BQwRcpdE1B8WwfSh7
Transaction hash: 0xe4be7b1a75b663eb345b957b216a8476b0f75e2bbfc5880943b05c82fab15dff
## 2019-03-26
### v3.0.0 appids
from account: 0x18f6d06de7e6d556b1bbb5875f8cfafb5eaef9c5
✔ Successfully published kredits-proposal.open.aragonpm.eth v3.0.0:
Contract address: 0x9f47c31aBB6F53ff2fec09C0bF79c3337C20f5AA
Content (ipfs): Qmdxg33FxAQSH7U8oTApaM5SgUUC9btiA6tu5Hystzp5tV
Transaction hash: 0xceb572f3fff368b9f07fc835577529a113e2de8ff7972a51ffaf4c63acbda9eb
## 2019-03-25
### v2.0.0 updated appid hashes
from account: 0x18f6d06de7e6d556b1bbb5875f8cfafb5eaef9c5
✔ Successfully published kredits-proposal.open.aragonpm.eth v2.0.0:
Contract address: 0x0a48dc5415f4d7A3B2B4a9aaD4A7a8775f923ce3
Content (ipfs): QmZej9xPJN7aTiQ7SzWziRuzEjjfMzjPakcGYcoN8QQBMH
Transaction hash: 0xf14c308b9f92b43a719fab2602c624dc2e11d0f629a0be9a6ec8ac47719ee9ca
### v1.0.0
from account: 0x18f6d06de7e6d556b1bbb5875f8cfafb5eaef9c5
✔ Successfully published kredits-proposal.open.aragonpm.eth v1.0.0:
Contract address: 0xFc04eB3eF666507F96A22d330d8a852d8eC996EA
Content (ipfs): QmRTzoYr7B5f8gDGY8RmoodJkMm59D4jSJLZNRnhAd4wCg
Transaction hash: 0xce419d9d555551eefc624a7ac87c19b5d660eb9c4fe0da611cd5e28e3ee6844f

View File

@@ -0,0 +1,34 @@
# Token deployments
## 2019-04-10 - Weltempfänger release
✔ Successfully published kredits-token.open.aragonpm.eth v4.0.0:
Contract address: 0x05E0C2bbdA8e5BeE22AC1E20C1457dA4de63aE26
Content (ipfs): QmUuYLRMRNZcundUk2pxVaSjMNvtB7hzdf3eyoaUNqDPow
Transaction hash: 0x98c28b5ca645904d56eb83c4783682f018c0fcee015b3a3d5fa8bd609223fb89
## 2019-04-04
✔ Successfully published kredits-token.open.aragonpm.eth v3.0.0:
Contract address: 0xd9913A96e087f50E71BF14c62cBCa3b9635392A9
Content (ipfs): QmfZ7LwjkQRuLsEnVjrEF3ryTaHsL6YTxffiiDS5KWmHQG
Transaction hash: 0x102b27e154d1e144ec084f5e8dc78e1626fda9f26c20db3e3b230fac381c317a
## 2019-03-26
### v2.0.0 support for appIds
from account: 0x18f6d06de7e6d556b1bbb5875f8cfafb5eaef9c5
✔ Successfully published kredits-token.open.aragonpm.eth v2.0.0:
Contract address: 0xc126919B3b30F14b848c2cc66Ec21A1e85a7c621
Content (ipfs): QmWB9JrWa93vtdv5VG2yohiWTbDiuzbz9P58apJdP3FnNP
Transaction hash: 0xa5ccd532a91d67b0616ee5505144988be4360440daf70dc2f5108dd2a59f3d68
## 2019-03-25
from account: 0x18f6d06de7e6d556b1bbb5875f8cfafb5eaef9c5
✔ Successfully published kredits-token.open.aragonpm.eth v1.0.0:
Contract address: 0xB4147Be6d4bcC790c6CbD3d508354DDfd3EbC8e6
Content (ipfs): QmQPue7WzQhaXbTLJwyZXSHaRY1u5ezWxyVmBP8bEgGoTE
Transaction hash: 0xa7866d81e236adfeaff6bf2d5dbc9f9757fbc1b0ce689357901194913fe93a3b"

BIN
docs/kredits-diagram.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

90
hardhat.config.js Normal file
View File

@@ -0,0 +1,90 @@
require("@nomiclabs/hardhat-waffle");
require("hardhat-deploy");
require("hardhat-deploy-ethers");
require("@nomicfoundation/hardhat-chai-matchers");
require("@openzeppelin/hardhat-upgrades");
const Kredits = require("./lib/kredits");
const promptly = require("promptly");
extendEnvironment(async (hre) => {
hre.kredits = new Kredits(
hre.ethers.provider,
hre.ethers.provider.getSigner()
);
await hre.kredits.init();
});
// This is a sample Hardhat task. To learn how to create your own go to
// https://hardhat.org/guides/create-task.html
task("accounts", "Prints the list of accounts", async () => {
const accounts = await ethers.getSigners();
for (const account of accounts) {
console.log(account.address);
}
});
task("fund", "Send eth to an address", async () => {
const to = await promptly.prompt("Address:");
const value = await promptly.prompt("Value:");
const signer = await ethers.getSigners();
const fundTransaction = await signer[0].sendTransaction({
to: to,
value: ethers.utils.parseEther(value),
});
console.log(fundTransaction);
});
task("create-wallet", "Creates a new wallet json", async () => {
const wallet = ethers.Wallet.createRandom();
console.log("New wallet:");
console.log(`Address: ${wallet.address}`);
console.log(`Public key: ${wallet.publicKey}`);
console.log(`Private key: ${wallet.privateKey}`);
console.log(`Mnemonic: ${JSON.stringify(wallet.mnemonic)}`);
const password = await promptly.prompt("Encryption password: ");
const encryptedJSON = await wallet.encrypt(password);
console.log("Encrypted wallet JSON:");
console.log(encryptedJSON);
});
// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more
/**
* @type import('hardhat/config').HardhatUserConfig
*/
module.exports = {
solidity: "0.8.2",
defaultNetwork: "localhost",
networks: {
hardhat: {
chainId: 1337,
},
rinkeby: {
url: "https://rinkeby.infura.io/v3/2e73045db2e84711912f8d0e5968f309",
accounts: [
process.env.DEPLOY_KEY ||
"0xffb4230bdf9b1f1dd48f0bc54e4007436733f225a4f163d4f7e58e620ae329eb",
],
},
rsk: {
url: "https://rsk-testnet.kosmos.org",
accounts: [
process.env.DEPLOY_KEY ||
"0xffb4230bdf9b1f1dd48f0bc54e4007436733f225a4f163d4f7e58e620ae329eb",
],
},
},
namedAccounts: {
deployer: {
default: 0,
},
},
};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1 +0,0 @@
[{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"contributors","outputs":[{"name":"account","type":"address"},{"name":"ipfsHash","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"},{"name":"isCore","type":"bool"},{"name":"exists","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"implementation","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"_proxiedContractName","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"contributorsCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"contributorIds","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":false,"name":"oldIpfsHash","type":"bytes32"},{"indexed":false,"name":"newIpfsHash","type":"bytes32"}],"name":"ContributorProfileUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":false,"name":"oldAccount","type":"address"},{"indexed":false,"name":"newAccount","type":"address"}],"name":"ContributorAccountUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":false,"name":"account","type":"address"}],"name":"ContributorAdded","type":"event"},{"constant":false,"inputs":[{"name":"sender","type":"address"}],"name":"initialize","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":true,"inputs":[],"name":"coreContributorsCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"id","type":"uint256"},{"name":"oldAccount","type":"address"},{"name":"newAccount","type":"address"}],"name":"updateContributorAccount","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"id","type":"uint256"},{"name":"ipfsHash","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"}],"name":"updateContributorIpfsHash","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"account","type":"address"},{"name":"ipfsHash","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"},{"name":"isCore","type":"bool"}],"name":"addContributor","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"id","type":"uint256"}],"name":"isCore","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"id","type":"uint256"}],"name":"exists","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"account","type":"address"}],"name":"addressIsCore","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"account","type":"address"}],"name":"addressExists","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"account","type":"address"}],"name":"getContributorIdByAddress","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"id","type":"uint256"}],"name":"getContributorAddressById","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_id","type":"uint256"}],"name":"getContributorById","outputs":[{"name":"id","type":"uint256"},{"name":"account","type":"address"},{"name":"ipfsHash","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"},{"name":"isCore","type":"bool"},{"name":"balance","type":"uint256"},{"name":"exists","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"}]

View File

@@ -1 +0,0 @@
[{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"proposals","outputs":[{"name":"creatorAccount","type":"address"},{"name":"contributorId","type":"uint256"},{"name":"votesCount","type":"uint256"},{"name":"votesNeeded","type":"uint256"},{"name":"amount","type":"uint256"},{"name":"executed","type":"bool"},{"name":"ipfsHash","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"},{"name":"exists","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"proposalsCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"implementation","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"_proxiedContractName","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"sender","type":"address"}],"name":"initialize","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":false,"name":"creatorAccount","type":"address"},{"indexed":false,"name":"contributorId","type":"uint256"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"ProposalCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":false,"name":"voterId","type":"uint256"},{"indexed":false,"name":"totalVotes","type":"uint256"}],"name":"ProposalVoted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":false,"name":"contributorId","type":"uint256"},{"indexed":false,"name":"amount","type":"uint256"}],"name":"ProposalExecuted","type":"event"},{"constant":true,"inputs":[],"name":"contributorsContract","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"tokenContract","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"contributorsCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"coreContributorsCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"contributorId","type":"uint256"},{"name":"amount","type":"uint256"},{"name":"ipfsHash","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"}],"name":"addProposal","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"proposalId","type":"uint256"}],"name":"getProposal","outputs":[{"name":"id","type":"uint256"},{"name":"creatorAccount","type":"address"},{"name":"contributorId","type":"uint256"},{"name":"votesCount","type":"uint256"},{"name":"votesNeeded","type":"uint256"},{"name":"amount","type":"uint256"},{"name":"executed","type":"bool"},{"name":"ipfsHash","type":"bytes32"},{"name":"hashFunction","type":"uint8"},{"name":"hashSize","type":"uint8"},{"name":"voterIds","type":"uint256[]"},{"name":"exists","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"proposalId","type":"uint256"}],"name":"vote","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]

View File

@@ -1 +0,0 @@
[{"constant":true,"inputs":[{"name":"","type":"bytes32"}],"name":"currentVersions","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"bytes32"}],"name":"proxies","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"bytes32"},{"name":"","type":"uint256"}],"name":"versions","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"name","type":"string"},{"indexed":false,"name":"proxy","type":"address"}],"name":"ProxyCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"name","type":"string"},{"indexed":false,"name":"version","type":"uint256"},{"indexed":false,"name":"implementation","type":"address"}],"name":"VersionAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"name","type":"string"},{"indexed":false,"name":"version","type":"uint256"}],"name":"ProxyImplementationUpgraded","type":"event"},{"constant":false,"inputs":[{"name":"name","type":"string"},{"name":"implementation","type":"address"}],"name":"addVersion","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"name","type":"string"},{"name":"version","type":"uint256"}],"name":"getVersion","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"name","type":"string"}],"name":"getLatestVersion","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"name","type":"string"}],"name":"getProxyFor","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"name","type":"string"},{"name":"version","type":"uint256"}],"name":"upgrade","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"name","type":"string"}],"name":"upgradeToLatest","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"name","type":"string"},{"name":"version","type":"uint256"}],"name":"createProxy","outputs":[{"name":"","type":"address"}],"payable":true,"stateMutability":"payable","type":"function"}]

View File

@@ -0,0 +1 @@
[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint32","name":"id","type":"uint32"},{"indexed":true,"internalType":"address","name":"addedByAccount","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"ReimbursementAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint32","name":"id","type":"uint32"},{"indexed":false,"internalType":"address","name":"vetoedByAccount","type":"address"}],"name":"ReimbursementVetoed","type":"event"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint32","name":"recipientId","type":"uint32"},{"internalType":"bytes32","name":"hashDigest","type":"bytes32"},{"internalType":"uint8","name":"hashFunction","type":"uint8"},{"internalType":"uint8","name":"hashSize","type":"uint8"}],"name":"add","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"blocksToWait","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"contributorContract","outputs":[{"internalType":"contract ContributorInterface","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"reimbursementId","type":"uint32"}],"name":"exists","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"reimbursementId","type":"uint32"}],"name":"get","outputs":[{"internalType":"uint32","name":"id","type":"uint32"},{"internalType":"uint32","name":"recipientId","type":"uint32"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"token","type":"address"},{"internalType":"bytes32","name":"hashDigest","type":"bytes32"},{"internalType":"uint8","name":"hashFunction","type":"uint8"},{"internalType":"uint8","name":"hashSize","type":"uint8"},{"internalType":"uint256","name":"confirmedAtBlock","type":"uint256"},{"internalType":"bool","name":"exists","type":"bool"},{"internalType":"bool","name":"vetoed","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"contributorId","type":"uint32"}],"name":"getContributorAddressById","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"contributorAccount","type":"address"}],"name":"getContributorIdByAddress","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"","type":"uint32"}],"name":"reimbursements","outputs":[{"internalType":"uint32","name":"recipientId","type":"uint32"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"token","type":"address"},{"internalType":"bytes32","name":"hashDigest","type":"bytes32"},{"internalType":"uint8","name":"hashFunction","type":"uint8"},{"internalType":"uint8","name":"hashSize","type":"uint8"},{"internalType":"uint256","name":"confirmedAtBlock","type":"uint256"},{"internalType":"bool","name":"vetoed","type":"bool"},{"internalType":"bool","name":"exists","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"reimbursementsCount","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"contributor","type":"address"}],"name":"setContributorContract","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"confirmedOnly","type":"bool"}],"name":"totalAmount","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"reimbursementId","type":"uint32"}],"name":"veto","outputs":[],"stateMutability":"nonpayable","type":"function"}]

View File

@@ -1 +1 @@
[{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"implementation","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"_proxiedContractName","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"recipient","type":"address"},{"indexed":false,"name":"amount","type":"uint256"},{"indexed":false,"name":"proposalId","type":"uint256"}],"name":"LogMint","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"constant":false,"inputs":[{"name":"sender","type":"address"}],"name":"initialize","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"name":"contributorAccount","type":"address"},{"name":"amount","type":"uint256"},{"name":"proposalId","type":"uint256"}],"name":"mintFor","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]
[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"KreditsMinted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"contributorContract","outputs":[{"internalType":"contract ContributorInterface","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"contributorContractAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"contributorAccount","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"mintFor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"contributor","type":"address"}],"name":"setContributorContract","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]

14
lib/addresses.json Normal file
View File

@@ -0,0 +1,14 @@
{
"31": {
"Contributor": "0x9C66a36fa6296EBb81d8F5D4642B05dF2CE85a8D",
"Contribution": "0xa12630a995337e45bDD746B6baedc1Ce2a1DCC9D",
"Token": "0x12Eb86338076450f86E5B552556028c7D21eaf1F",
"Reimbursement": "0xe2FE7cb00e2f94b8bA0AE526dfbe313f34c66E3C"
},
"1337": {
"Contributor": "0xCc66f9A3cA2670972938FAD91d0865c4a62DFB25",
"Contribution": "0x8999CaBc43E28202c5A2257f2a95A45b1F8A62BD",
"Token": "0xe082678eCF749982e33Ea6839852a8cd989aEDE2",
"Reimbursement": "0x984f797d26d3da2E9b9f8Ae4eeFEACC60fCAA90C"
}
}

View File

@@ -1 +0,0 @@
{"42":"0x205fe1b3dac678b594c5f0535e7d158e38591f93","100":"0xa7fc9b1f678c41396b53904f94f50a42ff44d826"}

View File

@@ -0,0 +1,3 @@
{
"4": "0x76e069b47b79442657eaf0555a32c6b16fa1b8b4"
}

View File

@@ -1 +0,0 @@
{"42":"0x9fd66ee78a5ebe86006f12b37ff59c63f9caa15b","100":"0x95d3bd7d136bb0b7ac9988097e964236f8a9976e"}

View File

@@ -1 +0,0 @@
{"42":"0xc270e6ea4fe303df9f1a3d4a132ac425264082e7","100":"0x7458dea485d9d8301e3ce43e8a1ec1456be5ba83"}

View File

@@ -1 +0,0 @@
{"42":"0xf71ccf7ab48044ef9ae0b5e6983dbd3266b78b36","100":"0x3fc29fbe40c2d0ca78c7e81342f00226650fe2ad"}

3
lib/addresses/dao.json Normal file
View File

@@ -0,0 +1,3 @@
{
"4": "0xc34edf7d11b7f8433d597f0bb0697acdff55ef14"
}

View File

@@ -1,27 +1,22 @@
const deprecate = require('../utils/deprecate');
class Base {
constructor(contract) {
constructor (contract) {
this.contract = contract;
}
get functions() {
return this.contract.functions;
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;
}
get ipfs() {
if (!this._ipfsAPI) { throw new Error('IPFS API not configured; please set an ipfs instance'); }
return this._ipfsAPI;
get address () {
return this.contract.address;
}
set ipfs(ipfsAPI) {
this._ipfsAPI = ipfsAPI;
}
on(type, callback) {
let eventMethod = `on${type.toLowerCase()}`;
// Don't use this.contract.events here. Seems to be a bug in ethers.js
this.contract[eventMethod] = callback;
return this;
on (type, callback) {
return this.contract.on(type, callback);
}
}
module.exports = Base;

View File

@@ -0,0 +1,72 @@
const Record = require('./record');
const ContributionSerializer = require('../serializers/contribution');
const deprecate = require('../utils/deprecate');
class Contribution extends Record {
get count () {
return this.contract.contributionsCount();
}
getById (id) {
return this.contract.getContribution(id)
.then(data => {
return this.ipfs.catAndMerge(data, ContributionSerializer.deserialize);
});
}
getData (id) {
return this.contract.getContribution(id);
}
getByContributorId (contributorId) {
return this.contract.getContributorAddressById(contributorId)
.then(address => this.getByContributorAddress(address));
}
getByContributorAddress (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.contract.tokenOfOwnerByIndex(address, index);
const contribution = await this.getById(id);
contributions.push(contribution);
}
return contributions;
});
}
async add (contributionAttr, callOptions = {}) {
const contribution = new ContributionSerializer(contributionAttr);
try { await contribution.validate(); }
catch (error) { return Promise.reject(error); }
const jsonStr = contribution.serialize();
return this.ipfs
.add(jsonStr)
.then(ipfsHashAttr => {
let contribution = [
contributionAttr.amount,
contributionAttr.contributorId,
ipfsHashAttr.hashDigest,
ipfsHashAttr.hashFunction,
ipfsHashAttr.hashSize,
];
return this.contract.add(...contribution, 0, false, callOptions);
});
}
addContribution () {
deprecate('The function `addContribution()` is deprecated and will be removed in the next major version. Use `add()` instead');
return this.add(...arguments);
}
}
module.exports = Contribution;

View File

@@ -1,48 +1,34 @@
const ethers = require('ethers');
const RSVP = require('rsvp');
const Record = require('./record');
const ContributorSerializer = require('../serializers/contributor');
const Base = require('./base');
const formatKredits = require('../utils/format-kredits');
class Contributor extends Base {
all() {
return this.functions.contributorsCount()
.then((count) => {
count = count.toNumber();
let contributors = [];
for (let id = 1; id <= count; id++) {
contributors.push(this.getById(id));
}
return RSVP.all(contributors);
});
class Contributor extends Record {
get count () {
return this.contract.contributorsCount();
}
getById(id) {
id = ethers.utils.bigNumberify(id);
return this.functions.getContributorById(id)
.then((data) => {
// TODO: remove when naming updated on the contract
data.hashDigest = data.ipfsHash;
return data;
})
// Fetch IPFS data if available
.then((data) => {
getById (id) {
return this.contract.getContributorById(id)
.then(contractData => {
let data = {...contractData};
data.balanceInt = formatKredits(data.balance);
return this.ipfs.catAndMerge(data, ContributorSerializer.deserialize);
});
}
filterByAccount(search) {
getData (id) {
return this.contract.getContributorById(id);
}
filterByAccount (search) {
return this._byAccount(search, 'filter');
}
findByAccount(search) {
findByAccount (search) {
return this._byAccount(search, 'find');
}
_byAccount(search, method = 'filter') {
_byAccount (search, method = 'filter') {
return this.all().then((contributors) => {
const searchEntries = Object.entries(search);
@@ -58,24 +44,52 @@ class Contributor extends Base {
});
}
add(contributorAttr, callOptions = {}) {
let json = ContributorSerializer.serialize(contributorAttr);
// TODO: validate against schema
async add (contributorAttr, callOptions = {}) {
let contributor = new ContributorSerializer(contributorAttr);
try { await contributor.validate(); }
catch (error) { return Promise.reject(error); }
const jsonStr = contributor.serialize();
return this.ipfs
.add(json)
.add(jsonStr)
.then((ipfsHashAttr) => {
let contributor = [
contributorAttr.account,
ipfsHashAttr.hashDigest,
ipfsHashAttr.hashFunction,
ipfsHashAttr.hashSize,
contributorAttr.isCore,
];
return this.functions.addContributor(...contributor, callOptions);
return this.contract.addContributor(...contributor, callOptions);
});
}
updateProfile (contributorId, updateAttr, callOptions = {}) {
return this.getById(contributorId).then(async (contributor) => {
let updatedContributorAttr = Object.assign(contributor, updateAttr);
let updatedContributor = new ContributorSerializer(updatedContributorAttr);
try { await updatedContributor.validate(); }
catch (error) { return Promise.reject(error); }
const jsonStr = updatedContributor.serialize();
return this.ipfs
.add(jsonStr)
.then(ipfsHashAttr => {
return this.contract.updateContributorProfileHash(
contributorId,
ipfsHashAttr.hashDigest,
ipfsHashAttr.hashFunction,
ipfsHashAttr.hashSize,
callOptions
);
});
});
}
}
module.exports = Contributor;

View File

@@ -1,6 +1,7 @@
module.exports = {
Contributors: require('./contributor'),
Operator: require('./operator'),
Contributor: require('./contributor'),
Contribution: require('./contribution'),
Proposal: require('./proposal'),
Token: require('./token'),
Registry: require('./registry')
Reimbursement: require('./reimbursement'),
};

View File

@@ -1,57 +0,0 @@
const ethers = require('ethers');
const RSVP = require('rsvp');
const ContributionSerializer = require('../serializers/contribution');
const Base = require('./base');
class Operator extends Base {
all() {
return this.functions.proposalsCount()
.then((count) => {
count = count.toNumber();
let proposals = [];
for (let id = 1; id <= count; id++) {
proposals.push(this.getById(id));
}
return RSVP.all(proposals);
});
}
getById(id) {
id = ethers.utils.bigNumberify(id);
return this.functions.getProposal(id)
.then((data) => {
// TODO: remove when naming updated on the contract
data.hashDigest = data.ipfsHash;
return data;
})
// Fetch IPFS data if available
.then((data) => {
return this.ipfs.catAndMerge(data, ContributionSerializer.deserialize);
});
}
addProposal(proposalAttr, callOptions = {}) {
let json = ContributionSerializer.serialize(proposalAttr);
// TODO: validate against schema
return this.ipfs
.add(json)
.then((ipfsHashAttr) => {
let proposal = [
proposalAttr.contributorId,
proposalAttr.amount,
ipfsHashAttr.hashDigest,
ipfsHashAttr.hashFunction,
ipfsHashAttr.hashSize,
];
return this.functions.addProposal(...proposal, callOptions);
});
}
}
module.exports = Operator;

46
lib/contracts/proposal.js Normal file
View File

@@ -0,0 +1,46 @@
const Record = require('./record');
const ContributionSerializer = require('../serializers/contribution');
const deprecate = require('../utils/deprecate');
class Proposal extends Record {
get count () {
return this.contract.proposalsCount();
}
getById (id) {
return this.contract.getProposal(id)
.then(data => {
return this.ipfs.catAndMerge(data, ContributionSerializer.deserialize);
});
}
async add (proposalAttr, callOptions = {}) {
const contribution = new ContributionSerializer(proposalAttr);
try { await contribution.validate(); }
catch (error) { return Promise.reject(error); }
const jsonStr = contribution.serialize();
return this.ipfs
.add(jsonStr)
.then((ipfsHashAttr) => {
let proposal = [
proposalAttr.contributorId,
proposalAttr.amount,
ipfsHashAttr.hashDigest,
ipfsHashAttr.hashFunction,
ipfsHashAttr.hashSize,
];
return this.contract.addProposal(...proposal, callOptions);
});
}
addProposal () {
deprecate('The function `addProposal()` is deprecated and will be removed in the next major version. Use `add()` instead');
return this.add(...arguments);
}
}
module.exports = Proposal;

14
lib/contracts/record.js Normal file
View File

@@ -0,0 +1,14 @@
const Base = require('./base');
const paged = require('../utils/pagination');
class Record extends Base {
all (options = {}) {
return this.count
.then((count) => {
let records = paged(count, options).map((id) => this.getById(id));
return Promise.all(records);
});
}
}
module.exports = Record;

View File

@@ -1,6 +0,0 @@
const Base = require('./base');
class Registry extends Base {
}
module.exports = Registry;

View File

@@ -0,0 +1,67 @@
const Record = require("./record");
const ExpenseSerializer = require("../serializers/expense");
class Reimbursement extends Record {
get count () {
return this.contract.reimbursementsCount();
}
getById (id) {
return this.contract.get(id).then((data) => {
return this.ipfs.catAndMerge(data, (ipfsDocument) => {
const expenses = JSON.parse(ipfsDocument);
return { expenses };
});
});
}
getData (id) {
return this.contract.getReimbursement(id);
}
async add (attrs, callOptions = {}) {
const amount = parseInt(attrs.amount);
const token = attrs.token;
const recipientId = attrs.recipientId;
const expenses = attrs.expenses.map((e) => new ExpenseSerializer(e));
let errorMessage;
if (typeof amount !== "number" || amount <= 0) {
errorMessage = "Invalid data: amount must be a positive number.";
}
if (!token || token === "") {
errorMessage = "Invalid data: token must be a token address.";
}
if (!recipientId || recipientId === "") {
errorMessage = "Invalid data: recipientId is required.";
}
if (expenses.length === 0) {
errorMessage = "Invalid data: at least one expense item is required.";
}
if (errorMessage) {
return Promise.reject(new Error(errorMessage));
}
return Promise.all(expenses.map((e) => e.validate())).then(() => {
const jsonStr = JSON.stringify(
expenses.map((e) => e.data),
null,
2
);
return this.ipfs.add(jsonStr).then((ipfsHashAttr) => {
const reimbursement = [
amount,
token,
parseInt(recipientId),
ipfsHashAttr.hashDigest,
ipfsHashAttr.hashFunction,
ipfsHashAttr.hashSize,
];
return this.contract.add(...reimbursement, callOptions);
});
});
}
}
module.exports = Reimbursement;

View File

@@ -4,4 +4,3 @@ class Token extends Base {
}
module.exports = Token;

View File

@@ -1,83 +1,110 @@
const ethers = require('ethers');
const RSVP = require('rsvp');
const Healthcheck = require('./utils/healthcheck');
const Preflight = require('./utils/preflight');
const deprecate = require('./utils/deprecate');
const ABIS = {
Contributors: require('./abis/Contributors.json'),
Operator: require('./abis/Operator.json'),
Registry: require('./abis/Registry.json'),
Token: require('./abis/Token.json')
Contributor: require('./abis/Contributor.json'),
Contribution: require('./abis/Contribution.json'),
Reimbursement: require('./abis/Reimbursement.json'),
Token: require('./abis/Token.json'),
};
const RegistryAddress = require('./addresses/Registry.json');
// const APP_CONTRACTS = [
// 'Contributor',
// 'Contribution',
// 'Token',
// 'Reimbursement',
// ];
const Addresses = require('./addresses.json');
const Contracts = require('./contracts');
const IPFS = require('./utils/ipfs')
const IPFS = require('./utils/ipfs');
// Helpers
function capitalize(word) {
function capitalize (word) {
let [first, ...rest] = word;
return `${first.toUpperCase()}${rest.join('')}`;
}
class Kredits {
constructor(provider, signer, options = {}) {
let { addresses, abis, ipfsConfig } = options;
constructor (provider, signer, options = {}) {
const { addresses, abis, ipfsConfig } = options;
this.provider = provider;
this.signer = signer;
// by default we only need the registry address.
// the rest is loaded from there in the init() function
this.addresses = addresses || { Registry: RegistryAddress[this.provider.chainId.toString()] }; // chainID must be a string
this.options = options;
this.addresses = addresses || {};
this.abis = abis || ABIS;
this.ipfs = new IPFS(ipfsConfig);
this.contracts = {};
}
init(names) {
let contractsToLoad = names || Object.keys(ABIS);
let addressPromises = contractsToLoad.map((contractName) => {
return this.Registry.functions.getProxyFor(contractName).then((address) => {
this.addresses[contractName] = address;
}).catch((error) => {
throw new Error(`Failed to get address for ${contractName} from registry at ${this.Registry.contract.address}
- correct registry? does it have version entry? - ${error.message}`
);
});
init (/* names */) {
// TODO implement
// const contractsToLoad = names || APP_CONTRACTS;
return this.provider.getNetwork().then(network => {
if (Object.keys(this.addresses).length === 0) {
this.addresses = Addresses[network.chainId.toString()];
}
return this;
});
return RSVP.all(addressPromises).then(() => { return this });
}
static setup(provider, signer, ipfsConfig = null) {
console.log('Kredits.setup() is deprecated use new Kredits().init() instead');
static setup (provider, signer, ipfsConfig = null) {
deprecate('Kredits.setup() is deprecated use new Kredits().init() instead');
return new Kredits(provider, signer, { ipfsConfig: ipfsConfig }).init();
}
get Registry() {
return this.contractFor('registry');
static for (connectionOptions, kreditsOptions) {
let { network, rpcUrl, wallet } = connectionOptions;
if (!rpcUrl && network === 'local') { rpcUrl = 'http://localhost:8545'; }
let ethProvider, signer;
if (rpcUrl) {
ethProvider = new ethers.providers.JsonRpcProvider(rpcUrl);
} else {
ethProvider = new ethers.getDefaultProvider(network);
}
if (wallet) {
signer = wallet.connect(ethProvider);
} else if (ethProvider.getSigner) {
signer = ethProvider.getSigner();
}
return new Kredits(ethProvider, signer, kreditsOptions);
}
get Contributor() {
// TODO: rename to contributor
return this.contractFor('contributors');
static availableNetworks () {
return Object.keys(Addresses);
}
get Contributors() {
console.log('Contributors is deprecated use Contributor instead');
return this.Contributor;
get Contributor () {
return this.contractFor('Contributor');
}
get Operator() {
return this.contractFor('operator');
get Contributors () {
deprecate('Contributors is deprecated use Contributor instead');
return this.contractFor('Contributor');
}
get Token() {
return this.contractFor('token');
get Operator () {
return this.Proposal;
}
get Token () {
return this.contractFor('Token');
}
get Contribution () {
return this.contractFor('Contribution');
}
get Reimbursement () {
return this.contractFor('Reimbursement');
}
// Should be private
contractFor(name) {
contractFor (name) {
if (this.contracts[name]) {
return this.contracts[name];
}
@@ -89,16 +116,16 @@ class Kredits {
throw new Error(`Address or ABI not found for ${contractName}`);
}
let signerOrProvider = this.signer || this.provider;
let contract = new ethers.Contract(address, abi, signerOrProvider);
const signerOrProvider = this.signer || this.provider;
const contract = new ethers.Contract(address, abi, signerOrProvider);
this.contracts[name] = new Contracts[contractName](contract);
this.contracts[name].ipfs = this.ipfs;
return this.contracts[name];
}
healthcheck() {
return new Healthcheck(this).check();
preflightChecks () {
return new Preflight(this).check();
}
}

49
lib/kreditskit.js Normal file
View File

@@ -0,0 +1,49 @@
const ethers = require('ethers');
const ABI = require('./abis/KreditsKit.json');
const Addresses = require('./addresses/KreditsKit.json');
class KreditsKit {
constructor (provider, signer, options = {}) {
let { address, abi } = options;
this.provider = provider;
this.signer = signer;
this.options = options;
this.address = address;
this.abi = abi || ABI;
}
init () {
return this.provider.getNetwork().then((network) => {
this.address = this.address || Addresses[network.chainId.toString()];
this.contract = new ethers.Contract(
this.address,
this.abi,
(this.signer || this.provider)
);
return this;
});
}
appIdFor (contractName) {
// see appIds in KreditsKit.sol for more details
const knownContracts = ['Contribution', 'Contributor', 'Proposal', 'Reimbursement', 'Token'];
return this.contract.appIds(knownContracts.indexOf(contractName));
}
newDAO (options = {}) {
return this.contract.newInstance(options).then(transaction => {
return transaction.wait().then(result => {
const deployEvent = result.events.find(e => e.event === 'DeployInstance');
return {
daoAddress: deployEvent.args.dao,
transactionHash: transaction.hash,
};
});
});
}
}
module.exports = KreditsKit;

View File

@@ -1,19 +1,75 @@
const schemas = require('@kosmos/schemas');
const validator = require('../utils/validator');
/**
* Handle serialization for JSON-LD object of the contribution, according to
* https://github.com/67P/kosmos-schemas/blob/master/schemas/contribution.json
* Serialization and validation for JSON-LD document of the contribution.
*
* @class
* @public
*/
class Contribution {
/**
* Deserialize JSON to object
*
* @method
* @public
*/
static deserialize(serialized) {
constructor (attrs) {
Object.keys(attrs).forEach(a => this[a] = attrs[a]);
}
/**
* Serialize object to JSON
*
* @public
*/
serialize () {
let {
contributorIpfsHash,
date,
time,
kind,
description,
url,
details,
} = this;
let data = {
'@context': 'https://schema.kosmos.org',
'@type': 'Contribution',
'contributor': {
'ipfs': contributorIpfsHash,
},
date,
time,
kind,
description,
'details': details || {},
};
if (url) {
data['url'] = url;
}
// Write it pretty to ipfs
return JSON.stringify(data, null, 2);
}
/**
* Validate serialized data against schema
*
* @public
*/
validate () {
const serialized = JSON.parse(this.serialize());
const valid = validator.validate(serialized, schemas['contribution']);
return valid ? Promise.resolve() : Promise.reject(validator.error);
}
/**
* Deserialize JSON to object
*
* @public
*/
static deserialize (serialized) {
let {
date,
time,
kind,
description,
details,
@@ -21,6 +77,8 @@ class Contribution {
} = JSON.parse(serialized.toString('utf8'));
return {
date,
time,
kind,
description,
details,
@@ -29,39 +87,6 @@ class Contribution {
};
}
/**
* Serialize object to JSON
*
* @method
* @public
*/
static serialize(deserialized) {
let {
contributorIpfsHash,
kind,
description,
url,
details
} = deserialized;
let data = {
"@context": "https://schema.kosmos.org",
"@type": "Contribution",
"contributor": {
"ipfs": contributorIpfsHash
},
kind,
description,
"details": details || {}
};
if (url) {
data["url"] = url;
}
// Write it pretty to ipfs
return JSON.stringify(data, null, 2);
}
}
module.exports = Contribution;

View File

@@ -1,3 +1,5 @@
const schemas = require('@kosmos/schemas');
const validator = require('../utils/validator');
/**
* Handle serialization for JSON-LD object of the contributor, according to
* https://github.com/67P/kosmos-schemas/blob/master/schemas/contributor.json
@@ -6,13 +8,95 @@
* @public
*/
class Contributor {
/**
constructor (attrs) {
Object.keys(attrs).forEach(a => this[a] = attrs[a]);
}
/**
* Serialize object to JSON
*
* @method
* @public
*/
serialize () {
let {
name,
kind,
url,
github_uid,
github_username,
gitea_username,
wiki_username,
zoom_display_name,
} = this;
let data = {
'@context': 'https://schema.kosmos.org',
'@type': 'Contributor',
kind,
name,
accounts: [],
};
if (url) {
data['url'] = url;
}
if (github_uid) {
data.accounts.push({
'site': 'github.com',
'uid': github_uid,
'username': github_username,
'url': `https://github.com/${github_username}`,
});
}
if (gitea_username) {
data.accounts.push({
'site': 'gitea.kosmos.org',
'username': gitea_username,
'url': `https://gitea.kosmos.org/${gitea_username}`,
});
}
if (wiki_username) {
data.accounts.push({
'site': 'wiki.kosmos.org',
'username': wiki_username,
'url': `https://wiki.kosmos.org/User:${wiki_username}`,
});
}
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);
}
/**
* Validate serialized data against schema
*
* @public
*/
validate () {
const serialized = JSON.parse(this.serialize());
const valid = validator.validate(serialized, schemas['contributor']);
return valid ? Promise.resolve() : Promise.reject(validator.error);
}
/**
* Deserialize JSON to object
*
* @method
* @public
*/
static deserialize(serialized) {
static deserialize (serialized) {
let {
name,
kind,
@@ -20,16 +104,24 @@ class Contributor {
accounts,
} = JSON.parse(serialized.toString('utf8'));
let github_username, github_uid, wiki_username;
let github = accounts.find((a) => a.site === 'github.com');
let wiki = accounts.find((a) => a.site === 'wiki.kosmos.org');
let github_username, github_uid, gitea_username, wiki_username, zoom_display_name;
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));
}
if (gitea) {
(({ username: gitea_username } = gitea));
}
if (wiki) {
(({ username: wiki_username } = wiki));
}
if (zoom) {
(({ username: zoom_display_name } = zoom));
}
return {
name,
@@ -38,59 +130,13 @@ class Contributor {
accounts,
github_uid,
github_username,
gitea_username,
wiki_username,
zoom_display_name,
ipfsData: serialized,
};
}
/**
* Serialize object to JSON
*
* @method
* @public
*/
static serialize(deserialized) {
let {
name,
kind,
url,
github_uid,
github_username,
wiki_username,
} = deserialized;
let data = {
"@context": "https://schema.kosmos.org",
"@type": "Contributor",
kind,
name,
"accounts": []
};
if (url) {
data["url"] = url;
}
if (github_uid) {
data.accounts.push({
"site": "github.com",
"uid": github_uid,
"username": github_username,
"url": `https://github.com/${github_username}`
});
}
if (wiki_username) {
data.accounts.push({
"site": "wiki.kosmos.org",
"username": wiki_username,
"url": `https://wiki.kosmos.org/User:${wiki_username}`
});
}
// Write it pretty to ipfs
return JSON.stringify(data, null, 2);
}
}
module.exports = Contributor;

100
lib/serializers/expense.js Normal file
View File

@@ -0,0 +1,100 @@
const schemas = require('@kosmos/schemas');
const validator = require('../utils/validator');
/**
* Serialization and validation for JSON-LD document of the Expense
*
* @class
* @public
*/
class ExpenseSerializer {
constructor (attrs) {
Object.keys(attrs).forEach(a => this[a] = attrs[a]);
}
/**
* Serialize object to JSON
*
* @public
*/
serialize () {
// Write it pretty to ipfs
return JSON.stringify(this.data, null, 2);
}
get data () {
const {
title,
description,
currency,
amount,
date,
url,
tags,
details,
} = this;
const data = {
'@context': 'https://schema.kosmos.org',
'@type': 'Expense',
title,
description,
currency,
amount,
date,
'tags': tags || [],
'details': details || {},
};
if (url) {
data['url'] = url;
}
return data;
}
/**
* Validate serialized data against schema
*
* @public
*/
validate () {
const serialized = JSON.parse(this.serialize());
const valid = validator.validate(serialized, schemas['expense']);
return valid ? Promise.resolve() : Promise.reject(validator.error);
}
/**
* Deserialize JSON to object
*
* @public
*/
static deserialize (serialized) {
const {
title,
description,
currency,
amount,
date,
url,
tags,
details,
} = JSON.parse(serialized.toString('utf8'));
return {
title,
description,
currency,
amount,
date,
url,
tags,
details,
ipfsData: serialized,
};
}
}
module.exports = ExpenseSerializer;

5
lib/utils/deprecate.js Normal file
View File

@@ -0,0 +1,5 @@
/*eslint no-console: ["error", { allow: ["warn"] }] */
module.exports = function deprecate (msg) {
console.warn(msg);
};

View File

@@ -0,0 +1,10 @@
const ethersUtils = require('ethers').utils;
module.exports = function(value, options = {}) {
let etherValue = ethersUtils.formatEther(value);
if (options.asFloat) {
return parseFloat(etherValue);
} else {
return parseInt(etherValue);
}
};

View File

@@ -1,17 +1,18 @@
const ipfsAPI = require('ipfs-api');
const ipfsClient = require('ipfs-http-client');
const multihashes = require('multihashes');
const fetch = require('node-fetch');
class IPFS {
constructor(config) {
constructor (config) {
if (!config) {
config = { host: 'localhost', port: '5001', protocol: 'http' };
}
this._ipfsAPI = ipfsAPI(config);
this._config = config;
this._ipfsAPI = ipfsClient.create(config);
}
catAndMerge(data, deserialize) {
async catAndMerge (contractData, deserialize) {
let data = {...contractData}; // data from ethers.js is not extensible. this copy the attributes in a new object
// if no hash details are found simply return the data; nothing to merge
if (!data.hashSize || data.hashSize === 0) {
return data;
@@ -21,42 +22,57 @@ class IPFS {
return this.cat(data.ipfsHash)
.then(deserialize)
.then((attributes) => {
.then(attributes => {
return Object.assign({}, data, attributes);
});
}
add(data) {
return this._ipfsAPI
.add(new this._ipfsAPI.Buffer(data))
.then((res) => {
return this.decodeHash(res[0].hash);
async add (data) {
return this._ipfsAPI.add(data)
.then(res => {
return this.decodeHash(res.path);
});
}
cat(hashData) {
async cat (hashData) {
let ipfsHash = hashData; // default - if it is a string
if (hashData.hasOwnProperty('hashSize')) {
if (Object.prototype.hasOwnProperty.call(hashData, 'hashSize')) {
ipfsHash = this.encodeHash(hashData);
}
return this._ipfsAPI.cat(ipfsHash);
if (this._config['gatewayUrl']) {
return fetch(`${this._config['gatewayUrl']}/${ipfsHash}`).then(r => r.text());
} else {
const res = this._ipfsAPI.cat(ipfsHash);
let str = '';
for await (const buffer of res) {
str += buffer.toString();
}
return Promise.resolve(str);
}
}
decodeHash(ipfsHash) {
pin (hashData) {
let ipfsHash = hashData; // default - if it is a string
if (Object.prototype.hasOwnProperty.call(hashData, 'hashSize')) {
ipfsHash = this.encodeHash(hashData);
}
return this._ipfsAPI.pin.add(multihashes.toB58String(ipfsHash));
}
decodeHash (ipfsHash) {
let multihash = multihashes.decode(multihashes.fromB58String(ipfsHash));
return {
hashDigest: '0x' + multihashes.toHexString(multihash.digest),
hashSize: multihash.length,
hashFunction: multihash.code,
ipfsHash: ipfsHash
ipfsHash: ipfsHash,
};
}
encodeHash(hashData) {
let digest = this._ipfsAPI.Buffer.from(hashData.hashDigest.slice(2), 'hex');
encodeHash (hashData) {
const digest = Buffer.from(hashData.hashDigest.slice(2), 'hex');
return multihashes.encode(digest, hashData.hashFunction, hashData.hashSize);
}
}
module.exports = IPFS;

46
lib/utils/pagination.js Normal file
View File

@@ -0,0 +1,46 @@
function pageNumber (number, size, recordCount) {
let numberOfPages = Math.ceil(recordCount / size);
number = parseInt(number) || 1;
// Ensure page number is in range
number = number > numberOfPages ? numberOfPages : number;
number = number < 1 ? 1 : number;
return number;
}
function buildIds (order, number, size, recordCount) {
let offset = size * (number - 1);
let start;
let mapFunction;
if (order === 'asc') {
start = 1 + offset;
mapFunction = (_, i) => start + i;
} else {
start = recordCount - offset;
mapFunction = (_, i) => start - i;
}
// Ensure size is in range
let end = offset + size;
if (end > recordCount) {
let diff = end - recordCount;
size = size - diff;
}
return Array.from({ length: size }, mapFunction);
}
module.exports = function paged (recordCount, options = {}) {
let { order, page } = options;
order = order || 'desc';
page = page || {};
let size = parseInt(page.size) || 25;
let number = pageNumber(page.number, size, recordCount);
return buildIds(order, number, size, recordCount);
};

View File

@@ -1,9 +1,9 @@
class Healthcheck {
constructor(kredits) {
class Preflight {
constructor (kredits) {
this.kredits = kredits;
}
check() {
check () {
return this.kredits.ipfs._ipfsAPI.id()
.catch((error) => {
throw new Error(`IPFS node not available; config: ${JSON.stringify(this.kredits.ipfs.config)} - ${error.message}`);
@@ -25,4 +25,4 @@ class Healthcheck {
}
}
module.exports = Healthcheck;
module.exports = Preflight;

15
lib/utils/validator.js Normal file
View File

@@ -0,0 +1,15 @@
const tv4 = require('tv4');
const validator = tv4.freshApi();
validator.addFormat({
'date': function(value) {
const dateRegexp = /^[0-9]{4,}-[0-9]{2}-[0-9]{2}$/;
return dateRegexp.test(value) ? null : 'A valid ISO 8601 full-date string is expected';
},
'time': function(value) {
const timeRegexp = /^([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?(([Zz])|([+|-]([01][0-9]|2[0-3]):[0-5][0-9]))$/;
return timeRegexp.test(value) ? null : 'A valid ISO 8601 full-time string is expected';
},
});
module.exports = validator;

View File

@@ -1,5 +0,0 @@
var Registry = artifacts.require('./upgradeable/Registry.sol');
module.exports = function(deployer) {
deployer.deploy(Registry);
};

View File

@@ -1,15 +0,0 @@
var Registry = artifacts.require('./Registry.sol');
var Token = artifacts.require('./Token.sol');
module.exports = function(deployer) {
deployer.deploy(Token).then(function(token) {
console.log('Registry address: ', Registry.address);
console.log('Token address: ', Token.address);
Registry.deployed().then(function(registry) {
registry.addVersion('Token', Token.address);
registry.createProxy('Token', 1);
});
});
};

View File

@@ -1,13 +0,0 @@
var Registry = artifacts.require('./Registry.sol');
var Contributors = artifacts.require('./Contributors.sol');
module.exports = function(deployer) {
deployer.deploy(Contributors).then(function(contributors) {
console.log('Registry address: ', Registry.address);
console.log('Contributors address: ', Contributors.address);
Registry.deployed().then(function(registry) {
registry.addVersion('Contributors', Contributors.address);
registry.createProxy('Contributors', 1);
});
});
};

View File

@@ -1,13 +0,0 @@
var Registry = artifacts.require('./Registry.sol');
var Operator = artifacts.require('./Operator.sol');
module.exports = function(deployer) {
deployer.deploy(Operator).then(function(operator) {
console.log('Registry address: ', Registry.address);
console.log('Operator address: ', Operator.address);
Registry.deployed().then(function(registry) {
registry.addVersion('Operator', Operator.address);
registry.createProxy('Operator', 1);
});
});
};

View File

@@ -1,5 +0,0 @@
var Migrations = artifacts.require("./Migrations.sol");
module.exports = function(deployer) {
deployer.deploy(Migrations);
};

42413
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,38 +1,82 @@
{
"name": "kredits-contracts",
"version": "3.0.0",
"version": "7.0.0-beta.0",
"description": "Ethereum contracts and npm wrapper for Kredits",
"main": "./lib/kredits.js",
"directories": {
"test": "test"
},
"scripts": {
"build-json": "truffle compile && node ./scripts/build-json.js",
"bootstrap": "truffle migrate --reset && npm run build-json && truffle exec scripts/seeds.js",
"ganache": "ganache-cli -p 7545 -i 100 --db=./.ganache-db -m kredits",
"dev": "truffle migrate && npm run build-json",
"test": "echo \"Error: no test specified\" && exit 1"
"wallet:create": "hardhat create-wallet",
"devchain": "hardhat node --network hardhat",
"deploy:dao": "hardhat run scripts/create-proxy.js",
"postshrinkwrap": "node scripts/fix-package-lock.js &>/dev/null || true",
"build": "npm run build:contracts && npm run build:json",
"build:contracts": "hardhat compile --force",
"build:json": "node ./scripts/build-json.js",
"seeds": "hardhat run scripts/seeds.js",
"fund": "hardhat fund",
"bootstrap": "npm run build && npm run deploy:dao && npm run seeds",
"repl": "hardhat console",
"lint:contracts": "solhint \"contracts/**/*.sol\" \"apps/*/contracts/**/*.sol\"",
"lint:contract-tests": "eslint apps/*/test",
"lint:wrapper": "eslint lib/",
"test": "hardhat test",
"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",
"setup-git-hooks": "sh scripts/git-hooks/install"
},
"repository": {
"type": "git",
"url": "git+https://github.com/67P/truffle-kredits.git"
"url": "git+https://github.com/67P/kredits-contracts.git"
},
"author": "",
"license": "MIT",
"bugs": {
"url": "https://github.com/67P/truffle-kredits/issues"
"url": "https://github.com/67P/kredits-contracts/issues"
},
"homepage": "https://github.com/67P/truffle-kredits#readme",
"homepage": "https://github.com/67P/kredits-contracts#readme",
"devDependencies": {
"@nomicfoundation/hardhat-chai-matchers": "^1.0.3",
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@openzeppelin/contracts-upgradeable": "^4.3.2",
"@openzeppelin/hardhat-upgrades": "^1.10.0",
"async-each-series": "^1.1.0",
"ganache-cli": "^6.0.3",
"chai": "^4.3.6",
"cli-table": "^0.3.1",
"colors": "^1.0.3",
"eslint": "^8.14.0",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.0.0",
"eth-provider": "^0.11.0",
"ethereum-block-by-date": "^1.4.0",
"ethereum-waffle": "^3.4.0",
"hardhat": "^2.6.4",
"hardhat-deploy": "^0.11.4",
"hardhat-deploy-ethers": "^0.3.0-beta.10",
"homedir": "^0.6.0",
"mocha": "^10.0.0",
"promptly": "^3.0.3",
"truffle": "^4.1.3",
"zeppelin-solidity": "^1.7.0"
"solhint": "^3.3.7",
"truffle-hdwallet-provider": "^1.0.17",
"truffle-hdwallet-provider-privkey": "^0.3.0",
"web3-providers-ws": "^1.7.3",
"yargs": "^15.0.0"
},
"dependencies": {
"ethers": "3.0.15",
"ipfs-api": "^19.0.0",
"rsvp": "^4.8.2"
}
"@kosmos/schemas": "^3.1.0",
"ethers": "^5.4.7",
"ipfs-http-client": "^56.0.3",
"multihashes": "^4.0.3",
"node-fetch": "^2.6.0",
"tv4": "^1.3.0"
},
"keywords": [
"kosmos",
"kredits"
]
}

View File

@@ -0,0 +1,55 @@
const promptly = require('promptly');
const { inspect } = require('util');
const { ethers } = require("hardhat");
const Kredits = require('../lib/kredits');
async function main() {
kredits = new Kredits(hre.ethers.provider, hre.ethers.provider.getSigner())
await kredits.init();
console.log(`Using Contributions at: ${kredits.Contribution.contract.address}`);
let contributor = await promptly.prompt('Contributor (address or id): ');
let contributorId;
let contributorAccount;
if (contributor.length < 5) {
contributorId = contributor;
contributorAccount = await kredits.Contributor.contract.getContributorAddressById(contributor);
} else {
contributorAccount = contributor;
contributorId = await kredits.Contributor.contract.getContributorIdByAddress(contributor);
}
console.log(`Creating a contribution for contributor account ${contributorAccount} ID: ${contributorId}`);
[ dateNow, timeNow ] = (new Date()).toISOString().split('T');
let contributionAttributes = {
contributorId,
date: dateNow,
time: timeNow,
amount: await promptly.prompt('Amount: '),
description: await promptly.prompt('Description: '),
kind: await promptly.prompt('Kind: ', { default: 'dev' }),
url: await promptly.prompt('URL: ', { default: '' })
}
const contributorData = await kredits.Contributor.getById(contributorId);
contributionAttributes.contributorIpfsHash = contributorData.ipfsHash;
console.log("\nAdding contribution:");
console.log(contributionAttributes);
kredits.Contribution.add(contributionAttributes, { gasLimit: 300000 })
.then(result => {
console.log("\n\nResult:");
console.log(result);
})
.catch(error => {
console.log('Failed to create contribution');
console.log(error);
});
}
main();

View File

@@ -1,7 +1,6 @@
const Registry = artifacts.require('./Registry.sol');
const promptly = require('promptly');
const ethers = require('ethers');
const { ethers } = require("hardhat");
const Kredits = require('../lib/kredits');
async function prompt(message, options) {
@@ -10,40 +9,32 @@ async function prompt(message, options) {
}
return await promptly.prompt(message, options);
}
async function main() {
kredits = new Kredits(hre.ethers.provider, hre.ethers.provider.getSigner())
await kredits.init();
module.exports = function(callback) {
Registry.deployed().then(async (registry) => {
console.log(`Using contributors at: ${kredits.Contributor.contract.address}`);
const networkId = parseInt(web3.version.network);
const provider = new ethers.providers.Web3Provider(
web3.currentProvider, { chainId: networkId }
);
const kredits = await Kredits.setup(provider, provider.getSigner());
let contributorAttributes = {
account: await prompt('Contributor address: ', {}),
name: await prompt('Name: '),
kind: await prompt('Kind (default person): ', {default: 'person'}),
url: await prompt('URL: '),
github_username: await prompt('GitHub username: '),
github_uid: parseInt(await prompt('GitHub UID: ')),
wiki_username: await prompt('Wiki username: '),
};
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: '),
};
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: 350000 }).then((result) => {
console.log("\n\nResult:");
console.log(result);
}).catch((error) => {
console.log('Failed to create contributor');
console.log(error);
});
}
main();

View File

@@ -1,46 +0,0 @@
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());
console.log(`Using operator at: ${kredits.Operator.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 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);
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);
});
});
}

View File

@@ -1,33 +1,18 @@
const fs = require('fs');
const path = require('path');
const fs = require("fs");
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 contractsPath = path.join(__dirname, "..", "artifacts", "contracts");
const libPath = path.join(__dirname, "..", "lib");
const abisPath = path.join(libPath, "abis");
const files = [
'Contributors',
'Operator',
'Registry',
'Token'
];
const files = ["Contributor", "Contribution", "Token", "Reimbursement"];
files.forEach((fileName) => {
let file = require(`${contractsPath}/${fileName}.json`);
let file = require(`${contractsPath}/${fileName}.sol/${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");
console.log(
"Don't forget to reaload the JSON files from your application; i.e. restart kredits-web"
);

View File

@@ -1,69 +0,0 @@
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());
let contractName = await promptly.prompt('Contract Name: ');
const contractWrapper = kredits[contractName];
let method;
method = await promptly.prompt('Function (? for available functions): ');
while (method === '?') {
console.log(`Contract functions: ${JSON.stringify(Object.keys(contractWrapper.functions))}`);
console.log(`\nWrapper functions: ${JSON.stringify(Object.getOwnPropertyNames(Object.getPrototypeOf(contractWrapper)))}`);
console.log("\n");
method = await promptly.prompt('Function: ');
}
if (!contractWrapper[method] && !contractWrapper.functions[method]) {
callback(new Error(`Method ${method} is not defined on ${contractName}`));
return;
}
let argumentInput = await promptly.prompt('Arguments (comma separated): ', { default: '' });
let args = [];
if (argumentInput !== '') {
args = argumentInput.split(',').map(a => a.trim());
}
console.log(`Using ${contractName} at ${contractWrapper.contract.address}`);
console.log(`Calling ${method} with ${JSON.stringify(args)}`);
let func;
if (contractWrapper[method]) {
func = contractWrapper[method];
} else {
func = contractWrapper.functions[method];
}
func.apply(contractWrapper, args).then((result) => {
console.log("\nResult:");
console.log(result);
console.log("\nStartig a REPL. (type .exit to exit)");
console.log(`defined variables: result, ${contractName}, kredis`);
let r = REPL.start();
r.context.result = result;
r.context[contractName] = contractWrapper;
r.context.kredits = kredits;
r.on('exit', () => {
console.log('Bye');
callback();
})
}).catch((error) => {
console.log("Call failed. Probably the contract raised an error?\n");
console.log("...");
callback(error);
});
})
}

97
scripts/create-proxy.js Normal file
View File

@@ -0,0 +1,97 @@
const { ethers, upgrades } = require("hardhat");
const path = require("path");
const fileInject = require("./helpers/file_inject.js");
function handleError(error) {
console.error(error.message);
process.exit(1);
}
async function main() {
const network = await hre.ethers.provider.getNetwork();
const networkId = network.chainId;
console.log(`Deploying to network #${networkId}`);
const contractFactories = {};
const contracts = {};
contractFactories.Contributor = await ethers.getContractFactory("Contributor");
contractFactories.Contribution = await ethers.getContractFactory("Contribution");
contractFactories.Token = await ethers.getContractFactory("Token");
contractFactories.Reimbursement = await ethers.getContractFactory("Reimbursement");
async function deployContractProxy (contractName, params=[]) {
let contract = await upgrades.deployProxy(contractFactories[contractName], params)
.catch(handleError);
contracts[contractName] = contract;
await contract.deployed().then(() => {
console.log(`${contractName} deployed to:`, contract.address);
console.log("...waiting for 1 confirmation");
}).catch(handleError);
await contract.deployTransaction.wait().catch(handleError);
}
const blocksVetoPeriod = 40320; // 7 days; 15 seconds block time
await deployContractProxy('Contributor');
await deployContractProxy('Contribution', [ blocksVetoPeriod ]);
await deployContractProxy('Token');
await deployContractProxy('Reimbursement');
console.log('Calling Contributor#setTokenContract')
await contracts.Contributor.functions
.setTokenContract(contracts.Token.address)
.then(res => {
console.log(`...transaction published: ${res.hash}`);
return res.wait();
}).catch(handleError);
console.log('Calling Contributor#setContributionContract')
await contracts.Contributor.functions
.setContributionContract(contracts.Contribution.address)
.then(res => {
console.log(`...transaction published: ${res.hash}`);
return res.wait();
}).catch(handleError);
console.log('Calling Contribution#setContributorContract')
await contracts.Contribution.functions
.setContributorContract(contracts.Contributor.address)
.then(res => {
console.log(`...transaction published: ${res.hash}`);
return res.wait();
}).catch(handleError);
console.log('Calling Token#setContributorContract')
await contracts.Token.functions
.setContributorContract(contracts.Contributor.address)
.then(res => {
console.log(`...transaction published: ${res.hash}`);
return res.wait();
}).catch(handleError);
console.log('Calling Reimbursement#setContributorContract')
await contracts.Reimbursement.functions
.setContributorContract(contracts.Contributor.address)
.then(res => {
console.log(`...transaction published: ${res.hash}`);
return res.wait();
}).catch(handleError);
const addresses = {
Contributor: contracts.Contributor.address,
Contribution: contracts.Contribution.address,
Token: contracts.Token.address,
Reimbursement: contracts.Reimbursement.address,
};
console.log("Writing addresses.json");
const libPath = path.join(__dirname, "..", "lib");
fileInject(path.join(libPath, "addresses.json"), networkId, addresses);
console.log("DONE!");
}
main();

View File

@@ -0,0 +1,42 @@
const Kredits = require('../../lib/kredits');
async function main() {
kredits = new Kredits(hre.ethers.provider, hre.ethers.provider.getSigner())
await kredits.init();
console.log(`Using Contribution at: ${kredits.Contribution.contract.address}`);
const count = await kredits.Contribution.count;
const currentBlockHeight = await hre.ethers.provider.getBlockNumber();
const backup = {};
const promises = [];
for (let i = 1; i <= count; i++) {
promises.push(new Promise((resolve, reject) => {
setTimeout(async () => {
console.log(`Loading contribution #${i}`);
await kredits.Contribution.contract.getContribution(i).then(contractData => {
backup[i] = {
amount: contractData.amount,
contributorId: contractData.contributorId,
hashDigest: contractData.hashDigest,
hashFunction: contractData.hashFunction,
hashSize: contractData.hashSize,
confirmedAtBlock: contractData.confirmedAtBlock,
confirmed: contractData.confirmedAtBlock <= currentBlockHeight,
vetoed: contractData.vetoed,
id: contractData.id,
}
resolve();
});
}, 100 * i);
}));
}
await Promise.all(promises).then(() => {
fs.writeFileSync("./data/contributions.json", JSON.stringify(backup, null, 2));
console.log("Exported");
});
}
main();

View File

@@ -0,0 +1,38 @@
const fs = require('fs');
const Kredits = require('../../lib/kredits');
async function main() {
kredits = new Kredits(hre.ethers.provider, hre.ethers.provider.getSigner())
await kredits.init();
console.log(`Using Contributor at: ${kredits.Contributor.contract.address}`);
const count = await kredits.Contributor.count;
const backup = {};
const promises = [];
for (let i = 1; i <= count; i++) {
promises.push(new Promise((resolve, reject) => {
setTimeout(async () => {
console.log(`Loading contributor #${i}`);
await kredits.Contributor.contract.getContributorById(i).then(contractData => {
backup[i] = {
account: contractData.account,
hashDigest: contractData.hashDigest,
hashFunction: contractData.hashFunction,
hashSize: contractData.hashSize,
id: contractData.id,
}
resolve();
});
}, 100 * i);
}));
}
await Promise.all(promises).then(() => {
fs.writeFileSync("./data/contributors.json", JSON.stringify(backup, null, 2));
console.log("Exported");
});
}
main();

View File

@@ -0,0 +1,22 @@
const promptly = require('promptly');
const EthDater = require('ethereum-block-by-date');
const { ethers } = require("hardhat");
const Kredits = require('../lib/kredits');
async function main() {
kredits = new Kredits(hre.ethers.provider, hre.ethers.provider.getSigner())
await kredits.init();
const dater = new EthDater(kredits.provider);
const dateStr = await promptly.prompt('Specify a date and time (e.g. 2021-05-07T14:00:40Z): ');
const blockData = await dater.getDate(dateStr, true);
console.log(`
The closest block is #${blockData.block}:
https://rinkeby.etherscan.io/block/${blockData.block}
`);
}
main();

View File

@@ -0,0 +1,2 @@
#!/bin/sh
cp -f scripts/git-hooks/pre-commit .git/hooks

17
scripts/git-hooks/pre-commit Executable file
View File

@@ -0,0 +1,17 @@
#!/bin/sh
#
# Run appropriate linter against staged files
#
if [ $(git diff --name-only --cached lib/ | wc -l) != 0 ]; then
./node_modules/.bin/eslint lib/
if [ $? != 0 ]; then
exit 1
fi
fi
# TODO master not linted yet, uncomment this when ready
# if [ $(git diff --name-only --cached contracts/ | wc -l) != 0 ]; then
# solhint contracts/**/*.sol && apps/*/contracts/**/*.sol
# if [ $? != 0 ]; then
# exit 1
# fi
# fi

View File

@@ -0,0 +1,8 @@
// help, give me a better name
const fs = require('fs');
module.exports = function (file, networkId, data) {
let content = JSON.parse(fs.readFileSync(file));
content[networkId] = data;
fs.writeFileSync(file, JSON.stringify(content, null, 2));
}

View File

@@ -0,0 +1,62 @@
const fs = require('fs');
const Kredits = require('../../lib/kredits');
const PARALLEL_TXS = 5;
async function main() {
kredits = new Kredits(hre.ethers.provider, hre.ethers.provider.getSigner())
await kredits.init();
console.log(`Using Contribution at: ${kredits.Contribution.contract.address}`);
try {
const data = fs.readFileSync("./data/contributions.json");
const contributions = JSON.parse(data);
const ids = Object.keys(contributions)
.map(k => parseInt(k))
.sort(function(a, b){return a-b});
const currentBlockHeight = await kredits.provider.getBlockNumber();
const confirmationPeriod = 40320 // blocks
const unconfirmedHeight = currentBlockHeight + confirmationPeriod;
const txBundlesAmount = Math.ceil(ids.length / PARALLEL_TXS);
let txBundles = [];
for (let i = 0; i < txBundlesAmount; i++) {
txBundles.push(ids.slice((i * PARALLEL_TXS), (i * PARALLEL_TXS) + PARALLEL_TXS));
}
for (const txBundle of txBundles) {
console.log(`Adding contributions #${txBundle[0]} to #${txBundle[txBundle.length - 1]}`)
let resultPromises = [];
for (const contributionId of txBundle) {
const c = contributions[contributionId.toString()];
const confirmedAtBlock = c.confirmed ? currentBlockHeight : unconfirmedHeight;
const result = await kredits.Contribution.contract.add(
c.amount, c.contributorId,
c.hashDigest, c.hashFunction, c.hashSize,
confirmedAtBlock, c.vetoed
);
resultPromises.push(result.wait());
console.log(`Added contribution #${contributionId}: ${result.hash}`);
}
console.log(`Waiting for confirmations...`);
await Promise.all(resultPromises);
console.log('Transactions confirmed');
}
} catch(e) {
console.log(e);
}
}
main();

View File

@@ -0,0 +1,33 @@
const fs = require('fs');
const Kredits = require('../../lib/kredits');
async function main() {
kredits = new Kredits(hre.ethers.provider, hre.ethers.provider.getSigner())
await kredits.init();
console.log(`Using Contributor at: ${kredits.Contributor.contract.address}`);
try {
const data = fs.readFileSync("./data/contributors.json");
const contributors = JSON.parse(data);
const ids = Object.keys(contributors)
.map(k => parseInt(k))
.sort(function(a, b){return a-b});
for (const contributorId of ids) {
const contributor = contributors[contributorId.toString()];
const result = await kredits.Contributor.contract.addContributor(
contributor.account,
contributor.hashDigest,
contributor.hashFunction,
contributor.hashSize,
);
// await result.wait();
console.log(`Added contributor #${contributorId}: ${result.hash}`);
};
} catch(e) {
console.log(e);
}
}
main();

View File

@@ -0,0 +1,68 @@
const promptly = require('promptly');
const Table = require('cli-table');
const { ethers } = require("hardhat");
const Kredits = require('../lib/kredits');
async function main() {
kredits = new Kredits(hre.ethers.provider, hre.ethers.provider.getSigner())
await kredits.init();
console.log(`Using Contribution at: ${kredits.Contribution.contract.address}`);
const table = new Table({
head: ['ID', 'Name', 'Kredits']
})
let currentBlockNumber = await kredits.provider.getBlockNumber();
console.log(`Current block number: ${currentBlockNumber}`);
let confirmedBeforeBlock = await promptly.prompt('Before block: ');
let confirmedAfterBlock = await promptly.prompt('After block: ');
let tokens = {};
let contributors = await kredits.Contributor.all();
contributors.forEach(c => {
tokens[c.id] = { amount: 0, contributor: c };
});
let contributionId = await kredits.Contribution.contract.contributionsCount();
let nextContribution = true;
while (nextContribution) {
console.log(`Getting contribution: ${contributionId}`);
let contribution = await kredits.Contribution.getById(contributionId);
contributionId = contributionId - 1;
// if no conribution is found
if (!contribution.exists) {
nextContribution = false;
break;
}
// check if the contribution is older
// in that case we assume all other contributions now are older
if (contribution.confirmedAtBlock < confirmedAfterBlock) {
nextContribution = false;
}
// if the contribution is within the range count it
if (!contribution.vetoed && contribution.confirmedAtBlock < confirmedBeforeBlock && contribution.confirmedAtBlock > confirmedAfterBlock) {
// init
tokens[contribution.contributorId].amount = tokens[contribution.contributorId].amount + contribution.amount;
}
}
Object.keys(tokens).forEach((contributorId) => {
table.push([
contributorId,
`${tokens[contributorId].contributor.name}`,
`${tokens[contributorId].amount}`
]);
});
const total = Object.keys(tokens).map(cid => { return tokens[cid].amount}).reduce((a,b) => { return a+b }, 0);
console.log(`Total confirmed Kredits: ${total} between block ${confirmedAfterBlock} and ${confirmedBeforeBlock}`);
console.log(table.toString());
}
main();

View File

@@ -0,0 +1,48 @@
const promptly = require('promptly');
const Table = require('cli-table');
const { ethers } = require("hardhat");
const Kredits = require('../lib/kredits');
async function main() {
let kredits;
kredits = new Kredits(hre.ethers.provider, hre.ethers.provider.getSigner())
await kredits.init();
console.log(`Using Contribution at: ${kredits.Contribution.contract.address}`);
const table = new Table({
head: ['ID', 'Contributor ID', 'Description', 'Amount', 'Confirmed?', 'Vetoed?', 'IPFS']
})
try {
let blockNumber = await kredits.provider.getBlockNumber();
let contributions = await kredits.Contribution.all({page: {size: 1000}});
let kreditsSum = 0;
console.log(`Current block number: ${blockNumber}`);
contributions.forEach((c) => {
const confirmed = c.confirmedAtBlock <= blockNumber;
table.push([
c.id.toString(),
c.contributorId,
`${c.description}`,
c.amount.toString(),
`${confirmed} (${c.confirmedAtBlock})`,
c.vetoed,
c.ipfsHash
])
});
console.log(table.toString());
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);
}
}
main();

View File

@@ -0,0 +1,32 @@
const Table = require('cli-table');
const Kredits = require('../lib/kredits');
async function main() {
kredits = new Kredits(hre.ethers.provider, hre.ethers.provider.getSigner())
await kredits.init();
console.log(`Using Contributor at: ${kredits.Contributor.contract.address}`);
const table = new Table({
head: ['ID', 'Account', 'Name', 'Core?', 'Balance', 'Kredits earned', 'Contributions count', 'IPFS']
})
const contributors = await kredits.Contributor.all()
contributors.forEach((c) => {
table.push([
c.id.toString(),
c.account,
`${c.name}`,
c.isCore,
c.balanceInt.toString(),
c.totalKreditsEarned.toString(),
c.contributionsCount.toString(),
c.ipfsHash
])
});
console.log(table.toString());
}
main();

View File

@@ -0,0 +1,49 @@
const Table = require("cli-table");
const Kredits = require("../lib/kredits");
async function main() {
kredits = new Kredits(hre.ethers.provider, hre.ethers.provider.getSigner());
await kredits.init();
console.log(
`Using Reimbursement at: ${kredits.Reimbursement.contract.address}`
);
const table = new Table({
head: ["ID", "Amount", "Token", "recipientId", "Confirmed?", "Vetoed?", "IPFS", "Expenses"],
});
const blockNumber = await kredits.provider.getBlockNumber();
const reimbursements = await kredits.Reimbursement.all();
console.log(`Current block number: ${blockNumber}`);
reimbursements.forEach((r) => {
const confirmed = r.confirmedAtBlock <= blockNumber;
table.push([
r.id.toString(),
r.amount.toString(),
`${r.token}`,
`${r.recipientId}`,
`${confirmed}`,
`${r.vetoed}`,
`${r.ipfsHash}`,
`${r.expenses.length}`,
]);
});
console.log(table.toString());
const totalAmountUnconfirmed = await kredits.Reimbursement.contract.totalAmount(
false
);
const totalAmountConfirmed = await kredits.Reimbursement.contract.totalAmount(
true
);
console.log(
`Total: ${totalAmountConfirmed} (confirmed) | ${totalAmountUnconfirmed} (including unconfirmed)`
);
}
main();

View File

@@ -1,25 +0,0 @@
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`);
let r = REPL.start();
r.context.kredits = kredits;
r.context.web3 = web3;
r.on('exit', () => {
console.log('Bye');
callback();
});
});
}

View File

@@ -1,51 +1,67 @@
const path = require('path');
const seeds = require(path.join(__dirname, '..', '/config/seeds.js'));
const path = require("path");
const colors = require('colors/safe');
const Kredits = require("../lib/kredits");
const seeds = require(path.join(__dirname, "..", "/config/seeds.js"));
const ethers = require('ethers');
const Kredits = require('../lib/kredits');
let somethingFailed = false;
const each = require('async-each-series');
async function main() {
kredits = new Kredits(hre.ethers.provider, hre.ethers.provider.getSigner());
await kredits.init();
module.exports = function(callback) {
const Registry = artifacts.require('./Registry.sol');
const address = await hre.ethers.provider.getSigner().getAddress();
console.log(`Sender account: ${address}\n`);
Registry.deployed().then(async (registry) => {
let fundingAmount = "2";
const networkId = parseInt(web3.version.network);
const provider = new ethers.providers.Web3Provider(
web3.currentProvider, { chainId: networkId }
);
const kredits = await Kredits.setup(provider, provider.getSigner());
for (const address of seeds.funds) {
console.log(`Funding ${address} with 2 ETH`);
let fundingAmount = 2;
each(seeds.funds, (address, next) => {
console.log(`funding ${address} with 2 ETH`);
web3.eth.sendTransaction({
try {
await hre.ethers.provider.getSigner().sendTransaction({
to: address,
value: web3.toWei(fundingAmount),
from: web3.eth.accounts[0]
},
(result) => { next(); }
)
});
each(seeds.contractCalls, (call, next) => {
let [contractName, method, args] = call;
let contractWrapper = kredits[contractName];
let func;
if (contractWrapper[method]) {
func = contractWrapper[method];
} else {
func = contractWrapper.functions[method];
}
func.apply(contractWrapper, args).then((result) => {
console.log(`[OK] kredits.${contractName}.${method}(${JSON.stringify(args)}) => ${result.hash}`);
next();
}).catch((error) => {
console.log(`[FAILD] kredits.${contractName}.${method}(${JSON.stringify(args)})`);
callback(error)
value: hre.ethers.utils.parseEther(fundingAmount),
});
}, () => { console.log("\nDone!") });
console.log(colors.green('Done'));
} catch (e) {
somethingFailed = true;
console.log(colors.red("FAILED:", e));
}
}
});
console.log(`\nRunning seeds (${seeds.contractCalls.length} contract calls)...\n`)
for (const call of seeds.contractCalls) {
const [contractName, method, args] = call;
const contractWrapper = kredits[contractName];
const func = contractWrapper[method] ?
contractWrapper[method] :
contractWrapper.contract[method];
try {
// console.log('trying', func);
const result = await func.apply(contractWrapper, args);
// console.log('result:', result);
await result.wait();
console.log(
`${colors.green('[OK]')} kredits.${contractName}.${method}(${JSON.stringify(
args
)}) => ${result.hash}`
);
} catch(error) {
somethingFailed = true;
console.log(
`${colors.red('[FAILED]')} kredits.${contractName}.${method}(${JSON.stringify(args)})`
);
console.log(`Reason: ${error.message}`);
}
}
}
main().then(() => {
if (somethingFailed) {
console.log("\nSomething went wrong while running the seeds. Please check the log output above.");
} else {
console.log("\nBravo, all done!");
}
});

View File

@@ -1,13 +0,0 @@
const promptly = require('promptly');
module.exports = async function(callback) {
let recipient = await promptly.prompt('Recipient address: ');
let amount = await promptly.prompt('Amount: ', {default: '1'});
amount = parseInt(amount);
console.log(`sending ${amount} ETH from ${web3.eth.accounts[0]} to ${recipient}`);
web3.eth.sendTransaction({to: recipient, value: web3.toWei(amount), from: web3.eth.accounts[0]}, console.log);
callback();
}

View File

@@ -0,0 +1,19 @@
const { ethers, upgrades } = require("hardhat");
const Kredits = require('../lib/kredits');
async function main() {
const network = await hre.ethers.provider.getNetwork();
kredits = new Kredits(hre.ethers.provider, hre.ethers.provider.getSigner());
await kredits.init();
const ContributorV2 = await ethers.getContractFactory("Contributor");
const contributor = await upgrades.upgradeProxy(kredits.Contributor.address, ContributorV2);
console.log("Contributor upgraded");
console.log(`Contributor address: ${contributor.address}`);
await contributor.deployTransaction.wait();
console.log("DONE!");
}
main();

View File

@@ -0,0 +1,29 @@
const promptly = require('promptly');
const { inspect } = require('util');
const { ethers } = require("hardhat");
const Kredits = require('../lib/kredits');
async function main() {
kredits = new Kredits(hre.ethers.provider, hre.ethers.provider.getSigner())
await kredits.init();
console.log(`Using Contributions at: ${kredits.Contribution.contract.address}\n`);
let contributionId = await promptly.prompt('Contribution ID: ');
console.log(`Recording a veto for contribution #${contributionId}`);
kredits.Contribution.contract.veto(contributionId, { gasLimit: 300000 })
.then(result => {
console.log("\n\nResult:");
console.log(result);
callback();
})
.catch(error => {
console.log('Failed to veto contribution');
callback(inspect(error));
});
}
main();

View File

@@ -0,0 +1,157 @@
const { expect } = require("chai");
const { ethers, upgrades } = require("hardhat");
const { anyValue } = require("@nomicfoundation/hardhat-chai-matchers/withArgs");
let owner, addr1, addr2, addr3, addr4, addr5, addr6, addr7;
let Contribution, Contributor;
describe("Contribution contract", async function () {
before(async function () {
[owner, addr1, addr2, addr3, addr4, addr5, addr6, addr7] = await ethers.getSigners();
let accounts = [owner, addr1, addr2, addr3, addr4, addr5, addr6, addr7];
const contributorFactory = await ethers.getContractFactory("Contributor");
Contributor = await upgrades.deployProxy(contributorFactory);
for (const account of accounts) {
await Contributor.addContributor(account.address, "0x99b8afd7b266e19990924a8be9099e81054b70c36b20937228a77a5cf75723b8", 18, 32);
}
});
describe("initialize()", function () {
before(async function () {
// const [owner] = await ethers.getSigners();
const contributionFactory = await ethers.getContractFactory("Contribution");
Contribution = await upgrades.deployProxy(contributionFactory, [40321]);
});
it("sets the veto confirmation period", async function () {
expect(await Contribution.blocksToWait()).to.equal(40321);
});
it("sets the data migration flag", async function () {
expect(await Contribution.migrationDone()).to.be.false;
});
it("sets the deployer address", async function () {
expect(await Contribution.deployer()).to.equal(owner.address);
expect(await Contribution.deployer()).to.not.equal(addr1.address);
});
});
describe("finishMigration()", function () {
before(async function () {
const contributionFactory = await ethers.getContractFactory("Contribution");
Contribution = await upgrades.deployProxy(contributionFactory, [40321]);
await Contribution.setContributorContract(Contributor.address).then(res => res.wait())
});
it("does not allow random accounts to mark the migration as finished", async function () {
await expect(Contribution.connect(addr1).finishMigration()).to.be.revertedWith("Deployer only");
expect(await Contribution.migrationDone()).to.be.false;
});
it("allows the deployer to mark the migration as finished", async function () {
await Contribution.finishMigration();
expect(await Contribution.migrationDone()).to.equal(true);
});
});
describe("add()", function () {
before(async function () {
const contributionFactory = await ethers.getContractFactory("Contribution");
Contribution = await upgrades.deployProxy(contributionFactory, [40321]);
await Contribution.setContributorContract(Contributor.address).then(res => res.wait())
await Contribution.finishMigration();
});
it("does not allow non-contributors to add a contribution", async function () {
await expect(Contribution.connect(addr7).add(
500, 1,
"0xe794f010e617449719c64076546254129f63a6d16cf200031afa646aeb35777f",
18, 32, 0, false
)).to.be.revertedWith("requires kredits or core status");
expect(await Contribution.contributionsCount()).to.equal(0);
});
it("does not allow special arguments outside of a migration", async function () {
await expect(Contribution.connect(addr7).add(
500, 1,
"0xe794f010e617449719c64076546254129f63a6d16cf200031afa646aeb35777f",
18, 32, 23000, true
)).to.be.revertedWith("extra arguments during migration only");
expect(await Contribution.contributionsCount()).to.equal(0);
});
it("allows core contributors to add a contribution", async function () {
await Contribution.connect(addr2).add(
2001, 1,
"0xe794f010e617449719c64076546254129f63a6d16cf200031afa646aeb35777f",
18, 32, 0, false
);
expect(await Contribution.contributionsCount()).to.equal(1);
});
it("allows contributors to add a contribution", async function () {
// Issue some kredits for new contributor #8 (addr7)
await Contribution.connect(addr1).add(
5000, 8,
"0xe794f010e617449719c64076546254129f63a6d16cf200031afa646aeb35777f",
18, 32, 0, false
);
await Contribution.connect(addr7).add(
1500, 1,
"0xe794f010e617449719c64076546254129f63a6d16cf200031afa646aeb35777f",
18, 32, 0, false
);
expect(await Contribution.contributionsCount()).to.equal(3);
});
it("sets confirmedAtBlock to current block plus blocksToWait", async function () {
await Contribution.connect(addr1).add(
500, 3,
"0xe794f010e617449719c64076546254129f63a6d16cf200031afa646aeb35777f",
18, 32, 0, false
);
expect(await Contribution.contributionsCount()).to.equal(4);
const c = await Contribution.getContribution(4);
const currentBlockNumber = await kredits.provider.getBlockNumber();
expect(c['confirmedAtBlock']).to.equal(currentBlockNumber + 1 + 40321);
});
it("emits a ContributionAdded event", async function () {
await expect(Contribution.connect(addr1).add(
2001, 1,
"0xe794f010e617449719c64076546254129f63a6d16cf200031afa646aeb35777f",
18, 32, 0, false
)).to.emit(Contribution, "ContributionAdded").withArgs(anyValue, 1, 2001);
});
describe("with extra arguments during migration", async function () {
before(async function () {
const contributionFactory = await ethers.getContractFactory("Contribution");
Contribution = await upgrades.deployProxy(contributionFactory, [40321]);
await Contribution.setContributorContract(Contributor.address);
});
it("allows to add a contribution with custom confirmedAtBlock", async function () {
await Contribution.connect(addr2).add(
2001, 1,
"0xe794f010e617449719c64076546254129f63a6d16cf200031afa646aeb35777f",
18, 32, 23000, false
);
expect(await Contribution.contributionsCount()).to.equal(1);
const c = await Contribution.getContribution(1);
expect(c['confirmedAtBlock'].toNumber()).to.equal(23000);
});
it("allows to add a vetoed contribution", async function () {
await Contribution.connect(addr2).add(
2001, 1,
"0xe794f010e617449719c64076546254129f63a6d16cf200031afa646aeb35777f",
18, 32, 23000, true
);
expect(await Contribution.contributionsCount()).to.equal(2);
const c = await Contribution.getContribution(2);
expect(c['vetoed']).to.be.true;
});
});
});
});

Some files were not shown because too many files have changed in this diff Show More