Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
Update contracts/exchange-forwarder to 0.5.5 (#1796)
Browse files Browse the repository at this point in the history
* Cherry-pick updated `@0x/contracts-exchange-forwarder` from `3.0` branch.

* Add PR numbers to changelogs
  • Loading branch information
dorothy-zbornak authored Apr 29, 2019
1 parent d303e9f commit bbc06be
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 49 deletions.
9 changes: 9 additions & 0 deletions contracts/exchange-forwarder/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
[
{
"version": "3.0.0",
"changes": [
{
"note": "Update contracts to solidity ^0.5.5 and unpin dependencies",
"pr": 1796
}
]
},
{
"version": "2.1.1",
"changes": [
Expand Down
3 changes: 2 additions & 1 deletion contracts/exchange-forwarder/contracts/src/Forwarder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

pragma solidity 0.4.24;
pragma solidity ^0.5.5;
pragma experimental ABIEncoderV2;

import "./MixinWeth.sol";
Expand All @@ -40,6 +40,7 @@ contract Forwarder is
bytes memory _wethAssetData
)
public
Ownable()
LibConstants(
_exchange,
_zrxAssetData,
Expand Down
10 changes: 5 additions & 5 deletions contracts/exchange-forwarder/contracts/src/MixinAssets.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

pragma solidity ^0.4.24;
pragma solidity ^0.5.5;

import "@0x/contracts-utils/contracts/src/LibBytes.sol";
import "@0x/contracts-utils/contracts/src/Ownable.sol";
Expand All @@ -35,13 +35,13 @@ contract MixinAssets is

bytes4 constant internal ERC20_TRANSFER_SELECTOR = bytes4(keccak256("transfer(address,uint256)"));

/// @dev Withdraws assets from this contract. The contract requires a ZRX balance in order to
/// @dev Withdraws assets from this contract. The contract requires a ZRX balance in order to
/// function optimally, and this function allows the ZRX to be withdrawn by owner. It may also be
/// used to withdraw assets that were accidentally sent to this contract.
/// @param assetData Byte array encoded for the respective asset proxy.
/// @param amount Amount of ERC20 token to withdraw.
function withdrawAsset(
bytes assetData,
bytes calldata assetData,
uint256 amount
)
external
Expand Down Expand Up @@ -84,7 +84,7 @@ contract MixinAssets is
// Transfer tokens.
// We do a raw call so we can check the success separate
// from the return data.
bool success = token.call(abi.encodeWithSelector(
(bool success,) = token.call(abi.encodeWithSelector(
ERC20_TRANSFER_SELECTOR,
msg.sender,
amount
Expand All @@ -93,7 +93,7 @@ contract MixinAssets is
success,
"TRANSFER_FAILED"
);

// Check return data.
// If there is no return data, we assume the token incorrectly
// does not return a bool. In this case we expect it to revert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

pragma solidity ^0.4.24;
pragma solidity ^0.5.5;
pragma experimental ABIEncoderV2;

import "./libs/LibConstants.sol";
Expand Down Expand Up @@ -144,6 +144,7 @@ contract MixinExchangeWrapper is
bytes memory wethAssetData = WETH_ASSET_DATA;

uint256 ordersLength = orders.length;
uint256 makerAssetFilledAmount = 0;
for (uint256 i = 0; i != ordersLength; i++) {

// We assume that asset being bought by taker is the same for each order.
Expand Down Expand Up @@ -175,7 +176,7 @@ contract MixinExchangeWrapper is
addFillResults(totalFillResults, singleFillResults);

// Stop execution if the entire amount of makerAsset has been bought
uint256 makerAssetFilledAmount = totalFillResults.makerAssetFilledAmount;
makerAssetFilledAmount = totalFillResults.makerAssetFilledAmount;
if (makerAssetFilledAmount >= makerAssetFillAmount) {
break;
}
Expand All @@ -192,7 +193,7 @@ contract MixinExchangeWrapper is
/// that at least zrxBuyAmount of ZRX is purchased (sometimes slightly over due to rounding issues).
/// It is possible that a request to buy 200 ZRX will require purchasing 202 ZRX
/// as 2 ZRX is required to purchase the 200 ZRX fee tokens. This guarantees at least 200 ZRX for future purchases.
/// The asset being sold by taker must always be WETH.
/// The asset being sold by taker must always be WETH.
/// @param orders Array of order specifications containing ZRX as makerAsset and WETH as takerAsset.
/// @param zrxBuyAmount Desired amount of ZRX to buy.
/// @param signatures Proofs that orders have been created by makers.
Expand Down Expand Up @@ -230,7 +231,7 @@ contract MixinExchangeWrapper is
// of the Maker. In this case we want to overestimate the amount of takerAsset.
uint256 remainingWethSellAmount = getPartialAmountCeil(
orders[i].takerAssetAmount,
safeSub(orders[i].makerAssetAmount, orders[i].takerFee), // our exchange rate after fees
safeSub(orders[i].makerAssetAmount, orders[i].takerFee), // our exchange rate after fees
remainingZrxBuyAmount
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

pragma solidity ^0.4.24;
pragma solidity ^0.5.5;
pragma experimental ABIEncoderV2;

import "./libs/LibConstants.sol";
Expand Down Expand Up @@ -58,7 +58,7 @@ contract MixinForwarderCore is
/// Any ZRX required to pay fees for primary orders will automatically be purchased by this contract.
/// 5% of ETH value is reserved for paying fees to order feeRecipients (in ZRX) and forwarding contract feeRecipient (in ETH).
/// Any ETH not spent will be refunded to sender.
/// @param orders Array of order specifications used containing desired makerAsset and WETH as takerAsset.
/// @param orders Array of order specifications used containing desired makerAsset and WETH as takerAsset.
/// @param signatures Proofs that orders have been created by makers.
/// @param feeOrders Array of order specifications containing ZRX as makerAsset and WETH as takerAsset. Used to purchase ZRX for primary order fees.
/// @param feeSignatures Proofs that feeOrders have been created by makers.
Expand All @@ -70,8 +70,8 @@ contract MixinForwarderCore is
bytes[] memory signatures,
LibOrder.Order[] memory feeOrders,
bytes[] memory feeSignatures,
uint256 feePercentage,
address feeRecipient
uint256 feePercentage,
address payable feeRecipient
)
public
payable
Expand Down Expand Up @@ -142,7 +142,7 @@ contract MixinForwarderCore is
/// @dev Attempt to purchase makerAssetFillAmount of makerAsset by selling ETH provided with transaction.
/// Any ZRX required to pay fees for primary orders will automatically be purchased by this contract.
/// Any ETH not spent will be refunded to sender.
/// @param orders Array of order specifications used containing desired makerAsset and WETH as takerAsset.
/// @param orders Array of order specifications used containing desired makerAsset and WETH as takerAsset.
/// @param makerAssetFillAmount Desired amount of makerAsset to purchase.
/// @param signatures Proofs that orders have been created by makers.
/// @param feeOrders Array of order specifications containing ZRX as makerAsset and WETH as takerAsset. Used to purchase ZRX for primary order fees.
Expand All @@ -156,8 +156,8 @@ contract MixinForwarderCore is
bytes[] memory signatures,
LibOrder.Order[] memory feeOrders,
bytes[] memory feeSignatures,
uint256 feePercentage,
address feeRecipient
uint256 feePercentage,
address payable feeRecipient
)
public
payable
Expand Down
8 changes: 4 additions & 4 deletions contracts/exchange-forwarder/contracts/src/MixinWeth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

pragma solidity ^0.4.24;
pragma solidity ^0.5.5;

import "@0x/contracts-exchange-libs/contracts/src/LibMath.sol";
import "./libs/LibConstants.sol";
Expand All @@ -30,7 +30,7 @@ contract MixinWeth is
{
/// @dev Default payabale function, this allows us to withdraw WETH
function ()
public
external
payable
{
require(
Expand Down Expand Up @@ -60,7 +60,7 @@ contract MixinWeth is
uint256 wethSoldExcludingFeeOrders,
uint256 wethSoldForZrx,
uint256 feePercentage,
address feeRecipient
address payable feeRecipient
)
internal
{
Expand Down Expand Up @@ -92,7 +92,7 @@ contract MixinWeth is
ethFee <= wethRemaining,
"INSUFFICIENT_ETH_REMAINING"
);

// Do nothing if no WETH remaining
if (wethRemaining > 0) {
// Convert remaining WETH to ETH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
*/

pragma solidity ^0.4.24;
pragma solidity ^0.5.5;


contract IAssets {

/// @dev Withdraws assets from this contract. The contract requires a ZRX balance in order to
/// @dev Withdraws assets from this contract. The contract requires a ZRX balance in order to
/// function optimally, and this function allows the ZRX to be withdrawn by owner. It may also be
/// used to withdraw assets that were accidentally sent to this contract.
/// @param assetData Byte array encoded for the respective asset proxy.
/// @param amount Amount of ERC20 token to withdraw.
function withdrawAsset(
bytes assetData,
bytes calldata assetData,
uint256 amount
)
external;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

pragma solidity ^0.4.24;
pragma solidity ^0.5.5;
pragma experimental ABIEncoderV2;

import "./IForwarderCore.sol";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

pragma solidity ^0.4.24;
pragma solidity ^0.5.5;
pragma experimental ABIEncoderV2;

import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol";
Expand All @@ -29,7 +29,7 @@ contract IForwarderCore {
/// Any ZRX required to pay fees for primary orders will automatically be purchased by this contract.
/// 5% of ETH value is reserved for paying fees to order feeRecipients (in ZRX) and forwarding contract feeRecipient (in ETH).
/// Any ETH not spent will be refunded to sender.
/// @param orders Array of order specifications used containing desired makerAsset and WETH as takerAsset.
/// @param orders Array of order specifications used containing desired makerAsset and WETH as takerAsset.
/// @param signatures Proofs that orders have been created by makers.
/// @param feeOrders Array of order specifications containing ZRX as makerAsset and WETH as takerAsset. Used to purchase ZRX for primary order fees.
/// @param feeSignatures Proofs that feeOrders have been created by makers.
Expand All @@ -41,8 +41,8 @@ contract IForwarderCore {
bytes[] memory signatures,
LibOrder.Order[] memory feeOrders,
bytes[] memory feeSignatures,
uint256 feePercentage,
address feeRecipient
uint256 feePercentage,
address payable feeRecipient
)
public
payable
Expand All @@ -54,7 +54,7 @@ contract IForwarderCore {
/// @dev Attempt to purchase makerAssetFillAmount of makerAsset by selling ETH provided with transaction.
/// Any ZRX required to pay fees for primary orders will automatically be purchased by this contract.
/// Any ETH not spent will be refunded to sender.
/// @param orders Array of order specifications used containing desired makerAsset and WETH as takerAsset.
/// @param orders Array of order specifications used containing desired makerAsset and WETH as takerAsset.
/// @param makerAssetFillAmount Desired amount of makerAsset to purchase.
/// @param signatures Proofs that orders have been created by makers.
/// @param feeOrders Array of order specifications containing ZRX as makerAsset and WETH as takerAsset. Used to purchase ZRX for primary order fees.
Expand All @@ -68,8 +68,8 @@ contract IForwarderCore {
bytes[] memory signatures,
LibOrder.Order[] memory feeOrders,
bytes[] memory feeSignatures,
uint256 feePercentage,
address feeRecipient
uint256 feePercentage,
address payable feeRecipient
)
public
payable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

pragma solidity ^0.4.24;
pragma solidity ^0.5.5;

import "@0x/contracts-utils/contracts/src/LibBytes.sol";
import "@0x/contracts-exchange/contracts/src/interfaces/IExchange.sol";
Expand All @@ -31,10 +31,10 @@ contract LibConstants {
bytes4 constant internal ERC20_DATA_ID = bytes4(keccak256("ERC20Token(address)"));
bytes4 constant internal ERC721_DATA_ID = bytes4(keccak256("ERC721Token(address,uint256)"));
uint256 constant internal MAX_UINT = 2**256 - 1;
uint256 constant internal PERCENTAGE_DENOMINATOR = 10**18;
uint256 constant internal PERCENTAGE_DENOMINATOR = 10**18;
uint256 constant internal MAX_FEE_PERCENTAGE = 5 * PERCENTAGE_DENOMINATOR / 100; // 5%
uint256 constant internal MAX_WETH_FILL_PERCENTAGE = 95 * PERCENTAGE_DENOMINATOR / 100; // 95%

// solhint-disable var-name-mixedcase
IExchange internal EXCHANGE;
IEtherToken internal ETHER_TOKEN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

// solhint-disable
pragma solidity ^0.4.24;
pragma solidity ^0.5.5;


/// This contract is intended to serve as a reference, but is not actually used for efficiency reasons.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

pragma solidity ^0.4.24;
pragma solidity ^0.5.5;

import "../interfaces/IAssets.sol";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

pragma solidity ^0.4.24;
pragma solidity ^0.5.5;
pragma experimental ABIEncoderV2;

import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol";
Expand Down Expand Up @@ -72,7 +72,7 @@ contract MExchangeWrapper {
/// that at least zrxBuyAmount of ZRX is purchased (sometimes slightly over due to rounding issues).
/// It is possible that a request to buy 200 ZRX will require purchasing 202 ZRX
/// as 2 ZRX is required to purchase the 200 ZRX fee tokens. This guarantees at least 200 ZRX for future purchases.
/// The asset being sold by taker must always be WETH.
/// The asset being sold by taker must always be WETH.
/// @param orders Array of order specifications containing ZRX as makerAsset and WETH as takerAsset.
/// @param zrxBuyAmount Desired amount of ZRX to buy.
/// @param signatures Proofs that orders have been created by makers.
Expand Down
4 changes: 2 additions & 2 deletions contracts/exchange-forwarder/contracts/src/mixins/MWeth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

pragma solidity ^0.4.24;
pragma solidity ^0.5.5;


contract MWeth {
Expand All @@ -35,7 +35,7 @@ contract MWeth {
uint256 wethSoldExcludingFeeOrders,
uint256 wethSoldForZrx,
uint256 feePercentage,
address feeRecipient
address payable feeRecipient
)
internal;
}
15 changes: 7 additions & 8 deletions contracts/exchange-forwarder/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@0x/contracts-exchange-forwarder",
"version": "2.1.1",
"version": "2.1.0",
"engines": {
"node": ">=6.12"
},
Expand All @@ -24,7 +24,6 @@
"clean": "shx rm -rf lib generated-artifacts generated-wrappers",
"generate_contract_wrappers": "abi-gen --abis ${npm_package_config_abis} --template ../../node_modules/@0x/abi-gen-templates/contract.handlebars --partials '../../node_modules/@0x/abi-gen-templates/partials/**/*.handlebars' --output generated-wrappers --backend ethers",
"lint": "tslint --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts",
"fix": "tslint --fix --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts",
"coverage:report:text": "istanbul report text",
"coverage:report:html": "istanbul report html && open coverage/index.html",
"profiler:report:html": "istanbul report html && open coverage/index.html",
Expand Down Expand Up @@ -71,14 +70,14 @@
"dependencies": {
"@0x/base-contract": "^5.0.5",
"@0x/contracts-asset-proxy": "^2.1.1",
"@0x/contracts-erc20": "1.0.8",
"@0x/contracts-erc721": "1.0.8",
"@0x/contracts-exchange": "1.0.2",
"@0x/contracts-exchange-libs": "1.0.2",
"@0x/contracts-utils": "2.0.1",
"@0x/contracts-erc20": "^2.2.0",
"@0x/contracts-erc721": "^2.1.0",
"@0x/contracts-exchange": "^2.1.1",
"@0x/contracts-exchange-libs": "^2.1.1",
"@0x/contracts-utils": "^3.1.1",
"@0x/order-utils": "^7.2.0",
"@0x/types": "^2.2.2",
"@0x/typescript-typings": "^4.2.2",
"@0x/typescript-typings": "^4.2.1",
"@0x/utils": "^4.3.1",
"@0x/web3-wrapper": "^6.0.5",
"ethereum-types": "^2.1.2",
Expand Down

0 comments on commit bbc06be

Please sign in to comment.