forked from JessicaChg/semanticSBT
-
Notifications
You must be signed in to change notification settings - Fork 1
/
DaoRegister.sol
77 lines (56 loc) · 2.76 KB
/
DaoRegister.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;
import "@openzeppelin/contracts/utils/Strings.sol";
import "../core/SemanticSBTUpgradeable.sol";
import "../interfaces/social/IDaoRegister.sol";
import "../interfaces/social/IDao.sol";
import {DaoRegisterLogic} from "../libraries/DaoRegisterLogic.sol";
contract DaoRegister is IDaoRegister, SemanticSBTUpgradeable {
using Strings for uint256;
using Strings for address;
struct DaoStruct {
address owner;
address contractAddress;
}
uint256 constant DAO_CONTRACT_PREDICATE_INDEX = 1;
uint256 constant SOUL_CLASS_INDEX = 1;
uint256 constant CONTRACT_CLASS_INDEX = 2;
mapping(uint256 => DaoStruct) _daoOf;
string public daoBaseURI;
address public daoImpl;
address public verifyContract;
function setDaoVerifyContract(address _verifyContract) external onlyMinter {
verifyContract = _verifyContract;
}
function setDaoBaseURI(string calldata daoBaseURI_) external onlyOwner {
daoBaseURI = daoBaseURI_;
}
function setDaoImpl(address _daoImpl) external onlyOwner {
daoImpl = _daoImpl;
}
function deployDaoContract(address to, string calldata name_) external returns (uint256){
require(daoImpl != address(0), "DaoRegister:daoImpl not set");
require(to == msg.sender || _minters[msg.sender], "DaoRegister:permission Denied");
uint256 tokenId = _addEmptyToken(to, 0);
address daoContractAddress = DaoRegisterLogic.createDao(daoImpl, verifyContract, to, address(this), name_, daoBaseURI);
_daoOf[tokenId] = DaoStruct(to, daoContractAddress);
uint256 contractIndex = SemanticSBTLogicUpgradeable.addSubject(daoContractAddress.toHexString(), _classNames[CONTRACT_CLASS_INDEX], _subjects, _subjectIndex, _classIndex);
SubjectPO[] memory subjectPOList = generateSubjectPOList(contractIndex);
_mint(tokenId, to, new IntPO[](0), new StringPO[](0), new AddressPO[](0), subjectPOList, new BlankNodePO[](0));
return tokenId;
}
function daoOf(uint256 tokenId) external view returns (address daoOwner, address contractAddress){
DaoStruct memory dao = _daoOf[tokenId];
daoOwner = dao.owner;
contractAddress = dao.contractAddress;
}
function supportsInterface(bytes4 interfaceId) public view virtual override(SemanticSBTUpgradeable) returns (bool) {
return interfaceId == type(IDaoRegister).interfaceId ||
super.supportsInterface(interfaceId);
}
function generateSubjectPOList(uint256 contractIndex) internal pure returns (SubjectPO[] memory) {
SubjectPO[] memory subjectPOList = new SubjectPO[](1);
subjectPOList[0] = SubjectPO(DAO_CONTRACT_PREDICATE_INDEX, contractIndex);
return subjectPOList;
}
}