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

ligo_v1.6.0 #46

Open
wants to merge 5 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
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
SHELL := /bin/bash

ligo_compiler?=docker run --rm -v "$(PWD)":"$(PWD)" -w "$(PWD)" ligolang/ligo:1.2.0
ligo_compiler?=docker run --rm -v "$(PWD)":"$(PWD)" -w "$(PWD)" ligolang/ligo:1.6.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?=
Expand Down Expand Up @@ -68,8 +68,7 @@ ifndef SUITE
@$(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)
@$(call test,fa2/nft/e2e_mutation.test.mligo)
else
@$(call test,$(SUITE).test.mligo)
endif
Expand Down
2 changes: 1 addition & 1 deletion lib/fa2.1/data/approvals.jsligo
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const decrease_approved_amount = (
amount_: Amount.T
): T => {
let balance_ = get_amount(approvals, from_, spender, token_id);
assert_with_error((balance_ >= amount_), Errors.ins_balance);
Assert.Error.assert((balance_ >= amount_), Errors.ins_balance);
balance_ = abs(balance_ - amount_);

return set_amount(approvals, from_, spender, token_id, balance_);
Expand Down
2 changes: 1 addition & 1 deletion lib/fa2.1/data/ledger.jsligo
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export namespace Common_Asset {

export const sub_to_val = (amount_: Amount.T, old_value: option<Amount.T>): Amount.T => {
const value = balance_of(old_value);
assert_with_error(value >= amount_, Errors.ins_balance);
Assert.Error.assert(value >= amount_, Errors.ins_balance);

return abs(value - amount_);
};
Expand Down
2 changes: 1 addition & 1 deletion lib/fa2.1/data/operators.jsligo
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const assert_authorisation = (
};

const assert_update_permission = (owner: owner): unit => {
assert_with_error(owner == Tezos.get_sender(), Errors.only_sender_manage_operators);
Assert.Error.assert(owner == Tezos.get_sender(), Errors.only_sender_manage_operators);
};

export const add_operator = (
Expand Down
4 changes: 2 additions & 2 deletions lib/fa2.1/entrypoints/approve.jsligo
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ type event_map_key = [address, address, Token.T];
const _approve = (approve: approve, approvals: Approvals.T): Approvals.T => {
const { owner, spender, token_id, old_value, new_value } = approve;
const amount = Approvals.get_amount(approvals, owner, spender, token_id);
assert_with_error(amount == old_value, Errors.unsafe_approval);
assert_with_error(owner == Tezos.get_sender(), Errors.not_owner);
Assert.Error.assert(amount == old_value, Errors.unsafe_approval);
Assert.Error.assert(owner == Tezos.get_sender(), Errors.not_owner);
return Approvals.set_amount(approvals, owner, spender, token_id, new_value);
};

Expand Down
2 changes: 1 addition & 1 deletion lib/fa2.1/entrypoints/balance_of.jsligo
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const balance_of = <A, L>(
const { requests, callback } = balance;

return [list([
Tezos.transaction(
Tezos.Next.Operation.transaction(
List.map(
(request) => get_balance_info(storage, ledgerModule, request),
requests
Expand Down
12 changes: 6 additions & 6 deletions lib/fa2.1/entrypoints/export_ticket.jsligo
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ const create_ticket = <A, L>(
const newLedger = Ledger.decrease_token_amount_for_user(ledger, from_, token_id, amount);
let newStorage = Storage.set_approvals(storage, authorizedApprovals);
newStorage = Storage.set_ledger(newStorage, newLedger.data);
const ticket = Option.unopt_with_error(
Tezos.create_ticket([token_id, None()], amount),
Errors.cannot_create_ticket
const ticket = Option.value_with_error(
Errors.cannot_create_ticket,
Tezos.Next.Ticket.create([token_id, None()], amount)
);
return [operations, ticket, newLedger, newStorage];
};
Expand All @@ -121,7 +121,7 @@ export const export_tickets = <A, L>(
newLedger = updatedLedger;
operations = list([...newOps, ...operations]);
const ticketReceiver: contract<ExportedTicket> = Tezos.get_contract_with_error(request.to_, Errors.invalid_destination);
operations = list([Tezos.transaction(ticket, 0tez, ticketReceiver), ...operations]);
operations = list([Tezos.Next.Operation.transaction(ticket, 0tez, ticketReceiver), ...operations]);
finalStorage = newStorage;
}
}
Expand All @@ -134,8 +134,8 @@ export const export_tickets = <A, L>(
operations = list([...newOps, ...operations]);
let ticketOps : list<ExportedTicket> = list([ticket]);
let finalTicketOps : list<ExportTicketsTo> = list([{to_: request.to_, ticketsToExport: ticketOps}]);
const ticketReceiver: contract<list<ExportTicketsTo>> = Tezos.get_contract_with_error(Option.unopt(op.destination), Errors.invalid_destination);
operations = list([Tezos.transaction(finalTicketOps, 0tez, ticketReceiver), ...operations]);
const ticketReceiver: contract<list<ExportTicketsTo>> = Tezos.get_contract_with_error(Option.value_with_error("Option is None", op.destination), Errors.invalid_destination);
operations = list([Tezos.Next.Operation.transaction(finalTicketOps, 0tez, ticketReceiver), ...operations]);
finalStorage = newStorage;
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/fa2.1/entrypoints/import_ticket.jsligo
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ const make_transfer = (from_: option<address>, txs: list<transaction>): transfer

// @inline
const assert_ticketer_is_self_address = (ticketer : address) : unit =>
assert_with_error(Tezos.get_self_address() == ticketer, Errors.invalid_ticket);
Assert.Error.assert (Tezos.get_self_address() == ticketer, Errors.invalid_ticket);

const import_ticket_to = <L>(
to_ : address,
imported_ticket : imported_ticket,
[transactions, ledger, operations] : [list<transaction>, LedgerModule<L>, list<operation>]
) : [list<transaction>, LedgerModule<L>, list<operation>] => {
let operationsEvent = operations;
const [[ticketer, [[token_id, _data], amount]], _] = Tezos.read_ticket(imported_ticket);
const [[ticketer, [[token_id, _data], amount]], _] = Tezos.Next.Ticket.read (imported_ticket);
assert_ticketer_is_self_address(ticketer);
const newLedger = Ledger.increase_token_amount_for_user(ledger, to_, token_id, amount);
const transaction = make_transaction(Some(to_), token_id, amount);
Expand Down
14 changes: 7 additions & 7 deletions lib/fa2.1/entrypoints/lambda_export.jsligo
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ const create_ticket = <A, L>(
let newStorage = Storage.set_approvals(storage, authorizedApprovals);
newStorage = Storage.set_ledger(newStorage, newLedger.data);

const ticket = Option.unopt_with_error(
Tezos.create_ticket([token_id, None()], amount),
Errors.cannot_create_ticket
const ticket = Option.value_with_error(
Errors.cannot_create_ticket,
Tezos.Next.Ticket.create([token_id, None()], amount)
);
return [operations, ticket, newLedger, newStorage];
};
Expand All @@ -123,15 +123,15 @@ export const lambda_export = <A, L>(
ticketsToExport
);

const operation = Tezos.transaction(
const operation = Tezos.Next.Operation.transaction(
{
tickets,
action: destination
},
Tezos.get_amount(),
Option.unopt_with_error(
Tezos.get_contract_opt(storage.proxy),
Errors.invalid_proxy
Option.value_with_error(
Errors.invalid_proxy,
Tezos.get_contract_opt(storage.proxy)
)
);
finalOperations = list([operation, ...newOperations]);
Expand Down
2 changes: 1 addition & 1 deletion lib/fa2.1/entrypoints/mint.jsligo
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type total_supply_update_type =
@layout("comb")
{
token_id: Token.T,
new_total_supply: nat,
new_total_supply: Amount.T,
diff: int
};

Expand Down
4 changes: 2 additions & 2 deletions lib/fa2/asset/extendable_multi_asset.impl.jsligo
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const decrease_token_amount_for_user = (
[ledger, from_, token_id, amount_]: [ledger, address, nat, nat]
): ledger => {
let balance_ = get_for_user([ledger, from_, token_id]);
assert_with_error((balance_ >= amount_), Errors.ins_balance);
Assert.Error.assert((balance_ >= amount_), Errors.ins_balance);
balance_ = abs(balance_ - amount_);
return set_for_user([ledger, from_, token_id, balance_])
};
Expand Down Expand Up @@ -167,7 +167,7 @@ export const balance_of = <T>(b: TZIP12.balance_of, s: storage<T>): ret<T> => {
return ({ request: request, balance: balance_ })
};
const callback_param = List.map(get_balance_info, requests);
const operation = Tezos.transaction(Main(callback_param), 0mutez, callback);
const operation = Tezos.Next.Operation.transaction(Main(callback_param), 0mutez, callback);
return [list([operation]), s]
};

Expand Down
9 changes: 5 additions & 4 deletions lib/fa2/asset/extendable_multi_asset.impl.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ let decrease_token_amount_for_user
(amount_ : nat)
: ledger =
let balance_ = get_for_user ledger from_ token_id in
let () = assert_with_error (balance_ >= amount_) Errors.ins_balance in
let () = Assert.Error.assert (balance_ >= amount_) Errors.ins_balance in
let balance_ = abs (balance_ - amount_) in
let ledger = set_for_user ledger from_ token_id balance_ in
ledger
Expand All @@ -121,9 +121,10 @@ let increase_token_amount_for_user
// Storage
let assert_token_exist (type a) (s : a storage) (token_id : nat) : unit =
let _ =
Option.unopt_with_error
Option.value_with_error
Errors.undefined_token
(Big_map.find_opt token_id s.token_metadata)
Errors.undefined_token in
in
()

let set_ledger (type a) (s : a storage) (ledger : ledger) =
Expand Down Expand Up @@ -176,7 +177,7 @@ let balance_of (type a) (b : TZIP12.balance_of) (s : a storage) : a ret =
balance = balance_
} in
let callback_param = List.map get_balance_info requests in
let operation = Tezos.transaction (Main callback_param) 0mutez callback in
let operation = Tezos.Next.Operation.transaction (Main callback_param) 0mutez callback in
([operation] : operation list), s

let update_operators (type a)
Expand Down
4 changes: 2 additions & 2 deletions lib/fa2/asset/extendable_single_asset.impl.jsligo
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const decrease_token_amount_for_user = (
amount_: nat
): ledger => {
let tokens = get_for_user(ledger, from_);
const _ = assert_with_error(tokens >= amount_, Errors.ins_balance);
const _ = Assert.Error.assert(tokens >= amount_, Errors.ins_balance);
tokens = abs(tokens - amount_);
return update_for_user(ledger, from_, tokens)
};
Expand Down Expand Up @@ -164,7 +164,7 @@ export const balance_of = <T>(b: TZIP12.balance_of, s: storage<T>): ret<T> => {
return { request: request, balance: balance_ }
};
const callback_param = List.map(get_balance_info, requests);
const operation = Tezos.transaction(Main(callback_param), 0mutez, callback);
const operation = Tezos.Next.Operation.transaction(Main(callback_param), 0mutez, callback);
return [list([operation]), s]
};

Expand Down
4 changes: 2 additions & 2 deletions lib/fa2/asset/extendable_single_asset.impl.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ let decrease_token_amount_for_user
(amount_ : nat)
: ledger =
let tokens = get_for_user ledger from_ in
let () = assert_with_error (tokens >= amount_) Errors.ins_balance in
let () = Assert.Error.assert (tokens >= amount_) Errors.ins_balance in
let tokens = abs (tokens - amount_) in
let ledger = update_for_user ledger from_ tokens in
ledger
Expand Down Expand Up @@ -156,7 +156,7 @@ let balance_of (type a) (b : TZIP12.balance_of) (s : a storage) : a ret =
balance = balance_
} in
let callback_param = List.map get_balance_info requests in
let operation = Tezos.transaction (Main callback_param) 0mutez callback in
let operation = Tezos.Next.Operation.transaction (Main callback_param) 0mutez callback in
([operation] : operation list), s

(**
Expand Down
12 changes: 6 additions & 6 deletions lib/fa2/common/assertions.jsligo
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@
*/

export const assert_update_permission = (owner: address): unit => {
return assert_with_error(
(owner == (Tezos.get_sender())),
return Assert.Error.assert(
(owner == Tezos.get_sender()),
Errors.only_sender_manage_operators
)
}

/**
* Check if the token id is already defined
* @param token_metadata : bigmap of token definitions
* @param token_id : the token id to test
* @param token_id : the token id to test
*/

export const assert_token_exist = (
token_metadata: TZIP12Datatypes.tokenMetadata,
token_id: nat
): unit => {
const _ =
Option.unopt_with_error(
Big_map.find_opt(token_id, token_metadata),
Errors.undefined_token
Option.value_with_error(
Errors.undefined_token,
Big_map.find_opt(token_id, token_metadata)
)
};
13 changes: 7 additions & 6 deletions lib/fa2/nft/extendable_nft.impl.jsligo
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type storage<T> = {

type ret<T> = [list<operation>, storage<T>];

const make_storage = (extension) =>
const make_storage = <T>(extension: T) : storage<T> =>
(
{
ledger: Big_map.empty,
Expand Down Expand Up @@ -57,7 +57,7 @@ export const assert_authorisation = (
export const add_operator = (
operators: operators,
owner: address,
operator: address,
operator: operator,
token_id: nat
): operators => {
if (owner == operator) {
Expand All @@ -80,7 +80,7 @@ export const add_operator = (
export const remove_operator = (
operators: operators,
owner: address,
operator: address,
operator: operator,
token_id: nat
): operators => {
if (owner == operator) {
Expand Down Expand Up @@ -108,12 +108,13 @@ export const remove_operator = (

// ledger
export const is_owner_of = (ledger: ledger, token_id: nat, owner: address): bool => {
const current_owner = Option.unopt(Big_map.find_opt(token_id, ledger));
const current_owner = Option.value_with_error ("option is None", Big_map.find_opt(token_id, ledger));
return (current_owner == owner)
};

export const assert_owner_of = (ledger: ledger, token_id: nat, owner: address): unit =>
assert_with_error(is_owner_of(ledger, token_id, owner), Errors.ins_balance);
Assert.Error.assert(is_owner_of(ledger, token_id, owner), Errors.ins_balance);


export const transfer_token_from_user_to_user = (
ledger: ledger,
Expand Down Expand Up @@ -171,7 +172,7 @@ export const balance_of = <T>(b: TZIP12.balance_of, s: storage<T>): ret<T> => {
return ({ request: request, balance: balance_ })
};
const callback_param = List.map(get_balance_info, requests);
const operation = Tezos.transaction(Main(callback_param), 0mutez, callback);
const operation = Tezos.Next.Operation.transaction(Main(callback_param), 0mutez, callback);
return [list([operation]), s]
};

Expand Down
16 changes: 7 additions & 9 deletions lib/fa2/nft/extendable_nft.impl.mligo
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[@public] #import "../common/assertions.jsligo" "Assertions"
[@public] #import "../common/errors.mligo" "Errors"
[@public] #import "../common/tzip12.datatypes.jsligo" "TZIP12"
[@public] #import "../common/tzip12.interfaces.jsligo" "TZIP12Interface"
[@public] #import "../common/tzip16.datatypes.jsligo" "TZIP16"

type ledger = (nat, address) big_map
Expand Down Expand Up @@ -36,15 +35,14 @@ let assert_authorisation
(from_ : address)
(token_id : nat)
: unit =
let sender_ = (Tezos.get_sender ()) in
if (sender_ = from_)
then ()
else
let sender_ = Tezos.get_sender () in
if sender_ <> from_
then
let authorized =
match Big_map.find_opt (from_, sender_) operators with
Some (a) -> a
| None -> Set.empty in
if Set.mem token_id authorized then () else failwith Errors.not_operator
if not (Set.mem token_id authorized) then failwith Errors.not_operator

let is_operator
(operators, owner, operator, token_id : (operators * address * address * nat))
Expand Down Expand Up @@ -96,11 +94,11 @@ let remove_operator

//module Ledger = struct
let is_owner_of (ledger : ledger) (token_id : nat) (owner : address) : bool =
let current_owner = Option.unopt (Big_map.find_opt token_id ledger) in
let current_owner: address = Option.value_with_error "Option is None" (Big_map.find_opt token_id ledger) in
current_owner = owner

let assert_owner_of (ledger : ledger) (token_id : nat) (owner : address) : unit =
assert_with_error (is_owner_of ledger token_id owner) Errors.ins_balance
Assert.Error.assert (is_owner_of ledger token_id owner) Errors.ins_balance

let transfer_token_from_user_to_user
(ledger : ledger)
Expand Down Expand Up @@ -176,7 +174,7 @@ let balance_of (type a) (b : TZIP12.balance_of) (s : a storage) : a ret =
balance = balance_
} in
let callback_param = List.map get_balance_info requests in
let operation = Tezos.transaction (Main callback_param) 0mutez callback in
let operation = Tezos.Next.Operation.transaction (Main callback_param) 0mutez callback in
([operation] : operation list), s

let update_operators (type a)
Expand Down
4 changes: 2 additions & 2 deletions lib/fa2/nft/nft.impl.jsligo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export #import "../common/assertions.jsligo" "Assertions"
#import "../common/assertions.jsligo" "Assertions"
export #import "../common/errors.mligo" "Errors"
export #import "../common/tzip12.datatypes.jsligo" "TZIP12"
export #import "../common/tzip16.datatypes.jsligo" "TZIP16"
#import "../common/tzip16.datatypes.jsligo" "TZIP16"

#import "./extendable_nft.impl.jsligo" "NFTExtendable"

Expand Down
Loading