Skip to content

Commit

Permalink
Implement access manager
Browse files Browse the repository at this point in the history
  • Loading branch information
cyri113 committed Jul 22, 2024
1 parent 62c51fc commit bd330a5
Show file tree
Hide file tree
Showing 10 changed files with 435 additions and 310 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
3 changes: 2 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"./cache",
"./node_modules",
"./coverage",
"./coverage.json"
"./coverage.json",
"./ignition/deployments"
]
}
}
15 changes: 9 additions & 6 deletions contracts/ApplicationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
pragma solidity 0.8.26;

import {IApplicationManager} from "./IApplicationManager.sol";
import {AccessManaged} from "@openzeppelin/contracts/access/manager/AccessManaged.sol";

contract ApplicationManager is IApplicationManager {
contract ApplicationManager is IApplicationManager, AccessManaged {
mapping(uint => Application) private applications;
mapping(address => bool) private addressUsed;
uint private nextApplicationId;

constructor() {}
constructor(address initialAuthority) AccessManaged(initialAuthority) {}

function applicationExists(uint id) internal view returns (bool) {
return applications[id].account != address(0);
Expand All @@ -18,7 +19,9 @@ contract ApplicationManager is IApplicationManager {
return nextApplicationId;
}

function createApplication(Application memory newApplication) external {
function createApplication(
Application memory newApplication
) external restricted {
require(
!addressUsed[newApplication.account],
"Address already used for another application"
Expand All @@ -35,18 +38,18 @@ contract ApplicationManager is IApplicationManager {
function updateApplication(
uint id,
Application memory updatedApplication
) external {
) external restricted {
require(applicationExists(id), "Application does not exist");
require(
!addressUsed[updatedApplication.account] ||
applications[id].account == updatedApplication.account,
"Address already used for another application"
"Account used by another application"
);
applications[id] = updatedApplication;
emit ApplicationUpdated(id, applications[id]);
}

function deleteApplication(uint id) external {
function deleteApplication(uint id) external restricted {
require(applicationExists(id), "Application does not exist");
addressUsed[applications[id].account] = false;
emit ApplicationDeleted(id, applications[id]);
Expand Down
11 changes: 11 additions & 0 deletions contracts/OIDAccessManager.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.26;

// solhint-disable-next-line max-line-length
import {AccessManagerUpgradeable} from "@openzeppelin/contracts-upgradeable/access/manager/AccessManagerUpgradeable.sol";

contract OIDAccessManager is AccessManagerUpgradeable {
function initialize() public initializer {
__AccessManager_init(msg.sender);
}
}
18 changes: 0 additions & 18 deletions ignition/modules/Lock.ts

This file was deleted.

17 changes: 17 additions & 0 deletions ignition/modules/OIDAccessManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";

const OIDAccessManagerModule = buildModule("OIDAccessManagerModule", (m) => {
// const deployer = m.getAccount(0);

const manager = m.contract("OIDAccessManager", [], {});
m.call(manager, "initialize", []);

// m.call(manager, "labelRole", [1n, "APP_MANAGER_ROLE"]);

// console.log(appManager);
// m.call(manager, "grantRole", [1n, appManager, 0]);

return { manager };
});

export default OIDAccessManagerModule;
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"@nomicfoundation/hardhat-verify": "^2.0.0",
"@nomicfoundation/hardhat-viem": "^2.0.0",
"@nomiclabs/hardhat-solhint": "^3.1.0",
"@openzeppelin/contracts": "^5.0.2",
"@openzeppelin/contracts-upgradeable": "^5.0.2",
"@types/chai": "^4.2.0",
"@types/chai-as-promised": "^7.1.6",
"@types/mocha": ">=9.1.0",
Expand Down
Loading

0 comments on commit bd330a5

Please sign in to comment.