Skip to content

Commit

Permalink
Merge pull request #1002 from yingjingyang/main
Browse files Browse the repository at this point in the history
import latest openzeppelin
  • Loading branch information
yanyanho authored Nov 2, 2023
2 parents 3f74ba8 + 6e2f8b1 commit e4cc243
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ contract ERC721Basic is ERC721, AccessControl {
constructor(string memory name, string memory symbol)
ERC721(name, symbol)
{
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
_grantRole(DEFAULT_ADMIN_ROLE, _msgSender());
}

function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721, AccessControl) returns (bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ pragma solidity ^0.8.0;
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";

contract ERC721LazyMint is ERC721, AccessControl {
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");

constructor(string memory name, string memory symbol)
ERC721(name, symbol)
{
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
_grantRole(DEFAULT_ADMIN_ROLE, _msgSender());
}

function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721, AccessControl) returns (bool) {
Expand All @@ -28,7 +29,7 @@ contract ERC721LazyMint is ERC721, AccessControl {
function _hash(address account, uint256 tokenId)
internal pure returns (bytes32)
{
return ECDSA.toEthSignedMessageHash(keccak256(abi.encodePacked(tokenId, account)));
return MessageHashUtils.toEthSignedMessageHash(keccak256(abi.encodePacked(tokenId, account)));
}

function _verify(bytes32 digest, bytes memory signature)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/cryptography/draft-EIP712.sol";
import "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";

contract ERC721LazyMintWith712 is ERC721, EIP712, AccessControl {
Expand All @@ -13,7 +13,7 @@ contract ERC721LazyMintWith712 is ERC721, EIP712, AccessControl {
ERC721(name, symbol)
EIP712(name, "1.0.0")
{
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
_grantRole(DEFAULT_ADMIN_ROLE, _msgSender());
}

function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721, AccessControl) returns (bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/cryptography/draft-EIP712.sol";
import "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
import "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol";

contract ERC721LazyMintWith712SignatureChecker is ERC721, EIP712, AccessControl {
Expand All @@ -13,7 +13,7 @@ contract ERC721LazyMintWith712SignatureChecker is ERC721, EIP712, AccessControl
ERC721(name, symbol)
EIP712(name, "1.0.0")
{
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
_grantRole(DEFAULT_ADMIN_ROLE, _msgSender());
}

function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721, AccessControl) returns (bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import "@openzeppelin/contracts/interfaces/IERC1271.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";

contract SmartWallet is Ownable, IERC1271 {
constructor(address initialOwner) {
transferOwnership(initialOwner);
constructor(address initialOwner) Ownable(initialOwner) {
}

function execute(address target, uint256 value, bytes memory data) external onlyOwner() returns (bytes memory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ pragma solidity >= 0.8.0;
import "../lib/IERC20.sol";
import "../lib/SafeERC20.sol";
import "../lib/Initializable.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/utils/math/Math.sol";
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";

contract HappyRedPacket is Initializable {
using SafeMath for uint256;

struct RedPacket {
Packed packed;
Expand Down Expand Up @@ -91,7 +90,8 @@ contract HappyRedPacket is Initializable {
uint256 balance_before_transfer = IERC20(_token_addr).balanceOf(address(this));
IERC20(_token_addr).safeTransferFrom(msg.sender, address(this), _total_tokens);
uint256 balance_after_transfer = IERC20(_token_addr).balanceOf(address(this));
received_amount = balance_after_transfer.sub(balance_before_transfer);
// received_amount = balance_after_transfer.sub(balance_before_transfer);
received_amount = balance_after_transfer - balance_before_transfer;
require(received_amount >= _number, "#received > #packets");
}

Expand Down Expand Up @@ -143,15 +143,15 @@ contract HappyRedPacket is Initializable {
// reserve minium amount => (total_number - claimed_number) * 0.1
uint reserve_amount = (total_number - claimed_number) * minium_value;
uint distribute_tokens = remaining_tokens - reserve_amount;
claimed_tokens = random(seed, nonce) % SafeMath.div(SafeMath.mul(distribute_tokens, 2), total_number - claimed_number);
claimed_tokens = random(seed, nonce) % Math.mulDiv(distribute_tokens, 2, total_number - claimed_number);
// minium claimed_tokens for user is 0.1 ; and round the claimed_tokens to decimal 0.1
claimed_tokens = claimed_tokens < minium_value ? minium_value : (claimed_tokens - (claimed_tokens % minium_value));
}
} else {
if (total_number - claimed_number == 1)
claimed_tokens = remaining_tokens;
else
claimed_tokens = SafeMath.div(remaining_tokens, (total_number - claimed_number));
claimed_tokens = Math.ceilDiv(remaining_tokens, (total_number - claimed_number));
}

rp.packed.packed1 = rewriteBox(packed.packed1, 128, 96, remaining_tokens - claimed_tokens);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
pragma solidity ^0.8.20;

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

contract SimpleToken is ERC20PresetMinterPauser {
contract SimpleToken is ERC20 {
/**
* @dev Constructor that gives msg.sender all of existing tokens.
*/
Expand All @@ -20,7 +20,7 @@ contract SimpleToken is ERC20PresetMinterPauser {
string memory symbol,
uint8 decimals_,
uint256 initial_supply
) ERC20PresetMinterPauser(name, symbol) {
) ERC20(name, symbol) {
_decimals = decimals_;
INITIAL_SUPPLY = initial_supply * (10**uint256(decimals_));
_mint(msg.sender, initial_supply * (10**uint256(decimals_)));
Expand Down
9 changes: 8 additions & 1 deletion basic/42-merkle-distributor-airdrop/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ module.exports = {
{ version: '0.7.6', settings },
{ version: '0.6.11', settings },
{ version: '0.5.16', settings },
{ version: '0.8.20', settings },
],
},
etherscan: {
apiKey: process.env.API_KEY
apiKey: {
optimisticEthereum: 'xxx'
},
},
networks: {
localhost: {
Expand Down Expand Up @@ -59,6 +62,10 @@ module.exports = {
url: 'https://polygon-mainnet.infura.io/v3/' + process.env.INFURA_ID,
accounts: mnemonic()
},
optim: {
url: "https://optimism-mainnet.infura.io/v3/" + process.env.INFURA_ID,
accounts: mnemonic()
},
},
gasReporter: {
currency: 'USD',
Expand Down
4 changes: 2 additions & 2 deletions basic/42-merkle-distributor-airdrop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.1",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@nomiclabs/hardhat-etherscan": "^3.0.0",
"@openzeppelin/contracts": "^4.4.2",
"chai": "^4.3.4",
"ethereum-waffle": "^3.3.0",
"ethereumjs-util": "^7.0.4",
Expand All @@ -32,6 +30,8 @@
"merkletreejs": "^0.2.13"
},
"dependencies": {
"@nomiclabs/hardhat-etherscan": "^3.1.7",
"@openzeppelin/contracts": "^5.0.0",
"dotenv": "^16.0.0",
"web3": "^1.4.0"
}
Expand Down

0 comments on commit e4cc243

Please sign in to comment.