Skip to content

Instantly share code, notes, and snippets.

@z0r0z
Created February 24, 2022 19:08
Show Gist options
  • Save z0r0z/70d19c52958ddac94938f32a7b180a3a to your computer and use it in GitHub Desktop.
Save z0r0z/70d19c52958ddac94938f32a7b180a3a 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
// 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