all files / contracts/Entity/ TokenManager.sol

100% Statements 18/18
50% Branches 2/4
100% Functions 5/5
100% Lines 21/21
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117                                                                      116×                               115×   115× 115×                                     98×       98× 98×     98×     98×       98×     98× 98×   98× 98×                            
/*
 
 * @name        Token Manager Contract
 * @package     BlockBitsIO
 * @author      Micky Socaci <[email protected]>
 
 
 
*/
 
pragma solidity ^0.4.17;
 
import "./Token.sol";
import "./../ApplicationAsset.sol";
import "./../ApplicationEntity.sol";
 
import "./../Algorithms/TokenSCADA1Market.sol";
 
contract TokenManager is ApplicationAsset {
 
    TokenSCADA1Market public TokenSCADAEntity;
    Token public TokenEntity;
 
    function addTokenSettingsAndInit(
        uint256 _tokenSupply,
        uint8 _tokenDecimals,
        string _tokenName,
        string _tokenSymbol,
        string _version
    )
        public
        requireInitialised
        requireSettingsNotApplied
        onlyDeployer
    {
        TokenEntity = new Token(
            _tokenSupply,
            _tokenName,
            _tokenDecimals,
            _tokenSymbol,
            _version
        );
    }
 
    function runBeforeApplyingSettings()
        internal
        requireInitialised
        requireSettingsNotApplied
    {
        // we need token address
        // we need funding contract address.. let's ask application entity ABI for it :D
        address fundingContractAddress = getApplicationAssetAddressByName('Funding');
 
        TokenSCADAEntity = new TokenSCADA1Market(address(TokenEntity), fundingContractAddress);
        EventRunBeforeApplyingSettings(assetName);
    }
 
    function getTokenSCADARequiresHardCap() public view returns (bool) {
        return TokenSCADAEntity.requiresHardCap();
    }
 
    // Funding initialization complete, give funding manager tokens we're selling
    event EventAllocatedInitialTokenBalances(address _addr, uint256 _value);
    bool InitialTokenBalancesAllocated = false;
 
    function AllocateInitialTokenBalances(
        uint8 _sellPercentage,
        address _FundingManagerAddress,
        address _BountyManagerAddress
    )
        public
        onlyAsset('Funding')
        returns (bool)
    {
        Erequire(InitialTokenBalancesAllocated == false);
        // TokenManager owns all tokens.
 
        // first we subtract bounty percentage, the rest is then distributed to funding and owner
        uint256 bountyPercent = getAppBylawUint256("token_bounty_percentage");
        uint256 bountyValue = TokenEntity.balanceOf(address(this)) / 100 * bountyPercent;
        // Allocate the percentage we're distributing using bounty to the BountyManager
        // from this as ( msg.sender ) , to BountyManager, value
        TokenEntity.transfer( _BountyManagerAddress, bountyValue );
 
        // calculate token value based on selling percentage
        uint256 tokenValue = TokenEntity.balanceOf(address(this)) / 100 * _sellPercentage;
        // Allocate the percentage we're selling to the FundingManager
 
        // in order to handle fraction and percentage rounding errors, we're allocating 1 full token from owners to sale.
        tokenValue = tokenValue + ( 1 ether );
 
        // from this as ( msg.sender ) , to FundingManager, value
        TokenEntity.transfer( _FundingManagerAddress, tokenValue );
        EventAllocatedInitialTokenBalances(_FundingManagerAddress, tokenValue);
 
        InitialTokenBalancesAllocated = true;
        return true;
    }
 
    // Development stage complete, release tokens to Project Owners
    event EventOwnerTokenBalancesReleased(address _addr, uint256 _value);
    bool OwnerTokenBalancesReleased = false;
 
    function ReleaseOwnersLockedTokens(address _multiSigOutputAddress)
        public
        onlyAsset('FundingManager')
        returns (bool)
    {
        Erequire(OwnerTokenBalancesReleased == false);
        uint256 lockedBalance = TokenEntity.balanceOf(address(this));
        TokenEntity.transfer( _multiSigOutputAddress, lockedBalance );
        EventOwnerTokenBalancesReleased(_multiSigOutputAddress, lockedBalance);
        OwnerTokenBalancesReleased = true;
        return true;
    }
 
}