diff options
author | Amir Bandeali <abandeali1@gmail.com> | 2017-12-07 12:46:53 +0800 |
---|---|---|
committer | Amir Bandeali <abandeali1@gmail.com> | 2017-12-13 07:02:05 +0800 |
commit | 548fda8dbaadc4827137d4b90753b306fdfd554b (patch) | |
tree | 7a2dc681b61394a5c6bf0731272acc2109ad7b51 /packages | |
parent | b58bf8259db7378b841e6695d99580027b4e2969 (diff) | |
download | dexon-sol-tools-548fda8dbaadc4827137d4b90753b306fdfd554b.tar.gz dexon-sol-tools-548fda8dbaadc4827137d4b90753b306fdfd554b.tar.zst dexon-sol-tools-548fda8dbaadc4827137d4b90753b306fdfd554b.zip |
Add updated contracts, reorganize contract file structure
Diffstat (limited to 'packages')
25 files changed, 170 insertions, 120 deletions
diff --git a/packages/contracts/contracts/Exchange.sol b/packages/contracts/contracts/Exchange.sol index 02deee967..2f734fb20 100644 --- a/packages/contracts/contracts/Exchange.sol +++ b/packages/contracts/contracts/Exchange.sol @@ -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> diff --git a/packages/contracts/contracts/TokenRegistry.sol b/packages/contracts/contracts/TokenRegistry.sol index d370f8cfe..c76eaea9d 100644 --- a/packages/contracts/contracts/TokenRegistry.sol +++ b/packages/contracts/contracts/TokenRegistry.sol @@ -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> diff --git a/packages/contracts/contracts/TokenTransferProxy.sol b/packages/contracts/contracts/TokenTransferProxy.sol index 23b0b9e6d..81ada804d 100644 --- a/packages/contracts/contracts/TokenTransferProxy.sol +++ b/packages/contracts/contracts/TokenTransferProxy.sol @@ -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> diff --git a/packages/contracts/contracts/base/Ownable.sol b/packages/contracts/contracts/base/Ownable.sol deleted file mode 100644 index b7d6ac71c..000000000 --- a/packages/contracts/contracts/base/Ownable.sol +++ /dev/null @@ -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; - } - } -} diff --git a/packages/contracts/contracts/base/SafeMath.sol b/packages/contracts/contracts/base/SafeMath.sol deleted file mode 100644 index fac674a20..000000000 --- a/packages/contracts/contracts/base/SafeMath.sol +++ /dev/null @@ -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; - } -} diff --git a/packages/contracts/contracts/base/MultiSigWallet.sol b/packages/contracts/contracts/multisig/MultiSigWallet.sol index 7531224ea..68f70fe83 100644 --- a/packages/contracts/contracts/base/MultiSigWallet.sol +++ b/packages/contracts/contracts/multisig/MultiSigWallet.sol @@ -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> diff --git a/packages/contracts/contracts/MultiSigWalletWithTimeLock.sol b/packages/contracts/contracts/multisig/MultiSigWalletWithTimeLock.sol index 70123e6b6..ed625f7f7 100644 --- a/packages/contracts/contracts/MultiSigWalletWithTimeLock.sol +++ b/packages/contracts/contracts/multisig/MultiSigWalletWithTimeLock.sol @@ -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> diff --git a/packages/contracts/contracts/MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress.sol b/packages/contracts/contracts/multisig/MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress.sol index 15fdb1d07..5c1620808 100644 --- a/packages/contracts/contracts/MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress.sol +++ b/packages/contracts/contracts/multisig/MultiSigWalletWithTimeLockExceptRemoveAuthorizedAddress.sol @@ -16,7 +16,7 @@ */ -pragma solidity 0.4.11; +pragma solidity ^0.4.11; import "./MultiSigWalletWithTimeLock.sol"; diff --git a/packages/contracts/contracts/test/DummyToken.sol b/packages/contracts/contracts/test/DummyToken.sol index 414c17b2a..cf8c27201 100644 --- a/packages/contracts/contracts/test/DummyToken.sol +++ b/packages/contracts/contracts/test/DummyToken.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)); diff --git a/packages/contracts/contracts/test/DummyToken_v2.sol b/packages/contracts/contracts/test/DummyToken_v2.sol new file mode 100644 index 000000000..24c604369 --- /dev/null +++ b/packages/contracts/contracts/test/DummyToken_v2.sol @@ -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; + } +} diff --git a/packages/contracts/contracts/test/MaliciousToken.sol b/packages/contracts/contracts/test/MaliciousToken.sol index 3c1a53612..9e1322984 100644 --- a/packages/contracts/contracts/test/MaliciousToken.sol +++ b/packages/contracts/contracts/test/MaliciousToken.sol @@ -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++; } diff --git a/packages/contracts/contracts/test/Mintable.sol b/packages/contracts/contracts/test/Mintable.sol index 257dca705..34c9eb858 100644 --- a/packages/contracts/contracts/test/Mintable.sol +++ b/packages/contracts/contracts/test/Mintable.sol @@ -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); diff --git a/packages/contracts/contracts/test/Mintable_v2.sol b/packages/contracts/contracts/test/Mintable_v2.sol new file mode 100644 index 000000000..95e2fcfe3 --- /dev/null +++ b/packages/contracts/contracts/test/Mintable_v2.sol @@ -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); + } +} diff --git a/packages/contracts/contracts/tokens/ERC20Token.sol b/packages/contracts/contracts/tokens/ERC20Token.sol index 8db58c707..4596331c1 100644 --- a/packages/contracts/contracts/tokens/ERC20Token.sol +++ b/packages/contracts/contracts/tokens/ERC20Token.sol @@ -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]; } diff --git a/packages/contracts/contracts/deprecated/EtherToken.sol b/packages/contracts/contracts/tokens/EtherToken.sol index 566782e35..900b95337 100644 --- a/packages/contracts/contracts/deprecated/EtherToken.sol +++ b/packages/contracts/contracts/tokens/EtherToken.sol @@ -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 { diff --git a/packages/contracts/contracts/tokens/EtherToken_v2.sol b/packages/contracts/contracts/tokens/EtherToken_v2.sol index 0c7acf8a0..fe6b64266 100644 --- a/packages/contracts/contracts/tokens/EtherToken_v2.sol +++ b/packages/contracts/contracts/tokens/EtherToken_v2.sol @@ -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"; diff --git a/packages/contracts/contracts/base/StandardToken.sol b/packages/contracts/contracts/tokens/StandardToken.sol index e0719d89a..0e5c33a3a 100644 --- a/packages/contracts/contracts/base/StandardToken.sol +++ b/packages/contracts/contracts/tokens/StandardToken.sol @@ -1,4 +1,4 @@ -pragma solidity 0.4.11; +pragma solidity ^0.4.11; import "./Token.sol"; diff --git a/packages/contracts/contracts/base/Token.sol b/packages/contracts/contracts/tokens/Token.sol index c6a55c2c0..10c6c41c1 100644 --- a/packages/contracts/contracts/base/Token.sol +++ b/packages/contracts/contracts/tokens/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); -} +}
\ No newline at end of file diff --git a/packages/contracts/contracts/tokens/Token_v2.sol b/packages/contracts/contracts/tokens/Token_v2.sol new file mode 100644 index 000000000..bd46dec2b --- /dev/null +++ b/packages/contracts/contracts/tokens/Token_v2.sol @@ -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); +} diff --git a/packages/contracts/contracts/tokens/UnlimitedAllowanceToken.sol b/packages/contracts/contracts/tokens/UnlimitedAllowanceToken.sol index 40e01b360..035993990 100644 --- a/packages/contracts/contracts/tokens/UnlimitedAllowanceToken.sol +++ b/packages/contracts/contracts/tokens/UnlimitedAllowanceToken.sol @@ -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 { diff --git a/packages/contracts/contracts/tokens/ZRXToken.sol b/packages/contracts/contracts/tokens/ZRXToken.sol index c8b9c08ab..9456d1649 100644 --- a/packages/contracts/contracts/tokens/ZRXToken.sol +++ b/packages/contracts/contracts/tokens/ZRXToken.sol @@ -16,7 +16,7 @@ */ -pragma solidity 0.4.11; +pragma solidity ^0.4.11; import "./UnlimitedAllowanceToken.sol"; diff --git a/packages/contracts/package.json b/packages/contracts/package.json index 46bf4f731..3c5dfe890 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -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", diff --git a/packages/contracts/test/ts/erc20Token.ts b/packages/contracts/test/ts/erc20Token.ts index e2282cbf3..9aa93180b 100644 --- a/packages/contracts/test/ts/erc20Token.ts +++ b/packages/contracts/test/ts/erc20Token.ts @@ -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); }); diff --git a/packages/contracts/test/ts/exchange/core.ts b/packages/contracts/test/ts/exchange/core.ts index e4aa74c32..7f632c6e6 100644 --- a/packages/contracts/test/ts/exchange/core.ts +++ b/packages/contracts/test/ts/exchange/core.ts @@ -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 () => { diff --git a/packages/contracts/util/artifacts.ts b/packages/contracts/util/artifacts.ts index cb06739af..6b05df78c 100644 --- a/packages/contracts/util/artifacts.ts +++ b/packages/contracts/util/artifacts.ts @@ -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( |