Decoding sensible contracts — 03

The Merge is a profitable NFT venture created by an nameless artist Pak. This venture offered for $91 million, and it’s the highest sales value by a living artist for a single artwork in a public sale.
The Merge is a dynamic on-chain NFT, with a singular token mechanism known as ‘merge’. The photographs of this NFT assortment are merely circles of various sizes, which characterize completely different plenty. Every account can solely personal one NFT on this assortment. Should you personal an NFT and buy one other one, two NFTs will merge into one, with their plenty added collectively, and the circle grows in measurement.
On this article, I’ll clarify the implementation of the merge mechanism. If you wish to be taught extra, I’ve created this notion page that explains all of the variables/capabilities within the sensible contract.
The contract tackle is 0xc3f8a0F5841aBFf777d3eefA5047e8D413a1C9AB
and yow will discover the sensible contract in Etherscan. On this article, we’ll look into the primary contract Merge.sol.
How can two tokens merge into one? The magic occurs within the _merge
perform. When transferring a token, the contract checks if the recipient tackle already owns a token. If that’s the case, it would set off the _merge
perform, as proven beneath.
The inputs are two tokenIds. This perform first checks the mass of two tokens utilizing perform decodeMass
, then merges the smaller token into the larger one by updating the mapping _values
with an increment of the smaller mass. To be taught extra about decodeMass
and _value
, please discuss with this notion page. It incorporates definitions and explanations of all variables/capabilities.
However, the smaller token will likely be burnt. A part of the burning occurs on this perform by deleting the smaller token in _value
. Many of the burning occurs outdoors of this _merge
perform with the help of the returned worth tokenIdSmall
. Unsure why if that is one of the best ways to construction the code, I believe there are room for enchancment and added concepts on this notion page.
This contract retains observe of the variety of instances every token is merged utilizing a mapping _mergeCount
. And this mapping will get up to date after the merge.
Lastly, the token with the biggest mass amongst all tokens is named alpha token, with its id and mass saved in variables _alphaId
and _alphaMass
. This perform checks if the mass of the merged token is bigger than _alphaMass
, by which case _alphaId
and _alphaMass
will likely be up to date.
The SVG technology code is within the second contract MergeMetadata.sol. With out complicating you with all of the element, a circle in an SVG is represented utilizing <circle id=’c’ cx=’1000' cy=’1000' r=’_RADIUS_TAG’/>
. The _RADIUS_TAG
is generated dynamically based mostly on the mass of every token.
There you may have it! I hope you discover this tutorial useful and enjoyable. If you wish to be taught extra about this sensible contract, this notion web page incorporates complete rationalization for all variables/capabilities on this sensible contract.
Please be at liberty to go away a remark when you’ve got any questions or solutions. I’m additionally open to solutions. If you recognize an fascinating venture and wish me to take a look at it, let me know!
Need to Join?Please be at liberty to achieve out (my LinkedIn) when you've got any questions, suggestions, and even only a random chat.