-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update to 4337 v0.7 (2/n) (#49)
- Loading branch information
Showing
13 changed files
with
129 additions
and
168 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
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 |
---|---|---|
@@ -1,45 +1,67 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity ^0.8.25; | ||
|
||
import {Address} from "@openzeppelin/contracts/utils/Address.sol"; | ||
|
||
import {AccountStorage, getAccountStorage} from "./AccountStorage.sol"; | ||
|
||
/// @title AccountStorageInitializable | ||
/// @dev Bulk of the impl is lifted from OZ 5.0 Initializible | ||
abstract contract AccountStorageInitializable { | ||
error AlreadyInitialized(); | ||
error AlreadyInitializing(); | ||
/** | ||
* @dev Triggered when the contract has been initialized or reinitialized. | ||
*/ | ||
event Initialized(uint64 version); | ||
|
||
/** | ||
* @dev The contract is already initialized. | ||
*/ | ||
error InvalidInitialization(); | ||
|
||
/** | ||
* @dev The contract is not initializing. | ||
*/ | ||
error NotInitializing(); | ||
|
||
/// @notice Modifier to put on function intended to be called only once per implementation | ||
/// @dev Reverts if the contract has already been initialized | ||
modifier initializer() { | ||
AccountStorage storage _storage = getAccountStorage(); | ||
bool isTopLevelCall = !_storage.initializing; | ||
if ( | ||
isTopLevelCall && _storage.initialized < 1 | ||
|| !Address.isContract(address(this)) && _storage.initialized == 1 | ||
) { | ||
_storage.initialized = 1; | ||
if (isTopLevelCall) { | ||
_storage.initializing = true; | ||
} | ||
_; | ||
if (isTopLevelCall) { | ||
_storage.initializing = false; | ||
} | ||
} else { | ||
revert AlreadyInitialized(); | ||
AccountStorage storage $ = getAccountStorage(); | ||
|
||
// Cache values to avoid duplicated sloads | ||
bool isTopLevelCall = !$.initializing; | ||
uint64 initialized = $.initialized; | ||
|
||
// Allowed calls: | ||
// - initialSetup: the contract is not in the initializing state and no previous version was | ||
// initialized | ||
// - construction: the contract is initialized at version 1 (no reininitialization) and the | ||
// current contract is just being deployed | ||
bool initialSetup = initialized == 0 && isTopLevelCall; | ||
bool construction = initialized == 1 && address(this).code.length == 0; | ||
|
||
if (!initialSetup && !construction) { | ||
revert InvalidInitialization(); | ||
} | ||
$.initialized = 1; | ||
if (isTopLevelCall) { | ||
$.initializing = true; | ||
} | ||
_; | ||
if (isTopLevelCall) { | ||
$.initializing = false; | ||
emit Initialized(1); | ||
} | ||
} | ||
|
||
/// @notice Internal function to disable calls to initialization functions | ||
/// @dev Reverts if the contract has already been initialized | ||
function _disableInitializers() internal virtual { | ||
AccountStorage storage _storage = getAccountStorage(); | ||
if (_storage.initializing) { | ||
revert AlreadyInitializing(); | ||
AccountStorage storage $ = getAccountStorage(); | ||
if ($.initializing) { | ||
revert InvalidInitialization(); | ||
} | ||
if (_storage.initialized != type(uint8).max) { | ||
_storage.initialized = type(uint8).max; | ||
if ($.initialized != type(uint8).max) { | ||
$.initialized = type(uint8).max; | ||
emit Initialized(type(uint8).max); | ||
} | ||
} | ||
} |
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
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
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
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
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
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
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,12 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.19; | ||
|
||
import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | ||
|
||
contract MockERC721 is ERC721 { | ||
constructor(string memory name, string memory symbol) ERC721(name, symbol) {} | ||
|
||
function mint(address account, uint256 tokenId) external { | ||
_mint(account, tokenId); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.