Skip to content

Commit

Permalink
feat: 🎸 openzeppelin upgraded to 5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
oleggrib committed Nov 28, 2023
1 parent d9a01b6 commit 4ef7a83
Show file tree
Hide file tree
Showing 22 changed files with 1,954 additions and 491 deletions.
9 changes: 6 additions & 3 deletions contracts/helpers/ExampleERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

pragma solidity ^0.8.16;

import "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract ExampleERC20 is ERC20PresetMinterPauser {
constructor(string memory name, string memory symbol) ERC20PresetMinterPauser(name, symbol) {}
contract ExampleERC20 is ERC20 {
constructor(string memory name, string memory symbol) ERC20(name, symbol) {}
function mint( address to, uint amount) public {
_mint(to, amount);
}
}
2 changes: 2 additions & 0 deletions contracts/helpers/ExampleERC5169.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ import "../package/ERC/ERC5169.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract ExampleERC5169 is Ownable, ERC5169 {
constructor() Ownable(msg.sender){}

function _authorizeSetScripts(string[] memory newScriptURI) internal override onlyOwner {}
}
23 changes: 13 additions & 10 deletions contracts/helpers/ExampleERC721.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.16;
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol";
import "../package/tokens/extensions/Minter.sol";
import "../package/tokens/extensions/ParentContracts.sol";
import "../package/tokens/extensions/SharedHolders.sol";
Expand All @@ -11,22 +10,27 @@ import "../package/tokens/OptimizedEnumerable.sol";
import "../package/royalty/ERC2981RoyaltyFull.sol";

contract ExampleERC721 is Ownable, ERC2981RoyaltyFull, Minter, SharedHolders, ParentContracts, OptimizedEnumerable {
constructor(string memory name, string memory symbol) OptimizedEnumerable(name, symbol) {}
constructor(string memory name, string memory symbol) OptimizedEnumerable(name, symbol) Ownable(msg.sender) {}

function _authorizeAddParent(address newContract) internal override onlyOwner {}

function _authorizeSetRoyalty() internal override onlyOwner {}

function _authorizeSetSharedHolder(address[] calldata newAddresses) internal override onlyOwner {}

function _beforeTokenTransfer(
address from,
function _update(
address to,
uint256 tokenId,
uint256
) internal override(Minter, OptimizedEnumerable) {
Minter._beforeTokenTransfer(from, to, tokenId, 1);
OptimizedEnumerable._beforeTokenTransfer(from, to, tokenId, 1);
address auth
) internal override(Minter, OptimizedEnumerable) returns (address) {
Minter._update(to, tokenId, auth);
return OptimizedEnumerable._update(to, tokenId, auth);
}

function _ownerOf(
uint256 tokenId
) internal override(Minter, ERC721) view returns (address) {
return ERC721._ownerOf(tokenId);
}

function _exists(uint256 tokenId) internal view override(ERC2981RoyaltyFull, OptimizedEnumerable) returns (bool) {
Expand All @@ -39,7 +43,6 @@ contract ExampleERC721 is Ownable, ERC2981RoyaltyFull, Minter, SharedHolders, Pa

function burn(uint256 tokenId) public virtual {
//solhint-disable-next-line max-line-length
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner or approved");
_burn(tokenId);
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/helpers/ExampleUriChanger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ contract ExampleUriChanger is Ownable, UriChanger {
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() UriChanger(msg.sender) {}
constructor() UriChanger(msg.sender) Ownable(msg.sender) {}

function _authorizeUpdateUriChanger(address newAddress) internal override onlyOwner {}

Expand Down
7 changes: 2 additions & 5 deletions contracts/helpers/ExampleUriChangerUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import "../package/access/UriChangerUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";

contract ExampleUriChangerUpgradeable is OwnableUpgradeable, UriChangerUpgradeable, UUPSUpgradeable {
contract ExampleUriChangerUpgradeable is OwnableUpgradeable, UriChangerUpgradeable {
uint public val;

/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
function initialize() public initializer {
__UUPSUpgradeable_init();
__Ownable_init();
__Ownable_init(msg.sender);
__UriChangerInit(msg.sender);
val = 1;
}
Expand All @@ -23,8 +22,6 @@ contract ExampleUriChangerUpgradeable is OwnableUpgradeable, UriChangerUpgradeab

function _authorizeUpdateUriChanger(address newAddress) internal override onlyOwner {}

function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}

function setValue(uint _val) public onlyUriChanger {
val = _val;
}
Expand Down
4 changes: 3 additions & 1 deletion contracts/helpers/RoyaltySpliterFull.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;
pragma solidity ^0.8.20;

import "../package/royalty/RoyaltySpliterERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract RoyaltySpliterFull is Ownable, RoyaltySpliterERC20 {
constructor() Ownable(msg.sender){}

function _authorizeUpdateRecievers(Receiver[] memory newReceivers) internal override onlyOwner {}
}
4 changes: 2 additions & 2 deletions contracts/package/attestation/AsnDecode.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: MIT
/* Attestation decode and validation */
/* AlphaWallet 2021 - 2022 */
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;
pragma solidity ^0.8.16;
pragma experimental ABIEncoderV2;

contract AsnDecode {
Expand Down
50 changes: 31 additions & 19 deletions contracts/package/derived/MintPassOptimized.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@ pragma solidity ^0.8.16;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/math/Math.sol";

import "@openzeppelin/contracts/utils/Address.sol";

import "../royalty/DerivedERC2981Royalty.sol";

contract MintPassOptimized is ERC721, Ownable, DerivedERC2981Royalty, IERC721Enumerable {
using SafeMath for uint256;
using Math for uint256;
using Address for address;

using Counters for Counters.Counter;

/* solhint-disable var-name-mixedcase */
// slither-disable-start naming-convention
address immutable _BAYC;
Expand All @@ -34,7 +31,7 @@ contract MintPassOptimized is ERC721, Ownable, DerivedERC2981Royalty, IERC721Enu
uint256 constant _MAX_PER_ADDRESS = 50;
uint256 constant _MAX_ALLOWED = 2500;

Counters.Counter private _tokenIdCounter;
uint private _tokenIdCounter;
/* solhint-disable var-name-mixedcase */
//slither-disable-next-line naming-convention
uint256 immutable _MINT_START_TIME;
Expand All @@ -56,21 +53,35 @@ contract MintPassOptimized is ERC721, Ownable, DerivedERC2981Royalty, IERC721Enu
address dape_,
address rr_,
uint256 mintStartTime_
) ERC721(name_, symbol_) Ownable() {
) ERC721(name_, symbol_) Ownable(msg.sender) {
require(bayc_ != address(0) && mayc_ != address(0) && dape_ != address(0), "Contract required");
_BAYC = bayc_;
_MAYC = mayc_;
_DAPE = dape_;
_setRoyaltyContract(rr_);

_tokenIdCounter.increment();
_tokenIdCounter++;

// TODO update royalty value
_setRoyalty(200); // 100 = 1%

_MINT_START_TIME = mintStartTime_;
}

function isContract(address _address) public view returns (bool) {
// address(..).code.size
// return account.code.length > 0;
uint32 size;
assembly {
size := extcodesize(_address)
}
return size > 0;
}

function _exists(uint tokenId) internal view returns(bool){
return ownerOf(tokenId) != address(0);
}

// required to solve inheritance
function supportsInterface(
bytes4 interfaceId
Expand All @@ -93,7 +104,7 @@ contract MintPassOptimized is ERC721, Ownable, DerivedERC2981Royalty, IERC721Enu
}

function _setRoyaltyContract(address newAddress) internal {
require(newAddress.isContract(), "Only Contract allowed");
require(isContract(newAddress), "Only Contract allowed");
emit RoyaltyContractUpdate(newAddress);
_royaltyReceiver = newAddress;
}
Expand All @@ -111,7 +122,7 @@ contract MintPassOptimized is ERC721, Ownable, DerivedERC2981Royalty, IERC721Enu
}

function mintedTotal() public view returns (uint256) {
return _tokenIdCounter.current() - 1;
return _tokenIdCounter - 1;
}

function mintedForAddress(address addr) public view returns (uint256) {
Expand All @@ -136,11 +147,12 @@ contract MintPassOptimized is ERC721, Ownable, DerivedERC2981Royalty, IERC721Enu
function _mintFor(uint256 mintpassNumber) internal virtual {
// uint256 currentBalance = ERC721Upgradeable.balanceOf(_msgSender());
uint256 minted = _mintedPerAddress[_msgSender()];

require(_getMintPrice().mul(mintpassNumber) == msg.value, "Ether value sent is not correct");
(bool ok, uint res) = _getMintPrice().tryMul(mintpassNumber);
require(ok, "Operation result overflows UINT256");
require(res == msg.value, "Ether value sent is not correct");

require(_MAX_PER_ADDRESS >= (minted + mintpassNumber), "Too much MintPasses requested");
require(_getMaxAllowed() >= (_tokenIdCounter.current() - 1 + mintpassNumber), "Limit reached");
require(_getMaxAllowed() >= (_tokenIdCounter - 1 + mintpassNumber), "Limit reached");
// require( _isTokenOwner(erc721, tokenId), "Sender not an owner");

uint256 originsNumber = _getBalance(_BAYC) + _getBalance(_MAYC);
Expand Down Expand Up @@ -182,8 +194,8 @@ contract MintPassOptimized is ERC721, Ownable, DerivedERC2981Royalty, IERC721Enu
}

function _mintWrap(address to) internal returns (uint256 currentId) {
currentId = _tokenIdCounter.current();
_tokenIdCounter.increment();
currentId = _tokenIdCounter;
_tokenIdCounter++;
_mint(to, currentId);
}

Expand All @@ -193,13 +205,13 @@ contract MintPassOptimized is ERC721, Ownable, DerivedERC2981Royalty, IERC721Enu
function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {
require(index < balanceOf(owner), "MP: owner index out of bounds");

uint256 numMintedSoFar = _tokenIdCounter.current();
uint256 numMintedSoFar = _tokenIdCounter;
uint256 tokenIdsIdx = 0;

// Counter overflow is impossible as the loop breaks when uint256 i is equal to another uint256 numMintedSoFar.
unchecked {
for (uint256 i = 1; i < numMintedSoFar; i++) {
if (_exists(i) && (ownerOf(i) == owner)) {
if (ownerOf(i) == owner) {
if (tokenIdsIdx == index) {
return i;
}
Expand All @@ -215,14 +227,14 @@ contract MintPassOptimized is ERC721, Ownable, DerivedERC2981Royalty, IERC721Enu
}

function totalSupply() public view virtual override returns (uint256) {
return _tokenIdCounter.current() - _burnt - 1;
return _tokenIdCounter - _burnt - 1;
}

/**
* @dev See {IERC721Enumerable-tokenByIndex}.
*/
function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
uint256 numMintedSoFar = _tokenIdCounter.current();
uint256 numMintedSoFar = _tokenIdCounter;

require(index < totalSupply(), "MP: index out of bounds");
uint256 tokenIdsIdx = 0;
Expand Down
2 changes: 1 addition & 1 deletion contracts/package/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stl-contracts",
"version": "2.2.0",
"version": "2.4.0",
"description": "STL contracts",
"repository": {
"type": "git",
Expand Down
19 changes: 9 additions & 10 deletions contracts/package/tokens/OptimizedEnumerable.sol
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.16;
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "./OptimizedEnumerableBase.sol";

contract OptimizedEnumerable is OptimizedEnumerableBase, ERC721 {
function _beforeTokenTransfer(
address from,
function _update(
address to,
uint256 tokenId,
uint256 batchSize
) internal virtual override(OptimizedEnumerableBase, ERC721) {
OptimizedEnumerableBase._beforeTokenTransfer(from, to, tokenId, batchSize);
ERC721._beforeTokenTransfer(from, to, tokenId, batchSize);
address auth
) internal virtual override(OptimizedEnumerableBase, ERC721) returns (address) {
OptimizedEnumerableBase._update(to, tokenId, auth);
return ERC721._update( to, tokenId, auth);
}

function balanceOf(
Expand All @@ -25,11 +24,11 @@ contract OptimizedEnumerable is OptimizedEnumerableBase, ERC721 {
function ownerOf(
uint256 tokenId
) public view virtual override(OptimizedEnumerableBase, ERC721) returns (address owner) {
return ERC721.ownerOf(tokenId);
return ERC721._ownerOf(tokenId);
}

function _exists(uint256 tokenId) internal view virtual override(OptimizedEnumerableBase, ERC721) returns (bool) {
return ERC721._exists(tokenId);
function _exists(uint256 tokenId) internal view virtual override returns (bool) {
return ownerOf(tokenId) != address(0);
}

function supportsInterface(
Expand Down
Loading

0 comments on commit 4ef7a83

Please sign in to comment.