CryptoPunks v1 vs CryptoPhunks

建立於 差異永不過期
121 刪除
140 行
290 新增
314 行
/**
// SPDX-License-Identifier: UNLICENSE
*Submitted for verification at Etherscan.io on 2017-06-17
pragma solidity ^0.8.0;
*/


pragma solidity ^0.4.8;
import "@openzeppelin/contracts/access/Ownable.sol";
contract CryptoPunks {
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/utils/Strings.sol";


// You can use this hash to verify the image file containing all the punks
contract CryptoPhunksV2 is Ownable, ERC721Enumerable, ReentrancyGuard {
string public imageHash = "ac39af4793119ee46bbff351d8cb6b5f23da60222126add4268e261199a2921b";
using Counters for Counters.Counter;
using Strings for uint256;


address owner;
// You can use this hash to verify the image file containing all the phunks
string public constant imageHash =
"122dab9670c21ad538dafdbb87191c4d7114c389af616c42c54556aa2211b899";


string public standard = 'CryptoPunks';
constructor() ERC721("CryptoPhunksV2", "PHUNK") {}
string public name;
string public symbol;
uint8 public decimals;
uint256 public totalSupply;


uint public nextPunkIndexToAssign = 0;
bool public isSaleOn = false;


//bool public allPunksAssigned = false;
bool public saleHasBeenStarted = false;
uint public punksRemainingToAssign = 0;
uint public numberOfPunksToReserve;
uint public numberOfPunksReserved = 0;


//mapping (address => uint) public addressToPunkIndex;
uint256 public constant MAX_MINTABLE_AT_ONCE = 50;
mapping (uint => address) public punkIndexToAddress;


/* This creates an array with all balances */
uint256[10000] private _availableTokens;
uint256 private _numAvailableTokens = 10000;
mapping (address => uint256) public balanceOf;
uint256 private _numFreeRollsGiven = 0;


struct Offer {
mapping(address => uint256) public freeRollPhunks;
bool isForSale;

uint punkIndex;
uint256 private _lastTokenIdMintedInInitialSet = 10000;
address seller;

uint minValue; // in ether
function numTotalPhunks() public view virtual returns (uint256) {
address onlySellTo; // specify to sell only to a specific person
return 10000;
}

function freeRollMint() public nonReentrant() {
uint256 toMint = freeRollPhunks[msg.sender];
freeRollPhunks[msg.sender] = 0;
uint256 remaining = numTotalPhunks() - totalSupply();
if (toMint > remaining) {
toMint = remaining;
}
_mint(toMint);
}

function getNumFreeRollPhunks(address owner) public view returns (uint256) {
return freeRollPhunks[owner];
}

function mint(uint256 _numToMint) public payable nonReentrant() {
require(isSaleOn, "Sale hasn't started.");
uint256 totalSupply = totalSupply();
require(
totalSupply + _numToMint <= numTotalPhunks(),
"There aren't this many phunks left."
);
uint256 costForMintingPhunks = getCostForMintingPhunks(_numToMint);
require(
msg.value >= costForMintingPhunks,
"Too little sent, please send more eth."
);
if (msg.value > costForMintingPhunks) {
payable(msg.sender).transfer(msg.value - costForMintingPhunks);
}
}


// A record of punks that are offered for sale at a specific minimum value, and perhaps to a specific person
_mint(_numToMint);
mapping (uint => Offer) public punksOfferedForSale;
}


mapping (address => uint) public pendingWithdrawals;
// internal minting function
function _mint(uint256 _numToMint) internal {
require(_numToMint <= MAX_MINTABLE_AT_ONCE, "Minting too many at once.");


event Assign(address indexed to, uint256 punkIndex);
uint256 updatedNumAvailableTokens = _numAvailableTokens;
event Transfer(address indexed from, address indexed to, uint256 value);
for (uint256 i = 0; i < _numToMint; i++) {
event PunkTransfer(address indexed from, address indexed to, uint256 punkIndex);
uint256 newTokenId = useRandomAvailableToken(_numToMint, i);
event PunkOffered(uint indexed punkIndex, uint minValue, address indexed toAddress);
_safeMint(msg.sender, newTokenId);
event PunkBought(uint indexed punkIndex, uint value, address indexed fromAddress, address indexed toAddress);
updatedNumAvailableTokens--;
event PunkNoLongerForSale(uint indexed punkIndex);
}
_numAvailableTokens = updatedNumAvailableTokens;
}


/* Initializes contract with initial supply tokens to the creator of the contract */
function useRandomAvailableToken(uint256 _numToFetch, uint256 _i)
function CryptoPunks() payable {
internal
// balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens
returns (uint256)
owner = msg.sender;
{
totalSupply = 10000; // Update total supply
uint256 randomNum =
punksRemainingToAssign = totalSupply;
uint256(
numberOfPunksToReserve = 1000;
keccak256(