Skip to content

Commit

Permalink
⚡️ Optimize Solady examples (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vectorized authored Jul 30, 2023
1 parent d723182 commit 02f27b3
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 41 deletions.
10 changes: 5 additions & 5 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,21 @@ ExampleSoladyERC1155UpgradeableTest:testSupportsInterface() (gas: 10063)
ExampleSoladyERC1155UpgradeableTest:testUpgradeable() (gas: 1262318)
ExampleSoladyERC721Test:testExcludeApprovals() (gas: 127369)
ExampleSoladyERC721Test:testExclusionExceptionDoesNotApplyToOperators() (gas: 151307)
ExampleSoladyERC721Test:testFilter() (gas: 55333)
ExampleSoladyERC721Test:testFilter() (gas: 55381)
ExampleSoladyERC721Test:testOwnersNotExcluded() (gas: 122430)
ExampleSoladyERC721Test:testOwnersNotExcludedSafeTransfer() (gas: 158673)
ExampleSoladyERC721Test:testOwnersNotExcludedSafeTransfer() (gas: 158495)
ExampleSoladyERC721Test:testRepeatRegistrationOk() (gas: 5755719)
ExampleSoladyERC721Test:testSetOperatorFilteringEnabled() (gas: 6088048)
ExampleSoladyERC721Test:testSupportsInterface() (gas: 9843)
ExampleSoladyERC721UpgradeableTest:testExcludeApprovals() (gas: 127427)
ExampleSoladyERC721UpgradeableTest:testExclusionExceptionDoesNotApplyToOperators() (gas: 151452)
ExampleSoladyERC721UpgradeableTest:testFilter() (gas: 55601)
ExampleSoladyERC721UpgradeableTest:testFilter() (gas: 55649)
ExampleSoladyERC721UpgradeableTest:testOwnersNotExcluded() (gas: 122542)
ExampleSoladyERC721UpgradeableTest:testOwnersNotExcludedSafeTransfer() (gas: 158790)
ExampleSoladyERC721UpgradeableTest:testOwnersNotExcludedSafeTransfer() (gas: 158612)
ExampleSoladyERC721UpgradeableTest:testRepeatRegistrationOk() (gas: 5765014)
ExampleSoladyERC721UpgradeableTest:testSetOperatorFilteringEnabled() (gas: 6097330)
ExampleSoladyERC721UpgradeableTest:testSupportsInterface() (gas: 9898)
ExampleSoladyERC721UpgradeableTest:testUpgradeable() (gas: 1182989)
ExampleSoladyERC721UpgradeableTest:testUpgradeable() (gas: 1152536)
OperatorFilterRegistryTest:testCodeHashOf() (gas: 8637)
OperatorFilterRegistryTest:testCopyEntriesOf() (gas: 564491)
OperatorFilterRegistryTest:testCopyEntriesOf_CannotUpdateWhileSubscribed() (gas: 271851)
Expand Down
2 changes: 2 additions & 0 deletions src/example/ExampleSoladyERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ abstract contract ExampleSoladyERC1155 is ERC1155, OperatorFilterer, Ownable, ER
bool public operatorFilteringEnabled;

constructor() {
// Solady's Ownable requires `_initializeOwner` to be called in
// the constructor / initializer.
_initializeOwner(msg.sender);
_registerForOperatorFiltering();
operatorFilteringEnabled = true;
Expand Down
24 changes: 6 additions & 18 deletions src/example/ExampleSoladyERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ abstract contract ExampleSoladyERC721 is ERC721, OperatorFilterer, Ownable, ERC2
bool public operatorFilteringEnabled;

constructor() {
// Solady's Ownable requires `_initializeOwner` to be called in
// the constructor / initializer.
_initializeOwner(msg.sender);
_registerForOperatorFiltering();
operatorFilteringEnabled = true;
Expand Down Expand Up @@ -51,6 +53,10 @@ abstract contract ExampleSoladyERC721 is ERC721, OperatorFilterer, Ownable, ERC2
super.approve(operator, tokenId);
}

/**
* @dev Both safeTransferFrom functions in Solady's ERC721 call this function
* so we don't need to override them.
*/
function transferFrom(address from, address to, uint256 tokenId)
public
payable
Expand All @@ -60,24 +66,6 @@ abstract contract ExampleSoladyERC721 is ERC721, OperatorFilterer, Ownable, ERC2
super.transferFrom(from, to, tokenId);
}

function safeTransferFrom(address from, address to, uint256 tokenId)
public
payable
override
onlyAllowedOperator(from)
{
super.safeTransferFrom(from, to, tokenId);
}

function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data)
public
payable
override
onlyAllowedOperator(from)
{
super.safeTransferFrom(from, to, tokenId, data);
}

function tokenURI(uint256) public pure override returns (string memory) {
return "";
}
Expand Down
2 changes: 2 additions & 0 deletions src/example/upgradeable/ExampleSoladyERC1155Upgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ abstract contract ExampleSoladyERC1155Upgradeable is ERC1155, OperatorFilterer,
initialized = true;
emit Initialized(1);

// Solady's Ownable requires `_initializeOwner` to be called in
// the constructor / initializer.
_initializeOwner(msg.sender);
_registerForOperatorFiltering();
operatorFilteringEnabled = true;
Expand Down
24 changes: 6 additions & 18 deletions src/example/upgradeable/ExampleSoladyERC721Upgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ abstract contract ExampleSoladyERC721Upgradeable is ERC721, OperatorFilterer, Ow
initialized = true;
emit Initialized(1);

// Solady's Ownable requires `_initializeOwner` to be called in
// the constructor / initializer.
_initializeOwner(msg.sender);
_registerForOperatorFiltering();
operatorFilteringEnabled = true;
Expand Down Expand Up @@ -58,6 +60,10 @@ abstract contract ExampleSoladyERC721Upgradeable is ERC721, OperatorFilterer, Ow
super.approve(operator, tokenId);
}

/**
* @dev Both safeTransferFrom functions in Solady's ERC721 call this function
* so we don't need to override them.
*/
function transferFrom(address from, address to, uint256 tokenId)
public
payable
Expand All @@ -67,24 +73,6 @@ abstract contract ExampleSoladyERC721Upgradeable is ERC721, OperatorFilterer, Ow
super.transferFrom(from, to, tokenId);
}

function safeTransferFrom(address from, address to, uint256 tokenId)
public
payable
override
onlyAllowedOperator(from)
{
super.safeTransferFrom(from, to, tokenId);
}

function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data)
public
payable
override
onlyAllowedOperator(from)
{
super.safeTransferFrom(from, to, tokenId, data);
}

function tokenURI(uint256) public pure override returns (string memory) {
return "";
}
Expand Down

0 comments on commit 02f27b3

Please sign in to comment.