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
/
RedeemableERC20Factory.sol
51 lines (46 loc) · 1.72 KB
/
RedeemableERC20Factory.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
// SPDX-License-Identifier: CAL
pragma solidity =0.8.10;
import {Factory} from "../factory/Factory.sol";
import {RedeemableERC20, RedeemableERC20Config} from "./RedeemableERC20.sol";
import {ITier} from "../tier/ITier.sol";
import "@openzeppelin/contracts/proxy/Clones.sol";
/// @title RedeemableERC20Factory
/// @notice Factory for deploying and registering `RedeemableERC20` contracts.
contract RedeemableERC20Factory is Factory {
/// Template contract to clone.
/// Deployed by the constructor.
address public immutable implementation;
/// Build the reference implementation to clone for each child.
constructor() {
address implementation_ = address(new RedeemableERC20());
emit Implementation(msg.sender, implementation_);
implementation = implementation_;
}
/// @inheritdoc Factory
function _createChild(bytes calldata data_)
internal
virtual
override
returns (address)
{
RedeemableERC20Config memory config_ = abi.decode(
data_,
(RedeemableERC20Config)
);
address clone_ = Clones.clone(implementation);
RedeemableERC20(clone_).initialize(config_);
return clone_;
}
/// Allows calling `createChild` with `RedeemableERC20Config` struct.
/// Use original `Factory` `createChild` function signature if function
/// parameters are already encoded.
///
/// @param config_ `RedeemableERC20` constructor configuration.
/// @return New `RedeemableERC20` child contract.
function createChildTyped(RedeemableERC20Config calldata config_)
external
returns (RedeemableERC20)
{
return RedeemableERC20(this.createChild(abi.encode(config_)));
}
}