Skip to content

Commit

Permalink
Merge pull request #166 from MyBitFoundation/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
0xjjpa committed Oct 19, 2018
2 parents 9480bc6 + 97e379a commit 92e6fcf
Show file tree
Hide file tree
Showing 22 changed files with 2,621 additions and 162 deletions.
4 changes: 3 additions & 1 deletion .gitignore
@@ -1,3 +1,5 @@
node_modules
build
dist
dist
accounts.json
addresses.json
358 changes: 312 additions & 46 deletions README.md

Large diffs are not rendered by default.

151 changes: 151 additions & 0 deletions UpdateProcess.md
@@ -0,0 +1,151 @@
# Process for updating git repositories and npm packages

When contracts are added/changed we have to make the following changes to these repositories:
- MyBit-Network.tech
- MyBit-Chain.tech
- network.js
- hello-network

## 1) Update migrations/export chain:
- Make sure any contracts that need to be deployed on the
local chain are included in *migrations/2_deploy_protocol.js*.
This includes importing the contract, setting a contract variable,
deploying it inside the chain of promises, and exporting the address
into addresses.json

- In terminal, run:

```bash
./export_chain ../MyBit-Chain.tech
```
*substitute ../MyBit-Chain.tech with whataver directory the chain is in*

- This will also push the changes to the respository if a .git file is present

## 2) Update lib/index.js and lib/js/:
- If there are any new contracts we need to update the files that export the ABI's
for use by network.js

- In terminal, run:

```bash
scripts/prepare_lib.sh
```

- This will generate the js files and index.js that will be used in the npm package.

## 3) Update git:
```bash
git add -u
git add contracts/.
git commit -m "New update description"
git push origin master
```

## 4) Publish to NPM:
- If the package is ready to be published, run the following:

```bash
npm version patch
npm publish --access=public
```

## 5) Move to MyBit-Chain.tech directory, and publish to NPM:
```bash
npm version patch
npm publish --access=public
```
*the chain should already have been pushed to the repository*

## 6) Move to network.js, update API:
- If you want the new contracts to be exposed by the API you'll need to update
index.js.

- First you must set up your contract artifacts. Under the section commented
as *//Setup contracts*, create your contract object, e.g.:

```javascript
var exampleContract = contract(ContractArtifacts.Example);
```

- Where 'exampleContract' is the name you'll be referencing when instatiating
contracts in your functions and 'ContractArtifacts.Example' is the variable
exported by @mybit/contracts. 'ContractArtifacts' is what we call @mybit/contracts
when it is imported, and 'Example' is just the file name of the contract
without the file type ('.sol').

- Next you'll want to build functions that expose the contract in the API. One
option is to simply instatiate the contract and the return the object. This
will expose all the contract's functions to the end user. For example:

```javascript
example: async () => {
return await exampleContract.at(Chain.Example());
}
```

- In this example we are just instatiating the contract that exists at Chain.Example(),
which is the address that is generated in *migrations/2_deploy_protocol.js*, which
we ran at the very beginning of this guide. Since we are returning the whole
contract we can call any function inside Example.sol. So if we import network.js
into a script as 'Network' we can call our function like so:

```javascript
example = await Network.example();
result = await example.function(parameter);
```

- Alternatively, one can expose functions directly in our API. If we go back to
*network.js/index.js* we can make the following function:

```javascript
someFunction: async (parameter) => {
instance = await exampleContract.at(Chain.Example());
result = await instance.function(parameter);
return result;
}
```

- Now we can access the function directly in our scripts:

```javascript
result = await Network.someFunction(parameter);
```

## 7) Update package.json and publish to NPM:
- Since we are using new npm packages, we need to update the version numbers in
package.json. You can update @mybit/contracts and @mybit/chain to the most recent
versions.

- Update network.js to git:
```bash
git add -u
git commit -m "Added example function"
git push origin master
```

- Now publish on npm:
```bash
npm version patch
npm publish --access=public
```

## 8) Update examples in hello-network:
- If you want to show examples and use cases for the new functions you wrote
in the API, you can add them here.

- After creating examples, update package.json to reference the newest version
of network.js.

- Then update git:
```bash
git add .
git commit -m "New stuff"
git push origin master
```

- Then publish to npm:
```bash
npm version patch
npm publish --access=public
```
20 changes: 10 additions & 10 deletions accounts.json
@@ -1,12 +1,12 @@
[
"0x34b4c0cf65a762f3042070a03425ab4bffe0170c",
"0x44067107f06443e6d125352bbf95de0c133456f8",
"0x02c4039e7d59b00e20f0f1dade6265c5a27ea715",
"0x9d01aafb060b3b76dc8e546b0550b68e8d7c529b",
"0xb220118ca37c21717fd09d9fc01fbb98d9b1f930",
"0x2fd989874137f24325474df1a3aacae508e3e2ce",
"0x6925b5a5cc617e466437a39ffb9c82a56c89e0a9",
"0xe42cd23ef408bf91042f3bb643db512c36d7a42e",
"0xee3cc3822bfeb1567ded5c507eba3a9c680988e7",
"0x20a698e36ae9bce21d5a00f87a98876a0e21af4e"
"0xeed17b217b1e0c63b1b525d8d2e59cad0546432d",
"0x0ec0e59bd4faf0a136c2ee638f3fcff19972a304",
"0xe273d3d13d69f82b8071365e110e13c0fbde0c59",
"0x4cbe9306228ff003fe5a47fe66f2e3d3162f0f37",
"0x0dcea99d96046de44f1ab2a4bf9b3e21f3ac2924",
"0x8bd581cca82af7cfff8ab46591803fe2f2061218",
"0xd6a41e3da4bdc4a27d5707b08612925347f5934f",
"0xd0702a4258c574ff15df4e65000dbb16843cbd24",
"0xc3dda1fc00ba83300b9ad2d00faa30166fabc657",
"0x45543e02e26442e6c95e3145f7d30a53b284f418"
]
32 changes: 16 additions & 16 deletions addresses.json
@@ -1,18 +1,18 @@
{
"MyBit": "0x1251954ebb35a93414c4fdd6eb572f9292f79bcf",
"ERC20Burner": "0xc263fabff96e5b4a11704478816c874fda9c4177",
"Database": "0x3f4c458f7adc3ce2300cd9fa7ab2c218d04ea18d",
"ContractManager": "0x346505e54761981543be0cd304d3c123887c6e99",
"API": "0xa12d771ffb785ad139dbe082be83259b7a0da142",
"SingleOwned": "0x5bb4c507e7a64c7db50f3a398dc80f399e9c968a",
"Pausible": "0x23ecf8d2811058b790f97fe3c307c16b8e41649e",
"AccessHierarchy": "0x24d2a3416e8b073dfc557fcf0b72cd73c4ae12c1",
"PlatformFunds": "0x6bbb45d95ddbb7a015d10257f66d13936212e64d",
"Operators": "0xbc135c1965c54aca5777aa750bf7863f23e074b3",
"AssetManagerEscrow": "0x172a12d553dd2a57a4227005972340dafcfcf14d",
"CrowdsaleETH": "0xdcf1b48d5bacfd16be0d03f68e0c748e08c79fb1",
"CrowdsaleGeneratorETH": "0x0ff213559567c2787abd8fb42ff46777fe978307",
"CrowdsaleERC20": "0xd5b03029ad72aa013cbcd5a8dd31f6a5cca04f45",
"CrowdsaleGeneratorERC20": "0xa1a8c7e4c9b1cb580428f3326dec41fc1b53391f",
"AssetExchange": "0x75fcdea05c36b0bdcbf1cd341b6cb7b846a885a3"
"MyBit": "0x82e8ed40b49fa4682d58807e99eaed6daf20b1d4",
"ERC20Burner": "0xfa3066aa522b18e0243f7c098e9c72fa85c89ae2",
"Database": "0xf3a985536aa63fcc5e0732fef35a9d6e0881682c",
"ContractManager": "0x8397e224cc3f2560d6c989bc29bb6800517d6f97",
"API": "0x94e839af9b8ec45da92d8a76e0acd1ca45b710c5",
"SingleOwned": "0x6df2e96b18b909e6127137a4a8ddf40eb259b610",
"Pausible": "0xbea6ba1b1aa691fc07a5b722bc491df03f4c280a",
"AccessHierarchy": "0xe4f4aeefd5087eababbd73bdd4c8188cbd008ebb",
"PlatformFunds": "0x7bd53d17ebee6c87d9937c8cb4fb04297cdc83c2",
"Operators": "0x54ae7cc1c7ec065a84b84ea7f9e33a14cf3d95e6",
"AssetManagerEscrow": "0x860b672a9fcb0f12c156cc9c233cfc3ed18fc202",
"CrowdsaleETH": "0x8af6ac104c639a9011b83f3baf789271e6df6198",
"CrowdsaleGeneratorETH": "0xeed31156aa0eeb2ebf473cd16faf70d2bf463137",
"CrowdsaleERC20": "0x03a685558ffd806ca2c44ab5f2ebe84688b82d57",
"CrowdsaleGeneratorERC20": "0xede40300bea9631bddbf1ab91ca286b5cd591d14",
"AssetExchange": "0x57bff4f318c5fb88e742d89627ad0b3ee62ab536"
}
39 changes: 13 additions & 26 deletions contracts/README.md
Expand Up @@ -2,47 +2,34 @@

:wrench: Block-end developer tools

MyBit SDK allows developers to create personalized platforms which create and distribute income using tokenized assets on the Ethereum virtual machine. Using these tools front-end developers can build decentralized asset management platforms of their own using MyBit deploy scripts and API's.

## Contract Categories

### Access

Access is where user access is managed. KYC restrictions can be applied across the platform using KYC.sol. Requirements can be set here, restricting access to users who can probably burn platform tokens, or pay for a time-based subscription.

### Crowdsale
### [Access](access)
Access is where user access is managed. KYC access restriction can be applied to users who can probably burn platform tokens, or pay for a time-based subscription.

### [Crowdsale](crowdsale)
In the crowdsale folder you can find all the contracts involved in funding new assets. Funds can be received in either Ether or any ERC20 token the operator agrees to accept. Each base unit of the received tokens or Wei represent 1 share of the asset. The total supply of each asset is determined by the amount raised plus the Asset Managers fee.

### Database

### [Database](database)
The database folder contains all contracts that abstract storage away from the logical 'front-end' contracts. When deploying the database, you can choose to have an upgradeable platform or a non-upgradeable. Write privileges to the database are determined by the contract manager, which is managed by the owner/owners of the platform.

### Ecosystem

The ecosystem folder contains all the non-core contracts that are used for the on-boarding of non-platform assets, asset-exchange, staking, and platform payment and token controls. Before funding assets the platform-token and the platform-wallet need to be set.

### Interfaces
### [Ecosystem](ecosystem)
The ecosystem folder contains all the non-core contracts that are used for the on-boarding of non-platform assets, asset-exchange, staking, and platform payment and token controls. Before funding assets the platform-token and the platform-wallet need to be set.

### [Interfaces](interfaces)
All interfaces that our contracts use to interact with other deployed contracts.

### Math

### [Math](math)
Math contracts are helper libraries for performing arithmetic without worrying about overflows and underflows.

### Ownership

Contracts for controlling the platform \(such as updating or pausing contracts\) by a single account, multiple accounts or ERC20 token holders. Investors holding asset-tokens can vote to choose or fire their current Asset Manager here.

### Roles
### [Ownership](ownership)
Contracts for controlling the platform (such as updating or pausing contracts) by a single account, multiple accounts or ERC20 token holders. Investors holding asset-tokens can vote to choose or fire their current Asset Manager here.

### [Roles](roles)
Asset Managers and Operators can control their funding preferences in the roles contracts. Asset Managers fees are held here to prevent them from transferring away the tokens.

### Test

### [Test](test)
Contracts that are only used for local testing to ensure full code coverage of the platform contracts.

### Tokens

### [Tokens](tokens)
Token contracts are used to represent fungible divisible assets. Tokens representing assets can be burnable, mintable, governed, and can receive ETH or ERC20 tokens as payment. The payment is distributed to asset-token holders according to their holdings.

1 change: 0 additions & 1 deletion contracts/crowdsale/CrowdsaleERC20.sol
Expand Up @@ -45,7 +45,6 @@ contract CrowdsaleERC20{
require(assetToken.mint(database.addressStorage(keccak256(abi.encodePacked("assetManager", _assetID))), database.uintStorage(keccak256(abi.encodePacked("assetManagerFee", _assetID))) ));
require(finalizeCrowdsale(_assetID));
require(assetToken.mint(msg.sender, tokensRemaining)); // Send remaining asset tokens to investor
// Give assetManager his portion of tokens
require(assetToken.finishMinting());
require(payoutERC20(_assetID, amountToRaise)); // 1 token = 1 wei
}
Expand Down
11 changes: 3 additions & 8 deletions contracts/crowdsale/CrowdsaleGeneratorERC20.sol
Expand Up @@ -34,9 +34,10 @@ contract CrowdsaleGeneratorERC20 {
// @param (address) _fundingToken = The ERC20 token to be used to fund the crowdsale (Operator must accept this token as payment)
function createAssetOrderERC20(string _assetURI, bytes32 _operatorID, uint _fundingLength, uint _amountToRaise, uint _assetManagerPerc, address _fundingToken)
external
isTrue(_assetManagerPerc < 100)
isTrue(database.boolStorage(keccak256(abi.encodePacked("acceptsToken", _operatorID, _fundingToken))))
burnRequired {
require(_amountToRaise > 0);
require(_assetManagerPerc < 100);
require(database.boolStorage(keccak256(abi.encodePacked("acceptsToken", _operatorID, _fundingToken))));
require(database.addressStorage(keccak256(abi.encodePacked("operator", _operatorID))) != address(0));
bytes32 assetID = keccak256(abi.encodePacked(msg.sender, _amountToRaise, _operatorID, _assetURI));
require(database.uintStorage(keccak256(abi.encodePacked("fundingDeadline", assetID))) == 0);
Expand All @@ -58,12 +59,6 @@ contract CrowdsaleGeneratorERC20 {
// Modifiers
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// @notice reverts if _conditional isn't true
modifier isTrue(bool _conditional){
require(_conditional);
_;
}

// @notice reverts if AssetManager hasn't approved burner to burn platform token
modifier burnRequired {
//emit LogSig(msg.sig);
Expand Down
13 changes: 5 additions & 8 deletions contracts/crowdsale/CrowdsaleGeneratorETH.sol
Expand Up @@ -33,10 +33,11 @@ contract CrowdsaleGeneratorETH {
// @param (uint) _assetManagerPerc = The percentage of the total revenue which is to go to the AssetManager if asset is a success
function createAssetOrderETH(string _assetURI, bytes32 _operatorID, uint _fundingLength, uint _amountToRaise, uint _assetManagerPerc)
external
isTrue(_assetManagerPerc < 100)
isTrue(database.boolStorage(keccak256(abi.encodePacked("acceptsEther", _operatorID))))
burnRequired
returns (bool) {
require(_amountToRaise > 0);
require(_assetManagerPerc < 100);
require(database.boolStorage(keccak256(abi.encodePacked("acceptsEther", _operatorID))));
require(database.addressStorage(keccak256(abi.encodePacked("operator", _operatorID))) != address(0));
bytes32 assetID = keccak256(abi.encodePacked(msg.sender, _amountToRaise, _operatorID, _assetURI));
require(database.uintStorage(keccak256(abi.encodePacked("fundingDeadline", assetID))) == 0);
Expand All @@ -47,7 +48,7 @@ contract CrowdsaleGeneratorETH {
database.setUint(keccak256(abi.encodePacked("amountToRaise", assetID)), _amountToRaise);
database.setAddress(keccak256(abi.encodePacked("tokenAddress", assetID)), assetAddress);
database.setBytes32(keccak256(abi.encodePacked("assetTokenID", assetAddress)), assetID);
database.setAddress(keccak256(abi.encodePacked("assetManager", assetID)), msg.sender); // Make this a require() if want to enforce escrow
database.setAddress(keccak256(abi.encodePacked("assetManager", assetID)), msg.sender);
database.setAddress(keccak256(abi.encodePacked("operator", assetID)), database.addressStorage(keccak256(abi.encodePacked("operator", _operatorID))));
emit LogAssetFundingStarted(assetID, msg.sender, _assetURI, address(assetAddress));
return true;
Expand All @@ -57,12 +58,8 @@ contract CrowdsaleGeneratorETH {
// Modifiers
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

modifier isTrue(bool _conditional){
require(_conditional);
_;
}


// @notice reverts if asset manager is unable to burn pp
modifier burnRequired {
//emit LogSig(msg.sig);
require(burner.burn(msg.sender, database.uintStorage(keccak256(abi.encodePacked(msg.sig, address(this))))));
Expand Down
15 changes: 14 additions & 1 deletion contracts/roles.md
Expand Up @@ -11,6 +11,19 @@ THe AssetManagerFunds are where the dividends belonging to the AssetManager are
The AssetManagerEscrow contract accepts MYB tokens to be held in escrow in order to align the assetManager's incentives with investors. If an asset is not distributing returns, investors can vote to burn the assetManager's MYB placed in escrow. If the asset does give ROI, the assetManager's escrow funds are returned relative to the ROI earned. If the asset is governed, the owners of the asset-tokens can vote to change the AssetManager here.

### Operators

This contract is used the platform owner to onboard new operators. An operator ID is needed for any new asset crowdsales to be created. Operators can choose if they wish to receive Ether and/or ERC20 tokens of their choosing.


## General roles

#### Platform Owner(s)
The owners of the platform are in charge of deciding high level upgrades and authorization changes made in the platform. Ownership can be decided by one owner, a multi-sig, or token holders themselves.

#### Investor
The investor is any user that holds asset tokens through participating in an asset crowdsale or by means of purchasing them on an exchange.

#### AssetManager
The AssetManager is a user that initiates a crowdfunding period for an asset. After the funding period, the AssetManager is in charge of handling real world operations between the asset operator and the investors. The role of the AssetManager varies depending on the type of asset, but they are responsible for the asset operating properly if the conditions allow it. The AssetManager can put down tokens in escrow, which is at stake to get burned if the owners of the asset find negligence.

#### Operator
The operator is the producer of the asset, physical or digital. They are in charge of receiving the crowdfunding funds and producing, delivering and installing the asset. AssetManagers will deal with Operators to ensure continued functioning of the asset.

0 comments on commit 92e6fcf

Please sign in to comment.