diff --git a/.ligo/repository_id b/.ligo/repository_id new file mode 100644 index 0000000..8390e73 --- /dev/null +++ b/.ligo/repository_id @@ -0,0 +1 @@ +72e42d92-b208-4622-4e31-3a9565aa1c64 \ No newline at end of file diff --git a/.ligo/term_acceptance b/.ligo/term_acceptance new file mode 100644 index 0000000..4516383 --- /dev/null +++ b/.ligo/term_acceptance @@ -0,0 +1 @@ +accepted \ No newline at end of file diff --git a/Makefile b/Makefile index 0805abe..3432c32 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/lib/multi_asset/storage.mligo b/lib/multi_asset/storage.mligo index 2d44806..82b69a0 100644 --- a/lib/multi_asset/storage.mligo +++ b/lib/multi_asset/storage.mligo @@ -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; diff --git a/ligo.json b/ligo.json new file mode 100644 index 0000000..e20149b --- /dev/null +++ b/ligo.json @@ -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 ", + "license": "MIT", + "bugs": { + "url": "https://github.com/smart-chain-fr/ligoExtendableFA2/issues" + }, + "homepage": "https://github.com/smart-chain-fr/ligoExtendableFA2" + } + \ No newline at end of file diff --git a/test/multi_asset.instance.mligo b/test/multi_asset.instance.mligo index a6ba832..f869143 100644 --- a/test/multi_asset.instance.mligo +++ b/test/multi_asset.instance.mligo @@ -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 diff --git a/test/multi_asset.test.mligo b/test/multi_asset.test.mligo index f14265a..079cb19 100644 --- a/test/multi_asset.test.mligo +++ b/test/multi_asset.test.mligo @@ -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)) @@ -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 @@ -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 () diff --git a/test/single_asset.extended.mligo b/test/single_asset.extended.mligo index 95c3d84..fc053cc 100644 --- a/test/single_asset.extended.mligo +++ b/test/single_asset.extended.mligo @@ -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 @@ -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 diff --git a/test/single_asset.extended.test.mligo b/test/single_asset.extended.test.mligo index eb8ebc5..5811cb9 100644 --- a/test/single_asset.extended.test.mligo +++ b/test/single_asset.extended.test.mligo @@ -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 @@ -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 () diff --git a/test/single_asset.instance.mligo b/test/single_asset.instance.mligo index f0eaa76..5baf3a2 100644 --- a/test/single_asset.instance.mligo +++ b/test/single_asset.instance.mligo @@ -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 diff --git a/test/single_asset.test.mligo b/test/single_asset.test.mligo index 0dbb2fd..30e0ead 100644 --- a/test/single_asset.test.mligo +++ b/test/single_asset.test.mligo @@ -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 @@ -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 ()