-
Notifications
You must be signed in to change notification settings - Fork 25
Refactor ERC20FixedDenomination and Manager for Hybrid NFT Support #146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
45e7482
d2d9b33
8d4e965
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,13 +1,19 @@ | ||||||
| // SPDX-License-Identifier: MIT | ||||||
| pragma solidity 0.8.24; | ||||||
|
|
||||||
| import "./ERC20NullOwnerCappedUpgradeable.sol"; | ||||||
| import "./ERC404NullOwnerCappedUpgradeable.sol"; | ||||||
| import "./libraries/Predeploys.sol"; | ||||||
| import "./Ethscriptions.sol"; | ||||||
| import "./ERC20FixedDenominationManager.sol"; | ||||||
| import {LibString} from "solady/utils/LibString.sol"; | ||||||
| import {Base64} from "solady/utils/Base64.sol"; | ||||||
|
|
||||||
| /// @title ERC20FixedDenomination | ||||||
| /// @notice ERC-20 proxy whose supply is managed in a fixed denomination by the manager contract. | ||||||
| /// @notice Hybrid ERC-20/ERC-721 proxy whose supply is managed in fixed denominations by the manager contract. | ||||||
| /// @dev User-initiated transfers/approvals are disabled; only the manager can mutate balances. | ||||||
| contract ERC20FixedDenomination is ERC20NullOwnerCappedUpgradeable { | ||||||
| /// Each NFT represents a fixed denomination amount (e.g., 1 NFT = mintAmount tokens). | ||||||
| contract ERC20FixedDenomination is ERC404NullOwnerCappedUpgradeable { | ||||||
| using LibString for *; | ||||||
|
|
||||||
| // ============================================================= | ||||||
| // CONSTANTS | ||||||
|
|
@@ -48,36 +54,153 @@ contract ERC20FixedDenomination is ERC20NullOwnerCappedUpgradeable { | |||||
| string memory name_, | ||||||
| string memory symbol_, | ||||||
| uint256 cap_, | ||||||
| uint256 mintAmount_, | ||||||
| bytes32 deployEthscriptionId_ | ||||||
| ) external initializer { | ||||||
| __ERC20_init(name_, symbol_); | ||||||
| __ERC20Capped_init(cap_); | ||||||
| // cap_ is maxSupply * 10**18 | ||||||
| // mintAmount_ is the denomination amount (e.g., 1000 for 1000 tokens per NFT) | ||||||
| // units is mintAmount_ * 10**18 (amount of wei per NFT) | ||||||
|
|
||||||
| uint256 units_ = mintAmount_ * (10 ** decimals()); | ||||||
|
|
||||||
| __ERC404_init(name_, symbol_, cap_, units_); | ||||||
| deployEthscriptionId = deployEthscriptionId_; | ||||||
| } | ||||||
|
|
||||||
| /// @notice Mint tokens (manager only) | ||||||
| function mint(address to, uint256 amount) external onlyManager { | ||||||
| _mint(to, amount); | ||||||
| /// @notice Historical accessor for the fixed denomination (whole tokens per NFT) | ||||||
| function mintAmount() public view returns (uint256) { | ||||||
| return denomination(); | ||||||
| } | ||||||
|
|
||||||
| /// @notice Mint one fixed-denomination note (manager only) | ||||||
| /// @param to The recipient address | ||||||
| /// @param nftId The specific NFT ID to mint (the mintId) | ||||||
| function mint(address to, uint256 nftId) external onlyManager { | ||||||
| // Mint the ERC20 tokens without triggering NFT creation | ||||||
| _mintERC20WithoutNFT(to, units()); | ||||||
| _mintERC721(to, nftId); | ||||||
| } | ||||||
|
|
||||||
| /// @notice Force transfer tokens (manager only) | ||||||
| function forceTransfer(address from, address to, uint256 amount) external onlyManager { | ||||||
| _update(from, to, amount); | ||||||
| /// @notice Force transfer the fixed-denomination NFT and its synced ERC20 lot (manager only) | ||||||
| /// @param from The sender address | ||||||
| /// @param to The recipient address | ||||||
| /// @param nftId The NFT ID to transfer (the mintId) | ||||||
| function forceTransfer(address from, address to, uint256 nftId) external onlyManager { | ||||||
| // Transfer the ERC20 tokens without triggering dynamic NFT logic | ||||||
| _transferERC20(from, to, units()); | ||||||
|
|
||||||
| // Transfer the specific NFT using the proper function | ||||||
| uint256 id = ID_ENCODING_PREFIX + nftId; | ||||||
| _transferERC721(from, to, id); | ||||||
| } | ||||||
|
|
||||||
| // ============================================================= | ||||||
| // DISABLED ERC20 FUNCTIONS | ||||||
| // DISABLED ERC20/721 FUNCTIONS | ||||||
| // ============================================================= | ||||||
|
|
||||||
| /// @notice Regular transfers are disabled - only manager can transfer | ||||||
| function transfer(address, uint256) public pure override returns (bool) { | ||||||
| revert TransfersOnlyViaEthscriptions(); | ||||||
| } | ||||||
|
|
||||||
| /// @notice Regular transferFrom is disabled - only manager can transfer | ||||||
| function transferFrom(address, address, uint256) public pure override returns (bool) { | ||||||
| revert TransfersOnlyViaEthscriptions(); | ||||||
| } | ||||||
|
|
||||||
| /// @notice Approvals are disabled | ||||||
| function approve(address, uint256) public pure override returns (bool) { | ||||||
| revert ApprovalsNotAllowed(); | ||||||
| } | ||||||
|
|
||||||
| /// @notice ERC721 approvals are disabled | ||||||
| function erc721Approve(address, uint256) public pure override { | ||||||
| revert ApprovalsNotAllowed(); | ||||||
| } | ||||||
|
|
||||||
| /// @notice ERC20 approvals are disabled | ||||||
| function erc20Approve(address, uint256) public pure override returns (bool) { | ||||||
| revert ApprovalsNotAllowed(); | ||||||
| } | ||||||
|
|
||||||
| /// @notice SetApprovalForAll is disabled | ||||||
| function setApprovalForAll(address, bool) public pure override { | ||||||
| revert ApprovalsNotAllowed(); | ||||||
| } | ||||||
|
|
||||||
| /// @notice ERC721 transferFrom is disabled | ||||||
| function erc721TransferFrom(address, address, uint256) public pure override { | ||||||
| revert TransfersOnlyViaEthscriptions(); | ||||||
| } | ||||||
|
|
||||||
| /// @notice ERC20 transferFrom is disabled | ||||||
| function erc20TransferFrom(address, address, uint256) public pure override returns (bool) { | ||||||
| revert TransfersOnlyViaEthscriptions(); | ||||||
| } | ||||||
|
|
||||||
| /// @notice Safe transfers are disabled | ||||||
| function safeTransferFrom(address, address, uint256) public pure override { | ||||||
| revert TransfersOnlyViaEthscriptions(); | ||||||
| } | ||||||
|
|
||||||
| /// @notice Safe transfers with data are disabled | ||||||
| function safeTransferFrom(address, address, uint256, bytes memory) public pure override { | ||||||
| revert TransfersOnlyViaEthscriptions(); | ||||||
| } | ||||||
|
|
||||||
| // ============================================================= | ||||||
| // TOKEN URI | ||||||
| // ============================================================= | ||||||
|
|
||||||
| /// @notice Returns metadata URI for NFT tokens | ||||||
| /// @dev Returns a data URI with JSON metadata fetched from the main Ethscriptions contract | ||||||
| function tokenURI(uint256 id_) public view virtual override returns (string memory) { | ||||||
| // This will revert InvalidTokenId / NotFound on bad ids | ||||||
| ownerOf(id_); | ||||||
|
|
||||||
| uint256 mintId = id_ & ~ID_ENCODING_PREFIX; | ||||||
|
||||||
| uint256 mintId = id_ & ~ID_ENCODING_PREFIX; | |
| uint256 mintId = id_ & (ID_ENCODING_PREFIX - 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing validation that the token exists before generating metadata. The function should call
ownerOf(id_)or check token existence to ensure it reverts for non-existent tokens, as per ERC721 standard behavior.