@0x/contracts-zero-ex
: Address review comments.
This commit is contained in:
@@ -35,6 +35,11 @@ import "./LibERC20Transformer.sol";
|
||||
contract FillQuoteTransformer is
|
||||
Transformer
|
||||
{
|
||||
using LibERC20TokenV06 for IERC20TokenV06;
|
||||
using LibERC20Transformer for IERC20TokenV06;
|
||||
using LibSafeMathV06 for uint256;
|
||||
using LibRichErrorsV06 for bytes;
|
||||
|
||||
/// @dev Whether we are performing a market sell or buy.
|
||||
enum Side {
|
||||
Sell,
|
||||
@@ -77,18 +82,15 @@ contract FillQuoteTransformer is
|
||||
}
|
||||
|
||||
/// @dev The Exchange ERC20Proxy ID.
|
||||
bytes4 constant private ERC20_ASSET_PROXY_ID = 0xf47261b0;
|
||||
bytes4 private constant ERC20_ASSET_PROXY_ID = 0xf47261b0;
|
||||
/// @dev Maximum uint256 value.
|
||||
uint256 private constant MAX_UINT256 = uint256(-1);
|
||||
|
||||
/// @dev The Exchange contract.
|
||||
IExchange public immutable exchange;
|
||||
/// @dev The ERC20Proxy address.
|
||||
address public immutable erc20Proxy;
|
||||
|
||||
using LibERC20TokenV06 for IERC20TokenV06;
|
||||
using LibERC20Transformer for IERC20TokenV06;
|
||||
using LibSafeMathV06 for uint256;
|
||||
using LibRichErrorsV06 for bytes;
|
||||
|
||||
/// @dev Create this contract.
|
||||
/// @param exchange_ The Exchange V3 instance.
|
||||
/// @param deploymentNonce_ The nonce of the deployer when deploying this contract.
|
||||
@@ -132,7 +134,7 @@ contract FillQuoteTransformer is
|
||||
).rrevert();
|
||||
}
|
||||
|
||||
if (data.side == Side.Sell && data.fillAmount == uint256(-1)) {
|
||||
if (data.side == Side.Sell && data.fillAmount == MAX_UINT256) {
|
||||
// If `sellAmount == -1 then we are selling
|
||||
// the entire balance of `sellToken`. This is useful in cases where
|
||||
// the exact sell amount is not exactly known in advance, like when
|
||||
@@ -181,7 +183,7 @@ contract FillQuoteTransformer is
|
||||
data.fillAmount.safeSub(soldAmount).min256(
|
||||
data.maxOrderFillAmounts.length > i
|
||||
? data.maxOrderFillAmounts[i]
|
||||
: uint256(-1)
|
||||
: MAX_UINT256
|
||||
),
|
||||
singleProtocolFee
|
||||
);
|
||||
@@ -195,7 +197,7 @@ contract FillQuoteTransformer is
|
||||
data.fillAmount.safeSub(boughtAmount).min256(
|
||||
data.maxOrderFillAmounts.length > i
|
||||
? data.maxOrderFillAmounts[i]
|
||||
: uint256(-1)
|
||||
: MAX_UINT256
|
||||
),
|
||||
singleProtocolFee
|
||||
);
|
||||
|
@@ -25,11 +25,11 @@ import "@0x/contracts-erc20/contracts/src/v06/LibERC20TokenV06.sol";
|
||||
|
||||
library LibERC20Transformer {
|
||||
|
||||
using LibERC20TokenV06 for IERC20TokenV06;
|
||||
|
||||
/// @dev ETH pseudo-token address.
|
||||
address constant internal ETH_TOKEN_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
|
||||
|
||||
using LibERC20TokenV06 for IERC20TokenV06;
|
||||
|
||||
/// @dev Transfer ERC20 tokens and ETH.
|
||||
/// @param token An ERC20 or the ETH pseudo-token address (`ETH_TOKEN_ADDRESS`).
|
||||
/// @param to The recipient.
|
||||
|
@@ -33,6 +33,9 @@ contract PayTakerTransformer is
|
||||
Transformer
|
||||
{
|
||||
// solhint-disable no-empty-blocks
|
||||
using LibRichErrorsV06 for bytes;
|
||||
using LibSafeMathV06 for uint256;
|
||||
using LibERC20Transformer for IERC20TokenV06;
|
||||
|
||||
/// @dev Transform data to ABI-encode and pass into `transform()`.
|
||||
struct TransformData {
|
||||
@@ -43,9 +46,8 @@ contract PayTakerTransformer is
|
||||
uint256[] amounts;
|
||||
}
|
||||
|
||||
using LibRichErrorsV06 for bytes;
|
||||
using LibSafeMathV06 for uint256;
|
||||
using LibERC20Transformer for IERC20TokenV06;
|
||||
/// @dev Maximum uint256 value.
|
||||
uint256 private constant MAX_UINT256 = uint256(-1);
|
||||
|
||||
/// @dev Create this contract.
|
||||
/// @param deploymentNonce_ The nonce of the deployer when deploying this contract.
|
||||
@@ -76,7 +78,7 @@ contract PayTakerTransformer is
|
||||
// The `amounts` array can be shorter than the `tokens` array.
|
||||
// Missing elements are treated as `uint256(-1)`.
|
||||
uint256 amount = data.amounts.length > i ? data.amounts[i] : uint256(-1);
|
||||
if (amount == uint256(-1)) {
|
||||
if (amount == MAX_UINT256) {
|
||||
amount = data.tokens[i].getTokenBalanceOf(address(this));
|
||||
}
|
||||
if (amount != 0) {
|
||||
|
@@ -31,6 +31,10 @@ import "./LibERC20Transformer.sol";
|
||||
contract WethTransformer is
|
||||
Transformer
|
||||
{
|
||||
using LibRichErrorsV06 for bytes;
|
||||
using LibSafeMathV06 for uint256;
|
||||
using LibERC20Transformer for IERC20TokenV06;
|
||||
|
||||
/// @dev Transform data to ABI-encode and pass into `transform()`.
|
||||
struct TransformData {
|
||||
// The token to wrap/unwrap. Must be either ETH or WETH.
|
||||
@@ -42,10 +46,8 @@ contract WethTransformer is
|
||||
|
||||
/// @dev The WETH contract address.
|
||||
IEtherTokenV06 public immutable weth;
|
||||
|
||||
using LibRichErrorsV06 for bytes;
|
||||
using LibSafeMathV06 for uint256;
|
||||
using LibERC20Transformer for IERC20TokenV06;
|
||||
/// @dev Maximum uint256 value.
|
||||
uint256 private constant MAX_UINT256 = uint256(-1);
|
||||
|
||||
/// @dev Construct the transformer and store the WETH address in an immutable.
|
||||
/// @param weth_ The weth token.
|
||||
@@ -80,7 +82,7 @@ contract WethTransformer is
|
||||
}
|
||||
|
||||
uint256 amount = data.amount;
|
||||
if (amount == uint256(-1)) {
|
||||
if (amount == MAX_UINT256) {
|
||||
amount = data.token.getTokenBalanceOf(address(this));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user