forked from sherlock-audit/2023-04-splits
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SwapperFactory.sol
64 lines (50 loc) · 2.22 KB
/
SwapperFactory.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
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;
import {OracleImpl} from "splits-oracle/OracleImpl.sol";
import {OracleParams} from "splits-oracle/peripherals/OracleParams.sol";
import {LibClone} from "splits-utils/LibClone.sol";
import {SwapperImpl} from "./SwapperImpl.sol";
/// @title Swapper Factory
/// @author 0xSplits
/// @notice Factory for creating & validating Swappers
/// @dev This contract uses token = address(0) to refer to ETH.
contract SwapperFactory {
using LibClone for address;
event CreateSwapper(SwapperImpl indexed swapper, SwapperImpl.InitParams params);
struct CreateSwapperParams {
address owner;
bool paused;
address beneficiary;
address tokenToBeneficiary;
OracleParams oracleParams;
}
SwapperImpl public immutable swapperImpl;
/// mapping of canonical swappers for flash callback validation
mapping(SwapperImpl => bool) internal $isSwapper;
constructor() {
swapperImpl = new SwapperImpl();
}
/// -----------------------------------------------------------------------
/// functions - public & external
/// -----------------------------------------------------------------------
function createSwapper(CreateSwapperParams calldata params_) external returns (SwapperImpl swapper) {
OracleImpl oracle = params_.oracleParams._parseIntoOracle();
swapper = SwapperImpl(payable(address(swapperImpl).clone()));
SwapperImpl.InitParams memory swapperInitParams = SwapperImpl.InitParams({
owner: params_.owner,
paused: params_.paused,
beneficiary: params_.beneficiary,
tokenToBeneficiary: params_.tokenToBeneficiary,
oracle: oracle
});
swapper.initializer(swapperInitParams);
$isSwapper[swapper] = true;
emit CreateSwapper({swapper: swapper, params: swapperInitParams});
}
/// -----------------------------------------------------------------------
/// functions - public & external - view
/// -----------------------------------------------------------------------
function isSwapper(SwapperImpl swapper) external view returns (bool) {
return $isSwapper[swapper];
}
}