Skip to content

Commit

Permalink
Merge branch 'thirdweb-dev:main' into account-benchmark-test
Browse files Browse the repository at this point in the history
  • Loading branch information
alfheimrShiven authored Oct 12, 2023
2 parents af5f955 + 600df98 commit 121a147
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 2 deletions.
2 changes: 1 addition & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@thirdweb-dev/contracts",
"description": "Collection of smart contracts deployable via the thirdweb SDK, dashboard and CLI",
"version": "3.10.1",
"version": "3.10.2-1",
"license": "Apache-2.0",
"repository": {
"type": "git",
Expand Down
60 changes: 60 additions & 0 deletions contracts/prebuilts/unaudited/contract-builder/CoreRouter.sol
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();
}
}
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];
}
}
7 changes: 6 additions & 1 deletion scripts/package-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ const artifactsForgeDir = path.join(__dirname, "..", "artifacts_forge");
const contractsDir = path.join(__dirname, "..", "contracts");
const contractArtifactsDir = path.join(__dirname, "..", "contract_artifacts");

const specialCases: string[] = ["IBaseRouter.sol", "MockContractPublisher.sol"];
const specialCases: string[] = [
"IRouterState.sol",
"BaseRouter.sol",
"ExtensionManager.sol",
"MockContractPublisher.sol",
];

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

0 comments on commit 121a147

Please sign in to comment.