Skip to content

Commit

Permalink
feat: minter address for minting
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoAcosta committed Nov 27, 2024
1 parent 9326811 commit 6b5b353
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/stamps/AccountOwnershipStamp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ contract AccountOwnershipStamp is Stamp, IAccountOwnershipStamp {
/// @param _platform The platform name for this stamp
constructor(
address _signer,
address _minter,
string memory _platform
)
Stamp(
IStampView.StampType.AccountOwnership,
string.concat(_platform, " Account Owner"),
"OWNER",
"0.1.0",
_signer
_signer,
_minter
)
{
PLATFORM = _platform;
Expand All @@ -50,7 +52,7 @@ contract AccountOwnershipStamp is Stamp, IAccountOwnershipStamp {

bytes memory encodedData = abi.encode(PLATFORM, username, msg.sender, deadline);

uint256 tokenId = _mintStamp(msg.sender, encodedData, signature, deadline);
uint256 tokenId = _mintWithSignature(msg.sender, encodedData, signature, deadline);

// _usedUsernames[username] = tokenId;
// _tokenUsernames[tokenId] = username;
Expand Down
28 changes: 26 additions & 2 deletions src/stamps/Stamp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ abstract contract Stamp is ERC721Enumerable, EIP712, IStamp {
/// @notice The address of the space this stamp is associated with
ISpace public space;

/// @notice The address authorized to mint stamps
address public minter;

/// @notice Initializes the Stamp contract
/// @dev Sets up the ERC721 token, EIP712 domain separator, and stamp-specific properties
/// @param _stampType The type of stamp
Expand All @@ -38,10 +41,12 @@ abstract contract Stamp is ERC721Enumerable, EIP712, IStamp {
string memory stampName,
string memory stampSymbol,
string memory eip712version,
address _signer
address _signer,
address _minter
) ERC721(stampName, stampSymbol) EIP712("Plasa Stamps", eip712version) {
signer = _signer;
stampType = _stampType;
minter = _minter;
}

/// @notice Computes the typed data hash for signature verification
Expand All @@ -57,7 +62,7 @@ abstract contract Stamp is ERC721Enumerable, EIP712, IStamp {
/// @param signature Signature authorizing the mint
/// @param deadline Timestamp after which the signature is no longer valid
/// @return uint256 The ID of the newly minted stamp
function _mintStamp(
function _mintWithSignature(
address to,
bytes memory data,
bytes calldata signature,
Expand All @@ -79,6 +84,25 @@ abstract contract Stamp is ERC721Enumerable, EIP712, IStamp {
}

// Mint the new stamp
return _mint(to);
}

/// @notice Internal function to mint a new stamp by the minter
/// @dev Checks if the sender is the minter, then mints the stamp
/// @param to Address to mint the stamp to
/// @return uint256 The ID of the newly minted stamp
function _mintByMinter(address to) internal virtual returns (uint256) {
if (msg.sender != minter) revert InvalidMinter();

// Mint the new stamp
return _mint(to);
}

/// @notice Internal function to mint a new stamp
/// @dev Mints the stamp and sets the minting timestamp
/// @param to Address to mint the stamp to
/// @return uint256 The ID of the newly minted stamp
function _mint(address to) private returns (uint256) {
uint256 newStampId = totalSupply() + 1;
_safeMint(to, newStampId);
mintingTimestamps[newStampId] = block.timestamp;
Expand Down
8 changes: 7 additions & 1 deletion src/stamps/interfaces/IFollowerSinceStamp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ interface IFollowerSinceStamp is IStamp {
/// @param deadline The deadline for the signature to be valid
/// @param signature The signature authorizing the mint
/// @return The ID of the minted stamp
function mintStamp(uint256 since, uint256 deadline, bytes calldata signature) external returns (uint256);
function mintWithSignature(uint256 since, uint256 deadline, bytes calldata signature) external returns (uint256);

/// @notice Mints a new follower since stamp by the minter
/// @param user The address of the follower
/// @param since The timestamp when the following relationship started
/// @return The ID of the minted stamp
function mintByMinter(address user, uint256 since) external returns (uint256);

/// @notice Retrieves the follower since timestamp for a given address
/// @param user The address of the follower
Expand Down
3 changes: 3 additions & 0 deletions src/stamps/interfaces/IStamp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ interface IStamp is IERC721Enumerable, IStampView {
/// @param tokenId The ID of the non-existent token
error TokenDoesNotExist(uint256 tokenId);

/// @notice Thrown when an invalid minter address is provided
error InvalidMinter();

/// @notice Returns the address of the signer authorized to sign minting requests
/// @return The address of the authorized signer
/// @dev This function should be implemented to return the current authorized signer's address
Expand Down

0 comments on commit 6b5b353

Please sign in to comment.