# Tezos Contract design ## Design Requirement - Use bytes as the type of fingerprint - the fingerprint bytes currently will be the `abi.encode` result which comes from ethereum - This is to ensure the id will be the same as the ethereum blockchain - Provide an `authorized_transfer` for delegating token transfer from the token owner - each transfer request includes a expiry time - the messages for signing will be packed using the same way that tezos PACK assembly does. ## Contract ### Overview - Issuance flow diagram ```mermaid sequenceDiagram participant AD as Admin participant FF as FeralFile participant AV as Account Vault participant TC as Tezos Contract AD->>+FF: Register exhibition artworks FF->>+AV: Register exhibition artworks AV->>+TC: Register artworks TC-->>-AV: Ok AV-->>-FF: TxID FF->>-FF: Wait for blockchain confirmation AD->>+FF: Issue exhibition FF->>+AV: Mint AP edition token AV->>+TC: Mint edition TC-->>-AV: Ok AV-->>-FF: TxID FF->>FF: Wait for blockchain confirmation FF->>+AV: Issue the rest of editions AV->>+TC: Mint edition TC-->>-AV: Ok AV-->>-FF: TxID FF->>FF: Wait for blockchain confirmation FF->>+AV: Send editions to FF AV->>+TC: Authorized transfer TC-->>-AV: Ok AV-->>-FF: TxID FF->>FF: Wait for blockchain confirmation FF->>+AV: Send editions to curator & artists AV->>+TC: Authorized transfer TC-->>-AV: Ok AV-->>-FF: TxID FF->>-FF: Wait for blockchain confirmation ``` ### On-demand Entrypoints of FeralFile FA2 Contract #### register_artworks To register artworks. The fingerprint will be used to generate the id of an artwork. It can not be duplicated. ```ligo type artwork_param = [@layout:comb] { title : string; artist_name : string; fingerprint : bytes; // packed fingerprint max_edition : nat; } let register_artworks(param: artwork_param list) ``` From [design requirement](/#Design-Requirement), we use the ethereum `abi.encode` packed result as fingerprint. #### mint_editions To mint editions to specific users. The `artwork_id` is from `register_artwork` result. The `token_info` should at least include token metadata link. ```ligo type ff_token_metadata = [@layout:comb] { token_info: (string, bytes) map; artwork_id: bytes; edition: nat; } type mint_edition_param = [@layout:comb] { owner : address; tokens : ff_token_metadata list; } let mint_editions(param : mint_edition_param list) ``` #### authorized_transfer From [design requirement](/#Design-Guide), admin(trustee) could transfer a certain edition to an address with owner's signature(consent). The signature is signed with the concatenation of destination address, token_id and expiry. The amount should always be 1 because there's no way to issue same edition twice. ```ligo type authorized_transfer_destination = [@layout:comb] { to_ : address; token_id : token_id; amount : nat; sig : signature; } type authorized_transfer = [@layout:comb] { from_ : address; pk : key; expiry : timestamp; txs : authorized_transfer_destination list; } let authorized_transfer (param : authorized_transfer list) ``` ### Storages #### Bitmark vs Tezos Asset Structure In bitmark blockchain, we have assets and bitmarks(issuances). In Feral File, we create assets for each artwork and issue editions in bitmarkss. ``` +-------+ +---------+ | Asset | <-- | Bitmark | +-------+ +---------+ (Artwork) (Editions) ``` We create a unique contract for each exhibition. Artists register their artworks into the contract. Based on the registered artwork, we mint edition tokens. ``` +------------+ +---------+ +---------+ | Exhibition | <-- | Artwork | <-- | Token | +------------+ +---------+ +---------+ ``` #### Global storage Each Tezos contract has a storage object which is an object maintains all contract related attributes. This is the global storage structure for our exhibition contract. ```ligo type asset_storage = { // exhibition metadata exhibition_title : string; secondary_sale_royalty_bps : nat; max_royalty_bps : nat; // determine tokens in this contract can be burned burnable : bool; // determine tokens in this contract can bridger to other blockchain bridgeable : bool; artworks : artwork_storage; assets : token_storage; admin : admin_storage; metadata : contract_metadata; token_attribute : token_attribute_storage; trustee : address; } ``` #### Artwork This is the structure for artworks. Some attributes are read-only and is not used by any entrypoints. ::info:: Artwork is saving in map. Please ensure not to create a lot of artwork into the contract. This would make the contract unusable. ```ligo type artwork = { title : string; artist_name : string; fingerprint : bytes; max_edition : nat; token_start_id : nat; royalty_address : address; } ``` #### Token Attribute Token attributes is a structure for preserving token status. ```ligo type token_attribute = { artwork_id : bytes; edition_number : nat; burned : bool; } ``` ### Metadata For each token, we will prepare a document as the following and upload to IPFS. The IPFS link will set into `token_info` inside token_metadata of each token in contract storage. ```json { "name": "Unsupervised — Data Universe — MoMA by Refik Anadol #2180/5000, 1 AP", "description": "Medium: Digital Painting / Year: 2022 / @bjorncalleja ", "medium": "video", "fingerprint": "0bac909097f7ef14493d4e8cc14ad75160da568296bf00438a3bdf811871e0c2", "metadataVersion": "v1", "rights": "No License / All Rights Reserved", "minter": "KT1Aq4wWmVanpQhq4TTfjZXB5AjFpx15iQMM", "editionIndex": 2180, "editionNumber": "#2180", "totalEdition": 5000, "date": "2022-03-01T19:13:35.185Z", "tags": [ "feralfile", "art" ], "symbol": "FF017", "artifactUri": "ipfs://QmU5YyvRezezHxH9TZa3yc6DUTajRRtT5nfafumnF7xDKk", // full artwork "displayUri": "ipfs://QmZ4m8wruiuoaabg2spM1f2dD8rvYYzuXickWqrEE6chYK", // preview "thumbnailUri": "ipfs://QmYXD99xYwn7jkkgmVSAmZkSQZ9rxvdatSFbCY1McXnN2s", "image": "ipfs://QmZ4m8wruiuoaabg2spM1f2dD8rvYYzuXickWqrEE6chYK", "exhibitionInfo": { "basePrice": "USDC100", "note": "Unsupervised is part of Machine Hallucinations, Refik Anadol Studio&rsquo;s ongoing project exploring data aesthetics based on collective visual memories. Since the inception of the project in 2016, Anadol has utilized machine intelligence as a collaborator of human consciousness, specifically DCGAN, PGAN, and StyleGAN algorithms trained on vast datasets to unfold unrecognized layers of our external realities. Anadol and his team collect data from digital archives and publicly available resources, and process these datasets with machine-learning classification models. As a masterfully curated multi-channel experience, Machine Hallucinations brings a self-regenerating element of surprise to the audience and offers a new form of sensorial autonomy via cybernetic serendipity. \n\nUnsupervised emerges from such an aesthetic/scientific vision and processes 138,151 pieces of metadata from the vast collection of The Museum of Modern Art in the mind of a machine. Using StyleGAN2 ADA to capture the machine&rsquo;s transformative &ldquo;hallucinations&rdquo; of modern art in a multi-dimensional space, Anadol trains a unique AI model with subsets of the archive of MoMA&rsquo;s collection of artworks, creating embeddings in 1024 dimensions. The sorted image datasets are then clustered into thematic categories to better understand the semantic context of data. This expanding data universe not only represents the interpolation of data as synthesis, but also becomes a latent cosmos in which hallucinatory potential arises from a novel form of artistic creativity interpreting MoMA&rsquo;s unparalleled collection of modern and contemporary art. Spanning more than 200 years of art, from paintings to photography to cars to video games, the MoMA collection is an extraordinary data set&mdash;within which works from artistic movements such as Surrealism, not unlike Unsupervised, explored automatism, chance, and systems to generate unprecedented new art forms. \n\nThis is work that resonates aesthetically and also pushes machine-learning research into new territories. Anadol is in dialogue with scholars such as Jaakko Lehtinen, Distinguished Research Scientist at NVIDIA Research, who are inventing the technologies that the artist is using. On seeing this new body of work, Lehtinen remarked: \n\n<p class=\"m-l-56 display-inline-block\">This is the beauty of fundamental research: to see the progress we&rsquo;ve made on a hard, technical machine learning problem being unexpectedly channeled to serve such astounding creativity is extremely satisfying. We&rsquo;re thrilled to witness the deepening interplay between art and AI research, and eagerly looking forward to seeing what we can do together in the future.</p> \n\nThe AI-based abstract images and shapes that result from the machine&rsquo;s unsupervised learning of modern art are dictated by the Museum&rsquo;s collection archive, weighted toward the special exhibition of new artworks at MoMA this fall. The AI data pigmentation, in turn, captures the movement in the latent space created by autonomous machine hallucinations. Each data connection is driven by an edge-detection algorithm and colorized by the density of its previous and next latent coordinates. In other words, the machine allows the artist to trace its &ldquo;unconscious decisions,&rdquo; in a network of intricate and poetic connections.", "noteTitle": "Deep Modern" }, "creators": [ "tz2Hz4TVJZjoQVks4SfWgt38RfZTmrHmVH62" ], "formats": [ { "uri": "ipfs://QmU5YyvRezezHxH9TZa3yc6DUTajRRtT5nfafumnF7xDKk", "mimeType": "image/jpeg", "fileSize": 376490, "fileName": "IMG_0490.JPG", "dimensions": { "value": "1000x1500", "unit": "px" } }, { "uri": "ipfs://QmZ4m8wruiuoaabg2spM1f2dD8rvYYzuXickWqrEE6chYK", "mimeType": "image/jpeg", "fileName": "cover-IMG_0490.jpg", "fileSize": 179874, "dimensions": { "value": "683x1024", "unit": "px" } }, { "uri": "ipfs://QmYXD99xYwn7jkkgmVSAmZkSQZ9rxvdatSFbCY1McXnN2s", "mimeType": "image/jpeg", "fileName": "thumbnail-IMG_0490.jpg", "fileSize": 26528, "dimensions": { "value": "233x350", "unit": "px" } } ], "attributes": [ { "name": "Edition of", "value": "5000, 1 AP" }, { "name": "Artist", "value": "Refik Anadol" } ], "decimals": 0, "royalties": { "decimals": 3, "shares": { "KT1DWnLiUkNtAQDErXxudFEH63JC6mqg3HEx": 100 "KT1Ndb5S46Y4hewjcGg14ffxPtwxggM2GA83": 50 } } } ``` ## References #### Ligo ##### Tutorials - [Beginner's Guide to Tezos Smart Contracts with LIGO](https://www.youtube.com/watch?v=Ozf250c52AI) - [How to extend an FA2 contract in CameLigo](https://medium.com/coinmonks/how-to-extend-an-fa2-contract-in-cameligo-a673858cbe2b) - [Michelson Interoperability in Ligo](https://medium.com/swlh/michelson-interoperability-in-ligo-d3759fb6039c) - [A Short Introduction to OCaml](https://www.enseignement.polytechnique.fr/profs/informatique/Jean-Christophe.Filliatre/14-15/INF549/slides.pdf) - [Declaring functions (currying)](https://ligolang.org/docs/language-basics/functions/#declaring-functions) - [Understand your bigmap](https://www.marigold.dev/post/understand-your-bigmap) - [Do FA2 entrypoints need to be at the top level in order to comply with the spec?](https://tezos.stackexchange.com/questions/3910/do-fa2-entrypoints-need-to-be-at-the-top-level-in-order-to-comply-with-the-spec) ##### Ocaml - https://www2.ocaml.org/learn/tutorials/basics.html - [What is the difference between the `fun` and `function` keywords?](https://stackoverflow.com/questions/1604270/what-is-the-difference-between-the-fun-and-function-keywords) #### Tezos ##### Sign message - [Sign & Inject :: TezosGuides](https://tezosguides.com/wallet_integration/basics/sign/) - [WalletBeacon Sign Payload](https://docs.walletbeacon.io/guides/sign-payload/) - [Tezos Signing Operations](https://www.ocamlpro.com/blog/2018_11_21_an_introduction_to_tezos_rpcs_signing_operations) - [Signing data | Taquito](https://tezostaquito.io/docs/signing/) ##### Pach / Hash - [How are integers serialized in Tezos?](https://tezos.stackexchange.com/questions/2878/how-are-integers-serialized-in-tezos) - [What are the differences between key, key_hash, address, contract and signature in Michelson?](https://tezos.stackexchange.com/questions/2311/what-are-the-differences-between-key-key-hash-address-contract-and-signature) #### Others - [Obsoleted Smart.Py development resource](/DnL-WGzNTdWzW3BY07V9uw) - [Michelson Anti-patterns](https://tezos.gitlab.io/developer/michelson_anti_patterns.html)