-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathNFTXEligibilityManager.sol
88 lines (78 loc) · 2.84 KB
/
NFTXEligibilityManager.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
// SPDX-License-Identifier: UNLICENSED
pragma experimental ABIEncoderV2;
pragma solidity ^0.8.0;
import {INFTXEligibility} from "@src/interfaces/INFTXEligibility.sol";
import {ClonesUpgradeable} from "@openzeppelin-upgradeable/contracts/proxy/ClonesUpgradeable.sol";
import {OwnableUpgradeable} from "@openzeppelin-upgradeable/contracts/access/OwnableUpgradeable.sol";
contract NFTXEligibilityManager is OwnableUpgradeable {
struct EligibilityModule {
address implementation;
address targetAsset;
string name;
}
EligibilityModule[] public modules;
event ModuleAdded(
address implementation,
address targetAsset,
string name,
bool finalizedOnDeploy
);
event ModuleUpdated(
address implementation,
string name,
bool finalizedOnDeploy
);
function __NFTXEligibilityManager_init() public initializer {
__Ownable_init();
}
function addModule(address implementation) external onlyOwner {
require(implementation != address(0), "Impl != address(0)");
INFTXEligibility elig = INFTXEligibility(implementation);
string memory name = elig.name();
EligibilityModule memory module = EligibilityModule(
implementation,
elig.targetAsset(),
name
);
modules.push(module);
emit ModuleAdded(
implementation,
module.targetAsset,
name,
elig.finalized()
);
}
function updateModule(
uint256 moduleIndex,
address implementation
) external onlyOwner {
require(moduleIndex < modules.length, "Out of bounds");
require(implementation != address(0), "Impl != address(0)");
modules[moduleIndex].implementation = implementation;
INFTXEligibility elig = INFTXEligibility(implementation);
emit ModuleUpdated(implementation, elig.name(), elig.finalized());
}
function deployEligibility(
uint256 moduleIndex,
bytes calldata configData
) external virtual returns (address) {
require(moduleIndex < modules.length, "Out of bounds");
address eligImpl = modules[moduleIndex].implementation;
address eligibilityClone = ClonesUpgradeable.clone(eligImpl);
INFTXEligibility(eligibilityClone).__NFTXEligibility_init_bytes(
configData
);
return eligibilityClone;
}
function allModules() external view returns (EligibilityModule[] memory) {
return modules;
}
function allModuleNames() external view returns (string[] memory) {
EligibilityModule[] memory modulesCopy = modules;
string[] memory names = new string[](modulesCopy.length);
for (uint256 i = 0; i < modulesCopy.length; i++) {
names[i] = modulesCopy[i].name;
}
return names;
}
}