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

Flatten contracts #3

Merged
merged 1 commit into from
May 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ gulp lint:contracts

We use a hosted Ethereum node cluster - [Infura](https://infura.io) for deployment to main and test networks.

Flattened contracts are in source control under `flattened` folder and can be generated via `yarn run flatten:contracts` which uses [solidity-flattener](https://github.com/BlockCatIO/solidity-flattener) which you can install via `pip3 install solidity-flattener`
Flattened contracts are in source control under `flattened` folder and can be generated via `yarn run flatten:contracts` which uses [/solidity-steamroller](https://github.com/JoinColony/solidity-steamroller)
98 changes: 98 additions & 0 deletions flattened/TokenAuthorityFlattened.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
pragma solidity ^0.4.23;


// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.



contract DSAuthority {
function canCall(
address src, address dst, bytes4 sig
) public view returns (bool);
}

contract DSAuthEvents {
event LogSetAuthority (address indexed authority);
event LogSetOwner (address indexed owner);
}

contract DSAuth is DSAuthEvents {
DSAuthority public authority;
address public owner;

constructor() public {
owner = msg.sender;
emit LogSetOwner(msg.sender);
}

function setOwner(address owner_)
public
auth
{
owner = owner_;
emit LogSetOwner(owner);
}

function setAuthority(DSAuthority authority_)
public
auth
{
authority = authority_;
emit LogSetAuthority(authority);
}

modifier auth {
require(isAuthorized(msg.sender, msg.sig));
_;
}

function isAuthorized(address src, bytes4 sig) internal view returns (bool) {
if (src == address(this)) {
return true;
} else if (src == owner) {
return true;
} else if (authority == DSAuthority(0)) {
return false;
} else {
return authority.canCall(src, this, sig);
}
}
}


contract TokenAuthority is DSAuthority {
address public token;
mapping(address => mapping(bytes4 => bool)) authorizations;

constructor(address _token, address _vesting, address _colonyMultiSig) public {
token = _token;
bytes4 transferSig = bytes4(keccak256("transfer(address,uint256)"));
bytes4 transferFromSig = bytes4(keccak256("transferFrom(address,address,uint256)"));
bytes4 mintSig = bytes4(keccak256("mint(uint256)"));

authorizations[_vesting][transferSig] = true;
authorizations[_vesting][transferFromSig] = true;
authorizations[_colonyMultiSig][transferSig] = true;
authorizations[_colonyMultiSig][transferFromSig] = true;
authorizations[_colonyMultiSig][mintSig] = true;
}

function canCall(address src, address dst, bytes4 sig) public view returns (bool) {
if (dst != token) {
return false;
}

return authorizations[src][sig];
}
}
153 changes: 117 additions & 36 deletions flattened/TokenFlattened.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
pragma solidity ^0.4.13;
pragma solidity ^0.4.23;
pragma experimental "v0.5.0";




// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.



contract DSAuthority {
function canCall(
Expand All @@ -15,25 +34,25 @@ contract DSAuth is DSAuthEvents {
DSAuthority public authority;
address public owner;

function DSAuth() public {
constructor() public {
owner = msg.sender;
LogSetOwner(msg.sender);
emit LogSetOwner(msg.sender);
}

function setOwner(address owner_)
public
auth
{
owner = owner_;
LogSetOwner(owner);
emit LogSetOwner(owner);
}

function setAuthority(DSAuthority authority_)
public
auth
{
authority = authority_;
LogSetAuthority(authority);
emit LogSetAuthority(authority);
}

modifier auth {
Expand All @@ -53,27 +72,22 @@ contract DSAuth is DSAuthEvents {
}
}
}
/// math.sol -- mixin for inline numerical wizardry

contract ERC20Events {
event Approval(address indexed src, address indexed guy, uint wad);
event Transfer(address indexed src, address indexed dst, uint wad);
}
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

contract ERC20 is ERC20Events {
function totalSupply() public view returns (uint);
function balanceOf(address guy) public view returns (uint);
function allowance(address src, address guy) public view returns (uint);
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

function approve(address guy, uint wad) public returns (bool);
function transfer(address dst, uint wad) public returns (bool);
function transferFrom(
address src, address dst, uint wad
) public returns (bool);
}

contract ERC20Extended is ERC20 {
function mint(uint wad) public;
}

contract DSMath {
function add(uint x, uint y) internal pure returns (uint z) {
Expand Down Expand Up @@ -142,6 +156,60 @@ contract DSMath {
}
}
}
/*
This file is part of The Colony Network.

The Colony Network is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

The Colony Network is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with The Colony Network. If not, see <http://www.gnu.org/licenses/>.
*/




/// erc20.sol -- API for the ERC20 token standard

// See <https://github.com/ethereum/EIPs/issues/20>.

// This file likely does not meet the threshold of originality
// required for copyright to apply. As a result, this is free and
// unencumbered software belonging to the public domain.



contract ERC20Events {
event Approval(address indexed src, address indexed guy, uint wad);
event Transfer(address indexed src, address indexed dst, uint wad);
}

contract ERC20 is ERC20Events {
function totalSupply() public view returns (uint);
function balanceOf(address guy) public view returns (uint);
function allowance(address src, address guy) public view returns (uint);

function approve(address guy, uint wad) public returns (bool);
function transfer(address dst, uint wad) public returns (bool);
function transferFrom(
address src, address dst, uint wad
) public returns (bool);
}


contract ERC20Extended is ERC20 {
event Mint(address indexed guy, uint wad);

function mint(uint wad) public;
}


contract Token is DSAuth, DSMath, ERC20Extended {
bytes32 public symbol;
Expand All @@ -151,11 +219,20 @@ contract Token is DSAuth, DSMath, ERC20Extended {
uint256 _supply;
mapping (address => uint256) _balances;
mapping (address => mapping (address => uint256)) _approvals;
bool public locked;

function Token(bytes32 _name, bytes32 _symbol, uint256 _decimals) public {
constructor(bytes32 _name, bytes32 _symbol, uint256 _decimals) public {
name = _name;
symbol = _symbol;
decimals = _decimals;
locked = true;
}

modifier unlocked {
if (locked) {
require(isAuthorized(msg.sender, msg.sig));
}
_;
}

function totalSupply() public view returns (uint256) {
Expand All @@ -171,21 +248,17 @@ contract Token is DSAuth, DSMath, ERC20Extended {
}

function transfer(address dst, uint wad) public returns (bool) {
assert(_balances[msg.sender] >= wad);

_balances[msg.sender] = sub(_balances[msg.sender], wad);
_balances[dst] = add(_balances[dst], wad);

emit Transfer(msg.sender, dst, wad);

return true;
return transferFrom(msg.sender, dst, wad);
}

function transferFrom(address src, address dst, uint wad) public returns (bool) {
assert(_balances[src] >= wad);
assert(_approvals[src][msg.sender] >= wad);
function transferFrom(address src, address dst, uint wad) public
unlocked
returns (bool)
{
if (src != msg.sender) {
_approvals[src][msg.sender] = sub(_approvals[src][msg.sender], wad);
}

_approvals[src][msg.sender] = sub(_approvals[src][msg.sender], wad);
_balances[src] = sub(_balances[src], wad);
_balances[dst] = add(_balances[dst], wad);

Expand All @@ -207,6 +280,14 @@ contract Token is DSAuth, DSMath, ERC20Extended {
{
_balances[msg.sender] = add(_balances[msg.sender], wad);
_supply = add(_supply, wad);

emit Mint(msg.sender, wad);
}
}

function unlock() public
auth
{
require(locked);
locked = false;
}
}
Loading