Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support LIGO 1.2.0 #8

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ligo/repository_id
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
72e42d92-b208-4622-4e31-3a9565aa1c64
1 change: 1 addition & 0 deletions .ligo/term_acceptance
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
accepted
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ help:
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'

ifndef LIGO
LIGO=docker run -u $(id -u):$(id -g) --rm -v "$(PWD)":"$(PWD)" -w "$(PWD)" ligolang/ligo:0.55.0
LIGO=docker run -u $(id -u):$(id -g) --rm -v "$(PWD)":"$(PWD)" -w "$(PWD)" ligolang/ligo:1.2.0
endif
# ^ use LIGO en var bin if configured, otherwise use docker

Expand Down
2 changes: 1 addition & 1 deletion lib/multi_asset/storage.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#import "ledger.mligo" "Ledger"

type token_id = nat
type 'a t = {
type 'a t = [@layout comb] {
metadata: Metadata.t;
ledger : Ledger.t;
token_metadata : TokenMetadata.t;
Expand Down
22 changes: 22 additions & 0 deletions ligo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "ligo-extendable-fa2",
"version": "1.0.5",
"main": "./lib/main.mligo",
"description": "Library of extendable FA2",
"directories": {
"lib": "lib",
"test": "test"
},
"repository": {
"type": "git",
"url": "git+https://github.com/smart-chain-fr/ligoExtendableFA2.git"
},
"keywords": ["ligo", "tezos", "FA2"],
"author": "Smart-chain <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/smart-chain-fr/ligoExtendableFA2/issues"
},
"homepage": "https://github.com/smart-chain-fr/ligoExtendableFA2"
}

17 changes: 12 additions & 5 deletions test/multi_asset.instance.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ type storage = FA2.storage
type extension = string
type extended_storage = extension storage

type parameter = [@layout:comb]
type parameter =
| Transfer of FA2.transfer
| Balance_of of FA2.balance_of
| Update_operators of FA2.update_operators

let main ((p,s):(parameter * extended_storage)): operation list * extended_storage = match p with
Transfer p -> FA2.transfer p s
| Balance_of p -> FA2.balance_of p s
| Update_operators p -> FA2.update_ops p s
[@entry]
let transfer (p: FA2.transfer) (s: extended_storage) : operation list * extended_storage =
FA2.transfer p s

[@entry]
let balance_of (p: FA2.balance_of) (s: extended_storage) : operation list * extended_storage =
FA2.balance_of p s

[@entry]
let update_operators (p: FA2.update_operators) (s: extended_storage) : operation list * extended_storage =
FA2.update_ops p s
11 changes: 5 additions & 6 deletions test/multi_asset.test.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ let get_initial_storage (a, b, c : nat * nat * nat) =
MultiAsset.FA2.TokenMetadata.data));
] : MultiAsset.FA2.TokenMetadata.t) in

let initial_storage = {
let initial_storage: MultiAsset.extended_storage = {
metadata = Big_map.literal [
("", Bytes.pack("tezos-storage:contents"));
("contents", ("": bytes))
Expand All @@ -51,11 +51,10 @@ let get_initial_storage (a, b, c : nat * nat * nat) =
operators = operators;
extension = "foo";
} in

initial_storage, owners, ops

let assert_balances
(contract_address : (MultiAsset.parameter, MultiAsset.extended_storage) typed_address )
(contract_address : ((MultiAsset parameter_of), MultiAsset.extended_storage) typed_address )
(a, b, c : (address * nat * nat) * (address * nat * nat) * (address * nat * nat)) =
let (owner1, token_id_1, balance1) = a in
let (owner2, token_id_2, balance2) = b in
Expand Down Expand Up @@ -87,8 +86,8 @@ let test_atomic_tansfer_success =
] : MultiAsset.FA2.transfer)
in
let () = Test.set_source op1 in
let (t_addr,_,_) = Test.originate MultiAsset.main initial_storage 0tez in
let contr = Test.to_contract t_addr in
let { addr;code = _code; size = _size} = Test.originate (contract_of MultiAsset) initial_storage 0tez in
let contr = Test.to_contract addr in
let _ = Test.transfer_to_contract_exn contr (Transfer transfer_requests) 0tez in
let () = assert_balances t_addr ((owner1, 2n, 8n), (owner2, 2n, 12n), (owner3, 3n, 10n)) in
let () = assert_balances addr ((owner1, 2n, 8n), (owner2, 2n, 12n), (owner3, 3n, 10n)) in
()
24 changes: 15 additions & 9 deletions test/single_asset.extended.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ type extension = {

type extended_storage = extension storage

type parameter = [@layout:comb]
type parameter =
| Transfer of FA2.transfer
| Balance_of of FA2.balance_of
| Update_operators of FA2.update_operators


let is_operator (operators : FA2.Operators.t) (from_ : address) : bool =
let sender_ = (Tezos.get_sender ()) in
if (sender_ = from_) then true
Expand All @@ -40,15 +39,22 @@ let authorize_transfer (s : extended_storage) : unit =
else
()

let main (p, s : parameter * extended_storage) : operation list * extended_storage =
match p with
Transfer p -> let _ = authorize_transfer s in
FA2.transfer p s
| Balance_of p -> FA2.balance_of p s
| Update_operators p -> FA2.update_ops p s

[@entry]
let transfer (p: FA2.transfer) (s: extended_storage) : operation list * extended_storage =
let _ = authorize_transfer s in
FA2.transfer p s

[@entry]
let balance_of (p: FA2.balance_of) (s: extended_storage) : operation list * extended_storage =
FA2.balance_of p s

[@entry]
let update_operators (p: FA2.update_operators) (s: extended_storage) : operation list * extended_storage =
FA2.update_ops p s

let get_balance (s : extended_storage) (owner : address) (_token_id : nat) : nat =
FA2.Ledger.get_for_user s.ledger owner

[@view] let get_balance (p, s : address * extended_storage) : nat =
[@view] let get_balance (p: address) (s: extended_storage) : nat =
get_balance s p 0n
8 changes: 4 additions & 4 deletions test/single_asset.extended.test.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ let get_initial_storage (a, b, c : nat * nat * nat) =
initial_storage, owners, ops

let assert_balances
(contract_address : (ExtendedAsset.parameter, extended_storage) typed_address )
(contract_address : ((ExtendedAsset parameter_of), extended_storage) typed_address )
(a, b, c : (address * nat) * (address * nat) * (address * nat)) =
let (owner1, balance1) = a in
let (owner2, balance2) = b in
Expand Down Expand Up @@ -95,8 +95,8 @@ let test_atomic_tansfer_success =
] : ExtendedAsset.FA2.transfer)
in
let () = Test.set_source op1 in
let (t_addr,_,_) = Test.originate ExtendedAsset.main initial_storage 0tez in
let contr = Test.to_contract t_addr in
let { addr;code = _code; size = _size} = Test.originate (contract_of ExtendedAsset) initial_storage 0tez in
let contr = Test.to_contract addr in
let _ = Test.transfer_to_contract_exn contr (Transfer transfer_requests) 0tez in
let () = assert_balances t_addr ((owner1, 8n), (owner2, 7n), (owner3, 15n)) in
let () = assert_balances addr ((owner1, 8n), (owner2, 7n), (owner3, 15n)) in
()
17 changes: 12 additions & 5 deletions test/single_asset.instance.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ type storage = FA2.storage
type extension = string
type extended_storage = extension storage

type parameter = [@layout:comb]
type parameter =
| Transfer of FA2.transfer
| Balance_of of FA2.balance_of
| Update_operators of FA2.update_operators

let main ((p,s):(parameter * extended_storage)): operation list * extended_storage = match p with
Transfer p -> FA2.transfer p s
| Balance_of p -> FA2.balance_of p s
| Update_operators p -> FA2.update_ops p s
[@entry]
let transfer (p: FA2.transfer) (s: extended_storage) : operation list * extended_storage =
FA2.transfer p s

[@entry]
let balance_of (p: FA2.balance_of) (s: extended_storage) : operation list * extended_storage =
FA2.balance_of p s

[@entry]
let update_operators (p: FA2.update_operators) (s: extended_storage) : operation list * extended_storage =
FA2.update_ops p s
8 changes: 4 additions & 4 deletions test/single_asset.test.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ let get_initial_storage (a, b, c : nat * nat * nat) =
initial_storage, owners, ops

let assert_balances
(contract_address : (SingleAsset.parameter, extended_storage) typed_address )
(contract_address : ((SingleAsset parameter_of), extended_storage) typed_address )
(a, b, c : (address * nat) * (address * nat) * (address * nat)) =
let (owner1, balance1) = a in
let (owner2, balance2) = b in
Expand Down Expand Up @@ -91,8 +91,8 @@ let test_atomic_tansfer_success =
] : SingleAsset.FA2.transfer)
in
let () = Test.set_source op1 in
let (t_addr,_,_) = Test.originate SingleAsset.main initial_storage 0tez in
let contr = Test.to_contract t_addr in
let { addr;code = _code; size = _size} = Test.originate (contract_of SingleAsset) initial_storage 0tez in
let contr = Test.to_contract addr in
let _ = Test.transfer_to_contract_exn contr (Transfer transfer_requests) 0tez in
let () = assert_balances t_addr ((owner1, 8n), (owner2, 7n), (owner3, 15n)) in
let () = assert_balances addr ((owner1, 8n), (owner2, 7n), (owner3, 15n)) in
()