-
Notifications
You must be signed in to change notification settings - Fork 3
/
Factory.sol
89 lines (69 loc) · 2.72 KB
/
Factory.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
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.4;
import { Lendgine } from "./Lendgine.sol";
import { IFactory } from "./interfaces/IFactory.sol";
contract Factory is IFactory {
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
event LendgineCreated(
address indexed token0,
address indexed token1,
uint256 token0Exp,
uint256 token1Exp,
uint256 indexed upperBound,
address lendgine
);
/*//////////////////////////////////////////////////////////////
ERRORS
//////////////////////////////////////////////////////////////*/
error SameTokenError();
error ZeroAddressError();
error DeployedError();
error ScaleError();
/*//////////////////////////////////////////////////////////////
FACTORY STORAGE
//////////////////////////////////////////////////////////////*/
/// @inheritdoc IFactory
mapping(address => mapping(address => mapping(uint256 => mapping(uint256 => mapping(uint256 => address)))))
public
override getLendgine;
/*//////////////////////////////////////////////////////////////
TEMPORARY DEPLOY STORAGE
//////////////////////////////////////////////////////////////*/
struct Parameters {
address token0;
address token1;
uint128 token0Exp;
uint128 token1Exp;
uint256 upperBound;
}
/// @inheritdoc IFactory
Parameters public override parameters;
/*//////////////////////////////////////////////////////////////
FACTORY LOGIC
//////////////////////////////////////////////////////////////*/
/// @inheritdoc IFactory
function createLendgine(
address token0,
address token1,
uint8 token0Exp,
uint8 token1Exp,
uint256 upperBound
)
external
override
returns (address lendgine)
{
if (token0 == token1) revert SameTokenError();
if (token0 == address(0) || token1 == address(0)) revert ZeroAddressError();
if (getLendgine[token0][token1][token0Exp][token1Exp][upperBound] != address(0)) revert DeployedError();
if (token0Exp > 18 || token0Exp < 6 || token1Exp > 18 || token1Exp < 6) revert ScaleError();
parameters =
Parameters({token0: token0, token1: token1, token0Exp: token0Exp, token1Exp: token1Exp, upperBound: upperBound});
lendgine = address(new Lendgine{ salt: keccak256(abi.encode(token0, token1, token0Exp, token1Exp, upperBound)) }());
delete parameters;
getLendgine[token0][token1][token0Exp][token1Exp][upperBound] = lendgine;
emit LendgineCreated(token0, token1, token0Exp, token1Exp, upperBound, lendgine);
}
}