Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge main into dev #179

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
CoreBenchmark:test_core_callCallbackFunction_required() (gas: 46411)
CoreBenchmark:test_core_callFunction_callback_callbackFunctionRequired() (gas: 44067)
CoreBenchmark:test_core_callFunction_notPermissionedDelegate() (gas: 18029)
CoreBenchmark:test_core_callFunction_notPermissionedExternal() (gas: 17985)
CoreBenchmark:test_deployCore() (gas: 1920924)
CoreBenchmark:test_deployExtension() (gas: 258057)
CoreBenchmark:test_extension_callFunction_notPermissionedDelegate() (gas: 8294)
CoreBenchmark:test_extension_callFunction_notPermissionedExternal() (gas: 8314)
CoreBenchmark:test_installExtension() (gas: 330369)
CoreBenchmark:test_uninstallExtension() (gas: 18385)
CoreBenchmark:test_core_callCallbackFunction_required() (gas: 67409)
CoreBenchmark:test_core_callFunction_callback_callbackFunctionRequired() (gas: 65131)
CoreBenchmark:test_core_callFunction_notPermissionedDelegate() (gas: 39115)
CoreBenchmark:test_core_callFunction_notPermissionedExternal() (gas: 39093)
CoreBenchmark:test_deployCore() (gas: 2139892)
CoreBenchmark:test_deployModule() (gas: 350173)
CoreBenchmark:test_installModule() (gas: 352153)
CoreBenchmark:test_module_callFunction_notPermissionedDelegate() (gas: 29381)
CoreBenchmark:test_module_callFunction_notPermissionedExternal() (gas: 29379)
CoreBenchmark:test_uninstallModule() (gas: 91332)
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

74 changes: 38 additions & 36 deletions src/Core.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ abstract contract Core is ICore, OwnableRoles, ReentrancyGuard {
EVENTS
//////////////////////////////////////////////////////////////*/

/// @notice Emitted when an module is installed.
/// @notice Emitted when a module is installed.
event ModuleInstalled(address caller, address implementation, address installedModule);

/// @notice Emitted when an module is uninstalled.
/// @notice Emitted when a module is uninstalled.
event ModuleUninstalled(address caller, address implementation, address installedModule);

/*//////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -125,7 +125,7 @@ abstract contract Core is ICore, OwnableRoles, ReentrancyGuard {
EXTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/

/// @notice Installs an module contract.
/// @notice Installs a module contract.
function installModule(address _module, bytes calldata _data)
external
payable
Expand All @@ -135,7 +135,7 @@ abstract contract Core is ICore, OwnableRoles, ReentrancyGuard {
_installModule(_module, _data);
}

/// @notice Uninstalls an module contract.
/// @notice Uninstalls a module contract.
function uninstallModule(address _module, bytes calldata _data)
external
payable
Expand All @@ -150,6 +150,10 @@ abstract contract Core is ICore, OwnableRoles, ReentrancyGuard {
if (interfaceId == 0xffffffff) {
return false;
}
if (interfaceId == 0x01ffc9a7) {
// ERC165 Interface ID for ERC165
return true;
}
if (supportedInterfaceRefCounter[interfaceId] > 0) {
return true;
}
Expand All @@ -171,7 +175,7 @@ abstract contract Core is ICore, OwnableRoles, ReentrancyGuard {
return false;
}

/// @dev Installs an module contract.
/// @dev Installs a module contract.
function _installModule(address _module, bytes memory _data) internal {
if (!modules.add(_module)) {
revert ModuleAlreadyInstalled();
Expand Down Expand Up @@ -253,7 +257,7 @@ abstract contract Core is ICore, OwnableRoles, ReentrancyGuard {
emit ModuleInstalled(msg.sender, _module, _module);
}

/// @notice Uninstalls an module contract.
/// @notice Uninstalls a module contract.
function _uninstallModule(address _module, bytes memory _data) internal {
// Check: remove and check if the module is installed
if (!modules.remove(_module)) {
Expand Down Expand Up @@ -288,7 +292,7 @@ abstract contract Core is ICore, OwnableRoles, ReentrancyGuard {
emit ModuleUninstalled(msg.sender, _module, _module);
}

/// @dev Calls an module callback function and checks whether it is optional or required.
/// @dev Calls a module callback function and checks whether it is optional or required.
function _executeCallbackFunction(bytes4 _selector, bytes memory _abiEncodedCalldata)
internal
nonReentrant
Expand All @@ -301,29 +305,28 @@ abstract contract Core is ICore, OwnableRoles, ReentrancyGuard {
revert CallbackFunctionNotSupported();
}

// Get callback mode -- required or not required.
SupportedCallbackFunction[] memory functions = getSupportedCallbackFunctions();
uint256 len = functions.length;

CallbackMode callbackMode;
for (uint256 i = 0; i < len; i++) {
if (functions[i].selector == _selector) {
callbackMode = functions[i].mode;
break;
}
}

if (callbackFunction.implementation != address(0)) {
(success, returndata) = callbackFunction.implementation.delegatecall(_abiEncodedCalldata);
if (!success) {
_revert(returndata, CallbackExecutionReverted.selector);
}
} else if (callbackMode == CallbackMode.REQUIRED) {
revert CallbackFunctionRequired();
} else {
// Get callback mode -- required or not required.
SupportedCallbackFunction[] memory functions = getSupportedCallbackFunctions();
uint256 len = functions.length;

for (uint256 i = 0; i < len; i++) {
if (functions[i].selector == _selector) {
if (functions[i].mode == CallbackMode.REQUIRED) {
revert CallbackFunctionRequired();
}
break;
}
}
}
}

/// @dev Calls an module callback function and checks whether it is optional or required.
/// @dev Calls a module callback function and checks whether it is optional or required.
function _executeCallbackFunctionView(bytes4 _selector, bytes memory _abiEncodedCalldata)
internal
view
Expand All @@ -336,25 +339,24 @@ abstract contract Core is ICore, OwnableRoles, ReentrancyGuard {
revert CallbackFunctionNotSupported();
}

// Get callback mode -- required or not required.
SupportedCallbackFunction[] memory functions = getSupportedCallbackFunctions();
uint256 len = functions.length;

CallbackMode callbackMode;
for (uint256 i = 0; i < len; i++) {
if (functions[i].selector == _selector) {
callbackMode = functions[i].mode;
break;
}
}

if (callbackFunction.implementation != address(0)) {
(success, returndata) = address(this).staticcall(_abiEncodedCalldata);
if (!success) {
_revert(returndata, CallbackExecutionReverted.selector);
}
} else if (callbackMode == CallbackMode.REQUIRED) {
revert CallbackFunctionRequired();
} else {
// Get callback mode -- required or not required.
SupportedCallbackFunction[] memory functions = getSupportedCallbackFunctions();
uint256 len = functions.length;

for (uint256 i = 0; i < len; i++) {
if (functions[i].selector == _selector) {
if (functions[i].mode == CallbackMode.REQUIRED) {
revert CallbackFunctionRequired();
}
break;
}
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/callback/BeforeMintCallbackERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ contract BeforeMintCallbackERC1155 {
*
* @param _to The address that is minting tokens.
* @param _id The token ID being minted.
* @param _quantity The quantity of tokens to mint.
* @param _amount The amount of tokens to mint.
* @param _data Optional extra data passed to the hook.
* @return result Abi encoded bytes result of the hook.
*/
function beforeMintERC1155(address _to, uint256 _id, uint256 _quantity, bytes memory _data)
function beforeMintERC1155(address _to, uint256 _id, uint256 _amount, bytes memory _data)
external
payable
virtual
Expand Down
5 changes: 3 additions & 2 deletions src/callback/BeforeMintCallbackERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ contract BeforeMintCallbackERC721 {
* @notice The beforeMintERC721 hook that is called by a core token before minting tokens.
*
* @param _to The address that is minting tokens.
* @param _quantity The quantity of tokens to mint.
* @param _startTokenId The token ID being minted.
* @param _amount The amount of tokens to mint.
* @param _data Optional extra data passed to the hook.
* @return result Abi encoded bytes result of the hook.
*/
function beforeMintERC721(address _to, uint256 _startTokenId, uint256 _quantity, bytes memory _data)
function beforeMintERC721(address _to, uint256 _startTokenId, uint256 _amount, bytes memory _data)
external
payable
virtual
Expand Down
36 changes: 36 additions & 0 deletions src/callback/BeforeMintWithSignatureCallbackERC1155.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.20;

contract BeforeMintWithSignatureCallbackERC1155 {

/*//////////////////////////////////////////////////////////////
ERRORS
//////////////////////////////////////////////////////////////*/

error BeforeMintWithSignatureCallbackERC1155NotImplemented();

/*//////////////////////////////////////////////////////////////
EXTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/

/**
* @notice The beforeMintWithSignatureERC1155 hook that is called by a core token before minting tokens.
*
* @param _to The address that is minting tokens.
* @param _id The token ID being minted.
* @param _amount The quantity of tokens to mint.
* @param _data Optional extra data passed to the hook.
* @param _signer The address that signed the minting request.
* @return result Abi encoded bytes result of the hook.
*/
function beforeMintWithSignatureERC1155(
address _to,
uint256 _id,
uint256 _amount,
bytes memory _data,
address _signer
) external payable virtual returns (bytes memory result) {
revert BeforeMintWithSignatureCallbackERC1155NotImplemented();
}

}
34 changes: 34 additions & 0 deletions src/callback/BeforeMintWithSignatureCallbackERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.20;

contract BeforeMintWithSignatureCallbackERC20 {

/*//////////////////////////////////////////////////////////////
ERRORS
//////////////////////////////////////////////////////////////*/

error BeforeMintWithSignatureCallbackERC20NotImplemented();

/*//////////////////////////////////////////////////////////////
EXTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/

/**
* @notice The beforeMintWithSignatureERC20 hook that is called by a core token before minting tokens.
*
* @param _to The address that is minting tokens.
* @param _amount The amount of tokens to mint.
* @param _data Optional extra data passed to the hook.
* @param _signer The address that signed the minting request.
* @return result Abi encoded bytes result of the hook.
*/
function beforeMintWithSignatureERC20(address _to, uint256 _amount, bytes memory _data, address _signer)
external
payable
virtual
returns (bytes memory result)
{
revert BeforeMintWithSignatureCallbackERC20NotImplemented();
}

}
36 changes: 36 additions & 0 deletions src/callback/BeforeMintWithSignatureCallbackERC721.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.20;

contract BeforeMintWithSignatureCallbackERC721 {

/*//////////////////////////////////////////////////////////////
ERRORS
//////////////////////////////////////////////////////////////*/

error BeforeMintWithSignatureCallbackERC721NotImplemented();

/*//////////////////////////////////////////////////////////////
EXTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/

/**
* @notice The beforeMintWithSignatureERC721 hook that is called by a core token before minting tokens.
*
* @param _to The address that is minting tokens.
* @param _startTokenId The token ID being minted.
* @param _amount The amount of tokens to mint.
* @param _data Optional extra data passed to the hook.
* @param _signer The address that signed the minting request.
* @return result Abi encoded bytes result of the hook.
*/
function beforeMintWithSignatureERC721(
address _to,
uint256 _startTokenId,
uint256 _amount,
bytes memory _data,
address _signer
) external payable virtual returns (bytes memory result) {
revert BeforeMintWithSignatureCallbackERC721NotImplemented();
}

}
4 changes: 2 additions & 2 deletions src/callback/BeforeTransferCallbackERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ contract BeforeTransferCallbackERC1155 {
* @param _from The address that is transferring tokens.
* @param _to The address that is receiving tokens.
* @param _id The token ID being transferred.
* @param _value The quantity of tokens being transferred.
* @param _amount The amount of tokens being transferred.
* @return result Abi encoded bytes result of the hook.
*/
function beforeTransferERC1155(address _from, address _to, uint256 _id, uint256 _value)
function beforeTransferERC1155(address _from, address _to, uint256 _id, uint256 _amount)
external
virtual
returns (bytes memory result)
Expand Down
33 changes: 33 additions & 0 deletions src/callback/UpdateMetadataCallbackERC1155.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.20;

contract UpdateMetadataCallbackERC1155 {

/*//////////////////////////////////////////////////////////////
ERRORS
//////////////////////////////////////////////////////////////*/

error UpdateMetadataCallbackERC1155NotImplemented();

/*//////////////////////////////////////////////////////////////
EXTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/

/**
* @notice The beforeMintERC1155 hook that is called by a core token before minting tokens.
*
* @param _to The address that is minting tokens.
* @param _quantity The quantity of tokens to mint.
* @param _baseURI The URI to fetch token metadata from.
* @return result Abi encoded bytes result of the hook.
*/
function updateMetadataERC1155(address _to, uint256 _startTokenId, uint256 _quantity, string calldata _baseURI)
external
payable
virtual
returns (bytes memory result)
{
revert UpdateMetadataCallbackERC1155NotImplemented();
}

}
33 changes: 33 additions & 0 deletions src/callback/UpdateMetadataCallbackERC721.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.20;

contract UpdateMetadataCallbackERC721 {

/*//////////////////////////////////////////////////////////////
ERRORS
//////////////////////////////////////////////////////////////*/

error UpdateMetadataCallbackERC721NotImplemented();

/*//////////////////////////////////////////////////////////////
EXTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/

/**
* @notice The beforeMintERC721 hook that is called by a core token before minting tokens.
*
* @param _to The address that is minting tokens.
* @param _amount The amount of tokens to mint.
* @param _baseURI The URI to fetch token metadata from.
* @return result Abi encoded bytes result of the hook.
*/
function updateMetadataERC721(address _to, uint256 _startTokenId, uint256 _amount, string calldata _baseURI)
external
payable
virtual
returns (bytes memory result)
{
revert UpdateMetadataCallbackERC721NotImplemented();
}

}
Loading