Skip to content
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

Create a test version for erc-4973 . #42

Open
WeuFoundDev opened this issue Aug 11, 2023 · 3 comments
Open

Create a test version for erc-4973 . #42

WeuFoundDev opened this issue Aug 11, 2023 · 3 comments
Assignees
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers

Comments

@WeuFoundDev
Copy link
Owner

You can also check out EIP-49731 . [EIP-4973 is an interface for non-transferrable NFTs binding to an Ethereum account like a legendary World of Warcraft item binds to a character] (https://eips.ethereum.org/EIPS/eip-4973). [It is still in the draft phase and the interface is still unstable @Adityapandey59

@WeuFoundDev WeuFoundDev added documentation Improvements or additions to documentation good first issue Good for newcomers labels Aug 11, 2023
@WeuFoundDev
Copy link
Owner Author

update the contracts docs and functionality @Adityapandey59 . And create a test version for badges upgradation . Like from a variable contributor to a core contributor

@Adityapandey59
Copy link
Collaborator

// SPDX-License-Identifier: MIT
pragma solidity 0.8.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/ERC721.sol";
import "https://github.com/OpenZeppelin/openzeppelin-co@openzeppelin/contracts/token/ERC721/ERC721.sntracts/blob/master/contracts/utils/introspection/ERC165.sol";

interface IERC4973Metadata {
function tokenURI(uint256 tokenId) external view returns (string memory);
}

contract MyNFTContract is ERC721, ERC165 {
IERC4973Metadata public metadataExtension;
mapping(address => uint256) public userBadges;
mapping(address => uint256) public leveragePower;
mapping(address => bool) public isBlacklisted;
mapping(address => bool) public isIssuer;

constructor(address nftTokenAddress, address metadataExtensionAddress) ERC721("MyNFTContract", "NFTC") {
    _registerInterface(type(IERC165).interfaceId);

    metadataExtension = IERC4973Metadata(metadataExtensionAddress);
    nftToken = ERC721(nftTokenAddress);
}
function getTokenURI(uint256 tokenId) public view returns (string memory) {
    return metadataExtension.tokenURI(tokenId);
}
function gainBadges(uint256 amount) public {
    userBadges[msg.sender] += amount;
}
function setLeveragePower(address user, uint256 power) public {
    require(isIssuer[msg.sender], "Only issuers can set leverage power");
    leveragePower[user] = power;
}
function revokeBadges(address user) public {
    require(isIssuer[msg.sender], "Only issuers can revoke badges");
    userBadges[user] = 0;
}
function blacklistUser(address user) public {
    require(isIssuer[msg.sender], "Only issuers can blacklist users");
    isBlacklisted[user] = true;
}
function mintAccountBoundToken(address user, uint256 tokenId) public {
    require(isIssuer[msg.sender], "Only issuers can mint tokens");
    nftToken.mint(user, tokenId);   
}
function multiplyRewards(uint256 rewards) public view returns (uint256) {
    uint256 badgesFactor = userBadges[msg.sender] + 1;
    uint256 leverageFactor = leveragePower[msg.sender] + 1;

    return rewards * badgesFactor * leverageFactor;
}  
function supportsInterface(bytes4 interfaceId) public view override returns (bool) {
    return interfaceId == type(IERC165).interfaceId || super.supportsInterface(interfaceId);
}

}

@Adityapandey59
Copy link
Collaborator

This smart contract is an implementation of a non-fungible token (NFT) contract in Solidity. It's designed to manage a collection of NFTs with additional features such as badge systems, leverage power settings, and issuer controls. Here's a breakdown of its main components:

  1. Pragma Directive: Specifies the Solidity version to be used (0.8.0) and the SPDX license identifier.

  2. Imports: The contract imports two ERC721-related contracts from the OpenZeppelin library. ERC721 is the base contract for creating NFTs, while ERC165 is used for interface support checks.

  3. Interface: IERC4973Metadata defines a function signature tokenURI(uint256 tokenId) which is used to fetch the metadata URI for a given token.

  4. Contract Definition: The main contract, MyNFTContract, inherits from both ERC721 and ERC165.

  5. State Variables:

    • metadataExtension: Stores the address of an external contract that implements the IERC4973Metadata interface.
    • userBadges: Maps user addresses to the number of badges they possess.
    • leveragePower: Maps user addresses to their leverage power setting.
    • isBlacklisted: Maps user addresses to whether they are blacklisted.
    • isIssuer: Maps user addresses to whether they are authorized issuers.
  6. Constructor: Initializes the contract with the name "MyNFTContract" and the symbol "NFTC". It registers support for the IERC165 interface and initializes the metadataExtension and nftToken addresses.

  7. Public Functions:

    • getTokenURI(uint256 tokenId): Fetches the metadata URI for a given token using the metadataExtension.
    • gainBadges(uint256 amount): Allows users to increase their badge count.
    • setLeveragePower(address user, uint256 power): Only authorized issuers can set the leverage power for a user.
    • revokeBadges(address user): Only authorized issuers can reset a user's badge count.
    • blacklistUser(address user): Only authorized issuers can blacklist a user.
    • mintAccountBoundToken(address user, uint256 tokenId): Only authorized issuers can mint NFTs and assign them to a user.
    • multiplyRewards(uint256 rewards): Calculates rewards based on user's badge count and leverage power.
  8. supportsInterface(bytes4 interfaceId): Overrides the function to indicate support for the IERC165 interface and additional interfaces from the parent contract.

Overall, this contract provides a way to manage and interact with a collection of NFTs, with specific functionalities for badges, leverage power, and issuer controls. The contract defines access restrictions using the require statement, ensuring that only authorized issuers can perform certain actions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants