-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c412a89
commit 3af4616
Showing
14 changed files
with
642 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[submodule "lib/forge-std"] | ||
path = lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std | ||
[submodule "lib/openzeppelin-contracts"] | ||
path = lib/openzeppelin-contracts | ||
url = https://github.com/OpenZeppelin/openzeppelin-contracts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,3 +64,4 @@ $ forge --help | |
$ anvil --help | ||
$ cast --help | ||
``` | ||
# V2-Core-08 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule openzeppelin-contracts
added at
dbb610
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/ | ||
ds-test/=lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/ | ||
erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/ | ||
forge-std/=lib/forge-std/src/ | ||
openzeppelin-contracts/=lib/openzeppelin-contracts/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Pausable.sol"; | ||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20FlashMint.sol"; | ||
|
||
contract UniswapV2ERC20 is | ||
ERC20, | ||
ERC20Burnable, | ||
ERC20Pausable, | ||
Ownable, | ||
ERC20Permit, | ||
ERC20Votes | ||
// ERC20FlashMint | ||
{ | ||
constructor( | ||
address initialOwner | ||
) | ||
ERC20("Uniswap V2", "UNI-V2") | ||
Ownable(initialOwner) | ||
ERC20Permit("Uniswap V2") | ||
{} | ||
|
||
function pause() public onlyOwner { | ||
_pause(); | ||
} | ||
|
||
function unpause() public onlyOwner { | ||
_unpause(); | ||
} | ||
|
||
function mint(address to, uint256 amount) public onlyOwner { | ||
_mint(to, amount); | ||
} | ||
|
||
// The following functions are overrides required by Solidity. | ||
|
||
function _update( | ||
address from, | ||
address to, | ||
uint256 value | ||
) internal override(ERC20, ERC20Pausable, ERC20Votes) { | ||
super._update(from, to, value); | ||
} | ||
|
||
function nonces( | ||
address owner | ||
) public view override(ERC20Permit, Nonces) returns (uint256) { | ||
return super.nonces(owner); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import "./interfaces/IUniswapV2Factory.sol"; | ||
import "./UniswapV2Pair.sol"; | ||
|
||
contract UniswapV2Factory is IUniswapV2Factory { | ||
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) { | ||
feeToSetter = _feeToSetter; | ||
} | ||
|
||
function allPairsLength() external view returns (uint) { | ||
return allPairs.length; | ||
} | ||
|
||
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( | ||
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 { | ||
pair := create2(0, add(bytecode, 32), mload(bytecode), salt) | ||
} | ||
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 { | ||
require(msg.sender == feeToSetter, "UniswapV2: FORBIDDEN"); | ||
feeTo = _feeTo; | ||
} | ||
|
||
function setFeeToSetter(address _feeToSetter) external { | ||
require(msg.sender == feeToSetter, "UniswapV2: FORBIDDEN"); | ||
feeToSetter = _feeToSetter; | ||
} | ||
} |
Oops, something went wrong.