Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure for v0.9.1 to separate value from logic #5

Merged
merged 17 commits into from
Nov 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ ubuntu-xenial-16.04-cloudimg-console.log
# we do commit the contract binaries in platform
contracts/bin/
contracts/abi/

# don't commit node_modules
node_modules
96 changes: 96 additions & 0 deletions contracts/BrandedToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
pragma solidity ^0.4.17;

// Copyright 2017 OpenST Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ----------------------------------------------------------------------------
// Utility chain: BrandedToken
//
// http://www.simpletoken.org/
//
// ----------------------------------------------------------------------------

import "./SafeMath.sol";

// utility chain contracts
import "./EIP20Token.sol";
import "./UtilityTokenAbstract.sol";

/// @dev Branded Token is an EIP20 token minted by staking Simple Token
/// on Ethereum mainnet. Branded tokens are designed to be used
/// within a (decentralised) application and support:
/// - smart contract controlled password reset for users who don't
/// yet (hard-spoon FTW) manage their own private keys (+v0.9.2)
/// - soft-exit for a user to redeem their equivalent part of the
/// Simple Token stake on Ethereum mainnet
/// - hard-exit for all users if the utility chain halts to reclaim
/// their equivalent part of the Simple Token stake
/// on Ethereum (before v1.0)
contract BrandedToken is EIP20Token, UtilityTokenAbstract {
using SafeMath for uint256;

/*
* Public functions
*/
function BrandedToken(
address _openSTProtocol,
bytes32 _uuid,
string _symbol,
string _name,
uint8 _decimals)
EIP20Token(_symbol, _name, _decimals)
UtilityTokenAbstract(_openSTProtocol, _uuid)
public
{

}

function claim(
address _beneficiary)
public
returns (bool /* success */)
{
uint256 amount = claimInternal(_beneficiary);

return claimEIP20(_beneficiary, amount);
}

function mint(
address _beneficiary,
uint256 _amount)
public
onlyProtocol
returns (bool /* success */)
{
mintEIP20(_amount);

return mintInternal(_beneficiary, _amount);
}

function burn(
address _burner,
uint256 _amount)
public
onlyProtocol
payable
returns (bool /* success */)
{
// force non-payable, as only ST' handles in base tokens
require(msg.value == 0);

burnEIP20(_amount);

return burnInternal(_burner, _amount);
}
}
99 changes: 99 additions & 0 deletions contracts/Core.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
pragma solidity ^0.4.17;

// Copyright 2017 OpenST Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ----------------------------------------------------------------------------
// Common: Core
//
// http://www.simpletoken.org/
//
// ----------------------------------------------------------------------------

import "./CoreInterface.sol";

contract Core is CoreInterface {

/*
* Structures
*/
// struct stakeTokenTuple {
// address stake;
// address token;
// }


/*
* Storage
*/
/// registrar registers for the two chains
address private coreRegistrar;
/// chainIdOrigin stores the chainId this chain
uint256 private coreChainIdOrigin;
/// chainIdRemote stores the chainId of the remote chain
uint256 private coreChainIdRemote;
/// OpenST remote is the address of the OpenST contract
/// on the remote chain
address private coreOpenSTRemote;
// ///
// mapping(bytes32 => address) stakeTokenTuple;


/*
* Public functions
*/
function Core(
address _registrar,
uint256 _chainIdOrigin,
uint256 _chainIdRemote,
address _openSTRemote)
public
{
require(_registrar != address(0));
require(_chainIdOrigin != 0);
require(_chainIdRemote != 0);
require(_openSTRemote != 0);
coreRegistrar = _registrar;
coreChainIdOrigin = _chainIdOrigin;
coreChainIdRemote = _chainIdRemote;
coreOpenSTRemote = _openSTRemote;
}

/*
* Public view functions
*/
function registrar()
public
view
returns (address /* registrar */)
{
return coreRegistrar;
}

function chainIdRemote()
public
view
returns (uint256 /* chainIdRemote */)
{
return coreChainIdRemote;
}

function openSTRemote()
public
view
returns (address /* OpenSTRemote */)
{
return coreOpenSTRemote;
}
}
30 changes: 30 additions & 0 deletions contracts/CoreInterface.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
pragma solidity ^0.4.17;

// Copyright 2017 OpenST Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ----------------------------------------------------------------------------
// Common: CoreInterface
//
// http://www.simpletoken.org/
//
// ----------------------------------------------------------------------------

contract CoreInterface {

function registrar() public view returns (address /* registrar */);

function chainIdRemote() public view returns (uint256 /* chainIdRemote */);
function openSTRemote() public view returns (address /* OpenSTRemote */);
}
2 changes: 1 addition & 1 deletion contracts/EIP20Interface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pragma solidity ^0.4.17;
// limitations under the License.
//
// ----------------------------------------------------------------------------
// Standard EIP20 Interface
// Common: Standard EIP20 Interface
//
// http://www.simpletoken.org/
//
Expand Down
47 changes: 30 additions & 17 deletions contracts/EIP20Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,35 @@ pragma solidity ^0.4.17;
// limitations under the License.
//
// ----------------------------------------------------------------------------
// EIP20 Token Implementation
// Utility chain: EIP20 Token Implementation
//
// http://www.simpletoken.org/
//
// ----------------------------------------------------------------------------

import "./EIP20Interface.sol";
import "./Owned.sol";
import "./SafeMath.sol";

/**
@title EIP20Token
@notice Implements EIP20 token
*/
contract EIP20Token is Owned, EIP20Interface {
contract EIP20Token is EIP20Interface {
using SafeMath for uint256;

string internal tokenName;
string internal tokenSymbol;
uint8 internal tokenDecimals;
uint256 internal tokenTotalSupply;
string private tokenName;
string private tokenSymbol;
uint8 private tokenDecimals;

mapping(address => uint256) balances;
mapping(address => mapping (address => uint256)) allowed;


function EIP20Token(string _symbol, string _name, uint8 _decimals) public
Owned()
{
tokenSymbol = _symbol;
tokenName = _name;
tokenDecimals = _decimals;

// According to the EIP20 standard, a token contract which creates new tokens should trigger
// a Transfer event and transfers of 0 values must also fire the event.
Transfer(0x0, owner, tokenTotalSupply);
}


Expand All @@ -69,11 +62,6 @@ contract EIP20Token is Owned, EIP20Interface {
}


function totalSupply() public view returns (uint256) {
return tokenTotalSupply;
}


function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner];
}
Expand Down Expand Up @@ -116,4 +104,29 @@ contract EIP20Token is Owned, EIP20Interface {

return true;
}


function claimEIP20(address _beneficiary, uint256 _amount) internal returns (bool success) {
// claimable tokens are minted in the contract address to be pulled on claim
balances[address(this)] = balances[address(this)].sub(_amount);
balances[_beneficiary] = balances[_beneficiary].add(_amount);

Transfer(address(this), _beneficiary, _amount);

return true;
}


function mintEIP20(uint256 _amount) internal returns (bool /* success */) {
// mint EIP20 tokens in contract address for them to be claimed
balances[address(this)] = balances[address(this)].add(_amount);

return true;
}

function burnEIP20(uint256 _amount) internal returns (bool /* success */) {
balances[msg.sender] = balances[msg.sender].sub(_amount);

return true;
}
}
Loading