-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'thirdweb-dev:main' into account-benchmark-test
- Loading branch information
Showing
4 changed files
with
119 additions
and
2 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
60 changes: 60 additions & 0 deletions
60
contracts/prebuilts/unaudited/contract-builder/CoreRouter.sol
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// SPDX-License-Identifier: MIT | ||
// @author: thirdweb (https://github.com/thirdweb-dev/dynamic-contracts) | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
// Interface | ||
import "lib/dynamic-contracts/src/presets/BaseRouter.sol"; | ||
|
||
// Core | ||
import "lib/dynamic-contracts/src/core/Router.sol"; | ||
|
||
// Utils | ||
import "lib/dynamic-contracts/src/lib/StringSet.sol"; | ||
import "./extension/PermissionOverride.sol"; | ||
|
||
// Fixed extensions | ||
import "../../../extension/Ownable.sol"; | ||
import "../../../extension/ContractMetadata.sol"; | ||
|
||
/** | ||
* //////////// | ||
* | ||
* NOTE: This contract is a work in progress, and has not been audited. | ||
* | ||
* //////////// | ||
*/ | ||
|
||
contract CoreRouter is BaseRouter, ContractMetadata, Ownable { | ||
using StringSet for StringSet.Set; | ||
|
||
/*/////////////////////////////////////////////////////////////// | ||
Constructor | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
constructor(address _owner, Extension[] memory _extensions) BaseRouter(_extensions) { | ||
// Initialize extensions | ||
__BaseRouter_init(); | ||
|
||
_setupOwner(_owner); | ||
} | ||
|
||
/*/////////////////////////////////////////////////////////////// | ||
Internal functions | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
/// @dev Returns whether all relevant permission and other checks are met before any upgrade. | ||
function _isAuthorizedCallToUpgrade() internal view virtual override returns (bool) { | ||
return msg.sender == owner(); | ||
} | ||
|
||
/// @dev Returns whether contract metadata can be set in the given execution context. | ||
function _canSetContractURI() internal view virtual override returns (bool) { | ||
return msg.sender == owner(); | ||
} | ||
|
||
/// @dev Returns whether owner can be set in the given execution context. | ||
function _canSetOwner() internal view virtual override returns (bool) { | ||
return msg.sender == owner(); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
contracts/prebuilts/unaudited/contract-builder/extension/PermissionOverride.sol
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
/// @author thirdweb | ||
|
||
/** | ||
* //////////// | ||
* | ||
* NOTE: This contract is a work in progress, and has not been audited. | ||
* | ||
* //////////// | ||
*/ | ||
|
||
library PermissionsStorage { | ||
bytes32 public constant PERMISSIONS_STORAGE_POSITION = keccak256("permissions.storage"); | ||
|
||
struct Data { | ||
/// @dev Map from keccak256 hash of a role => a map from address => whether address has role. | ||
mapping(bytes32 => mapping(address => bool)) _hasRole; | ||
/// @dev Map from keccak256 hash of a role to role admin. See {getRoleAdmin}. | ||
mapping(bytes32 => bytes32) _getRoleAdmin; | ||
} | ||
|
||
function permissionsStorage() internal pure returns (Data storage permissionsData) { | ||
bytes32 position = PERMISSIONS_STORAGE_POSITION; | ||
assembly { | ||
permissionsData.slot := position | ||
} | ||
} | ||
} | ||
|
||
contract PermissionOverrideCoreRouter { | ||
bytes32 private constant DEFAULT_ADMIN_ROLE = 0x00; | ||
bytes32 private constant EXTENSION_ROLE = keccak256("EXTENSION_ROLE"); | ||
|
||
function canSetContractURI(address _caller) public view returns (bool) { | ||
return _hasRole(DEFAULT_ADMIN_ROLE, _caller); | ||
} | ||
|
||
function canSetOwner(address _caller) public view returns (bool) { | ||
return _hasRole(DEFAULT_ADMIN_ROLE, _caller); | ||
} | ||
|
||
function canSetExtension(address _caller) public view returns (bool) { | ||
return _hasRole(DEFAULT_ADMIN_ROLE, _caller); | ||
} | ||
|
||
function _hasRole(bytes32 role, address account) internal view returns (bool) { | ||
PermissionsStorage.Data storage data = PermissionsStorage.permissionsStorage(); | ||
return data._hasRole[role][account]; | ||
} | ||
} |
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