change erc1155

master
lza_menace 2 years ago
parent cddd46385e
commit d947a5c8cd

@ -10,19 +10,19 @@ BOMB holders can randomly mail bombs to other owners
chaos ensues until 1000 survivors - the game stops chaos ensues until 1000 survivors - the game stops
********/ ********/
import {ERC721} from "solmate/tokens/ERC721.sol"; import {ERC1155} from "solmate/tokens/ERC1155.sol";
import {Owned} from "solmate/auth/Owned.sol"; import {Owned} from "solmate/auth/Owned.sol";
import {LibString} from "solmate/utils/LibString.sol"; import {LibString} from "solmate/utils/LibString.sol";
import {UnaboomerCommon} from "./UnaboomerCommon.sol"; import {UnaboomerCommon} from "./UnaboomerCommon.sol";
contract Mailbomb is ERC721, Owned { contract Mailbomb is ERC1155, Owned {
using LibString for uint256; using LibString for uint256;
uint256 public minted; uint256 public bombsAssembled;
string public baseURI; string public baseURI;
UnaboomerCommon public main; UnaboomerCommon public main;
constructor() ERC721("Mailbomb", "BOMB") Owned(msg.sender) {} constructor() ERC1155() Owned(msg.sender) {}
// ========================================================================= // =========================================================================
// Admin // Admin
@ -34,7 +34,7 @@ contract Mailbomb is ERC721, Owned {
payable(msg.sender).transfer(balance); payable(msg.sender).transfer(balance);
} }
/// Set metadata URI for alive BOOMR /// Set metadata URI for all BOMB (token 1)
function setBaseURI(string calldata _baseURI) external onlyOwner { function setBaseURI(string calldata _baseURI) external onlyOwner {
baseURI = _baseURI; baseURI = _baseURI;
} }
@ -45,35 +45,42 @@ contract Mailbomb is ERC721, Owned {
} }
// ========================================================================= // =========================================================================
// Tokens // Modifiers
// ========================================================================= // =========================================================================
/// Mint tokens from main contract modifier onlyMain {
function mint(address _to, uint256 _amount) external payable {
require(msg.sender == address(main), "invalid minter"); require(msg.sender == address(main), "invalid minter");
unchecked { _;
for (uint256 i; i < _amount; i++) {
minted++;
_mint(_to, minted);
}
} }
// =========================================================================
// Tokens
// =========================================================================
/// Mint tokens from main contract
function mint(address _to, uint256 _amount) external payable onlyMain {
bombsAssembled += _amount;
super._mint(_to, 1, _amount, "");
} }
/// Burn spent tokens from main contract /// Burn spent tokens from main contract
function burn(uint256 tokenId) external { function burn(address _from, uint256 _amount) external onlyMain {
require(msg.sender == address(main), "invalid minter"); super._burn(_from, 1, _amount);
super._burn(tokenId);
} }
function totalSupply() public view returns (uint256 supply) { function totalSupply() public view returns (uint256 supply) {
return minted; return bombsAssembled;
}
function uri(uint256 _tokenId) public view override returns (string memory) {
return baseURI;
} }
function tokenURI(uint256 _tokenId) public view override returns (string memory) { function tokenURI(uint256 _tokenId) public view returns (string memory) {
return string(abi.encodePacked(baseURI, _tokenId.toString(), ".json")); return uri(_tokenId);
} }
function supportsInterface(bytes4 interfaceId) public view virtual override (ERC721) returns (bool) { function supportsInterface(bytes4 interfaceId) public view virtual override (ERC1155) returns (bool) {
return super.supportsInterface(interfaceId); return super.supportsInterface(interfaceId);
} }
} }

@ -86,18 +86,17 @@ contract UnaboomerCommon is Owned {
/// If the Unaboomer is already dead, the bomb is considered a dud. /// If the Unaboomer is already dead, the bomb is considered a dud.
/// @dev Pick a pseudo-random tokenID from Unaboomer contract and toggle a mapping value /// @dev Pick a pseudo-random tokenID from Unaboomer contract and toggle a mapping value
/// @dev The likelihood of killing a boomer decreases as time goes on - i.e. more duds /// @dev The likelihood of killing a boomer decreases as time goes on - i.e. more duds
function sendBombs(uint256[] calldata tokenIds) external missionNotCompleted returns (bool[] memory results) { function sendBombs(uint256 _amount) external missionNotCompleted returns (bool[] memory results) {
require(tokenIds.length <= mailbomb.balanceOf(msg.sender), "not enough bombs"); require(_amount <= mailbomb.balanceOf(msg.sender, 1), "not enough bombs");
bool[] memory res = new bool[](tokenIds.length); bool[] memory res = new bool[](_amount);
uint256 boomerSupply = unaboomer.totalSupply(); uint256 boomerSupply = unaboomer.totalSupply();
for (uint256 i; i < tokenIds.length; i++) { for (uint256 i; i < _amount; i++) {
require(mailbomb.ownerOf(tokenIds[i]) == msg.sender, "token not owned"); uint256 randomBoomer = uint256(keccak256(abi.encodePacked(i, block.timestamp, msg.sender))) % boomerSupply;
uint256 randomBoomer = uint256(keccak256(abi.encodePacked(tokenIds[i], block.timestamp, msg.sender))) % boomerSupply;
mailbomb.burn(tokenIds[i]);
bool dud = unaboomer.tokenDead(randomBoomer); bool dud = unaboomer.tokenDead(randomBoomer);
unaboomer.kill(randomBoomer); unaboomer.kill(randomBoomer);
res[i] = dud; res[i] = dud;
} }
mailbomb.burn(msg.sender, _amount);
return res; return res;
} }
} }

@ -21,6 +21,27 @@ contract UnaboomerTest is Test {
main.setMailbombContract(address(bomb)); main.setMailbombContract(address(bomb));
} }
function testBasicMechanics() public {
address t = address(3);
address t2 = address(4);
startHoax(t);
// mint 20 boomers - should have 20 BOOMR and 40 BOMB
main.radicalizeBoomers{value: .2 ether}(20);
assertEq(boomr.totalSupply(), 20);
assertEq(bomb.bombsAssembled(), 40);
assertEq(bomb.balanceOf(t, 1), 40);
// mint 20 more bombs - should have 60 BOMB
main.assembleBombs{value: .2 ether}(20);
assertEq(bomb.bombsAssembled(), 60);
assertEq(bomb.balanceOf(t, 1), 60);
stopHoax();
vm.prank(t2);
main.assembleBombs{value: .2 ether}(20);
assertEq(bomb.bombsAssembled(), 80);
assertEq(bomb.balanceOf(t2, 1), 20);
}
// function testWithdraws() public { // function testWithdraws() public {
// vm.deal(address(main), 10 ether); // vm.deal(address(main), 10 ether);
// vm.prank(address(main.owner())); // vm.prank(address(main.owner()));
@ -58,46 +79,46 @@ contract UnaboomerTest is Test {
// Unaboomer // Unaboomer
// ========================================================================= // =========================================================================
function testWithdrawUnaboomer() public {} // function testWithdrawUnaboomer() public {}
function testUnaboomerSetters() public { // function testUnaboomerSetters() public {
string memory aliveURI = 'ipfs://xxxx/'; // string memory aliveURI = 'ipfs://xxxx/';
string memory deadURI = 'ipfs://yyyy/'; // string memory deadURI = 'ipfs://yyyy/';
boomr.setAliveURI(aliveURI); // boomr.setAliveURI(aliveURI);
boomr.setDeadURI(deadURI); // boomr.setDeadURI(deadURI);
assertEq(boomr.aliveURI(), aliveURI); // assertEq(boomr.aliveURI(), aliveURI);
assertEq(boomr.deadURI(), deadURI); // assertEq(boomr.deadURI(), deadURI);
} // }
function testUnaboomerMainMint() public { // function testUnaboomerMainMint() public {
startHoax(address(3)); // startHoax(address(3));
main.radicalizeBoomers{value: .1 ether}(10); // main.radicalizeBoomers{value: .1 ether}(10);
assertEq(boomr.totalSupply(), 10); // assertEq(boomr.totalSupply(), 10);
assertEq(bomb.totalSupply(), 20); // assertEq(bomb.totalSupply(), 20);
} // }
function testUnaboomerMainKill() public { // function testUnaboomerMainKill() public {
startHoax(address(3)); // startHoax(address(3));
main.radicalizeBoomers{value: .01 ether}(1); // main.radicalizeBoomers{value: .01 ether}(1);
uint256[] memory bombs = new uint256[](2); // uint256[] memory bombs = new uint256[](2);
bombs[0] = 1; // bombs[0] = 1;
bombs[1] = 2; // bombs[1] = 2;
main.sendBombs(bombs); // main.sendBombs(bombs);
vm.expectRevert(bytes("not enough bombs")); // vm.expectRevert(bytes("not enough bombs"));
main.sendBombs(bombs); // main.sendBombs(bombs);
main.radicalizeBoomers{value: .01 ether}(1); // main.radicalizeBoomers{value: .01 ether}(1);
main.sendBombs(bombs); // main.sendBombs(bombs);
} // }
function testUnaboomerSupply() public {} // function testUnaboomerSupply() public {}
function testUnaboomerTokenURIs() public {} // function testUnaboomerTokenURIs() public {}
function testUnaboomerDirectMint() public { // function testUnaboomerDirectMint() public {
startHoax(address(5)); // startHoax(address(5));
vm.expectRevert(bytes("invalid minter")); // vm.expectRevert(bytes("invalid minter"));
boomr.mint(address(5), 2); // boomr.mint(address(5), 2);
} // }
function testUnaboomerDirectKill() public { // function testUnaboomerDirectKill() public {
startHoax(address(5)); // startHoax(address(5));
main.radicalizeBoomers{value: .05 ether}(5); // main.radicalizeBoomers{value: .05 ether}(5);
vm.expectRevert(bytes("invalid minter")); // vm.expectRevert(bytes("invalid minter"));
boomr.kill(1); // boomr.kill(1);
} // }
} }

Loading…
Cancel
Save