1
- pragma solidity = 0.5.16 ;
1
+ pragma solidity = 0.6.6 ;
2
2
3
- import '@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol ' ;
4
3
import '@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol ' ;
5
4
6
5
import './interfaces/IUniswapV2Library.sol ' ;
@@ -9,8 +8,11 @@ import './libraries/SafeMath.sol';
9
8
contract UniswapV2Library is IUniswapV2Library {
10
9
using SafeMath for uint ;
11
10
12
- // factory address is identical across mainnet and testnets but differs between testing and deployed environments
13
- IUniswapV2Factory public constant factory = IUniswapV2Factory (0xdCCc660F92826649754E357b11bd41C31C0609B9 );
11
+ address public immutable override factory;
12
+
13
+ constructor (address _factory ) public {
14
+ factory = _factory;
15
+ }
14
16
15
17
// returns sorted token addresses, used to handle return values from pairs sorted in this order
16
18
function sortTokens (address tokenA , address tokenB ) internal pure returns (address token0 , address token1 ) {
@@ -20,13 +22,13 @@ contract UniswapV2Library is IUniswapV2Library {
20
22
}
21
23
22
24
// calculates the CREATE2 address for a pair without making any external calls
23
- function pairFor (address tokenA , address tokenB ) internal pure returns (address pair ) {
25
+ function pairFor (address tokenA , address tokenB ) internal view returns (address pair ) {
24
26
(address token0 , address token1 ) = sortTokens (tokenA, tokenB);
25
27
pair = address (uint (keccak256 (abi.encodePacked (
26
28
hex 'ff ' ,
27
29
factory,
28
30
keccak256 (abi.encodePacked (token0, token1)),
29
- hex '0b77fb54a078d9399fa29cac94f5b35b9f11611b456ab507c7f46754712b642b ' // init code hash
31
+ hex '96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f ' // init code hash
30
32
))));
31
33
}
32
34
@@ -38,14 +40,14 @@ contract UniswapV2Library is IUniswapV2Library {
38
40
}
39
41
40
42
// given some amount of an asset and pair reserves, returns an equivalent amount of the other asset
41
- function quote (uint amountA , uint reserveA , uint reserveB ) public pure returns (uint amountB ) {
43
+ function quote (uint amountA , uint reserveA , uint reserveB ) public pure override returns (uint amountB ) {
42
44
require (amountA > 0 , 'UniswapV2Helper: INSUFFICIENT_AMOUNT ' );
43
45
require (reserveA > 0 && reserveB > 0 , 'UniswapV2Helper: INSUFFICIENT_LIQUIDITY ' );
44
46
amountB = amountA.mul (reserveB) / reserveA;
45
47
}
46
48
47
49
// given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset
48
- function getAmountOut (uint amountIn , uint reserveIn , uint reserveOut ) public pure returns (uint amountOut ) {
50
+ function getAmountOut (uint amountIn , uint reserveIn , uint reserveOut ) public pure override returns (uint amountOut ) {
49
51
require (amountIn > 0 , 'UniswapV2Helper: INSUFFICIENT_INPUT_AMOUNT ' );
50
52
require (reserveIn > 0 && reserveOut > 0 , 'UniswapV2Helper: INSUFFICIENT_LIQUIDITY ' );
51
53
uint amountInWithFee = amountIn.mul (997 );
@@ -55,7 +57,7 @@ contract UniswapV2Library is IUniswapV2Library {
55
57
}
56
58
57
59
// given an output amount of an asset and pair reserves, returns a required input amount of the other asset
58
- function getAmountIn (uint amountOut , uint reserveIn , uint reserveOut ) public pure returns (uint amountIn ) {
60
+ function getAmountIn (uint amountOut , uint reserveIn , uint reserveOut ) public pure override returns (uint amountIn ) {
59
61
require (amountOut > 0 , 'UniswapV2Helper: INSUFFICIENT_OUTPUT_AMOUNT ' );
60
62
require (reserveIn > 0 && reserveOut > 0 , 'UniswapV2Helper: INSUFFICIENT_LIQUIDITY ' );
61
63
uint numerator = reserveIn.mul (amountOut).mul (1000 );
@@ -64,7 +66,7 @@ contract UniswapV2Library is IUniswapV2Library {
64
66
}
65
67
66
68
// performs chained getAmountOut calculations on any number of pairs
67
- function getAmountsOut (uint amountIn , address [] memory path ) public view returns (uint [] memory amounts ) {
69
+ function getAmountsOut (uint amountIn , address [] memory path ) public view override returns (uint [] memory amounts ) {
68
70
require (path.length >= 2 , 'UniswapV2Helper: INVALID_PATH ' );
69
71
amounts = new uint [](path.length );
70
72
amounts[0 ] = amountIn;
@@ -75,7 +77,7 @@ contract UniswapV2Library is IUniswapV2Library {
75
77
}
76
78
77
79
// performs chained getAmountIn calculations on any number of pairs
78
- function getAmountsIn (uint amountOut , address [] memory path ) public view returns (uint [] memory amounts ) {
80
+ function getAmountsIn (uint amountOut , address [] memory path ) public view override returns (uint [] memory amounts ) {
79
81
require (path.length >= 2 , 'UniswapV2Helper: INVALID_PATH ' );
80
82
amounts = new uint [](path.length );
81
83
amounts[amounts.length - 1 ] = amountOut;
0 commit comments