CryptoPunk is the world's first decentralized NFT trading market
CryptoPunk is not only a top blue-chip NFT project (the floor price is 70 ETH about 15 W),It is also the source of inspiration for the subsequent ERC 721 standard protocol.
The NFT trading market is currently the highest-income track in the entire blockchain industry except for Ethereum itself, while OpenSea, x2y2, and LooksRare are currently the top 3 platforms, and their combined transaction volume accounts for more than 99%.
Today we will interpret CryptoPunk's mere 230 lines of source code, its implementation of the order model and transaction process,Explore the pros and cons of its built-in dedicated NFT marketplace, and also paved the way for the subsequent step-by-step source code analysis of the contract models of the three major NFT trading markets.
first level title
CryptoPunk's built-in trading market
image description

[Source Code Interpretation] What exactly is the NFT you bought?
Further reading:[Source Code Interpretation] What exactly is the NFT you bought?
first level title
1. Punk's beautiful order model
Recall that how we buy and sell goods in reality, there are probably three categories
The seller quotes, the buyer pays → equal to supermarket purchase
The buyer quotes the price and the seller agrees → it is equal to bargaining at the vegetable market
Offline bargaining, on-chain transaction → equal to offline notarized auction
Either way, in order to finally reach a deal, it is necessary to perform an exchange, not only to prevent the seller from not giving the goods, but also to prevent the buyer from not giving money.
Although the blockchain technology perfectly solves the problem of not giving money, it also brings the pain point of difficulty in bargaining. After all, "cutting the price with a knife" must be uploaded to the chain, and it is definitely not possible to cut the decimal point like Pinduoduo. 6 digits (- .-)
Punk's market supports these three types of transactions at the same time. It can be quoted by the seller, the buyer can quote, or the contract can help you complete the transaction after negotiation. There is no royalties deducted in the whole process, and the 230-line short code also eliminates the back door possibility of
His order structure is very simple and divided into two types:secondary title
1.1. The seller’s offer list Offer
Like the standard NFT, each Punk has a unique ID, so each punk has an exclusive Offer order book. This exclusive means that if I re-quote whether it is a price increase or a price reduction, it will replace the previous offer. one.
Here, whether it is for sale is marked by isForSale, and the designated buyer is marked by onlySellTo, which is used for off-chain bargaining and on-chain execution of transaction functions

We can clearly feel that the order model is very simple, and there is not even a common order validity period. As long as the seller of the pending order does not take the initiative to cancel it, it is always possible for the buyer to buy it at this price
Special Note: Although this is similar to opensea’s long-term authorized sell order, there will be no abnormal price transactions, because Punk will cancel the historical quotation records when transferring
1.2. Buyer Bid Bid
The bidding form is also very simple, basically equal to (I, want to buy, this, how much for this) quadruple.
In addition to the form where the seller bids and waits to buy, anyone can declare which punk I am willing to buy with an amount of x by submitting a bid. The hasBid variable is also provided here to reflect whether the current bid is valid
The buyer can cancel the previous bid at any time, but if there is no higher price coverage, the original bid price will be retained (although it has become invalid), this is the information sharing design for assisting other buyers in pricing bids

When bidding, where is the money? ? In fact, it's already in the Punk contract.
1.3. Summary
1.3. Summary
After understanding its core order book structure, it caught the mouse’s tail. In fact, its corresponding methods are all reviewing whether the current transaction is reasonable and legal. After confirming that it is legal, add, delete, check and modify the order data

For example, after the seller makes a deal, it will modify the total amount of Punk held by the user recorded in balanceOf, and will also modify the core punkIndexToAddress which records which PunkID owner is which information
NFT Leasing Proposal EIP-5006 Enters Final Review! Make it possible to change the chain of large overseas games
first level title
secondary title
2.1. The seller quotes first, and the buyer bids again
If I want to sell Punk as one of the distinguished users who hold Punk, I need 3 steps
The seller quotes -> the buyer submits the purchase order -> the seller withdraws the proceeds
expand to see
Seller’s offer: The seller executes the offerPunkForSale setting and is willing to sell a certain nft at a certain price, and then the order book is as follows

Buyer buys: Execute the buyPunk method and the value of the transaction exceeds the minValue of the seller to make the purchase successful. **
The seller needs to call withdraw again to withdraw his current income (that is, the value deposited into the contract when the buyer buys)
If the seller suddenly does not want to sell: call punkNoLongerForSale to quote
What process could be simpler than this?
secondary title
2.2. The buyer bids first, and the seller confirms first
If I don't own Punk but have a soft spot for a certain ID, I can also bid first in 3 steps:
Buyer Bid Bid->Seller Accepts->Seller Withdraws Proceeds
expand to see
Buyer offer: call enterBidForPunk, and use eth as value, and the money is stored in the punk contract
The seller accepts: call acceptBidForPunk, and accept the transaction at the price quoted by the buyer. After execution, the buyer has already obtained the punk NFTID
Withdrawal of proceeds by the seller: need to execute withdraw again to withdraw all withdrawable amount
secondary title
2.3. Off-chain bargaining and on-chain execution
The last one is simpler, that is, the price has been completely negotiated, and the seller approves the price.
offerPunkForSaleToAddress not only sets the price for the order book, but also sets a unique buyer address onlySellTo, only this address can complete the order
first level title
3. How to evaluate the trading market of Punk?
At first glance, it is a very standard minimum NFT transaction model, which can indeed accurately, stably and reliably realize the core link of the transaction, butThere are gains and losses, what are his advantages, and what is missing
3.1. Low gas cost
[Source Code Interpretation] What exactly is the NFT you bought?[Source Code Interpretation] What exactly is the NFT you bought?
Therefore, the overall gas consumption in the Punk market is not high. The author calculates that after completing the whole process of buying, selling and extracting, the gas consumption is roughly 30 W (including the total expenditure of both buyers and sellers)
Sort by transaction GAS: Punk< opensea < GEM < Genie < X2Y2< Looksrare
3.2. No handling fee
At present, it can be seen on the chain that Punk has a total of 21 W transactions. If 5 transactions can be completed in one order, there will be 4 W transfers. For such a top blue chip with a market value of billions, not charging royalties is nothing short of violent. ah
Of course, it is unfair to compare such a built-in trading service with a full-time trading market, but it is precisely because punk’s built-in transaction completion function is far from a complete functional system, so there are various markets. Opportunity
secondary titlePunk( 0% )< X2Y2( 0.5% ) < Looksrare( 2% ) < OS( 2.5% )
3.3. Evaluation of the shortcomings of the mechanism
Conclusion 1: The buying and selling mechanism is not conducive to the liquidity pool
Liquidity is very important for NFT, and it is obviously cold water to go to the chain every time a quotation is made. Sellers are not willing to move if they are not short of money, and buyers lack motivation when it is difficult to make a deal. Therefore, the bidder is charged and requires lock-in Assets to Punk Although there will be no deduction failure, it will also lead to the loss of the time value of the buyer's assets
In this regard, platforms such as Os later adopted the signature method to match purchase intentions off-chain. Quotations require almost no gas and only order results need to be registered on the chain to execute the transfer.
This blow is a competition for efficiency between centralization and decentralization. Obviously, the current market still needs efficiency
Conclusion 2: The order model is not conducive to batch operations
The simplicity of the Punk order model can be regarded as a model of the transaction model, but what about the demand for batch transactions?
Seller: get each id and each order, and confirm the transaction
Buyer: get every bid for every id, and wait for the deal
Although the income funds have a design that can be accumulated and withdrawn in batches, it is not the point
The batch quotation transaction is now a must in the NFT market
Both x2y2 and Looksrare are making efforts at this point as a siege against os, and even use aggregators such as Gem to break through the limitations of traffic pools, and the latest SeaPort protocol of os also implements a new order model for bundled transactions, so that any asset can The combination corresponds to any asset combination and directly realizes market transactions
However, Punk's source code is too advanced and lacks the function of withholding authorization, so there is no chance of batch transactions
Conclusion 3: A single auction process is not conducive to matching transactions and pricing
The transaction requires compromise, and the current value of NFT also needs to be gamed through the transaction. How to price NFT has always been a huge problem
Therefore, there are four common auction mechanisms:
English auction. Open bidding to pick up the price, the highest bidder wins
Dutch auction. The price decreases from high to low, and the first bidder wins
First price auction. Make a separate bid for the lot, without knowing the bids of other bidders
Second Price Auction. Similar to above, except that the highest bidder at the end wins, but only pays the second highest price
And these auction mechanisms (English auction and Dutch auction) are the basic functions of Opensea, which are conducive to promoting transactions and pricing
Yingpai: A limited time auction, which does not take up the capital cost of high-value blue chips, but also has a time buffer to fit the game results of each group
finally

finally
Although I complained a lot, such a streamlined and beautiful NFT protocol + NFT trading market was implemented in 2017 with only 230 lines of code, and it has evolved into one of the most valuable blue-chip NFTs in the world. It is a product worth studying
In the future, the trading market may not be dominated by one head, and more vertical categories will also have built-in trading functions in their own NFTs, such as StepN, Axie Infinity, NBA Top Shot,And after Seaport is open source and open, the built-in market may not be the endorsement of the condensed version
In the follow-up, the author will continue to study OpenSea, X2Y2, Looksrare, Gem and other leading NFT market platforms, starting from the contract, to see its advantages and limitations. If you are interested, please follow up and follow up~


