forked from nnlgsakib/Mindchainswap-Contracts-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMindchainswapFactory.sol
52 lines (42 loc) · 2.02 KB
/
MindchainswapFactory.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// SPDX-License-Identifier: GPL-3.0
pragma solidity =0.5.16;
import './interfaces/IMindchainswapFactory.sol';
import './MindchainswapPair.sol';
contract MindchainswapFactory is IMindchainswapFactory {
bytes32 public constant INIT_CODE_PAIR_HASH = keccak256(abi.encodePacked(type(MindchainswapPair).creationCode));
address public feeTo;
address public feeToSetter;
mapping(address => mapping(address => address)) public getPair;
address[] public allPairs;
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
constructor(address _feeToSetter) public {
feeToSetter = _feeToSetter;
}
function allPairsLength() external view returns (uint) {
return allPairs.length;
}
function createPair(address tokenA, address tokenB) external returns (address pair) {
require(tokenA != tokenB, 'Mindchainswap: IDENTICAL_ADDRESSES');
(address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
require(token0 != address(0), 'Mindchainswap: ZERO_ADDRESS');
require(getPair[token0][token1] == address(0), 'Mindchainswap: PAIR_EXISTS'); // single check is sufficient
bytes memory bytecode = type(MindchainswapPair).creationCode;
bytes32 salt = keccak256(abi.encodePacked(token0, token1));
assembly {
pair := create2(0, add(bytecode, 32), mload(bytecode), salt)
}
IMindchainswapPair(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 {
require(msg.sender == feeToSetter, 'Mindchainswap: FORBIDDEN');
feeTo = _feeTo;
}
function setFeeToSetter(address _feeToSetter) external {
require(msg.sender == feeToSetter, 'Mindchainswap: FORBIDDEN');
feeToSetter = _feeToSetter;
}
}