Skip to content

Commit 4089aa2

Browse files
committed
add Mint function
1 parent 22bdc65 commit 4089aa2

File tree

4 files changed

+1015
-15
lines changed

4 files changed

+1015
-15
lines changed

contracts/Ownable.sol

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// SPDX-License-Identifier: No License (None)
2+
pragma solidity =0.5.16;
3+
4+
/**
5+
* @title Ownable
6+
* @dev The Ownable contract has an owner address, and provides basic authorization control
7+
* functions, this simplifies the implementation of "user permissions".
8+
*
9+
* Source https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-solidity/v2.1.3/contracts/ownership/Ownable.sol
10+
* This contract is copied here and renamed from the original to avoid clashes in the compiled artifacts
11+
* when the user imports a zos-lib contract (that transitively causes this contract to be compiled and added to the
12+
* build/artifacts folder) as well as the vanilla Ownable implementation from an openzeppelin version.
13+
*/
14+
contract Ownable {
15+
address private _owner;
16+
17+
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
18+
19+
/**
20+
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
21+
* account.
22+
*/
23+
constructor () internal {
24+
_owner = msg.sender;
25+
emit OwnershipTransferred(address(0), _owner);
26+
}
27+
28+
/**
29+
* @return the address of the owner.
30+
*/
31+
function owner() public view returns (address) {
32+
return _owner;
33+
}
34+
35+
/**
36+
* @dev Throws if called by any account other than the owner.
37+
*/
38+
modifier onlyOwner() {
39+
require(isOwner(),"Not Owner");
40+
_;
41+
}
42+
43+
/**
44+
* @return true if `msg.sender` is the owner of the contract.
45+
*/
46+
function isOwner() public view returns (bool) {
47+
return msg.sender == _owner;
48+
}
49+
50+
/**
51+
* @dev Allows the current owner to relinquish control of the contract.
52+
* @notice Renouncing to ownership will leave the contract without an owner.
53+
* It will not be possible to call the functions with the `onlyOwner`
54+
* modifier anymore.
55+
*/
56+
function renounceOwnership() public onlyOwner {
57+
emit OwnershipTransferred(_owner, address(0));
58+
_owner = address(0);
59+
}
60+
61+
/**
62+
* @dev Allows the current owner to transfer control of the contract to a newOwner.
63+
* @param newOwner The address to transfer ownership to.
64+
*/
65+
function transferOwnership(address newOwner) public onlyOwner {
66+
_transferOwnership(newOwner);
67+
}
68+
69+
/**
70+
* @dev Transfers control of the contract to a newOwner.
71+
* @param newOwner The address to transfer ownership to.
72+
*/
73+
function _transferOwnership(address newOwner) internal {
74+
require(newOwner != address(0),"Zero address not allowed");
75+
emit OwnershipTransferred(_owner, newOwner);
76+
_owner = newOwner;
77+
}
78+
}

contracts/UniswapV2Factory.sol

+21-15
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
pragma solidity =0.5.16;
22

3-
import './interfaces/IUniswapV2Factory.sol';
43
import './UniswapV2Pair.sol';
4+
import "./Ownable.sol";
5+
6+
contract UniswapV2Factory is Ownable {
57

6-
contract UniswapV2Factory is IUniswapV2Factory {
7-
address public feeTo;
8-
address public feeToSetter;
98
address public constant BNB = 0x0000000000000000000000000000000000000001;
109

1110
mapping(address => mapping(address => address)) public getPair;
1211
address[] public allPairs;
1312

13+
mapping(address => bool) isAllowedAddress;
1414
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
1515

16-
constructor(address _feeToSetter) public {
17-
feeToSetter = _feeToSetter;
16+
function changeAllowedAddress(address _which,bool _bool) external onlyOwner returns(bool){
17+
isAllowedAddress[_which] = _bool;
18+
return true;
1819
}
1920

21+
2022
function allPairsLength() external view returns (uint) {
2123
return allPairs.length;
2224
}
@@ -38,18 +40,22 @@ contract UniswapV2Factory is IUniswapV2Factory {
3840
emit PairCreated(token0, token1, pair, allPairs.length);
3941
}
4042

41-
function setFeeTo(address _feeTo) external {
42-
require(msg.sender == feeToSetter, 'UniswapV2: FORBIDDEN');
43-
feeTo = _feeTo;
44-
}
43+
function cratePool(address tokenA, address tokenB, uint amountA, uint amountB, address payable to) external payable returns(address pair, uint liquidity) {
44+
pair = createPair(tokenA, tokenB);
45+
bool isBNB;
46+
if (tokenA == BNB) isBNB = true;
47+
else safeTransferFrom(tokenA, msg.sender, pair, amountA);
4548

46-
function setFeeToSetter(address _feeToSetter) external {
47-
require(msg.sender == feeToSetter, 'UniswapV2: FORBIDDEN');
48-
feeToSetter = _feeToSetter;
49+
if (tokenB == BNB) isBNB = true;
50+
else safeTransferFrom(tokenB, msg.sender, pair, amountB);
51+
52+
if (isBNB) liquidity = IUniswapV2Pair(pair).mint.value(msg.value)(to);
53+
else liquidity = IUniswapV2Pair(pair).mint(to);
4954
}
5055

51-
function cratePool(address tokenA, address tokenB, uint amountA, uint amountB, address payable to) external payable returns(address pair, uint liquidity) {
52-
pair = createPair(tokenA, tokenB);
56+
function mint(address tokenA, address tokenB, uint amountA, uint amountB, address payable to) external payable returns(uint liquidity) {
57+
require(isAllowedAddress[msg.sender],"ERR_ALLOWED_ADDRESS_ONLY");
58+
address pair = getPair[tokenA][tokenB];
5359
bool isBNB;
5460
if (tokenA == BNB) isBNB = true;
5561
else safeTransferFrom(tokenA, msg.sender, pair, amountA);

0 commit comments

Comments
 (0)