Skip to content

Commit

Permalink
Merge pull request #169 from kyledewy/master
Browse files Browse the repository at this point in the history
Added AssetGenerator documentation. Removed broker reference from API
  • Loading branch information
0xdewy committed Oct 23, 2018
2 parents 60b32b1 + de31ee7 commit 713caca
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 21 deletions.
74 changes: 57 additions & 17 deletions README.md
Expand Up @@ -10,13 +10,9 @@

[![CircleCI](https://circleci.com/gh/MyBitFoundation/MyBit-Network.tech.svg?style=shield)](https://circleci.com/gh/MyBitFoundation/MyBit-Network.tech) [![Coverage Status](https://coveralls.io/repos/github/MyBitFoundation/MyBit-Network.tech/badge.svg)](https://coveralls.io/github/MyBitFoundation/MyBit-Network.tech)

:factory: A software development kit for the automated machine economy.
A software development kit for the automated machine economy.

Network SDK's are a protocol that allows the creation of decentralised digital assets, funding and trading. It also enables the distribution of revenue generated by assets. These SDK's contain all the functional logic of [MyBit-Go](https://github.com/MyBitFoundation/MyBit-Go.app).

* For a simple example see [Hello-Network](https://github.com/MyBitFoundation/hello-network)

* For importing the SDK's as an NPM package see [Network.js](https://github.com/MyBitFoundation/network.js)
The contract SDK is a set of contracts that implement the business logic for the network. The Network SDK is a tool for building Wealth Management Decentralised Applications, without needing in depth blockchain knowledge. For a simple example you can see [Hello-Network](https://github.com/MyBitFoundation/hello-network). To quickly integrate the SDK contracts see [Network.js](https://github.com/MyBitFoundation/network.js).

## Getting Started
First install dependencies using [Yarn](https://yarnpkg.com/lang/en/docs/install/#debian-stable):
Expand All @@ -34,8 +30,8 @@ If successful you should see output similar to below:
[4/4] Building fresh packages...
Done in 5.69s.
```

Then get a local test blockchain running using [Ganache](https://truffleframework.com/ganache)
## Testing
To start local blockchain, [Ganache](https://truffleframework.com/ganache) run:

```bash
yarn blockchain
Expand All @@ -52,14 +48,19 @@ yarn coverage
```
## [Roles](contracts/roles)
The MYB SDK's have 4 fundamental roles:
To understand the SDK, it's important to understand the 4 fundamental roles on the network:
* Investor `must burn MYB to participate`
* AssetManager `must burn MYB to participate`
* Operator `must be registered by owners`
* Platform Owner(s)
#### Investor
Investors can contribute ETH or ERC20 tokens to invest in asset orders, receiving asset-tokens in return. To invest they must approve the burner contract.
Investors can contribute ETH or Erc20 tokens to invest in new asset crowdsales. The assets are managed by the AssetManager, who receives a fee for his work and escrows tokens as collateral to investors. The Operator receives funds from the crowdsale and produces and install the asset. Platform owners can choose how assets are governed, and whether or not a contract upgrade should happen. The platform owner can be a single account or a contract governed by many accounts.
#### AssetManager
The assets are managed and created by the AssetManager, who receives a fee for his work and escrows tokens as collateral to investors. The AssetManager must approve the burner contract to burn platform tokens.
#### Operator
The Operator is responsible for producing and installing the asset. They receive 99% of the crowdsale income as a fee for doing so. Platform owners must approve each Operator.
#### Platform Owner(s)
Platform owners can choose how assets are governed, and whether or not a contract upgrade should happen. The platform owner can be a single account or a contract governed by many accounts. Platform owners receive 1% of crowdsale income as a fee.
## Setting Up The Platform
Expand Down Expand Up @@ -311,6 +312,48 @@ Investors an withdraw income by calling `withdraw()` which updates their persona
}
```

## Onboarding Assets
Using the AssetGenerator contract, users are able to create already funded assets and manage them using the SDK's.

To create a funded asset call:
```javascript
function createAsset(string _tokenURI, address[] _tokenHolders, uint[] _amount)
external
burnRequired
returns (bool) {
require (_tokenHolders.length == _amount.length && _tokenHolders.length <= 100);
bytes32 assetID = keccak256(abi.encodePacked(msg.sender, _tokenURI));
require(database.addressStorage(keccak256(abi.encodePacked("tokenAddress", assetID))) == address(0));
FixedDistribution assetInstance = new FixedDistribution(_tokenURI, _tokenHolders, _amount);
database.setAddress(keccak256(abi.encodePacked("assetManager", assetID)), msg.sender);
database.setAddress(keccak256(abi.encodePacked("tokenAddress", assetID)), address(assetInstance));
emit LogAssetCreated(assetID, address(assetInstance), msg.sender, _tokenURI);
return true;
}
```

If you want the asset to be tradeable on ERC20 exchanges call:
```javascript
function createTradeableAsset(string _tokenURI, address[] _tokenHolders, uint[] _amount)
external
burnRequired
returns (bool) {
require (_tokenHolders.length == _amount.length && _tokenHolders.length <= uint8(100));
address assetGeneratorAddress = database.addressStorage(keccak256(abi.encodePacked("contract", "AssetGenerator")));
bytes32 assetID = keccak256(abi.encodePacked(msg.sender, _tokenURI));
require(database.addressStorage(keccak256(abi.encodePacked("tokenAddress", assetID))) == address(0));
DividendToken assetInstance = new DividendToken(_tokenURI, assetGeneratorAddress); // Gives this contract all new asset tokens
for (uint8 i = 0; i < _tokenHolders.length; i++) {
assetInstance.mint(_tokenHolders[i], _amount[i]);
}
assetInstance.finishMinting();
database.setAddress(keccak256(abi.encodePacked("assetManager", assetID)), msg.sender);
database.setAddress(keccak256(abi.encodePacked("tokenAddress", assetID)), address(assetInstance));
emit LogTradeableAssetCreated(assetID, address(assetInstance), msg.sender, _tokenURI);
return true;
}
```

## In-Development
:construction: The SDK's are a work in progress and we hope to implement more features such as asset-governance, platform-governance and obfuscated asset authentication.

Expand Down Expand Up @@ -361,9 +404,6 @@ GIT_USER=<GIT_USER> \
yarn run publish-gh-pages
```

## Live example test-net contracts


⚠️ This application is unstable and has not undergone any rigorous security audits. Use at your own risk.

MyBit Platform™ CHE-177.186.963
4 changes: 2 additions & 2 deletions contracts/database/API.sol
Expand Up @@ -72,11 +72,11 @@ contract API {
return (totalVotes * 100) / TokenView(_assetToken).totalSupply();
}

function getAssetManagerParameterHash(bytes32 _assetID, address _oldBroker, address _newBroker, uint _amount, bool _burn)
function getAssetManagerParameterHash(bytes32 _assetID, address _oldAssetManager, address _newAssetManager, uint _amount, bool _burn)
public
pure
returns (bytes32){
return keccak256(abi.encodePacked(_assetID, _oldBroker, _newBroker, _amount, _burn));
return keccak256(abi.encodePacked(_assetID, _oldAssetManager, _newAssetManager, _amount, _burn));
}

function getExecutionID(address _executingContract, bytes32 _assetID, bytes4 _methodID, bytes32 _parameterHash)
Expand Down
5 changes: 3 additions & 2 deletions contracts/ecosystem/AssetGenerator.sol
Expand Up @@ -7,6 +7,7 @@ import "../tokens/erc20/DividendToken.sol";
import "../tokens/distribution/FixedDistribution.sol";

// @title An asset generator contract for onboarding existing real-world assets
// @notice This contract creates ERC20 dividend tokens and give sthem to the _tokenHolders provided
// @author Kyle Dewhurst, MyBit Foundation
contract AssetGenerator {
using SafeMath for uint256;
Expand All @@ -28,7 +29,7 @@ contract AssetGenerator {
external
burnRequired
returns (bool) {
require (_tokenHolders.length == _amount.length && _tokenHolders.length <= 200);
require (_tokenHolders.length == _amount.length && _tokenHolders.length <= 100);
bytes32 assetID = keccak256(abi.encodePacked(msg.sender, _tokenURI));
require(database.addressStorage(keccak256(abi.encodePacked("tokenAddress", assetID))) == address(0));
FixedDistribution assetInstance = new FixedDistribution(_tokenURI, _tokenHolders, _amount);
Expand All @@ -44,7 +45,7 @@ contract AssetGenerator {
external
burnRequired
returns (bool) {
require (_tokenHolders.length == _amount.length && _tokenHolders.length <= uint8(200));
require (_tokenHolders.length == _amount.length && _tokenHolders.length <= uint8(100));
address assetGeneratorAddress = database.addressStorage(keccak256(abi.encodePacked("contract", "AssetGenerator")));
bytes32 assetID = keccak256(abi.encodePacked(msg.sender, _tokenURI));
require(database.addressStorage(keccak256(abi.encodePacked("tokenAddress", assetID))) == address(0));
Expand Down

0 comments on commit 713caca

Please sign in to comment.