exchange -> pair
This commit is contained in:
@ -1,41 +1,40 @@
|
||||
pragma solidity =0.5.16;
|
||||
|
||||
import './interfaces/IUniswapV2Factory.sol';
|
||||
import './UniswapV2Exchange.sol';
|
||||
import './interfaces/IUniswapV2Exchange.sol';
|
||||
import './UniswapV2Pair.sol';
|
||||
|
||||
contract UniswapV2Factory is IUniswapV2Factory {
|
||||
address public feeTo;
|
||||
address public feeToSetter;
|
||||
|
||||
mapping(address => mapping(address => address)) public getExchange;
|
||||
address[] public allExchanges;
|
||||
mapping(address => mapping(address => address)) public getPair;
|
||||
address[] public allPairs;
|
||||
|
||||
event ExchangeCreated(address indexed token0, address indexed token1, address exchange, uint);
|
||||
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
|
||||
|
||||
constructor(address _feeToSetter) public {
|
||||
feeToSetter = _feeToSetter;
|
||||
}
|
||||
|
||||
function allExchangesLength() external view returns (uint) {
|
||||
return allExchanges.length;
|
||||
function allPairsLength() external view returns (uint) {
|
||||
return allPairs.length;
|
||||
}
|
||||
|
||||
function createExchange(address tokenA, address tokenB) external returns (address exchange) {
|
||||
function createPair(address tokenA, address tokenB) external returns (address pair) {
|
||||
require(tokenA != tokenB, 'UniswapV2: IDENTICAL_ADDRESSES');
|
||||
(address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
|
||||
require(token0 != address(0), 'UniswapV2: ZERO_ADDRESS');
|
||||
require(getExchange[token0][token1] == address(0), 'UniswapV2: EXCHANGE_EXISTS'); // single check is sufficient
|
||||
bytes memory exchangeBytecode = type(UniswapV2Exchange).creationCode;
|
||||
require(getPair[token0][token1] == address(0), 'UniswapV2: PAIR_EXISTS'); // single check is sufficient
|
||||
bytes memory bytecode = type(UniswapV2Pair).creationCode;
|
||||
bytes32 salt = keccak256(abi.encodePacked(token0, token1));
|
||||
assembly {
|
||||
exchange := create2(0, add(exchangeBytecode, 32), mload(exchangeBytecode), salt)
|
||||
pair := create2(0, add(bytecode, 32), mload(bytecode), salt)
|
||||
}
|
||||
IUniswapV2Exchange(exchange).initialize(token0, token1);
|
||||
getExchange[token0][token1] = exchange;
|
||||
getExchange[token1][token0] = exchange; // populate mapping in the reverse direction
|
||||
allExchanges.push(exchange);
|
||||
emit ExchangeCreated(token0, token1, exchange, allExchanges.length);
|
||||
IUniswapV2Pair(pair).initialize(token0, token1);
|
||||
getPair[token0][token1] = pair;
|
||||
getPair[token1][token0] = pair; // populate mapping in the reverse direction
|
||||
allPairs.push(pair);
|
||||
emit PairCreated(token0, token1, pair, allPairs.length);
|
||||
}
|
||||
|
||||
function setFeeTo(address _feeTo) external {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
pragma solidity =0.5.16;
|
||||
|
||||
import './interfaces/IUniswapV2Exchange.sol';
|
||||
import './interfaces/IUniswapV2Pair.sol';
|
||||
import './UniswapV2ERC20.sol';
|
||||
import './libraries/Math.sol';
|
||||
import './libraries/UQ112x112.sol';
|
||||
@ -8,7 +8,7 @@ import './interfaces/IERC20.sol';
|
||||
import './interfaces/IUniswapV2Factory.sol';
|
||||
import './interfaces/IUniswapV2Callee.sol';
|
||||
|
||||
contract UniswapV2Exchange is IUniswapV2Exchange, UniswapV2ERC20 {
|
||||
contract UniswapV2Pair is IUniswapV2Pair, UniswapV2ERC20 {
|
||||
using SafeMath for uint;
|
||||
using UQ112x112 for uint224;
|
||||
|
||||
@ -1,16 +1,16 @@
|
||||
pragma solidity =0.5.16;
|
||||
|
||||
interface IUniswapV2Factory {
|
||||
event ExchangeCreated(address indexed token0, address indexed token1, address exchange, uint);
|
||||
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
|
||||
|
||||
function feeTo() external view returns (address);
|
||||
function feeToSetter() external view returns (address);
|
||||
|
||||
function getExchange(address tokenA, address tokenB) external view returns (address exchange);
|
||||
function allExchanges(uint) external view returns (address exchange);
|
||||
function allExchangesLength() external view returns (uint);
|
||||
function getPair(address tokenA, address tokenB) external view returns (address pair);
|
||||
function allPairs(uint) external view returns (address pair);
|
||||
function allPairsLength() external view returns (uint);
|
||||
|
||||
function createExchange(address tokenA, address tokenB) external returns (address exchange);
|
||||
function createPair(address tokenA, address tokenB) external returns (address pair);
|
||||
|
||||
function setFeeTo(address) external;
|
||||
function setFeeToSetter(address) external;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
pragma solidity =0.5.16;
|
||||
|
||||
interface IUniswapV2Exchange {
|
||||
interface IUniswapV2Pair {
|
||||
event Approval(address indexed owner, address indexed spender, uint value);
|
||||
event Transfer(address indexed from, address indexed to, uint value);
|
||||
|
||||
Reference in New Issue
Block a user