reworking

master
lza_menace 2 years ago
parent 16041a2972
commit 4622f2788f

@ -11,6 +11,7 @@ chaos ensues until 1000 survivors - the game stops
********/ ********/
import {ERC721} from "solmate/tokens/ERC721.sol"; import {ERC721} from "solmate/tokens/ERC721.sol";
import {Owned} from "solmate/auth/Owned.sol";
import {LibString} from "solmate/utils/LibString.sol"; import {LibString} from "solmate/utils/LibString.sol";
error NotOwnerOfToken(); error NotOwnerOfToken();
@ -24,67 +25,44 @@ error NotAdmin();
error NoRemoveSelf(); error NoRemoveSelf();
error NoRemoveDeployer(); error NoRemoveDeployer();
contract Unaboomer is ERC721 { contract Unaboomer is ERC721, Owned {
using LibString for uint256; using LibString for uint256;
mapping(uint256 => bool) public tokenDead; mapping(uint256 => bool) public tokenDead;
mapping(address => bool) public adminWallets;
uint256 public constant MAX_SUPPLY = 10000; uint256 public constant MAX_SUPPLY = 10000;
uint256 public minted; uint256 public minted;
string public livingURI; string public aliveURI;
string public deadURI; string public deadURI;
address public deployer; address public MailBombContract;
address[] public payoutWallets;
constructor() ERC721("Unaboomer", "BOOMR") { constructor() ERC721("Unaboomer", "BOOMR") Owned(msg.sender) {}
deployer = msg.sender;
adminWallets[msg.sender] = true;
}
// ========================================================================= // =========================================================================
// Admin // Admin
// ========================================================================= // =========================================================================
modifier onlyAdmin { /// Withdraw funds to contract owner
if (adminWallets[msg.sender] == false) revert NotAdmin(); function withdraw() external onlyOwner {
_;
}
///@dev Specify team wallets for payouts and contract administration
function updateAdmins(address[] calldata _admins) external onlyAdmin {
payoutWallets = _admins;
for (uint256 i; i < _admins.length; i++) {
adminWallets[_admins[i]] = true;
}
}
///@dev Remove admins if needed
function removeAdmin(address _admin) external onlyAdmin {
if (msg.sender == _admin) revert NoRemoveSelf();
if (_admin == deployer) revert NoRemoveDeployer();
adminWallets[_admin] = false;
}
///@dev Split payments to team
function withdraw() external onlyAdmin {
if (payoutWallets.length == 0) revert NoAdmins();
uint256 balance = address(this).balance; uint256 balance = address(this).balance;
for (uint256 i; i < payoutWallets.length; i++) { payable(msg.sender).transfer(balance);
// payable(payoutWallets[i]).transfer(balance / payoutWallets.length);
(bool success, ) = payable(payoutWallets[i]).call{value: balance / payoutWallets.length}("");
require(success, "failed to withdraw");
}
} }
function setLivingURI(string calldata _baseURI) external onlyAdmin { /// Set metadata URI for alive BOOMR
livingURI = _baseURI; function setAliveURI(string calldata _baseURI) external onlyOwner {
aliveURI = _baseURI;
} }
function setDeadURI(string calldata _baseURI) external onlyAdmin { /// Set metadata URI for dead BOOMR
function setDeadURI(string calldata _baseURI) external onlyOwner {
deadURI = _baseURI; deadURI = _baseURI;
} }
/// Set contract address for Mailbomb tokens
function setMailBombContract(address _address) external onlyOwner {
MailBombContract = _address;
}
// ========================================================================= // =========================================================================
// Tokens // Tokens
// ========================================================================= // =========================================================================
@ -99,6 +77,7 @@ contract Unaboomer is ERC721 {
minted++; minted++;
} }
} }
// also mint 2 BOMB to user
} }
function totalSupply() view public returns (uint256 supply) { function totalSupply() view public returns (uint256 supply) {
@ -106,10 +85,10 @@ contract Unaboomer is ERC721 {
} }
function tokenURI(uint256 _tokenId) public view override returns (string memory) { function tokenURI(uint256 _tokenId) public view override returns (string memory) {
if (tokenDead[_tokenId] == false) { if (tokenDead[_tokenId]) {
return string(abi.encodePacked(livingURI, _tokenId.toString(), ".json"));
} else {
return string(abi.encodePacked(deadURI, _tokenId.toString(), ".json")); return string(abi.encodePacked(deadURI, _tokenId.toString(), ".json"));
} else {
return string(abi.encodePacked(aliveURI, _tokenId.toString(), ".json"));
} }
} }

@ -6,42 +6,20 @@ import "../src/Unaboomer.sol";
contract UnaboomerTest is Test { contract UnaboomerTest is Test {
Unaboomer public boomr; Unaboomer public boomr;
address alice = address(1);
address bob = address(2);
address[] admins = new address[](2);
function setUp() public { function setUp() public {
boomr = new Unaboomer(); boomr = new Unaboomer();
admins[0] = address(1);
admins[1] = address(2);
boomr.updateAdmins(admins);
}
function testUpdatingAdmins() public {
// confirm admin on 1 and 2
assertEq(boomr.adminWallets(boomr.deployer()), true);
assertEq(boomr.adminWallets(address(1)), true);
assertEq(boomr.adminWallets(address(2)), true);
assertEq(boomr.adminWallets(address(3)), false);
hoax(address(1));
boomr.removeAdmin(address(2));
assertEq(boomr.adminWallets(address(2)), false);
hoax(address(2));
vm.expectRevert();
boomr.withdraw();
} }
function testWithdraws() public { function testWithdraws() public {
// confirm payouts divvy equally vm.deal(address(boomr), 11 ether);
vm.deal(address(boomr), 11.5 ether); vm.prank(address(boomr.owner()));
vm.prank(address(1));
boomr.withdraw(); boomr.withdraw();
assertEq(address(1).balance, 5.75 ether); assertEq(boomr.owner().balance > 10 ether, true);
assertEq(address(2).balance, 5.75 ether);
} }
function testMint() public { function testMint() public {
vm.startPrank(alice); vm.startPrank(address(1));
boomr.mint(5); boomr.mint(5);
assertEq(boomr.totalSupply(), 5); assertEq(boomr.totalSupply(), 5);
assertEq(boomr.tokenDead(1), false); assertEq(boomr.tokenDead(1), false);

Loading…
Cancel
Save