-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoolFactory.sol
81 lines (71 loc) · 3.36 KB
/
PoolFactory.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
/**
* /-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\
* | |
* \ _____ ____ /
* -|_ _| / ___|_ ____ _ _ __ -
* / | |____\___ \ \ /\ / / _` | '_ \ \
* | | |_____|__) \ V V / (_| | |_) | |
* \ |_| |____/ \_/\_/ \__,_| .__/ /
* - |_| -
* / \
* | |
* \-/|\-/|\-/|\-/|\-/|\-/|\-/|\-/|\-/|\-/
*/
// SPDX-License-Identifier: GNU General Public License v3.0
pragma solidity 0.8.20;
import {TSwapPool} from "./TSwapPool.sol";
import {IERC20} from "forge-std/interfaces/IERC20.sol";
contract PoolFactory {
error PoolFactory__PoolAlreadyExists(address tokenAddress);
// @written-info - this error is not used
error PoolFactory__PoolDoesNotExist(address tokenAddress);
/*//////////////////////////////////////////////////////////////
STATE VARIABLES
//////////////////////////////////////////////////////////////*/
mapping(address token => address pool) private s_pools; // e probably pool token -> pool
mapping(address pool => address token) private s_tokens; // e mapping back
address private immutable i_wethToken;
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
event PoolCreated(address tokenAddress, address poolAddress);
/*//////////////////////////////////////////////////////////////
FUNCTIONS
//////////////////////////////////////////////////////////////*/
constructor(address wethToken) {
// @written-info - lacking zero address check
i_wethToken = wethToken;
}
/*//////////////////////////////////////////////////////////////
EXTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/
// e tokenAddress -> weth for a token/weth pool
function createPool(address tokenAddress) external returns (address) {
if (s_pools[tokenAddress] != address(0)) {
revert PoolFactory__PoolAlreadyExists(tokenAddress);
}
// e "T-Swap DAI"
// q wierd ERC20 " what if the name function reverts"
string memory liquidityTokenName = string.concat("T-Swap ", IERC20(tokenAddress).name());
// "tsUSDC"
// @written-info this should not be .symbol() not .name()
string memory liquidityTokenSymbol = string.concat("ts", IERC20(tokenAddress).name());
TSwapPool tPool = new TSwapPool(tokenAddress, i_wethToken, liquidityTokenName, liquidityTokenSymbol);
s_pools[tokenAddress] = address(tPool);
s_tokens[address(tPool)] = tokenAddress;
emit PoolCreated(tokenAddress, address(tPool));
return address(tPool);
}
/*//////////////////////////////////////////////////////////////
EXTERNAL AND PUBLIC VIEW AND PURE
//////////////////////////////////////////////////////////////*/
function getPool(address tokenAddress) external view returns (address) {
return s_pools[tokenAddress];
}
function getToken(address pool) external view returns (address) {
return s_tokens[pool];
}
function getWethToken() external view returns (address) {
return i_wethToken;
}
}