Skip to content

Commit

Permalink
feat: update solhint and prettier packages
Browse files Browse the repository at this point in the history
  • Loading branch information
adjisb committed Jun 9, 2023
1 parent a14aa54 commit 51a8b08
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 94 deletions.
1 change: 0 additions & 1 deletion packages/giveaway/.prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ module.exports = {
printWidth: 120,
tabWidth: 4,
singleQuote: false,
explicitTypes: 'always',
},
},
],
Expand Down
90 changes: 20 additions & 70 deletions packages/giveaway/contracts/SignedMultiGiveaway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,9 @@ import {IERC721Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC7
import {IERC1155Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC1155/IERC1155Upgradeable.sol";
import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import {ERC2771Handler} from "./ERC2771Handler.sol";
import {
ERC1155HolderUpgradeable,
ERC1155ReceiverUpgradeable
} from "@openzeppelin/contracts-upgradeable/token/ERC1155/utils/ERC1155HolderUpgradeable.sol";
import {
ERC721HolderUpgradeable,
IERC721ReceiverUpgradeable
} from "@openzeppelin/contracts-upgradeable/token/ERC721/utils/ERC721HolderUpgradeable.sol";
import {
AccessControlEnumerableUpgradeable
} from "@openzeppelin/contracts-upgradeable/access/AccessControlEnumerableUpgradeable.sol";
import {ERC1155HolderUpgradeable, ERC1155ReceiverUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC1155/utils/ERC1155HolderUpgradeable.sol";
import {ERC721HolderUpgradeable, IERC721ReceiverUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/utils/ERC721HolderUpgradeable.sol";
import {AccessControlEnumerableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/AccessControlEnumerableUpgradeable.sol";

/// @title This contract give rewards in any ERC20, ERC721 or ERC1155 when the backend authorize it via message signing.
/// @dev The whole contract is split in the base one this implementation to facilitate the reading and split
Expand Down Expand Up @@ -180,11 +172,7 @@ contract SignedMultiGiveaway is
/// @param tokenId for ERC1155 is the id of the token, else it must be zero
/// @param maxWeiPerClaim the max amount per each claim, for example 0.01eth per claim
/// @dev even tokenId is kind of inconsistent for tokenType!=ERC1155 it doesn't harm
function setMaxWeiPerClaim(
address token,
uint256 tokenId,
uint256 maxWeiPerClaim
) external onlyAdmin {
function setMaxWeiPerClaim(address token, uint256 tokenId, uint256 maxWeiPerClaim) external onlyAdmin {
require(token != address(0), "invalid token address");
_perTokenLimitData[token][tokenId].maxWeiPerClaim = maxWeiPerClaim;
emit MaxWeiPerClaimSet(token, tokenId, maxWeiPerClaim, _msgSender());
Expand Down Expand Up @@ -240,21 +228,13 @@ contract SignedMultiGiveaway is
}

/// @dev See {IERC165-supportsInterface}.
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(AccessControlEnumerableUpgradeable, ERC1155ReceiverUpgradeable)
returns (bool)
{
function supportsInterface(
bytes4 interfaceId
) public view virtual override(AccessControlEnumerableUpgradeable, ERC1155ReceiverUpgradeable) returns (bool) {
return (interfaceId == type(IERC721ReceiverUpgradeable).interfaceId) || super.supportsInterface(interfaceId);
}

function _transfer(
address from,
address to,
ClaimEntry[] calldata claims
) internal {
function _transfer(address from, address to, ClaimEntry[] calldata claims) internal {
uint256 len = claims.length;
require(len <= _limits.maxClaimEntries + 1, "too many claims");
for (uint256 i; i < len; i++) {
Expand All @@ -263,11 +243,7 @@ contract SignedMultiGiveaway is
}

// solhint-disable code-complexity
function _transferEntry(
address from,
address to,
ClaimEntry calldata claimEntry
) internal {
function _transferEntry(address from, address to, ClaimEntry calldata claimEntry) internal {
if (claimEntry.tokenType == TokenType.ERC20) {
_transferERC20(from, to, claimEntry);
} else if (claimEntry.tokenType == TokenType.ERC721) {
Expand All @@ -287,11 +263,7 @@ contract SignedMultiGiveaway is
}
}

function _transferERC20(
address from,
address to,
ClaimEntry calldata claimEntry
) internal {
function _transferERC20(address from, address to, ClaimEntry calldata claimEntry) internal {
address tokenAddress = claimEntry.tokenAddress;
uint256 amount = abi.decode(claimEntry.data, (uint256));
_checkLimits(_perTokenLimitData[tokenAddress][0], amount);
Expand All @@ -302,23 +274,15 @@ contract SignedMultiGiveaway is
}
}

function _transferERC721(
address from,
address to,
ClaimEntry calldata claimEntry
) internal {
function _transferERC721(address from, address to, ClaimEntry calldata claimEntry) internal {
address tokenAddress = claimEntry.tokenAddress;
uint256 tokenId = abi.decode(claimEntry.data, (uint256));
// We want a global limit, not per tokenId.
_checkLimits(_perTokenLimitData[tokenAddress][0], 1);
IERC721Upgradeable(tokenAddress).transferFrom(from, to, tokenId);
}

function _transferERC721Batch(
address from,
address to,
ClaimEntry calldata claimEntry
) internal {
function _transferERC721Batch(address from, address to, ClaimEntry calldata claimEntry) internal {
address tokenAddress = claimEntry.tokenAddress;
uint256[] memory tokenIds = abi.decode(claimEntry.data, (uint256[]));
uint256 len = tokenIds.length;
Expand All @@ -329,23 +293,15 @@ contract SignedMultiGiveaway is
}
}

function _transferERC721Safe(
address from,
address to,
ClaimEntry calldata claimEntry
) internal {
function _transferERC721Safe(address from, address to, ClaimEntry calldata claimEntry) internal {
address tokenAddress = claimEntry.tokenAddress;
uint256 tokenId = abi.decode(claimEntry.data, (uint256));
// We want a global limit, not per tokenId.
_checkLimits(_perTokenLimitData[tokenAddress][0], 1);
IERC721Upgradeable(tokenAddress).safeTransferFrom(from, to, tokenId);
}

function _transferERC721SafeBatch(
address from,
address to,
ClaimEntry calldata claimEntry
) internal {
function _transferERC721SafeBatch(address from, address to, ClaimEntry calldata claimEntry) internal {
address tokenAddress = claimEntry.tokenAddress;
uint256[] memory tokenIds = abi.decode(claimEntry.data, (uint256[]));
uint256 len = tokenIds.length;
Expand All @@ -356,25 +312,19 @@ contract SignedMultiGiveaway is
}
}

function _transferERC1155(
address from,
address to,
ClaimEntry calldata claimEntry
) internal {
function _transferERC1155(address from, address to, ClaimEntry calldata claimEntry) internal {
address tokenAddress = claimEntry.tokenAddress;
(uint256 tokenId, uint256 amount, bytes memory data) = abi.decode(claimEntry.data, (uint256, uint256, bytes));
_checkLimits(_perTokenLimitData[tokenAddress][tokenId], amount);
IERC1155Upgradeable(tokenAddress).safeTransferFrom(from, to, tokenId, amount, data);
}

function _transferERC1155Batch(
address from,
address to,
ClaimEntry calldata claimEntry
) internal {
function _transferERC1155Batch(address from, address to, ClaimEntry calldata claimEntry) internal {
address tokenAddress = claimEntry.tokenAddress;
(uint256[] memory ids, uint256[] memory amounts, bytes memory data) =
abi.decode(claimEntry.data, (uint256[], uint256[], bytes));
(uint256[] memory ids, uint256[] memory amounts, bytes memory data) = abi.decode(
claimEntry.data,
(uint256[], uint256[], bytes)
);

uint256 len = ids.length;
require(len > 0, "invalid data len");
Expand Down
26 changes: 15 additions & 11 deletions packages/giveaway/contracts/SignedMultiGiveawayBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ pragma solidity 0.8.18;

import {EIP712Upgradeable} from "@openzeppelin/contracts-upgradeable/utils/cryptography/draft-EIP712Upgradeable.sol";
import {ECDSAUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/cryptography/ECDSAUpgradeable.sol";
import {
AccessControlEnumerableUpgradeable
} from "@openzeppelin/contracts-upgradeable/access/AccessControlEnumerableUpgradeable.sol";
import {AccessControlEnumerableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/AccessControlEnumerableUpgradeable.sol";

/// @title This contract give rewards in any ERC20, ERC721 or ERC1155 when the backend authorize it via message signing.
/// @dev The whole contract is split in this base one and implementation to facilitate the reading and split
Expand All @@ -19,7 +17,16 @@ abstract contract SignedMultiGiveawayBase is EIP712Upgradeable, AccessControlEnu
bytes32 s;
}

enum TokenType {INVALID, ERC20, ERC721, ERC721_BATCH, ERC721_SAFE, ERC721_SAFE_BATCH, ERC1155, ERC1155_BATCH}
enum TokenType {
INVALID,
ERC20,
ERC721,
ERC721_BATCH,
ERC721_SAFE,
ERC721_SAFE_BATCH,
ERC1155,
ERC1155_BATCH
}
/// @dev this is a union type, data depends on the tokenType it can be amount, amount + tokenId, etc.
struct ClaimEntry {
TokenType tokenType;
Expand Down Expand Up @@ -78,11 +85,7 @@ abstract contract SignedMultiGiveawayBase is EIP712Upgradeable, AccessControlEnu
}
}

function _checkSig(
uint256 numberOfSignatures,
bytes32 digest,
Signature[] calldata sigs
) internal virtual {
function _checkSig(uint256 numberOfSignatures, bytes32 digest, Signature[] calldata sigs) internal virtual {
require(numberOfSignatures == sigs.length, "not enough signatures");
address lastSig = address(0);
for (uint256 i; i < numberOfSignatures; i++) {
Expand Down Expand Up @@ -127,8 +130,9 @@ abstract contract SignedMultiGiveawayBase is EIP712Upgradeable, AccessControlEnu
address to,
ClaimEntry[] calldata claims
) internal view virtual returns (bytes32) {
bytes32 structHash =
keccak256(abi.encode(CLAIM_TYPEHASH, _hashClaimIds(claimIds), expiration, from, to, _hashClaims(claims)));
bytes32 structHash = keccak256(
abi.encode(CLAIM_TYPEHASH, _hashClaimIds(claimIds), expiration, from, to, _hashClaims(claims))
);
return _hashTypedDataV4(structHash);
}

Expand Down
7 changes: 1 addition & 6 deletions packages/giveaway/contracts/test/FakeMintableERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ contract FakeMintableERC1155 is ERC1155Upgradeable {
super.__ERC1155_init("http://test.test");
}

function mint(
address account,
uint256 id,
uint256 amount,
bytes memory data
) public {
function mint(address account, uint256 id, uint256 amount, bytes memory data) public {
_mint(account, id, amount, data);
}
}
14 changes: 8 additions & 6 deletions packages/giveaway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"version": "0.0.1",
"description": "Contracts used to airdrop tokens",
"license": "MIT",

"main": "index.js",
"directories": {
"contracts": "contracts"
Expand Down Expand Up @@ -43,8 +42,11 @@
"@nomiclabs/hardhat-ethers": "^2.2.3",
"@nomiclabs/hardhat-etherscan": "^3.1.7",
"@openzeppelin/contracts-upgradeable": "^4.9.0",
"@typechain/ethers-v5": "^11.0.0",
"@typechain/hardhat": "^7.0.0",
"@typechain/ethers-v5": "^10.1.0",
"@typechain/hardhat": "^6.1.2",
"@types/chai": "^4.3.5",
"@types/mocha": "^10.0.1",
"@types/node": "^20.2.5",
"@typescript-eslint/eslint-plugin": "^5.59.8",
"@typescript-eslint/parser": "^5.59.8",
"chai": "^4.3.7",
Expand All @@ -59,13 +61,13 @@
"ethers": "^5.0.0",
"hardhat": "^2.14.1",
"hardhat-gas-reporter": "^1.0.9",
"prettier": "2.0.5",
"prettier-plugin-solidity": "1.0.0-beta.11",
"prettier": "^2.8.8",
"prettier-plugin-solidity": "^1.1.3",
"solhint": "^3.4.1",
"solhint-plugin-prettier": "^0.0.5",
"solidity-coverage": "^0.8.2",
"ts-node": "^10.9.1",
"typechain": "^8.2.0",
"typescript": "^5.0.4"
"typescript": "5.0.4"
}
}

0 comments on commit 51a8b08

Please sign in to comment.