Skip to content

Commit

Permalink
feat: add different signatures, waveMint
Browse files Browse the repository at this point in the history
  • Loading branch information
Andres Adjimann committed Sep 24, 2024
1 parent 2259967 commit 04284d6
Show file tree
Hide file tree
Showing 15 changed files with 1,206 additions and 590 deletions.
35 changes: 34 additions & 1 deletion packages/avatar/contracts/mocks/MockERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ contract MockERC20 is ERC20, Ownable {
address target;
address wallet;
uint256 amount;
uint256 waveIndex;
uint256 signatureId;
bytes signature;
}
Expand Down Expand Up @@ -42,10 +43,34 @@ contract MockERC20 is ERC20, Ownable {
uint256 _signatureId,
bytes calldata _signature
) external {
mintArgs = MintArgs({target : _target, wallet : _wallet, amount : _amount, signatureId : _signatureId, signature : _signature});
mintArgs = MintArgs({target : _target, wallet : _wallet, amount : _amount, waveIndex : 0, signatureId : _signatureId, signature : _signature});
MintInterface(_target).mint(_wallet, _amount, _signatureId, _signature);
}

/// @dev instead of using approve and call we use this method directly for testing.
function waveMint(
MintInterface target,
address _wallet,
uint256 _amount,
uint256 _waveIndex,
uint256 _signatureId,
bytes calldata _signature
) external {
target.waveMint(_wallet, _amount, _waveIndex, _signatureId, _signature);
}

function waveMintReenter(
address _target,
address _wallet,
uint256 _amount,
uint256 _waveIndex,
uint256 _signatureId,
bytes calldata _signature
) external {
mintArgs = MintArgs({target : _target, wallet : _wallet, amount : _amount, waveIndex : _waveIndex, signatureId : _signatureId, signature : _signature});
MintInterface(_target).waveMint(_wallet, _amount, _waveIndex, _signatureId, _signature);
}

/// @notice Approve `target` to spend `amount` and call it with data.
/// @param target The address to be given rights to transfer and destination of the call.
/// @param amount The number of tokens allowed.
Expand Down Expand Up @@ -115,4 +140,12 @@ interface MintInterface {
uint256 _signatureId,
bytes calldata _signature
) external;

function waveMint(
address wallet,
uint256 amount,
uint256 waveIndex,
uint256 signatureId,
bytes calldata signature
) external;
}
2 changes: 2 additions & 0 deletions packages/avatar/contracts/mocks/NFTCollectionMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ contract NFTCollectionMock is NFTCollection {
bytes32 erc2771HandlerUpgradable;
bytes32 updatableOperatorFiltererUpgradeable;
bytes32 nftCollection;
bytes32 nftCollectionSignature;
}

/// @custom:oz-upgrades-unsafe-allow constructor
Expand Down Expand Up @@ -49,6 +50,7 @@ contract NFTCollectionMock is NFTCollection {
ret.erc2771HandlerUpgradable = ERC2771_HANDLER_UPGRADABLE_STORAGE_LOCATION;
ret.updatableOperatorFiltererUpgradeable = UPDATABLE_OPERATOR_FILTERER_UPGRADABLE_STORAGE_LOCATION;
ret.nftCollection = NFT_COLLECTION_STORAGE_LOCATION;
ret.nftCollectionSignature = NFT_COLLECTION_SIGNATURE_STORAGE_LOCATION;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import {ContextUpgradeable} from "@openzeppelin/contracts-upgradeable-5.0.2/utils/ContextUpgradeable.sol";

/**
* @title ERC2771HandlerUpgradeable
* @author The Sandbox
Expand All @@ -9,7 +11,7 @@ pragma solidity 0.8.26;
* @dev based on: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.6.0/contracts/metatx/ERC2771Context.sol
* with an initializer for proxies and a mutable forwarder
*/
abstract contract ERC2771HandlerUpgradeable {
abstract contract ERC2771HandlerUpgradeable is ContextUpgradeable {
struct ERC2771HandlerUpgradeableStorage {
address trustedForwarder;
}
Expand Down Expand Up @@ -69,7 +71,7 @@ abstract contract ERC2771HandlerUpgradeable {
* @dev Defaults to the original `msg.sender` whenever a call is not performed by the trusted forwarder
* or the calldata length is less than 20 bytes (an address length).
*/
function _msgSender() internal view virtual returns (address) {
function _msgSender() internal view override virtual returns (address) {
uint256 calldataLength = msg.data.length;
uint256 contextSuffixLength = _contextSuffixLength();
if (_isTrustedForwarder(msg.sender) && calldataLength >= contextSuffixLength) {
Expand All @@ -85,7 +87,7 @@ abstract contract ERC2771HandlerUpgradeable {
* @dev Defaults to the original `msg.data` whenever a call is not performed by the trusted forwarder
* or the calldata length is less than 20 bytes (an address length).
*/
function _msgData() internal view virtual returns (bytes calldata) {
function _msgData() internal view override virtual returns (bytes calldata) {
uint256 calldataLength = msg.data.length;
uint256 contextSuffixLength = _contextSuffixLength();
if (_isTrustedForwarder(msg.sender) && calldataLength >= contextSuffixLength) {
Expand All @@ -108,7 +110,7 @@ abstract contract ERC2771HandlerUpgradeable {
/**
* @notice ERC-2771 specifies the context as being a single address (20 bytes).
*/
function _contextSuffixLength() internal view virtual returns (uint256) {
function _contextSuffixLength() internal view override virtual returns (uint256) {
return 20;
}
}
21 changes: 0 additions & 21 deletions packages/avatar/contracts/nft-collection/INFTCollection.sol
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,6 @@ interface INFTCollection {
*/
event BaseURISet(address indexed operator, string oldBaseURI, string newBaseURI);

/**
* @notice Event emitted when the signer address was set or changed
* @dev emitted when setSignAddress is called
* @param operator the sender of the transaction
* @param oldSignAddress old signer address that is allowed to create mint signatures
* @param newSignAddress new signer address that is allowed to create mint signatures
*/
event SignAddressSet(address indexed operator, address indexed oldSignAddress, address indexed newSignAddress);

/**
* @notice Event emitted when the max supply is set or changed
* @dev emitted when setSignAddress is called
Expand Down Expand Up @@ -166,12 +157,6 @@ interface INFTCollection {
*/
error InvalidTreasury(address mintTreasury);

/**
* @notice The operation failed because the signAddress is wrong
* @param signAddress signer address that is allowed to create mint signatures
*/
error InvalidSignAddress(address signAddress);

/**
* @notice The operation failed because the allowedToExecuteMint is not a contract or wrong
* @param allowedToExecuteMint token address that is used for payments and that is allowed to execute mint
Expand All @@ -190,12 +175,6 @@ interface INFTCollection {
*/
error InvalidBatchData();

/**
* @notice The operation failed because signature is invalid or it was already used
* @param signatureId the ID of the provided signature
*/
error InvalidSignature(uint256 signatureId);

/**
* @notice The operation failed because the wave arguments are wrong
* @param waveMaxTokensOverall the allowed number of tokens to be minted in this wave (cumulative by all minting wallets)
Expand Down
Loading

1 comment on commit 04284d6

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage for this commit

90.36%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
packages/avatar/contracts/avatar
   AvatarCollection.sol74.25%56.56%73.81%90.37%285, 329–337, 339–340, 345, 403–407, 425, 442, 459, 483–487, 491–492, 495, 526, 537, 545, 545–546, 565, 599, 621, 631, 712, 732, 745, 745, 745, 763, 763, 765, 774, 774, 776, 786, 786–787, 797, 797–798, 809, 809–810, 823, 832, 861–862, 992–993, 996, 999
   CollectionAccessControl.sol60.87%53.33%63.64%67.86%120, 130–131, 140, 150–151, 161–162, 162, 162, 164–165, 167, 173, 173–174, 185, 192, 192–194, 98–99
   ERC721BurnMemoryEnumerableUpgradeable.sol93.33%75%100%100%62, 75
packages/avatar/contracts/common
   IERC4906.sol100%100%100%100%
   IERC5313.sol100%100%100%100%
packages/avatar/contracts/common/BaseWithStorage/ERC2771
   ERC2771HandlerUpgradeable.sol44.44%25%60%44.44%22, 26, 29, 38, 38, 38–39, 41
packages/avatar/contracts/common/OperatorFilterer
   IOperatorFilterRegistry.sol100%100%100%100%
   UpdatableOperatorFiltererUpgradeable.sol11.11%10%25%9.52%18, 23–24, 24, 24–25, 27, 27, 27–28, 30, 38, 38, 38, 42, 42, 42–44, 46, 46, 46–47, 50, 55, 55, 55–56, 56, 56–57, 60, 68, 68, 68–69, 71
packages/avatar/contracts/nft-collection
   ERC2771HandlerUpgradeable.sol100%100%100%100%
   ERC721BurnMemoryUpgradeable.sol100%100%100%100%
   INFTCollection.sol100%100%100%100%
   NFTCollection.sol99.76%99.28%100%100%303
   NFTCollectionSignature.sol100%100%100%100%
   UpdatableOperatorFiltererUpgradeable.sol100%100%100%100%
packages/avatar/contracts/proxy
   CollectionFactory.sol86.59%89.06%75%87.50%149, 230, 293, 362–366, 368, 385, 402, 410, 410–411, 423, 423–424
   CollectionProxy.sol88.24%50%100%100%55, 70
packages/avatar/contracts/raffle
   DanceFight.sol75%50%100%100%20
   FistOfTheNorthStar.sol75%50%100%100%20
   GenericRaffle.sol67.92%52.22%62.07%84.95%178, 189–195, 225–229, 252–259, 266–267, 270, 288, 288–289, 289, 289–290, 308, 381, 390, 409, 409–410, 419, 419, 421, 430, 430, 432, 442, 442–443, 453, 453–454, 465, 465–466, 566, 575, 626–627, 630, 633
   HellsKitchen.sol75%50%100%100%20
   MadBalls.sol75%50%100%100%20
   ParisHilton.sol75%50%100%100%20
   Rabbids.sol75%50%100%100%20

Please sign in to comment.