-
Notifications
You must be signed in to change notification settings - Fork 0
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
avenbreaks
committed
Nov 5, 2023
0 parents
commit 6f7022f
Showing
33 changed files
with
9,334 additions
and
0 deletions.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
*.sol linguist-language=Solidity |
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,37 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
strategy: | ||
matrix: | ||
node: ['10.x', '12.x'] | ||
os: [ubuntu-latest] | ||
|
||
runs-on: ${{ matrix.os }} | ||
|
||
steps: | ||
- uses: actions/checkout@v1 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node }} | ||
|
||
- run: npm install -g yarn | ||
|
||
- id: yarn-cache | ||
run: echo "::set-output name=dir::$(yarn cache dir)" | ||
- uses: actions/cache@v1 | ||
with: | ||
path: ${{ steps.yarn-cache.outputs.dir }} | ||
key: ${{ matrix.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | ||
restore-keys: | | ||
${{ matrix.os }}-yarn- | ||
- run: yarn | ||
- run: yarn lint | ||
- run: yarn test |
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,2 @@ | ||
node_modules/ | ||
build/ |
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,6 @@ | ||
{ | ||
"extension": ["ts"], | ||
"spec": "./test/**/*.spec.ts", | ||
"require": "ts-node/register", | ||
"timeout": 12000 | ||
} |
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 @@ | ||
{ | ||
"semi": false, | ||
"singleQuote": true, | ||
"printWidth": 120 | ||
} |
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,24 @@ | ||
{ | ||
"compilerVersion": "./node_modules/solc", | ||
"outputType": "all", | ||
"compilerOptions": { | ||
"outputSelection": { | ||
"*": { | ||
"*": [ | ||
"evm.bytecode.object", | ||
"evm.deployedBytecode.object", | ||
"abi", | ||
"evm.bytecode.sourceMap", | ||
"evm.deployedBytecode.sourceMap", | ||
"metadata" | ||
], | ||
"": ["ast"] | ||
} | ||
}, | ||
"evmVersion": "istanbul", | ||
"optimizer": { | ||
"enabled": true, | ||
"runs": 999999 | ||
} | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
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,24 @@ | ||
# Uniswap V2 | ||
|
||
[![Actions Status](https://github.com/Uniswap/uniswap-v2-core/workflows/CI/badge.svg)](https://github.com/Uniswap/uniswap-v2-core/actions) | ||
[![Version](https://img.shields.io/npm/v/@uniswap/v2-core)](https://www.npmjs.com/package/@uniswap/v2-core) | ||
|
||
In-depth documentation on Uniswap V2 is available at [uniswap.org](https://uniswap.org/docs). | ||
|
||
The built contract artifacts can be browsed via [unpkg.com](https://unpkg.com/browse/@uniswap/v2-core@latest/). | ||
|
||
# Local Development | ||
|
||
The following assumes the use of `node@>=10`. | ||
|
||
## Install Dependencies | ||
|
||
`yarn` | ||
|
||
## Compile Contracts | ||
|
||
`yarn compile` | ||
|
||
## Run Tests | ||
|
||
`yarn test` |
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,23 @@ | ||
pragma solidity =0.5.16; | ||
|
||
contract Migrations { | ||
address public owner; | ||
uint256 public last_completed_migration; | ||
|
||
modifier restricted() { | ||
if (msg.sender == owner) _; | ||
} | ||
|
||
constructor() public { | ||
owner = msg.sender; | ||
} | ||
|
||
function setCompleted(uint completed) public restricted { | ||
last_completed_migration = completed; | ||
} | ||
|
||
function upgrade(address new_address) public restricted { | ||
Migrations upgraded = Migrations(new_address); | ||
upgraded.setCompleted(last_completed_migration); | ||
} | ||
} |
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,94 @@ | ||
pragma solidity =0.5.16; | ||
|
||
import './interfaces/IUniswapV2ERC20.sol'; | ||
import './libraries/SafeMath.sol'; | ||
|
||
contract UniswapV2ERC20 is IUniswapV2ERC20 { | ||
using SafeMath for uint; | ||
|
||
string public constant name = 'Uniswap V2'; | ||
string public constant symbol = 'UNI-V2'; | ||
uint8 public constant decimals = 18; | ||
uint public totalSupply; | ||
mapping(address => uint) public balanceOf; | ||
mapping(address => mapping(address => uint)) public allowance; | ||
|
||
bytes32 public DOMAIN_SEPARATOR; | ||
// keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"); | ||
bytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9; | ||
mapping(address => uint) public nonces; | ||
|
||
event Approval(address indexed owner, address indexed spender, uint value); | ||
event Transfer(address indexed from, address indexed to, uint value); | ||
|
||
constructor() public { | ||
uint chainId; | ||
assembly { | ||
chainId := chainid | ||
} | ||
DOMAIN_SEPARATOR = keccak256( | ||
abi.encode( | ||
keccak256('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)'), | ||
keccak256(bytes(name)), | ||
keccak256(bytes('1')), | ||
chainId, | ||
address(this) | ||
) | ||
); | ||
} | ||
|
||
function _mint(address to, uint value) internal { | ||
totalSupply = totalSupply.add(value); | ||
balanceOf[to] = balanceOf[to].add(value); | ||
emit Transfer(address(0), to, value); | ||
} | ||
|
||
function _burn(address from, uint value) internal { | ||
balanceOf[from] = balanceOf[from].sub(value); | ||
totalSupply = totalSupply.sub(value); | ||
emit Transfer(from, address(0), value); | ||
} | ||
|
||
function _approve(address owner, address spender, uint value) private { | ||
allowance[owner][spender] = value; | ||
emit Approval(owner, spender, value); | ||
} | ||
|
||
function _transfer(address from, address to, uint value) private { | ||
balanceOf[from] = balanceOf[from].sub(value); | ||
balanceOf[to] = balanceOf[to].add(value); | ||
emit Transfer(from, to, value); | ||
} | ||
|
||
function approve(address spender, uint value) external returns (bool) { | ||
_approve(msg.sender, spender, value); | ||
return true; | ||
} | ||
|
||
function transfer(address to, uint value) external returns (bool) { | ||
_transfer(msg.sender, to, value); | ||
return true; | ||
} | ||
|
||
function transferFrom(address from, address to, uint value) external returns (bool) { | ||
if (allowance[from][msg.sender] != uint(-1)) { | ||
allowance[from][msg.sender] = allowance[from][msg.sender].sub(value); | ||
} | ||
_transfer(from, to, value); | ||
return true; | ||
} | ||
|
||
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external { | ||
require(deadline >= block.timestamp, 'UniswapV2: EXPIRED'); | ||
bytes32 digest = keccak256( | ||
abi.encodePacked( | ||
'\x19\x01', | ||
DOMAIN_SEPARATOR, | ||
keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, nonces[owner]++, deadline)) | ||
) | ||
); | ||
address recoveredAddress = ecrecover(digest, v, r, s); | ||
require(recoveredAddress != address(0) && recoveredAddress == owner, 'UniswapV2: INVALID_SIGNATURE'); | ||
_approve(owner, spender, value); | ||
} | ||
} |
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,49 @@ | ||
pragma solidity =0.5.16; | ||
|
||
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) 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, '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.