Skip to content

Commit

Permalink
Use latest dynamic contracts deps (#475)
Browse files Browse the repository at this point in the history
* Use latest version of dynamic-contracts

* add dynamic-contracts deps in node modules and add foundry remapping

* Update dynamic-contracts version
  • Loading branch information
nkrishang authored Aug 18, 2023
1 parent 2108627 commit 86cd91c
Show file tree
Hide file tree
Showing 23 changed files with 63 additions and 60 deletions.
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
[submodule "lib/ds-test"]
path = lib/ds-test
url = https://github.com/dapphub/ds-test
[submodule "lib/dynamic-contracts"]
path = lib/dynamic-contracts
url = https://github.com/thirdweb-dev/dynamic-contracts
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/openzeppelin/openzeppelin-contracts
Expand All @@ -24,3 +21,6 @@
path = lib/ERC721A
url = https://github.com/chiru-labs/ERC721A
branch = v3.3.0
[submodule "lib/dynamic-contracts"]
path = lib/dynamic-contracts
url = https://github.com/thirdweb-dev/dynamic-contracts
10 changes: 5 additions & 5 deletions contracts/dynamic-contracts/ExtensionRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import "./interface/IExtensionRegistry.sol";

// Extensions
import "../extension/PermissionsEnumerable.sol";
import "lib/dynamic-contracts/src/presets/utils/ExtensionState.sol";
import "lib/dynamic-contracts/src/presets/utils/StringSet.sol";
import "@thirdweb-dev/dynamic-contracts/src/presets/utils/ExtensionState.sol";
import "@thirdweb-dev/dynamic-contracts/src/presets/utils/StringSet.sol";

contract ExtensionRegistry is IExtensionRegistry, ExtensionState, PermissionsEnumerable {
using StringSet for StringSet.Set;
Expand Down Expand Up @@ -45,7 +45,7 @@ contract ExtensionRegistry is IExtensionRegistry, ExtensionState, PermissionsEnu

/// @notice Returns all extensions stored.
function getAllExtensions() external view returns (Extension[] memory allExtensions) {
ExtensionStateStorage.Data storage data = ExtensionStateStorage.extensionStateStorage();
ExtensionStateStorage.Data storage data = _extensionStateStorage();

string[] memory names = data.extensionNames.values();
uint256 len = names.length;
Expand All @@ -59,7 +59,7 @@ contract ExtensionRegistry is IExtensionRegistry, ExtensionState, PermissionsEnu

/// @notice Returns the extension metadata and functions for a given extension.
function getExtension(string memory _extensionName) public view returns (Extension memory) {
ExtensionStateStorage.Data storage data = ExtensionStateStorage.extensionStateStorage();
ExtensionStateStorage.Data storage data = _extensionStateStorage();
require(data.extensionNames.contains(_extensionName), "ExtensionRegistry: extension does not exist.");
return data.extensions[_extensionName];
}
Expand All @@ -80,7 +80,7 @@ contract ExtensionRegistry is IExtensionRegistry, ExtensionState, PermissionsEnu

/// @notice Returns the extension metadata for a given function.
function getExtensionForFunction(bytes4 _functionSelector) external view returns (ExtensionMetadata memory) {
ExtensionStateStorage.Data storage data = ExtensionStateStorage.extensionStateStorage();
ExtensionStateStorage.Data storage data = _extensionStateStorage();
ExtensionMetadata memory metadata = data.extensionMetadata[_functionSelector];
require(metadata.implementation != address(0), "ExtensionRegistry: no extension for function.");
return metadata;
Expand Down
14 changes: 7 additions & 7 deletions contracts/dynamic-contracts/TWRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import "./interface/IExtensionRegistry.sol";
import "../extension/Multicall.sol";

// Extension pattern imports
import "lib/dynamic-contracts/src/presets/utils/StringSet.sol";
import "lib/dynamic-contracts/src/core/Router.sol";
import "lib/dynamic-contracts/src/presets/utils/DefaultExtensionSet.sol";
import "lib/dynamic-contracts/src/presets/utils/ExtensionState.sol";
import "@thirdweb-dev/dynamic-contracts/src/presets/utils/StringSet.sol";
import "@thirdweb-dev/dynamic-contracts/src/core/Router.sol";
import "@thirdweb-dev/dynamic-contracts/src/presets/utils/DefaultExtensionSet.sol";
import "@thirdweb-dev/dynamic-contracts/src/presets/utils/ExtensionState.sol";

abstract contract TWRouter is ITWRouter, Multicall, ExtensionState, Router {
using StringSet for StringSet.Set;
Expand Down Expand Up @@ -86,7 +86,7 @@ abstract contract TWRouter is ITWRouter, Multicall, ExtensionState, Router {
Extension[] memory mapExtensions = IDefaultExtensionSet(defaultExtensionSet).getAllExtensions();
uint256 mapExtensionsLen = mapExtensions.length;

ExtensionStateStorage.Data storage data = ExtensionStateStorage.extensionStateStorage();
ExtensionStateStorage.Data storage data = _extensionStateStorage();
string[] memory names = data.extensionNames.values();
uint256 namesLen = names.length;

Expand Down Expand Up @@ -118,7 +118,7 @@ abstract contract TWRouter is ITWRouter, Multicall, ExtensionState, Router {

/// @dev Returns the extension metadata and functions for a given extension.
function getExtension(string memory _extensionName) public view returns (Extension memory) {
ExtensionStateStorage.Data storage data = ExtensionStateStorage.extensionStateStorage();
ExtensionStateStorage.Data storage data = _extensionStateStorage();
bool isLocalExtension = data.extensionNames.contains(_extensionName);

return
Expand All @@ -143,7 +143,7 @@ abstract contract TWRouter is ITWRouter, Multicall, ExtensionState, Router {

/// @dev Returns the Extension metadata for a given function.
function getExtensionForFunction(bytes4 _functionSelector) public view returns (ExtensionMetadata memory) {
ExtensionStateStorage.Data storage data = ExtensionStateStorage.extensionStateStorage();
ExtensionStateStorage.Data storage data = _extensionStateStorage();
ExtensionMetadata memory metadata = data.extensionMetadata[_functionSelector];

bool isLocalExtension = metadata.implementation != address(0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

import "lib/dynamic-contracts/src/interface/IDefaultExtensionSet.sol";
import "@thirdweb-dev/dynamic-contracts/src/interface/IDefaultExtensionSet.sol";

interface IExtensionRegistry is IDefaultExtensionSet {
/*///////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion contracts/dynamic-contracts/interface/ITWRouter.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

import "lib/dynamic-contracts/src/interface/IDefaultExtensionSet.sol";
import "@thirdweb-dev/dynamic-contracts/src/interface/IDefaultExtensionSet.sol";

interface ITWRouter is IDefaultExtensionSet {
/*///////////////////////////////////////////////////////////////
Expand Down
10 changes: 4 additions & 6 deletions contracts/smart-wallet/dynamic/DynamicAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pragma solidity ^0.8.11;

import "../utils/AccountCore.sol";

import "lib/dynamic-contracts/src/presets/BaseRouter.sol";
import "@thirdweb-dev/dynamic-contracts/src/presets/BaseRouterWithDefaults.sol";

// $$\ $$\ $$\ $$\ $$\
// $$ | $$ | \__| $$ | $$ |
Expand All @@ -18,16 +18,14 @@ import "lib/dynamic-contracts/src/presets/BaseRouter.sol";
// \$$$$ |$$ | $$ |$$ |$$ | \$$$$$$$ |\$$$$$\$$$$ |\$$$$$$$\ $$$$$$$ |
// \____/ \__| \__|\__|\__| \_______| \_____\____/ \_______|\_______/

contract DynamicAccount is AccountCore, BaseRouter {
contract DynamicAccount is AccountCore, BaseRouterWithDefaults {
/*///////////////////////////////////////////////////////////////
Constructor
//////////////////////////////////////////////////////////////*/

receive() external payable override(Router, AccountCore) {}

constructor(IEntryPoint _entrypoint, Extension[] memory _defaultExtensions)
AccountCore(_entrypoint, msg.sender)
BaseRouter(_defaultExtensions)
BaseRouterWithDefaults(_defaultExtensions)
{
_disableInitializers();
}
Expand All @@ -37,7 +35,7 @@ contract DynamicAccount is AccountCore, BaseRouter {
//////////////////////////////////////////////////////////////*/

/// @dev Returns whether a extension can be set in the given execution context.
function _canSetExtension() internal view virtual override returns (bool) {
function _canSetExtension(Extension memory) internal view virtual override returns (bool) {
return isAdmin(msg.sender);
}
}
2 changes: 1 addition & 1 deletion contracts/smart-wallet/dynamic/DynamicAccountFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.12;

// Utils
import "../utils/BaseAccountFactory.sol";
import "lib/dynamic-contracts/src/interface/IExtension.sol";
import "@thirdweb-dev/dynamic-contracts/src/interface/IExtension.sol";

// Extensions
import "../../dynamic-contracts/extension/PermissionsEnumerable.sol";
Expand Down
5 changes: 1 addition & 4 deletions contracts/smart-wallet/managed/ManagedAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@ pragma solidity ^0.8.11;
// \____/ \__| \__|\__|\__| \_______| \_____\____/ \_______|\_______/

import "../utils/AccountCore.sol";
import "lib/dynamic-contracts/src/core/Router.sol";
import "@thirdweb-dev/dynamic-contracts/src/core/Router.sol";

contract ManagedAccount is AccountCore, Router {
constructor(IEntryPoint _entrypoint, address _factory) AccountCore(_entrypoint, _factory) {}

// solhint-disable-next-line no-empty-blocks
receive() external payable virtual override(Router, AccountCore) {}

/// @notice Returns the implementation contract address for a given function signature.
function getImplementationForFunction(bytes4 _functionSelector) public view virtual override returns (address) {
return Router(payable(factory)).getImplementationForFunction(_functionSelector);
Expand Down
10 changes: 5 additions & 5 deletions contracts/smart-wallet/managed/ManagedAccountFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.12;

// Utils
import "lib/dynamic-contracts/src/presets/BaseRouter.sol";
import "@thirdweb-dev/dynamic-contracts/src/presets/BaseRouterWithDefaults.sol";
import "../utils/BaseAccountFactory.sol";

// Extensions
Expand All @@ -21,19 +21,19 @@ import { ManagedAccount, IEntryPoint } from "./ManagedAccount.sol";
// \$$$$ |$$ | $$ |$$ |$$ | \$$$$$$$ |\$$$$$\$$$$ |\$$$$$$$\ $$$$$$$ |
// \____/ \__| \__|\__|\__| \_______| \_____\____/ \_______|\_______/

contract ManagedAccountFactory is BaseAccountFactory, ContractMetadata, PermissionsEnumerable, BaseRouter {
contract ManagedAccountFactory is BaseAccountFactory, ContractMetadata, PermissionsEnumerable, BaseRouterWithDefaults {
/*///////////////////////////////////////////////////////////////
Constructor
//////////////////////////////////////////////////////////////*/

constructor(IEntryPoint _entrypoint, Extension[] memory _defaultExtensions)
BaseRouter(_defaultExtensions)
BaseRouterWithDefaults(_defaultExtensions)
BaseAccountFactory(payable(address(new ManagedAccount(_entrypoint, address(this)))), address(_entrypoint))
{
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
}

receive() external payable override {
receive() external payable {
revert("Cannot accept ether.");
}

Expand All @@ -51,7 +51,7 @@ contract ManagedAccountFactory is BaseAccountFactory, ContractMetadata, Permissi
}

/// @dev Returns whether an extension can be set in the given execution context.
function _canSetExtension() internal view virtual override returns (bool) {
function _canSetExtension(Extension memory) internal view virtual override returns (bool) {
return hasRole(DEFAULT_ADMIN_ROLE, msg.sender);
}

Expand Down
16 changes: 8 additions & 8 deletions contracts/smart-wallet/utils/BaseRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
pragma solidity ^0.8.0;

// Interface
import "lib/dynamic-contracts/src/interface/IBaseRouter.sol";
import "@thirdweb-dev/dynamic-contracts/src/interface/IBaseRouter.sol";

// Core
import "lib/dynamic-contracts/src/core/Router.sol";
import "@thirdweb-dev/dynamic-contracts/src/core/Router.sol";

// Utils
import "lib/dynamic-contracts/src/presets/utils/StringSet.sol";
import "lib/dynamic-contracts/src/presets/utils/ExtensionState.sol";
import "@thirdweb-dev/dynamic-contracts/src/presets/utils/StringSet.sol";
import "@thirdweb-dev/dynamic-contracts/src/presets/utils/ExtensionState.sol";

abstract contract BaseRouter is IBaseRouter, Router, ExtensionState {
using StringSet for StringSet.Set;
Expand All @@ -27,7 +27,7 @@ abstract contract BaseRouter is IBaseRouter, Router, ExtensionState {
//////////////////////////////////////////////////////////////*/

/// @dev See {IERC165-supportsInterface}.
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IBaseRouter).interfaceId;
}

Expand Down Expand Up @@ -65,7 +65,7 @@ abstract contract BaseRouter is IBaseRouter, Router, ExtensionState {
* given precedence over default extensions in DefaultExtensionSet.
*/
function getAllExtensions() external view returns (Extension[] memory allExtensions) {
ExtensionStateStorage.Data storage data = ExtensionStateStorage.extensionStateStorage();
ExtensionStateStorage.Data storage data = _extensionStateStorage();

string[] memory names = data.extensionNames.values();
uint256 len = names.length;
Expand All @@ -79,7 +79,7 @@ abstract contract BaseRouter is IBaseRouter, Router, ExtensionState {

/// @dev Returns the extension metadata and functions for a given extension.
function getExtension(string memory _extensionName) public view returns (Extension memory) {
ExtensionStateStorage.Data storage data = ExtensionStateStorage.extensionStateStorage();
ExtensionStateStorage.Data storage data = _extensionStateStorage();
return data.extensions[_extensionName];
}

Expand All @@ -99,7 +99,7 @@ abstract contract BaseRouter is IBaseRouter, Router, ExtensionState {

/// @dev Returns the extension metadata for a given function.
function getExtensionForFunction(bytes4 _functionSelector) public view returns (ExtensionMetadata memory) {
ExtensionStateStorage.Data storage data = ExtensionStateStorage.extensionStateStorage();
ExtensionStateStorage.Data storage data = _extensionStateStorage();
return data.extensionMetadata[_functionSelector];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pragma solidity ^0.8.11;
// \$$$$ |$$ | $$ |$$ |$$ | \$$$$$$$ |\$$$$$\$$$$ |\$$$$$$$\ $$$$$$$ |
// \____/ \__| \__|\__|\__| \_______| \_____\____/ \_______|\_______/

import "lib/dynamic-contracts/src/presets/BaseRouter.sol";
import "@thirdweb-dev/dynamic-contracts/src/presets/BaseRouterWithDefaults.sol";

import "../../extension/Multicall.sol";

Expand All @@ -34,7 +34,7 @@ contract BurnToClaimDropERC721 is
Initializable,
Multicall,
ERC2771ContextUpgradeable,
BaseRouter,
BaseRouterWithDefaults,
DefaultOperatorFiltererInit,
ContractMetadataInit,
PlatformFeeInit,
Expand All @@ -48,7 +48,7 @@ contract BurnToClaimDropERC721 is
Constructor + initializer logic
//////////////////////////////////////////////////////////////*/

constructor(Extension[] memory _extensions) BaseRouter(_extensions) {}
constructor(Extension[] memory _extensions) BaseRouterWithDefaults(_extensions) {}

/// @dev Initiliazes the contract, like a constructor.
function initialize(
Expand Down Expand Up @@ -128,7 +128,7 @@ contract BurnToClaimDropERC721 is
//////////////////////////////////////////////////////////////*/

/// @dev Returns whether an extension can be set in the given execution context.
function _canSetExtension() internal view virtual override returns (bool) {
function _canSetExtension(Extension memory) internal view virtual override returns (bool) {
return _hasRole(keccak256("EXTENSION_ROLE"), msg.sender);
}

Expand Down
9 changes: 5 additions & 4 deletions contracts/unaudited/evolving-nfts/EvolvingNFT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pragma solidity ^0.8.11;
// \$$$$ |$$ | $$ |$$ |$$ | \$$$$$$$ |\$$$$$\$$$$ |\$$$$$$$\ $$$$$$$ |
// \____/ \__| \__|\__|\__| \_______| \_____\____/ \_______|\_______/

import "lib/dynamic-contracts/src/presets/BaseRouter.sol";
import "@thirdweb-dev/dynamic-contracts/src/presets/BaseRouterWithDefaults.sol";

import "../../extension/Multicall.sol";
import "../../dynamic-contracts/extension/Initializable.sol";
Expand All @@ -27,7 +27,7 @@ import "../../dynamic-contracts/init/DefaultOperatorFiltererInit.sol";

contract EvolvingNFT is
Initializable,
BaseRouter,
BaseRouterWithDefaults,
Multicall,
ERC721AQueryableInit,
ERC2771ContextInit,
Expand All @@ -41,7 +41,7 @@ contract EvolvingNFT is
/// @dev Only MINTER_ROLE holders can sign off on `MintRequest`s.
bytes32 private constant EXTENSION_ROLE = keccak256("EXTENSION_ROLE");

constructor(Extension[] memory _extensions) BaseRouter(_extensions) {}
constructor(Extension[] memory _extensions) BaseRouterWithDefaults(_extensions) {}

/// @dev Initiliazes the contract, like a constructor.
function initialize(
Expand All @@ -65,6 +65,7 @@ contract EvolvingNFT is
_setupOperatorFilterer();

_setupRole(DEFAULT_ADMIN_ROLE, _defaultAdmin);
_setupRole(EXTENSION_ROLE, _defaultAdmin);
_setupRole(keccak256("MINTER_ROLE"), _defaultAdmin);
_setupRole(_transferRole, _defaultAdmin);
_setupRole(_transferRole, address(0));
Expand All @@ -83,7 +84,7 @@ contract EvolvingNFT is
}

/// @dev Returns whether a extension can be set in the given execution context.
function _canSetExtension() internal view virtual override returns (bool) {
function _canSetExtension(Extension memory) internal view virtual override returns (bool) {
return _hasRole(EXTENSION_ROLE, msg.sender);
}

Expand Down
1 change: 1 addition & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ remappings = [
'contracts/=contracts/',
'erc721a-upgradeable/=lib/ERC721A-Upgradeable/',
'erc721a/=lib/ERC721A/',
'@thirdweb-dev/dynamic-contracts/=lib/dynamic-contracts/',
]
src = 'contracts'
test = 'src/test'
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@openzeppelin/contracts": "4.7.3",
"@openzeppelin/contracts-upgradeable": "4.7.3",
"@primitivefi/hardhat-dodoc": "^0.2.0",
"@thirdweb-dev/dynamic-contracts": "^1.1.2",
"@thirdweb-dev/sdk": "3.10.33",
"@typechain/ethers-v5": "^10.0.0",
"@typechain/hardhat": "^4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/test/EvolvingNFT.t.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

import { IExtension } from "lib/dynamic-contracts/src/interface/IExtension.sol";
import { IExtension } from "@thirdweb-dev/dynamic-contracts/src/interface/IExtension.sol";

import { EvolvingNFT } from "contracts/unaudited/evolving-nfts/EvolvingNFT.sol";
import { EvolvingNFTLogic } from "contracts/unaudited/evolving-nfts/EvolvingNFTLogic.sol";
Expand Down
Loading

0 comments on commit 86cd91c

Please sign in to comment.