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

Initialize extensions in onInstall #114

Merged
merged 3 commits into from
May 31, 2024
Merged
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
11 changes: 5 additions & 6 deletions src/ModularCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ abstract contract ModularCore is IModularCore, OwnableRoles {
//////////////////////////////////////////////////////////////*/

/// @notice Emitted when an extension is installed.
event ExtensionInstalled(address sender, address implementation, address installedExtension);
event ExtensionInstalled(address caller, address implementation, address installedExtension);

/// @notice Emitted when an extension is uninstalled.
event ExtensionUninstalled(address sender, address implementation, address installedExtension);
event ExtensionUninstalled(address caller, address implementation, address installedExtension);

/*//////////////////////////////////////////////////////////////
STORAGE
Expand Down Expand Up @@ -233,7 +233,7 @@ abstract contract ModularCore is IModularCore, OwnableRoles {
// Call `onInstall` callback function if extension has registered installation callback.
if (config.registerInstallationCallback) {
(bool success, bytes memory returndata) =
_extension.call{value: msg.value}(abi.encodeCall(IInstallationCallback.onInstall, (msg.sender, _data)));
_extension.delegatecall(abi.encodeCall(IInstallationCallback.onInstall, (_data)));
if (!success) {
_revert(returndata, CallbackExecutionReverted.selector);
}
Expand Down Expand Up @@ -271,9 +271,8 @@ abstract contract ModularCore is IModularCore, OwnableRoles {
}

if (config.registerInstallationCallback) {
(bool success, bytes memory returndata) = _extension.call{value: msg.value}(
abi.encodeCall(IInstallationCallback.onUninstall, (msg.sender, _data))
);
(bool success, bytes memory returndata) =
_extension.delegatecall(abi.encodeCall(IInstallationCallback.onUninstall, (_data)));
if (!success) {
_revert(returndata, CallbackExecutionReverted.selector);
}
Expand Down
4 changes: 2 additions & 2 deletions src/callback/BeforeApproveCallbackERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ contract BeforeApproveCallbackERC20 {

/**
* @notice The beforeApproveERC20 hook that is called by a core token before approving tokens.
* @param _caller The address of the caller.
*
* @param _from The address that is approving tokens.
* @param _to The address that is being approved.
* @param _amount The amount of tokens being approved.
* @return result Abi encoded bytes result of the hook.
*/
function beforeApproveERC20(address _caller, address _from, address _to, uint256 _amount)
function beforeApproveERC20(address _from, address _to, uint256 _amount)
external
virtual
returns (bytes memory result)
Expand Down
4 changes: 2 additions & 2 deletions src/callback/BeforeApproveCallbackERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ contract BeforeApproveCallbackERC721 {

/**
* @notice The beforeApproveERC721 hook that is called by a core token before approving a token.
* @param _caller The address of the caller.
*
* @param _from The address that is approving tokens.
* @param _to The address that is being approved.
* @param _tokenId The token ID being approved.
* @param _approve The approval status to set.
* @return result Abi encoded bytes result of the hook.
*/
function beforeApproveERC721(address _caller, address _from, address _to, uint256 _tokenId, bool _approve)
function beforeApproveERC721(address _from, address _to, uint256 _tokenId, bool _approve)
external
virtual
returns (bytes memory result)
Expand Down
4 changes: 2 additions & 2 deletions src/callback/BeforeApproveForAllCallback.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ contract BeforeApproveForAllCallback {

/**
* @notice The beforeApproveForAll hook that is called by a core token before approving an operator to transfer all tokens.
* @param _caller The address of the caller.
*
* @param _from The address that is approving tokens.
* @param _to The address that is being approved.
* @param _approved Whether to grant or revoke approval.
*/
function beforeApproveForAll(address _caller, address _from, address _to, bool _approved)
function beforeApproveForAll(address _from, address _to, bool _approved)
external
virtual
returns (bytes memory result)
Expand Down
14 changes: 6 additions & 8 deletions src/callback/BeforeBatchTransferCallbackERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,18 @@ contract BeforeBatchTransferCallbackERC1155 {

/**
* @notice The beforeBatchTransferERC1155 hook that is called by a core token before batch transferring tokens.
* @param _caller The address of the caller.
*
* @param from The address that is transferring tokens.
* @param to The address that is receiving tokens.
* @param ids The token IDs being transferred.
* @param values The quantities of tokens being transferred.
* @return result Abi encoded bytes result of the hook.
*/
function beforeBatchTransferERC1155(
address _caller,
address from,
address to,
uint256[] calldata ids,
uint256[] calldata values
) external virtual returns (bytes memory result) {
function beforeBatchTransferERC1155(address from, address to, uint256[] calldata ids, uint256[] calldata values)
external
virtual
returns (bytes memory result)
{
revert BeforeBatchTransferCallbackERC1155NotImplemented();
}
}
4 changes: 2 additions & 2 deletions src/callback/BeforeBurnCallbackERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ contract BeforeBurnCallbackERC1155 {

/**
* @notice The beforeBurnERC1155 hook that is called by a core token before burning a token.
* @param _caller The address of the caller.
*
* @param _from The address whose tokens are being burned.
* @param _id The token ID being burned.
* @param _value The quantity of tokens being burned.
* @param _data The encoded arguments for the beforeBurn hook.
* @return result Abi encoded bytes result of the hook.
*/
function beforeBurnERC1155(address _caller, address _from, uint256 _id, uint256 _value, bytes memory _data)
function beforeBurnERC1155(address _from, uint256 _id, uint256 _value, bytes memory _data)
external
payable
virtual
Expand Down
4 changes: 2 additions & 2 deletions src/callback/BeforeBurnCallbackERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ contract BeforeBurnCallbackERC20 {

/**
* @notice The beforeBurnERC20 hook that is called by a core token before burning tokens.
* @param _caller The address of the caller.
*
* @param _from The address whose tokens are being burned.
* @param _amount The amount of tokens being burned.
* @param _data The encoded arguments for the beforeBurn hook.
* @return result Abi encoded bytes result of the hook.
*/
function beforeBurnERC20(address _caller, address _from, uint256 _amount, bytes memory _data)
function beforeBurnERC20(address _from, uint256 _amount, bytes memory _data)
external
payable
virtual
Expand Down
4 changes: 2 additions & 2 deletions src/callback/BeforeBurnCallbackERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ contract BeforeBurnCallbackERC721 {

/**
* @notice The beforeBurnERC721 hook that is called by a core token before burning a token.
* @param _caller The address of the caller.
*
* @param _tokenId The token ID being burned.
* @param _data The encoded arguments for the beforeBurn hook.
* @return result Abi encoded bytes result of the hook.
*/
function beforeBurnERC721(address _caller, uint256 _tokenId, bytes memory _data)
function beforeBurnERC721(uint256 _tokenId, bytes memory _data)
external
payable
virtual
Expand Down
4 changes: 2 additions & 2 deletions src/callback/BeforeMintCallbackERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ contract BeforeMintCallbackERC1155 {

/**
* @notice The beforeMintERC1155 hook that is called by a core token before minting tokens.
* @param _caller The address of the caller.
*
* @param _to The address that is minting tokens.
* @param _id The token ID being minted.
* @param _quantity The quantity 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 _caller, address _to, uint256 _id, uint256 _quantity, bytes memory _data)
function beforeMintERC1155(address _to, uint256 _id, uint256 _quantity, bytes memory _data)
external
payable
virtual
Expand Down
4 changes: 2 additions & 2 deletions src/callback/BeforeMintCallbackERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ contract BeforeMintCallbackERC20 {

/**
* @notice The beforeMintERC20 hook that is called by a core token before minting tokens.
* @param _caller The address of the caller.
*
* @param _to The address to mint tokens to.
* @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 beforeMintERC20(address _caller, address _to, uint256 _amount, bytes memory _data)
function beforeMintERC20(address _to, uint256 _amount, bytes memory _data)
external
payable
virtual
Expand Down
15 changes: 7 additions & 8 deletions src/callback/BeforeMintCallbackERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,18 @@ contract BeforeMintCallbackERC721 {

/**
* @notice The beforeMintERC721 hook that is called by a core token before minting tokens.
* @param _caller The address of the caller.
*
* @param _to The address that is minting tokens.
* @param _quantity The quantity 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 _caller,
address _to,
uint256 _startTokenId,
uint256 _quantity,
bytes memory _data
) external payable virtual returns (bytes memory result) {
function beforeMintERC721(address _to, uint256 _startTokenId, uint256 _quantity, bytes memory _data)
external
payable
virtual
returns (bytes memory result)
{
revert BeforeMintCallbackERC721NotImplemented();
}
}
2 changes: 1 addition & 1 deletion src/callback/BeforeTransferCallbackERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contract BeforeTransferCallbackERC1155 {
* @param _value The quantity of tokens being transferred.
* @return result Abi encoded bytes result of the hook.
*/
function beforeTransferERC1155(address _caller, address _from, address _to, uint256 _id, uint256 _value)
function beforeTransferERC1155(address _from, address _to, uint256 _id, uint256 _value)
external
virtual
returns (bytes memory result)
Expand Down
4 changes: 2 additions & 2 deletions src/callback/BeforeTransferCallbackERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ contract BeforeTransferCallbackERC20 {

/**
* @notice The beforeTransferERC20 hook that is called by a core token before transferring tokens.
* @param _caller The address of the caller.
*
* @param _from The address that is transferring tokens.
* @param _to The address that is receiving tokens.
* @param _amount The amount of tokens being transferred.
* @return result Abi encoded bytes result of the hook.
*/
function beforeTransferERC20(address _caller, address _from, address _to, uint256 _amount)
function beforeTransferERC20(address _from, address _to, uint256 _amount)
external
virtual
returns (bytes memory result)
Expand Down
4 changes: 2 additions & 2 deletions src/callback/BeforeTransferCallbackERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ contract BeforeTransferCallbackERC721 {

/**
* @notice The beforeTransferERC721 hook that is called by a core token before transferring a token.
* @param _caller The address of the caller.
*
* @param _from The address that is transferring tokens.
* @param _to The address that is receiving tokens.
* @param _tokenId The token ID being transferred.
* @return result Abi encoded bytes result of the hook.
*/
function beforeTransferERC721(address _caller, address _from, address _to, uint256 _tokenId)
function beforeTransferERC721(address _from, address _to, uint256 _tokenId)
external
virtual
returns (bytes memory result)
Expand Down
12 changes: 5 additions & 7 deletions src/core/token/ERC1155Core.sol
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,15 @@ contract ERC1155Core is ERC1155, ModularCore, Multicallable {
function _beforeMint(address to, uint256 tokenId, uint256 value, bytes memory data) internal virtual {
_executeCallbackFunction(
BeforeMintCallbackERC1155.beforeMintERC1155.selector,
abi.encodeCall(BeforeMintCallbackERC1155.beforeMintERC1155, (msg.sender, to, tokenId, value, data))
abi.encodeCall(BeforeMintCallbackERC1155.beforeMintERC1155, (to, tokenId, value, data))
);
}

/// @dev Calls the beforeTransfer hook, if installed.
function _beforeTransfer(address from, address to, uint256 tokenId, uint256 value) internal virtual {
_executeCallbackFunction(
BeforeTransferCallbackERC1155.beforeTransferERC1155.selector,
abi.encodeCall(BeforeTransferCallbackERC1155.beforeTransferERC1155, (msg.sender, from, to, tokenId, value))
abi.encodeCall(BeforeTransferCallbackERC1155.beforeTransferERC1155, (from, to, tokenId, value))
);
}

Expand All @@ -271,25 +271,23 @@ contract ERC1155Core is ERC1155, ModularCore, Multicallable {
{
_executeCallbackFunction(
BeforeBatchTransferCallbackERC1155.beforeBatchTransferERC1155.selector,
abi.encodeCall(
BeforeBatchTransferCallbackERC1155.beforeBatchTransferERC1155, (msg.sender, from, to, tokenIds, values)
)
abi.encodeCall(BeforeBatchTransferCallbackERC1155.beforeBatchTransferERC1155, (from, to, tokenIds, values))
);
}

/// @dev Calls the beforeBurn hook, if installed.
function _beforeBurn(address from, uint256 tokenId, uint256 value, bytes memory data) internal virtual {
_executeCallbackFunction(
BeforeBurnCallbackERC1155.beforeBurnERC1155.selector,
abi.encodeCall(BeforeBurnCallbackERC1155.beforeBurnERC1155, (msg.sender, from, tokenId, value, data))
abi.encodeCall(BeforeBurnCallbackERC1155.beforeBurnERC1155, (from, tokenId, value, data))
);
}

/// @dev Calls the beforeApprove hook, if installed.
function _beforeApproveForAll(address from, address to, bool approved) internal virtual {
_executeCallbackFunction(
BeforeApproveForAllCallback.beforeApproveForAll.selector,
abi.encodeCall(BeforeApproveForAllCallback.beforeApproveForAll, (msg.sender, from, to, approved))
abi.encodeCall(BeforeApproveForAllCallback.beforeApproveForAll, (from, to, approved))
);
}

Expand Down
12 changes: 5 additions & 7 deletions src/core/token/ERC1155CoreInitializable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,15 @@ contract ERC1155CoreInitializable is ERC1155, ModularCore, Multicallable, Initia
function _beforeMint(address to, uint256 tokenId, uint256 value, bytes memory data) internal virtual {
_executeCallbackFunction(
BeforeMintCallbackERC1155.beforeMintERC1155.selector,
abi.encodeCall(BeforeMintCallbackERC1155.beforeMintERC1155, (msg.sender, to, tokenId, value, data))
abi.encodeCall(BeforeMintCallbackERC1155.beforeMintERC1155, (to, tokenId, value, data))
);
}

/// @dev Calls the beforeTransfer hook, if installed.
function _beforeTransfer(address from, address to, uint256 tokenId, uint256 value) internal virtual {
_executeCallbackFunction(
BeforeTransferCallbackERC1155.beforeTransferERC1155.selector,
abi.encodeCall(BeforeTransferCallbackERC1155.beforeTransferERC1155, (msg.sender, from, to, tokenId, value))
abi.encodeCall(BeforeTransferCallbackERC1155.beforeTransferERC1155, (from, to, tokenId, value))
);
}

Expand All @@ -272,25 +272,23 @@ contract ERC1155CoreInitializable is ERC1155, ModularCore, Multicallable, Initia
{
_executeCallbackFunction(
BeforeBatchTransferCallbackERC1155.beforeBatchTransferERC1155.selector,
abi.encodeCall(
BeforeBatchTransferCallbackERC1155.beforeBatchTransferERC1155, (msg.sender, from, to, tokenIds, values)
)
abi.encodeCall(BeforeBatchTransferCallbackERC1155.beforeBatchTransferERC1155, (from, to, tokenIds, values))
);
}

/// @dev Calls the beforeBurn hook, if installed.
function _beforeBurn(address from, uint256 tokenId, uint256 value, bytes memory data) internal virtual {
_executeCallbackFunction(
BeforeBurnCallbackERC1155.beforeBurnERC1155.selector,
abi.encodeCall(BeforeBurnCallbackERC1155.beforeBurnERC1155, (msg.sender, from, tokenId, value, data))
abi.encodeCall(BeforeBurnCallbackERC1155.beforeBurnERC1155, (from, tokenId, value, data))
);
}

/// @dev Calls the beforeApprove hook, if installed.
function _beforeApproveForAll(address from, address to, bool approved) internal virtual {
_executeCallbackFunction(
BeforeApproveForAllCallback.beforeApproveForAll.selector,
abi.encodeCall(BeforeApproveForAllCallback.beforeApproveForAll, (msg.sender, from, to, approved))
abi.encodeCall(BeforeApproveForAllCallback.beforeApproveForAll, (from, to, approved))
);
}

Expand Down
8 changes: 4 additions & 4 deletions src/core/token/ERC20Core.sol
Original file line number Diff line number Diff line change
Expand Up @@ -217,31 +217,31 @@ contract ERC20Core is ERC20, Multicallable, ModularCore {
function _beforeMint(address to, uint256 amount, bytes calldata data) internal virtual {
_executeCallbackFunction(
BeforeMintCallbackERC20.beforeMintERC20.selector,
abi.encodeCall(BeforeMintCallbackERC20.beforeMintERC20, (msg.sender, to, amount, data))
abi.encodeCall(BeforeMintCallbackERC20.beforeMintERC20, (to, amount, data))
);
}

/// @dev Calls the beforeTransfer hook, if installed.
function _beforeTransfer(address from, address to, uint256 amount) internal virtual {
_executeCallbackFunction(
BeforeTransferCallbackERC20.beforeTransferERC20.selector,
abi.encodeCall(BeforeTransferCallbackERC20.beforeTransferERC20, (msg.sender, from, to, amount))
abi.encodeCall(BeforeTransferCallbackERC20.beforeTransferERC20, (from, to, amount))
);
}

/// @dev Calls the beforeBurn hook, if installed.
function _beforeBurn(address from, uint256 amount, bytes calldata data) internal virtual {
_executeCallbackFunction(
BeforeBurnCallbackERC20.beforeBurnERC20.selector,
abi.encodeCall(BeforeBurnCallbackERC20.beforeBurnERC20, (msg.sender, from, amount, data))
abi.encodeCall(BeforeBurnCallbackERC20.beforeBurnERC20, (from, amount, data))
);
}

/// @dev Calls the beforeApprove hook, if installed.
function _beforeApprove(address from, address to, uint256 amount) internal virtual {
_executeCallbackFunction(
BeforeApproveCallbackERC20.beforeApproveERC20.selector,
abi.encodeCall(BeforeApproveCallbackERC20.beforeApproveERC20, (msg.sender, from, to, amount))
abi.encodeCall(BeforeApproveCallbackERC20.beforeApproveERC20, (from, to, amount))
);
}
}
Loading