├── .gitattributes ├── cryptocats ├── README.md └── PreviousCryptoCatsContract.sol ├── mooncats-wrapped ├── README.md ├── MoonCatsRescue.sol ├── IERC721Metadata.sol ├── IERC165.sol ├── IERC721Receiver.sol ├── Context.sol ├── IERC721Enumerable.sol ├── lib │ ├── Strings.sol │ ├── Counters.sol │ └── SafeMath.sol ├── ERC165.sol ├── MoonCatsWrapped.sol └── IERC721.sol ├── doomcats ├── ProxyRegistry.sol ├── IDoomCat.sol ├── IUniswapV2Router02Minimal.sol ├── IERC721Metadata.sol ├── IERC165.sol ├── ERC721OnOpenSea.sol ├── IERC721Receiver.sol ├── ERC165.sol ├── Context.sol ├── IERC721Enumerable.sol ├── NOTES.md ├── lib │ └── Strings.sol ├── IERC20.sol ├── DoomCat.sol ├── IERC721.sol ├── DoomCatRescue.sol └── ERC721Enumerable.sol ├── mooncats-hd ├── ForeignNFT.sol ├── ForeignToken.sol ├── IERC721Metadata.sol ├── IERC165.sol ├── IERC721Receiver.sol ├── Context.sol ├── ERC165.sol ├── IERC721Enumerable.sol ├── WrapperContract.sol ├── lib │ └── Strings.sol ├── Ownable.sol ├── MooncatsContract.sol ├── HDMooncats.sol └── IERC721.sol ├── mooncats-acclimated ├── NOTES.md ├── ERC721Holder.sol ├── IERC721Metadata.sol ├── IERC165.sol ├── IERC721Receiver.sol ├── Context.sol ├── IERC721Enumerable.sol ├── lib │ └── Strings.sol ├── IMoonCatRescue.sol ├── IMoonCatsWrapped.sol ├── ERC165.sol ├── Ownable.sol ├── Pausable.sol ├── IERC721.sol └── MoonCatOrderLookup.sol ├── cryptokitties-wrapped ├── KittyCore.sol ├── IERC20.sol ├── ReentrancyGuard.sol └── lib │ └── SafeMath.sol ├── NOTES.md ├── cryptokitties ├── GeneScienceInterface.sol ├── Ownable.sol ├── ERC721Metadata.sol ├── Pausable.sol ├── ERC721.sol ├── KittyMinting.sol ├── SiringClockAuction.sol ├── SaleClockAuction.sol ├── KittyAccessControl.sol ├── CHEATSHEET.md ├── KittyAuction.sol ├── ClockAuction.sol └── KittyCore.sol ├── lasercats ├── IERC721Metadata.sol ├── IERC165.sol ├── IERC721Receiver.sol ├── Context.sol ├── ERC165.sol ├── IERC721Enumerable.sol ├── NOTES.md ├── lib │ ├── Strings.sol │ └── SafeMath.sol ├── Ownable.sol ├── LaserCats.sol ├── IERC721.sol └── ERC721Enumerable.sol ├── mooncats-helper └── MooncatHelper.sol ├── mooncats-vote ├── PonderwareTransferOfAuthority.sol └── MoonCatKeyVote.sol └── mooncats └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | *.sol linguist-language=Solidity 2 | -------------------------------------------------------------------------------- /cryptocats/README.md: -------------------------------------------------------------------------------- 1 | # Inside the CryptoCats Blockchain Contract / Service 2 | -------------------------------------------------------------------------------- /mooncats-wrapped/README.md: -------------------------------------------------------------------------------- 1 | # Inside the Wrapped MoonCatsRescue (WMCR) Blockchain Contract / Service 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /doomcats/ProxyRegistry.sol: -------------------------------------------------------------------------------- 1 | 2 | interface ProxyRegistry { 3 | function proxies(address) external view returns (address); 4 | } 5 | -------------------------------------------------------------------------------- /mooncats-hd/ForeignNFT.sol: -------------------------------------------------------------------------------- 1 | 2 | 3 | interface ForeignNFT { 4 | 5 | function transferFrom(address from, address to, uint _tokenId) external payable; 6 | 7 | } 8 | 9 | -------------------------------------------------------------------------------- /mooncats-hd/ForeignToken.sol: -------------------------------------------------------------------------------- 1 | 2 | interface ForeignToken { 3 | 4 | function balanceOf(address) external view returns (uint); 5 | 6 | function transfer(address, uint) external returns (bool); 7 | } 8 | 9 | -------------------------------------------------------------------------------- /mooncats-acclimated/NOTES.md: -------------------------------------------------------------------------------- 1 | # Notes 2 | 3 | MoonCatAcclimator 4 | @ etherscan 5 | 6 | - Arg [0] : baseURI (string): https://api.mooncat.community/traits/ 7 | 8 | -------------------------------------------------------------------------------- /doomcats/IDoomCat.sol: -------------------------------------------------------------------------------- 1 | // File contracts/interfaces/IDoomCat.sol 2 | 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | interface IDoomCat { 7 | function mint(address, uint256) external; 8 | function swapAndBurn(uint256) external; 9 | } 10 | -------------------------------------------------------------------------------- /cryptokitties-wrapped/KittyCore.sol: -------------------------------------------------------------------------------- 1 | /// @title Interface for interacting with the CryptoKitties Core contract created by Dapper Labs Inc. 2 | contract KittyCore { 3 | function ownerOf(uint256 _tokenId) public view returns (address owner); 4 | function transferFrom(address _from, address _to, uint256 _tokenId) external; 5 | function transfer(address _to, uint256 _tokenId) external; 6 | mapping (uint256 => address) public kittyIndexToApproved; 7 | } 8 | -------------------------------------------------------------------------------- /doomcats/IUniswapV2Router02Minimal.sol: -------------------------------------------------------------------------------- 1 | // File contracts/interfaces/IUniswapV2Router02Minimal.sol 2 | 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | interface IUniswapV2Router02Minimal { 7 | function WETH() external pure returns (address); 8 | function swapExactETHForTokensSupportingFeeOnTransferTokens( 9 | uint256 amountOutMin, 10 | address[] calldata path, 11 | address to, 12 | uint256 deadline 13 | ) external payable; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /mooncats-wrapped/MoonCatsRescue.sol: -------------------------------------------------------------------------------- 1 | interface MoonCatsRescue { 2 | struct AdoptionOffer { 3 | bool exists; 4 | bytes5 catId; 5 | address seller; 6 | uint price; 7 | address onlyOfferTo; 8 | } 9 | 10 | function acceptAdoptionOffer(bytes5 catId) external payable; 11 | function giveCat(bytes5 catId, address to) external; 12 | function adoptionOffers(bytes5 catId) external returns (AdoptionOffer memory); 13 | } 14 | 15 | 16 | -------------------------------------------------------------------------------- /NOTES.md: -------------------------------------------------------------------------------- 1 | # Notes 2 | 3 | 4 | ## More Contracts 5 | 6 | ### MarsCatsWrapped @ Binance 7 | 8 | see 9 | 10 | ### MoonCatRescue @ Binance 11 | 12 | see 13 | 14 | ### WrappedCryptoCat (WCCAT) 15 | 16 | see 17 | 18 | 19 | 20 | --- 21 | 22 | More Notes 23 | 24 | https://twitter.com/CryptoCatsFD - CryptoCats "First Deployed" 25 | 26 | https://cryptocatslistings.com 27 | 28 | 29 | -------------------------------------------------------------------------------- /cryptokitties/GeneScienceInterface.sol: -------------------------------------------------------------------------------- 1 | 2 | /// @title SEKRETOOOO 3 | contract GeneScienceInterface { 4 | /// @dev simply a boolean to indicate this is the contract we expect to be 5 | function isGeneScience() public pure returns (bool); 6 | 7 | /// @dev given genes of kitten 1 & 2, return a genetic combination - may have a random factor 8 | /// @param genes1 genes of mom 9 | /// @param genes2 genes of sire 10 | /// @return the genes that are supposed to be passed down the child 11 | function mixGenes(uint256 genes1, uint256 genes2, uint256 targetBlock) public returns (uint256); 12 | } 13 | 14 | -------------------------------------------------------------------------------- /lasercats/IERC721Metadata.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "./IERC721.sol"; 6 | 7 | /** 8 | * @title ERC-721 Non-Fungible Token Standard, optional metadata extension 9 | * @dev See https://eips.ethereum.org/EIPS/eip-721 10 | */ 11 | interface IERC721Metadata is IERC721 { 12 | 13 | /** 14 | * @dev Returns the token collection name. 15 | */ 16 | function name() external view returns (string memory); 17 | 18 | /** 19 | * @dev Returns the token collection symbol. 20 | */ 21 | function symbol() external view returns (string memory); 22 | 23 | /** 24 | * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. 25 | */ 26 | function tokenURI(uint256 tokenId) external view returns (string memory); 27 | } -------------------------------------------------------------------------------- /mooncats-acclimated/ERC721Holder.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.6.0 <0.8.0; 4 | 5 | import "./IERC721Receiver.sol"; 6 | 7 | /** 8 | * @dev Implementation of the {IERC721Receiver} interface. 9 | * 10 | * Accepts all token transfers. 11 | * Make sure the contract is able to use its token with {IERC721-safeTransferFrom}, {IERC721-approve} or {IERC721-setApprovalForAll}. 12 | */ 13 | contract ERC721Holder is IERC721Receiver { 14 | 15 | /** 16 | * @dev See {IERC721Receiver-onERC721Received}. 17 | * 18 | * Always returns `IERC721Receiver.onERC721Received.selector`. 19 | */ 20 | function onERC721Received(address, address, uint256, bytes memory) public virtual override returns (bytes4) { 21 | return this.onERC721Received.selector; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /mooncats-acclimated/IERC721Metadata.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.6.2 <0.8.0; 4 | 5 | import "./IERC721.sol"; 6 | 7 | /** 8 | * @title ERC-721 Non-Fungible Token Standard, optional metadata extension 9 | * @dev See https://eips.ethereum.org/EIPS/eip-721 10 | */ 11 | interface IERC721Metadata is IERC721 { 12 | 13 | /** 14 | * @dev Returns the token collection name. 15 | */ 16 | function name() external view returns (string memory); 17 | 18 | /** 19 | * @dev Returns the token collection symbol. 20 | */ 21 | function symbol() external view returns (string memory); 22 | 23 | /** 24 | * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. 25 | */ 26 | function tokenURI(uint256 tokenId) external view returns (string memory); 27 | } -------------------------------------------------------------------------------- /cryptokitties-wrapped/IERC20.sol: -------------------------------------------------------------------------------- 1 | /** 2 | * @title ERC20 interface 3 | * @dev see https://github.com/ethereum/EIPs/issues/20 4 | */ 5 | interface IERC20 { 6 | function transfer(address to, uint256 value) external returns (bool); 7 | 8 | function approve(address spender, uint256 value) external returns (bool); 9 | 10 | function transferFrom(address from, address to, uint256 value) external returns (bool); 11 | 12 | function totalSupply() external view returns (uint256); 13 | 14 | function balanceOf(address who) external view returns (uint256); 15 | 16 | function allowance(address owner, address spender) external view returns (uint256); 17 | 18 | event Transfer(address indexed from, address indexed to, uint256 value); 19 | 20 | event Approval(address indexed owner, address indexed spender, uint256 value); 21 | } 22 | 23 | -------------------------------------------------------------------------------- /doomcats/IERC721Metadata.sol: -------------------------------------------------------------------------------- 1 | // File @openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol@v4.0.0 2 | 3 | 4 | 5 | pragma solidity ^0.8.0; 6 | 7 | /** 8 | * @title ERC-721 Non-Fungible Token Standard, optional metadata extension 9 | * @dev See https://eips.ethereum.org/EIPS/eip-721 10 | */ 11 | interface IERC721Metadata is IERC721 { 12 | 13 | /** 14 | * @dev Returns the token collection name. 15 | */ 16 | function name() external view returns (string memory); 17 | 18 | /** 19 | * @dev Returns the token collection symbol. 20 | */ 21 | function symbol() external view returns (string memory); 22 | 23 | /** 24 | * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. 25 | */ 26 | function tokenURI(uint256 tokenId) external view returns (string memory); 27 | } 28 | 29 | -------------------------------------------------------------------------------- /mooncats-hd/IERC721Metadata.sol: -------------------------------------------------------------------------------- 1 | 2 | // File: @openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol 3 | 4 | 5 | 6 | pragma solidity ^0.8.0; 7 | 8 | 9 | /** 10 | * @title ERC-721 Non-Fungible Token Standard, optional metadata extension 11 | * @dev See https://eips.ethereum.org/EIPS/eip-721 12 | */ 13 | interface IERC721Metadata is IERC721 { 14 | 15 | /** 16 | * @dev Returns the token collection name. 17 | */ 18 | function name() external view returns (string memory); 19 | 20 | /** 21 | * @dev Returns the token collection symbol. 22 | */ 23 | function symbol() external view returns (string memory); 24 | 25 | /** 26 | * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. 27 | */ 28 | function tokenURI(uint256 tokenId) external view returns (string memory); 29 | } 30 | -------------------------------------------------------------------------------- /lasercats/IERC165.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | /** 6 | * @dev Interface of the ERC165 standard, as defined in the 7 | * https://eips.ethereum.org/EIPS/eip-165[EIP]. 8 | * 9 | * Implementers can declare support of contract interfaces, which can then be 10 | * queried by others ({ERC165Checker}). 11 | * 12 | * For an implementation, see {ERC165}. 13 | */ 14 | interface IERC165 { 15 | /** 16 | * @dev Returns true if this contract implements the interface defined by 17 | * `interfaceId`. See the corresponding 18 | * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] 19 | * to learn more about how these ids are created. 20 | * 21 | * This function call must use less than 30 000 gas. 22 | */ 23 | function supportsInterface(bytes4 interfaceId) external view returns (bool); 24 | } -------------------------------------------------------------------------------- /mooncats-acclimated/IERC165.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.6.0 <0.8.0; 4 | 5 | /** 6 | * @dev Interface of the ERC165 standard, as defined in the 7 | * https://eips.ethereum.org/EIPS/eip-165[EIP]. 8 | * 9 | * Implementers can declare support of contract interfaces, which can then be 10 | * queried by others ({ERC165Checker}). 11 | * 12 | * For an implementation, see {ERC165}. 13 | */ 14 | interface IERC165 { 15 | /** 16 | * @dev Returns true if this contract implements the interface defined by 17 | * `interfaceId`. See the corresponding 18 | * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] 19 | * to learn more about how these ids are created. 20 | * 21 | * This function call must use less than 30 000 gas. 22 | */ 23 | function supportsInterface(bytes4 interfaceId) external view returns (bool); 24 | } 25 | -------------------------------------------------------------------------------- /mooncats-wrapped/IERC721Metadata.sol: -------------------------------------------------------------------------------- 1 | // File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/IERC721Metadata.sol 2 | 3 | 4 | 5 | pragma solidity >=0.6.2 <0.8.0; 6 | 7 | 8 | /** 9 | * @title ERC-721 Non-Fungible Token Standard, optional metadata extension 10 | * @dev See https://eips.ethereum.org/EIPS/eip-721 11 | */ 12 | interface IERC721Metadata is IERC721 { 13 | 14 | /** 15 | * @dev Returns the token collection name. 16 | */ 17 | function name() external view returns (string memory); 18 | 19 | /** 20 | * @dev Returns the token collection symbol. 21 | */ 22 | function symbol() external view returns (string memory); 23 | 24 | /** 25 | * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. 26 | */ 27 | function tokenURI(uint256 tokenId) external view returns (string memory); 28 | } 29 | 30 | 31 | -------------------------------------------------------------------------------- /mooncats-hd/IERC165.sol: -------------------------------------------------------------------------------- 1 | // File: @openzeppelin/contracts/utils/introspection/IERC165.sol 2 | 3 | 4 | 5 | pragma solidity ^0.8.0; 6 | 7 | /** 8 | * @dev Interface of the ERC165 standard, as defined in the 9 | * https://eips.ethereum.org/EIPS/eip-165[EIP]. 10 | * 11 | * Implementers can declare support of contract interfaces, which can then be 12 | * queried by others ({ERC165Checker}). 13 | * 14 | * For an implementation, see {ERC165}. 15 | */ 16 | interface IERC165 { 17 | /** 18 | * @dev Returns true if this contract implements the interface defined by 19 | * `interfaceId`. See the corresponding 20 | * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] 21 | * to learn more about how these ids are created. 22 | * 23 | * This function call must use less than 30 000 gas. 24 | */ 25 | function supportsInterface(bytes4 interfaceId) external view returns (bool); 26 | } 27 | 28 | -------------------------------------------------------------------------------- /doomcats/IERC165.sol: -------------------------------------------------------------------------------- 1 | // File @openzeppelin/contracts/utils/introspection/IERC165.sol@v4.0.0 2 | 3 | 4 | 5 | pragma solidity ^0.8.0; 6 | 7 | /** 8 | * @dev Interface of the ERC165 standard, as defined in the 9 | * https://eips.ethereum.org/EIPS/eip-165[EIP]. 10 | * 11 | * Implementers can declare support of contract interfaces, which can then be 12 | * queried by others ({ERC165Checker}). 13 | * 14 | * For an implementation, see {ERC165}. 15 | */ 16 | interface IERC165 { 17 | /** 18 | * @dev Returns true if this contract implements the interface defined by 19 | * `interfaceId`. See the corresponding 20 | * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] 21 | * to learn more about how these ids are created. 22 | * 23 | * This function call must use less than 30 000 gas. 24 | */ 25 | function supportsInterface(bytes4 interfaceId) external view returns (bool); 26 | } 27 | 28 | -------------------------------------------------------------------------------- /lasercats/IERC721Receiver.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | /** 6 | * @title ERC721 token receiver interface 7 | * @dev Interface for any contract that wants to support safeTransfers 8 | * from ERC721 asset contracts. 9 | */ 10 | interface IERC721Receiver { 11 | /** 12 | * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} 13 | * by `operator` from `from`, this function is called. 14 | * 15 | * It must return its Solidity selector to confirm the token transfer. 16 | * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. 17 | * 18 | * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`. 19 | */ 20 | function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4); 21 | } -------------------------------------------------------------------------------- /mooncats-acclimated/IERC721Receiver.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.6.0 <0.8.0; 4 | 5 | /** 6 | * @title ERC721 token receiver interface 7 | * @dev Interface for any contract that wants to support safeTransfers 8 | * from ERC721 asset contracts. 9 | */ 10 | interface IERC721Receiver { 11 | /** 12 | * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} 13 | * by `operator` from `from`, this function is called. 14 | * 15 | * It must return its Solidity selector to confirm the token transfer. 16 | * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. 17 | * 18 | * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`. 19 | */ 20 | function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4); 21 | } -------------------------------------------------------------------------------- /doomcats/ERC721OnOpenSea.sol: -------------------------------------------------------------------------------- 1 | // File contracts/ERC721OnOpenSea.sol 2 | 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | 7 | /** 8 | * @dev helper contract to allow gasless OpenSea listings 9 | */ 10 | contract ERC721OnOpenSea is ERC721Enumerable { 11 | address public proxyRegistryAddress; 12 | 13 | constructor( 14 | string memory name, 15 | string memory symbol, 16 | address registryProxyAddress_ 17 | ) ERC721(name, symbol) { 18 | proxyRegistryAddress = registryProxyAddress_; 19 | } 20 | 21 | function isApprovedForAll(address owner, address operator) 22 | public 23 | view 24 | override 25 | returns (bool) 26 | { 27 | ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress); 28 | 29 | if (address(proxyRegistry.proxies(owner)) == operator) { 30 | return true; 31 | } 32 | 33 | return super.isApprovedForAll(owner, operator); 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /mooncats-wrapped/IERC165.sol: -------------------------------------------------------------------------------- 1 | // File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/introspection/IERC165.sol 2 | 3 | 4 | 5 | pragma solidity ^0.7.6; 6 | 7 | /** 8 | * @dev Interface of the ERC165 standard, as defined in the 9 | * https://eips.ethereum.org/EIPS/eip-165[EIP]. 10 | * 11 | * Implementers can declare support of contract interfaces, which can then be 12 | * queried by others ({ERC165Checker}). 13 | * 14 | * For an implementation, see {ERC165}. 15 | */ 16 | interface IERC165 { 17 | /** 18 | * @dev Returns true if this contract implements the interface defined by 19 | * `interfaceId`. See the corresponding 20 | * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] 21 | * to learn more about how these ids are created. 22 | * 23 | * This function call must use less than 30 000 gas. 24 | */ 25 | function supportsInterface(bytes4 interfaceId) external view returns (bool); 26 | } 27 | -------------------------------------------------------------------------------- /doomcats/IERC721Receiver.sol: -------------------------------------------------------------------------------- 1 | // File @openzeppelin/contracts/token/ERC721/IERC721Receiver.sol@v4.0.0 2 | 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | /** 7 | * @title ERC721 token receiver interface 8 | * @dev Interface for any contract that wants to support safeTransfers 9 | * from ERC721 asset contracts. 10 | */ 11 | interface IERC721Receiver { 12 | /** 13 | * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} 14 | * by `operator` from `from`, this function is called. 15 | * 16 | * It must return its Solidity selector to confirm the token transfer. 17 | * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. 18 | * 19 | * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`. 20 | */ 21 | function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4); 22 | } 23 | 24 | -------------------------------------------------------------------------------- /mooncats-hd/IERC721Receiver.sol: -------------------------------------------------------------------------------- 1 | // File: @openzeppelin/contracts/token/ERC721/IERC721Receiver.sol 2 | 3 | 4 | 5 | pragma solidity ^0.8.0; 6 | 7 | /** 8 | * @title ERC721 token receiver interface 9 | * @dev Interface for any contract that wants to support safeTransfers 10 | * from ERC721 asset contracts. 11 | */ 12 | interface IERC721Receiver { 13 | /** 14 | * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} 15 | * by `operator` from `from`, this function is called. 16 | * 17 | * It must return its Solidity selector to confirm the token transfer. 18 | * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. 19 | * 20 | * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`. 21 | */ 22 | function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4); 23 | } 24 | 25 | -------------------------------------------------------------------------------- /cryptokitties/Ownable.sol: -------------------------------------------------------------------------------- 1 | /** 2 | * @title Ownable 3 | * @dev The Ownable contract has an owner address, and provides basic authorization control 4 | * functions, this simplifies the implementation of "user permissions". 5 | */ 6 | contract Ownable { 7 | address public owner; 8 | 9 | 10 | /** 11 | * @dev The Ownable constructor sets the original `owner` of the contract to the sender 12 | * account. 13 | */ 14 | function Ownable() { 15 | owner = msg.sender; 16 | } 17 | 18 | 19 | /** 20 | * @dev Throws if called by any account other than the owner. 21 | */ 22 | modifier onlyOwner() { 23 | require(msg.sender == owner); 24 | _; 25 | } 26 | 27 | 28 | /** 29 | * @dev Allows the current owner to transfer control of the contract to a newOwner. 30 | * @param newOwner The address to transfer ownership to. 31 | */ 32 | function transferOwnership(address newOwner) onlyOwner { 33 | if (newOwner != address(0)) { 34 | owner = newOwner; 35 | } 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /lasercats/Context.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | /* 6 | * @dev Provides information about the current execution context, including the 7 | * sender of the transaction and its data. While these are generally available 8 | * via msg.sender and msg.data, they should not be accessed in such a direct 9 | * manner, since when dealing with meta-transactions the account sending and 10 | * paying for execution may not be the actual sender (as far as an application 11 | * is concerned). 12 | * 13 | * This contract is only required for intermediate, library-like contracts. 14 | */ 15 | abstract contract Context { 16 | function _msgSender() internal view virtual returns (address) { 17 | return msg.sender; 18 | } 19 | 20 | function _msgData() internal view virtual returns (bytes calldata) { 21 | this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 22 | return msg.data; 23 | } 24 | } -------------------------------------------------------------------------------- /lasercats/ERC165.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "./IERC165.sol"; 6 | 7 | /** 8 | * @dev Implementation of the {IERC165} interface. 9 | * 10 | * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check 11 | * for the additional interface id that will be supported. For example: 12 | * 13 | * ```solidity 14 | * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { 15 | * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); 16 | * } 17 | * ``` 18 | * 19 | * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. 20 | */ 21 | abstract contract ERC165 is IERC165 { 22 | /** 23 | * @dev See {IERC165-supportsInterface}. 24 | */ 25 | function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { 26 | return interfaceId == type(IERC165).interfaceId; 27 | } 28 | } -------------------------------------------------------------------------------- /mooncats-acclimated/Context.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.6.0 <0.8.0; 4 | 5 | /* 6 | * @dev Provides information about the current execution context, including the 7 | * sender of the transaction and its data. While these are generally available 8 | * via msg.sender and msg.data, they should not be accessed in such a direct 9 | * manner, since when dealing with GSN meta-transactions the account sending and 10 | * paying for execution may not be the actual sender (as far as an application 11 | * is concerned). 12 | * 13 | * This contract is only required for intermediate, library-like contracts. 14 | */ 15 | abstract contract Context { 16 | function _msgSender() internal view virtual returns (address payable) { 17 | return msg.sender; 18 | } 19 | 20 | function _msgData() internal view virtual returns (bytes memory) { 21 | this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 22 | return msg.data; 23 | } 24 | } -------------------------------------------------------------------------------- /mooncats-hd/Context.sol: -------------------------------------------------------------------------------- 1 | // File: @openzeppelin/contracts/utils/Context.sol 2 | 3 | 4 | 5 | pragma solidity ^0.8.0; 6 | 7 | /* 8 | * @dev Provides information about the current execution context, including the 9 | * sender of the transaction and its data. While these are generally available 10 | * via msg.sender and msg.data, they should not be accessed in such a direct 11 | * manner, since when dealing with meta-transactions the account sending and 12 | * paying for execution may not be the actual sender (as far as an application 13 | * is concerned). 14 | * 15 | * This contract is only required for intermediate, library-like contracts. 16 | */ 17 | abstract contract Context { 18 | function _msgSender() internal view virtual returns (address) { 19 | return msg.sender; 20 | } 21 | 22 | function _msgData() internal view virtual returns (bytes calldata) { 23 | this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 24 | return msg.data; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /doomcats/ERC165.sol: -------------------------------------------------------------------------------- 1 | // File @openzeppelin/contracts/utils/introspection/ERC165.sol@v4.0.0 2 | 3 | 4 | 5 | pragma solidity ^0.8.0; 6 | 7 | /** 8 | * @dev Implementation of the {IERC165} interface. 9 | * 10 | * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check 11 | * for the additional interface id that will be supported. For example: 12 | * 13 | * ```solidity 14 | * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { 15 | * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); 16 | * } 17 | * ``` 18 | * 19 | * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. 20 | */ 21 | abstract contract ERC165 is IERC165 { 22 | /** 23 | * @dev See {IERC165-supportsInterface}. 24 | */ 25 | function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { 26 | return interfaceId == type(IERC165).interfaceId; 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /mooncats-wrapped/IERC721Receiver.sol: -------------------------------------------------------------------------------- 1 | // File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/IERC721Receiver.sol 2 | 3 | 4 | 5 | pragma solidity ^0.7.6; 6 | 7 | /** 8 | * @title ERC721 token receiver interface 9 | * @dev Interface for any contract that wants to support safeTransfers 10 | * from ERC721 asset contracts. 11 | */ 12 | interface IERC721Receiver { 13 | /** 14 | * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} 15 | * by `operator` from `from`, this function is called. 16 | * 17 | * It must return its Solidity selector to confirm the token transfer. 18 | * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. 19 | * 20 | * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`. 21 | */ 22 | function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4); 23 | } 24 | -------------------------------------------------------------------------------- /doomcats/Context.sol: -------------------------------------------------------------------------------- 1 | // File @openzeppelin/contracts/utils/Context.sol@v4.0.0 2 | 3 | 4 | 5 | pragma solidity ^0.8.0; 6 | 7 | /* 8 | * @dev Provides information about the current execution context, including the 9 | * sender of the transaction and its data. While these are generally available 10 | * via msg.sender and msg.data, they should not be accessed in such a direct 11 | * manner, since when dealing with meta-transactions the account sending and 12 | * paying for execution may not be the actual sender (as far as an application 13 | * is concerned). 14 | * 15 | * This contract is only required for intermediate, library-like contracts. 16 | */ 17 | abstract contract Context { 18 | function _msgSender() internal view virtual returns (address) { 19 | return msg.sender; 20 | } 21 | 22 | function _msgData() internal view virtual returns (bytes calldata) { 23 | this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 24 | return msg.data; 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /lasercats/IERC721Enumerable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "./IERC721.sol"; 6 | 7 | /** 8 | * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension 9 | * @dev See https://eips.ethereum.org/EIPS/eip-721 10 | */ 11 | interface IERC721Enumerable is IERC721 { 12 | 13 | /** 14 | * @dev Returns the total amount of tokens stored by the contract. 15 | */ 16 | function totalSupply() external view returns (uint256); 17 | 18 | /** 19 | * @dev Returns a token ID owned by `owner` at a given `index` of its token list. 20 | * Use along with {balanceOf} to enumerate all of ``owner``'s tokens. 21 | */ 22 | function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId); 23 | 24 | /** 25 | * @dev Returns a token ID at a given `index` of all the tokens stored by the contract. 26 | * Use along with {totalSupply} to enumerate all tokens. 27 | */ 28 | function tokenByIndex(uint256 index) external view returns (uint256); 29 | } -------------------------------------------------------------------------------- /mooncats-hd/ERC165.sol: -------------------------------------------------------------------------------- 1 | // File: @openzeppelin/contracts/utils/introspection/ERC165.sol 2 | 3 | 4 | 5 | pragma solidity ^0.8.0; 6 | 7 | 8 | /** 9 | * @dev Implementation of the {IERC165} interface. 10 | * 11 | * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check 12 | * for the additional interface id that will be supported. For example: 13 | * 14 | * ```solidity 15 | * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { 16 | * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); 17 | * } 18 | * ``` 19 | * 20 | * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. 21 | */ 22 | abstract contract ERC165 is IERC165 { 23 | /** 24 | * @dev See {IERC165-supportsInterface}. 25 | */ 26 | function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { 27 | return interfaceId == type(IERC165).interfaceId; 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /cryptokitties/ERC721Metadata.sol: -------------------------------------------------------------------------------- 1 | /// @title The external contract that is responsible for generating metadata for the kitties, 2 | /// it has one function that will return the data as bytes. 3 | 4 | contract ERC721Metadata { 5 | /// @dev Given a token Id, returns a byte array that is supposed to be converted into string. 6 | function getMetadata(uint256 _tokenId, string) public view returns (bytes32[4] buffer, uint256 count) { 7 | if (_tokenId == 1) { 8 | buffer[0] = "Hello World! :D"; 9 | count = 15; 10 | } else if (_tokenId == 2) { 11 | buffer[0] = "I would definitely choose a medi"; 12 | buffer[1] = "um length string."; 13 | count = 49; 14 | } else if (_tokenId == 3) { 15 | buffer[0] = "Lorem ipsum dolor sit amet, mi e"; 16 | buffer[1] = "st accumsan dapibus augue lorem,"; 17 | buffer[2] = " tristique vestibulum id, libero"; 18 | buffer[3] = " suscipit varius sapien aliquam."; 19 | count = 128; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /mooncats-acclimated/IERC721Enumerable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.6.2 <0.8.0; 4 | 5 | import "./IERC721.sol"; 6 | 7 | /** 8 | * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension 9 | * @dev See https://eips.ethereum.org/EIPS/eip-721 10 | */ 11 | interface IERC721Enumerable is IERC721 { 12 | 13 | /** 14 | * @dev Returns the total amount of tokens stored by the contract. 15 | */ 16 | function totalSupply() external view returns (uint256); 17 | 18 | /** 19 | * @dev Returns a token ID owned by `owner` at a given `index` of its token list. 20 | * Use along with {balanceOf} to enumerate all of ``owner``'s tokens. 21 | */ 22 | function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId); 23 | 24 | /** 25 | * @dev Returns a token ID at a given `index` of all the tokens stored by the contract. 26 | * Use along with {totalSupply} to enumerate all tokens. 27 | */ 28 | function tokenByIndex(uint256 index) external view returns (uint256); 29 | } -------------------------------------------------------------------------------- /mooncats-acclimated/lib/Strings.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.6.0 <0.8.0; 4 | 5 | /** 6 | * @dev String operations. 7 | */ 8 | library Strings { 9 | /** 10 | * @dev Converts a `uint256` to its ASCII `string` representation. 11 | */ 12 | function toString(uint256 value) internal pure returns (string memory) { 13 | // Inspired by OraclizeAPI's implementation - MIT licence 14 | // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol 15 | 16 | if (value == 0) { 17 | return "0"; 18 | } 19 | uint256 temp = value; 20 | uint256 digits; 21 | while (temp != 0) { 22 | digits++; 23 | temp /= 10; 24 | } 25 | bytes memory buffer = new bytes(digits); 26 | uint256 index = digits - 1; 27 | temp = value; 28 | while (temp != 0) { 29 | buffer[index--] = bytes1(uint8(48 + temp % 10)); 30 | temp /= 10; 31 | } 32 | return string(buffer); 33 | } 34 | } -------------------------------------------------------------------------------- /cryptokitties/Pausable.sol: -------------------------------------------------------------------------------- 1 | /** 2 | * @title Pausable 3 | * @dev Base contract which allows children to implement an emergency stop mechanism. 4 | */ 5 | 6 | contract Pausable is Ownable { 7 | event Pause(); 8 | event Unpause(); 9 | 10 | bool public paused = false; 11 | 12 | 13 | /** 14 | * @dev modifier to allow actions only when the contract IS paused 15 | */ 16 | modifier whenNotPaused() { 17 | require(!paused); 18 | _; 19 | } 20 | 21 | /** 22 | * @dev modifier to allow actions only when the contract IS NOT paused 23 | */ 24 | modifier whenPaused { 25 | require(paused); 26 | _; 27 | } 28 | 29 | /** 30 | * @dev called by the owner to pause, triggers stopped state 31 | */ 32 | function pause() onlyOwner whenNotPaused returns (bool) { 33 | paused = true; 34 | Pause(); 35 | return true; 36 | } 37 | 38 | /** 39 | * @dev called by the owner to unpause, returns to normal state 40 | */ 41 | function unpause() onlyOwner whenPaused returns (bool) { 42 | paused = false; 43 | Unpause(); 44 | return true; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /doomcats/IERC721Enumerable.sol: -------------------------------------------------------------------------------- 1 | // File @openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol@v4.0.0 2 | 3 | 4 | 5 | pragma solidity ^0.8.0; 6 | 7 | /** 8 | * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension 9 | * @dev See https://eips.ethereum.org/EIPS/eip-721 10 | */ 11 | interface IERC721Enumerable is IERC721 { 12 | 13 | /** 14 | * @dev Returns the total amount of tokens stored by the contract. 15 | */ 16 | function totalSupply() external view returns (uint256); 17 | 18 | /** 19 | * @dev Returns a token ID owned by `owner` at a given `index` of its token list. 20 | * Use along with {balanceOf} to enumerate all of ``owner``'s tokens. 21 | */ 22 | function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId); 23 | 24 | /** 25 | * @dev Returns a token ID at a given `index` of all the tokens stored by the contract. 26 | * Use along with {totalSupply} to enumerate all tokens. 27 | */ 28 | function tokenByIndex(uint256 index) external view returns (uint256); 29 | } 30 | 31 | -------------------------------------------------------------------------------- /mooncats-hd/IERC721Enumerable.sol: -------------------------------------------------------------------------------- 1 | // File: @openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol 2 | 3 | 4 | 5 | pragma solidity ^0.8.0; 6 | 7 | 8 | /** 9 | * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension 10 | * @dev See https://eips.ethereum.org/EIPS/eip-721 11 | */ 12 | interface IERC721Enumerable is IERC721 { 13 | 14 | /** 15 | * @dev Returns the total amount of tokens stored by the contract. 16 | */ 17 | function totalSupply() external view returns (uint256); 18 | 19 | /** 20 | * @dev Returns a token ID owned by `owner` at a given `index` of its token list. 21 | * Use along with {balanceOf} to enumerate all of ``owner``'s tokens. 22 | */ 23 | function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId); 24 | 25 | /** 26 | * @dev Returns a token ID at a given `index` of all the tokens stored by the contract. 27 | * Use along with {totalSupply} to enumerate all tokens. 28 | */ 29 | function tokenByIndex(uint256 index) external view returns (uint256); 30 | } 31 | 32 | -------------------------------------------------------------------------------- /mooncats-wrapped/Context.sol: -------------------------------------------------------------------------------- 1 | // File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/GSN/Context.sol 2 | 3 | 4 | 5 | pragma solidity ^0.7.6; 6 | 7 | /* 8 | * @dev Provides information about the current execution context, including the 9 | * sender of the transaction and its data. While these are generally available 10 | * via msg.sender and msg.data, they should not be accessed in such a direct 11 | * manner, since when dealing with GSN meta-transactions the account sending and 12 | * paying for execution may not be the actual sender (as far as an application 13 | * is concerned). 14 | * 15 | * This contract is only required for intermediate, library-like contracts. 16 | */ 17 | abstract contract Context { 18 | function _msgSender() internal view virtual returns (address payable) { 19 | return msg.sender; 20 | } 21 | 22 | function _msgData() internal view virtual returns (bytes memory) { 23 | this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 24 | return msg.data; 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /mooncats-wrapped/IERC721Enumerable.sol: -------------------------------------------------------------------------------- 1 | // File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/IERC721Enumerable.sol 2 | 3 | 4 | 5 | pragma solidity >=0.6.2 <0.8.0; 6 | 7 | 8 | /** 9 | * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension 10 | * @dev See https://eips.ethereum.org/EIPS/eip-721 11 | */ 12 | interface IERC721Enumerable is IERC721 { 13 | 14 | /** 15 | * @dev Returns the total amount of tokens stored by the contract. 16 | */ 17 | function totalSupply() external view returns (uint256); 18 | 19 | /** 20 | * @dev Returns a token ID owned by `owner` at a given `index` of its token list. 21 | * Use along with {balanceOf} to enumerate all of ``owner``'s tokens. 22 | */ 23 | function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId); 24 | 25 | /** 26 | * @dev Returns a token ID at a given `index` of all the tokens stored by the contract. 27 | * Use along with {totalSupply} to enumerate all tokens. 28 | */ 29 | function tokenByIndex(uint256 index) external view returns (uint256); 30 | } 31 | -------------------------------------------------------------------------------- /mooncats-wrapped/lib/Strings.sol: -------------------------------------------------------------------------------- 1 | // File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Strings.sol 2 | 3 | 4 | 5 | pragma solidity ^0.7.6; 6 | 7 | /** 8 | * @dev String operations. 9 | */ 10 | library Strings { 11 | /** 12 | * @dev Converts a `uint256` to its ASCII `string` representation. 13 | */ 14 | function toString(uint256 value) internal pure returns (string memory) { 15 | // Inspired by OraclizeAPI's implementation - MIT licence 16 | // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol 17 | 18 | if (value == 0) { 19 | return "0"; 20 | } 21 | uint256 temp = value; 22 | uint256 digits; 23 | while (temp != 0) { 24 | digits++; 25 | temp /= 10; 26 | } 27 | bytes memory buffer = new bytes(digits); 28 | uint256 index = digits - 1; 29 | temp = value; 30 | while (temp != 0) { 31 | buffer[index--] = byte(uint8(48 + temp % 10)); 32 | temp /= 10; 33 | } 34 | return string(buffer); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /cryptokitties-wrapped/ReentrancyGuard.sol: -------------------------------------------------------------------------------- 1 | /** 2 | * @title Helps contracts guard against reentrancy attacks. 3 | * @author Remco Bloemen , Eenae 4 | * @dev If you mark a function `nonReentrant`, you should also 5 | * mark it `external`. 6 | */ 7 | contract ReentrancyGuard { 8 | /// @dev counter to allow mutex lock with only one SSTORE operation 9 | uint256 private _guardCounter; 10 | 11 | constructor() public { 12 | // The counter starts at one to prevent changing it from zero to a non-zero 13 | // value, which is a more expensive operation. 14 | _guardCounter = 1; 15 | } 16 | 17 | /** 18 | * @dev Prevents a contract from calling itself, directly or indirectly. 19 | * Calling a `nonReentrant` function from another `nonReentrant` 20 | * function is not supported. It is possible to prevent this from happening 21 | * by making the `nonReentrant` function external, and make it call a 22 | * `private` function that does the actual work. 23 | */ 24 | modifier nonReentrant() { 25 | _guardCounter += 1; 26 | uint256 localCounter = _guardCounter; 27 | _; 28 | require(localCounter == _guardCounter); 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /cryptokitties/ERC721.sol: -------------------------------------------------------------------------------- 1 | /// @title Interface for contracts conforming to ERC-721: Non-Fungible Tokens 2 | /// @author Dieter Shirley (https://github.com/dete) 3 | 4 | contract ERC721 { 5 | // Required methods 6 | function totalSupply() public view returns (uint256 total); 7 | function balanceOf(address _owner) public view returns (uint256 balance); 8 | function ownerOf(uint256 _tokenId) external view returns (address owner); 9 | function approve(address _to, uint256 _tokenId) external; 10 | function transfer(address _to, uint256 _tokenId) external; 11 | function transferFrom(address _from, address _to, uint256 _tokenId) external; 12 | 13 | // Events 14 | event Transfer(address from, address to, uint256 tokenId); 15 | event Approval(address owner, address approved, uint256 tokenId); 16 | 17 | // Optional 18 | // function name() public view returns (string name); 19 | // function symbol() public view returns (string symbol); 20 | // function tokensOfOwner(address _owner) external view returns (uint256[] tokenIds); 21 | // function tokenMetadata(uint256 _tokenId, string _preferredTransport) public view returns (string infoUrl); 22 | 23 | // ERC-165 Compatibility (https://github.com/ethereum/EIPs/issues/165) 24 | function supportsInterface(bytes4 _interfaceID) external view returns (bool); 25 | } 26 | -------------------------------------------------------------------------------- /lasercats/NOTES.md: -------------------------------------------------------------------------------- 1 | # Lasercat Notes 2 | 3 | - 4 | - 5 | - - open source code for drawing laser cats (in javascript) 6 | 7 | Contract: 8 | - 9 | 10 | Markets: 11 | - 12 | 13 | 14 | 15 | 16 | ## Contract Notes 17 | 18 | What's different from original? 19 | 20 | Looks like this is a "plain-vanilla" token only. 21 | No 5-byte mooncat id or rescue id / order or naming your token etc. 22 | 23 | 24 | 25 | 26 | 27 | ## More 28 | 29 | > MISSION IMPURRSABLE 30 | > 31 | > While LaserCats may seem dangerous or unnatural 32 | > compared to their predecessors, we believe them to be equally 33 | > lovable and ready to be saved from further exploitation. 34 | 35 | Just a clone? 36 | 37 | > Each LaserCat was procedurally generated with 38 | > the use of a forked MoonCat parser and algorithms coded 39 | > from scratch. 40 | > 41 | > Each LaserCat was assigned a tier based on attribute frequency. 42 | > Two headed LaserCats are the rarest of all, 43 | > accounting for the entirety of tiers 1-3. 44 | > Only 1 in 31 LaserCats are two headed. 45 | > 46 | > Approximately 1 in 20 LaserCats developed an ability 47 | > to distort the surrounding fabric of spacetime. 48 | > As you might imagine, this is extremely dangerous. 49 | 50 | See [**lasercatcapture.com** »](https://lasercatcapture.com) 51 | 52 | What's your take? Performance Art? Trash? Cash Grab? Remake? Clone? Discuss. 53 | 54 | 55 | -------------------------------------------------------------------------------- /mooncats-acclimated/IMoonCatRescue.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.7.3; 2 | interface MoonCatRescue { 3 | function getCatDetails(bytes5 catId) 4 | external 5 | view 6 | returns ( 7 | bytes5 id, 8 | address owner, 9 | bytes32 name, 10 | address onlyOfferTo, 11 | uint256 offerPrice, 12 | address requester, 13 | uint256 requestPrice 14 | ); 15 | 16 | function rescueOrder(uint256 _rescueOrder) 17 | external 18 | view 19 | returns (bytes5 catId); 20 | 21 | function acceptAdoptionOffer(bytes5 catId) external payable; 22 | 23 | function acceptAdoptionRequest(bytes5 catId) external; 24 | 25 | function adoptionRequests(bytes5 _catId) 26 | external 27 | view 28 | returns ( 29 | bool exists, 30 | bytes5 catId, 31 | address requester, 32 | uint256 price 33 | ); 34 | 35 | function adoptionOffers(bytes5 _catId) 36 | external 37 | view 38 | returns ( 39 | bool exists, 40 | bytes5 catId, 41 | address seller, 42 | uint256 price, 43 | address offerOnlyTo 44 | ); 45 | 46 | function giveCat(bytes5 catId, address to) external; 47 | 48 | function catOwners(bytes5) external view returns (address); 49 | 50 | function makeAdoptionOfferToAddress(bytes5 catId, uint256 price, address to) external; 51 | 52 | function makeAdoptionOffer(bytes5 catId, uint256 price) external; 53 | 54 | function withdraw() external; 55 | } -------------------------------------------------------------------------------- /mooncats-acclimated/IMoonCatsWrapped.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.7.3; 2 | interface MoonCatsWrapped { 3 | 4 | /** 5 | * @dev in the original contract, this is a public map property, so is 6 | * using the default getter action, which does NOT check for "exists"; 7 | * if this returns a zero, it might be referencing token ID #0, or it might 8 | * be meaning "that MoonCat ID is not wrapped in this contract". 9 | */ 10 | function _catIDToTokenID(bytes5 catId) external pure 11 | returns (uint256); 12 | 13 | /** 14 | * @dev in the original contract, this is a public map property, so is 15 | * using the default getter action, which does NOT check for "exists". 16 | * However, no MoonCat has an ID of `0x0000000000`, so if this returns 17 | * all zeroes, it means "that token ID does not exist in this contract". 18 | */ 19 | function _tokenIDToCatID(uint256 _tokenID) external pure 20 | returns (bytes5 catId); 21 | 22 | function safeTransferFrom(address from, address to, uint256 tokenId) external; 23 | function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) external; 24 | function balanceOf(address owner) external view returns (uint256 balance); 25 | function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId); 26 | function wrap(bytes5 catId) external; 27 | function unwrap(uint256 tokenID) external; 28 | function ownerOf(uint256 tokenID) external view returns(address); 29 | function setApprovalForAll(address operator, bool _approved) external; 30 | function isApprovedForAll(address owner, address operator) external view returns (bool); 31 | function approve(address to, uint256 tokenId) external; 32 | } -------------------------------------------------------------------------------- /mooncats-wrapped/lib/Counters.sol: -------------------------------------------------------------------------------- 1 | // File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Counters.sol 2 | 3 | // SPDX-License-Identifier: MIT 4 | 5 | 6 | pragma solidity ^0.7.6; 7 | 8 | 9 | /** 10 | * @title Counters 11 | * @author Matt Condon (@shrugs) 12 | * @dev Provides counters that can only be incremented or decremented by one. This can be used e.g. to track the number 13 | * of elements in a mapping, issuing ERC721 ids, or counting request ids. 14 | * 15 | * Include with `using Counters for Counters.Counter;` 16 | * Since it is not possible to overflow a 256 bit integer with increments of one, `increment` can skip the {SafeMath} 17 | * overflow check, thereby saving gas. This does assume however correct usage, in that the underlying `_value` is never 18 | * directly accessed. 19 | */ 20 | library Counters { 21 | using SafeMath for uint256; 22 | 23 | struct Counter { 24 | // This variable should never be directly accessed by users of the library: interactions must be restricted to 25 | // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add 26 | // this feature: see https://github.com/ethereum/solidity/issues/4637 27 | uint256 _value; // default: 0 28 | } 29 | 30 | function current(Counter storage counter) internal view returns (uint256) { 31 | return counter._value; 32 | } 33 | 34 | function increment(Counter storage counter) internal { 35 | // The {SafeMath} overflow check can be skipped here, see the comment at the top 36 | counter._value += 1; 37 | } 38 | 39 | function decrement(Counter storage counter) internal { 40 | counter._value = counter._value.sub(1); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /mooncats-acclimated/ERC165.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.6.0 <0.8.0; 4 | 5 | import "./IERC165.sol"; 6 | 7 | /** 8 | * @dev Implementation of the {IERC165} interface. 9 | * 10 | * Contracts may inherit from this and call {_registerInterface} to declare 11 | * their support of an interface. 12 | */ 13 | abstract contract ERC165 is IERC165 { 14 | /* 15 | * bytes4(keccak256('supportsInterface(bytes4)')) == 0x01ffc9a7 16 | */ 17 | bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7; 18 | 19 | /** 20 | * @dev Mapping of interface ids to whether or not it's supported. 21 | */ 22 | mapping(bytes4 => bool) private _supportedInterfaces; 23 | 24 | constructor () internal { 25 | // Derived contracts need only register support for their own interfaces, 26 | // we register support for ERC165 itself here 27 | _registerInterface(_INTERFACE_ID_ERC165); 28 | } 29 | 30 | /** 31 | * @dev See {IERC165-supportsInterface}. 32 | * 33 | * Time complexity O(1), guaranteed to always use less than 30 000 gas. 34 | */ 35 | function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { 36 | return _supportedInterfaces[interfaceId]; 37 | } 38 | 39 | /** 40 | * @dev Registers the contract as an implementer of the interface defined by 41 | * `interfaceId`. Support of the actual ERC165 interface is automatic and 42 | * registering its interface id is not required. 43 | * 44 | * See {IERC165-supportsInterface}. 45 | * 46 | * Requirements: 47 | * 48 | * - `interfaceId` cannot be the ERC165 invalid interface (`0xffffffff`). 49 | */ 50 | function _registerInterface(bytes4 interfaceId) internal virtual { 51 | require(interfaceId != 0xffffffff, "ERC165: invalid interface id"); 52 | _supportedInterfaces[interfaceId] = true; 53 | } 54 | } -------------------------------------------------------------------------------- /mooncats-wrapped/ERC165.sol: -------------------------------------------------------------------------------- 1 | // File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/introspection/ERC165.sol 2 | 3 | 4 | 5 | pragma solidity ^0.7.6; 6 | 7 | 8 | /** 9 | * @dev Implementation of the {IERC165} interface. 10 | * 11 | * Contracts may inherit from this and call {_registerInterface} to declare 12 | * their support of an interface. 13 | */ 14 | abstract contract ERC165 is IERC165 { 15 | /* 16 | * bytes4(keccak256('supportsInterface(bytes4)')) == 0x01ffc9a7 17 | */ 18 | bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7; 19 | 20 | /** 21 | * @dev Mapping of interface ids to whether or not it's supported. 22 | */ 23 | mapping(bytes4 => bool) private _supportedInterfaces; 24 | 25 | constructor () internal { 26 | // Derived contracts need only register support for their own interfaces, 27 | // we register support for ERC165 itself here 28 | _registerInterface(_INTERFACE_ID_ERC165); 29 | } 30 | 31 | /** 32 | * @dev See {IERC165-supportsInterface}. 33 | * 34 | * Time complexity O(1), guaranteed to always use less than 30 000 gas. 35 | */ 36 | function supportsInterface(bytes4 interfaceId) public view override returns (bool) { 37 | return _supportedInterfaces[interfaceId]; 38 | } 39 | 40 | /** 41 | * @dev Registers the contract as an implementer of the interface defined by 42 | * `interfaceId`. Support of the actual ERC165 interface is automatic and 43 | * registering its interface id is not required. 44 | * 45 | * See {IERC165-supportsInterface}. 46 | * 47 | * Requirements: 48 | * 49 | * - `interfaceId` cannot be the ERC165 invalid interface (`0xffffffff`). 50 | */ 51 | function _registerInterface(bytes4 interfaceId) internal virtual { 52 | require(interfaceId != 0xffffffff, "ERC165: invalid interface id"); 53 | _supportedInterfaces[interfaceId] = true; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /doomcats/NOTES.md: -------------------------------------------------------------------------------- 1 | # Doomcat Notes 2 | 3 | - 4 | - 5 | 6 | Contract: 7 | - 8 | 9 | Markets: 10 | - <> 11 | 12 | 13 | 14 | 15 | 16 | 17 | ## More 18 | 19 | > How can I rescue the DoomCats? 20 | > On 4/7/2021 at 10:00:00 PM, transportation for the DoomCat 21 | > souls will be possible through an affordable, linear bonding 22 | > curve starting at 0.01 ETH, increasing by 0.00086 ETH every 23 | > 100 cats sold, to a cap of 0.22758 ETH. 24 | 25 | Just a clone? 26 | 27 | > The highest ascended cats - the 6% of most spiritually evolved Cats - are given unique breeds (Glowie, Alien, Zombie, Nuke, Hate, or Smokey). 28 | > 5% of DoomCats have a chance for their journey to be 29 | > backdropped with a special background, including: Desert, Beach, Windows, Matrix, or Heaven. 30 | > 2% of DoomCats brought their favorite item to ease the graduation process: items include: googles, ciggies, or one of five colored party hats. Party hat colors include: red, blue, yellow, purple, or white. 31 | > There are 39 purple-draped cats in honor of the first 39 ascended Members. Additionally, the oldest 0.1% of souls will be completely black and white, the "Genesis DoomCats". 32 | 33 | and 34 | 35 | > Is this a MoonCats clone? 36 | > 37 | > The contract code is completely new, original code, 38 | > which includes autonomous Auctions and the Rescue linear bonding curve 39 | > 40 | > The cats were all newly procedurally generated, 41 | > with additional attributes like backgrounds, hats, ciggies, etc. 42 | 43 | See [**doom.cat** »](https://www.doom.cat) 44 | 45 | What's your take? Performance Art? Trash? Cash Grab? Remake? Clone? Discuss. 46 | 47 | **Update** The devs write: 48 | 49 | > Rescues are live! 50 | > 51 | > Apologies for any failed txns, 52 | > we did not expect this level of demand off the bat! 53 | > 54 | > We spun up 16 servers now, to tell you how heavy the demand is! 55 | 56 | 57 | -------------------------------------------------------------------------------- /cryptokitties-wrapped/lib/SafeMath.sol: -------------------------------------------------------------------------------- 1 | /** 2 | * @title SafeMath 3 | * @dev Unsigned math operations with safety checks that revert on error 4 | */ 5 | library SafeMath { 6 | /** 7 | * @dev Multiplies two unsigned integers, reverts on overflow. 8 | */ 9 | function mul(uint256 a, uint256 b) internal pure returns (uint256) { 10 | // Gas optimization: this is cheaper than requiring 'a' not being zero, but the 11 | // benefit is lost if 'b' is also tested. 12 | // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522 13 | if (a == 0) { 14 | return 0; 15 | } 16 | 17 | uint256 c = a * b; 18 | require(c / a == b); 19 | 20 | return c; 21 | } 22 | 23 | /** 24 | * @dev Integer division of two unsigned integers truncating the quotient, reverts on division by zero. 25 | */ 26 | function div(uint256 a, uint256 b) internal pure returns (uint256) { 27 | // Solidity only automatically asserts when dividing by 0 28 | require(b > 0); 29 | uint256 c = a / b; 30 | // assert(a == b * c + a % b); // There is no case in which this doesn't hold 31 | 32 | return c; 33 | } 34 | 35 | /** 36 | * @dev Subtracts two unsigned integers, reverts on overflow (i.e. if subtrahend is greater than minuend). 37 | */ 38 | function sub(uint256 a, uint256 b) internal pure returns (uint256) { 39 | require(b <= a); 40 | uint256 c = a - b; 41 | 42 | return c; 43 | } 44 | 45 | /** 46 | * @dev Adds two unsigned integers, reverts on overflow. 47 | */ 48 | function add(uint256 a, uint256 b) internal pure returns (uint256) { 49 | uint256 c = a + b; 50 | require(c >= a); 51 | 52 | return c; 53 | } 54 | 55 | /** 56 | * @dev Divides two unsigned integers and returns the remainder (unsigned integer modulo), 57 | * reverts when dividing by zero. 58 | */ 59 | function mod(uint256 a, uint256 b) internal pure returns (uint256) { 60 | require(b != 0); 61 | return a % b; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /mooncats-hd/WrapperContract.sol: -------------------------------------------------------------------------------- 1 | interface WrapperContract { 2 | 3 | // Events 4 | 5 | event Wrapped(bytes5 indexed catId, uint tokenID); 6 | event Unwrapped(bytes5 indexed catId, uint tokenID); 7 | 8 | // Read contract 9 | 10 | function _baseURI() external view returns (string memory); 11 | 12 | function _catIDToTokenID(bytes5) external view returns (uint); 13 | 14 | function _moonCats() external view returns (address); 15 | 16 | function _owner() external view returns (address); 17 | 18 | function _tokenIDToCatID(uint) external view returns (bytes5); 19 | 20 | function balanceOf(address) external view returns (uint); 21 | 22 | function baseURI() external view returns (string memory); 23 | 24 | function getApproved(uint) external view returns (address); 25 | 26 | function isApprovedForAll(address owner, address operator) external view returns (bool); 27 | 28 | function name() external view returns (string memory); 29 | 30 | function ownerOf(uint) external view returns (address); 31 | 32 | function supportsInterface(bytes4) external view returns (bool); 33 | 34 | function symbol() external view returns (string memory); 35 | 36 | function tokenByIndex(uint) external view returns (uint); 37 | 38 | function tokenOfOwnerByIndex(address owner, uint index) external view returns (uint); 39 | 40 | function tokenURI(uint) external view returns (uint); 41 | 42 | function totalSupply() external view returns (uint); 43 | 44 | // Write contract 45 | 46 | function approve(address to, uint tokenId) external; 47 | 48 | function renounceOwnership() external; 49 | 50 | function safeTransferFrom(address from, address to, uint tokenId) external; 51 | 52 | function safeTransferFrom(address from, address to, uint tokenId, bytes memory _data) external; 53 | 54 | function setApprovalForAll(address operator, bool approved) external; 55 | 56 | function setBaseURI(string memory _newBaseURI) external; 57 | 58 | function transferFrom(address from, address to, uint tokenId) external; 59 | 60 | function unwrap(uint tokenId) external; 61 | 62 | function wrap(bytes5 catId) external; 63 | } 64 | -------------------------------------------------------------------------------- /mooncats-helper/MooncatHelper.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * copied from https://etherscan.io/address/0x9aa3d159eb155305a11af921696576a3e195d24d#code 3 | * 4 | * Submitted for verification at Etherscan.io on 2021-03-16 5 | */ 6 | 7 | // SPDX-License-Identifier: GPL-3.0 8 | 9 | pragma solidity ^0.6.0; 10 | 11 | interface MooncatContract { 12 | 13 | function catOwners(bytes5 catId) external view returns (address); 14 | 15 | function remainingGenesisCats() external view returns (uint); 16 | 17 | function makeAdoptionOffer(bytes5 catId, uint price) external; 18 | 19 | function makeAdoptionOfferToAddress(bytes5 catId, uint price, address to) external; 20 | 21 | function acceptAdoptionOffer(bytes5 catId) external payable; 22 | 23 | } 24 | 25 | interface WrappedMooncatContract { 26 | 27 | function wrap(bytes5 catId) external; 28 | 29 | function unwrap(uint256 tokenID) external; 30 | 31 | function transferFrom(address from, address to, uint256 tokenId) external; 32 | 33 | function _catIDToTokenID(bytes5 catId) external view returns (uint); 34 | 35 | function ownerOf(uint256 tokenId) external view returns (address); 36 | } 37 | 38 | contract MooncatHelper { 39 | 40 | address mc = 0x60cd862c9C687A9dE49aecdC3A99b74A4fc54aB6; 41 | address wmc = 0x7C40c393DC0f283F318791d746d894DdD3693572; 42 | uint256 fee = 10000000000000000; 43 | address payable public dev; 44 | 45 | constructor() public payable { 46 | dev = payable(msg.sender); 47 | } 48 | 49 | function buyAndWrap(bytes5 catId) public payable { 50 | require(msg.value > fee, "Please include 0.01 eth fee"); 51 | MooncatContract(mc).acceptAdoptionOffer{value:msg.value-fee}(catId); 52 | MooncatContract(mc).makeAdoptionOfferToAddress(catId, 0, wmc); 53 | WrappedMooncatContract(wmc).wrap(catId); 54 | uint tokenId = WrappedMooncatContract(wmc)._catIDToTokenID(catId); 55 | WrappedMooncatContract(wmc).transferFrom(address(this), msg.sender, tokenId); 56 | } 57 | 58 | function withdraw() public { 59 | uint amount = address(this).balance; 60 | (bool success,) = dev.call{value: amount}(""); 61 | require(success, "Failed to send Ether"); 62 | } 63 | 64 | } -------------------------------------------------------------------------------- /lasercats/lib/Strings.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | /** 6 | * @dev String operations. 7 | */ 8 | library Strings { 9 | bytes16 private constant alphabet = "0123456789abcdef"; 10 | 11 | /** 12 | * @dev Converts a `uint256` to its ASCII `string` decimal representation. 13 | */ 14 | function toString(uint256 value) internal pure returns (string memory) { 15 | // Inspired by OraclizeAPI's implementation - MIT licence 16 | // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol 17 | 18 | if (value == 0) { 19 | return "0"; 20 | } 21 | uint256 temp = value; 22 | uint256 digits; 23 | while (temp != 0) { 24 | digits++; 25 | temp /= 10; 26 | } 27 | bytes memory buffer = new bytes(digits); 28 | while (value != 0) { 29 | digits -= 1; 30 | buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); 31 | value /= 10; 32 | } 33 | return string(buffer); 34 | } 35 | 36 | /** 37 | * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. 38 | */ 39 | function toHexString(uint256 value) internal pure returns (string memory) { 40 | if (value == 0) { 41 | return "0x00"; 42 | } 43 | uint256 temp = value; 44 | uint256 length = 0; 45 | while (temp != 0) { 46 | length++; 47 | temp >>= 8; 48 | } 49 | return toHexString(value, length); 50 | } 51 | 52 | /** 53 | * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. 54 | */ 55 | function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { 56 | bytes memory buffer = new bytes(2 * length + 2); 57 | buffer[0] = "0"; 58 | buffer[1] = "x"; 59 | for (uint256 i = 2 * length + 1; i > 1; --i) { 60 | buffer[i] = alphabet[value & 0xf]; 61 | value >>= 4; 62 | } 63 | require(value == 0, "Strings: hex length insufficient"); 64 | return string(buffer); 65 | } 66 | 67 | } -------------------------------------------------------------------------------- /mooncats-hd/lib/Strings.sol: -------------------------------------------------------------------------------- 1 | // File: @openzeppelin/contracts/utils/Strings.sol 2 | 3 | 4 | 5 | pragma solidity ^0.8.0; 6 | 7 | /** 8 | * @dev String operations. 9 | */ 10 | library Strings { 11 | bytes16 private constant alphabet = "0123456789abcdef"; 12 | 13 | /** 14 | * @dev Converts a `uint256` to its ASCII `string` decimal representation. 15 | */ 16 | function toString(uint256 value) internal pure returns (string memory) { 17 | // Inspired by OraclizeAPI's implementation - MIT licence 18 | // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol 19 | 20 | if (value == 0) { 21 | return "0"; 22 | } 23 | uint256 temp = value; 24 | uint256 digits; 25 | while (temp != 0) { 26 | digits++; 27 | temp /= 10; 28 | } 29 | bytes memory buffer = new bytes(digits); 30 | while (value != 0) { 31 | digits -= 1; 32 | buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); 33 | value /= 10; 34 | } 35 | return string(buffer); 36 | } 37 | 38 | /** 39 | * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. 40 | */ 41 | function toHexString(uint256 value) internal pure returns (string memory) { 42 | if (value == 0) { 43 | return "0x00"; 44 | } 45 | uint256 temp = value; 46 | uint256 length = 0; 47 | while (temp != 0) { 48 | length++; 49 | temp >>= 8; 50 | } 51 | return toHexString(value, length); 52 | } 53 | 54 | /** 55 | * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. 56 | */ 57 | function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { 58 | bytes memory buffer = new bytes(2 * length + 2); 59 | buffer[0] = "0"; 60 | buffer[1] = "x"; 61 | for (uint256 i = 2 * length + 1; i > 1; --i) { 62 | buffer[i] = alphabet[value & 0xf]; 63 | value >>= 4; 64 | } 65 | require(value == 0, "Strings: hex length insufficient"); 66 | return string(buffer); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /doomcats/lib/Strings.sol: -------------------------------------------------------------------------------- 1 | // File @openzeppelin/contracts/utils/Strings.sol@v4.0.0 2 | 3 | 4 | 5 | pragma solidity ^0.8.0; 6 | 7 | /** 8 | * @dev String operations. 9 | */ 10 | library Strings { 11 | bytes16 private constant alphabet = "0123456789abcdef"; 12 | 13 | /** 14 | * @dev Converts a `uint256` to its ASCII `string` decimal representation. 15 | */ 16 | function toString(uint256 value) internal pure returns (string memory) { 17 | // Inspired by OraclizeAPI's implementation - MIT licence 18 | // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol 19 | 20 | if (value == 0) { 21 | return "0"; 22 | } 23 | uint256 temp = value; 24 | uint256 digits; 25 | while (temp != 0) { 26 | digits++; 27 | temp /= 10; 28 | } 29 | bytes memory buffer = new bytes(digits); 30 | while (value != 0) { 31 | digits -= 1; 32 | buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); 33 | value /= 10; 34 | } 35 | return string(buffer); 36 | } 37 | 38 | /** 39 | * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. 40 | */ 41 | function toHexString(uint256 value) internal pure returns (string memory) { 42 | if (value == 0) { 43 | return "0x00"; 44 | } 45 | uint256 temp = value; 46 | uint256 length = 0; 47 | while (temp != 0) { 48 | length++; 49 | temp >>= 8; 50 | } 51 | return toHexString(value, length); 52 | } 53 | 54 | /** 55 | * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. 56 | */ 57 | function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { 58 | bytes memory buffer = new bytes(2 * length + 2); 59 | buffer[0] = "0"; 60 | buffer[1] = "x"; 61 | for (uint256 i = 2 * length + 1; i > 1; --i) { 62 | buffer[i] = alphabet[value & 0xf]; 63 | value >>= 4; 64 | } 65 | require(value == 0, "Strings: hex length insufficient"); 66 | return string(buffer); 67 | } 68 | 69 | } 70 | 71 | -------------------------------------------------------------------------------- /mooncats-vote/PonderwareTransferOfAuthority.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * copied from https://etherscan.io/address/0xa3843c6f47384e3ca951bd0207179f58d2179d3f#code 3 | * 4 | * Submitted for verification at Etherscan.io on 2021-03-22 5 | */ 6 | 7 | // SPDX-License-Identifier: MIT 8 | 9 | pragma solidity ^0.8.0; 10 | 11 | contract PonderwareTransferOfAuthority { 12 | 13 | // ponderware is destroying the private key controlling the MooncatRescue contract 14 | // due to the outcome of the vote contract: 0x1916F482BB9F3523a489791Ae3d6e052b362C777 15 | 16 | // This contract, if confirmed, represents a public transfer of the official ponderware address. 17 | 18 | // To ensure confirmation and get ponderware's new address, call the `whereIsPonderware` function 19 | 20 | address immutable oldPonderwareAddress; 21 | address payable immutable newPonderwareAddress; 22 | 23 | bool confirmedByOld = false; 24 | bool confirmedByNew = false; 25 | bool transferVoid = false; 26 | 27 | modifier addressIsAuthorized { 28 | require((msg.sender == oldPonderwareAddress) || (msg.sender == newPonderwareAddress), "Unauthorized"); 29 | _; 30 | } 31 | 32 | modifier transferIsNotVoid { 33 | require(!transferVoid, "Transfer Of Authority Void"); 34 | _; 35 | } 36 | 37 | modifier transferIsConfirmed { 38 | require((confirmedByOld && confirmedByNew), "Not Confirmed"); 39 | _; 40 | } 41 | 42 | constructor(address payable newPonderwareAddress_) { 43 | oldPonderwareAddress = msg.sender; 44 | newPonderwareAddress = newPonderwareAddress_; 45 | } 46 | 47 | receive() external payable { 48 | newPonderwareAddress.transfer(msg.value); 49 | } 50 | 51 | function voidTransfer () public transferIsNotVoid addressIsAuthorized { 52 | require(!confirmedByOld, "Already Confirmed"); 53 | transferVoid = true; 54 | } 55 | 56 | function confirm () public transferIsNotVoid addressIsAuthorized { 57 | if (msg.sender == newPonderwareAddress){ 58 | confirmedByNew = true; 59 | } else { 60 | require(confirmedByNew, "New Not Confirmed"); 61 | confirmedByOld = true; 62 | } 63 | } 64 | 65 | function whereIsPonderware() public view transferIsNotVoid transferIsConfirmed returns (address) { 66 | return newPonderwareAddress; 67 | } 68 | 69 | } -------------------------------------------------------------------------------- /mooncats-wrapped/MoonCatsWrapped.sol: -------------------------------------------------------------------------------- 1 | // File: browser/MoonCatsWrapped.sol 2 | 3 | pragma solidity ^0.7.6; 4 | pragma abicoder v2; 5 | 6 | 7 | contract MoonCatsWrapped is ERC721 { 8 | 9 | using Counters for Counters.Counter; 10 | Counters.Counter private _tokenIdTracker; 11 | 12 | MoonCatsRescue public _moonCats = MoonCatsRescue(0x60cd862c9C687A9dE49aecdC3A99b74A4fc54aB6); 13 | 14 | mapping(bytes5 => uint) public _catIDToTokenID; 15 | mapping(uint => bytes5) public _tokenIDToCatID; 16 | string private _baseTokenURI; 17 | address public _owner = 0xD2927a91570146218eD700566DF516d67C5ECFAB; 18 | 19 | 20 | event Wrapped(bytes5 indexed catId, uint tokenID); 21 | event Unwrapped(bytes5 indexed catId, uint tokenID); 22 | 23 | constructor() ERC721("Wrapped MoonCatsRescue", "WMCR") {} 24 | 25 | function setBaseURI(string memory _newBaseURI) public { 26 | require(_msgSender() == _owner); 27 | _baseTokenURI = _newBaseURI; 28 | } 29 | 30 | function renounceOwnership() public { 31 | require(_msgSender() == _owner); 32 | _owner = address(0x0); 33 | } 34 | 35 | 36 | function _baseURI() public view virtual returns (string memory) { 37 | return _baseTokenURI; 38 | } 39 | 40 | 41 | function wrap(bytes5 catId) public { 42 | MoonCatsRescue.AdoptionOffer memory offer = _moonCats.adoptionOffers(catId); 43 | require(offer.seller == _msgSender()); //only owner can wrap 44 | _moonCats.acceptAdoptionOffer(catId); 45 | 46 | 47 | //check if it was previously assigned 48 | uint tokenID = _catIDToTokenID[catId]; 49 | uint tokenIDToAssign = tokenID; 50 | 51 | if (tokenID == 0) { 52 | tokenIDToAssign = _tokenIdTracker.current(); 53 | _tokenIdTracker.increment(); 54 | _catIDToTokenID[catId] = tokenIDToAssign; 55 | _tokenIDToCatID[tokenIDToAssign] = catId; 56 | } 57 | _mint(_msgSender(), tokenIDToAssign); 58 | emit Wrapped(catId, tokenIDToAssign); 59 | 60 | } 61 | 62 | function unwrap(uint256 tokenID) public { 63 | bytes5 catId = _tokenIDToCatID[tokenID]; 64 | address owner = ownerOf(tokenID); 65 | require(owner == _msgSender()); //only owner can unwrap 66 | _moonCats.giveCat(catId, owner); 67 | _burn(tokenID); 68 | emit Unwrapped(catId, tokenID); 69 | } 70 | 71 | } -------------------------------------------------------------------------------- /lasercats/Ownable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "./Context.sol"; 6 | /** 7 | * @dev Contract module which provides a basic access control mechanism, where 8 | * there is an account (an owner) that can be granted exclusive access to 9 | * specific functions. 10 | * 11 | * By default, the owner account will be the one that deploys the contract. This 12 | * can later be changed with {transferOwnership}. 13 | * 14 | * This module is used through inheritance. It will make available the modifier 15 | * `onlyOwner`, which can be applied to your functions to restrict their use to 16 | * the owner. 17 | */ 18 | abstract contract Ownable is Context { 19 | address private _owner; 20 | 21 | event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); 22 | 23 | /** 24 | * @dev Initializes the contract setting the deployer as the initial owner. 25 | */ 26 | constructor () { 27 | address msgSender = _msgSender(); 28 | _owner = msgSender; 29 | emit OwnershipTransferred(address(0), msgSender); 30 | } 31 | 32 | /** 33 | * @dev Returns the address of the current owner. 34 | */ 35 | function owner() public view virtual returns (address) { 36 | return _owner; 37 | } 38 | 39 | /** 40 | * @dev Throws if called by any account other than the owner. 41 | */ 42 | modifier onlyOwner() { 43 | require(owner() == _msgSender(), "Ownable: caller is not the owner"); 44 | _; 45 | } 46 | 47 | /** 48 | * @dev Leaves the contract without owner. It will not be possible to call 49 | * `onlyOwner` functions anymore. Can only be called by the current owner. 50 | * 51 | * NOTE: Renouncing ownership will leave the contract without an owner, 52 | * thereby removing any functionality that is only available to the owner. 53 | */ 54 | function renounceOwnership() public virtual onlyOwner { 55 | emit OwnershipTransferred(_owner, address(0)); 56 | _owner = address(0); 57 | } 58 | 59 | /** 60 | * @dev Transfers ownership of the contract to a new account (`newOwner`). 61 | * Can only be called by the current owner. 62 | */ 63 | function transferOwnership(address newOwner) public virtual onlyOwner { 64 | require(newOwner != address(0), "Ownable: new owner is the zero address"); 65 | emit OwnershipTransferred(_owner, newOwner); 66 | _owner = newOwner; 67 | } 68 | } -------------------------------------------------------------------------------- /mooncats-hd/Ownable.sol: -------------------------------------------------------------------------------- 1 | 2 | // File: @openzeppelin/contracts/access/Ownable.sol 3 | 4 | 5 | 6 | pragma solidity ^0.8.0; 7 | 8 | /** 9 | * @dev Contract module which provides a basic access control mechanism, where 10 | * there is an account (an owner) that can be granted exclusive access to 11 | * specific functions. 12 | * 13 | * By default, the owner account will be the one that deploys the contract. This 14 | * can later be changed with {transferOwnership}. 15 | * 16 | * This module is used through inheritance. It will make available the modifier 17 | * `onlyOwner`, which can be applied to your functions to restrict their use to 18 | * the owner. 19 | */ 20 | abstract contract Ownable is Context { 21 | address private _owner; 22 | 23 | event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); 24 | 25 | /** 26 | * @dev Initializes the contract setting the deployer as the initial owner. 27 | */ 28 | constructor () { 29 | address msgSender = _msgSender(); 30 | _owner = msgSender; 31 | emit OwnershipTransferred(address(0), msgSender); 32 | } 33 | 34 | /** 35 | * @dev Returns the address of the current owner. 36 | */ 37 | function owner() public view virtual returns (address) { 38 | return _owner; 39 | } 40 | 41 | /** 42 | * @dev Throws if called by any account other than the owner. 43 | */ 44 | modifier onlyOwner() { 45 | require(owner() == _msgSender(), "Ownable: caller is not the owner"); 46 | _; 47 | } 48 | 49 | /** 50 | * @dev Leaves the contract without owner. It will not be possible to call 51 | * `onlyOwner` functions anymore. Can only be called by the current owner. 52 | * 53 | * NOTE: Renouncing ownership will leave the contract without an owner, 54 | * thereby removing any functionality that is only available to the owner. 55 | */ 56 | function renounceOwnership() public virtual onlyOwner { 57 | emit OwnershipTransferred(_owner, address(0)); 58 | _owner = address(0); 59 | } 60 | 61 | /** 62 | * @dev Transfers ownership of the contract to a new account (`newOwner`). 63 | * Can only be called by the current owner. 64 | */ 65 | function transferOwnership(address newOwner) public virtual onlyOwner { 66 | require(newOwner != address(0), "Ownable: new owner is the zero address"); 67 | emit OwnershipTransferred(_owner, newOwner); 68 | _owner = newOwner; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /mooncats-acclimated/Ownable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.6.0 <0.8.0; 4 | 5 | import "../utils/Context.sol"; 6 | /** 7 | * @dev Contract module which provides a basic access control mechanism, where 8 | * there is an account (an owner) that can be granted exclusive access to 9 | * specific functions. 10 | * 11 | * By default, the owner account will be the one that deploys the contract. This 12 | * can later be changed with {transferOwnership}. 13 | * 14 | * This module is used through inheritance. It will make available the modifier 15 | * `onlyOwner`, which can be applied to your functions to restrict their use to 16 | * the owner. 17 | */ 18 | abstract contract Ownable is Context { 19 | address private _owner; 20 | 21 | event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); 22 | 23 | /** 24 | * @dev Initializes the contract setting the deployer as the initial owner. 25 | */ 26 | constructor () internal { 27 | address msgSender = _msgSender(); 28 | _owner = msgSender; 29 | emit OwnershipTransferred(address(0), msgSender); 30 | } 31 | 32 | /** 33 | * @dev Returns the address of the current owner. 34 | */ 35 | function owner() public view virtual returns (address) { 36 | return _owner; 37 | } 38 | 39 | /** 40 | * @dev Throws if called by any account other than the owner. 41 | */ 42 | modifier onlyOwner() { 43 | require(owner() == _msgSender(), "Ownable: caller is not the owner"); 44 | _; 45 | } 46 | 47 | /** 48 | * @dev Leaves the contract without owner. It will not be possible to call 49 | * `onlyOwner` functions anymore. Can only be called by the current owner. 50 | * 51 | * NOTE: Renouncing ownership will leave the contract without an owner, 52 | * thereby removing any functionality that is only available to the owner. 53 | */ 54 | function renounceOwnership() public virtual onlyOwner { 55 | emit OwnershipTransferred(_owner, address(0)); 56 | _owner = address(0); 57 | } 58 | 59 | /** 60 | * @dev Transfers ownership of the contract to a new account (`newOwner`). 61 | * Can only be called by the current owner. 62 | */ 63 | function transferOwnership(address newOwner) public virtual onlyOwner { 64 | require(newOwner != address(0), "Ownable: new owner is the zero address"); 65 | emit OwnershipTransferred(_owner, newOwner); 66 | _owner = newOwner; 67 | } 68 | } -------------------------------------------------------------------------------- /mooncats-acclimated/Pausable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.6.0 <0.8.0; 4 | 5 | import "./Context.sol"; 6 | 7 | /** 8 | * @dev Contract module which allows children to implement an emergency stop 9 | * mechanism that can be triggered by an authorized account. 10 | * 11 | * This module is used through inheritance. It will make available the 12 | * modifiers `whenNotPaused` and `whenPaused`, which can be applied to 13 | * the functions of your contract. Note that they will not be pausable by 14 | * simply including this module, only once the modifiers are put in place. 15 | */ 16 | abstract contract Pausable is Context { 17 | /** 18 | * @dev Emitted when the pause is triggered by `account`. 19 | */ 20 | event Paused(address account); 21 | 22 | /** 23 | * @dev Emitted when the pause is lifted by `account`. 24 | */ 25 | event Unpaused(address account); 26 | 27 | bool private _paused; 28 | 29 | /** 30 | * @dev Initializes the contract in unpaused state. 31 | */ 32 | constructor () internal { 33 | _paused = false; 34 | } 35 | 36 | /** 37 | * @dev Returns true if the contract is paused, and false otherwise. 38 | */ 39 | function paused() public view virtual returns (bool) { 40 | return _paused; 41 | } 42 | 43 | /** 44 | * @dev Modifier to make a function callable only when the contract is not paused. 45 | * 46 | * Requirements: 47 | * 48 | * - The contract must not be paused. 49 | */ 50 | modifier whenNotPaused() { 51 | require(!paused(), "Pausable: paused"); 52 | _; 53 | } 54 | 55 | /** 56 | * @dev Modifier to make a function callable only when the contract is paused. 57 | * 58 | * Requirements: 59 | * 60 | * - The contract must be paused. 61 | */ 62 | modifier whenPaused() { 63 | require(paused(), "Pausable: not paused"); 64 | _; 65 | } 66 | 67 | /** 68 | * @dev Triggers stopped state. 69 | * 70 | * Requirements: 71 | * 72 | * - The contract must not be paused. 73 | */ 74 | function _pause() internal virtual whenNotPaused { 75 | _paused = true; 76 | emit Paused(_msgSender()); 77 | } 78 | 79 | /** 80 | * @dev Returns to normal state. 81 | * 82 | * Requirements: 83 | * 84 | * - The contract must be paused. 85 | */ 86 | function _unpause() internal virtual whenPaused { 87 | _paused = false; 88 | emit Unpaused(_msgSender()); 89 | } 90 | } -------------------------------------------------------------------------------- /cryptokitties/KittyMinting.sol: -------------------------------------------------------------------------------- 1 | /// @title all functions related to creating kittens 2 | 3 | contract KittyMinting is KittyAuction { 4 | 5 | // Limits the number of cats the contract owner can ever create. 6 | uint256 public constant PROMO_CREATION_LIMIT = 5000; 7 | uint256 public constant GEN0_CREATION_LIMIT = 45000; 8 | 9 | // Constants for gen0 auctions. 10 | uint256 public constant GEN0_STARTING_PRICE = 10 finney; 11 | uint256 public constant GEN0_AUCTION_DURATION = 1 days; 12 | 13 | // Counts the number of cats the contract owner has created. 14 | uint256 public promoCreatedCount; 15 | uint256 public gen0CreatedCount; 16 | 17 | /// @dev we can create promo kittens, up to a limit. Only callable by COO 18 | /// @param _genes the encoded genes of the kitten to be created, any value is accepted 19 | /// @param _owner the future owner of the created kittens. Default to contract COO 20 | function createPromoKitty(uint256 _genes, address _owner) external onlyCOO { 21 | address kittyOwner = _owner; 22 | if (kittyOwner == address(0)) { 23 | kittyOwner = cooAddress; 24 | } 25 | require(promoCreatedCount < PROMO_CREATION_LIMIT); 26 | 27 | promoCreatedCount++; 28 | _createKitty(0, 0, 0, _genes, kittyOwner); 29 | } 30 | 31 | /// @dev Creates a new gen0 kitty with the given genes and 32 | /// creates an auction for it. 33 | function createGen0Auction(uint256 _genes) external onlyCOO { 34 | require(gen0CreatedCount < GEN0_CREATION_LIMIT); 35 | 36 | uint256 kittyId = _createKitty(0, 0, 0, _genes, address(this)); 37 | _approve(kittyId, saleAuction); 38 | 39 | saleAuction.createAuction( 40 | kittyId, 41 | _computeNextGen0Price(), 42 | 0, 43 | GEN0_AUCTION_DURATION, 44 | address(this) 45 | ); 46 | 47 | gen0CreatedCount++; 48 | } 49 | 50 | /// @dev Computes the next gen0 auction starting price, given 51 | /// the average of the past 5 prices + 50%. 52 | function _computeNextGen0Price() internal view returns (uint256) { 53 | uint256 avePrice = saleAuction.averageGen0SalePrice(); 54 | 55 | // Sanity check to ensure we don't overflow arithmetic 56 | require(avePrice == uint256(uint128(avePrice))); 57 | 58 | uint256 nextPrice = avePrice + (avePrice / 2); 59 | 60 | // We never auction for less than starting price 61 | if (nextPrice < GEN0_STARTING_PRICE) { 62 | nextPrice = GEN0_STARTING_PRICE; 63 | } 64 | 65 | return nextPrice; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /cryptokitties/SiringClockAuction.sol: -------------------------------------------------------------------------------- 1 | /// @title Reverse auction modified for siring 2 | /// @notice We omit a fallback function to prevent accidental sends to this contract. 3 | 4 | contract SiringClockAuction is ClockAuction { 5 | 6 | // @dev Sanity check that allows us to ensure that we are pointing to the 7 | // right auction in our setSiringAuctionAddress() call. 8 | bool public isSiringClockAuction = true; 9 | 10 | // Delegate constructor 11 | function SiringClockAuction(address _nftAddr, uint256 _cut) public 12 | ClockAuction(_nftAddr, _cut) {} 13 | 14 | /// @dev Creates and begins a new auction. Since this function is wrapped, 15 | /// require sender to be KittyCore contract. 16 | /// @param _tokenId - ID of token to auction, sender must be owner. 17 | /// @param _startingPrice - Price of item (in wei) at beginning of auction. 18 | /// @param _endingPrice - Price of item (in wei) at end of auction. 19 | /// @param _duration - Length of auction (in seconds). 20 | /// @param _seller - Seller, if not the message sender 21 | function createAuction( 22 | uint256 _tokenId, 23 | uint256 _startingPrice, 24 | uint256 _endingPrice, 25 | uint256 _duration, 26 | address _seller 27 | ) 28 | external 29 | { 30 | // Sanity check that no inputs overflow how many bits we've allocated 31 | // to store them in the auction struct. 32 | require(_startingPrice == uint256(uint128(_startingPrice))); 33 | require(_endingPrice == uint256(uint128(_endingPrice))); 34 | require(_duration == uint256(uint64(_duration))); 35 | 36 | require(msg.sender == address(nonFungibleContract)); 37 | _escrow(_seller, _tokenId); 38 | Auction memory auction = Auction( 39 | _seller, 40 | uint128(_startingPrice), 41 | uint128(_endingPrice), 42 | uint64(_duration), 43 | uint64(now) 44 | ); 45 | _addAuction(_tokenId, auction); 46 | } 47 | 48 | /// @dev Places a bid for siring. Requires the sender 49 | /// is the KittyCore contract because all bid methods 50 | /// should be wrapped. Also returns the kitty to the 51 | /// seller rather than the winner. 52 | function bid(uint256 _tokenId) 53 | external 54 | payable 55 | { 56 | require(msg.sender == address(nonFungibleContract)); 57 | address seller = tokenIdToAuction[_tokenId].seller; 58 | // _bid checks that token ID is valid and will throw if bid fails 59 | _bid(_tokenId, msg.value); 60 | // We transfer the kitty back to the seller, the winner will get 61 | // the offspring 62 | _transfer(seller, _tokenId); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /cryptocats/PreviousCryptoCatsContract.sol: -------------------------------------------------------------------------------- 1 | contract PreviousCryptoCatsContract { 2 | 3 | /* You can use this hash to verify the image file containing all cats */ 4 | string public imageHash = "e055fe5eb1d95ea4e42b24d1038db13c24667c494ce721375bdd827d34c59059"; 5 | 6 | /* Variables to store contract owner and contract token standard details */ 7 | address owner; 8 | string public standard = 'CryptoCats'; 9 | string public name; 10 | string public symbol; 11 | uint8 public decimals; 12 | uint256 public _totalSupply; 13 | 14 | // Store reference to previous cryptocat contract containing alpha release owners 15 | // PROD 16 | address public previousContractAddress = 0xa185B9E63FB83A5a1A13A4460B8E8605672b6020; 17 | // ROPSTEN 18 | // address public previousContractAddress = 0x0b0DB7bd68F944C219566E54e84483b6c512737B; 19 | uint8 public contractVersion; 20 | bool public totalSupplyIsLocked; 21 | 22 | bool public allCatsAssigned = false; // boolean flag to indicate if all available cats are claimed 23 | uint public catsRemainingToAssign = 0; // variable to track cats remaining to be assigned/claimed 24 | uint public currentReleaseCeiling; // variable to track maximum cat index for latest release 25 | 26 | /* Create array to store cat index to owner address */ 27 | mapping (uint => address) public catIndexToAddress; 28 | 29 | /* Create an array with all balances */ 30 | mapping (address => uint) public balanceOf; 31 | 32 | /* Initializes contract with initial supply tokens to the creator of the contract */ 33 | function PreviousCryptoCatsContract() payable { 34 | owner = msg.sender; // Set contract creation sender as owner 35 | } 36 | 37 | /* Returns count of how many cats are owned by an owner */ 38 | function balanceOf(address _owner) constant returns (uint256 balance) { 39 | require(balanceOf[_owner] != 0); // requires that cat owner balance is not 0 40 | return balanceOf[_owner]; // return number of cats owned from array of balances by owner address 41 | } 42 | 43 | /* Return total supply of cats existing */ 44 | function totalSupply() constant returns (uint256 totalSupply) { 45 | return _totalSupply; 46 | } 47 | 48 | /* Get address of owner based on cat index */ 49 | function getCatOwner(uint256 catIndex) public returns (address) { 50 | require(catIndexToAddress[catIndex] != 0x0); 51 | return catIndexToAddress[catIndex]; // Return address at array position of cat index 52 | } 53 | 54 | /* Get address of contract owner who performed contract creation and initialisation */ 55 | function getContractOwner() public returns (address) { 56 | return owner; // Return address of contract owner 57 | } 58 | } -------------------------------------------------------------------------------- /cryptokitties/SaleClockAuction.sol: -------------------------------------------------------------------------------- 1 | /// @title Clock auction modified for sale of kitties 2 | /// @notice We omit a fallback function to prevent accidental sends to this contract. 3 | 4 | contract SaleClockAuction is ClockAuction { 5 | 6 | // @dev Sanity check that allows us to ensure that we are pointing to the 7 | // right auction in our setSaleAuctionAddress() call. 8 | bool public isSaleClockAuction = true; 9 | 10 | // Tracks last 5 sale price of gen0 kitty sales 11 | uint256 public gen0SaleCount; 12 | uint256[5] public lastGen0SalePrices; 13 | 14 | // Delegate constructor 15 | function SaleClockAuction(address _nftAddr, uint256 _cut) public 16 | ClockAuction(_nftAddr, _cut) {} 17 | 18 | /// @dev Creates and begins a new auction. 19 | /// @param _tokenId - ID of token to auction, sender must be owner. 20 | /// @param _startingPrice - Price of item (in wei) at beginning of auction. 21 | /// @param _endingPrice - Price of item (in wei) at end of auction. 22 | /// @param _duration - Length of auction (in seconds). 23 | /// @param _seller - Seller, if not the message sender 24 | function createAuction( 25 | uint256 _tokenId, 26 | uint256 _startingPrice, 27 | uint256 _endingPrice, 28 | uint256 _duration, 29 | address _seller 30 | ) 31 | external 32 | { 33 | // Sanity check that no inputs overflow how many bits we've allocated 34 | // to store them in the auction struct. 35 | require(_startingPrice == uint256(uint128(_startingPrice))); 36 | require(_endingPrice == uint256(uint128(_endingPrice))); 37 | require(_duration == uint256(uint64(_duration))); 38 | 39 | require(msg.sender == address(nonFungibleContract)); 40 | _escrow(_seller, _tokenId); 41 | Auction memory auction = Auction( 42 | _seller, 43 | uint128(_startingPrice), 44 | uint128(_endingPrice), 45 | uint64(_duration), 46 | uint64(now) 47 | ); 48 | _addAuction(_tokenId, auction); 49 | } 50 | 51 | /// @dev Updates lastSalePrice if seller is the nft contract 52 | /// Otherwise, works the same as default bid method. 53 | function bid(uint256 _tokenId) 54 | external 55 | payable 56 | { 57 | // _bid verifies token ID size 58 | address seller = tokenIdToAuction[_tokenId].seller; 59 | uint256 price = _bid(_tokenId, msg.value); 60 | _transfer(msg.sender, _tokenId); 61 | 62 | // If not a gen0 auction, exit 63 | if (seller == address(nonFungibleContract)) { 64 | // Track gen0 sale prices 65 | lastGen0SalePrices[gen0SaleCount % 5] = price; 66 | gen0SaleCount++; 67 | } 68 | } 69 | 70 | function averageGen0SalePrice() external view returns (uint256) { 71 | uint256 sum = 0; 72 | for (uint256 i = 0; i < 5; i++) { 73 | sum += lastGen0SalePrices[i]; 74 | } 75 | return sum / 5; 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /doomcats/IERC20.sol: -------------------------------------------------------------------------------- 1 | // File @openzeppelin/contracts/token/ERC20/IERC20.sol@v4.0.0 2 | 3 | // SPDX-License-Identifier: MIT 4 | 5 | pragma solidity ^0.8.0; 6 | 7 | /** 8 | * @dev Interface of the ERC20 standard as defined in the EIP. 9 | */ 10 | interface IERC20 { 11 | /** 12 | * @dev Returns the amount of tokens in existence. 13 | */ 14 | function totalSupply() external view returns (uint256); 15 | 16 | /** 17 | * @dev Returns the amount of tokens owned by `account`. 18 | */ 19 | function balanceOf(address account) external view returns (uint256); 20 | 21 | /** 22 | * @dev Moves `amount` tokens from the caller's account to `recipient`. 23 | * 24 | * Returns a boolean value indicating whether the operation succeeded. 25 | * 26 | * Emits a {Transfer} event. 27 | */ 28 | function transfer(address recipient, uint256 amount) external returns (bool); 29 | 30 | /** 31 | * @dev Returns the remaining number of tokens that `spender` will be 32 | * allowed to spend on behalf of `owner` through {transferFrom}. This is 33 | * zero by default. 34 | * 35 | * This value changes when {approve} or {transferFrom} are called. 36 | */ 37 | function allowance(address owner, address spender) external view returns (uint256); 38 | 39 | /** 40 | * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. 41 | * 42 | * Returns a boolean value indicating whether the operation succeeded. 43 | * 44 | * IMPORTANT: Beware that changing an allowance with this method brings the risk 45 | * that someone may use both the old and the new allowance by unfortunate 46 | * transaction ordering. One possible solution to mitigate this race 47 | * condition is to first reduce the spender's allowance to 0 and set the 48 | * desired value afterwards: 49 | * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 50 | * 51 | * Emits an {Approval} event. 52 | */ 53 | function approve(address spender, uint256 amount) external returns (bool); 54 | 55 | /** 56 | * @dev Moves `amount` tokens from `sender` to `recipient` using the 57 | * allowance mechanism. `amount` is then deducted from the caller's 58 | * allowance. 59 | * 60 | * Returns a boolean value indicating whether the operation succeeded. 61 | * 62 | * Emits a {Transfer} event. 63 | */ 64 | function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); 65 | 66 | /** 67 | * @dev Emitted when `value` tokens are moved from one account (`from`) to 68 | * another (`to`). 69 | * 70 | * Note that `value` may be zero. 71 | */ 72 | event Transfer(address indexed from, address indexed to, uint256 value); 73 | 74 | /** 75 | * @dev Emitted when the allowance of a `spender` for an `owner` is set by 76 | * a call to {approve}. `value` is the new allowance. 77 | */ 78 | event Approval(address indexed owner, address indexed spender, uint256 value); 79 | } 80 | 81 | -------------------------------------------------------------------------------- /lasercats/LaserCats.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^ 0.8.0; 4 | 5 | import "./SafeMath.sol"; 6 | import "./Context.sol"; 7 | import "./Ownable.sol"; 8 | import "./Strings.sol"; 9 | import "./Address.sol"; 10 | import "./IERC165.sol"; 11 | import "./ERC165.sol"; 12 | import "./IERC721.sol"; 13 | import "./IERC721Enumerable.sol"; 14 | import "./IERC721Metadata.sol"; 15 | import "./IERC721Receiver.sol"; 16 | 17 | 18 | 19 | contract LaserCats is ERC721Enumerable, Ownable { 20 | using SafeMath for uint256; 21 | uint public constant maxTokenSupply = 25440; 22 | uint public presalePriceCap; 23 | uint public startPrice; 24 | uint public priceFactor; 25 | uint public maxTxQty; 26 | bool public mintingAllowed; 27 | 28 | constructor() ERC721("LaserCats", "LaserCats") { } 29 | 30 | function getTokensOfOwner(address _owner) external view returns(uint256[] memory) { 31 | uint256 tokenCount = balanceOf(_owner); 32 | if (tokenCount == 0) { 33 | return new uint256[](0); 34 | } else { 35 | uint256[] memory result = new uint256[](tokenCount); 36 | uint256 index; 37 | for (index = 0; index < tokenCount; index++) { 38 | result[index] = tokenOfOwnerByIndex(_owner, index); 39 | } 40 | return result; 41 | } 42 | } 43 | 44 | function getPresaleQty() public view returns(uint256) { 45 | require(mintingAllowed == true, "Minting not allowed yet."); 46 | require(totalSupply() < maxTokenSupply, "All tokens have been minted."); 47 | return maxTxQty; 48 | } 49 | 50 | function getPresalePrice() public view returns(uint256) { 51 | require(mintingAllowed == true, "Minting not allowed yet."); 52 | require(totalSupply() < maxTokenSupply, "All tokens have been minted."); 53 | return startPrice.mul(10 ** 16) + totalSupply().div(100).mul(priceFactor); 54 | } 55 | 56 | function mintToken(uint256 qty) public payable { 57 | require(qty > 0 && qty <= getPresaleQty(), "Quantity exceeds allowed."); 58 | require(totalSupply().add(qty) <= maxTokenSupply, "Quantity exceeds max supply."); 59 | require(msg.value >= getPresalePrice().mul(qty), "Ether value to send is insufficient."); 60 | 61 | for (uint i = 0; i < qty; i++) { 62 | uint mintIndex = totalSupply(); 63 | _safeMint(msg.sender, mintIndex); 64 | } 65 | } 66 | 67 | // reserves tokens 0-99 for giveaways 68 | function mintPromoToken(uint256 qty) public onlyOwner { 69 | require(totalSupply().add(qty) <= 100, "Quantity exceeds allowed."); 70 | 71 | for (uint i = 0; i < qty; i++) { 72 | uint mintIndex = totalSupply(); 73 | _safeMint(msg.sender, mintIndex); 74 | } 75 | } 76 | 77 | function setPresaleAmounts(uint start, uint cap, uint qty) public onlyOwner { 78 | startPrice = start; 79 | presalePriceCap = cap; 80 | maxTxQty = qty; 81 | priceFactor = ((cap - start) * (10 ** 5) / (maxTokenSupply.div(100))) * (10 ** 11); 82 | } 83 | 84 | function setBaseURI(string memory baseURI) public onlyOwner { 85 | _setBaseURI(baseURI); 86 | } 87 | 88 | function beginPresale() public onlyOwner { 89 | mintingAllowed = true; 90 | } 91 | 92 | function pausePresale() public onlyOwner { 93 | mintingAllowed = false; 94 | } 95 | 96 | function withdraw() public payable onlyOwner { 97 | require(payable(msg.sender).send(address(this).balance)); 98 | } 99 | } -------------------------------------------------------------------------------- /mooncats-vote/MoonCatKeyVote.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * copied from https://etherscan.io/address/0x1916F482BB9F3523a489791Ae3d6e052b362C777#code 3 | * 4 | * Submitted for verification at Etherscan.io on 2021-03-19 5 | */ 6 | 7 | // SPDX-License-Identifier: MIT 8 | 9 | pragma solidity ^0.8.0; 10 | 11 | contract MoonCatKeyVote { 12 | 13 | // Should the MoonCatRescue developers destroy their private key so that no future Genesis MoonCats can ever be released? 14 | // true = Yes 15 | // false = No 16 | 17 | event VoteSubmitted(address voter, bool vote); 18 | 19 | uint public voteStartTime = 0; 20 | bool public voteCancelled = false; 21 | mapping (address => bool) public hasVoted; 22 | uint32 public yesVotes = 0; 23 | uint32 public noVotes = 0; 24 | 25 | //bytes32 public immutable voterRollSha256; 26 | bytes32 public immutable merkleRoot; 27 | address public immutable owner; 28 | 29 | modifier onlyOwner { 30 | require(msg.sender == owner, "Owner Only"); 31 | _; 32 | } 33 | 34 | modifier voteContractIsPending { 35 | require(!voteCancelled, "Vote Contract Cancelled"); 36 | require(voteStartTime == 0, "Vote Already Started"); 37 | _; 38 | } 39 | 40 | modifier voteContractIsActive { 41 | require(!voteCancelled, "Vote Contract Cancelled"); 42 | require(voteStartTime > 0, "Vote Not Started"); 43 | require(block.timestamp < (voteStartTime + 48 hours), "Vote Ended"); 44 | _; 45 | } 46 | 47 | modifier voteContractIsComplete { 48 | require(!voteCancelled, "Vote Contract Cancelled"); 49 | require(voteStartTime > 0, "Vote Not Started"); 50 | require(block.timestamp > (voteStartTime + 48 hours), "Vote Not Ended"); 51 | _; 52 | } 53 | 54 | constructor(bytes32 merkleRoot_) { 55 | merkleRoot = merkleRoot_; 56 | owner = msg.sender; 57 | } 58 | 59 | function startVote() public onlyOwner voteContractIsPending { 60 | voteStartTime = block.timestamp; 61 | } 62 | 63 | function cancelVote() public onlyOwner voteContractIsPending { 64 | voteCancelled = true; 65 | } 66 | 67 | function getResult() public view voteContractIsComplete returns (bool) { 68 | return (yesVotes > noVotes); 69 | } 70 | 71 | uint24 empty = 0; 72 | 73 | function submitVote(bytes32[] calldata eligibilityProof, bool vote) public voteContractIsActive { 74 | require(!hasVoted[msg.sender], "Duplicate Vote"); 75 | 76 | // https://github.com/miguelmota/merkletreejs-solidity/blob/master/contracts/MerkleProof.sol 77 | bytes32 computedHash = keccak256(abi.encodePacked(msg.sender)); 78 | for (uint256 i = 0; i < eligibilityProof.length; i++) { 79 | bytes32 proofElement = eligibilityProof[i]; 80 | 81 | if (computedHash < proofElement) { 82 | computedHash = keccak256(abi.encodePacked(computedHash, proofElement)); 83 | } else { 84 | computedHash = keccak256(abi.encodePacked(proofElement, computedHash)); 85 | } 86 | } 87 | 88 | require(computedHash == merkleRoot, "Ineligible Voter"); 89 | 90 | hasVoted[msg.sender] = true; 91 | 92 | if(vote){ 93 | yesVotes++; 94 | } else { 95 | noVotes++; 96 | } 97 | 98 | emit VoteSubmitted(msg.sender, vote); 99 | 100 | } 101 | } -------------------------------------------------------------------------------- /mooncats-hd/MooncatsContract.sol: -------------------------------------------------------------------------------- 1 | interface MooncatsContract { 2 | 3 | // Events 4 | 5 | event CatRescued(address indexed to, bytes5 indexed catId); 6 | event CatNamed(bytes5 indexed catId, bytes32 catName); 7 | event Transfer(address indexed from, address indexed to, uint256 value); 8 | event CatAdopted(bytes5 indexed catId, uint price, address indexed from, address indexed to); 9 | event AdoptionOffered(bytes5 indexed catId, uint price, address indexed toAddress); 10 | event AdoptionOfferCancelled(bytes5 indexed catId); 11 | event AdoptionRequested(bytes5 indexed catId, uint price, address indexed from); 12 | event AdoptionRequestCancelled(bytes5 indexed catId); 13 | event GenesisCatsAdded(bytes5[16] catIds); 14 | 15 | // Read contract 16 | 17 | function name() external view returns (string memory); 18 | 19 | function remainingGenesisCats() external view returns (uint16); 20 | 21 | function totalSupply() external view returns (uint16); 22 | 23 | function mode() external view returns (uint8); 24 | 25 | function getCatDetails(bytes5) external view returns (bytes5 id, address owner, bytes32 catName, address onlyOfferTo, uint256 offerPrice, address requester, uint256 requestPrice); 26 | 27 | function decimals() external view returns (uint8); 28 | 29 | function getCatOwners() external view returns (address[] memory); 30 | 31 | function catOwners(bytes5 catId) external view returns (address); 32 | 33 | function rescueOrder(uint256 order) external view returns (bytes5 catId); 34 | 35 | function getCatIds() external view returns (bytes5[] memory); 36 | 37 | function balanceOf(address) external view returns (uint256); 38 | 39 | function getCatNames() external view returns (bytes32[] memory); 40 | 41 | function adoptionOffers(bytes5) external view returns (bool exists, bytes5 catId, address seller, uint256 price, address onlyOfferTo); 42 | 43 | function catNames(bytes5 catId) external view returns (bytes32); 44 | 45 | function symbol() external view returns (string memory); 46 | 47 | function getCatRequestPrices() external view returns (uint256[] memory); 48 | 49 | function searchSeed() external view returns (bytes32); 50 | 51 | function imageGenerationCodeMD5() external view returns (bytes16); 52 | 53 | function adoptionRequests(bytes5) external view returns (bool exists, bytes5 catId, address requester, uint256 price); 54 | 55 | function getCatOfferPrices() external view returns (uint256[] memory); 56 | 57 | function rescueIndex() external view returns (uint16); 58 | 59 | function pendingWithdrawals(address) external view returns (uint256); 60 | 61 | // Write contract 62 | 63 | function makeAdoptionOffer(bytes5 catId, uint256 price) external; 64 | 65 | function activate() external; 66 | 67 | function acceptAdoptionOffer(bytes5 catId) external payable; 68 | 69 | function withdraw() external; 70 | 71 | function rescueCat(bytes32 seed) external; 72 | 73 | function cancelAdoptionOffer(bytes5 catId) external; 74 | 75 | function nameCat(bytes5 catId, bytes32 catName) external; 76 | 77 | function activateInTestMode() external; 78 | 79 | function cancelAdoptionRequest(bytes5 catId) external; 80 | 81 | function disableBeforeActivation() external; 82 | 83 | function addGenesisCatGroup() external; 84 | 85 | function makeAdoptionOfferToAddress(bytes5 catId, uint256 price, address to) external; 86 | 87 | function acceptAdoptionRequest(bytes5 catId) external payable; 88 | 89 | function giveCat(bytes5 catId, address to) external; 90 | 91 | } 92 | -------------------------------------------------------------------------------- /mooncats-hd/HDMooncats.sol: -------------------------------------------------------------------------------- 1 | // File: contracts/HDMooncats.sol 2 | 3 | // SPDX-License-Identifier: GPL-3.0 4 | 5 | pragma solidity ^0.8.0; 6 | 7 | 8 | contract HDMooncats is Ownable, ERC721 { 9 | 10 | // MD5 hash of the megaimage (80k x 80k pixels) containing 25440 cats 11 | string public imageHash = "6d834cc1d92d2e05656da65819749732"; 12 | 13 | address payable public mooncatsAddress = payable(0x60cd862c9C687A9dE49aecdC3A99b74A4fc54aB6); 14 | address public wrapperAddress = payable(0x7C40c393DC0f283F318791d746d894DdD3693572); 15 | string public _baseTokenURI; 16 | 17 | uint public minted = 0; 18 | 19 | address payable public splitter; 20 | address payable public ercRecipient; 21 | 22 | event Mint(address indexed owner, uint indexed _rescueOrder); 23 | 24 | constructor(address _feeSplitter, address _ercRecipient) payable ERC721("HD Mooncats", "HDMC") { 25 | splitter = payable(_feeSplitter); 26 | ercRecipient = payable(_ercRecipient); 27 | } 28 | 29 | /** 30 | * @dev Mint an HD Mooncat. The HDMC will be given to the user currently holding the OG mooncat. 31 | */ 32 | function mint(uint _rescueOrder) public payable { 33 | // Take mint fee 34 | require(msg.value >= mintFee(), "Please include mint fee"); 35 | 36 | // Check if token already exists 37 | require(!_exists(_rescueOrder), "Token already minted"); 38 | 39 | bytes5 catId = MooncatsContract(mooncatsAddress).rescueOrder(_rescueOrder); 40 | address owner = MooncatsContract(mooncatsAddress).catOwners(catId); 41 | if (owner == wrapperAddress) { 42 | uint tokenId = WrapperContract(wrapperAddress)._catIDToTokenID(catId); 43 | owner = WrapperContract(wrapperAddress).ownerOf(tokenId); 44 | } 45 | 46 | _mint(owner, _rescueOrder); 47 | minted += 1; 48 | Mint(owner, _rescueOrder); 49 | } 50 | 51 | /** 52 | * @dev Returns the current minting fee 53 | */ 54 | function mintFee() public view returns (uint) { 55 | if (minted <= 999) { 56 | return 0.01 ether; 57 | } else if (minted <= 4999) { 58 | return 0.05 ether; 59 | } else if (minted <= 14999) { 60 | return 0.10 ether; 61 | } else { 62 | return 0.20 ether; 63 | } 64 | } 65 | 66 | /** 67 | * @dev Withdraw the contract balance to the dev address 68 | */ 69 | function withdraw() public { 70 | uint amount = address(this).balance; 71 | (bool success,) = splitter.call{value: amount}(""); 72 | require(success, "Failed to send ether"); 73 | } 74 | 75 | /** 76 | * @dev Withdraw ERC20 tokens from the contract 77 | */ 78 | function withdrawFungible(address _tokenContract) public { 79 | ForeignToken token = ForeignToken(_tokenContract); 80 | uint256 amount = token.balanceOf(address(this)); 81 | token.transfer(ercRecipient, amount); 82 | } 83 | 84 | /** 85 | * @dev Withdraw ERC721 tokens from the contract 86 | */ 87 | function withdrawNonFungible(address _tokenContract, uint256 _tokenId) public { 88 | ForeignNFT(_tokenContract).transferFrom(address(this), ercRecipient, _tokenId); 89 | } 90 | 91 | /** 92 | * @dev Returns a URI for a given token ID's metadata 93 | */ 94 | function tokenURI(uint256 _tokenId) public view override returns (string memory) { 95 | return string(abi.encodePacked(_baseTokenURI, Strings.toString(_tokenId))); 96 | } 97 | 98 | function setBaseTokenURI(string memory __baseTokenURI) public onlyOwner { 99 | _baseTokenURI = __baseTokenURI; 100 | } 101 | 102 | } 103 | 104 | -------------------------------------------------------------------------------- /doomcats/DoomCat.sol: -------------------------------------------------------------------------------- 1 | // File contracts/DoomCat.sol 2 | 3 | 4 | 5 | pragma solidity ^0.8.0; 6 | 7 | 8 | 9 | /** 10 | * @dev we like the cats 11 | */ 12 | contract DoomCat is IDoomCat, DoomCatRescue, DoomCatAuction, ERC721OnOpenSea { 13 | string private __baseURI; 14 | 15 | // there's an owner, but they can only update the BaseURI 16 | address public owner; 17 | 18 | // track the cat names here 19 | mapping(uint256 => string) public catNames; 20 | 21 | // how much does a name change cost 22 | uint256 public nameChangePrice; 23 | 24 | // reference to the token (HATE) that all funds will be swapped into 25 | address public immutable HATE; 26 | 27 | // reference to the address where all swapped HATE will be burned to 28 | address public immutable burn; 29 | 30 | // uniswap router address 31 | IUniswapV2Router02Minimal public immutable uniswapV2Router; 32 | 33 | // events for public functions 34 | event NameCat(address indexed account, uint256 catId, string name); 35 | event UpdateBaseURI(string baseURI); 36 | event RevokeOwner(); 37 | 38 | constructor( 39 | address[4] memory addresses, 40 | string memory baseURI_, 41 | uint32 normalCats_, 42 | uint256[5] memory rescueDetails_, 43 | uint64[6] memory auctionsDetails_, 44 | uint256 nameChangePrice_ 45 | ) 46 | ERC721OnOpenSea("DoomCatRescue", "DOOM", addresses[3]) 47 | DoomCatRescue( 48 | IDoomCat(address(this)), 49 | [ 50 | uint256( 51 | auctionsDetails_[3] * auctionsDetails_[4] + normalCats_ 52 | ), 53 | normalCats_ 54 | ], 55 | rescueDetails_ 56 | ) 57 | DoomCatAuction(IDoomCat(address(this)), auctionsDetails_) 58 | { 59 | HATE = addresses[0]; 60 | uniswapV2Router = IUniswapV2Router02Minimal(addresses[1]); 61 | burn = addresses[2]; 62 | __baseURI = baseURI_; 63 | owner = msg.sender; 64 | nameChangePrice = nameChangePrice_; 65 | } 66 | 67 | /** 68 | * @dev override OZ ERC721 _baseURI() function 69 | */ 70 | function _baseURI() internal view virtual override returns (string memory) { 71 | return __baseURI; 72 | } 73 | 74 | /** 75 | * @dev we want to be able to update this later, to fully decentralize it 76 | */ 77 | function updateBaseURI(string calldata baseURI) public { 78 | require(msg.sender == owner, "not owner"); 79 | __baseURI = baseURI; 80 | emit UpdateBaseURI(baseURI); 81 | } 82 | 83 | /** 84 | * @dev after getting baseURI into it's final form, revoke ownership 85 | */ 86 | function revokeOwner() public { 87 | require(msg.sender == owner, "not owner"); 88 | owner = address(0); 89 | emit RevokeOwner(); 90 | } 91 | 92 | /** 93 | * @dev mint a new token to recipient with specified id, but only from current contract 94 | */ 95 | function mint(address to_, uint256 tokenId_) public override { 96 | require(msg.sender == address(this), "can't mint"); 97 | _mint(to_, tokenId_); 98 | } 99 | 100 | /** 101 | * @dev given an amount of Ether, swap all for HATE and send to burn address 102 | */ 103 | function swapAndBurn(uint256 _amount) public override { 104 | require(msg.sender == address(this), "can't swap and burn"); 105 | 106 | address[] memory path = new address[](2); 107 | path[0] = uniswapV2Router.WETH(); 108 | path[1] = HATE; 109 | 110 | uniswapV2Router.swapExactETHForTokensSupportingFeeOnTransferTokens{ 111 | value: _amount 112 | }(0, path, burn, block.timestamp); 113 | } 114 | 115 | /** 116 | * @dev owner of a cat can name a cat, once 117 | */ 118 | function nameCat(uint256 catId, string calldata catName) external { 119 | require(ownerOf(catId) == msg.sender, "not your cat"); 120 | 121 | // can only name a cat if it's not already named 122 | bytes memory currentName = bytes(catNames[catId]); 123 | require(currentName.length == 0, "already named"); 124 | 125 | catNames[catId] = catName; 126 | IERC20(HATE).transferFrom(msg.sender, burn, nameChangePrice); 127 | 128 | emit NameCat(msg.sender, catId, catName); 129 | } 130 | } 131 | 132 | -------------------------------------------------------------------------------- /cryptokitties/KittyAccessControl.sol: -------------------------------------------------------------------------------- 1 | /// @title A facet of KittyCore that manages special access privileges. 2 | /// @author Axiom Zen (https://www.axiomzen.co) 3 | /// @dev See the KittyCore contract documentation to understand how the various contract facets are arranged. 4 | 5 | contract KittyAccessControl { 6 | // This facet controls access control for CryptoKitties. There are four roles managed here: 7 | // 8 | // - The CEO: The CEO can reassign other roles and change the addresses of our dependent smart 9 | // contracts. It is also the only role that can unpause the smart contract. It is initially 10 | // set to the address that created the smart contract in the KittyCore constructor. 11 | // 12 | // - The CFO: The CFO can withdraw funds from KittyCore and its auction contracts. 13 | // 14 | // - The COO: The COO can release gen0 kitties to auction, and mint promo cats. 15 | // 16 | // It should be noted that these roles are distinct without overlap in their access abilities, the 17 | // abilities listed for each role above are exhaustive. In particular, while the CEO can assign any 18 | // address to any role, the CEO address itself doesn't have the ability to act in those roles. This 19 | // restriction is intentional so that we aren't tempted to use the CEO address frequently out of 20 | // convenience. The less we use an address, the less likely it is that we somehow compromise the 21 | // account. 22 | 23 | /// @dev Emited when contract is upgraded - See README.md for updgrade plan 24 | event ContractUpgrade(address newContract); 25 | 26 | // The addresses of the accounts (or contracts) that can execute actions within each roles. 27 | address public ceoAddress; 28 | address public cfoAddress; 29 | address public cooAddress; 30 | 31 | // @dev Keeps track whether the contract is paused. When that is true, most actions are blocked 32 | bool public paused = false; 33 | 34 | /// @dev Access modifier for CEO-only functionality 35 | modifier onlyCEO() { 36 | require(msg.sender == ceoAddress); 37 | _; 38 | } 39 | 40 | /// @dev Access modifier for CFO-only functionality 41 | modifier onlyCFO() { 42 | require(msg.sender == cfoAddress); 43 | _; 44 | } 45 | 46 | /// @dev Access modifier for COO-only functionality 47 | modifier onlyCOO() { 48 | require(msg.sender == cooAddress); 49 | _; 50 | } 51 | 52 | modifier onlyCLevel() { 53 | require( 54 | msg.sender == cooAddress || 55 | msg.sender == ceoAddress || 56 | msg.sender == cfoAddress 57 | ); 58 | _; 59 | } 60 | 61 | /// @dev Assigns a new address to act as the CEO. Only available to the current CEO. 62 | /// @param _newCEO The address of the new CEO 63 | function setCEO(address _newCEO) external onlyCEO { 64 | require(_newCEO != address(0)); 65 | 66 | ceoAddress = _newCEO; 67 | } 68 | 69 | /// @dev Assigns a new address to act as the CFO. Only available to the current CEO. 70 | /// @param _newCFO The address of the new CFO 71 | function setCFO(address _newCFO) external onlyCEO { 72 | require(_newCFO != address(0)); 73 | 74 | cfoAddress = _newCFO; 75 | } 76 | 77 | /// @dev Assigns a new address to act as the COO. Only available to the current CEO. 78 | /// @param _newCOO The address of the new COO 79 | function setCOO(address _newCOO) external onlyCEO { 80 | require(_newCOO != address(0)); 81 | 82 | cooAddress = _newCOO; 83 | } 84 | 85 | /*** Pausable functionality adapted from OpenZeppelin ***/ 86 | 87 | /// @dev Modifier to allow actions only when the contract IS NOT paused 88 | modifier whenNotPaused() { 89 | require(!paused); 90 | _; 91 | } 92 | 93 | /// @dev Modifier to allow actions only when the contract IS paused 94 | modifier whenPaused { 95 | require(paused); 96 | _; 97 | } 98 | 99 | /// @dev Called by any "C-level" role to pause the contract. Used only when 100 | /// a bug or exploit is detected and we need to limit damage. 101 | function pause() external onlyCLevel whenNotPaused { 102 | paused = true; 103 | } 104 | 105 | /// @dev Unpauses the smart contract. Can only be called by the CEO, since 106 | /// one reason we may pause the contract is when CFO or COO accounts are 107 | /// compromised. 108 | /// @notice This is public rather than external so it can be called by 109 | /// derived contracts. 110 | function unpause() public onlyCEO whenPaused { 111 | // can't unpause if contract was upgraded 112 | paused = false; 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /cryptokitties/CHEATSHEET.md: -------------------------------------------------------------------------------- 1 | # CryptoKitties Contracts Cheatsheet / Quickref 2 | 3 | 4 | 5 | ## KittyCore Contract: [0x06012c8cf97BEaD5deAe237070F9587f8E7A266d](https://etherscan.io/address/0x06012c8cf97bead5deae237070f9587f8e7a266d#code) 6 | 7 | ### Dependencies/External Calls 8 | 9 | - `saleAuction()`: address of sales-auction contract aka "0xb1690C08E213a35Ed9bAb7B318DE14420FB57d8C" 10 | - `siringAuction()`: address of siring-auction contract aka "0xC7af99Fe5513eB6710e6D5f44F9989dA40F27F26" 11 | - `geneScience()`: address of gene-science contract aka "0xf97e0A5b616dfFC913e72455Fde9eA8bBe946a2B" 12 | 13 | ### Calls/Reads 14 | 15 | - `autoBirthFee()`: variable storing birth fee 16 | - `pregnantKitties()`: number of kitties currently pregnant 17 | - `totalSupply()`: total number of kittens created so far 18 | - `gen0CreatedCount()`: returns number of generation 0 cats created so far 19 | - `balanceOf(address)`: number of kittens owned by some address 20 | - `tokensOfOwner(address)`: returns array of kittyIDs owned by some address 21 | - `isPregnant(uint256)`: true if the given kittyID is pregnant 22 | - `isReadyToBreed(uint256)`: true if kittyID can breed 23 | - `canBreedWith(uint256,uint256)`: true if two kittyIDs can breed together 24 | - `ownerOf(uint256)`: returns address that owns some kittyID 25 | - `getKitty(uint256)`: returns [isPregnant [bool], isReady [bool], coolDownIndex [uint256], nextActionTime [uint256], 26 | SiringWith [uint256], birthTime [uint256], matronID [uint256], sireID [uint256], generation [uint256], genes [uint256]] 27 | 28 | ### Methods/Transactions/Writes 29 | 30 | - `createSaleAuction(kittyID [uint256], startingPrice [uint256], endPrice [uint256], duration [uint256])`: Put kittyID up for sale 31 | - `createSiringAuction(kittyID [uint256], startingPrice [uint256], endPrice [uint256], duration [uint256])`: Put kittyID up for sire 32 | - `breedWithAuto(kittyID [uint256], kittyID [uint256])`: Breed two kittyIDs that you own 33 | - `giveBirth(kittyID [uint256])`: Handler for pregnant kittyID who is ready to deliver 34 | - `transfer(recipient [address], kittyID [uint256])`: give some recipient address one of the kittyIDs you own 35 | - `bidOnSiringAuction(sireID [uint256], matronID [uint256])`: ends some siring auction for sireID by bidding & breeding w our matronID 36 | 37 | ### Events 38 | - `Transfer(from [address], to [address], kittyID [uint256])` 39 | - `Approval(owner [address], approved [address], kittyID [uint256])` 40 | - `Birth(owner [address], kittyID [uint256], matronID [uint256], sireID [uint256], genes [uint256])` 41 | - `Pregnant(owner [address], matronID [uint256], sireID [uint256], cooldownEndBlock [uint256])` 42 | 43 | ### Storage aka `eth.getStorageAt(core.address, i)` where `i =` 44 | 45 | 0. ceoAddress: `0x000000000000000000000000af1e54b359b0897133f437fc961dd16f20c045e1` 46 | 1. cfoAddress: `0x0000000000000000000000002041bb7d8b49f0bde3aa1fa7fb506ac6c539394c` 47 | 2. cooAddress: `0x000000000000000000000000a1e12defa6dbc8e900a6596083322946c03f01e3` 48 | 3. first half of cooldowns array: `0x0000384000001c2000000e1000000708000002580000012c000000780000003c` 49 | 4. second half of cooldowns array: `0x000000000000000000093a80000546000002a300000151800000e10000007080` 50 | 5. seconds per block: `0x000000000000000000000000000000000000000000000000000000000000000f` 51 | 6. kitties: length eg `0x00000000000000000000000000000000000000000000000000000000000682cb` 52 | 7. kittyIndexToOwner 53 | 8. ownershipTokenCount 54 | 9. ownershipTokenCount 55 | 10. sireAllowedToAddress 56 | 11. saleAuction(?): `0x000000000000000000000000b1690c08e213a35ed9bab7b318de14420fb57d8c` 57 | 12. sireAuction(?): `0x000000000000000000000000c7af99fe5513eb6710e6d5f44f9989da40f27f26` 58 | 13. ??? 59 | 60 | (Above labels are according to order of declared variables in kitty core contract source code) 61 | 62 | 63 | ## KittySales Contract: [0xb1690C08E213a35Ed9bAb7B318DE14420FB57d8C](https://etherscan.io/address/0xb1690C08E213a35Ed9bAb7B318DE14420FB57d8C#code) 64 | 65 | ### Calls/Reads 66 | - `getAuction(kittyID [uint256])`: returns [seller [address], startPrice [uint256], endPrice [uint256], duration [uint256], startTime [uint256]] 67 | 68 | ### Events 69 | - `AuctionCreated(kittyID [uint256], startPrice [uint256], endPrice [uint256], duration [uint256])` 70 | - `AuctionSuccessful(kittyID [uint256], price [uint256], winner [address])` 71 | - `AuctionCancelled(kittyID [uint256])` 72 | 73 | 74 | ## KittySires Contract: [0xC7af99Fe5513eB6710e6D5f44F9989dA40F27F26](https://etherscan.io/address/0xC7af99Fe5513eB6710e6D5f44F9989dA40F27F26#code) 75 | 76 | ### Calls/Reads 77 | - `getAuction(kittyID [uint256])`: returns [seller [address], startPrice [uint256], endPrice [uint256], duration [uint256], startTime [uint256]] 78 | 79 | ### Events 80 | - `AuctionCreated(kittyID [uint256], startPrice [uint256], endPrice [uint256], duration [uint256])` 81 | - `AuctionSuccessful(kittyID [uint256], price [uint256], winner [address])` 82 | - `AuctionCancelled(kittyID [uint256])` 83 | 84 | 85 | 86 | References: 87 | 88 | [Cheat Sheet @ CryptoKitties Mill](https://github.com/bohendo/ck-mill#cryptokitties-smart-contract-developer-cheat-sheet) 89 | -------------------------------------------------------------------------------- /lasercats/IERC721.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "./IERC165.sol"; 6 | 7 | /** 8 | * @dev Required interface of an ERC721 compliant contract. 9 | */ 10 | interface IERC721 is IERC165 { 11 | /** 12 | * @dev Emitted when `tokenId` token is transferred from `from` to `to`. 13 | */ 14 | event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); 15 | 16 | /** 17 | * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. 18 | */ 19 | event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); 20 | 21 | /** 22 | * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. 23 | */ 24 | event ApprovalForAll(address indexed owner, address indexed operator, bool approved); 25 | 26 | /** 27 | * @dev Returns the number of tokens in ``owner``'s account. 28 | */ 29 | function balanceOf(address owner) external view returns (uint256 balance); 30 | 31 | /** 32 | * @dev Returns the owner of the `tokenId` token. 33 | * 34 | * Requirements: 35 | * 36 | * - `tokenId` must exist. 37 | */ 38 | function ownerOf(uint256 tokenId) external view returns (address owner); 39 | 40 | /** 41 | * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients 42 | * are aware of the ERC721 protocol to prevent tokens from being forever locked. 43 | * 44 | * Requirements: 45 | * 46 | * - `from` cannot be the zero address. 47 | * - `to` cannot be the zero address. 48 | * - `tokenId` token must exist and be owned by `from`. 49 | * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. 50 | * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. 51 | * 52 | * Emits a {Transfer} event. 53 | */ 54 | function safeTransferFrom(address from, address to, uint256 tokenId) external; 55 | 56 | /** 57 | * @dev Transfers `tokenId` token from `from` to `to`. 58 | * 59 | * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. 60 | * 61 | * Requirements: 62 | * 63 | * - `from` cannot be the zero address. 64 | * - `to` cannot be the zero address. 65 | * - `tokenId` token must be owned by `from`. 66 | * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. 67 | * 68 | * Emits a {Transfer} event. 69 | */ 70 | function transferFrom(address from, address to, uint256 tokenId) external; 71 | 72 | /** 73 | * @dev Gives permission to `to` to transfer `tokenId` token to another account. 74 | * The approval is cleared when the token is transferred. 75 | * 76 | * Only a single account can be approved at a time, so approving the zero address clears previous approvals. 77 | * 78 | * Requirements: 79 | * 80 | * - The caller must own the token or be an approved operator. 81 | * - `tokenId` must exist. 82 | * 83 | * Emits an {Approval} event. 84 | */ 85 | function approve(address to, uint256 tokenId) external; 86 | 87 | /** 88 | * @dev Returns the account approved for `tokenId` token. 89 | * 90 | * Requirements: 91 | * 92 | * - `tokenId` must exist. 93 | */ 94 | function getApproved(uint256 tokenId) external view returns (address operator); 95 | 96 | /** 97 | * @dev Approve or remove `operator` as an operator for the caller. 98 | * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. 99 | * 100 | * Requirements: 101 | * 102 | * - The `operator` cannot be the caller. 103 | * 104 | * Emits an {ApprovalForAll} event. 105 | */ 106 | function setApprovalForAll(address operator, bool _approved) external; 107 | 108 | /** 109 | * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. 110 | * 111 | * See {setApprovalForAll} 112 | */ 113 | function isApprovedForAll(address owner, address operator) external view returns (bool); 114 | 115 | /** 116 | * @dev Safely transfers `tokenId` token from `from` to `to`. 117 | * 118 | * Requirements: 119 | * 120 | * - `from` cannot be the zero address. 121 | * - `to` cannot be the zero address. 122 | * - `tokenId` token must exist and be owned by `from`. 123 | * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. 124 | * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. 125 | * 126 | * Emits a {Transfer} event. 127 | */ 128 | function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external; 129 | } -------------------------------------------------------------------------------- /mooncats-hd/IERC721.sol: -------------------------------------------------------------------------------- 1 | // File: @openzeppelin/contracts/token/ERC721/IERC721.sol 2 | 3 | 4 | 5 | pragma solidity ^0.8.0; 6 | 7 | 8 | /** 9 | * @dev Required interface of an ERC721 compliant contract. 10 | */ 11 | interface IERC721 is IERC165 { 12 | /** 13 | * @dev Emitted when `tokenId` token is transferred from `from` to `to`. 14 | */ 15 | event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); 16 | 17 | /** 18 | * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. 19 | */ 20 | event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); 21 | 22 | /** 23 | * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. 24 | */ 25 | event ApprovalForAll(address indexed owner, address indexed operator, bool approved); 26 | 27 | /** 28 | * @dev Returns the number of tokens in ``owner``'s account. 29 | */ 30 | function balanceOf(address owner) external view returns (uint256 balance); 31 | 32 | /** 33 | * @dev Returns the owner of the `tokenId` token. 34 | * 35 | * Requirements: 36 | * 37 | * - `tokenId` must exist. 38 | */ 39 | function ownerOf(uint256 tokenId) external view returns (address owner); 40 | 41 | /** 42 | * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients 43 | * are aware of the ERC721 protocol to prevent tokens from being forever locked. 44 | * 45 | * Requirements: 46 | * 47 | * - `from` cannot be the zero address. 48 | * - `to` cannot be the zero address. 49 | * - `tokenId` token must exist and be owned by `from`. 50 | * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. 51 | * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. 52 | * 53 | * Emits a {Transfer} event. 54 | */ 55 | function safeTransferFrom(address from, address to, uint256 tokenId) external; 56 | 57 | /** 58 | * @dev Transfers `tokenId` token from `from` to `to`. 59 | * 60 | * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. 61 | * 62 | * Requirements: 63 | * 64 | * - `from` cannot be the zero address. 65 | * - `to` cannot be the zero address. 66 | * - `tokenId` token must be owned by `from`. 67 | * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. 68 | * 69 | * Emits a {Transfer} event. 70 | */ 71 | function transferFrom(address from, address to, uint256 tokenId) external; 72 | 73 | /** 74 | * @dev Gives permission to `to` to transfer `tokenId` token to another account. 75 | * The approval is cleared when the token is transferred. 76 | * 77 | * Only a single account can be approved at a time, so approving the zero address clears previous approvals. 78 | * 79 | * Requirements: 80 | * 81 | * - The caller must own the token or be an approved operator. 82 | * - `tokenId` must exist. 83 | * 84 | * Emits an {Approval} event. 85 | */ 86 | function approve(address to, uint256 tokenId) external; 87 | 88 | /** 89 | * @dev Returns the account approved for `tokenId` token. 90 | * 91 | * Requirements: 92 | * 93 | * - `tokenId` must exist. 94 | */ 95 | function getApproved(uint256 tokenId) external view returns (address operator); 96 | 97 | /** 98 | * @dev Approve or remove `operator` as an operator for the caller. 99 | * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. 100 | * 101 | * Requirements: 102 | * 103 | * - The `operator` cannot be the caller. 104 | * 105 | * Emits an {ApprovalForAll} event. 106 | */ 107 | function setApprovalForAll(address operator, bool _approved) external; 108 | 109 | /** 110 | * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. 111 | * 112 | * See {setApprovalForAll} 113 | */ 114 | function isApprovedForAll(address owner, address operator) external view returns (bool); 115 | 116 | /** 117 | * @dev Safely transfers `tokenId` token from `from` to `to`. 118 | * 119 | * Requirements: 120 | * 121 | * - `from` cannot be the zero address. 122 | * - `to` cannot be the zero address. 123 | * - `tokenId` token must exist and be owned by `from`. 124 | * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. 125 | * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. 126 | * 127 | * Emits a {Transfer} event. 128 | */ 129 | function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external; 130 | } 131 | 132 | -------------------------------------------------------------------------------- /doomcats/IERC721.sol: -------------------------------------------------------------------------------- 1 | // File @openzeppelin/contracts/token/ERC721/IERC721.sol@v4.0.0 2 | 3 | 4 | 5 | pragma solidity ^0.8.0; 6 | 7 | /** 8 | * @dev Required interface of an ERC721 compliant contract. 9 | */ 10 | interface IERC721 is IERC165 { 11 | /** 12 | * @dev Emitted when `tokenId` token is transferred from `from` to `to`. 13 | */ 14 | event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); 15 | 16 | /** 17 | * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. 18 | */ 19 | event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); 20 | 21 | /** 22 | * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. 23 | */ 24 | event ApprovalForAll(address indexed owner, address indexed operator, bool approved); 25 | 26 | /** 27 | * @dev Returns the number of tokens in ``owner``'s account. 28 | */ 29 | function balanceOf(address owner) external view returns (uint256 balance); 30 | 31 | /** 32 | * @dev Returns the owner of the `tokenId` token. 33 | * 34 | * Requirements: 35 | * 36 | * - `tokenId` must exist. 37 | */ 38 | function ownerOf(uint256 tokenId) external view returns (address owner); 39 | 40 | /** 41 | * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients 42 | * are aware of the ERC721 protocol to prevent tokens from being forever locked. 43 | * 44 | * Requirements: 45 | * 46 | * - `from` cannot be the zero address. 47 | * - `to` cannot be the zero address. 48 | * - `tokenId` token must exist and be owned by `from`. 49 | * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. 50 | * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. 51 | * 52 | * Emits a {Transfer} event. 53 | */ 54 | function safeTransferFrom(address from, address to, uint256 tokenId) external; 55 | 56 | /** 57 | * @dev Transfers `tokenId` token from `from` to `to`. 58 | * 59 | * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. 60 | * 61 | * Requirements: 62 | * 63 | * - `from` cannot be the zero address. 64 | * - `to` cannot be the zero address. 65 | * - `tokenId` token must be owned by `from`. 66 | * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. 67 | * 68 | * Emits a {Transfer} event. 69 | */ 70 | function transferFrom(address from, address to, uint256 tokenId) external; 71 | 72 | /** 73 | * @dev Gives permission to `to` to transfer `tokenId` token to another account. 74 | * The approval is cleared when the token is transferred. 75 | * 76 | * Only a single account can be approved at a time, so approving the zero address clears previous approvals. 77 | * 78 | * Requirements: 79 | * 80 | * - The caller must own the token or be an approved operator. 81 | * - `tokenId` must exist. 82 | * 83 | * Emits an {Approval} event. 84 | */ 85 | function approve(address to, uint256 tokenId) external; 86 | 87 | /** 88 | * @dev Returns the account approved for `tokenId` token. 89 | * 90 | * Requirements: 91 | * 92 | * - `tokenId` must exist. 93 | */ 94 | function getApproved(uint256 tokenId) external view returns (address operator); 95 | 96 | /** 97 | * @dev Approve or remove `operator` as an operator for the caller. 98 | * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. 99 | * 100 | * Requirements: 101 | * 102 | * - The `operator` cannot be the caller. 103 | * 104 | * Emits an {ApprovalForAll} event. 105 | */ 106 | function setApprovalForAll(address operator, bool _approved) external; 107 | 108 | /** 109 | * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. 110 | * 111 | * See {setApprovalForAll} 112 | */ 113 | function isApprovedForAll(address owner, address operator) external view returns (bool); 114 | 115 | /** 116 | * @dev Safely transfers `tokenId` token from `from` to `to`. 117 | * 118 | * Requirements: 119 | * 120 | * - `from` cannot be the zero address. 121 | * - `to` cannot be the zero address. 122 | * - `tokenId` token must exist and be owned by `from`. 123 | * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. 124 | * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. 125 | * 126 | * Emits a {Transfer} event. 127 | */ 128 | function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external; 129 | } 130 | 131 | 132 | -------------------------------------------------------------------------------- /mooncats-acclimated/IERC721.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity >=0.6.2 <0.8.0; 4 | 5 | import "../../introspection/IERC165.sol"; 6 | 7 | /** 8 | * @dev Required interface of an ERC721 compliant contract. 9 | */ 10 | interface IERC721 is IERC165 { 11 | /** 12 | * @dev Emitted when `tokenId` token is transferred from `from` to `to`. 13 | */ 14 | event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); 15 | 16 | /** 17 | * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. 18 | */ 19 | event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); 20 | 21 | /** 22 | * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. 23 | */ 24 | event ApprovalForAll(address indexed owner, address indexed operator, bool approved); 25 | 26 | /** 27 | * @dev Returns the number of tokens in ``owner``'s account. 28 | */ 29 | function balanceOf(address owner) external view returns (uint256 balance); 30 | 31 | /** 32 | * @dev Returns the owner of the `tokenId` token. 33 | * 34 | * Requirements: 35 | * 36 | * - `tokenId` must exist. 37 | */ 38 | function ownerOf(uint256 tokenId) external view returns (address owner); 39 | 40 | /** 41 | * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients 42 | * are aware of the ERC721 protocol to prevent tokens from being forever locked. 43 | * 44 | * Requirements: 45 | * 46 | * - `from` cannot be the zero address. 47 | * - `to` cannot be the zero address. 48 | * - `tokenId` token must exist and be owned by `from`. 49 | * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. 50 | * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. 51 | * 52 | * Emits a {Transfer} event. 53 | */ 54 | function safeTransferFrom(address from, address to, uint256 tokenId) external; 55 | 56 | /** 57 | * @dev Transfers `tokenId` token from `from` to `to`. 58 | * 59 | * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. 60 | * 61 | * Requirements: 62 | * 63 | * - `from` cannot be the zero address. 64 | * - `to` cannot be the zero address. 65 | * - `tokenId` token must be owned by `from`. 66 | * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. 67 | * 68 | * Emits a {Transfer} event. 69 | */ 70 | function transferFrom(address from, address to, uint256 tokenId) external; 71 | 72 | /** 73 | * @dev Gives permission to `to` to transfer `tokenId` token to another account. 74 | * The approval is cleared when the token is transferred. 75 | * 76 | * Only a single account can be approved at a time, so approving the zero address clears previous approvals. 77 | * 78 | * Requirements: 79 | * 80 | * - The caller must own the token or be an approved operator. 81 | * - `tokenId` must exist. 82 | * 83 | * Emits an {Approval} event. 84 | */ 85 | function approve(address to, uint256 tokenId) external; 86 | 87 | /** 88 | * @dev Returns the account approved for `tokenId` token. 89 | * 90 | * Requirements: 91 | * 92 | * - `tokenId` must exist. 93 | */ 94 | function getApproved(uint256 tokenId) external view returns (address operator); 95 | 96 | /** 97 | * @dev Approve or remove `operator` as an operator for the caller. 98 | * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. 99 | * 100 | * Requirements: 101 | * 102 | * - The `operator` cannot be the caller. 103 | * 104 | * Emits an {ApprovalForAll} event. 105 | */ 106 | function setApprovalForAll(address operator, bool _approved) external; 107 | 108 | /** 109 | * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. 110 | * 111 | * See {setApprovalForAll} 112 | */ 113 | function isApprovedForAll(address owner, address operator) external view returns (bool); 114 | 115 | /** 116 | * @dev Safely transfers `tokenId` token from `from` to `to`. 117 | * 118 | * Requirements: 119 | * 120 | * - `from` cannot be the zero address. 121 | * - `to` cannot be the zero address. 122 | * - `tokenId` token must exist and be owned by `from`. 123 | * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. 124 | * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. 125 | * 126 | * Emits a {Transfer} event. 127 | */ 128 | function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external; 129 | } -------------------------------------------------------------------------------- /mooncats-acclimated/MoonCatOrderLookup.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-3.0-only 2 | pragma solidity ^0.7.3; 3 | 4 | import "@openzeppelin/contracts/access/Ownable.sol"; 5 | import "./IMoonCatRescue.sol"; 6 | import "./IMoonCatsWrapped.sol"; 7 | 8 | /** 9 | * @title MoonCat Order Lookup 10 | * @notice A space to have an on-chain record mapping token IDs for OLD_MCRW to their original "rescue order" IDs 11 | * @dev This contract exists because there is no MoonCat ID => Rescue ID function 12 | * on the original MoonCatRescue contract. The only way to tell a given MoonCat's 13 | * rescue order if you don't know it is to iterate through the whole `rescueOrder` 14 | * array. Looping through that whole array in a smart contract would be 15 | * prohibitively high gas-usage, and so this alternative is needed. 16 | */ 17 | contract MoonCatOrderLookup is Ownable { 18 | 19 | MoonCatRescue MCR = MoonCatRescue(0x60cd862c9C687A9dE49aecdC3A99b74A4fc54aB6); 20 | MoonCatsWrapped OLD_MCRW = MoonCatsWrapped(0x7C40c393DC0f283F318791d746d894DdD3693572); 21 | 22 | uint256[25600] private _oldTokenIdToRescueOrder; 23 | uint8 constant VALUE_OFFSET = 10; 24 | 25 | constructor() Ownable() {} 26 | 27 | /** 28 | * @dev Submit a batch of token IDs, and their associated rescue orders 29 | * This is the primary method for the utility of the contract. Anyone 30 | * can submit this pairing information (not just the owners of the token) 31 | * and the information can be submitted in batches. 32 | * 33 | * Submitting pairs of token IDs with their rescue orders is verified with 34 | * the original MoonCatRescue contract before recording. 35 | * 36 | * Within the private array holding this information, a VALUE_OFFSET is used 37 | * to differentiate between "not set" and "set to zero" (because Solidity 38 | * has no concept of "null" or "undefined"). Because the maximum value of the 39 | * rescue ordering can only be 25,600, we can safely shift the stored values 40 | * up, and not hit the uint256 limit. 41 | */ 42 | function submitRescueOrder( 43 | uint256[] memory oldTokenIds, 44 | uint16[] memory rescueOrders 45 | ) public { 46 | for (uint256 i = 0; i < oldTokenIds.length; i++) { 47 | require( 48 | MCR.rescueOrder(rescueOrders[i]) == OLD_MCRW._tokenIDToCatID(oldTokenIds[i]), 49 | "Pair does not match!" 50 | ); 51 | _oldTokenIdToRescueOrder[oldTokenIds[i]] = rescueOrders[i] + VALUE_OFFSET; 52 | } 53 | } 54 | 55 | /** 56 | * @dev verify a given old token ID is mapped yet or not 57 | * 58 | * This function can use just a zero-check because internally all values are 59 | * stored with a VALUE_OFFSET added onto them (e.g. storing an actual zero 60 | * is saved as 0 + VALUE_OFFSET = 10, internally), so anything set to an 61 | * actual zero means "unset". 62 | */ 63 | function _exists(uint256 oldTokenId) internal view returns (bool) { 64 | return _oldTokenIdToRescueOrder[oldTokenId] != 0; 65 | } 66 | 67 | /** 68 | * @dev public function to verify whether a given old token ID is mapped or not 69 | */ 70 | function oldTokenIdExists(uint256 oldTokenId) public view returns(bool) { 71 | return _exists(oldTokenId); 72 | } 73 | 74 | /** 75 | * @dev given an old token ID, return the rescue order of that MoonCat 76 | * 77 | * Throws an error if that particular token ID does not have a recorded 78 | * mapping to a rescue order. 79 | */ 80 | function oldTokenIdToRescueOrder(uint256 oldTokenId) public view returns(uint256) { 81 | require(_exists(oldTokenId), "That token ID is not mapped yet"); 82 | return _oldTokenIdToRescueOrder[oldTokenId] - VALUE_OFFSET; 83 | } 84 | 85 | /** 86 | * @dev remove a mapping from the data structure 87 | * 88 | * This allows reclaiming some gas, so as part of the re-wrapping process, 89 | * this gets called by the Acclimator contract, to recoup some gas for the 90 | * MoonCat owner. 91 | */ 92 | function removeEntry(uint256 _oldTokenId) public onlyOwner { 93 | delete _oldTokenIdToRescueOrder[_oldTokenId]; 94 | } 95 | 96 | /** 97 | * @dev for a given address, iterate through all the tokens they own in the 98 | * old wrapping contract, and for each of them, determine how many are mapped 99 | * in this lookup contract. 100 | * 101 | * This method is used by the Acclimator `balanceOf` and `tokenOfOwnerByIndex` 102 | * to be able to enumerate old-wrapped MoonCats as if they were already 103 | * re-wrapped in the Acclimator contract. 104 | */ 105 | function entriesPerAddress(address _owner) public view returns (uint256) { 106 | uint256 countMapped = 0; 107 | for (uint256 i = 0; i < OLD_MCRW.balanceOf(_owner); i++) { 108 | uint256 oldTokenId = OLD_MCRW.tokenOfOwnerByIndex(_owner, i); 109 | if (_exists(oldTokenId)) { 110 | countMapped++; 111 | } 112 | } 113 | return countMapped; 114 | } 115 | } -------------------------------------------------------------------------------- /mooncats-wrapped/IERC721.sol: -------------------------------------------------------------------------------- 1 | // File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/IERC721.sol 2 | 3 | 4 | 5 | pragma solidity >=0.6.2 <0.8.0; 6 | 7 | 8 | /** 9 | * @dev Required interface of an ERC721 compliant contract. 10 | */ 11 | interface IERC721 is IERC165 { 12 | /** 13 | * @dev Emitted when `tokenId` token is transferred from `from` to `to`. 14 | */ 15 | event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); 16 | 17 | /** 18 | * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. 19 | */ 20 | event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); 21 | 22 | /** 23 | * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. 24 | */ 25 | event ApprovalForAll(address indexed owner, address indexed operator, bool approved); 26 | 27 | /** 28 | * @dev Returns the number of tokens in ``owner``'s account. 29 | */ 30 | function balanceOf(address owner) external view returns (uint256 balance); 31 | 32 | /** 33 | * @dev Returns the owner of the `tokenId` token. 34 | * 35 | * Requirements: 36 | * 37 | * - `tokenId` must exist. 38 | */ 39 | function ownerOf(uint256 tokenId) external view returns (address owner); 40 | 41 | /** 42 | * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients 43 | * are aware of the ERC721 protocol to prevent tokens from being forever locked. 44 | * 45 | * Requirements: 46 | * 47 | * - `from` cannot be the zero address. 48 | * - `to` cannot be the zero address. 49 | * - `tokenId` token must exist and be owned by `from`. 50 | * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. 51 | * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. 52 | * 53 | * Emits a {Transfer} event. 54 | */ 55 | function safeTransferFrom(address from, address to, uint256 tokenId) external; 56 | 57 | /** 58 | * @dev Transfers `tokenId` token from `from` to `to`. 59 | * 60 | * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. 61 | * 62 | * Requirements: 63 | * 64 | * - `from` cannot be the zero address. 65 | * - `to` cannot be the zero address. 66 | * - `tokenId` token must be owned by `from`. 67 | * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. 68 | * 69 | * Emits a {Transfer} event. 70 | */ 71 | function transferFrom(address from, address to, uint256 tokenId) external; 72 | 73 | /** 74 | * @dev Gives permission to `to` to transfer `tokenId` token to another account. 75 | * The approval is cleared when the token is transferred. 76 | * 77 | * Only a single account can be approved at a time, so approving the zero address clears previous approvals. 78 | * 79 | * Requirements: 80 | * 81 | * - The caller must own the token or be an approved operator. 82 | * - `tokenId` must exist. 83 | * 84 | * Emits an {Approval} event. 85 | */ 86 | function approve(address to, uint256 tokenId) external; 87 | 88 | /** 89 | * @dev Returns the account approved for `tokenId` token. 90 | * 91 | * Requirements: 92 | * 93 | * - `tokenId` must exist. 94 | */ 95 | function getApproved(uint256 tokenId) external view returns (address operator); 96 | 97 | /** 98 | * @dev Approve or remove `operator` as an operator for the caller. 99 | * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. 100 | * 101 | * Requirements: 102 | * 103 | * - The `operator` cannot be the caller. 104 | * 105 | * Emits an {ApprovalForAll} event. 106 | */ 107 | function setApprovalForAll(address operator, bool _approved) external; 108 | 109 | /** 110 | * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. 111 | * 112 | * See {setApprovalForAll} 113 | */ 114 | function isApprovedForAll(address owner, address operator) external view returns (bool); 115 | 116 | /** 117 | * @dev Safely transfers `tokenId` token from `from` to `to`. 118 | * 119 | * Requirements: 120 | * 121 | * - `from` cannot be the zero address. 122 | * - `to` cannot be the zero address. 123 | * - `tokenId` token must exist and be owned by `from`. 124 | * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. 125 | * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. 126 | * 127 | * Emits a {Transfer} event. 128 | */ 129 | function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external; 130 | } 131 | -------------------------------------------------------------------------------- /cryptokitties/KittyAuction.sol: -------------------------------------------------------------------------------- 1 | /// @title Handles creating auctions for sale and siring of kitties. 2 | /// This wrapper of ReverseAuction exists only so that users can create 3 | /// auctions with only one transaction. 4 | 5 | contract KittyAuction is KittyBreeding { 6 | 7 | // @notice The auction contract variables are defined in KittyBase to allow 8 | // us to refer to them in KittyOwnership to prevent accidental transfers. 9 | // `saleAuction` refers to the auction for gen0 and p2p sale of kitties. 10 | // `siringAuction` refers to the auction for siring rights of kitties. 11 | 12 | /// @dev Sets the reference to the sale auction. 13 | /// @param _address - Address of sale contract. 14 | function setSaleAuctionAddress(address _address) external onlyCEO { 15 | SaleClockAuction candidateContract = SaleClockAuction(_address); 16 | 17 | // NOTE: verify that a contract is what we expect - https://github.com/Lunyr/crowdsale-contracts/blob/cfadd15986c30521d8ba7d5b6f57b4fefcc7ac38/contracts/LunyrToken.sol#L117 18 | require(candidateContract.isSaleClockAuction()); 19 | 20 | // Set the new contract address 21 | saleAuction = candidateContract; 22 | } 23 | 24 | /// @dev Sets the reference to the siring auction. 25 | /// @param _address - Address of siring contract. 26 | function setSiringAuctionAddress(address _address) external onlyCEO { 27 | SiringClockAuction candidateContract = SiringClockAuction(_address); 28 | 29 | // NOTE: verify that a contract is what we expect - https://github.com/Lunyr/crowdsale-contracts/blob/cfadd15986c30521d8ba7d5b6f57b4fefcc7ac38/contracts/LunyrToken.sol#L117 30 | require(candidateContract.isSiringClockAuction()); 31 | 32 | // Set the new contract address 33 | siringAuction = candidateContract; 34 | } 35 | 36 | /// @dev Put a kitty up for auction. 37 | /// Does some ownership trickery to create auctions in one tx. 38 | function createSaleAuction( 39 | uint256 _kittyId, 40 | uint256 _startingPrice, 41 | uint256 _endingPrice, 42 | uint256 _duration 43 | ) 44 | external 45 | whenNotPaused 46 | { 47 | // Auction contract checks input sizes 48 | // If kitty is already on any auction, this will throw 49 | // because it will be owned by the auction contract. 50 | require(_owns(msg.sender, _kittyId)); 51 | // Ensure the kitty is not pregnant to prevent the auction 52 | // contract accidentally receiving ownership of the child. 53 | // NOTE: the kitty IS allowed to be in a cooldown. 54 | require(!isPregnant(_kittyId)); 55 | _approve(_kittyId, saleAuction); 56 | // Sale auction throws if inputs are invalid and clears 57 | // transfer and sire approval after escrowing the kitty. 58 | saleAuction.createAuction( 59 | _kittyId, 60 | _startingPrice, 61 | _endingPrice, 62 | _duration, 63 | msg.sender 64 | ); 65 | } 66 | 67 | /// @dev Put a kitty up for auction to be sire. 68 | /// Performs checks to ensure the kitty can be sired, then 69 | /// delegates to reverse auction. 70 | function createSiringAuction( 71 | uint256 _kittyId, 72 | uint256 _startingPrice, 73 | uint256 _endingPrice, 74 | uint256 _duration 75 | ) 76 | external 77 | whenNotPaused 78 | { 79 | // Auction contract checks input sizes 80 | // If kitty is already on any auction, this will throw 81 | // because it will be owned by the auction contract. 82 | require(_owns(msg.sender, _kittyId)); 83 | require(isReadyToBreed(_kittyId)); 84 | _approve(_kittyId, siringAuction); 85 | // Siring auction throws if inputs are invalid and clears 86 | // transfer and sire approval after escrowing the kitty. 87 | siringAuction.createAuction( 88 | _kittyId, 89 | _startingPrice, 90 | _endingPrice, 91 | _duration, 92 | msg.sender 93 | ); 94 | } 95 | 96 | /// @dev Completes a siring auction by bidding. 97 | /// Immediately breeds the winning matron with the sire on auction. 98 | /// @param _sireId - ID of the sire on auction. 99 | /// @param _matronId - ID of the matron owned by the bidder. 100 | function bidOnSiringAuction( 101 | uint256 _sireId, 102 | uint256 _matronId 103 | ) 104 | external 105 | payable 106 | whenNotPaused 107 | { 108 | // Auction contract checks input sizes 109 | require(_owns(msg.sender, _matronId)); 110 | require(isReadyToBreed(_matronId)); 111 | require(_canBreedWithViaAuction(_matronId, _sireId)); 112 | 113 | // Define the current price of the auction. 114 | uint256 currentPrice = siringAuction.getCurrentPrice(_sireId); 115 | require(msg.value >= currentPrice + autoBirthFee); 116 | 117 | // Siring auction will throw if the bid fails. 118 | siringAuction.bid.value(msg.value - autoBirthFee)(_sireId); 119 | _breedWith(uint32(_matronId), uint32(_sireId)); 120 | } 121 | 122 | /// @dev Transfers the balance of the sale auction contract 123 | /// to the KittyCore contract. We use two-step withdrawal to 124 | /// prevent two transfer calls in the auction bid function. 125 | function withdrawAuctionBalances() external onlyCLevel { 126 | saleAuction.withdrawBalance(); 127 | siringAuction.withdrawBalance(); 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /mooncats-wrapped/lib/SafeMath.sol: -------------------------------------------------------------------------------- 1 | // File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/math/SafeMath.sol 2 | 3 | 4 | 5 | pragma solidity ^0.7.6; 6 | 7 | /** 8 | * @dev Wrappers over Solidity's arithmetic operations with added overflow 9 | * checks. 10 | * 11 | * Arithmetic operations in Solidity wrap on overflow. This can easily result 12 | * in bugs, because programmers usually assume that an overflow raises an 13 | * error, which is the standard behavior in high level programming languages. 14 | * `SafeMath` restores this intuition by reverting the transaction when an 15 | * operation overflows. 16 | * 17 | * Using this library instead of the unchecked operations eliminates an entire 18 | * class of bugs, so it's recommended to use it always. 19 | */ 20 | library SafeMath { 21 | /** 22 | * @dev Returns the addition of two unsigned integers, reverting on 23 | * overflow. 24 | * 25 | * Counterpart to Solidity's `+` operator. 26 | * 27 | * Requirements: 28 | * 29 | * - Addition cannot overflow. 30 | */ 31 | function add(uint256 a, uint256 b) internal pure returns (uint256) { 32 | uint256 c = a + b; 33 | require(c >= a, "SafeMath: addition overflow"); 34 | 35 | return c; 36 | } 37 | 38 | /** 39 | * @dev Returns the subtraction of two unsigned integers, reverting on 40 | * overflow (when the result is negative). 41 | * 42 | * Counterpart to Solidity's `-` operator. 43 | * 44 | * Requirements: 45 | * 46 | * - Subtraction cannot overflow. 47 | */ 48 | function sub(uint256 a, uint256 b) internal pure returns (uint256) { 49 | return sub(a, b, "SafeMath: subtraction overflow"); 50 | } 51 | 52 | /** 53 | * @dev Returns the subtraction of two unsigned integers, reverting with custom message on 54 | * overflow (when the result is negative). 55 | * 56 | * Counterpart to Solidity's `-` operator. 57 | * 58 | * Requirements: 59 | * 60 | * - Subtraction cannot overflow. 61 | */ 62 | function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 63 | require(b <= a, errorMessage); 64 | uint256 c = a - b; 65 | 66 | return c; 67 | } 68 | 69 | /** 70 | * @dev Returns the multiplication of two unsigned integers, reverting on 71 | * overflow. 72 | * 73 | * Counterpart to Solidity's `*` operator. 74 | * 75 | * Requirements: 76 | * 77 | * - Multiplication cannot overflow. 78 | */ 79 | function mul(uint256 a, uint256 b) internal pure returns (uint256) { 80 | // Gas optimization: this is cheaper than requiring 'a' not being zero, but the 81 | // benefit is lost if 'b' is also tested. 82 | // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 83 | if (a == 0) { 84 | return 0; 85 | } 86 | 87 | uint256 c = a * b; 88 | require(c / a == b, "SafeMath: multiplication overflow"); 89 | 90 | return c; 91 | } 92 | 93 | /** 94 | * @dev Returns the integer division of two unsigned integers. Reverts on 95 | * division by zero. The result is rounded towards zero. 96 | * 97 | * Counterpart to Solidity's `/` operator. Note: this function uses a 98 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 99 | * uses an invalid opcode to revert (consuming all remaining gas). 100 | * 101 | * Requirements: 102 | * 103 | * - The divisor cannot be zero. 104 | */ 105 | function div(uint256 a, uint256 b) internal pure returns (uint256) { 106 | return div(a, b, "SafeMath: division by zero"); 107 | } 108 | 109 | /** 110 | * @dev Returns the integer division of two unsigned integers. Reverts with custom message on 111 | * division by zero. The result is rounded towards zero. 112 | * 113 | * Counterpart to Solidity's `/` operator. Note: this function uses a 114 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 115 | * uses an invalid opcode to revert (consuming all remaining gas). 116 | * 117 | * Requirements: 118 | * 119 | * - The divisor cannot be zero. 120 | */ 121 | function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 122 | require(b > 0, errorMessage); 123 | uint256 c = a / b; 124 | // assert(a == b * c + a % b); // There is no case in which this doesn't hold 125 | 126 | return c; 127 | } 128 | 129 | /** 130 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 131 | * Reverts when dividing by zero. 132 | * 133 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 134 | * opcode (which leaves remaining gas untouched) while Solidity uses an 135 | * invalid opcode to revert (consuming all remaining gas). 136 | * 137 | * Requirements: 138 | * 139 | * - The divisor cannot be zero. 140 | */ 141 | function mod(uint256 a, uint256 b) internal pure returns (uint256) { 142 | return mod(a, b, "SafeMath: modulo by zero"); 143 | } 144 | 145 | /** 146 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 147 | * Reverts with custom message when dividing by zero. 148 | * 149 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 150 | * opcode (which leaves remaining gas untouched) while Solidity uses an 151 | * invalid opcode to revert (consuming all remaining gas). 152 | * 153 | * Requirements: 154 | * 155 | * - The divisor cannot be zero. 156 | */ 157 | function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 158 | require(b != 0, errorMessage); 159 | return a % b; 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /doomcats/DoomCatRescue.sol: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | $$$$$$$\ $$$$$$\ $$$$$$\ $$\ $$\ 4 | $$ __$$\ $$ __$$\ $$ __$$\ $$$\ $$$ | 5 | $$ | $$ |$$ / $$ |$$ / $$ |$$$$\ $$$$ | 6 | $$ | $$ |$$ | $$ |$$ | $$ |$$\$$\$$ $$ | 7 | $$ | $$ |$$ | $$ |$$ | $$ |$$ \$$$ $$ | 8 | $$ | $$ |$$ | $$ |$$ | $$ |$$ |\$ /$$ | 9 | $$$$$$$ | $$$$$$ | $$$$$$ |$$ | \_/ $$ | 10 | \_______/ \______/ \______/ \__| \__| 11 | 12 | 13 | 14 | $$$$$$\ $$$$$$\ $$$$$$$$\ 15 | $$ __$$\ $$ __$$\\__$$ __| 16 | $$ / \__|$$ / $$ | $$ | 17 | $$ | $$$$$$$$ | $$ | 18 | $$ | $$ __$$ | $$ | 19 | $$ | $$\ $$ | $$ | $$ | 20 | \$$$$$$ |$$ | $$ | $$ | 21 | \______/ \__| \__| \__| 22 | 23 | 24 | 25 | $$$$$$$\ $$$$$$$$\ $$$$$$\ $$$$$$\ $$\ $$\ $$$$$$$$\ 26 | $$ __$$\ $$ _____|$$ __$$\ $$ __$$\ $$ | $$ |$$ _____| 27 | $$ | $$ |$$ | $$ / \__|$$ / \__|$$ | $$ |$$ | 28 | $$$$$$$ |$$$$$\ \$$$$$$\ $$ | $$ | $$ |$$$$$\ 29 | $$ __$$< $$ __| \____$$\ $$ | $$ | $$ |$$ __| 30 | $$ | $$ |$$ | $$\ $$ |$$ | $$\ $$ | $$ |$$ | 31 | $$ | $$ |$$$$$$$$\ \$$$$$$ |\$$$$$$ |\$$$$$$ |$$$$$$$$\ 32 | \__| \__|\________| \______/ \______/ \______/ \________| 33 | 34 | */ 35 | 36 | 37 | // File contracts/DoomCatRescue.sol 38 | 39 | 40 | pragma solidity ^0.8.0; 41 | 42 | /** 43 | * @dev we rescue the cats 44 | */ 45 | contract DoomCatRescue { 46 | // reference to, basically, self 47 | IDoomCat private _doomCat; 48 | 49 | // total number of cats that exist 50 | uint256 public immutable totalCats; 51 | 52 | // how many cats initially existed to be rescued 53 | uint256 private immutable _remainingCatsInitial; 54 | 55 | // how many cats are left to be rescued 56 | uint256 public remainingCats; 57 | 58 | // when rescues can begin 59 | uint256 public immutable rescueStartTime; 60 | 61 | // initial price of rescues 62 | uint256 public immutable rescuePriceInitial; 63 | 64 | // current price of rescues 65 | uint256 public rescuePrice; 66 | 67 | // amount of rescue price increases 68 | uint256 public immutable rescuePriceIncrement; 69 | 70 | // amount of cats to rescue before price increase is triggered 71 | uint256 public immutable rescueTrancheSize; 72 | 73 | // how many blocks must exist between rescues for a given address 74 | uint256 public immutable rescueRateLimit; 75 | 76 | // track last block that an address performed a rescue 77 | mapping(address => uint256) public rescueLastBlock; 78 | 79 | // how many funds have been collected for rescues (resets every tranche) 80 | uint256 private collectedRescueFunds; 81 | 82 | event Rescue(address indexed rescuer, uint256 tokenId, uint256 price); 83 | 84 | constructor( 85 | IDoomCat doomCat_, 86 | uint256[2] memory catDetails_, 87 | uint256[5] memory rescueDetails_ 88 | ) { 89 | _doomCat = doomCat_; 90 | 91 | totalCats = catDetails_[0]; 92 | _remainingCatsInitial = catDetails_[1]; 93 | remainingCats = catDetails_[1]; 94 | 95 | rescuePriceInitial = rescueDetails_[0]; 96 | rescuePrice = rescueDetails_[0]; 97 | rescuePriceIncrement = rescueDetails_[1]; 98 | rescueTrancheSize = rescueDetails_[2]; 99 | rescueStartTime = rescueDetails_[3]; 100 | rescueRateLimit = rescueDetails_[4]; 101 | } 102 | 103 | /** 104 | * @dev public function to rescue a cat 105 | */ 106 | function rescue() public payable { 107 | // require that rescues have globally started 108 | require(block.timestamp >= rescueStartTime, "too early"); 109 | 110 | // require that address has passed their rate limit 111 | require( 112 | block.number >= rescueLastBlock[msg.sender] + rescueRateLimit, 113 | "too soon" 114 | ); 115 | 116 | // require that there are cats left to be rescued 117 | require(remainingCats > 0, "no cats left"); 118 | 119 | // require that the correct amount is paid (at minimum) 120 | require(msg.value >= rescuePrice, "value too low"); 121 | 122 | // update address' last block rate limit tracker 123 | rescueLastBlock[msg.sender] = block.number; 124 | 125 | // grab the current rescue price (for use after updating `rescuePrice`) 126 | uint256 currentRescuePrice = rescuePrice; 127 | 128 | // update the amount of funds that have been used for rescues 129 | collectedRescueFunds += currentRescuePrice; 130 | 131 | // decrement remaining cats 132 | remainingCats--; 133 | 134 | // if we are at a tranch boundary, OR, there are no remaining cats, then 135 | // we want to update the price and swap & burn all collected ETH from previous 136 | // tranche 137 | if ( 138 | (_remainingCatsInitial - remainingCats) % rescueTrancheSize == 0 || 139 | remainingCats == 0 140 | ) { 141 | // if there are no more cats, set rescuePrice at 0 for cleanup sake 142 | if (remainingCats == 0) { 143 | rescuePrice = 0; 144 | } else { 145 | // otherwise, increment rescuePrice by the increment amount 146 | rescuePrice += rescuePriceIncrement; 147 | } 148 | 149 | // swap and burn collected funds 150 | _doomCat.swapAndBurn(collectedRescueFunds); 151 | 152 | // reset collected funds back to 0 153 | collectedRescueFunds = 0; 154 | } 155 | 156 | // get the tokenId for the cat to mint, mint it 157 | uint256 tokenId = totalCats - remainingCats; 158 | _doomCat.mint(msg.sender, tokenId); 159 | 160 | // if the user overpaid, refund their Ether 161 | if (msg.value > currentRescuePrice) { 162 | payable(msg.sender).transfer(msg.value - currentRescuePrice); 163 | } 164 | 165 | emit Rescue(msg.sender, tokenId, rescuePrice); 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /cryptokitties/ClockAuction.sol: -------------------------------------------------------------------------------- 1 | /// @title Clock auction for non-fungible tokens. 2 | /// @notice We omit a fallback function to prevent accidental sends to this contract. 3 | 4 | contract ClockAuction is Pausable, ClockAuctionBase { 5 | 6 | /// @dev The ERC-165 interface signature for ERC-721. 7 | /// Ref: https://github.com/ethereum/EIPs/issues/165 8 | /// Ref: https://github.com/ethereum/EIPs/issues/721 9 | bytes4 constant InterfaceSignature_ERC721 = bytes4(0x9a20483d); 10 | 11 | /// @dev Constructor creates a reference to the NFT ownership contract 12 | /// and verifies the owner cut is in the valid range. 13 | /// @param _nftAddress - address of a deployed contract implementing 14 | /// the Nonfungible Interface. 15 | /// @param _cut - percent cut the owner takes on each auction, must be 16 | /// between 0-10,000. 17 | function ClockAuction(address _nftAddress, uint256 _cut) public { 18 | require(_cut <= 10000); 19 | ownerCut = _cut; 20 | 21 | ERC721 candidateContract = ERC721(_nftAddress); 22 | require(candidateContract.supportsInterface(InterfaceSignature_ERC721)); 23 | nonFungibleContract = candidateContract; 24 | } 25 | 26 | /// @dev Remove all Ether from the contract, which is the owner's cuts 27 | /// as well as any Ether sent directly to the contract address. 28 | /// Always transfers to the NFT contract, but can be called either by 29 | /// the owner or the NFT contract. 30 | function withdrawBalance() external { 31 | address nftAddress = address(nonFungibleContract); 32 | 33 | require( 34 | msg.sender == owner || 35 | msg.sender == nftAddress 36 | ); 37 | // We are using this boolean method to make sure that even if one fails it will still work 38 | bool res = nftAddress.send(this.balance); 39 | } 40 | 41 | /// @dev Creates and begins a new auction. 42 | /// @param _tokenId - ID of token to auction, sender must be owner. 43 | /// @param _startingPrice - Price of item (in wei) at beginning of auction. 44 | /// @param _endingPrice - Price of item (in wei) at end of auction. 45 | /// @param _duration - Length of time to move between starting 46 | /// price and ending price (in seconds). 47 | /// @param _seller - Seller, if not the message sender 48 | function createAuction( 49 | uint256 _tokenId, 50 | uint256 _startingPrice, 51 | uint256 _endingPrice, 52 | uint256 _duration, 53 | address _seller 54 | ) 55 | external 56 | whenNotPaused 57 | { 58 | // Sanity check that no inputs overflow how many bits we've allocated 59 | // to store them in the auction struct. 60 | require(_startingPrice == uint256(uint128(_startingPrice))); 61 | require(_endingPrice == uint256(uint128(_endingPrice))); 62 | require(_duration == uint256(uint64(_duration))); 63 | 64 | require(_owns(msg.sender, _tokenId)); 65 | _escrow(msg.sender, _tokenId); 66 | Auction memory auction = Auction( 67 | _seller, 68 | uint128(_startingPrice), 69 | uint128(_endingPrice), 70 | uint64(_duration), 71 | uint64(now) 72 | ); 73 | _addAuction(_tokenId, auction); 74 | } 75 | 76 | /// @dev Bids on an open auction, completing the auction and transferring 77 | /// ownership of the NFT if enough Ether is supplied. 78 | /// @param _tokenId - ID of token to bid on. 79 | function bid(uint256 _tokenId) 80 | external 81 | payable 82 | whenNotPaused 83 | { 84 | // _bid will throw if the bid or funds transfer fails 85 | _bid(_tokenId, msg.value); 86 | _transfer(msg.sender, _tokenId); 87 | } 88 | 89 | /// @dev Cancels an auction that hasn't been won yet. 90 | /// Returns the NFT to original owner. 91 | /// @notice This is a state-modifying function that can 92 | /// be called while the contract is paused. 93 | /// @param _tokenId - ID of token on auction 94 | function cancelAuction(uint256 _tokenId) 95 | external 96 | { 97 | Auction storage auction = tokenIdToAuction[_tokenId]; 98 | require(_isOnAuction(auction)); 99 | address seller = auction.seller; 100 | require(msg.sender == seller); 101 | _cancelAuction(_tokenId, seller); 102 | } 103 | 104 | /// @dev Cancels an auction when the contract is paused. 105 | /// Only the owner may do this, and NFTs are returned to 106 | /// the seller. This should only be used in emergencies. 107 | /// @param _tokenId - ID of the NFT on auction to cancel. 108 | function cancelAuctionWhenPaused(uint256 _tokenId) 109 | whenPaused 110 | onlyOwner 111 | external 112 | { 113 | Auction storage auction = tokenIdToAuction[_tokenId]; 114 | require(_isOnAuction(auction)); 115 | _cancelAuction(_tokenId, auction.seller); 116 | } 117 | 118 | /// @dev Returns auction info for an NFT on auction. 119 | /// @param _tokenId - ID of NFT on auction. 120 | function getAuction(uint256 _tokenId) 121 | external 122 | view 123 | returns 124 | ( 125 | address seller, 126 | uint256 startingPrice, 127 | uint256 endingPrice, 128 | uint256 duration, 129 | uint256 startedAt 130 | ) { 131 | Auction storage auction = tokenIdToAuction[_tokenId]; 132 | require(_isOnAuction(auction)); 133 | return ( 134 | auction.seller, 135 | auction.startingPrice, 136 | auction.endingPrice, 137 | auction.duration, 138 | auction.startedAt 139 | ); 140 | } 141 | 142 | /// @dev Returns the current price of an auction. 143 | /// @param _tokenId - ID of the token price we are checking. 144 | function getCurrentPrice(uint256 _tokenId) 145 | external 146 | view 147 | returns (uint256) 148 | { 149 | Auction storage auction = tokenIdToAuction[_tokenId]; 150 | require(_isOnAuction(auction)); 151 | return _currentPrice(auction); 152 | } 153 | 154 | } 155 | -------------------------------------------------------------------------------- /lasercats/ERC721Enumerable.sol: -------------------------------------------------------------------------------- 1 | /** 2 | * @dev This implements an optional extension of {ERC721} defined in the EIP that adds 3 | * enumerability of all the token ids in the contract as well as all token ids owned by each 4 | * account. 5 | */ 6 | abstract contract ERC721Enumerable is ERC721, IERC721Enumerable { 7 | // Mapping from owner to list of owned token IDs 8 | mapping(address => mapping(uint256 => uint256)) private _ownedTokens; 9 | 10 | // Mapping from token ID to index of the owner tokens list 11 | mapping(uint256 => uint256) private _ownedTokensIndex; 12 | 13 | // Array with all token ids, used for enumeration 14 | uint256[] private _allTokens; 15 | 16 | // Mapping from token id to position in the allTokens array 17 | mapping(uint256 => uint256) private _allTokensIndex; 18 | 19 | /** 20 | * @dev See {IERC165-supportsInterface}. 21 | */ 22 | function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns(bool) { 23 | return interfaceId == type(IERC721Enumerable).interfaceId 24 | || super.supportsInterface(interfaceId); 25 | } 26 | 27 | /** 28 | * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. 29 | */ 30 | function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns(uint256) { 31 | require(index < ERC721.balanceOf(owner), "ERC721Enumerable: owner index out of bounds"); 32 | return _ownedTokens[owner][index]; 33 | } 34 | 35 | /** 36 | * @dev See {IERC721Enumerable-totalSupply}. 37 | */ 38 | function totalSupply() public view virtual override returns(uint256) { 39 | return _allTokens.length; 40 | } 41 | 42 | /** 43 | * @dev See {IERC721Enumerable-tokenByIndex}. 44 | */ 45 | function tokenByIndex(uint256 index) public view virtual override returns(uint256) { 46 | require(index < ERC721Enumerable.totalSupply(), "ERC721Enumerable: global index out of bounds"); 47 | return _allTokens[index]; 48 | } 49 | 50 | /** 51 | * @dev Hook that is called before any token transfer. This includes minting 52 | * and burning. 53 | * 54 | * Calling conditions: 55 | * 56 | * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be 57 | * transferred to `to`. 58 | * - When `from` is zero, `tokenId` will be minted for `to`. 59 | * - When `to` is zero, ``from``'s `tokenId` will be burned. 60 | * - `from` cannot be the zero address. 61 | * - `to` cannot be the zero address. 62 | * 63 | * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. 64 | */ 65 | function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual override { 66 | super._beforeTokenTransfer(from, to, tokenId); 67 | 68 | if (from == address(0)) { 69 | _addTokenToAllTokensEnumeration(tokenId); 70 | } else if (from != to) { 71 | _removeTokenFromOwnerEnumeration(from, tokenId); 72 | } 73 | if (to == address(0)) { 74 | _removeTokenFromAllTokensEnumeration(tokenId); 75 | } else if (to != from) { 76 | _addTokenToOwnerEnumeration(to, tokenId); 77 | } 78 | } 79 | 80 | /** 81 | * @dev Private function to add a token to this extension's ownership-tracking data structures. 82 | * @param to address representing the new owner of the given token ID 83 | * @param tokenId uint256 ID of the token to be added to the tokens list of the given address 84 | */ 85 | function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private { 86 | uint256 length = ERC721.balanceOf(to); 87 | _ownedTokens[to][length] = tokenId; 88 | _ownedTokensIndex[tokenId] = length; 89 | } 90 | 91 | /** 92 | * @dev Private function to add a token to this extension's token tracking data structures. 93 | * @param tokenId uint256 ID of the token to be added to the tokens list 94 | */ 95 | function _addTokenToAllTokensEnumeration(uint256 tokenId) private { 96 | _allTokensIndex[tokenId] = _allTokens.length; 97 | _allTokens.push(tokenId); 98 | } 99 | 100 | /** 101 | * @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that 102 | * while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for 103 | * gas optimizations e.g. when performing a transfer operation (avoiding double writes). 104 | * This has O(1) time complexity, but alters the order of the _ownedTokens array. 105 | * @param from address representing the previous owner of the given token ID 106 | * @param tokenId uint256 ID of the token to be removed from the tokens list of the given address 107 | */ 108 | function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private { 109 | // To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and 110 | // then delete the last slot (swap and pop). 111 | 112 | uint256 lastTokenIndex = ERC721.balanceOf(from) - 1; 113 | uint256 tokenIndex = _ownedTokensIndex[tokenId]; 114 | 115 | // When the token to delete is the last token, the swap operation is unnecessary 116 | if (tokenIndex != lastTokenIndex) { 117 | uint256 lastTokenId = _ownedTokens[from][lastTokenIndex]; 118 | 119 | _ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token 120 | _ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index 121 | } 122 | 123 | // This also deletes the contents at the last position of the array 124 | delete _ownedTokensIndex[tokenId]; 125 | delete _ownedTokens[from][lastTokenIndex]; 126 | } 127 | 128 | /** 129 | * @dev Private function to remove a token from this extension's token tracking data structures. 130 | * This has O(1) time complexity, but alters the order of the _allTokens array. 131 | * @param tokenId uint256 ID of the token to be removed from the tokens list 132 | */ 133 | function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private { 134 | // To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and 135 | // then delete the last slot (swap and pop). 136 | 137 | uint256 lastTokenIndex = _allTokens.length - 1; 138 | uint256 tokenIndex = _allTokensIndex[tokenId]; 139 | 140 | // When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so 141 | // rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding 142 | // an 'if' statement (like in _removeTokenFromOwnerEnumeration) 143 | uint256 lastTokenId = _allTokens[lastTokenIndex]; 144 | 145 | _allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token 146 | _allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index 147 | 148 | // This also deletes the contents at the last position of the array 149 | delete _allTokensIndex[tokenId]; 150 | _allTokens.pop(); 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /mooncats/README.md: -------------------------------------------------------------------------------- 1 | # Inside the MoonCatRescue Blockchain Contract / Service 2 | 3 | 4 | ## Source Code 5 | 6 | MoonCatRescue @ Etherscan, see contract address [`0x60cd862c9c687a9de49aecdc3a99b74a4fc54ab6`](https://etherscan.io/address/0x60cd862c9c687a9de49aecdc3a99b74a4fc54ab6#code) 7 | 8 | Contracts & More @ 9 | GitHub, see [MoonCatRescue-Contract @ ponderware](https://github.com/ponderware/MoonCatRescue-Contract) 10 | 11 | 12 | 13 | 14 | ### MoonCatRescue 15 | 16 | #### Constants 17 | 18 | Use this to verify mooncatparser.js the cat image data generation javascript file 19 | 20 | ``` solidity 21 | bytes16 public imageGenerationCodeMD5 = 0xdbad5c08ec98bec48490e3c196eec683; 22 | ``` 23 | 24 | MoonCats meta data: 25 | 26 | ``` solidity 27 | string public name = "MoonCats"; 28 | string public symbol = "🐱"; // unicode cat symbol 29 | uint8 public decimals = 0; 30 | 31 | uint256 public totalSupply = 25600; 32 | uint16 public remainingCats = 25600 - 256; // there will only ever be 25,000 cats 33 | uint16 public remainingGenesisCats = 256; // there can only be a maximum of 256 genesis cats 34 | ``` 35 | 36 | Gets set with the immediately preceding blockhash when the contract is activated to prevent "premining" 37 | 38 | ``` solidity 39 | bytes32 public searchSeed = 0x0; 40 | ``` 41 | 42 | 43 | 44 | 45 | #### Events 46 | 47 | **CatRescued** 48 | 49 | ``` solidity 50 | event CatRescued(address indexed to, bytes5 indexed catId); 51 | ``` 52 | 53 | **CatNamed** 54 | 55 | ``` solidity 56 | event CatNamed(bytes5 indexed catId, bytes32 catName); 57 | ``` 58 | 59 | **CatAdopted** 60 | 61 | ``` solidity 62 | event CatAdopted(bytes5 indexed catId, uint price, address indexed from, address indexed to); 63 | ``` 64 | 65 | **AdoptionOffered / AdoptionOfferCancelled** 66 | 67 | ``` solidity 68 | event AdoptionOffered(bytes5 indexed catId, uint price, address indexed toAddress); 69 | event AdoptionOfferCancelled(bytes5 indexed catId); 70 | ``` 71 | 72 | **AdoptionRequested / AdoptionRequestCancelled** 73 | 74 | ``` solidity 75 | event AdoptionRequested(bytes5 indexed catId, uint price, address indexed from); 76 | event AdoptionRequestCancelled(bytes5 indexed catId); 77 | ``` 78 | 79 | **GenesisCatsAdded** 80 | 81 | ``` solidity 82 | event GenesisCatsAdded(bytes5[16] catIds); 83 | ``` 84 | 85 | **Transfer** 86 | 87 | ``` solidity 88 | event Transfer(address indexed from, address indexed to, uint256 value); 89 | ``` 90 | 91 | 92 | #### Structs 93 | 94 | **AdoptionOffer** 95 | 96 | ``` solidity 97 | struct AdoptionOffer { 98 | bool exists; 99 | bytes5 catId; 100 | address seller; 101 | uint price; 102 | address onlyOfferTo; 103 | } 104 | ``` 105 | 106 | **AdoptionRequest** 107 | 108 | ``` solidity 109 | struct AdoptionRequest { 110 | bool exists; 111 | bytes5 catId; 112 | address requester; 113 | uint price; 114 | } 115 | ``` 116 | 117 | #### Storage 118 | 119 | **adoptionOffers** 120 | 121 | ``` solidity 122 | mapping (bytes5 => AdoptionOffer) public adoptionOffers; 123 | ``` 124 | 125 | **adoptionRequests** 126 | 127 | ``` solidity 128 | mapping (bytes5 => AdoptionRequest) public adoptionRequests; 129 | ``` 130 | 131 | **catNames** 132 | 133 | ``` solidity 134 | mapping (bytes5 => bytes32) public catNames; 135 | ``` 136 | 137 | **catOwners** 138 | 139 | ``` solidity 140 | mapping (bytes5 => address) public catOwners; 141 | ``` 142 | 143 | **balanceOf** 144 | 145 | number of cats owned by a given address 146 | ``` solidity 147 | mapping (address => uint256) public balanceOf; 148 | ``` 149 | 150 | **pendingWithdrawals** 151 | 152 | ``` solidity 153 | mapping (address => uint) public pendingWithdrawals; 154 | ``` 155 | 156 | 157 | 158 | #### Functions 159 | 160 | **rescueCat (Historic)** 161 | 162 | registers and validates cats that are found 163 | 164 | ``` solidity 165 | function rescueCat(bytes32 seed) returns (bytes5) 166 | ``` 167 | 168 | **nameCat** 169 | 170 | assigns a name to a cat, once a name is assigned it cannot be changed 171 | 172 | note: ensure the current name is empty; cats can only be named once 173 | 174 | note: cats cannot be named while they are up for adoption 175 | 176 | ``` solidity 177 | function nameCat(bytes5 catId, bytes32 catName) 178 | ``` 179 | 180 | **makeAdoptionOffer** 181 | 182 | puts a cat up for anyone to adopt 183 | 184 | ``` solidity 185 | function makeAdoptionOffer(bytes5 catId, uint price) 186 | ``` 187 | 188 | **makeAdoptionOfferToAddress** 189 | 190 | puts a cat up for a specific address to adopt 191 | 192 | ``` solidity 193 | function makeAdoptionOfferToAddress(bytes5 catId, uint price, address to) 194 | ``` 195 | 196 | **cancelAdoptionOffer** 197 | 198 | cancel an adoption offer 199 | 200 | ``` solidity 201 | function cancelAdoptionOffer(bytes5 catId) 202 | ``` 203 | 204 | **acceptAdoptionOffer** 205 | 206 | accepts an adoption offer 207 | 208 | ``` solidity 209 | function acceptAdoptionOffer(bytes5 catId) payable 210 | ``` 211 | 212 | **giveCat** 213 | 214 | transfer a cat directly without payment 215 | 216 | ``` solidity 217 | function giveCat(bytes5 catId, address to) 218 | ``` 219 | 220 | **makeAdoptionRequest** 221 | 222 | requests adoption of a cat with an ETH offer 223 | 224 | ``` solidity 225 | function makeAdoptionRequest(bytes5 catId) payable 226 | ``` 227 | 228 | **acceptAdoptionRequest** 229 | 230 | allows the owner of the cat to accept an adoption request 231 | 232 | ``` solidity 233 | function acceptAdoptionRequest(bytes5 catId) 234 | ``` 235 | 236 | **cancelAdoptionRequest** 237 | 238 | allows the requester to cancel their adoption request 239 | 240 | ``` solidity 241 | function cancelAdoptionRequest(bytes5 catId) 242 | ``` 243 | 244 | **withdraw** 245 | 246 | ``` solidity 247 | function withdraw() 248 | ``` 249 | 250 | 251 | 252 | ##### Owner only functions 253 | 254 | **addGenesisCatGroup** 255 | 256 | add genesis cats in groups of 16 257 | 258 | ``` solidity 259 | function addGenesisCatGroup() 260 | ``` 261 | 262 | ##### Aggregate getters 263 | 264 | **getCatIds** 265 | 266 | ``` solidity 267 | function getCatIds() constant returns (bytes5[]) { 268 | ``` 269 | 270 | **getCatNames** 271 | 272 | ``` solidity 273 | function getCatNames() constant returns (bytes32[]) { 274 | ``` 275 | 276 | **getCatOwners** 277 | 278 | ``` solidity 279 | function getCatOwners() constant returns (address[]) { 280 | ``` 281 | 282 | **getCatOfferPrices** 283 | 284 | ``` solidity 285 | function getCatOfferPrices() constant returns (uint[]) { 286 | ``` 287 | 288 | **getCatRequestPrices** 289 | 290 | ``` solidity 291 | function getCatRequestPrices() constant returns (uint[]) { 292 | ``` 293 | 294 | **getCatDetails** 295 | 296 | ``` solidity 297 | function getCatDetails(bytes5 catId) constant returns (bytes5 id, 298 | address owner, 299 | bytes32 name, 300 | address onlyOfferTo, 301 | uint offerPrice, 302 | address requester, 303 | uint requestPrice) 304 | ``` 305 | -------------------------------------------------------------------------------- /doomcats/ERC721Enumerable.sol: -------------------------------------------------------------------------------- 1 | // File @openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol@v4.0.0 2 | 3 | 4 | 5 | pragma solidity ^0.8.0; 6 | 7 | 8 | /** 9 | * @dev This implements an optional extension of {ERC721} defined in the EIP that adds 10 | * enumerability of all the token ids in the contract as well as all token ids owned by each 11 | * account. 12 | */ 13 | abstract contract ERC721Enumerable is ERC721, IERC721Enumerable { 14 | // Mapping from owner to list of owned token IDs 15 | mapping(address => mapping(uint256 => uint256)) private _ownedTokens; 16 | 17 | // Mapping from token ID to index of the owner tokens list 18 | mapping(uint256 => uint256) private _ownedTokensIndex; 19 | 20 | // Array with all token ids, used for enumeration 21 | uint256[] private _allTokens; 22 | 23 | // Mapping from token id to position in the allTokens array 24 | mapping(uint256 => uint256) private _allTokensIndex; 25 | 26 | /** 27 | * @dev See {IERC165-supportsInterface}. 28 | */ 29 | function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) { 30 | return interfaceId == type(IERC721Enumerable).interfaceId 31 | || super.supportsInterface(interfaceId); 32 | } 33 | 34 | /** 35 | * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}. 36 | */ 37 | function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) { 38 | require(index < ERC721.balanceOf(owner), "ERC721Enumerable: owner index out of bounds"); 39 | return _ownedTokens[owner][index]; 40 | } 41 | 42 | /** 43 | * @dev See {IERC721Enumerable-totalSupply}. 44 | */ 45 | function totalSupply() public view virtual override returns (uint256) { 46 | return _allTokens.length; 47 | } 48 | 49 | /** 50 | * @dev See {IERC721Enumerable-tokenByIndex}. 51 | */ 52 | function tokenByIndex(uint256 index) public view virtual override returns (uint256) { 53 | require(index < ERC721Enumerable.totalSupply(), "ERC721Enumerable: global index out of bounds"); 54 | return _allTokens[index]; 55 | } 56 | 57 | /** 58 | * @dev Hook that is called before any token transfer. This includes minting 59 | * and burning. 60 | * 61 | * Calling conditions: 62 | * 63 | * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be 64 | * transferred to `to`. 65 | * - When `from` is zero, `tokenId` will be minted for `to`. 66 | * - When `to` is zero, ``from``'s `tokenId` will be burned. 67 | * - `from` cannot be the zero address. 68 | * - `to` cannot be the zero address. 69 | * 70 | * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. 71 | */ 72 | function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual override { 73 | super._beforeTokenTransfer(from, to, tokenId); 74 | 75 | if (from == address(0)) { 76 | _addTokenToAllTokensEnumeration(tokenId); 77 | } else if (from != to) { 78 | _removeTokenFromOwnerEnumeration(from, tokenId); 79 | } 80 | if (to == address(0)) { 81 | _removeTokenFromAllTokensEnumeration(tokenId); 82 | } else if (to != from) { 83 | _addTokenToOwnerEnumeration(to, tokenId); 84 | } 85 | } 86 | 87 | /** 88 | * @dev Private function to add a token to this extension's ownership-tracking data structures. 89 | * @param to address representing the new owner of the given token ID 90 | * @param tokenId uint256 ID of the token to be added to the tokens list of the given address 91 | */ 92 | function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private { 93 | uint256 length = ERC721.balanceOf(to); 94 | _ownedTokens[to][length] = tokenId; 95 | _ownedTokensIndex[tokenId] = length; 96 | } 97 | 98 | /** 99 | * @dev Private function to add a token to this extension's token tracking data structures. 100 | * @param tokenId uint256 ID of the token to be added to the tokens list 101 | */ 102 | function _addTokenToAllTokensEnumeration(uint256 tokenId) private { 103 | _allTokensIndex[tokenId] = _allTokens.length; 104 | _allTokens.push(tokenId); 105 | } 106 | 107 | /** 108 | * @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that 109 | * while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for 110 | * gas optimizations e.g. when performing a transfer operation (avoiding double writes). 111 | * This has O(1) time complexity, but alters the order of the _ownedTokens array. 112 | * @param from address representing the previous owner of the given token ID 113 | * @param tokenId uint256 ID of the token to be removed from the tokens list of the given address 114 | */ 115 | function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private { 116 | // To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and 117 | // then delete the last slot (swap and pop). 118 | 119 | uint256 lastTokenIndex = ERC721.balanceOf(from) - 1; 120 | uint256 tokenIndex = _ownedTokensIndex[tokenId]; 121 | 122 | // When the token to delete is the last token, the swap operation is unnecessary 123 | if (tokenIndex != lastTokenIndex) { 124 | uint256 lastTokenId = _ownedTokens[from][lastTokenIndex]; 125 | 126 | _ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token 127 | _ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index 128 | } 129 | 130 | // This also deletes the contents at the last position of the array 131 | delete _ownedTokensIndex[tokenId]; 132 | delete _ownedTokens[from][lastTokenIndex]; 133 | } 134 | 135 | /** 136 | * @dev Private function to remove a token from this extension's token tracking data structures. 137 | * This has O(1) time complexity, but alters the order of the _allTokens array. 138 | * @param tokenId uint256 ID of the token to be removed from the tokens list 139 | */ 140 | function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private { 141 | // To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and 142 | // then delete the last slot (swap and pop). 143 | 144 | uint256 lastTokenIndex = _allTokens.length - 1; 145 | uint256 tokenIndex = _allTokensIndex[tokenId]; 146 | 147 | // When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so 148 | // rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding 149 | // an 'if' statement (like in _removeTokenFromOwnerEnumeration) 150 | uint256 lastTokenId = _allTokens[lastTokenIndex]; 151 | 152 | _allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token 153 | _allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index 154 | 155 | // This also deletes the contents at the last position of the array 156 | delete _allTokensIndex[tokenId]; 157 | _allTokens.pop(); 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /cryptokitties/KittyCore.sol: -------------------------------------------------------------------------------- 1 | /// @title CryptoKitties: Collectible, breedable, and oh-so-adorable cats on the Ethereum blockchain. 2 | /// @author Axiom Zen (https://www.axiomzen.co) 3 | /// @dev The main CryptoKitties contract, keeps track of kittens so they don't wander around and get lost. 4 | 5 | contract KittyCore is KittyMinting { 6 | 7 | // This is the main CryptoKitties contract. In order to keep our code seperated into logical sections, 8 | // we've broken it up in two ways. First, we have several seperately-instantiated sibling contracts 9 | // that handle auctions and our super-top-secret genetic combination algorithm. The auctions are 10 | // seperate since their logic is somewhat complex and there's always a risk of subtle bugs. By keeping 11 | // them in their own contracts, we can upgrade them without disrupting the main contract that tracks 12 | // kitty ownership. The genetic combination algorithm is kept seperate so we can open-source all of 13 | // the rest of our code without making it _too_ easy for folks to figure out how the genetics work. 14 | // Don't worry, I'm sure someone will reverse engineer it soon enough! 15 | // 16 | // Secondly, we break the core contract into multiple files using inheritence, one for each major 17 | // facet of functionality of CK. This allows us to keep related code bundled together while still 18 | // avoiding a single giant file with everything in it. The breakdown is as follows: 19 | // 20 | // - KittyBase: This is where we define the most fundamental code shared throughout the core 21 | // functionality. This includes our main data storage, constants and data types, plus 22 | // internal functions for managing these items. 23 | // 24 | // - KittyAccessControl: This contract manages the various addresses and constraints for operations 25 | // that can be executed only by specific roles. Namely CEO, CFO and COO. 26 | // 27 | // - KittyOwnership: This provides the methods required for basic non-fungible token 28 | // transactions, following the draft ERC-721 spec (https://github.com/ethereum/EIPs/issues/721). 29 | // 30 | // - KittyBreeding: This file contains the methods necessary to breed cats together, including 31 | // keeping track of siring offers, and relies on an external genetic combination contract. 32 | // 33 | // - KittyAuctions: Here we have the public methods for auctioning or bidding on cats or siring 34 | // services. The actual auction functionality is handled in two sibling contracts (one 35 | // for sales and one for siring), while auction creation and bidding is mostly mediated 36 | // through this facet of the core contract. 37 | // 38 | // - KittyMinting: This final facet contains the functionality we use for creating new gen0 cats. 39 | // We can make up to 5000 "promo" cats that can be given away (especially important when 40 | // the community is new), and all others can only be created and then immediately put up 41 | // for auction via an algorithmically determined starting price. Regardless of how they 42 | // are created, there is a hard limit of 50k gen0 cats. After that, it's all up to the 43 | // community to breed, breed, breed! 44 | 45 | // Set in case the core contract is broken and an upgrade is required 46 | address public newContractAddress; 47 | 48 | /// @notice Creates the main CryptoKitties smart contract instance. 49 | function KittyCore() public { 50 | // Starts paused. 51 | paused = true; 52 | 53 | // the creator of the contract is the initial CEO 54 | ceoAddress = msg.sender; 55 | 56 | // the creator of the contract is also the initial COO 57 | cooAddress = msg.sender; 58 | 59 | // start with the mythical kitten 0 - so we don't have generation-0 parent issues 60 | _createKitty(0, 0, 0, uint256(-1), address(0)); 61 | } 62 | 63 | /// @dev Used to mark the smart contract as upgraded, in case there is a serious 64 | /// breaking bug. This method does nothing but keep track of the new contract and 65 | /// emit a message indicating that the new address is set. It's up to clients of this 66 | /// contract to update to the new contract address in that case. (This contract will 67 | /// be paused indefinitely if such an upgrade takes place.) 68 | /// @param _v2Address new address 69 | function setNewAddress(address _v2Address) external onlyCEO whenPaused { 70 | // See README.md for updgrade plan 71 | newContractAddress = _v2Address; 72 | ContractUpgrade(_v2Address); 73 | } 74 | 75 | /// @notice No tipping! 76 | /// @dev Reject all Ether from being sent here, unless it's from one of the 77 | /// two auction contracts. (Hopefully, we can prevent user accidents.) 78 | function() external payable { 79 | require( 80 | msg.sender == address(saleAuction) || 81 | msg.sender == address(siringAuction) 82 | ); 83 | } 84 | 85 | /// @notice Returns all the relevant information about a specific kitty. 86 | /// @param _id The ID of the kitty of interest. 87 | function getKitty(uint256 _id) 88 | external 89 | view 90 | returns ( 91 | bool isGestating, 92 | bool isReady, 93 | uint256 cooldownIndex, 94 | uint256 nextActionAt, 95 | uint256 siringWithId, 96 | uint256 birthTime, 97 | uint256 matronId, 98 | uint256 sireId, 99 | uint256 generation, 100 | uint256 genes 101 | ) { 102 | Kitty storage kit = kitties[_id]; 103 | 104 | // if this variable is 0 then it's not gestating 105 | isGestating = (kit.siringWithId != 0); 106 | isReady = (kit.cooldownEndBlock <= block.number); 107 | cooldownIndex = uint256(kit.cooldownIndex); 108 | nextActionAt = uint256(kit.cooldownEndBlock); 109 | siringWithId = uint256(kit.siringWithId); 110 | birthTime = uint256(kit.birthTime); 111 | matronId = uint256(kit.matronId); 112 | sireId = uint256(kit.sireId); 113 | generation = uint256(kit.generation); 114 | genes = kit.genes; 115 | } 116 | 117 | /// @dev Override unpause so it requires all external contract addresses 118 | /// to be set before contract can be unpaused. Also, we can't have 119 | /// newContractAddress set either, because then the contract was upgraded. 120 | /// @notice This is public rather than external so we can call super.unpause 121 | /// without using an expensive CALL. 122 | function unpause() public onlyCEO whenPaused { 123 | require(saleAuction != address(0)); 124 | require(siringAuction != address(0)); 125 | require(geneScience != address(0)); 126 | require(newContractAddress == address(0)); 127 | 128 | // Actually unpause the contract. 129 | super.unpause(); 130 | } 131 | 132 | // @dev Allows the CFO to capture the balance available to the contract. 133 | function withdrawBalance() external onlyCFO { 134 | uint256 balance = this.balance; 135 | // Subtract all the currently pregnant kittens we have, plus 1 of margin. 136 | uint256 subtractFees = (pregnantKitties + 1) * autoBirthFee; 137 | 138 | if (balance > subtractFees) { 139 | cfoAddress.send(balance - subtractFees); 140 | } 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /lasercats/lib/SafeMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | // CAUTION 6 | // This version of SafeMath should only be used with Solidity 0.8 or later, 7 | // because it relies on the compiler's built in overflow checks. 8 | 9 | /** 10 | * @dev Wrappers over Solidity's arithmetic operations. 11 | * 12 | * NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler 13 | * now has built in overflow checking. 14 | */ 15 | library SafeMath { 16 | /** 17 | * @dev Returns the addition of two unsigned integers, with an overflow flag. 18 | * 19 | * _Available since v3.4._ 20 | */ 21 | function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { 22 | unchecked { 23 | uint256 c = a + b; 24 | if (c < a) return (false, 0); 25 | return (true, c); 26 | } 27 | } 28 | 29 | /** 30 | * @dev Returns the substraction of two unsigned integers, with an overflow flag. 31 | * 32 | * _Available since v3.4._ 33 | */ 34 | function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { 35 | unchecked { 36 | if (b > a) return (false, 0); 37 | return (true, a - b); 38 | } 39 | } 40 | 41 | /** 42 | * @dev Returns the multiplication of two unsigned integers, with an overflow flag. 43 | * 44 | * _Available since v3.4._ 45 | */ 46 | function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { 47 | unchecked { 48 | // Gas optimization: this is cheaper than requiring 'a' not being zero, but the 49 | // benefit is lost if 'b' is also tested. 50 | // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 51 | if (a == 0) return (true, 0); 52 | uint256 c = a * b; 53 | if (c / a != b) return (false, 0); 54 | return (true, c); 55 | } 56 | } 57 | 58 | /** 59 | * @dev Returns the division of two unsigned integers, with a division by zero flag. 60 | * 61 | * _Available since v3.4._ 62 | */ 63 | function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { 64 | unchecked { 65 | if (b == 0) return (false, 0); 66 | return (true, a / b); 67 | } 68 | } 69 | 70 | /** 71 | * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. 72 | * 73 | * _Available since v3.4._ 74 | */ 75 | function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { 76 | unchecked { 77 | if (b == 0) return (false, 0); 78 | return (true, a % b); 79 | } 80 | } 81 | 82 | /** 83 | * @dev Returns the addition of two unsigned integers, reverting on 84 | * overflow. 85 | * 86 | * Counterpart to Solidity's `+` operator. 87 | * 88 | * Requirements: 89 | * 90 | * - Addition cannot overflow. 91 | */ 92 | function add(uint256 a, uint256 b) internal pure returns (uint256) { 93 | return a + b; 94 | } 95 | 96 | /** 97 | * @dev Returns the subtraction of two unsigned integers, reverting on 98 | * overflow (when the result is negative). 99 | * 100 | * Counterpart to Solidity's `-` operator. 101 | * 102 | * Requirements: 103 | * 104 | * - Subtraction cannot overflow. 105 | */ 106 | function sub(uint256 a, uint256 b) internal pure returns (uint256) { 107 | return a - b; 108 | } 109 | 110 | /** 111 | * @dev Returns the multiplication of two unsigned integers, reverting on 112 | * overflow. 113 | * 114 | * Counterpart to Solidity's `*` operator. 115 | * 116 | * Requirements: 117 | * 118 | * - Multiplication cannot overflow. 119 | */ 120 | function mul(uint256 a, uint256 b) internal pure returns (uint256) { 121 | return a * b; 122 | } 123 | 124 | /** 125 | * @dev Returns the integer division of two unsigned integers, reverting on 126 | * division by zero. The result is rounded towards zero. 127 | * 128 | * Counterpart to Solidity's `/` operator. 129 | * 130 | * Requirements: 131 | * 132 | * - The divisor cannot be zero. 133 | */ 134 | function div(uint256 a, uint256 b) internal pure returns (uint256) { 135 | return a / b; 136 | } 137 | 138 | /** 139 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 140 | * reverting when dividing by zero. 141 | * 142 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 143 | * opcode (which leaves remaining gas untouched) while Solidity uses an 144 | * invalid opcode to revert (consuming all remaining gas). 145 | * 146 | * Requirements: 147 | * 148 | * - The divisor cannot be zero. 149 | */ 150 | function mod(uint256 a, uint256 b) internal pure returns (uint256) { 151 | return a % b; 152 | } 153 | 154 | /** 155 | * @dev Returns the subtraction of two unsigned integers, reverting with custom message on 156 | * overflow (when the result is negative). 157 | * 158 | * CAUTION: This function is deprecated because it requires allocating memory for the error 159 | * message unnecessarily. For custom revert reasons use {trySub}. 160 | * 161 | * Counterpart to Solidity's `-` operator. 162 | * 163 | * Requirements: 164 | * 165 | * - Subtraction cannot overflow. 166 | */ 167 | function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 168 | unchecked { 169 | require(b <= a, errorMessage); 170 | return a - b; 171 | } 172 | } 173 | 174 | /** 175 | * @dev Returns the integer division of two unsigned integers, reverting with custom message on 176 | * division by zero. The result is rounded towards zero. 177 | * 178 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 179 | * opcode (which leaves remaining gas untouched) while Solidity uses an 180 | * invalid opcode to revert (consuming all remaining gas). 181 | * 182 | * Counterpart to Solidity's `/` operator. Note: this function uses a 183 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 184 | * uses an invalid opcode to revert (consuming all remaining gas). 185 | * 186 | * Requirements: 187 | * 188 | * - The divisor cannot be zero. 189 | */ 190 | function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 191 | unchecked { 192 | require(b > 0, errorMessage); 193 | return a / b; 194 | } 195 | } 196 | 197 | /** 198 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 199 | * reverting with custom message when dividing by zero. 200 | * 201 | * CAUTION: This function is deprecated because it requires allocating memory for the error 202 | * message unnecessarily. For custom revert reasons use {tryMod}. 203 | * 204 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 205 | * opcode (which leaves remaining gas untouched) while Solidity uses an 206 | * invalid opcode to revert (consuming all remaining gas). 207 | * 208 | * Requirements: 209 | * 210 | * - The divisor cannot be zero. 211 | */ 212 | function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 213 | unchecked { 214 | require(b > 0, errorMessage); 215 | return a % b; 216 | } 217 | } 218 | } --------------------------------------------------------------------------------