This repository has been archived by the owner on Dec 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
TrustFactory.sol
102 lines (90 loc) · 3.79 KB
/
TrustFactory.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
90
91
92
93
94
95
96
97
98
99
100
101
102
// SPDX-License-Identifier: CAL
pragma solidity ^0.8.10;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {ITier} from "../tier/ITier.sol";
import "@openzeppelin/contracts/proxy/Clones.sol";
import {Factory} from "../factory/Factory.sol";
import {Trust, TrustConstructionConfig, TrustConfig} from "../trust/Trust.sol";
// solhint-disable-next-line max-line-length
import {RedeemableERC20Factory} from "../redeemableERC20/RedeemableERC20Factory.sol";
// solhint-disable-next-line max-line-length
import {RedeemableERC20, RedeemableERC20Config} from "../redeemableERC20/RedeemableERC20.sol";
import {SeedERC20Factory} from "../seed/SeedERC20Factory.sol";
// solhint-disable-next-line max-line-length
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {TrustRedeemableERC20Config, TrustSeedERC20Config} from "./Trust.sol";
import {BPoolFeeEscrow} from "../escrow/BPoolFeeEscrow.sol";
import {ERC20Config} from "../erc20/ERC20Config.sol";
/// @title TrustFactory
/// @notice The `TrustFactory` contract is the only contract that the
/// deployer uses to deploy all contracts for a single project
/// fundraising event. It takes references to
/// `RedeemableERC20Factory`, `RedeemableERC20PoolFactory` and
/// `SeedERC20Factory` contracts, and builds a new `Trust` contract.
/// @dev Factory for creating and registering new Trust contracts.
contract TrustFactory is Factory {
using SafeERC20 for RedeemableERC20;
/// Template contract to clone.
/// Deployed by the constructor.
address private immutable implementation;
/// Build the reference implementation to clone for each child.
/// @param config_ All configuration for the `TrustFactory`.
constructor(TrustConstructionConfig memory config_) {
address implementation_ = address(new Trust(config_));
// This silences slither.
require(implementation_ != address(0), "TRUST_0");
emit Implementation(msg.sender, implementation_);
implementation = implementation_;
}
/// Allows calling `createChild` with TrustConfig,
/// TrustRedeemableERC20Config and
/// TrustRedeemableERC20PoolConfig parameters.
/// Can use original Factory `createChild` function signature if function
/// parameters are already encoded.
///
/// @param trustConfig_ Trust constructor configuration.
/// @param trustRedeemableERC20Config_ RedeemableERC20
/// constructor configuration.
/// @param trustSeedERC20Config_ SeedERC20
/// constructor configuration.
/// @return New Trust child contract address.
function createChildTyped(
TrustConfig calldata trustConfig_,
TrustRedeemableERC20Config calldata trustRedeemableERC20Config_,
TrustSeedERC20Config calldata trustSeedERC20Config_
) external returns (Trust) {
return
Trust(
this.createChild(
abi.encode(
trustConfig_,
trustRedeemableERC20Config_,
trustSeedERC20Config_
)
)
);
}
/// @inheritdoc Factory
function _createChild(bytes calldata data_)
internal
virtual
override
returns (address)
{
(
TrustConfig memory trustConfig_,
TrustRedeemableERC20Config memory trustRedeemableERC20Config_,
TrustSeedERC20Config memory trustSeedERC20Config_
) = abi.decode(
data_,
(TrustConfig, TrustRedeemableERC20Config, TrustSeedERC20Config)
);
address clone_ = Clones.clone(implementation);
Trust(clone_).initialize(
trustConfig_,
trustRedeemableERC20Config_,
trustSeedERC20Config_
);
return clone_;
}
}