-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit of extesnion version of fa/lib 1.1.1 for debug
- Loading branch information
Showing
100 changed files
with
16,324 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
8273581c-4ea5-460e-2f17-d458f3504157 |
21 changes: 21 additions & 0 deletions
21
solution_extension/.ligo/source/i/ligo__s__fa__1.1.1__ffffffff/LICENSE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
65 changes: 65 additions & 0 deletions
65
solution_extension/.ligo/source/i/ligo__s__fa__1.1.1__ffffffff/Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
160 changes: 160 additions & 0 deletions
160
solution_extension/.ligo/source/i/ligo__s__fa__1.1.1__ffffffff/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
Oops, something went wrong.