-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStablePoolFactory..sol
55 lines (40 loc) · 1.81 KB
/
StablePoolFactory..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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;
import {PoolDeployer} from "./abstract/PoolDeployer.sol";
import {StablePool} from "./StablePool.sol";
import {IStablePoolFactory} from "./interfaces/IStablePoolFactory.sol";
import {IDeployer} from "./interfaces/IDeployer.sol";
contract StablePoolFactory is IStablePoolFactory, PoolDeployer {
bytes32 public constant bytecodeHash = keccak256(type(StablePool).creationCode);
bytes private cachedDeployData;
constructor(address _masterDeployer) PoolDeployer(_masterDeployer) {}
function deployPool(bytes memory _deployData) external returns (address pool) {
(address tokenA, address tokenB, uint256 swapFee) = abi.decode(_deployData, (address, address, uint256));
if (tokenA > tokenB) {
(tokenA, tokenB) = (tokenB, tokenA);
}
// Strips any extra data.
_deployData = abi.encode(tokenA, tokenB, swapFee);
address[] memory tokens = new address[](2);
tokens[0] = tokenA;
tokens[1] = tokenB;
bytes32 salt = keccak256(_deployData);
cachedDeployData = _deployData;
pool = address(new StablePool{salt: salt}());
cachedDeployData = "";
_registerPool(pool, tokens, salt);
}
// This called in the StablePool constructor.
function getDeployData() external view override returns (bytes memory, IDeployer) {
return (cachedDeployData, IDeployer(masterDeployer));
}
function calculatePoolAddress(
address token0,
address token1,
uint256 swapFee
) external view returns (address) {
bytes32 salt = keccak256(abi.encode(token0, token1, swapFee));
bytes32 hash = keccak256(abi.encodePacked(bytes1(0xff), address(this), salt, bytecodeHash));
return address(uint160(uint256(hash)));
}
}