@0x:contracts-utils Removed SafeMath and the use of the contract throughout contracts/
				
					
				
			This commit is contained in:
		@@ -19,7 +19,7 @@
 | 
			
		||||
pragma solidity ^0.5.9;
 | 
			
		||||
 | 
			
		||||
import "@0x/contracts-utils/contracts/src/LibBytes.sol";
 | 
			
		||||
import "@0x/contracts-utils/contracts/src/SafeMath.sol";
 | 
			
		||||
import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
 | 
			
		||||
import "@0x/contracts-erc1155/contracts/src/interfaces/IERC1155.sol";
 | 
			
		||||
import "../archive/MixinAuthorizable.sol";
 | 
			
		||||
import "./interfaces/IAssetProxy.sol";
 | 
			
		||||
@@ -27,10 +27,10 @@ import "./interfaces/IAssetProxy.sol";
 | 
			
		||||
 | 
			
		||||
contract ERC1155Proxy is
 | 
			
		||||
    MixinAuthorizable,
 | 
			
		||||
    SafeMath,
 | 
			
		||||
    IAssetProxy
 | 
			
		||||
{
 | 
			
		||||
    using LibBytes for bytes;
 | 
			
		||||
    using LibSafeMath for uint256;
 | 
			
		||||
 | 
			
		||||
    // Id of this proxy.
 | 
			
		||||
    bytes4 constant internal PROXY_ID = bytes4(keccak256("ERC1155Assets(address,uint256[],uint256[],bytes)"));
 | 
			
		||||
@@ -71,7 +71,7 @@ contract ERC1155Proxy is
 | 
			
		||||
            // to avoid copying over `ids` or `data`. This is possible if they are
 | 
			
		||||
            // identical to `values` and the offsets for each are pointing to the
 | 
			
		||||
            // same location in the ABI encoded calldata.
 | 
			
		||||
            scaledValues[i] = _safeMul(values[i], amount);
 | 
			
		||||
            scaledValues[i] = values[i].safeMul(amount);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Execute `safeBatchTransferFrom` call
 | 
			
		||||
 
 | 
			
		||||
@@ -18,7 +18,7 @@
 | 
			
		||||
 | 
			
		||||
pragma solidity ^0.5.9;
 | 
			
		||||
 | 
			
		||||
import "@0x/contracts-utils/contracts/src/SafeMath.sol";
 | 
			
		||||
import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
 | 
			
		||||
import "@0x/contracts-utils/contracts/src/LibAddress.sol";
 | 
			
		||||
import "./interfaces/IERC1155.sol";
 | 
			
		||||
import "./interfaces/IERC1155Receiver.sol";
 | 
			
		||||
@@ -26,11 +26,11 @@ import "./MixinNonFungibleToken.sol";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
contract ERC1155 is
 | 
			
		||||
    SafeMath,
 | 
			
		||||
    IERC1155,
 | 
			
		||||
    MixinNonFungibleToken
 | 
			
		||||
{
 | 
			
		||||
    using LibAddress for address;
 | 
			
		||||
    using LibSafeMath for uint256;
 | 
			
		||||
 | 
			
		||||
    // selectors for receiver callbacks
 | 
			
		||||
    bytes4 constant public ERC1155_RECEIVED       = 0xf23a6e61;
 | 
			
		||||
@@ -88,11 +88,11 @@ contract ERC1155 is
 | 
			
		||||
            nfOwners[id] = to;
 | 
			
		||||
            // You could keep balance of NF type in base type id like so:
 | 
			
		||||
            // uint256 baseType = getNonFungibleBaseType(_id);
 | 
			
		||||
            // balances[baseType][_from] = balances[baseType][_from]._safeSub(_value);
 | 
			
		||||
            // balances[baseType][_to]   = balances[baseType][_to]._safeAdd(_value);
 | 
			
		||||
            // balances[baseType][_from] = balances[baseType][_from].safeSub(_value);
 | 
			
		||||
            // balances[baseType][_to]   = balances[baseType][_to].safeAdd(_value);
 | 
			
		||||
        } else {
 | 
			
		||||
            balances[id][from] = _safeSub(balances[id][from], value);
 | 
			
		||||
            balances[id][to] = _safeAdd(balances[id][to], value);
 | 
			
		||||
            balances[id][from] = balances[id][from].safeSub(value);
 | 
			
		||||
            balances[id][to] = balances[id][to].safeAdd(value);
 | 
			
		||||
        }
 | 
			
		||||
        emit TransferSingle(msg.sender, from, to, id, value);
 | 
			
		||||
 | 
			
		||||
@@ -170,8 +170,8 @@ contract ERC1155 is
 | 
			
		||||
                );
 | 
			
		||||
                nfOwners[id] = to;
 | 
			
		||||
            } else {
 | 
			
		||||
                balances[id][from] = _safeSub(balances[id][from], value);
 | 
			
		||||
                balances[id][to] = _safeAdd(balances[id][to], value);
 | 
			
		||||
                balances[id][from] = balances[id][from].safeSub(value);
 | 
			
		||||
                balances[id][to] = balances[id][to].safeAdd(value);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        emit TransferBatch(msg.sender, from, to, ids, values);
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
pragma solidity ^0.5.9;
 | 
			
		||||
 | 
			
		||||
import "@0x/contracts-utils/contracts/src/SafeMath.sol";
 | 
			
		||||
import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
 | 
			
		||||
import "./ERC1155.sol";
 | 
			
		||||
import "./interfaces/IERC1155Mintable.sol";
 | 
			
		||||
 | 
			
		||||
@@ -11,6 +11,7 @@ contract ERC1155Mintable is
 | 
			
		||||
    IERC1155Mintable,
 | 
			
		||||
    ERC1155
 | 
			
		||||
{
 | 
			
		||||
    using LibSafeMath for uint256;
 | 
			
		||||
 | 
			
		||||
    /// token nonce
 | 
			
		||||
    uint256 internal nonce;
 | 
			
		||||
@@ -37,7 +38,7 @@ contract ERC1155Mintable is
 | 
			
		||||
    )
 | 
			
		||||
        external
 | 
			
		||||
        returns (uint256 type_)
 | 
			
		||||
    { 
 | 
			
		||||
    {
 | 
			
		||||
        // Store the type in the upper 128 bits
 | 
			
		||||
        type_ = (++nonce << 128);
 | 
			
		||||
 | 
			
		||||
@@ -114,7 +115,7 @@ contract ERC1155Mintable is
 | 
			
		||||
            uint256 quantity = quantities[i];
 | 
			
		||||
 | 
			
		||||
            // Grant the items to the caller
 | 
			
		||||
            balances[id][dst] = _safeAdd(quantity, balances[id][dst]);
 | 
			
		||||
            balances[id][dst] = quantity.safeAdd(balances[id][dst]);
 | 
			
		||||
 | 
			
		||||
            // Emit the Transfer/Mint event.
 | 
			
		||||
            // the 0x0 source address implies a mint
 | 
			
		||||
@@ -172,7 +173,7 @@ contract ERC1155Mintable is
 | 
			
		||||
            nfOwners[id] = dst;
 | 
			
		||||
 | 
			
		||||
            // You could use base-type id to store NF type balances if you wish.
 | 
			
		||||
            // balances[_type][dst] = quantity._safeAdd(balances[_type][dst]);
 | 
			
		||||
            // balances[_type][dst] = quantity.safeAdd(balances[_type][dst]);
 | 
			
		||||
 | 
			
		||||
            emit TransferSingle(msg.sender, address(0x0), dst, id, 1);
 | 
			
		||||
 | 
			
		||||
@@ -194,6 +195,6 @@ contract ERC1155Mintable is
 | 
			
		||||
 | 
			
		||||
        // record the `maxIndex` of this nft type
 | 
			
		||||
        // this allows us to mint more nft's of this type in a subsequent call.
 | 
			
		||||
        maxIndex[type_] = _safeAdd(to.length, maxIndex[type_]);
 | 
			
		||||
        maxIndex[type_] = to.length.safeAdd(maxIndex[type_]);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -18,22 +18,23 @@
 | 
			
		||||
 | 
			
		||||
pragma solidity ^0.5.9;
 | 
			
		||||
 | 
			
		||||
import "@0x/contracts-utils/contracts/src/SafeMath.sol";
 | 
			
		||||
import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
 | 
			
		||||
import "./UnlimitedAllowanceERC20Token.sol";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
contract MintableERC20Token is 
 | 
			
		||||
    SafeMath,
 | 
			
		||||
contract MintableERC20Token is
 | 
			
		||||
    UnlimitedAllowanceERC20Token
 | 
			
		||||
{
 | 
			
		||||
    using LibSafeMath for uint256;
 | 
			
		||||
 | 
			
		||||
    /// @dev Mints new tokens
 | 
			
		||||
    /// @param _to Address of the beneficiary that will own the minted token
 | 
			
		||||
    /// @param _value Amount of tokens to mint
 | 
			
		||||
    function _mint(address _to, uint256 _value)
 | 
			
		||||
        internal
 | 
			
		||||
    {
 | 
			
		||||
        balances[_to] = _safeAdd(_value, balances[_to]);
 | 
			
		||||
        _totalSupply = _safeAdd(_totalSupply, _value);
 | 
			
		||||
        balances[_to] = _value.safeAdd(balances[_to]);
 | 
			
		||||
        _totalSupply = _totalSupply.safeAdd(_value);
 | 
			
		||||
 | 
			
		||||
        emit Transfer(
 | 
			
		||||
            address(0),
 | 
			
		||||
@@ -48,8 +49,8 @@ contract MintableERC20Token is
 | 
			
		||||
    function _burn(address _owner, uint256 _value)
 | 
			
		||||
        internal
 | 
			
		||||
    {
 | 
			
		||||
        balances[_owner] = _safeSub(balances[_owner], _value);
 | 
			
		||||
        _totalSupply = _safeSub(_totalSupply, _value);
 | 
			
		||||
        balances[_owner] = balances[_owner].safeSub(_value);
 | 
			
		||||
        _totalSupply = _totalSupply.safeSub(_value);
 | 
			
		||||
 | 
			
		||||
        emit Transfer(
 | 
			
		||||
            _owner,
 | 
			
		||||
 
 | 
			
		||||
@@ -18,14 +18,17 @@
 | 
			
		||||
 | 
			
		||||
pragma solidity ^0.5.5;
 | 
			
		||||
 | 
			
		||||
import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
 | 
			
		||||
import "@0x/contracts-utils/contracts/src/Ownable.sol";
 | 
			
		||||
import "../src/MintableERC20Token.sol";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
contract DummyERC20Token is 
 | 
			
		||||
contract DummyERC20Token is
 | 
			
		||||
    Ownable,
 | 
			
		||||
    MintableERC20Token
 | 
			
		||||
{
 | 
			
		||||
    using LibSafeMath for uint256;
 | 
			
		||||
 | 
			
		||||
    string public name;
 | 
			
		||||
    string public symbol;
 | 
			
		||||
    uint256 public decimals;
 | 
			
		||||
@@ -55,9 +58,9 @@ contract DummyERC20Token is
 | 
			
		||||
    {
 | 
			
		||||
        uint256 currBalance = balances[_target];
 | 
			
		||||
        if (_value < currBalance) {
 | 
			
		||||
            _totalSupply = _safeSub(_totalSupply, _safeSub(currBalance, _value));
 | 
			
		||||
            _totalSupply = _totalSupply.safeSub(currBalance.safeSub(_value));
 | 
			
		||||
        } else {
 | 
			
		||||
            _totalSupply = _safeAdd(_totalSupply, _safeSub(_value, currBalance));
 | 
			
		||||
            _totalSupply = _totalSupply.safeAdd(_value.safeSub(currBalance));
 | 
			
		||||
        }
 | 
			
		||||
        balances[_target] = _value;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -20,13 +20,14 @@ pragma solidity ^0.5.9;
 | 
			
		||||
 | 
			
		||||
import "./interfaces/IERC721Token.sol";
 | 
			
		||||
import "./interfaces/IERC721Receiver.sol";
 | 
			
		||||
import "@0x/contracts-utils/contracts/src/SafeMath.sol";
 | 
			
		||||
import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
contract ERC721Token is
 | 
			
		||||
    IERC721Token,
 | 
			
		||||
    SafeMath
 | 
			
		||||
    IERC721Token
 | 
			
		||||
{
 | 
			
		||||
    using LibSafeMath for uint256;
 | 
			
		||||
 | 
			
		||||
    // Function selector for ERC721Receiver.onERC721Received
 | 
			
		||||
    // 0x150b7a02
 | 
			
		||||
    bytes4 constant internal ERC721_RECEIVED = bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"));
 | 
			
		||||
@@ -163,7 +164,7 @@ contract ERC721Token is
 | 
			
		||||
            _approved
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    /// @notice Count all NFTs assigned to an owner
 | 
			
		||||
    /// @dev NFTs assigned to the zero address are considered invalid, and this
 | 
			
		||||
    ///      function throws for queries about the zero address.
 | 
			
		||||
@@ -223,9 +224,9 @@ contract ERC721Token is
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        owners[_tokenId] = _to;
 | 
			
		||||
        balances[_from] = _safeSub(balances[_from], 1);
 | 
			
		||||
        balances[_to] = _safeAdd(balances[_to], 1);
 | 
			
		||||
    
 | 
			
		||||
        balances[_from] = balances[_from].safeSub(1);
 | 
			
		||||
        balances[_to] = balances[_to].safeAdd(1);
 | 
			
		||||
 | 
			
		||||
        emit Transfer(
 | 
			
		||||
            _from,
 | 
			
		||||
            _to,
 | 
			
		||||
 
 | 
			
		||||
@@ -18,16 +18,19 @@
 | 
			
		||||
 | 
			
		||||
pragma solidity ^0.5.9;
 | 
			
		||||
 | 
			
		||||
import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
 | 
			
		||||
import "./ERC721Token.sol";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
contract MintableERC721Token is
 | 
			
		||||
    ERC721Token
 | 
			
		||||
{
 | 
			
		||||
    using LibSafeMath for uint256;
 | 
			
		||||
 | 
			
		||||
    /// @dev Function to mint a new token
 | 
			
		||||
    ///      Reverts if the given token ID already exists
 | 
			
		||||
    /// @param _to Address of the beneficiary that will own the minted token
 | 
			
		||||
    /// @param _tokenId ID of the token to be minted by the msg.sender    
 | 
			
		||||
    /// @param _tokenId ID of the token to be minted by the msg.sender
 | 
			
		||||
    function _mint(address _to, uint256 _tokenId)
 | 
			
		||||
        internal
 | 
			
		||||
    {
 | 
			
		||||
@@ -43,7 +46,7 @@ contract MintableERC721Token is
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        owners[_tokenId] = _to;
 | 
			
		||||
        balances[_to] = _safeAdd(balances[_to], 1);
 | 
			
		||||
        balances[_to] = balances[_to].safeAdd(1);
 | 
			
		||||
 | 
			
		||||
        emit Transfer(
 | 
			
		||||
            address(0),
 | 
			
		||||
@@ -71,7 +74,7 @@ contract MintableERC721Token is
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        owners[_tokenId] = address(0);
 | 
			
		||||
        balances[_owner] = _safeSub(balances[_owner], 1);
 | 
			
		||||
        balances[_owner] = balances[_owner].safeSub(1);
 | 
			
		||||
 | 
			
		||||
        emit Transfer(
 | 
			
		||||
            _owner,
 | 
			
		||||
 
 | 
			
		||||
@@ -85,9 +85,9 @@ library LibMath {
 | 
			
		||||
            ));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // _safeDiv computes `floor(a / b)`. We use the identity (a, b integer):
 | 
			
		||||
        // safeDiv computes `floor(a / b)`. We use the identity (a, b integer):
 | 
			
		||||
        //       ceil(a / b) = floor((a + b - 1) / b)
 | 
			
		||||
        // To implement `ceil(a / b)` using _safeDiv.
 | 
			
		||||
        // To implement `ceil(a / b)` using safeDiv.
 | 
			
		||||
        partialAmount = numerator.safeMul(target)
 | 
			
		||||
            .safeAdd(denominator.safeSub(1))
 | 
			
		||||
            .safeDiv(denominator);
 | 
			
		||||
@@ -127,9 +127,9 @@ library LibMath {
 | 
			
		||||
        pure
 | 
			
		||||
        returns (uint256 partialAmount)
 | 
			
		||||
    {
 | 
			
		||||
        // _safeDiv computes `floor(a / b)`. We use the identity (a, b integer):
 | 
			
		||||
        // safeDiv computes `floor(a / b)`. We use the identity (a, b integer):
 | 
			
		||||
        //       ceil(a / b) = floor((a + b - 1) / b)
 | 
			
		||||
        // To implement `ceil(a / b)` using _safeDiv.
 | 
			
		||||
        // To implement `ceil(a / b)` using safeDiv.
 | 
			
		||||
        partialAmount = numerator.safeMul(target)
 | 
			
		||||
            .safeAdd(denominator.safeSub(1))
 | 
			
		||||
            .safeDiv(denominator);
 | 
			
		||||
 
 | 
			
		||||
@@ -23,13 +23,13 @@ import "@0x/contracts-exchange/contracts/src/interfaces/IExchange.sol";
 | 
			
		||||
import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol";
 | 
			
		||||
import "@0x/contracts-erc20/contracts/src/interfaces/IERC20Token.sol";
 | 
			
		||||
import "@0x/contracts-utils/contracts/src/LibBytes.sol";
 | 
			
		||||
import "@0x/contracts-utils/contracts/src/SafeMath.sol";
 | 
			
		||||
import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
contract DutchAuction is
 | 
			
		||||
    SafeMath
 | 
			
		||||
{
 | 
			
		||||
contract DutchAuction {
 | 
			
		||||
 | 
			
		||||
    using LibBytes for bytes;
 | 
			
		||||
    using LibSafeMath for uint256;
 | 
			
		||||
 | 
			
		||||
    // solhint-disable var-name-mixedcase
 | 
			
		||||
    IExchange internal EXCHANGE;
 | 
			
		||||
@@ -120,8 +120,8 @@ contract DutchAuction is
 | 
			
		||||
            address token = assetData.readAddress(16);
 | 
			
		||||
            // Calculate the excess from the buy order. This can occur if the buyer sends in a higher
 | 
			
		||||
            // amount than the calculated current amount
 | 
			
		||||
            uint256 buyerExcessAmount = _safeSub(buyOrder.makerAssetAmount, auctionDetails.currentAmount);
 | 
			
		||||
            uint256 sellerExcessAmount = _safeSub(leftMakerAssetSpreadAmount, buyerExcessAmount);
 | 
			
		||||
            uint256 buyerExcessAmount = buyOrder.makerAssetAmount.safeSub(auctionDetails.currentAmount);
 | 
			
		||||
            uint256 sellerExcessAmount = leftMakerAssetSpreadAmount.safeSub(buyerExcessAmount);
 | 
			
		||||
            // Return the difference between auctionDetails.currentAmount and sellOrder.takerAssetAmount
 | 
			
		||||
            // to the seller
 | 
			
		||||
            if (sellerExcessAmount > 0) {
 | 
			
		||||
@@ -190,12 +190,8 @@ contract DutchAuction is
 | 
			
		||||
            // Auction end time is guaranteed by 0x Exchange due to the order expiration
 | 
			
		||||
            auctionDetails.currentAmount = minAmount;
 | 
			
		||||
        } else {
 | 
			
		||||
            auctionDetails.currentAmount = _safeAdd(
 | 
			
		||||
                minAmount,
 | 
			
		||||
                _safeDiv(
 | 
			
		||||
                    _safeMul(remainingDurationSeconds, amountDelta),
 | 
			
		||||
                    auctionDurationSeconds
 | 
			
		||||
                )
 | 
			
		||||
            auctionDetails.currentAmount = minAmount.safeAdd(
 | 
			
		||||
                remainingDurationSeconds.safeMul(amountDelta).safeDiv(auctionDurationSeconds)
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
        return auctionDetails;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,90 +0,0 @@
 | 
			
		||||
pragma solidity ^0.5.9;
 | 
			
		||||
 | 
			
		||||
import "./LibRichErrors.sol";
 | 
			
		||||
import "./LibSafeMathRichErrors.sol";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
contract SafeMath {
 | 
			
		||||
 | 
			
		||||
    function _safeMul(uint256 a, uint256 b)
 | 
			
		||||
        internal
 | 
			
		||||
        pure
 | 
			
		||||
        returns (uint256)
 | 
			
		||||
    {
 | 
			
		||||
        if (a == 0) {
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
        uint256 c = a * b;
 | 
			
		||||
        if (c / a != b) {
 | 
			
		||||
            LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinOpError(
 | 
			
		||||
                LibSafeMathRichErrors.BinOpErrorCodes.MULTIPLICATION_OVERFLOW,
 | 
			
		||||
                a,
 | 
			
		||||
                b
 | 
			
		||||
            ));
 | 
			
		||||
        }
 | 
			
		||||
        return c;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function _safeDiv(uint256 a, uint256 b)
 | 
			
		||||
        internal
 | 
			
		||||
        pure
 | 
			
		||||
        returns (uint256)
 | 
			
		||||
    {
 | 
			
		||||
        if (b == 0) {
 | 
			
		||||
            LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinOpError(
 | 
			
		||||
                LibSafeMathRichErrors.BinOpErrorCodes.DIVISION_BY_ZERO,
 | 
			
		||||
                a,
 | 
			
		||||
                b
 | 
			
		||||
            ));
 | 
			
		||||
        }
 | 
			
		||||
        uint256 c = a / b;
 | 
			
		||||
        return c;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function _safeSub(uint256 a, uint256 b)
 | 
			
		||||
        internal
 | 
			
		||||
        pure
 | 
			
		||||
        returns (uint256)
 | 
			
		||||
    {
 | 
			
		||||
        if (b > a) {
 | 
			
		||||
            LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinOpError(
 | 
			
		||||
                LibSafeMathRichErrors.BinOpErrorCodes.SUBTRACTION_UNDERFLOW,
 | 
			
		||||
                a,
 | 
			
		||||
                b
 | 
			
		||||
            ));
 | 
			
		||||
        }
 | 
			
		||||
        return a - b;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function _safeAdd(uint256 a, uint256 b)
 | 
			
		||||
        internal
 | 
			
		||||
        pure
 | 
			
		||||
        returns (uint256)
 | 
			
		||||
    {
 | 
			
		||||
        uint256 c = a + b;
 | 
			
		||||
        if (c < a) {
 | 
			
		||||
            LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinOpError(
 | 
			
		||||
                LibSafeMathRichErrors.BinOpErrorCodes.ADDITION_OVERFLOW,
 | 
			
		||||
                a,
 | 
			
		||||
                b
 | 
			
		||||
            ));
 | 
			
		||||
        }
 | 
			
		||||
        return c;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function _max256(uint256 a, uint256 b)
 | 
			
		||||
        internal
 | 
			
		||||
        pure
 | 
			
		||||
        returns (uint256)
 | 
			
		||||
    {
 | 
			
		||||
        return a >= b ? a : b;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function _min256(uint256 a, uint256 b)
 | 
			
		||||
        internal
 | 
			
		||||
        pure
 | 
			
		||||
        returns (uint256)
 | 
			
		||||
    {
 | 
			
		||||
        return a < b ? a : b;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -18,18 +18,19 @@
 | 
			
		||||
 | 
			
		||||
pragma solidity ^0.5.9;
 | 
			
		||||
 | 
			
		||||
import "../src/SafeMath.sol";
 | 
			
		||||
import "../src/LibSafeMath.sol";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
contract TestSafeMath is
 | 
			
		||||
    SafeMath
 | 
			
		||||
{
 | 
			
		||||
contract TestLibSafeMath {
 | 
			
		||||
 | 
			
		||||
    using LibSafeMath for uint256;
 | 
			
		||||
 | 
			
		||||
    function externalSafeMul(uint256 a, uint256 b)
 | 
			
		||||
        external
 | 
			
		||||
        pure
 | 
			
		||||
        returns (uint256)
 | 
			
		||||
    {
 | 
			
		||||
        return _safeMul(a, b);
 | 
			
		||||
        return a.safeMul(b);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function externalSafeDiv(uint256 a, uint256 b)
 | 
			
		||||
@@ -37,7 +38,7 @@ contract TestSafeMath is
 | 
			
		||||
        pure
 | 
			
		||||
        returns (uint256)
 | 
			
		||||
    {
 | 
			
		||||
        return _safeDiv(a, b);
 | 
			
		||||
        return a.safeDiv(b);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function externalSafeSub(uint256 a, uint256 b)
 | 
			
		||||
@@ -45,7 +46,7 @@ contract TestSafeMath is
 | 
			
		||||
        pure
 | 
			
		||||
        returns (uint256)
 | 
			
		||||
    {
 | 
			
		||||
        return _safeSub(a, b);
 | 
			
		||||
        return a.safeSub(b);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function externalSafeAdd(uint256 a, uint256 b)
 | 
			
		||||
@@ -53,7 +54,7 @@ contract TestSafeMath is
 | 
			
		||||
        pure
 | 
			
		||||
        returns (uint256)
 | 
			
		||||
    {
 | 
			
		||||
        return _safeAdd(a, b);
 | 
			
		||||
        return a.safeAdd(b);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function externalMaxUint256(uint256 a, uint256 b)
 | 
			
		||||
@@ -61,7 +62,7 @@ contract TestSafeMath is
 | 
			
		||||
        pure
 | 
			
		||||
        returns (uint256)
 | 
			
		||||
    {
 | 
			
		||||
        return _max256(a, b);
 | 
			
		||||
        return a.max256(b);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function externalMinUint256(uint256 a, uint256 b)
 | 
			
		||||
@@ -69,6 +70,6 @@ contract TestSafeMath is
 | 
			
		||||
        pure
 | 
			
		||||
        returns (uint256)
 | 
			
		||||
    {
 | 
			
		||||
        return _min256(a, b);
 | 
			
		||||
        return a.min256(b);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -36,7 +36,7 @@
 | 
			
		||||
    },
 | 
			
		||||
    "config": {
 | 
			
		||||
        "abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually.",
 | 
			
		||||
        "abis": "./generated-artifacts/@(Authorizable|IAuthorizable|IOwnable|LibAddress|LibAddressArray|LibAddressArrayRichErrors|LibAuthorizableRichErrors|LibBytes|LibBytesRichErrors|LibEIP1271|LibEIP712|LibFractions|LibOwnableRichErrors|LibReentrancyGuardRichErrors|LibRichErrors|LibSafeMath|LibSafeMathRichErrors|Ownable|ReentrancyGuard|Refundable|SafeMath|TestLibAddress|TestLibAddressArray|TestLibBytes|TestLibEIP712|TestLibRichErrors|TestLogDecoding|TestLogDecodingDownstream|TestOwnable|TestReentrancyGuard|TestRefundable|TestRefundableReceiver|TestSafeMath).json"
 | 
			
		||||
        "abis": "./generated-artifacts/@(Authorizable|IAuthorizable|IOwnable|LibAddress|LibAddressArray|LibAddressArrayRichErrors|LibAuthorizableRichErrors|LibBytes|LibBytesRichErrors|LibEIP1271|LibEIP712|LibFractions|LibOwnableRichErrors|LibReentrancyGuardRichErrors|LibRichErrors|LibSafeMath|LibSafeMathRichErrors|Ownable|ReentrancyGuard|Refundable|TestLibAddress|TestLibAddressArray|TestLibBytes|TestLibEIP712|TestLibRichErrors|TestLibSafeMath|TestLogDecoding|TestLogDecodingDownstream|TestOwnable|TestReentrancyGuard|TestRefundable|TestRefundableReceiver).json"
 | 
			
		||||
    },
 | 
			
		||||
    "repository": {
 | 
			
		||||
        "type": "git",
 | 
			
		||||
 
 | 
			
		||||
@@ -25,19 +25,18 @@ import * as LibSafeMathRichErrors from '../generated-artifacts/LibSafeMathRichEr
 | 
			
		||||
import * as Ownable from '../generated-artifacts/Ownable.json';
 | 
			
		||||
import * as ReentrancyGuard from '../generated-artifacts/ReentrancyGuard.json';
 | 
			
		||||
import * as Refundable from '../generated-artifacts/Refundable.json';
 | 
			
		||||
import * as SafeMath from '../generated-artifacts/SafeMath.json';
 | 
			
		||||
import * as TestLibAddress from '../generated-artifacts/TestLibAddress.json';
 | 
			
		||||
import * as TestLibAddressArray from '../generated-artifacts/TestLibAddressArray.json';
 | 
			
		||||
import * as TestLibBytes from '../generated-artifacts/TestLibBytes.json';
 | 
			
		||||
import * as TestLibEIP712 from '../generated-artifacts/TestLibEIP712.json';
 | 
			
		||||
import * as TestLibRichErrors from '../generated-artifacts/TestLibRichErrors.json';
 | 
			
		||||
import * as TestLibSafeMath from '../generated-artifacts/TestLibSafeMath.json';
 | 
			
		||||
import * as TestLogDecoding from '../generated-artifacts/TestLogDecoding.json';
 | 
			
		||||
import * as TestLogDecodingDownstream from '../generated-artifacts/TestLogDecodingDownstream.json';
 | 
			
		||||
import * as TestOwnable from '../generated-artifacts/TestOwnable.json';
 | 
			
		||||
import * as TestReentrancyGuard from '../generated-artifacts/TestReentrancyGuard.json';
 | 
			
		||||
import * as TestRefundable from '../generated-artifacts/TestRefundable.json';
 | 
			
		||||
import * as TestRefundableReceiver from '../generated-artifacts/TestRefundableReceiver.json';
 | 
			
		||||
import * as TestSafeMath from '../generated-artifacts/TestSafeMath.json';
 | 
			
		||||
export const artifacts = {
 | 
			
		||||
    Authorizable: Authorizable as ContractArtifact,
 | 
			
		||||
    LibAddress: LibAddress as ContractArtifact,
 | 
			
		||||
@@ -57,7 +56,6 @@ export const artifacts = {
 | 
			
		||||
    Ownable: Ownable as ContractArtifact,
 | 
			
		||||
    ReentrancyGuard: ReentrancyGuard as ContractArtifact,
 | 
			
		||||
    Refundable: Refundable as ContractArtifact,
 | 
			
		||||
    SafeMath: SafeMath as ContractArtifact,
 | 
			
		||||
    IAuthorizable: IAuthorizable as ContractArtifact,
 | 
			
		||||
    IOwnable: IOwnable as ContractArtifact,
 | 
			
		||||
    TestLibAddress: TestLibAddress as ContractArtifact,
 | 
			
		||||
@@ -65,11 +63,11 @@ export const artifacts = {
 | 
			
		||||
    TestLibBytes: TestLibBytes as ContractArtifact,
 | 
			
		||||
    TestLibEIP712: TestLibEIP712 as ContractArtifact,
 | 
			
		||||
    TestLibRichErrors: TestLibRichErrors as ContractArtifact,
 | 
			
		||||
    TestLibSafeMath: TestLibSafeMath as ContractArtifact,
 | 
			
		||||
    TestLogDecoding: TestLogDecoding as ContractArtifact,
 | 
			
		||||
    TestLogDecodingDownstream: TestLogDecodingDownstream as ContractArtifact,
 | 
			
		||||
    TestOwnable: TestOwnable as ContractArtifact,
 | 
			
		||||
    TestReentrancyGuard: TestReentrancyGuard as ContractArtifact,
 | 
			
		||||
    TestRefundable: TestRefundable as ContractArtifact,
 | 
			
		||||
    TestRefundableReceiver: TestRefundableReceiver as ContractArtifact,
 | 
			
		||||
    TestSafeMath: TestSafeMath as ContractArtifact,
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -23,16 +23,15 @@ export * from '../generated-wrappers/lib_safe_math_rich_errors';
 | 
			
		||||
export * from '../generated-wrappers/ownable';
 | 
			
		||||
export * from '../generated-wrappers/reentrancy_guard';
 | 
			
		||||
export * from '../generated-wrappers/refundable';
 | 
			
		||||
export * from '../generated-wrappers/safe_math';
 | 
			
		||||
export * from '../generated-wrappers/test_lib_address';
 | 
			
		||||
export * from '../generated-wrappers/test_lib_address_array';
 | 
			
		||||
export * from '../generated-wrappers/test_lib_bytes';
 | 
			
		||||
export * from '../generated-wrappers/test_lib_e_i_p712';
 | 
			
		||||
export * from '../generated-wrappers/test_lib_rich_errors';
 | 
			
		||||
export * from '../generated-wrappers/test_lib_safe_math';
 | 
			
		||||
export * from '../generated-wrappers/test_log_decoding';
 | 
			
		||||
export * from '../generated-wrappers/test_log_decoding_downstream';
 | 
			
		||||
export * from '../generated-wrappers/test_ownable';
 | 
			
		||||
export * from '../generated-wrappers/test_reentrancy_guard';
 | 
			
		||||
export * from '../generated-wrappers/test_refundable';
 | 
			
		||||
export * from '../generated-wrappers/test_refundable_receiver';
 | 
			
		||||
export * from '../generated-wrappers/test_safe_math';
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@ import { blockchainTests, constants, describe, expect } from '@0x/contracts-test
 | 
			
		||||
import { BigNumber, SafeMathRevertErrors } from '@0x/utils';
 | 
			
		||||
import * as _ from 'lodash';
 | 
			
		||||
 | 
			
		||||
import { artifacts, TestSafeMathContract } from '../src';
 | 
			
		||||
import { artifacts, TestLibSafeMathContract } from '../src';
 | 
			
		||||
import * as ReferenceFunctions from '../src/reference_functions';
 | 
			
		||||
 | 
			
		||||
function toBigNumber(a: number | string): BigNumber {
 | 
			
		||||
@@ -11,19 +11,19 @@ function toBigNumber(a: number | string): BigNumber {
 | 
			
		||||
 | 
			
		||||
blockchainTests('SafeMath', env => {
 | 
			
		||||
    const { ONE_ETHER } = constants;
 | 
			
		||||
    let safeMath: TestSafeMathContract;
 | 
			
		||||
    let safeMath: TestLibSafeMathContract;
 | 
			
		||||
 | 
			
		||||
    before(async () => {
 | 
			
		||||
        // Deploy SafeMath
 | 
			
		||||
        safeMath = await TestSafeMathContract.deployFrom0xArtifactAsync(
 | 
			
		||||
            artifacts.TestSafeMath,
 | 
			
		||||
        safeMath = await TestLibSafeMathContract.deployFrom0xArtifactAsync(
 | 
			
		||||
            artifacts.TestLibSafeMath,
 | 
			
		||||
            env.provider,
 | 
			
		||||
            env.txDefaults,
 | 
			
		||||
            {},
 | 
			
		||||
        );
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    describe('_safeMul', () => {
 | 
			
		||||
    describe('safeMul', () => {
 | 
			
		||||
        it('should match the output of the reference function', async () => {
 | 
			
		||||
            const a = ONE_ETHER;
 | 
			
		||||
            const b = ONE_ETHER.times(2);
 | 
			
		||||
@@ -59,7 +59,7 @@ blockchainTests('SafeMath', env => {
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    describe('_safeDiv', () => {
 | 
			
		||||
    describe('safeDiv', () => {
 | 
			
		||||
        it('should match the output of the reference function', async () => {
 | 
			
		||||
            const a = ONE_ETHER;
 | 
			
		||||
            const b = ONE_ETHER.times(2);
 | 
			
		||||
@@ -100,7 +100,7 @@ blockchainTests('SafeMath', env => {
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    describe('_safeSub', () => {
 | 
			
		||||
    describe('safeSub', () => {
 | 
			
		||||
        it('should match the output of the reference function', async () => {
 | 
			
		||||
            const a = ONE_ETHER;
 | 
			
		||||
            const b = ONE_ETHER.dividedToIntegerBy(2);
 | 
			
		||||
@@ -131,7 +131,7 @@ blockchainTests('SafeMath', env => {
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    describe('_safeAdd', () => {
 | 
			
		||||
    describe('safeAdd', () => {
 | 
			
		||||
        it('should match the output of the reference function', async () => {
 | 
			
		||||
            const a = ONE_ETHER;
 | 
			
		||||
            const b = ONE_ETHER.dividedToIntegerBy(2);
 | 
			
		||||
@@ -167,7 +167,7 @@ blockchainTests('SafeMath', env => {
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    describe('_maxUint256', () => {
 | 
			
		||||
    describe('maxUint256', () => {
 | 
			
		||||
        it('should return first argument if it is greater than the second', async () => {
 | 
			
		||||
            const result = await safeMath.externalMaxUint256.callAsync(toBigNumber(13), constants.ZERO_AMOUNT);
 | 
			
		||||
            expect(result).bignumber.to.be.eq(toBigNumber(13));
 | 
			
		||||
@@ -184,7 +184,7 @@ blockchainTests('SafeMath', env => {
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    describe('_minUint256', () => {
 | 
			
		||||
    describe('minUint256', () => {
 | 
			
		||||
        it('should return first argument if it is less than the second', async () => {
 | 
			
		||||
            const result = await safeMath.externalMaxUint256.callAsync(constants.ZERO_AMOUNT, toBigNumber(13));
 | 
			
		||||
            expect(result).bignumber.to.be.eq(toBigNumber(13));
 | 
			
		||||
@@ -23,19 +23,18 @@
 | 
			
		||||
        "generated-artifacts/Ownable.json",
 | 
			
		||||
        "generated-artifacts/ReentrancyGuard.json",
 | 
			
		||||
        "generated-artifacts/Refundable.json",
 | 
			
		||||
        "generated-artifacts/SafeMath.json",
 | 
			
		||||
        "generated-artifacts/TestLibAddress.json",
 | 
			
		||||
        "generated-artifacts/TestLibAddressArray.json",
 | 
			
		||||
        "generated-artifacts/TestLibBytes.json",
 | 
			
		||||
        "generated-artifacts/TestLibEIP712.json",
 | 
			
		||||
        "generated-artifacts/TestLibRichErrors.json",
 | 
			
		||||
        "generated-artifacts/TestLibSafeMath.json",
 | 
			
		||||
        "generated-artifacts/TestLogDecoding.json",
 | 
			
		||||
        "generated-artifacts/TestLogDecodingDownstream.json",
 | 
			
		||||
        "generated-artifacts/TestOwnable.json",
 | 
			
		||||
        "generated-artifacts/TestReentrancyGuard.json",
 | 
			
		||||
        "generated-artifacts/TestRefundable.json",
 | 
			
		||||
        "generated-artifacts/TestRefundableReceiver.json",
 | 
			
		||||
        "generated-artifacts/TestSafeMath.json"
 | 
			
		||||
        "generated-artifacts/TestRefundableReceiver.json"
 | 
			
		||||
    ],
 | 
			
		||||
    "exclude": ["./deploy/solc/solc_bin"]
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user