-
Notifications
You must be signed in to change notification settings - Fork 156
Expand file tree
/
Copy pathDNFactory.sol
More file actions
72 lines (64 loc) · 2.25 KB
/
DNFactory.sol
File metadata and controls
72 lines (64 loc) · 2.25 KB
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
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.4;
import {LibClone} from "solady/utils/LibClone.sol";
import {DN404Cloneable} from "./example/DN404Cloneable.sol";
contract DNFactory {
error FailedToInitialize();
error ArrayLengthMismatch();
error InvalidLiquidityConfig();
error InvalidAllocations();
error EtherProvidedForZeroLiquidity();
error InvalidAirdropConfig();
address public immutable implementation;
struct Allocations {
uint80 liquidityAllocation;
uint80 teamAllocation;
uint80 airdropAllocation;
}
constructor() {
DN404Cloneable dn = new DN404Cloneable();
implementation = address(dn);
}
function deployDN(
string calldata name,
string calldata sym,
Allocations calldata allocations,
uint96 totalSupply,
uint256 liquidityLockPeriodInSeconds,
address[] calldata addresses,
uint256[] calldata amounts
) external payable returns (address tokenAddress) {
if (
allocations.liquidityAllocation + allocations.teamAllocation
+ allocations.airdropAllocation != totalSupply
) {
revert InvalidAllocations();
}
if (addresses.length != amounts.length) revert ArrayLengthMismatch();
if (
(addresses.length == 0 && allocations.airdropAllocation > 0)
|| (addresses.length != 0 && allocations.airdropAllocation == 0)
) revert InvalidAirdropConfig();
if (
(allocations.liquidityAllocation != 0 && msg.value == 0)
|| (allocations.liquidityAllocation == 0 && msg.value > 0)
) {
revert InvalidLiquidityConfig();
}
tokenAddress =
LibClone.cloneDeterministic(implementation, keccak256(abi.encodePacked(name)));
(bool success,) = tokenAddress.call{value: msg.value}(
abi.encodeWithSelector(
DN404Cloneable.initialize.selector,
name,
sym,
allocations,
totalSupply,
liquidityLockPeriodInSeconds,
addresses,
amounts
)
);
if (!success) revert FailedToInitialize();
}
}