contract DigitalMarketProxy is DigitalMarketStorage{
    // every called functions of premissoned delegates must be added first
    function addFunctions(address _delegate, bytes4 _function, string memory _signiture) public onlyOwner{
        require(funDelegates[_function] == address(0), "Function is already exist!" );
        funDelegates[_function]= _delegate; 
        funcN++;
        emit FunctionUpdate(_function, address(0), _delegate, string(_signiture));
    }
    
    function updateFunctions(address _delegate, bytes4 _function) public onlyOwner{
        require(funDelegates[_function] != address(0), "Function Not found!" );
        require(funDelegates[_function] == _delegate, "Function doesn't match delegate!" );
        funDelegates[_function]= address(0); 
        funcN--;
        emit FunctionUpdate(_function, _delegate, address(0), string('Function disabled'));
    }
    
    function  () external payable {
        address delegate = funDelegates[msg.sig];
        require(delegate != address(0), "Delegate does not exist.");
        
        assembly {
          let ptr := mload(0x40)
          // (1) copy incoming call data
          calldatacopy(ptr, 0, calldatasize)
          
          // (2) forward call to logic contract
          let result := delegatecall(gas, delegate, ptr, calldatasize, 0, 0)
          let size := returndatasize
          
          // (3) retrieve return data
          returndatacopy(ptr, 0, size)
          
          // (4) forward return data back to caller
          switch result
          case 0 {revert(ptr, size)}
          default {return (ptr, size)}
        } 
    }
    
    function balanceOfUsers(address token, address user) public view returns (uint balance) {
        return tokens[token][user];
    }
      
    function balanceOfFillOrders(address userAdd, bytes32 msgHash) public view returns (uint balance) {
        return orderFills[userAdd][msgHash];
    }
    
    
}
function addFunctions(address _delegate, bytes4 _function, string memory _signiture) public onlyOwner{
        require(funDelegates[_function] == address(0), "Function is already exist!" );
        funDelegates[_function]= _delegate; 
        funcN++;
        emit FunctionUpdate(_function, address(0), _delegate, string(_signiture));
    }
// every called functions of premissoned delegates must be added first