diff --git a/contracts/WTFSBT1155Minter.sol b/contracts/WTFSBT1155Minter.sol index 4b5f5ce..9c82d3a 100644 --- a/contracts/WTFSBT1155Minter.sol +++ b/contracts/WTFSBT1155Minter.sol @@ -12,9 +12,18 @@ contract WTFSBT1155Minter is Ownable, Nonces { using ECDSA for bytes32; /* ============ Events ============ */ - /// @notice This event is emitted when signer address is changed + /** + * @dev This event is emitted when the signer address is changed + * @param oldSigner The address of the old signer + * @param newSigner The address of the new signer + */ event SignerChanged(address indexed oldSigner, address indexed newSigner); - /// @notice This event is emitted when new SBT is minted + /** + * @dev This event is emitted when a new SBT is minted + * @param to The address to which the SBT is minted + * @param soulId The ID of the SBT + * @param donation The donation amount sent during the mint + */ event SBTMinted( address indexed to, uint256 indexed soulId, @@ -22,12 +31,16 @@ contract WTFSBT1155Minter is Ownable, Nonces { ); /* ============ State Variables ============ */ - address public signer; // singer address + address public signer; // Signer address WTFSBT1155 public wtfsbt; // WTF SBT ERC1155 contract address - uint256 public immutable _cachedChainId; + uint256 public immutable _cachedChainId; // Cached chain ID for replay protection /* ============ Constructor ============ */ - /// @notice initialize WTFSBT1155 addresss and signer address + /** + * @dev Initializes the WTFSBT1155 contract address and signer address + * @param sbtAddr_ The address of the WTFSBT1155 contract + * @param signer_ The address of the initial signer + */ constructor(address payable sbtAddr_, address signer_) Ownable(msg.sender) { wtfsbt = WTFSBT1155(sbtAddr_); signer = signer_; @@ -35,7 +48,17 @@ contract WTFSBT1155Minter is Ownable, Nonces { } /* ============ Public Functions ============ */ - // @dev verify whether a signature is valid + /** + * @dev Verifies whether a signature is valid + * @param to The address to which the SBT will be minted + * @param soulId The ID of the SBT + * @param mintPrice The price of minting the SBT + * @param deadline The deadline until which the signature is valid + * @param chainId The chain ID for replay protection + * @param nonces The nonce to prevent replay attacks + * @param signature The signature to verify + * @return True if the signature is valid, false otherwise + */ function verifySignature( address to, uint256 soulId, @@ -45,25 +68,24 @@ contract WTFSBT1155Minter is Ownable, Nonces { uint256 nonces, bytes memory signature ) public view returns (bool) { - // 生成用于签名的消息 + // Generate the message for signature bytes32 message = keccak256( abi.encodePacked(to, soulId, mintPrice, deadline, chainId, nonces) ); bytes32 ethSignedMessage = message.toEthSignedMessageHash(); - // 恢复签名者地址 + // Recover the address of the signer return signer == ethSignedMessage.recover(signature); } /* ============ External Functions ============ */ /** - * @dev mint token `soulId` to `account` if `signature` is valid. - * `msgHash` is concatenated by `soulId` and `account`. - * @param to: mint address - * @param soulId: ERC1155 token id - * @param mintPrice: token mint price - * @param deadline: token mint deadline - * @param signature: signature by signer + * @dev Mints a token `soulId` to `to` if the `signature` is valid + * @param to The address to which the SBT will be minted + * @param soulId The ID of the SBT + * @param mintPrice The price of minting the SBT + * @param deadline The deadline until which the signature is valid + * @param signature The signature to verify */ function mint( address to, @@ -99,24 +121,26 @@ contract WTFSBT1155Minter is Ownable, Nonces { } /** - * @dev recover sbt to new address. only owner can call. - * @param oldOwner The old owner address for SBT. - * @param newOwner The new owner address for SBT. + * @dev Recovers SBTs to a new address. Only the owner can call this function. + * @param oldOwner The old owner address for SBT + * @param newOwner The new owner address for SBT */ function recover(address oldOwner, address newOwner) external onlyOwner { wtfsbt.recover(oldOwner, newOwner); } /** - * @dev change signer address. only owner can call. - * @param newSigner: address of new signer + * @dev Changes the signer address. Only the owner can call this function. + * @param newSigner The address of the new signer */ function setSigner(address newSigner) external onlyOwner { signer = newSigner; emit SignerChanged(signer, newSigner); } - // withdraw eth + /** + * @dev Withdraws the contract's balance. Only the owner can call this function. + */ function withdraw() external onlyOwner { payable(owner()).transfer(address(this).balance); }