From 0d35e31a899ba895f95e4bf2852f5b854e158c5a Mon Sep 17 00:00:00 2001 From: Noah Zinsmeister Date: Wed, 22 Jan 2020 13:36:26 -0500 Subject: [PATCH] tweak factory functions --- contracts/UniswapV2Factory.sol | 30 ++++++++++------------ contracts/interfaces/IUniswapV2Factory.sol | 4 +-- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/contracts/UniswapV2Factory.sol b/contracts/UniswapV2Factory.sol index a547e22..446f5b2 100644 --- a/contracts/UniswapV2Factory.sol +++ b/contracts/UniswapV2Factory.sol @@ -5,10 +5,10 @@ import "./UniswapV2Exchange.sol"; import "./interfaces/IUniswapV2Exchange.sol"; contract UniswapV2Factory is IUniswapV2Factory { - address public feeToSetter; address public feeTo; + address public feeToSetter; - mapping (address => mapping(address => address)) private getExchange_; + mapping (address => mapping(address => address)) private _getExchange; address[] public exchanges; event ExchangeCreated(address indexed token0, address indexed token1, address exchange, uint); @@ -18,12 +18,14 @@ contract UniswapV2Factory is IUniswapV2Factory { } function sortTokens(address tokenA, address tokenB) public pure returns (address token0, address token1) { - return tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA); + require(tokenA != tokenB, "UniswapV2Factory: SAME_ADDRESS"); + require(tokenA != address(0) && tokenB != address(0), "UniswapV2Factory: ZERO_ADDRESS"); + (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA); } function getExchange(address tokenA, address tokenB) external view returns (address exchange) { (address token0, address token1) = sortTokens(tokenA, tokenB); - return getExchange_[token0][token1]; + exchange = _getExchange[token0][token1]; } function exchangesCount() external view returns (uint) { @@ -31,28 +33,24 @@ contract UniswapV2Factory is IUniswapV2Factory { } function createExchange(address tokenA, address tokenB) external returns (address exchange) { - require(tokenA != tokenB, "UniswapV2Factory: SAME_ADDRESS"); - require(tokenA != address(0) && tokenB != address(0), "UniswapV2Factory: ZERO_ADDRESS"); (address token0, address token1) = sortTokens(tokenA, tokenB); - require(getExchange_[token0][token1] == address(0), "UniswapV2Factory: EXCHANGE_EXISTS"); + require(_getExchange[token0][token1] == address(0), "UniswapV2Factory: EXCHANGE_EXISTS"); bytes memory exchangeBytecode = type(UniswapV2Exchange).creationCode; bytes32 salt = keccak256(abi.encodePacked(token0, token1)); - assembly { // solium-disable-line security/no-inline-assembly - exchange := create2(0, add(exchangeBytecode, 32), mload(exchangeBytecode), salt) - } + assembly { exchange := create2(0, add(exchangeBytecode, 32), mload(exchangeBytecode), salt) } IUniswapV2Exchange(exchange).initialize(token0, token1); - getExchange_[token0][token1] = exchange; + _getExchange[token0][token1] = exchange; exchanges.push(exchange); emit ExchangeCreated(token0, token1, exchange, exchanges.length); } - function setFeeToSetter(address _feeToSetter) external { - require(msg.sender == feeToSetter, "UniswapV2Factory: FORBIDDEN"); - feeToSetter = _feeToSetter; - } - function setFeeTo(address _feeTo) external { require(msg.sender == feeToSetter, "UniswapV2Factory: FORBIDDEN"); feeTo = _feeTo; } + + function setFeeToSetter(address _feeToSetter) external { + require(msg.sender == feeToSetter, "UniswapV2Factory: FORBIDDEN"); + feeToSetter = _feeToSetter; + } } diff --git a/contracts/interfaces/IUniswapV2Factory.sol b/contracts/interfaces/IUniswapV2Factory.sol index 1f7b7a9..15e9b83 100644 --- a/contracts/interfaces/IUniswapV2Factory.sol +++ b/contracts/interfaces/IUniswapV2Factory.sol @@ -1,10 +1,10 @@ pragma solidity =0.5.16; interface IUniswapV2Factory { - event ExchangeCreated(address indexed token0, address indexed token1, address exchange, uint256); + event ExchangeCreated(address indexed token0, address indexed token1, address exchange, uint); - function feeToSetter() external view returns (address); function feeTo() external view returns (address); + function feeToSetter() external view returns (address); function sortTokens(address tokenA, address tokenB) external pure returns (address token0, address token1); function getExchange(address tokenA, address tokenB) external view returns (address exchange);