-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathUniswapV3FactoryUpgradeable.sol
110 lines (95 loc) · 3.77 KB
/
UniswapV3FactoryUpgradeable.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.15;
import {IUniswapV3Factory} from "./interfaces/IUniswapV3Factory.sol";
import {OwnableUpgradeable} from "@openzeppelin-upgradeable/contracts/access/OwnableUpgradeable.sol";
import {INFTXFeeDistributorV3} from "@src/interfaces/INFTXFeeDistributorV3.sol";
import {UniswapV3PoolDeployerUpgradeable, UpgradeableBeacon} from "./UniswapV3PoolDeployerUpgradeable.sol";
/// @title Canonical Uniswap V3 factory
/// @notice Deploys Uniswap V3 pools and manages ownership and control over pool protocol fees
contract UniswapV3FactoryUpgradeable is
IUniswapV3Factory,
UniswapV3PoolDeployerUpgradeable
{
/// @inheritdoc IUniswapV3Factory
address public override feeDistributor;
/// @inheritdoc IUniswapV3Factory
mapping(uint24 => int24) public override feeAmountTickSpacing;
/// @inheritdoc IUniswapV3Factory
mapping(address => mapping(address => mapping(uint24 => address)))
public
override getPool;
uint16 public override rewardTierCardinality;
function __UniswapV3FactoryUpgradeable_init(
address beaconImplementation_,
uint16 rewardTierCardinality_
) external initializer {
__UniswapV3PoolDeployerUpgradeable_init(beaconImplementation_);
if (rewardTierCardinality_ <= 1) revert InvalidRewardTierCardinality();
rewardTierCardinality = rewardTierCardinality_;
feeAmountTickSpacing[3_000] = 60;
emit FeeAmountEnabled(3_000, 60);
feeAmountTickSpacing[10_000] = 200;
emit FeeAmountEnabled(10_000, 200);
}
/// @inheritdoc IUniswapV3Factory
function createPool(
address tokenA,
address tokenB,
uint24 fee
) external override returns (address pool) {
require(tokenA != tokenB);
(address token0, address token1) = tokenA < tokenB
? (tokenA, tokenB)
: (tokenB, tokenA);
require(token0 != address(0));
int24 tickSpacing = feeAmountTickSpacing[fee];
require(tickSpacing != 0);
require(getPool[token0][token1][fee] == address(0));
pool = deploy(
address(this),
token0,
token1,
fee,
tickSpacing,
rewardTierCardinality
);
getPool[token0][token1][fee] = pool;
// populate mapping in the reverse direction, deliberate choice to avoid the cost of comparing addresses
getPool[token1][token0][fee] = pool;
emit PoolCreated(token0, token1, fee, tickSpacing, pool);
}
/// @inheritdoc IUniswapV3Factory
function setFeeDistributor(
address feeDistributor_
) external override onlyOwner {
feeDistributor = feeDistributor_;
}
function setRewardTierCardinality(
uint16 rewardTierCardinality_
) external override onlyOwner {
if (rewardTierCardinality_ <= 1) revert InvalidRewardTierCardinality();
rewardTierCardinality = rewardTierCardinality_;
}
/// @inheritdoc IUniswapV3Factory
function enableFeeAmount(
uint24 fee,
int24 tickSpacing
) public override onlyOwner {
require(fee < 1000000);
// tick spacing is capped at 16384 to prevent the situation where tickSpacing is so large that
// TickBitmap#nextInitializedTickWithinOneWord overflows int24 container from a valid tick
// 16384 ticks represents a >5x price change with ticks of 1 bips
require(tickSpacing > 0 && tickSpacing < 16384);
require(feeAmountTickSpacing[fee] == 0);
feeAmountTickSpacing[fee] = tickSpacing;
emit FeeAmountEnabled(fee, tickSpacing);
}
function owner()
public
view
override(IUniswapV3Factory, OwnableUpgradeable)
returns (address)
{
return super.owner();
}
}