Skip to content

Commit

Permalink
commit of extesnion version of fa/lib 1.1.1 for debug
Browse files Browse the repository at this point in the history
  • Loading branch information
zamrokk committed Feb 20, 2024
1 parent d550efe commit 5d617f8
Show file tree
Hide file tree
Showing 100 changed files with 16,324 additions and 6 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ Follow these steps to set up a Taqueria project:
1. Install the `ligo/fa` library, which provides templates for creating FA2 tokens:

```bash
echo '{ "name": "app", "dependencies": { "@ligo/fa": "^1.0.9" } }' >> ligo.json
TAQ_LIGO_IMAGE=ligolang/ligo:1.1.0 taq ligo --command "install @ligo/fa"
echo '{ "name": "app", "dependencies": { "@ligo/fa": "^1.1.1" } }' >> ligo.json
TAQ_LIGO_IMAGE=ligolang/ligo:1.3.0 taq ligo --command "install @ligo/fa"
```

This command can take some time because it downloads and installs the `@ligo/fa` package.
Expand Down Expand Up @@ -328,7 +328,7 @@ The code also defines the type for the value that entrypoints return: a list of
1. Save the contract and compile it by running this command:

```bash
TAQ_LIGO_IMAGE=ligolang/ligo:1.1.0 taq compile nft.jsligo
TAQ_LIGO_IMAGE=ligolang/ligo:1.3.0 taq compile nft.jsligo
```

Taqueria compiles the contract to the file `artifacts/nft.tz`.
Expand Down Expand Up @@ -384,7 +384,7 @@ The code also defines the type for the value that entrypoints return: a list of
1. Compile the contract:

```bash
TAQ_LIGO_IMAGE=ligolang/ligo:1.1.0 taq compile nft.jsligo
TAQ_LIGO_IMAGE=ligolang/ligo:1.3.0 taq compile nft.jsligo
```

1. Use one of these options to set up a Ghostnet account to use to deploy (originate) the contract:
Expand Down
4 changes: 2 additions & 2 deletions solution/.taq/state.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// WARNING: This file is autogenerated and should NOT be modified
{
"build": "0b37e42",
"configHash": "b8a9fefadba3d671471400307dddb7aef919ef9d64b4e03580b53550a980d928",
"configHash": "be3e18e596ca1de92147260bd11ceb666f4939638568ce8b6f76c1ba86156bc6",
"tasks": {
"ligo": {
"type": "npm",
Expand Down Expand Up @@ -89,7 +89,7 @@
"version": "0.1",
"schema": "1.0",
"alias": "ligo",
"postInstall": "node /home/zamrokk/training-nft-1/nft-marketplace/node_modules/@taqueria/lib-ligo/postinstall.js",
"postInstall": "node /home/zamrokk/training-nft-1/solution/node_modules/@taqueria/lib-ligo/postinstall.js",
"tasks": [
{
"task": "ligo",
Expand Down
12 changes: 12 additions & 0 deletions solution/.taq/testing-state.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@
"alias": "nft"
}
]
},
"@taqueria/plugin-taquito.deploy.1699872896612": {
"task": "deploy",
"plugin": "@taqueria/plugin-taquito",
"time": 1699872896612,
"output": [
{
"contract": "nft.tz",
"address": "KT1PBkqvCfSFaoSztuLd5AEGtWFhhEqMD81V",
"alias": "nft"
}
]
}
}
}
5 changes: 5 additions & 0 deletions solution_extension/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.DS_Store
artifacts
.taq/*-state.json
.taq/config.local.*.json
node_modules/
1 change: 1 addition & 0 deletions solution_extension/.ligo/repository_id
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8273581c-4ea5-460e-2f17-d458f3504157
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021-2023 the LigoLang team.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
SHELL := /bin/bash

ligo_compiler?=docker run --rm -v "$(PWD)":"$(PWD)" -w "$(PWD)" ligolang/ligo:1.2.0
# ^ Override this variable when you run make command by make <COMMAND> ligo_compiler=<LIGO_EXECUTABLE>
# ^ Otherwise use default one (you'll need docker)
PROTOCOL_OPT?=

project_root=--project-root .
# ^ required when using packages

help:
@grep -E '^[ a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'

compile = $(ligo_compiler) compile contract $(project_root) ./lib/$(1) -o ./compiled/$(2) $(3) $(PROTOCOL_OPT)
# ^ compile contract to michelson or micheline

test = $(ligo_compiler) run test $(project_root) ./test/$(1) $(PROTOCOL_OPT)
# ^ run given test file

compile: ## compile contracts
@if [ ! -d ./compiled ]; then mkdir -p ./compiled/fa2/nft && mkdir -p ./compiled/fa2/asset ; fi
@echo "Compiling contracts..."
@$(call compile,fa2/nft/nft.impl.mligo,fa2/nft/nft.impl.mligo.tz)
@$(call compile,fa2/nft/nft.impl.mligo,fa2/nft/nft.impl.mligo.json,--michelson-format json)
@$(call compile,fa2/asset/single_asset.impl.mligo,fa2/asset/single_asset.impl.mligo.tz)
@$(call compile,fa2/asset/single_asset.impl.mligo,fa2/asset/single_asset.impl.mligo.json,--michelson-format json)
@$(call compile,fa2/asset/multi_asset.impl.mligo,fa2/asset/multi_asset.impl.mligo.tz)
@$(call compile,fa2/asset/multi_asset.impl.mligo,fa2/asset/multi_asset.impl.mligo.json,--michelson-format json)
@echo "Compiled contracts!"
clean: ## clean up
@rm -rf compiled

deploy: deploy_deps deploy.js

deploy.js:
@echo "Running deploy script\n"
@cd deploy && npm i && npm start

deploy_deps:
@echo "Installing deploy script dependencies"
@cd deploy && npm install
@echo ""

install: ## install dependencies
@$(ligo_compiler) install

.PHONY: test
test: ## run tests (SUITE=permit make test)
ifndef SUITE
@$(call test,fa2/single_asset.test.mligo)
@$(call test,fa2/single_asset_jsligo.test.mligo)
@$(call test,fa2/multi_asset.test.mligo)
@$(call test,fa2/nft/nft.test.mligo)
@$(call test,fa2/multi_asset_jsligo.test.mligo)
@$(call test,fa2/nft/nft_jsligo.test.mligo)
@$(call test,fa2/nft/views.test.mligo)

## @$(call test,fa2/nft/e2e_mutation.test.mligo)
else
@$(call test,$(SUITE).test.mligo)
endif

lint: ## lint code
@npx eslint ./scripts --ext .ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# FA2 tokens

`ligo/fa` library provides :

- the [interface](./lib/fa2/common/tzip12.interfaces.jsligo) and [types](./lib/fa2/common/tzip12.datatypes.jsligo) defined by [FA2 (TZIP-12)](https://tzip.tezosagora.org/proposal/tzip-12/)
- a [LIGO](https://ligolang.org/) implementation for :
- unique [NFTs](./lib/fa2/nft/nft.impl.jsligo): This contract implements the FA2 interface for
NFT(non-fungible-token) where a token can belong to only one address at a time
(1:1)
- [Single Assets](./lib/fa2/asset/single_asset.impl.mligo): This is an implementation of
Single Asset Token where a different amount of single token can belong to multiple
addresses at a time (1:n)
- [Multiple Assets](./lib/fa2/asset/multi_asset.impl.mligo): This is an implementation of
Multi Asset Token where there are several token ids (available in different amounts)
and they can belong to multiple addresses (m:n)

## Use the implementation directly

The library provides you 3 template implementations ready to deploy

1. To install this package, run `ligo install @ligo/fa`. It will download the files
1. Deploy the NFT contract with Taquito the Ghostnet with `alice` wallet

```bash
make compile
make deploy
```

## Extend an implementation

If you need additional features in your contract, you can use the extendable version. An example is
available in the file `examples/mintable.mligo`. Using the extension mechanism, it adds an admin
address to the storage, as well as a `mint` entrypoint to mint owner-less NFTs. Only the admin can
call this entrypoint.

Install the library and create a new file

```bash
ligo install @ligo/fa
touch mintable.mligo
```

To extend the storage, define the type of the extension and refer to the original storage type as
such:

```ocaml
#import "@ligo/fa/lib/main.mligo" "FA2"
module NFT = FA2.NFTExtendable
type extension = {
admin: address
}
type storage = extension NFT.storage
type ret = operation list * storage
```

Importing the library allows you to refer to the TZIP12 operations signatures and make it easier to
redefine all the entrypoints and views that are required:

```ocaml
(* Standard FA2 interface, copied from the source *)
[@entry]
let transfer (t: NFT.TZIP12.transfer) (s: storage) : ret =
NFT.transfer t s
[@entry]
let balance_of (b: NFT.TZIP12.balance_of) (s: storage) : ret =
NFT.balance_of b s
(* Etc. *)
```

To make it easier to define new entrypoints, some functions are available in the library, and you
can also use the `storage` fields directly:

```ocaml
(* Extension *)
type mint = {
owner : address;
token_id : nat;
}
[@entry]
let mint (mint : mint) (s : storage): ret =
let sender = Tezos.get_sender () in
let () = assert (sender = s.extension.admin) in
let () = NFT.Assertions.assert_token_exist s.token_metadata mint.token_id in
(* Check that nobody owns the token already *)
let () = assert (Option.is_none (Big_map.find_opt mint.token_id s.ledger)) in
let s = NFT.set_balance s mint.owner mint.token_id in
[], s
```

Note that this version requires the minted NFTs to be already defined in the `token_metadata` big
map. However, you can also change the `mint` entrypoint to create new tokens dynamically.

## Implement the interface differently

If you are not happy with the default NFT implementation, you can define your own

Create a new file

```bash
touch myTzip12NFTImplementation.jsligo
```

Import some code and define implementation of missing types `ledger` and `operators`

```ligolang
#import "@ligo/fa/lib/fa2/common/errors.mligo" "Errors"
#import "@ligo/fa/lib/fa2/common/assertions.jsligo" "Assertions"
#import "@ligo/fa/lib/fa2/common/tzip12.datatypes.jsligo" "TZIP12"
#import "@ligo/fa/lib/fa2/common/tzip12.interfaces.jsligo" "TZIP12Interface"
#import "@ligo/fa/lib/fa2/common/tzip16.datatypes.jsligo" "TZIP16"
export namespace NFT implements TZIP12Interface.FA2{
export type ledger = big_map<nat, address>;
type operator = address;
export type operators = big_map<[address, operator], set<nat>>;
export type storage = {
ledger: ledger,
operators: operators,
token_metadata: TZIP12.tokenMetadata,
metadata: TZIP16.metadata
};
type ret = [list<operation>, storage];
}
```

Copy the missing entrypoints from the TZIP12 interface and give your own implementation

```ligolang
@entry
const transfer = (p: TZIP12.transfer, s: storage): ret => {
failwith("TODO");
};
@entry
const balance_of = (p: TZIP12.balance_of, s: storage): ret => {
failwith("TODO");
};
@entry
const update_operators = (p: TZIP12.update_operators, s: storage): ret => {
failwith("TODO");
};
```

Compile it (do not forget to add the parameter -m NFT as you have to define a namespace to be able to implement an interface)

```bash
ligo compile contract myTzip12NFTImplementation.jsligo -m NFT
```
Loading

0 comments on commit 5d617f8

Please sign in to comment.