Skip to content

Commit 600df98

Browse files
authored
core router (#490)
* special cases * v3.9.3-0 * core router * fix * v3.9.3-1 * update dynamic-contracts * v3.10.1-0 * special case * v3.10.2-1
1 parent ee78bf9 commit 600df98

File tree

4 files changed

+119
-2
lines changed

4 files changed

+119
-2
lines changed

contracts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@thirdweb-dev/contracts",
33
"description": "Collection of smart contracts deployable via the thirdweb SDK, dashboard and CLI",
4-
"version": "3.10.1",
4+
"version": "3.10.2-1",
55
"license": "Apache-2.0",
66
"repository": {
77
"type": "git",
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// SPDX-License-Identifier: MIT
2+
// @author: thirdweb (https://github.com/thirdweb-dev/dynamic-contracts)
3+
4+
pragma solidity ^0.8.0;
5+
6+
// Interface
7+
import "lib/dynamic-contracts/src/presets/BaseRouter.sol";
8+
9+
// Core
10+
import "lib/dynamic-contracts/src/core/Router.sol";
11+
12+
// Utils
13+
import "lib/dynamic-contracts/src/lib/StringSet.sol";
14+
import "./extension/PermissionOverride.sol";
15+
16+
// Fixed extensions
17+
import "../../../extension/Ownable.sol";
18+
import "../../../extension/ContractMetadata.sol";
19+
20+
/**
21+
* ////////////
22+
*
23+
* NOTE: This contract is a work in progress, and has not been audited.
24+
*
25+
* ////////////
26+
*/
27+
28+
contract CoreRouter is BaseRouter, ContractMetadata, Ownable {
29+
using StringSet for StringSet.Set;
30+
31+
/*///////////////////////////////////////////////////////////////
32+
Constructor
33+
//////////////////////////////////////////////////////////////*/
34+
35+
constructor(address _owner, Extension[] memory _extensions) BaseRouter(_extensions) {
36+
// Initialize extensions
37+
__BaseRouter_init();
38+
39+
_setupOwner(_owner);
40+
}
41+
42+
/*///////////////////////////////////////////////////////////////
43+
Internal functions
44+
//////////////////////////////////////////////////////////////*/
45+
46+
/// @dev Returns whether all relevant permission and other checks are met before any upgrade.
47+
function _isAuthorizedCallToUpgrade() internal view virtual override returns (bool) {
48+
return msg.sender == owner();
49+
}
50+
51+
/// @dev Returns whether contract metadata can be set in the given execution context.
52+
function _canSetContractURI() internal view virtual override returns (bool) {
53+
return msg.sender == owner();
54+
}
55+
56+
/// @dev Returns whether owner can be set in the given execution context.
57+
function _canSetOwner() internal view virtual override returns (bool) {
58+
return msg.sender == owner();
59+
}
60+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.0;
3+
4+
/// @author thirdweb
5+
6+
/**
7+
* ////////////
8+
*
9+
* NOTE: This contract is a work in progress, and has not been audited.
10+
*
11+
* ////////////
12+
*/
13+
14+
library PermissionsStorage {
15+
bytes32 public constant PERMISSIONS_STORAGE_POSITION = keccak256("permissions.storage");
16+
17+
struct Data {
18+
/// @dev Map from keccak256 hash of a role => a map from address => whether address has role.
19+
mapping(bytes32 => mapping(address => bool)) _hasRole;
20+
/// @dev Map from keccak256 hash of a role to role admin. See {getRoleAdmin}.
21+
mapping(bytes32 => bytes32) _getRoleAdmin;
22+
}
23+
24+
function permissionsStorage() internal pure returns (Data storage permissionsData) {
25+
bytes32 position = PERMISSIONS_STORAGE_POSITION;
26+
assembly {
27+
permissionsData.slot := position
28+
}
29+
}
30+
}
31+
32+
contract PermissionOverrideCoreRouter {
33+
bytes32 private constant DEFAULT_ADMIN_ROLE = 0x00;
34+
bytes32 private constant EXTENSION_ROLE = keccak256("EXTENSION_ROLE");
35+
36+
function canSetContractURI(address _caller) public view returns (bool) {
37+
return _hasRole(DEFAULT_ADMIN_ROLE, _caller);
38+
}
39+
40+
function canSetOwner(address _caller) public view returns (bool) {
41+
return _hasRole(DEFAULT_ADMIN_ROLE, _caller);
42+
}
43+
44+
function canSetExtension(address _caller) public view returns (bool) {
45+
return _hasRole(DEFAULT_ADMIN_ROLE, _caller);
46+
}
47+
48+
function _hasRole(bytes32 role, address account) internal view returns (bool) {
49+
PermissionsStorage.Data storage data = PermissionsStorage.permissionsStorage();
50+
return data._hasRole[role][account];
51+
}
52+
}

scripts/package-release.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ const artifactsForgeDir = path.join(__dirname, "..", "artifacts_forge");
66
const contractsDir = path.join(__dirname, "..", "contracts");
77
const contractArtifactsDir = path.join(__dirname, "..", "contract_artifacts");
88

9-
const specialCases: string[] = ["IBaseRouter.sol", "MockContractPublisher.sol"];
9+
const specialCases: string[] = [
10+
"IRouterState.sol",
11+
"BaseRouter.sol",
12+
"ExtensionManager.sol",
13+
"MockContractPublisher.sol",
14+
];
1015

1116
async function getAllSolidityFiles(dir: string): Promise<string[]> {
1217
const dirents = await fs.readdir(dir, { withFileTypes: true });

0 commit comments

Comments
 (0)