-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from volkanguneri/fix/factory
add clone to fix contract creation
- Loading branch information
Showing
7 changed files
with
107 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,35 @@ | ||
#!/bin/bash | ||
|
||
while true | ||
do | ||
echo "Welcome to the deployment menu" | ||
echo "Please select an option:" | ||
|
||
PS3='Choose a deployment option: ' | ||
options=("Tests" "Deploy Local" "Deploy Harmonie Testnet" "Quit") | ||
select opt in "${options[@]}" | ||
do | ||
case $opt in | ||
"Tests") | ||
echo "Testing the contracts on localhost network" | ||
REPORT_GAS=true npx hardhat coverage | ||
break | ||
;; | ||
"Deploy Local") | ||
echo "Deploying contracts on localhost network" | ||
npx hardhat run scripts/deploy.js --network localhost | ||
break | ||
;; | ||
"Deploy Harmonie Testnet") | ||
echo "Deploying factory on localhost network" | ||
npx hardhat run scripts/deploy.js --network localhost | ||
break | ||
;; | ||
"Quit") | ||
echo "Exiting..." | ||
exit 0 | ||
;; | ||
*) echo "Invalid option $REPLY";; | ||
esac | ||
done | ||
done | ||
#!/bin/bash | ||
|
||
while true | ||
do | ||
echo "Welcome to the deployment menu" | ||
echo "Please select an option:" | ||
|
||
PS3='Choose a deployment option: ' | ||
options=("Tests" "Deploy Local" "Deploy Harmonie Testnet" "Quit") | ||
select opt in "${options[@]}" | ||
do | ||
case $opt in | ||
"Tests") | ||
echo "Testing the contracts on localhost network" | ||
REPORT_GAS=true npx hardhat coverage | ||
break | ||
;; | ||
"Deploy Local") | ||
echo "Deploying contracts on localhost network" | ||
npx hardhat run scripts/deploy.js --network localhost | ||
break | ||
;; | ||
"Deploy Harmonie Testnet") | ||
echo "Deploying factory on localhost network" | ||
npx hardhat run scripts/deploy.js --network localhost | ||
break | ||
;; | ||
"Quit") | ||
echo "Exiting..." | ||
exit 0 | ||
;; | ||
*) echo "Invalid option $REPLY";; | ||
esac | ||
done | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.24; | ||
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; | ||
import "@openzeppelin/contracts/proxy/Clones.sol"; | ||
import "./Albums.sol"; | ||
/// @custom:security-contact [email protected] | ||
/** | ||
|
@@ -30,12 +31,15 @@ contract Admins is Ownable{ | |
mapping(address => address) public adminsContracts; | ||
address[] public adminsAccounts; | ||
address[] private superAdminsAccounts; | ||
|
||
address private immutable _albumsTemplate; | ||
|
||
/** | ||
* @dev Constructor that sets the deployer as the initial admin. | ||
*/ | ||
constructor(address initialOwner) Ownable(initialOwner){ | ||
adminRoles[initialOwner] = Role.SuperAdmin; | ||
_albumsTemplate = address(new Albums()); | ||
} | ||
|
||
/** | ||
|
@@ -117,26 +121,17 @@ contract Admins is Ownable{ | |
require(ensureAdminDoNotExist(newAdmin), "admin exists"); | ||
require(ensureSuperAdmin(msg.sender), "not super admin"); | ||
require(adminRoles[newAdmin] == Role.None, "role already set"); | ||
// todo factory call to deploy the contract and get the deployment address deployment address | ||
|
||
adminRoles[newAdmin] = Role.Admin; | ||
bytes memory collectionBytecode = type(Albums).creationCode; | ||
bytes32 salt = keccak256(abi.encodePacked(newAdmin, block.timestamp)); | ||
address collectionAddress; | ||
// assembly { | ||
// collectionAddress := create2( | ||
// 0, | ||
// add(collectionBytecode, 0x20), | ||
// mload(collectionBytecode), | ||
// salt | ||
// ) | ||
// if iszero(extcodesize(collectionAddress)) { | ||
// // revert if something gone wrong (collectionAddress doesn't contain an address) | ||
// revert(0, 0) | ||
// } | ||
// } | ||
adminsContracts[newAdmin] = collectionAddress; // change this with deployed address | ||
adminsAccounts.push(collectionAddress); | ||
emit Granted(msg.sender,newAdmin, Role.Admin, collectionAddress); | ||
|
||
address clone = Clones.clone(_albumsTemplate); | ||
Albums(clone).initialize( | ||
newAdmin | ||
); | ||
|
||
adminsContracts[newAdmin] = clone; | ||
adminsAccounts.push(clone); | ||
emit Granted(msg.sender, newAdmin, Role.Admin, clone); | ||
} | ||
|
||
function removeAdmin(address oldAdmin) external { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters