opt factory

main
cyhhao 2 years ago
parent a2b9329a79
commit 22d19ea1fb

@ -1,4 +1,4 @@
//SPDX-License-Identifier: Unlicense
//SPDX-License-Identifier: GLP-3.0
pragma solidity ^0.8.0;
// import "hardhat/console.sol";

@ -1,4 +1,4 @@
//SPDX-License-Identifier: Unlicense
//SPDX-License-Identifier: GLP-3.0
pragma solidity ^0.8.0;
contract Git3HubStorage_SLI {

@ -1,4 +1,4 @@
//SPDX-License-Identifier: Unlicense
//SPDX-License-Identifier: GLP-3.0
pragma solidity ^0.8.0;
contract Hello{

@ -3,6 +3,7 @@ pragma solidity ^0.8.0;
contract Git3NameService {
mapping(string => address) public nameHub;
mapping(address => string) public hubName;
mapping(string => address) public nameOwner;
string[] public nameList;
@ -18,6 +19,7 @@ contract Git3NameService {
function registerHub(string memory name, address hub) public {
require(nameHub[name] == address(0), "Name already registered");
nameHub[name] = hub;
hubName[hub] = name;
nameOwner[name] = msg.sender;
nameList.push(name);
}
@ -31,6 +33,7 @@ contract Git3NameService {
address hub
) public onlyHubOwner(name) {
nameHub[name] = hub;
hubName[hub] = name;
}
function transferNameOwner(

@ -1,3 +1,4 @@
//SPDX-License-Identifier: GLP-3.0
pragma solidity ^0.8.0;
// import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
@ -8,12 +9,14 @@ import "./Hubv3.sol";
contract HubFactory is Ownable {
event CreateHub(address indexed hub, address indexed creator);
bool public dbSelector;
address[] public hubs;
Hubv3 public hubImp;
// function initialize() initializer public {
// __Ownable_init();
// }
constructor(bool _dbSelector) {
dbSelector = _dbSelector;
}
function newHubImp() public onlyOwner {
hubImp = new Hubv3();
@ -23,10 +26,10 @@ contract HubFactory is Ownable {
hubImp = Hubv3(addr);
}
function createHub(bool dbSelector) external {
function createHub(bool isPermissionless) external{
address instance = Clones.clone(address(hubImp));
hubs.push(instance);
Hubv3(instance).initialize(dbSelector, _msgSender());
Hubv3(instance).initialize(dbSelector, _msgSender(), isPermissionless);
emit CreateHub(instance, _msgSender());
}
}

@ -1,3 +1,4 @@
//SPDX-License-Identifier: GLP-3.0
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/access/AccessControl.sol";
@ -41,11 +42,16 @@ contract Hubv3 is AccessControl, Initializable {
_setRoleAdmin(CONTRIBUTOR, MANAGER);
}
function initialize(bool dbSelector, address user) public initializer {
function initialize(
bool dbSelector,
address user,
bool isPermissionless
) public initializer {
_setupRole(AccessControl.DEFAULT_ADMIN_ROLE, user);
_setupRole(MANAGER, user);
_setRoleAdmin(CONTRIBUTOR, MANAGER);
_newDataBase(dbSelector);
permissionless = isPermissionless;
}
// ===== hub operator functions======
@ -226,9 +232,9 @@ contract Hubv3 is AccessControl, Initializable {
}
// ===== database operator functions======
function newDataBase(bool flag) public onlyRole(DEFAULT_ADMIN_ROLE) {
_newDataBase(flag);
}
// function newDataBase(bool flag) public onlyRole(DEFAULT_ADMIN_ROLE) {
// _newDataBase(flag);
// }
function _newDataBase(bool flag) internal {
if (flag) {
@ -253,4 +259,15 @@ contract Hubv3 is AccessControl, Initializable {
) external payable {
return db.upload(repoName, path, data);
}
function batchUpload(
bytes memory repoName,
bytes[] memory path,
bytes[] calldata data
) external payable {
require(path.length == data.length, "path and data length mismatch");
for (uint i = 0; i < path.length; i++) {
db.upload(repoName, path[i], data[i]);
}
}
}

@ -1,3 +1,4 @@
//SPDX-License-Identifier: GLP-3.0
pragma solidity ^0.8.0;
library Repolib {

@ -1,3 +1,4 @@
//SPDX-License-Identifier: GLP-3.0
pragma solidity ^0.8.0;
interface database {

@ -1,3 +1,4 @@
//SPDX-License-Identifier: GLP-3.0
pragma solidity ^0.8.0;
import "./EthStorage/LargeStorageManagerV2.sol";
import "./database.sol";

@ -1,3 +1,4 @@
//SPDX-License-Identifier: GLP-3.0
pragma solidity ^0.8.0;
import "./database.sol";

@ -1,32 +1,34 @@
import { ethers } from "hardhat";
async function main() {
let provider = ethers.provider
let [operator,] = await ethers.getSigners();
let nonce = await operator.getTransactionCount()
let provider = ethers.provider;
let [operator] = await ethers.getSigners();
let nonce = await operator.getTransactionCount();
let price = await provider.getFeeData()
console.log(price)
let price = await provider.getFeeData();
console.log(price);
console.log(operator.address, nonce)
console.log(operator.address, nonce);
const Git3Fac = await ethers.getContractFactory("HubFactory");
const hubFac = await Git3Fac.deploy({ nonce: nonce });
const hubFac = await Git3Fac.deploy(true, { nonce: nonce });
let logicReceipt = await hubFac.deployed();
console.log(logicReceipt.deployTransaction.hash);
nonce++;
let newHubReceipt = await hubFac.newHubImp({ nonce: nonce });
nonce++;
let logicReceipt = await hubFac.deployed()
console.log(logicReceipt.deployTransaction.hash)
nonce++
await newHubReceipt.wait();
await hubFac.newHubImp({ nonce: nonce });
nonce++
let createHubReceipt = await hubFac.createHub({ nonce: nonce });
nonce++;
await hubFac.createHub(true,{ nonce: nonce })
nonce++
await createHubReceipt.wait();
let hubAddr = await hubFac.hubs(0);
let git3 = await ethers.getContractAt("Hubv3",hubAddr)
let git3 = await ethers.getContractAt("Hubv3", hubAddr);
// console.log({logicReceipt,proxyReceipt});
console.log("HubFactory Contract", hubFac.address);

@ -1,31 +1,30 @@
import { ethers } from "hardhat";
async function main() {
let provider = ethers.provider
let [operator,] = await ethers.getSigners();
let nonce = await operator.getTransactionCount()
let provider = ethers.provider;
let [operator] = await ethers.getSigners();
let nonce = await operator.getTransactionCount();
let price = await provider.getFeeData();
console.log(price);
let price = await provider.getFeeData()
console.log(price)
console.log(operator.address, nonce)
console.log(operator.address, nonce);
const Git3Fac = await ethers.getContractFactory("HubFactory");
const hubFac = await Git3Fac.deploy({ nonce: nonce });
const hubFac = await Git3Fac.deploy(false, { nonce: nonce });
let logicReceipt = await hubFac.deployed()
console.log(logicReceipt.deployTransaction.hash)
nonce++
let logicReceipt = await hubFac.deployed();
console.log(logicReceipt.deployTransaction.hash);
nonce++;
await hubFac.newHubImp({ nonce: nonce });
nonce++
let newHubReceipt = await hubFac.newHubImp({ nonce: nonce });
nonce++;
await hubFac.createHub(false,{ nonce: nonce })
nonce++
let createHubReceipt = await hubFac.createHub({ nonce: nonce });
nonce++;
let hubAddr = await hubFac.hubs(0);
let git3 = await ethers.getContractAt("Hubv3",hubAddr)
let git3 = await ethers.getContractAt("Hubv3", hubAddr);
// console.log({logicReceipt,proxyReceipt});
console.log("HubFactory Contract", hubFac.address);

Loading…
Cancel
Save