This commit is contained in:
2019-03-24 11:01:59 +01:00
parent e7affdb531
commit 0d9b2d7d58
6 changed files with 43 additions and 737 deletions

128
README.md
View File

@@ -2,10 +2,12 @@
# Kredits Contracts
This repository contains the Solidity smart contracts and JavaScript API
wrapper for [Kosmos Kredits](https://wiki.kosmos.org/Kredits).
This repository contains the Solidity smart contracts organized as [Aragon](https://hack.aragon.org/)
apps and JavaScript API wrapper for [Kosmos Kredits](https://wiki.kosmos.org/Kredits).
It uses the [Truffle framework](http://truffleframework.com/) for some things.
It is based on [aragonOS](https://hack.aragon.org/docs/aragonos-intro.html) and
follows the aragonOS conventions.
Aragon itself uses the [Truffle framework](http://truffleframework.com/) for some things.
## Development
@@ -17,77 +19,40 @@ It uses the [Truffle framework](http://truffleframework.com/) for some things.
All requirements are defined in `package.json`.
Those can be installed globally for convenience:
### Local development chain
* [truffle framework](http://truffleframework.com): `npm install -g truffle`
* [ganache](http://truffleframework.com/ganache): `npm install -g ganache-cli`
For local development it is recommended to use
[ganache](http://truffleframework.com/ganache/) to run a local development
chain. Using the ganache simulator no full Ethereum node is required.
We use following solidity contract libraries:
We use the default aragon-cli devchain command to confgure and run a local
development ganache.
* [Open Zeppelin](https://github.com/OpenZeppelin/zeppelin-solidity)
`npm run devchain` (or `aragon devchain --port 7545)
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.
To clear/reset the chain use:
We default to:
`npm run devchain -- --reset` (or `aragon devchain --port 7545 --reset`)
* 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
We default to port 7545 for development to not get in conflict with the default
Ethereum RPC port.
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`.
Contracts are organized in independent apps (see `/apps`) and are developed
and deployed independently. Each app has a version and can be "installed"
on the Kredits DAO independently.
Run the truffle migration scripts:
![](docs/kredits-diagram.png)
$ truffle deploy
$ truffle deploy --network=<network config from truffle.js>
A DAO can be deployed using the `scripts/deploy-kit.js` script or with the
`npm run deploy:dao:dev` command. This deploys a new Kredits DAO, installs
the latest app versions and sets the required permissions.
Truffle keeps track of already executed migration scripts. To reset the
migration use the `--reset` option
See each app in `/apps/*` for details.
$ 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
## ACL / Permissions
## Helper scripts
@@ -123,6 +88,12 @@ Adds a new proposal for an existing contributor
$ truffle exec scripts/add-proposal.js
### add-contribution.js
Adds a new contribution for an existing contributor
$ truffle exec scripts/add-contribution.js
### send-funds.js
Sends funds to an address. Helpful in development mode to for example fund a
@@ -139,40 +110,19 @@ Run seeds defined in `config/seeds.js`.
## 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.
We use aragonOS for upgradeablity of the different contracts.
Refer to the [aragonOS upgradeablity documentation](https://hack.aragon.org/docs/upgradeability-intro)
for more details.
### 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)`
1. Deploy each contract/apps (see `/apps/*`)
2. Create a new DAO (see scripts/deploy-kit.js)
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)`
1. Deploy a new Version of the contract/app (see `/apps/*`)
2. Use the `aragon dao upgrade` command to "install" the new version for the DAO
(`aragon dao upgrade <DAO address> <app name>`)
## Known Issues