ecadlabs / taquito

A library for building dApps on the Tezos Blockchain - JavaScript / TypeScript
https://taquito.io
Apache License 2.0
298 stars 116 forks source link

Token Metadata support for TZIP-7/FA1.2 contracts #593

Closed jevonearth closed 3 years ago

jevonearth commented 3 years ago

A proposal (https://gitlab.com/tzip/tzip/-/merge_requests/140) to use FA2/TZIP-12 metadata in FA1.2 contracts is in the process of being finalised.

The single difference is that FA1.2 contracts use only token id 0.

An example FA1.2 contract with token metadata from Kolibri exists here https://delphi.tzstats.com/KT1CiJv61tJ7CUK7oKMmNYRSjpxGJ4GC9TX5

Appears to work okay in the Taquito Metadata explorer. See: https://taquito-metadata-explorer.netlify.app/#/delphinet/KT1CiJv61tJ7CUK7oKMmNYRSjpxGJ4GC9TX5

We need to evaluate the impact of this in Taquito, and how to document/present how to get fa1.2 metadata. The provider is named tzip-12 at the moment.

Acceptance criteria:

michaelkernaghan commented 3 years ago

The delphi net material is no longer avilabale. Perhaps the equivalent from mainnet is here: https://better-call.dev/mainnet/KT1K9gCRgaLRFKTErYt1wVxA3Frb9FjasjTV/code

michaelkernaghan commented 3 years ago

The example above uses a governance contract that is at: https://better-call.dev/mainnet/KT1JBmbYxTv3xptk2CadgEdMfjUCUXKEfe5u/operations

michaelkernaghan commented 3 years ago

I have found a simpler example to follow by Michael Klien: https://github.com/tqtezos/lorentz-contract-metadata

michaelkernaghan commented 3 years ago

The existing Test: tzip12-token-metadata.spec.ts is for tokens that have multiple ids, not tokens that are only id = 0

michaelkernaghan commented 3 years ago

Here is the originated contract getMetadata entrpoint on Better Call Dev: https://better-call.dev/granadanet/KT1TS8gncRVzT3RsZYbXXht6nxxvUXYd66cP/interact?entrypoint=getMetadata

the example contract I have made by Michael Klien with Lorentz does not have a metadata bigmap

The Taquito docs say: There are two scenarios to obtain the metadata of a token:

They can be obtained from executing an off-chain view named token_metadata present in the contract metadata or from a big map named token_metadata in the contract storage.

The storage is just this:

storage (pair (big_map address (pair nat (map address nat)))
      (pair address (pair bool nat)));

There is a getMetadata entrypoint that has parameter:

  (pair %getMetadata (list nat)
                                 (contract (list (pair nat
                                                     (pair string
                                                           (pair string
                                                                 (pair nat
                                                                       (map
                                                                         string
                                                                         string))))))))))));

and the code ends with this:

 { DUP ;
               CAR ;
               DIP { CDR } ;
               DIP { DIP { DUP } ; SWAP } ;
               PAIR ;
               CAR ;
               ITER { PUSH nat 0 ;
                      COMPARE ;
                      EQ ;
                      IF
                        {}
                        { PUSH string "single token only has id 0" ; FAILWITH } } ;
               PUSH (list (pair nat
                            (pair string
                                  (pair string (pair nat (map string string)))))) { Pair 0 (Pair "TOK" (Pair "Token" (Pair 0 {}))) } ;
               DIP { AMOUNT } ;
               TRANSFER_TOKENS ;
               NIL operation ;
               SWAP ;
               CONS ;
               PAIR } } } } }}`;

for this contract, the tzip12 and tzip16 abstract extensions do not apply

michaelkernaghan commented 3 years ago

If the token id is not 0, then it fails. That defines the FA2 part. If it is 0, it creates the token.

I have not figured out how to obtain the token for this contract with Taquito.

michaelkernaghan commented 3 years ago

The above contract requires to be called by another contract. It won't be appropriate for this test.

michaelkernaghan commented 3 years ago

The integration test "contract-originate-token-contract.spec.ts" creates a token from a similar contract, and does not have metadata. So that test shows a tzip-7 contract with tokens.

Innkst commented 3 years ago

Closing based on the above comments.