Skip to content

Commit 675dee5

Browse files
Merge branch 'main' into volkan
2 parents d8b3f0d + 14f395a commit 675dee5

File tree

7 files changed

+4443
-4205
lines changed

7 files changed

+4443
-4205
lines changed

.github/workflows/ci.yml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: CI
2+
3+
# Controls when the workflow will run
4+
on: push
5+
6+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
7+
jobs:
8+
# This workflow contains a single job called "build"
9+
build:
10+
# The type of runner that the job will run on
11+
runs-on: ubuntu-latest
12+
defaults:
13+
run:
14+
working-directory: ./backend
15+
16+
# Steps represent a sequence of tasks that will be executed as part of the job
17+
steps:
18+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
19+
- uses: actions/checkout@v3
20+
- uses: actions/setup-node@v3
21+
with:
22+
node-version: 20.0.0
23+
24+
- name: Setup yarn
25+
run: npm install -g yarn
26+
27+
- name: Install Dependencies
28+
run: yarn install
29+
30+
# Compile
31+
- name: Compile
32+
run: yarn hardhat compile
33+
34+
# Solhint
35+
- name: Linter
36+
run: yarn hardhat check
37+
38+
# Tests
39+
- name: Test
40+
run: REPORT_GAS=true yarn hardhat test
41+
42+
# Coverage
43+
- name: Coverage
44+
id: coverage
45+
run: yarn hardhat coverage

README.md

+20-13
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
## Dependencies
2-
3-
### Backend
4-
5-
To install the backend dependencies, navigate to the backend directory and run:
6-
7-
`yarn install`
8-
9-
### Frontend
10-
11-
To install the frontend dependencies, navigate to the frontend directory and run:
12-
13-
`npm install`
1+
[![CI](https://github.com/volkanguneri/Allfeat-Hackaton-Musicmint/actions/workflows/ci.yml/badge.svg)](https://github.com/volkanguneri/Allfeat-Hackaton-Musicmint/actions/workflows/ci.yml)
2+
3+
## Dependencies
4+
5+
### Backend
6+
7+
To install the backend dependencies, navigate to the backend directory and run:
8+
9+
`yarn install`
10+
11+
To see available options, run:
12+
```
13+
sh a_launcher.sh
14+
```
15+
16+
### Frontend
17+
18+
To install the frontend dependencies, navigate to the frontend directory and run:
19+
20+
`npm install`

backend/contracts/Admins.sol

+155-135
Original file line numberDiff line numberDiff line change
@@ -1,135 +1,155 @@
1-
// SPDX-License-Identifier: MIT
2-
pragma solidity ^0.8.24;
3-
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
4-
/// @custom:security-contact [email protected]
5-
/**
6-
* @title Admins Contract
7-
* @dev Manages administrative privileges in a smart contract system.
8-
* @notice This contract allows for the addition and removal of admin addresses.
9-
*/
10-
contract Admins is Ownable{
11-
12-
event Granted (
13-
/// Granter of the role.
14-
address from,
15-
/// Grantee of the role.
16-
address to,
17-
/// The role granted.
18-
Role role,
19-
address contractt
20-
);
21-
22-
enum Role {
23-
None,
24-
Admin,
25-
SuperAdmin
26-
}
27-
// Mapping of the user roles.
28-
mapping(address => Role) public adminRoles;
29-
mapping(address => address) public adminsContracts;
30-
address[] public adminsAccounts;
31-
address[] private superAdminsAccounts;
32-
33-
/**
34-
* @dev Constructor that sets the deployer as the initial admin.
35-
*/
36-
constructor(address initialOwner) Ownable(initialOwner){
37-
adminRoles[initialOwner] = Role.SuperAdmin;
38-
}
39-
40-
/**
41-
* @dev Checks if the given address is assigned the SuperAdmin role.
42-
* This function is internal and can be used within the contract to ensure that
43-
* an operation is being performed by a SuperAdmin.
44-
* @param _addr The address to check for the SuperAdmin role.
45-
* @return bool Returns true if the address is a SuperAdmin, false otherwise.
46-
*/
47-
function ensureSuperAdmin(address _addr) internal view returns (bool){
48-
return uint(adminRoles[_addr]) == uint(Role.SuperAdmin);
49-
}
50-
51-
/**
52-
* @dev Ensures that the given address is not already present in the `adminsAccounts` array.
53-
* This check helps in avoiding duplicate admin entries. Since this function iterates
54-
* over the `adminsAccounts` array, be cautious of gas costs when the array size grows.
55-
* @param _addr The address to verify against the admin accounts mapping.
56-
* @return bool Returns true if the address is not an admin, false if it already exists as an admin.
57-
*/
58-
function ensureAdminDoNotExist(address _addr) internal view returns (bool){
59-
return uint(adminRoles[_addr]) == uint(Role.None);
60-
}
61-
62-
/**
63-
* @dev Verifies that the given address is not already listed in the `superAdminsAccounts` array.
64-
* Useful for maintaining a clean list of SuperAdmins without duplicates. As with `ensureAdminDoNotExist`,
65-
* be mindful of potential gas costs due to array iteration.
66-
* @param _addr The address to check against the super admin accounts list.
67-
* @return bool Returns true if the address is not a super admin, false if it already exists as a super admin.
68-
*/
69-
function ensureSuperAdminDoNotExist(address _addr) internal view returns (bool){
70-
return uint(adminRoles[_addr]) == uint(Role.None);
71-
}
72-
73-
/**
74-
* @dev Adds a new SuperAdmin to the contract.
75-
* This function can only be called by the contract owner. It ensures that the address being added does not already exist as either a SuperAdmin or Admin. After verification, it assigns the SuperAdmin role to the address and emits an event.
76-
* @param _addr Address to be added as a SuperAdmin.
77-
* @notice This action is irreversible through this function and can only be performed by the contract owner.
78-
*/
79-
function addSuperAdmin(address _addr) external onlyOwner {
80-
require(ensureSuperAdminDoNotExist(_addr) && ensureAdminDoNotExist(_addr), "role already set");
81-
// todo factory call to deploy the contract and get the deployment address deployment address
82-
address _deployedTO = address(0);
83-
adminRoles[_addr] = Role.SuperAdmin;
84-
superAdminsAccounts.push(_addr);
85-
emit Granted(msg.sender,_addr, Role.SuperAdmin, _deployedTO);
86-
}
87-
88-
/**
89-
* @dev Removes a super administrator from the contract.
90-
* This function allows the contract owner to remove an address from the list of super administrators.
91-
* It updates the admin's role to 'None' and emits a 'Granted' event indicating the role change.
92-
* Note: This function should be called only by the contract owner.
93-
* @param _addr The address to be removed from the super administrators list.
94-
* @notice Ensure that the address being removed is indeed a super administrator and that
95-
* you have the necessary permissions to perform this action.
96-
*/
97-
function removeSuperAdmin(address _addr) external onlyOwner {
98-
for (uint256 i = 0; i < superAdminsAccounts.length; i++) {
99-
if (superAdminsAccounts[i] == _addr) {
100-
delete superAdminsAccounts[i];
101-
}
102-
}
103-
//address _deployedTO = address(0);
104-
adminRoles[_addr] = Role.None;
105-
superAdminsAccounts.push(_addr);
106-
emit Granted(msg.sender,_addr, Role.None, _addr);
107-
}
108-
109-
/**
110-
* @dev Adds a new admin.
111-
* @param newAdmin Address to be added as admin.
112-
* @notice Only existing superadmins can add new admins.
113-
//TODO newContract will be removed to be used after deploy
114-
*/
115-
function addAdmin(address newAdmin, address newContract) external {
116-
require(ensureAdminDoNotExist(newAdmin), "admin exists");
117-
require(ensureSuperAdmin(msg.sender), "not super admin");
118-
require(adminRoles[newAdmin] == Role.None, "role already set");
119-
// todo factory call to deploy the contract and get the deployment address deployment address
120-
adminRoles[newAdmin] = Role.Admin;
121-
adminsContracts[newAdmin] = newAdmin; // change this with deployed adress
122-
adminsAccounts.push(newAdmin);
123-
emit Granted(msg.sender,newAdmin, Role.Admin , newContract);
124-
}
125-
126-
function removeAdmin(address oldAdmin) external {
127-
require(ensureSuperAdmin(msg.sender), "not super admin caller");
128-
require(adminRoles[oldAdmin] == Role.Admin, "not an admin");
129-
// todo factory call to deploy the contract and get the deployment address deployment address
130-
adminRoles[oldAdmin] = Role.None;
131-
// deal with adminsContracts[oldAdmin] ?
132-
// remove it ? adminsAccounts.push(oldAdmin);
133-
emit Granted(msg.sender,oldAdmin, Role.None , oldAdmin);
134-
}
135-
}
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.24;
3+
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
4+
import "./Albums.sol";
5+
/// @custom:security-contact [email protected]
6+
/**
7+
* @title Admins Contract
8+
* @dev Manages administrative privileges in a smart contract system.
9+
* @notice This contract allows for the addition and removal of admin addresses.
10+
*/
11+
contract Admins is Ownable{
12+
13+
event Granted (
14+
/// Granter of the role.
15+
address from,
16+
/// Grantee of the role.
17+
address to,
18+
/// The role granted.
19+
Role role,
20+
address contractt
21+
);
22+
23+
enum Role {
24+
None,
25+
Admin,
26+
SuperAdmin
27+
}
28+
// Mapping of the user roles.
29+
mapping(address => Role) public adminRoles;
30+
mapping(address => address) public adminsContracts;
31+
address[] public adminsAccounts;
32+
address[] private superAdminsAccounts;
33+
34+
/**
35+
* @dev Constructor that sets the deployer as the initial admin.
36+
*/
37+
constructor(address initialOwner) Ownable(initialOwner){
38+
adminRoles[initialOwner] = Role.SuperAdmin;
39+
}
40+
41+
/**
42+
* @dev Checks if the given address is assigned the SuperAdmin role.
43+
* This function is internal and can be used within the contract to ensure that
44+
* an operation is being performed by a SuperAdmin.
45+
* @param _addr The address to check for the SuperAdmin role.
46+
* @return bool Returns true if the address is a SuperAdmin, false otherwise.
47+
*/
48+
function ensureSuperAdmin(address _addr) internal view returns (bool){
49+
return uint(adminRoles[_addr]) == uint(Role.SuperAdmin);
50+
}
51+
52+
/**
53+
* @dev Ensures that the given address is not already present in the `adminsAccounts` array.
54+
* This check helps in avoiding duplicate admin entries. Since this function iterates
55+
* over the `adminsAccounts` array, be cautious of gas costs when the array size grows.
56+
* @param _addr The address to verify against the admin accounts mapping.
57+
* @return bool Returns true if the address is not an admin, false if it already exists as an admin.
58+
*/
59+
function ensureAdminDoNotExist(address _addr) internal view returns (bool){
60+
return uint(adminRoles[_addr]) == uint(Role.None);
61+
}
62+
63+
/**
64+
* @dev Verifies that the given address is not already listed in the `superAdminsAccounts` array.
65+
* Useful for maintaining a clean list of SuperAdmins without duplicates. As with `ensureAdminDoNotExist`,
66+
* be mindful of potential gas costs due to array iteration.
67+
* @param _addr The address to check against the super admin accounts list.
68+
* @return bool Returns true if the address is not a super admin, false if it already exists as a super admin.
69+
*/
70+
function ensureSuperAdminDoNotExist(address _addr) internal view returns (bool){
71+
return uint(adminRoles[_addr]) == uint(Role.None);
72+
}
73+
74+
/**
75+
* @dev Adds a new SuperAdmin to the contract.
76+
* This function can only be called by the contract owner. It ensures that the address being added does not already exist as either a SuperAdmin or Admin. After verification, it assigns the SuperAdmin role to the address and emits an event.
77+
* @param _addr Address to be added as a SuperAdmin.
78+
* @notice This action is irreversible through this function and can only be performed by the contract owner.
79+
*/
80+
function addSuperAdmin(address _addr) external onlyOwner {
81+
require(ensureSuperAdminDoNotExist(_addr) && ensureAdminDoNotExist(_addr), "role already set");
82+
// todo factory call to deploy the contract and get the deployment address deployment address
83+
address _deployedTO = address(0);
84+
adminRoles[_addr] = Role.SuperAdmin;
85+
superAdminsAccounts.push(_addr);
86+
emit Granted(msg.sender,_addr, Role.SuperAdmin, _deployedTO);
87+
}
88+
89+
/**
90+
* @dev Removes a super administrator from the contract.
91+
* This function allows the contract owner to remove an address from the list of super administrators.
92+
* It updates the admin's role to 'None' and emits a 'Granted' event indicating the role change.
93+
* Note: This function should be called only by the contract owner.
94+
* @param _addr The address to be removed from the super administrators list.
95+
* @notice Ensure that the address being removed is indeed a super administrator and that
96+
* you have the necessary permissions to perform this action.
97+
*/
98+
function removeSuperAdmin(address _addr) external onlyOwner {
99+
for (uint256 i = 0; i < superAdminsAccounts.length; i++) {
100+
if (superAdminsAccounts[i] == _addr) {
101+
delete superAdminsAccounts[i];
102+
}
103+
}
104+
//address _deployedTO = address(0);
105+
adminRoles[_addr] = Role.None;
106+
superAdminsAccounts.push(_addr);
107+
emit Granted(msg.sender,_addr, Role.None, _addr);
108+
}
109+
110+
/**
111+
* @dev Adds a new admin.
112+
* @param newAdmin Address to be added as admin.
113+
* @notice Only existing superadmins can add new admins.
114+
//TODO newContract will be removed to be used after deploy
115+
*/
116+
function addAdmin(address newAdmin) external {
117+
require(ensureAdminDoNotExist(newAdmin), "admin exists");
118+
require(ensureSuperAdmin(msg.sender), "not super admin");
119+
require(adminRoles[newAdmin] == Role.None, "role already set");
120+
// todo factory call to deploy the contract and get the deployment address deployment address
121+
adminRoles[newAdmin] = Role.Admin;
122+
bytes memory collectionBytecode = type(Albums).creationCode;
123+
bytes32 salt = keccak256(abi.encodePacked(newAdmin, block.timestamp));
124+
address collectionAddress;
125+
// assembly {
126+
// collectionAddress := create2(
127+
// 0,
128+
// add(collectionBytecode, 0x20),
129+
// mload(collectionBytecode),
130+
// salt
131+
// )
132+
// if iszero(extcodesize(collectionAddress)) {
133+
// // revert if something gone wrong (collectionAddress doesn't contain an address)
134+
// revert(0, 0)
135+
// }
136+
// }
137+
adminsContracts[newAdmin] = collectionAddress; // change this with deployed address
138+
adminsAccounts.push(collectionAddress);
139+
emit Granted(msg.sender,newAdmin, Role.Admin, collectionAddress);
140+
}
141+
142+
function removeAdmin(address oldAdmin) external {
143+
require(ensureSuperAdmin(msg.sender), "not super admin caller");
144+
require(adminRoles[oldAdmin] == Role.Admin, "not an admin");
145+
// todo factory call to deploy the contract and get the deployment address deployment address
146+
adminRoles[oldAdmin] = Role.None;
147+
// deal with adminsContracts[oldAdmin] ?
148+
// remove it ? adminsAccounts.push(oldAdmin);
149+
emit Granted(msg.sender,oldAdmin, Role.None , oldAdmin);
150+
}
151+
152+
153+
154+
}
155+

0 commit comments

Comments
 (0)