Created
February 10, 2022 04:06
-
-
Save z0r0z/2b9f1e4fc3b0a00ad20b878c6c7ac76e to your computer and use it in GitHub Desktop.
The selected bid NFT controls how long voting units can be minted. When party NFT transfers, voting units follow.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.2; | |
import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | |
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol"; | |
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol"; | |
import "@openzeppelin/contracts/token/ERC721/extensions/draft-ERC721Votes.sol"; | |
import "@openzeppelin/contracts/security/Pausable.sol"; | |
contract PartyNFT is ERC721, ERC721Burnable, ERC721Enumerable, ERC721Votes, Pausable { | |
ERC721 immutable bidChoice; | |
mapping(address => uint256) public favors; | |
constructor( | |
string memory name, | |
string memory symbol, | |
ERC721 bidChoice_ | |
) | |
ERC721(name, symbol) | |
EIP712(name, "1") | |
{ | |
bidChoice = bidChoice_; | |
_pause(); | |
} | |
function startParty() public virtual { | |
if (bidChoice.balanceOf(address(this)) != 0) | |
_unpause(); | |
} | |
function contribute() public payable virtual { | |
if (bidChoice.balanceOf(address(this)) == 0) { | |
unchecked { | |
if (balanceOf(msg.sender) == 0) { | |
_safeMint(msg.sender, totalSupply() + 1); | |
} | |
favors[msg.sender] += msg.value; | |
} | |
} | |
} | |
// OpenZeppelin Overrides | |
function _beforeTokenTransfer( | |
address from, | |
address to, | |
uint256 tokenId | |
) | |
internal | |
virtual | |
override(ERC721, ERC721Enumerable) | |
{ | |
super._beforeTokenTransfer(from, to, tokenId); | |
} | |
function _afterTokenTransfer( | |
address from, | |
address to, | |
uint256 tokenId | |
) internal virtual override(ERC721, ERC721Votes) { | |
uint256 fvrs = favors[from]; | |
favors[to] += fvrs; | |
_transferVotingUnits(from, to, fvrs); | |
super._afterTokenTransfer(from, to, tokenId); | |
delete favors[from]; | |
} | |
function _getVotingUnits(address account) internal virtual override(ERC721Votes) returns (uint256) { | |
return favors[account]; | |
} | |
// The following functions are overrides required by Solidity. | |
function supportsInterface(bytes4 interfaceId) | |
public | |
view | |
override(ERC721, ERC721Enumerable) | |
returns (bool) | |
{ | |
return super.supportsInterface(interfaceId); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment