From b06ba55be31ff88591e3be18acdea053de3cf3f6 Mon Sep 17 00:00:00 2001 From: Remco Bloemen Date: Tue, 6 Feb 2018 11:46:00 -0800 Subject: Add interfaces for Exchange, TokenRegistery and TokenTransferProxy --- .../current/protocol/Exchange/IExchange.sol | 226 +++++++++++++++++++++ .../protocol/TokenRegistry/ITokenRegistery.sol | 195 ++++++++++++++++++ .../TokenTransferProxy/ITokenTransferProxy.sol | 72 +++++++ .../src/contracts/previous/Ownable/IOwnable_v1.sol | 18 ++ .../src/contracts/previous/Token/IToken_v1.sol | 52 +++++ 5 files changed, 563 insertions(+) create mode 100644 packages/contracts/src/contracts/current/protocol/Exchange/IExchange.sol create mode 100644 packages/contracts/src/contracts/current/protocol/TokenRegistry/ITokenRegistery.sol create mode 100644 packages/contracts/src/contracts/current/protocol/TokenTransferProxy/ITokenTransferProxy.sol create mode 100644 packages/contracts/src/contracts/previous/Ownable/IOwnable_v1.sol create mode 100644 packages/contracts/src/contracts/previous/Token/IToken_v1.sol (limited to 'packages/contracts') diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/IExchange.sol b/packages/contracts/src/contracts/current/protocol/Exchange/IExchange.sol new file mode 100644 index 000000000..b899eb105 --- /dev/null +++ b/packages/contracts/src/contracts/current/protocol/Exchange/IExchange.sol @@ -0,0 +1,226 @@ +pragma solidity ^0.4.19; + +contract IExchange { + + // Error Codes + enum Errors { + ORDER_EXPIRED, // Order has already expired + ORDER_FULLY_FILLED_OR_CANCELLED, // Order has already been fully filled or cancelled + ROUNDING_ERROR_TOO_LARGE, // Rounding error too large + INSUFFICIENT_BALANCE_OR_ALLOWANCE // Insufficient balance or allowance for token transfer + } + + event LogError(uint8 indexed errorId, bytes32 indexed orderHash); + + event LogFill( + address indexed maker, + address taker, + address indexed feeRecipient, + address makerToken, + address takerToken, + uint filledMakerTokenAmount, + uint filledTakerTokenAmount, + uint paidMakerFee, + uint paidTakerFee, + bytes32 indexed tokens, // keccak256(makerToken, takerToken), allows subscribing to a token pair + bytes32 orderHash + ); + + event LogCancel( + address indexed maker, + address indexed feeRecipient, + address makerToken, + address takerToken, + uint cancelledMakerTokenAmount, + uint cancelledTakerTokenAmount, + bytes32 indexed tokens, + bytes32 orderHash + ); + + function ZRX_TOKEN_CONTRACT() + public view + returns (address); + + function TOKEN_TRANSFER_PROXY_CONTRACT() + public view + returns (address); + + function EXTERNAL_QUERY_GAS_LIMIT() + public view + returns (uint16); + + function VERSION() + public view + returns (string); + + function filled(bytes32) + public view + returns (uint256); + + function cancelled(bytes32) + public view + returns (uint256); + + /// @dev Calculates the sum of values already filled and cancelled for a given order. + /// @param orderHash The Keccak-256 hash of the given order. + /// @return Sum of values already filled and cancelled. + function getUnavailableTakerTokenAmount(bytes32 orderHash) + public constant + returns (uint); + + /// @dev Calculates partial value given a numerator and denominator. + /// @param numerator Numerator. + /// @param denominator Denominator. + /// @param target Value to calculate partial of. + /// @return Partial value of target. + function getPartialAmount(uint numerator, uint denominator, uint target) + public constant + returns (uint); + + /// @dev Checks if rounding error > 0.1%. + /// @param numerator Numerator. + /// @param denominator Denominator. + /// @param target Value to multiply with numerator/denominator. + /// @return Rounding error is present. + function isRoundingError(uint numerator, uint denominator, uint target) + public constant + returns (bool); + + /// @dev Calculates Keccak-256 hash of order with specified parameters. + /// @param orderAddresses Array of order's maker, taker, makerToken, takerToken, and feeRecipient. + /// @param orderValues Array of order's makerTokenAmount, takerTokenAmount, makerFee, takerFee, expirationTimestampInSec, and salt. + /// @return Keccak-256 hash of order. + function getOrderHash(address[5] orderAddresses, uint[6] orderValues) + public + constant + returns (bytes32); + + /// @dev Verifies that an order signature is valid. + /// @param signer address of signer. + /// @param hash Signed Keccak-256 hash. + /// @param v ECDSA signature parameter v. + /// @param r ECDSA signature parameters r. + /// @param s ECDSA signature parameters s. + /// @return Validity of order signature. + function isValidSignature( + address signer, + bytes32 hash, + uint8 v, + bytes32 r, + bytes32 s) + public constant + returns (bool); + + /// @dev Fills the input order. + /// @param orderAddresses Array of order's maker, taker, makerToken, takerToken, and feeRecipient. + /// @param orderValues Array of order's makerTokenAmount, takerTokenAmount, makerFee, takerFee, expirationTimestampInSec, and salt. + /// @param fillTakerTokenAmount Desired amount of takerToken to fill. + /// @param shouldThrowOnInsufficientBalanceOrAllowance Test if transfer will fail before attempting. + /// @param v ECDSA signature parameter v. + /// @param r ECDSA signature parameters r. + /// @param s ECDSA signature parameters s. + /// @return Total amount of takerToken filled in trade. + function fillOrder( + address[5] orderAddresses, + uint[6] orderValues, + uint fillTakerTokenAmount, + bool shouldThrowOnInsufficientBalanceOrAllowance, + uint8 v, + bytes32 r, + bytes32 s) + public + returns (uint filledTakerTokenAmount); + + /// @dev Cancels the input order. + /// @param orderAddresses Array of order's maker, taker, makerToken, takerToken, and feeRecipient. + /// @param orderValues Array of order's makerTokenAmount, takerTokenAmount, makerFee, takerFee, expirationTimestampInSec, and salt. + /// @param cancelTakerTokenAmount Desired amount of takerToken to cancel in order. + /// @return Amount of takerToken cancelled. + function cancelOrder( + address[5] orderAddresses, + uint[6] orderValues, + uint cancelTakerTokenAmount) + public + returns (uint); + + + /// @dev Fills an order with specified parameters and ECDSA signature, throws if specified amount not filled entirely. + /// @param orderAddresses Array of order's maker, taker, makerToken, takerToken, and feeRecipient. + /// @param orderValues Array of order's makerTokenAmount, takerTokenAmount, makerFee, takerFee, expirationTimestampInSec, and salt. + /// @param fillTakerTokenAmount Desired amount of takerToken to fill. + /// @param v ECDSA signature parameter v. + /// @param r ECDSA signature parameters r. + /// @param s ECDSA signature parameters s. + function fillOrKillOrder( + address[5] orderAddresses, + uint[6] orderValues, + uint fillTakerTokenAmount, + uint8 v, + bytes32 r, + bytes32 s) + public; + + /// @dev Synchronously executes multiple fill orders in a single transaction. + /// @param orderAddresses Array of address arrays containing individual order addresses. + /// @param orderValues Array of uint arrays containing individual order values. + /// @param fillTakerTokenAmounts Array of desired amounts of takerToken to fill in orders. + /// @param shouldThrowOnInsufficientBalanceOrAllowance Test if transfers will fail before attempting. + /// @param v Array ECDSA signature v parameters. + /// @param r Array of ECDSA signature r parameters. + /// @param s Array of ECDSA signature s parameters. + function batchFillOrders( + address[5][] orderAddresses, + uint[6][] orderValues, + uint[] fillTakerTokenAmounts, + bool shouldThrowOnInsufficientBalanceOrAllowance, + uint8[] v, + bytes32[] r, + bytes32[] s) + public; + + /// @dev Synchronously executes multiple fillOrKill orders in a single transaction. + /// @param orderAddresses Array of address arrays containing individual order addresses. + /// @param orderValues Array of uint arrays containing individual order values. + /// @param fillTakerTokenAmounts Array of desired amounts of takerToken to fill in orders. + /// @param v Array ECDSA signature v parameters. + /// @param r Array of ECDSA signature r parameters. + /// @param s Array of ECDSA signature s parameters. + function batchFillOrKillOrders( + address[5][] orderAddresses, + uint[6][] orderValues, + uint[] fillTakerTokenAmounts, + uint8[] v, + bytes32[] r, + bytes32[] s) + public; + + /// @dev Synchronously executes multiple fill orders in a single transaction until total fillTakerTokenAmount filled. + /// @param orderAddresses Array of address arrays containing individual order addresses. + /// @param orderValues Array of uint arrays containing individual order values. + /// @param fillTakerTokenAmount Desired total amount of takerToken to fill in orders. + /// @param shouldThrowOnInsufficientBalanceOrAllowance Test if transfers will fail before attempting. + /// @param v Array ECDSA signature v parameters. + /// @param r Array of ECDSA signature r parameters. + /// @param s Array of ECDSA signature s parameters. + /// @return Total amount of fillTakerTokenAmount filled in orders. + function fillOrdersUpTo( + address[5][] orderAddresses, + uint[6][] orderValues, + uint fillTakerTokenAmount, + bool shouldThrowOnInsufficientBalanceOrAllowance, + uint8[] v, + bytes32[] r, + bytes32[] s) + public + returns (uint); + + /// @dev Synchronously cancels multiple orders in a single transaction. + /// @param orderAddresses Array of address arrays containing individual order addresses. + /// @param orderValues Array of uint arrays containing individual order values. + /// @param cancelTakerTokenAmounts Array of desired amounts of takerToken to cancel in orders. + function batchCancelOrders( + address[5][] orderAddresses, + uint[6][] orderValues, + uint[] cancelTakerTokenAmounts) + public; +} diff --git a/packages/contracts/src/contracts/current/protocol/TokenRegistry/ITokenRegistery.sol b/packages/contracts/src/contracts/current/protocol/TokenRegistry/ITokenRegistery.sol new file mode 100644 index 000000000..7220444f2 --- /dev/null +++ b/packages/contracts/src/contracts/current/protocol/TokenRegistry/ITokenRegistery.sol @@ -0,0 +1,195 @@ +/* + + Copyright 2017 ZeroEx Intl. + + 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. + +*/ + +pragma solidity ^0.4.19; + +import { IOwnable_v1 as IOwnable } from "../../../previous/Ownable/IOwnable_v1.sol"; + +/// @title Token Registry - Stores metadata associated with ERC20 tokens. See ERC22 https://github.com/ethereum/EIPs/issues/22 +/// @author Amir Bandeali - , Will Warren - +contract ITokenRegistery is IOwnable { + + event LogAddToken( + address indexed token, + string name, + string symbol, + uint8 decimals, + bytes ipfsHash, + bytes swarmHash + ); + + event LogRemoveToken( + address indexed token, + string name, + string symbol, + uint8 decimals, + bytes ipfsHash, + bytes swarmHash + ); + + event LogTokenNameChange( + address indexed token, + string oldName, + string newName + ); + + event LogTokenSymbolChange( + address indexed token, + string oldSymbol, + string newSymbol + ); + + event LogTokenIpfsHashChange( + address indexed token, + bytes oldIpfsHash, + bytes newIpfsHash + ); + + event LogTokenSwarmHashChange( + address indexed token, + bytes oldSwarmHash, + bytes newSwarmHash + ); + + function tokens(address tokenAddress) + public view + returns ( + address token, + string name, + string symbol, + uint8 decimals, + bytes ipfsHash, + bytes swarmHash + ); + + function tokenAddresses(uint256 index) + public view + returns (address); + + + /// @dev Allows owner to add a new token to the registry. + /// @param _token Address of new token. + /// @param _name Name of new token. + /// @param _symbol Symbol for new token. + /// @param _decimals Number of decimals, divisibility of new token. + /// @param _ipfsHash IPFS hash of token icon. + /// @param _swarmHash Swarm hash of token icon. + function addToken( + address _token, + string _name, + string _symbol, + uint8 _decimals, + bytes _ipfsHash, + bytes _swarmHash) + public; + + /// @dev Allows owner to remove an existing token from the registry. + /// @param _token Address of existing token. + function removeToken(address _token, uint _index) + public; + + /// @dev Allows owner to modify an existing token's name. + /// @param _token Address of existing token. + /// @param _name New name. + function setTokenName(address _token, string _name) + public; + + /// @dev Allows owner to modify an existing token's symbol. + /// @param _token Address of existing token. + /// @param _symbol New symbol. + function setTokenSymbol(address _token, string _symbol) + public; + + /// @dev Allows owner to modify an existing token's IPFS hash. + /// @param _token Address of existing token. + /// @param _ipfsHash New IPFS hash. + function setTokenIpfsHash(address _token, bytes _ipfsHash) + public; + + /// @dev Allows owner to modify an existing token's Swarm hash. + /// @param _token Address of existing token. + /// @param _swarmHash New Swarm hash. + function setTokenSwarmHash(address _token, bytes _swarmHash) + public; + + /* + * Web3 call functions + */ + + /// @dev Provides a registered token's address when given the token symbol. + /// @param _symbol Symbol of registered token. + /// @return Token's address. + function getTokenAddressBySymbol(string _symbol) + public constant + returns (address); + + /// @dev Provides a registered token's address when given the token name. + /// @param _name Name of registered token. + /// @return Token's address. + function getTokenAddressByName(string _name) + public constant + returns (address); + + /// @dev Provides a registered token's metadata, looked up by address. + /// @param _token Address of registered token. + /// @return Token metadata. + function getTokenMetaData(address _token) + public constant + returns ( + address, //tokenAddress + string, //name + string, //symbol + uint8, //decimals + bytes, //ipfsHash + bytes //swarmHash + ); + + /// @dev Provides a registered token's metadata, looked up by name. + /// @param _name Name of registered token. + /// @return Token metadata. + function getTokenByName(string _name) + public constant + returns ( + address, //tokenAddress + string, //name + string, //symbol + uint8, //decimals + bytes, //ipfsHash + bytes //swarmHash + ); + + /// @dev Provides a registered token's metadata, looked up by symbol. + /// @param _symbol Symbol of registered token. + /// @return Token metadata. + function getTokenBySymbol(string _symbol) + public constant + returns ( + address, //tokenAddress + string, //name + string, //symbol + uint8, //decimals + bytes, //ipfsHash + bytes //swarmHash + ); + + /// @dev Returns an array containing all token addresses. + /// @return Array of token addresses. + function getTokenAddresses() + public constant + returns (address[]); +} diff --git a/packages/contracts/src/contracts/current/protocol/TokenTransferProxy/ITokenTransferProxy.sol b/packages/contracts/src/contracts/current/protocol/TokenTransferProxy/ITokenTransferProxy.sol new file mode 100644 index 000000000..9f2ec551d --- /dev/null +++ b/packages/contracts/src/contracts/current/protocol/TokenTransferProxy/ITokenTransferProxy.sol @@ -0,0 +1,72 @@ +/* + + Copyright 2017 ZeroEx Intl. + + 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. + +*/ + +pragma solidity ^0.4.19; + +import { IOwnable_v1 as IOwnable } from "../../../previous/Ownable/IOwnable_v1.sol"; + +/// @title TokenTransferProxy - Transfers tokens on behalf of contracts that have been approved via decentralized governance. +/// @author Amir Bandeali - , Will Warren - +contract ITokenTransferProxy is IOwnable { + + function authorized(address addr) + public view + returns (bool); + + function authorities(uint256 index) + public view + returns (address); + + /// @dev Gets all authorized addresses. + /// @return Array of authorized addresses. + function getAuthorizedAddresses() + public view + returns (address[]); + + /// @dev Authorizes an address. + /// @param target Address to authorize. + function addAuthorizedAddress(address target) + public; + + /// @dev Removes authorizion of an address. + /// @param target Address to remove authorization from. + function removeAuthorizedAddress(address target) + public; + + /// @dev Calls into ERC20 Token contract, invoking transferFrom. + /// @param token Address of token to transfer. + /// @param from Address to transfer token from. + /// @param to Address to transfer token to. + /// @param value Amount of token to transfer. + /// @return Success of transfer. + function transferFrom( + address token, + address from, + address to, + uint value) + public + returns (bool); + + event LogAuthorizedAddressAdded( + address indexed target, + address indexed caller); + + event LogAuthorizedAddressRemoved( + address indexed target, + address indexed caller); +} diff --git a/packages/contracts/src/contracts/previous/Ownable/IOwnable_v1.sol b/packages/contracts/src/contracts/previous/Ownable/IOwnable_v1.sol new file mode 100644 index 000000000..7e22d544d --- /dev/null +++ b/packages/contracts/src/contracts/previous/Ownable/IOwnable_v1.sol @@ -0,0 +1,18 @@ +pragma solidity ^0.4.19; + +/* + * 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 IOwnable_v1 { + + function owner() + public view + returns (address); + + function transferOwnership(address newOwner) + public; +} diff --git a/packages/contracts/src/contracts/previous/Token/IToken_v1.sol b/packages/contracts/src/contracts/previous/Token/IToken_v1.sol new file mode 100644 index 000000000..db4286964 --- /dev/null +++ b/packages/contracts/src/contracts/previous/Token/IToken_v1.sol @@ -0,0 +1,52 @@ +pragma solidity ^0.4.18; + +contract IToken_v1 { + + /// @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); +} -- cgit v1.2.3