-
-
Save meefs/e2dbb19f5815d25a2eb8b74372aeabb5 to your computer and use it in GitHub Desktop.
an NFT that sits in your wallet until you contribute 0.01 ETH to public goods
This file contains 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: AGPL-3.0-only | |
pragma solidity >=0.8.4; | |
import 'https://github.com/Rari-Capital/solmate/blob/main/src/tokens/ERC721.sol'; | |
error NotGood(); | |
error NotEnough(); | |
error ETHtransferFailed(); | |
error NotSummoner(); | |
contract MolochBound is ERC721("Moloch Bound", "BOUND") { | |
string public baseURI; | |
address public publicGood; | |
address public summoner; | |
uint256 public tithe; | |
mapping(address => bool) public good; | |
modifier onlyGood(address from) { | |
if (!good[from]) revert NotGood(); | |
_; | |
} | |
modifier onlySummoner { | |
if (msg.sender != summoner) revert NotSummoner(); | |
_; | |
} | |
constructor(string memory baseURI_, address publicGood_) { | |
baseURI = baseURI_; | |
publicGood = publicGood_; | |
summoner = msg.sender; | |
tithe = 0.01 ether; | |
} | |
function tokenURI(uint256) public view override returns (string memory) { | |
return baseURI; | |
} | |
/// ----------------------------------------------------------------------- | |
/// Sweet Release | |
/// ----------------------------------------------------------------------- | |
function transferFrom( | |
address from, | |
address to, | |
uint256 id | |
) public override onlyGood(from) { | |
transferFrom(from, to, id); | |
} | |
function safeTransferFrom( | |
address from, | |
address to, | |
uint256 id | |
) public override onlyGood(from) { | |
safeTransferFrom(from, to, id); | |
} | |
function safeTransferFrom( | |
address from, | |
address to, | |
uint256 id, | |
bytes memory data | |
) public override onlyGood(from) { | |
safeTransferFrom(from, to, id, data); | |
} | |
/// ----------------------------------------------------------------------- | |
/// Goodness | |
/// ----------------------------------------------------------------------- | |
function doGood() public payable { | |
if (msg.value != tithe) revert NotEnough(); | |
_safeTransferETH(publicGood, msg.value); | |
good[msg.sender] = true; | |
} | |
function _safeTransferETH(address to, uint256 amount) internal { | |
bool callStatus; | |
assembly { | |
// transfer the ETH and store if it succeeded or not | |
callStatus := call(gas(), to, amount, 0, 0, 0, 0) | |
} | |
if (!callStatus) revert ETHtransferFailed(); | |
} | |
/// ----------------------------------------------------------------------- | |
/// Governance | |
/// ----------------------------------------------------------------------- | |
function mint(address to, uint256 id) public onlySummoner { | |
_safeMint(to, id); | |
} | |
function newPublicGood(address publicGood_) public onlySummoner { | |
publicGood = publicGood_; | |
} | |
function newTithe(uint256 tithe_) public onlySummoner { | |
tithe = tithe_; | |
} | |
function newSummoner(address summoner_) public onlySummoner { | |
summoner = summoner_; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment