forked from sherlock-audit/2023-04-splits
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UniV3OracleFactory.sol
50 lines (39 loc) · 1.96 KB
/
UniV3OracleFactory.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
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;
import {IUniswapV3Factory} from "v3-core/interfaces/IUniswapV3Factory.sol";
import {LibClone} from "solady/utils/LibClone.sol";
import {OracleImpl} from "./OracleImpl.sol";
import {IOracleFactory} from "./interfaces/IOracleFactory.sol";
import {UniV3OracleImpl} from "./UniV3OracleImpl.sol";
/// @title UniV3 Oracle Factory
/// @author 0xSplits
/// @notice Factory for creating uniV3 oracles
contract UniV3OracleFactory is IOracleFactory {
using LibClone for address;
event CreateUniV3Oracle(UniV3OracleImpl indexed oracle, UniV3OracleImpl.InitParams params);
UniV3OracleImpl public immutable uniV3OracleImpl;
constructor(IUniswapV3Factory uniswapV3Factory_, address weth9_) {
uniV3OracleImpl = new UniV3OracleImpl({
uniswapV3Factory_: uniswapV3Factory_,
weth9_: weth9_
});
}
/// -----------------------------------------------------------------------
/// functions - public & external
/// -----------------------------------------------------------------------
function createUniV3Oracle(UniV3OracleImpl.InitParams calldata params_) external returns (UniV3OracleImpl) {
return _createUniV3Oracle(params_);
}
function createOracle(bytes calldata data_) external returns (OracleImpl) {
UniV3OracleImpl.InitParams memory params = abi.decode(data_, (UniV3OracleImpl.InitParams));
return _createUniV3Oracle(params);
}
/// -----------------------------------------------------------------------
/// functions - private & internal
/// -----------------------------------------------------------------------
function _createUniV3Oracle(UniV3OracleImpl.InitParams memory params_) internal returns (UniV3OracleImpl oracle) {
oracle = UniV3OracleImpl(address(uniV3OracleImpl).clone());
oracle.initializer(params_);
emit CreateUniV3Oracle({oracle: oracle, params: params_});
}
}