Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create wkFactory.sol #252

Open
wants to merge 1 commit into
base: 2020131127
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions contracts/wkFactory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./wkSwap.sol";
@@ -8,20 +9,19 @@ contract Factory {
mapping(address => mapping(address => address)) public getPair;
address[] public allPairs;

constructor() public {}

function allPairsLength() external view returns (uint) {
return allPairs.length;
}

function createPair(address tokenA, address tokenB) external returns (address pair) {
function createPair(address tokenA, address tokenB) external returns(address) {
require(tokenA != tokenB, "IDENTICAL_ADDRESSES");
(address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
require(token0 != address(0), "ZERO_ADDRESS");
require(getPair[token0][token1] == address(0), "PAIR_EXISTS");
Swap swap = new Swap(tokenA, tokenB);
getPair[token0][token1] = swap;
getPair[token1][token0] = swap;
allPairs.push(swap);
getPair[token0][token1] = address(swap);
getPair[token1][token0] = address(swap);
allPairs.push(address(swap));
return address(swap);
}
}