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 Dec 16, 2024
1 parent f75f7ea commit df972b0
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

0 comments on commit df972b0

Please sign in to comment.