Add updated contracts, reorganize contract file structure
This commit is contained in:
@@ -16,11 +16,11 @@
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.4.11;
|
||||
pragma solidity ^0.4.11;
|
||||
|
||||
import "./TokenTransferProxy.sol";
|
||||
import "./base/Token.sol";
|
||||
import "./base/SafeMath.sol";
|
||||
import "./tokens/Token.sol";
|
||||
import "./lib/SafeMath.sol";
|
||||
|
||||
/// @title Exchange - Facilitates exchange of ERC20 tokens.
|
||||
/// @author Amir Bandeali - <amir@0xProject.com>, Will Warren - <will@0xProject.com>
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.4.11;
|
||||
pragma solidity ^0.4.11;
|
||||
|
||||
import "./base/Ownable.sol";
|
||||
import "./lib/Ownable.sol";
|
||||
|
||||
/// @title Token Registry - Stores metadata associated with ERC20 tokens. See ERC22 https://github.com/ethereum/EIPs/issues/22
|
||||
/// @author Amir Bandeali - <amir@0xProject.com>, Will Warren - <will@0xProject.com>
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.4.11;
|
||||
pragma solidity ^0.4.11;
|
||||
|
||||
import "./base/Token.sol";
|
||||
import "./base/Ownable.sol";
|
||||
import "./tokens/Token.sol";
|
||||
import "./lib/Ownable.sol";
|
||||
|
||||
/// @title TokenTransferProxy - Transfers tokens on behalf of contracts that have been approved via decentralized governance.
|
||||
/// @author Amir Bandeali - <amir@0xProject.com>, Will Warren - <will@0xProject.com>
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
pragma solidity 0.4.11;
|
||||
|
||||
/*
|
||||
* Ownable
|
||||
*
|
||||
* Base contract with an owner.
|
||||
* Provides onlyOwner modifier, which prevents function from running if it is called by anyone other than the owner.
|
||||
*/
|
||||
|
||||
contract Ownable {
|
||||
address public owner;
|
||||
|
||||
function Ownable() {
|
||||
owner = msg.sender;
|
||||
}
|
||||
|
||||
modifier onlyOwner() {
|
||||
require(msg.sender == owner);
|
||||
_;
|
||||
}
|
||||
|
||||
function transferOwnership(address newOwner) onlyOwner {
|
||||
if (newOwner != address(0)) {
|
||||
owner = newOwner;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
pragma solidity 0.4.11;
|
||||
|
||||
contract SafeMath {
|
||||
function safeMul(uint a, uint b) internal constant returns (uint256) {
|
||||
uint c = a * b;
|
||||
assert(a == 0 || c / a == b);
|
||||
return c;
|
||||
}
|
||||
|
||||
function safeDiv(uint a, uint b) internal constant returns (uint256) {
|
||||
uint c = a / b;
|
||||
return c;
|
||||
}
|
||||
|
||||
function safeSub(uint a, uint b) internal constant returns (uint256) {
|
||||
assert(b <= a);
|
||||
return a - b;
|
||||
}
|
||||
|
||||
function safeAdd(uint a, uint b) internal constant returns (uint256) {
|
||||
uint c = a + b;
|
||||
assert(c >= a);
|
||||
return c;
|
||||
}
|
||||
|
||||
function max64(uint64 a, uint64 b) internal constant returns (uint64) {
|
||||
return a >= b ? a : b;
|
||||
}
|
||||
|
||||
function min64(uint64 a, uint64 b) internal constant returns (uint64) {
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
function max256(uint256 a, uint256 b) internal constant returns (uint256) {
|
||||
return a >= b ? a : b;
|
||||
}
|
||||
|
||||
function min256(uint256 a, uint256 b) internal constant returns (uint256) {
|
||||
return a < b ? a : b;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
pragma solidity 0.4.11;
|
||||
pragma solidity ^0.4.11;
|
||||
|
||||
/// @title Multisignature wallet - Allows multiple parties to agree on transactions before execution.
|
||||
/// @author Stefan George - <stefan.george@consensys.net>
|
||||
@@ -16,9 +16,9 @@
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.4.11;
|
||||
pragma solidity ^0.4.11;
|
||||
|
||||
import "./base/MultiSigWallet.sol";
|
||||
import "./MultiSigWallet.sol";
|
||||
|
||||
/// @title Multisignature wallet with time lock- Allows multiple parties to execute a transaction after a time lock has passed.
|
||||
/// @author Amir Bandeali - <amir@0xProject.com>
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.4.11;
|
||||
pragma solidity ^0.4.11;
|
||||
|
||||
import "./MultiSigWalletWithTimeLock.sol";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
pragma solidity 0.4.11;
|
||||
pragma solidity ^0.4.11;
|
||||
|
||||
import "./Mintable.sol";
|
||||
import "./../base/Ownable.sol";
|
||||
import "./../lib/Ownable.sol";
|
||||
|
||||
contract DummyToken is Mintable, Ownable {
|
||||
string public name;
|
||||
@@ -21,7 +21,9 @@ contract DummyToken is Mintable, Ownable {
|
||||
balances[msg.sender] = _totalSupply;
|
||||
}
|
||||
|
||||
function setBalance(address _target, uint _value) onlyOwner {
|
||||
function setBalance(address _target, uint _value)
|
||||
onlyOwner
|
||||
{
|
||||
uint currBalance = balanceOf(_target);
|
||||
if (_value < currBalance) {
|
||||
totalSupply = safeSub(totalSupply, safeSub(currBalance, _value));
|
||||
|
||||
37
packages/contracts/contracts/test/DummyToken_v2.sol
Normal file
37
packages/contracts/contracts/test/DummyToken_v2.sol
Normal file
@@ -0,0 +1,37 @@
|
||||
pragma solidity 0.4.18;
|
||||
|
||||
import "./Mintable_v2.sol";
|
||||
import "./../lib/Ownable_v2.sol";
|
||||
|
||||
contract DummyToken_v2 is Mintable_v2, Ownable_v2 {
|
||||
string public name;
|
||||
string public symbol;
|
||||
uint public decimals;
|
||||
|
||||
function DummyToken(
|
||||
string _name,
|
||||
string _symbol,
|
||||
uint _decimals,
|
||||
uint _totalSupply)
|
||||
public
|
||||
{
|
||||
name = _name;
|
||||
symbol = _symbol;
|
||||
decimals = _decimals;
|
||||
totalSupply = _totalSupply;
|
||||
balances[msg.sender] = _totalSupply;
|
||||
}
|
||||
|
||||
function setBalance(address _target, uint _value)
|
||||
public
|
||||
onlyOwner
|
||||
{
|
||||
uint currBalance = balanceOf(_target);
|
||||
if (_value < currBalance) {
|
||||
totalSupply = safeSub(totalSupply, safeSub(currBalance, _value));
|
||||
} else {
|
||||
totalSupply = safeAdd(totalSupply, safeSub(_value, currBalance));
|
||||
}
|
||||
balances[_target] = _value;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
pragma solidity 0.4.11;
|
||||
pragma solidity ^0.4.11;
|
||||
|
||||
import "./../base/StandardToken.sol";
|
||||
import "./../tokens/StandardToken.sol";
|
||||
|
||||
contract MaliciousToken is StandardToken {
|
||||
uint8 stateToUpdate = 1; // Not null so that change only requires 5000 gas
|
||||
|
||||
function updateState() internal {
|
||||
function updateState()
|
||||
internal
|
||||
{
|
||||
stateToUpdate++;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
pragma solidity 0.4.11;
|
||||
pragma solidity ^0.4.11;
|
||||
|
||||
import "./../tokens/ERC20Token.sol";
|
||||
import "./../base/SafeMath.sol";
|
||||
import "./../tokens/UnlimitedAllowanceToken.sol";
|
||||
import "./../lib/SafeMath.sol";
|
||||
|
||||
/*
|
||||
* Mintable
|
||||
* Base contract that creates a mintable UnlimitedAllowanceToken
|
||||
*/
|
||||
contract Mintable is ERC20Token, SafeMath {
|
||||
function mint(uint _value) {
|
||||
contract Mintable is UnlimitedAllowanceToken, SafeMath {
|
||||
function mint(uint _value)
|
||||
public
|
||||
{
|
||||
require(_value <= 100000000000000000000);
|
||||
balances[msg.sender] = safeAdd(_value, balances[msg.sender]);
|
||||
totalSupply = safeAdd(totalSupply, _value);
|
||||
|
||||
18
packages/contracts/contracts/test/Mintable_v2.sol
Normal file
18
packages/contracts/contracts/test/Mintable_v2.sol
Normal file
@@ -0,0 +1,18 @@
|
||||
pragma solidity 0.4.18;
|
||||
|
||||
import "./../tokens/ERC20Token.sol";
|
||||
import "./../lib/SafeMath_v2.sol";
|
||||
|
||||
/*
|
||||
* Mintable
|
||||
* Base contract that creates a mintable UnlimitedAllowanceToken
|
||||
*/
|
||||
contract Mintable_v2 is ERC20Token, SafeMath_v2 {
|
||||
function mint(uint _value)
|
||||
public
|
||||
{
|
||||
require(_value <= 100000000000000000000);
|
||||
balances[msg.sender] = safeAdd(_value, balances[msg.sender]);
|
||||
totalSupply = safeAdd(totalSupply, _value);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,15 @@
|
||||
pragma solidity 0.4.11;
|
||||
pragma solidity ^0.4.18;
|
||||
|
||||
import "./../base/Token.sol";
|
||||
import "./Token_v2.sol";
|
||||
|
||||
contract ERC20Token is Token {
|
||||
contract ERC20Token is Token_v2 {
|
||||
|
||||
uint constant MAX_UINT = 2**256 - 1;
|
||||
|
||||
function transfer(address _to, uint _value) returns (bool) {
|
||||
function transfer(address _to, uint _value)
|
||||
public
|
||||
returns (bool)
|
||||
{
|
||||
require(balances[msg.sender] >= _value && balances[_to] + _value >= balances[_to]);
|
||||
balances[msg.sender] -= _value;
|
||||
balances[_to] += _value;
|
||||
@@ -19,7 +22,10 @@ contract ERC20Token is Token {
|
||||
/// @param _to Address to transfer to.
|
||||
/// @param _value Amount to transfer.
|
||||
/// @return Success of transfer.
|
||||
function transferFrom(address _from, address _to, uint _value) returns (bool) {
|
||||
function transferFrom(address _from, address _to, uint _value)
|
||||
public
|
||||
returns (bool)
|
||||
{
|
||||
uint allowance = allowed[_from][msg.sender];
|
||||
require(balances[_from] >= _value && allowance >= _value && balances[_to] + _value >= balances[_to]);
|
||||
balances[_to] += _value;
|
||||
@@ -31,17 +37,28 @@ contract ERC20Token is Token {
|
||||
return true;
|
||||
}
|
||||
|
||||
function balanceOf(address _owner) constant returns (uint) {
|
||||
return balances[_owner];
|
||||
}
|
||||
|
||||
function approve(address _spender, uint _value) returns (bool) {
|
||||
function approve(address _spender, uint _value)
|
||||
public
|
||||
returns (bool)
|
||||
{
|
||||
allowed[msg.sender][_spender] = _value;
|
||||
Approval(msg.sender, _spender, _value);
|
||||
return true;
|
||||
}
|
||||
|
||||
function allowance(address _owner, address _spender) constant returns (uint) {
|
||||
function balanceOf(address _owner)
|
||||
public
|
||||
view
|
||||
returns (uint)
|
||||
{
|
||||
return balances[_owner];
|
||||
}
|
||||
|
||||
function allowance(address _owner, address _spender)
|
||||
public
|
||||
view
|
||||
returns (uint)
|
||||
{
|
||||
return allowed[_owner][_spender];
|
||||
}
|
||||
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.4.11;
|
||||
pragma solidity ^0.4.11;
|
||||
|
||||
import "./../tokens/UnlimitedAllowanceToken.sol";
|
||||
import "./../base/SafeMath.sol";
|
||||
import ".//UnlimitedAllowanceToken.sol";
|
||||
import "./../lib/SafeMath.sol";
|
||||
|
||||
contract EtherToken is UnlimitedAllowanceToken, SafeMath {
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.4.11;
|
||||
pragma solidity 0.4.18;
|
||||
|
||||
import "./../tokens/ERC20Token.sol";
|
||||
import "./../base/SafeMath.sol";
|
||||
import "./ERC20Token.sol";
|
||||
import "./../lib/SafeMath_v2.sol";
|
||||
|
||||
contract EtherToken_v2 is ERC20Token, SafeMath {
|
||||
contract EtherToken_v2 is ERC20Token, SafeMath_v2 {
|
||||
|
||||
string constant public name = "Ether Token";
|
||||
string constant public symbol = "WETH";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
pragma solidity 0.4.11;
|
||||
pragma solidity ^0.4.11;
|
||||
|
||||
import "./Token.sol";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
pragma solidity 0.4.11;
|
||||
pragma solidity ^0.4.11;
|
||||
|
||||
contract Token {
|
||||
|
||||
@@ -35,4 +35,4 @@ contract Token {
|
||||
|
||||
event Transfer(address indexed _from, address indexed _to, uint _value);
|
||||
event Approval(address indexed _owner, address indexed _spender, uint _value);
|
||||
}
|
||||
}
|
||||
38
packages/contracts/contracts/tokens/Token_v2.sol
Normal file
38
packages/contracts/contracts/tokens/Token_v2.sol
Normal file
@@ -0,0 +1,38 @@
|
||||
pragma solidity 0.4.18;
|
||||
|
||||
contract Token_v2 {
|
||||
|
||||
/// @return total amount of tokens
|
||||
function totalSupply() public view returns (uint) {}
|
||||
|
||||
/// @notice send `_value` token to `_to` from `msg.sender`
|
||||
/// @param _to The address of the recipient
|
||||
/// @param _value The amount of token to be transferred
|
||||
/// @return Whether the transfer was successful or not
|
||||
function transfer(address _to, uint _value) public returns (bool) {}
|
||||
|
||||
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
|
||||
/// @param _from The address of the sender
|
||||
/// @param _to The address of the recipient
|
||||
/// @param _value The amount of token to be transferred
|
||||
/// @return Whether the transfer was successful or not
|
||||
function transferFrom(address _from, address _to, uint _value) public returns (bool) {}
|
||||
|
||||
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
|
||||
/// @param _spender The address of the account able to transfer the tokens
|
||||
/// @param _value The amount of wei to be approved for transfer
|
||||
/// @return Whether the approval was successful or not
|
||||
function approve(address _spender, uint _value) public returns (bool) {}
|
||||
|
||||
/// @param _owner The address from which the balance will be retrieved
|
||||
/// @return The balance
|
||||
function balanceOf(address _owner) public view returns (uint) {}
|
||||
|
||||
/// @param _owner The address of the account owning tokens
|
||||
/// @param _spender The address of the account able to transfer the tokens
|
||||
/// @return Amount of remaining tokens allowed to spent
|
||||
function allowance(address _owner, address _spender) public view returns (uint) {}
|
||||
|
||||
event Transfer(address indexed _from, address indexed _to, uint _value);
|
||||
event Approval(address indexed _owner, address indexed _spender, uint _value);
|
||||
}
|
||||
@@ -16,9 +16,9 @@
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.4.11;
|
||||
pragma solidity ^0.4.11;
|
||||
|
||||
import "./../base/StandardToken.sol";
|
||||
import "./StandardToken.sol";
|
||||
|
||||
contract UnlimitedAllowanceToken is StandardToken {
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.4.11;
|
||||
pragma solidity ^0.4.11;
|
||||
|
||||
import "./UnlimitedAllowanceToken.sol";
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
"dirty-chai": "^2.0.1",
|
||||
"mocha": "^4.0.1",
|
||||
"solc": "^0.4.18",
|
||||
"truffle": "3.4.3",
|
||||
"truffle": "^4.0.1",
|
||||
"tslint": "5.8.0",
|
||||
"types-bn": "^0.0.1",
|
||||
"types-ethereumjs-util": "0xProject/types-ethereumjs-util",
|
||||
|
||||
@@ -9,7 +9,7 @@ import {ContractInstance} from '../../util/types';
|
||||
|
||||
import {chaiSetup} from './utils/chai_setup';
|
||||
|
||||
const {DummyToken} = new Artifacts(artifacts);
|
||||
const {DummyTokenV2} = new Artifacts(artifacts);
|
||||
const web3: Web3 = (global as any).web3;
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
@@ -24,7 +24,7 @@ contract('ERC20Token', (accounts: string[]) => {
|
||||
let token: ContractInstance;
|
||||
|
||||
beforeEach(async () => {
|
||||
token = await DummyToken.new({from: owner});
|
||||
token = await DummyTokenV2.new({from: owner});
|
||||
await token.mint(MAX_MINT_VALUE, {from: owner});
|
||||
tokenAddress = token.address;
|
||||
});
|
||||
@@ -33,7 +33,7 @@ contract('ERC20Token', (accounts: string[]) => {
|
||||
it('should throw if owner has insufficient balance', async () => {
|
||||
const ownerBalance = await zeroEx.token.getBalanceAsync(tokenAddress, owner);
|
||||
const amountToTransfer = ownerBalance.plus(1);
|
||||
return expect(token.transfer.call(owner, spender, amountToTransfer, {from: spender}))
|
||||
return expect(token.transfer.call(spender, amountToTransfer, {from: owner}))
|
||||
.to.be.rejectedWith(constants.REVERT);
|
||||
});
|
||||
|
||||
|
||||
@@ -610,7 +610,7 @@ contract('Exchange', (accounts: string[]) => {
|
||||
});
|
||||
|
||||
return expect(exWrapper.fillOrderAsync(order, taker, {shouldThrowOnInsufficientBalanceOrAllowance: false}))
|
||||
.to.be.rejectedWith(constants.INVALID_OPCODE);
|
||||
.to.be.rejectedWith(constants.REVERT);
|
||||
});
|
||||
|
||||
it('should not change balances if an order is expired', async () => {
|
||||
|
||||
@@ -6,6 +6,7 @@ export class Artifacts {
|
||||
public Exchange: any;
|
||||
public ZRXToken: any;
|
||||
public DummyToken: any;
|
||||
public DummyTokenV2: any;
|
||||
public EtherToken: any;
|
||||
public EtherTokenV2: any;
|
||||
public MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress: any;
|
||||
@@ -18,6 +19,7 @@ export class Artifacts {
|
||||
this.Exchange = artifacts.require('Exchange');
|
||||
this.ZRXToken = artifacts.require('ZRXToken');
|
||||
this.DummyToken = artifacts.require('DummyToken');
|
||||
this.DummyTokenV2 = artifacts.require('DummyToken_v2');
|
||||
this.EtherToken = artifacts.require('EtherToken');
|
||||
this.EtherTokenV2 = artifacts.require('EtherToken_v2');
|
||||
this.MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress = artifacts.require(
|
||||
|
||||
Reference in New Issue
Block a user