diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index a215cb1b20b3fd8eabcc58ac08bab9d0fce515eb..d36f8f6312cd265dc27de58df5c5237bd9ecdc9d 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -5250,7 +5250,7 @@ module Token : sig | `Block_fees | `Frozen_bonds of Contract.t * Bond_id.t ] - type source = + type giver = [ `Invoice | `Bootstrap | `Initial_commitments @@ -5265,7 +5265,7 @@ module Token : sig | `Sc_rollup_refutation_rewards | container ] - type sink = + type receiver = [ `Storage_fees | `Double_signing_punishments | `Lost_endorsing_rewards of public_key_hash * bool * bool @@ -5281,15 +5281,15 @@ module Token : sig val transfer_n : ?origin:Receipt.update_origin -> context -> - ([< source] * Tez.t) list -> - [< sink] -> + ([< giver] * Tez.t) list -> + [< receiver] -> (context * Receipt.balance_updates) tzresult Lwt.t val transfer : ?origin:Receipt.update_origin -> context -> - [< source] -> - [< sink] -> + [< giver] -> + [< receiver] -> Tez.t -> (context * Receipt.balance_updates) tzresult Lwt.t end @@ -5305,14 +5305,14 @@ module Fees : sig ?origin:Receipt.update_origin -> context -> storage_limit:Z.t -> - payer:Token.source -> + payer:Token.giver -> Z.t -> (context * Z.t * Receipt.balance_updates) tzresult Lwt.t val burn_storage_increase_fees : ?origin:Receipt_repr.update_origin -> context -> - payer:Token.source -> + payer:Token.giver -> Z.t -> (context * Receipt.balance_updates) tzresult Lwt.t @@ -5320,21 +5320,21 @@ module Fees : sig ?origin:Receipt.update_origin -> context -> storage_limit:Z.t -> - payer:Token.source -> + payer:Token.giver -> (context * Z.t * Receipt.balance_updates) tzresult Lwt.t val burn_tx_rollup_origination_fees : ?origin:Receipt.update_origin -> context -> storage_limit:Z.t -> - payer:Token.source -> + payer:Token.giver -> (context * Z.t * Receipt.balance_updates) tzresult Lwt.t val burn_sc_rollup_origination_fees : ?origin:Receipt.update_origin -> context -> storage_limit:Z.t -> - payer:Token.source -> + payer:Token.giver -> Z.t -> (context * Z.t * Receipt.balance_updates) tzresult Lwt.t @@ -5342,7 +5342,7 @@ module Fees : sig ?origin:Receipt.update_origin -> context -> storage_limit:Z.t -> - payer:Token.source -> + payer:Token.giver -> Z.t -> (context * Z.t * Receipt.balance_updates) tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/fees_storage.mli b/src/proto_alpha/lib_protocol/fees_storage.mli index 78a13395d9775a40d64ab8ce4ac8871bed5de0a9..87044b04c81a6e4e568bf28799564082dc7f9a12 100644 --- a/src/proto_alpha/lib_protocol/fees_storage.mli +++ b/src/proto_alpha/lib_protocol/fees_storage.mli @@ -67,7 +67,7 @@ val burn_storage_fees : ?origin:Receipt_repr.update_origin -> Raw_context.t -> storage_limit:Z.t -> - payer:Token.source -> + payer:Token.giver -> Z.t -> (Raw_context.t * Z.t * Receipt_repr.balance_updates) tzresult Lwt.t @@ -82,7 +82,7 @@ val burn_storage_fees : val burn_storage_increase_fees : ?origin:Receipt_repr.update_origin -> Raw_context.t -> - payer:Token.source -> + payer:Token.giver -> Z.t -> (Raw_context.t * Receipt_repr.balance_updates) tzresult Lwt.t @@ -92,7 +92,7 @@ val burn_origination_fees : ?origin:Receipt_repr.update_origin -> Raw_context.t -> storage_limit:Z.t -> - payer:Token.source -> + payer:Token.giver -> (Raw_context.t * Z.t * Receipt_repr.balance_updates) tzresult Lwt.t (** Calls [burn_storage_fees] with the parameter [consumed] mapped to the @@ -101,7 +101,7 @@ val burn_tx_rollup_origination_fees : ?origin:Receipt_repr.update_origin -> Raw_context.t -> storage_limit:Z.t -> - payer:Token.source -> + payer:Token.giver -> (Raw_context.t * Z.t * Receipt_repr.balance_updates) tzresult Lwt.t (** [burn_sc_rollup_origination_fees ~origin ctxt ~storage_limit ~payer consumed] @@ -110,7 +110,7 @@ val burn_sc_rollup_origination_fees : ?origin:Receipt_repr.update_origin -> Raw_context.t -> storage_limit:Z.t -> - payer:Token.source -> + payer:Token.giver -> Z.t -> (Raw_context.t * Z.t * Receipt_repr.balance_updates) tzresult Lwt.t @@ -120,6 +120,6 @@ val burn_zk_rollup_origination_fees : ?origin:Receipt_repr.update_origin -> Raw_context.t -> storage_limit:Z.t -> - payer:Token.source -> + payer:Token.giver -> Z.t -> (Raw_context.t * Z.t * Receipt_repr.balance_updates) tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/test/integration/test_token.ml b/src/proto_alpha/lib_protocol/test/integration/test_token.ml index 89d9389517ca6bd23c69f8743fdfae7a4ded7760..edf122f6c9575aa9c1f7f146dde5030aea4bcd43 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_token.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_token.ml @@ -57,19 +57,19 @@ let test_simple_balances () = let open Lwt_result_wrap_syntax in Random.init 0 ; create_context () >>=? fun (ctxt, pkh) -> - let src = `Contract (Contract.Implicit pkh) in + let giver = `Contract (Contract.Implicit pkh) in let pkh, _pk, _sk = Signature.generate_key () in - let dest = `Contract (Contract.Implicit pkh) in + let receiver = `Contract (Contract.Implicit pkh) in let amount = Tez.one in - wrap (Token.transfer ctxt src dest amount) >>=? fun (ctxt', _) -> - wrap (Token.balance ctxt src) >>=? fun (ctxt, bal_src) -> - wrap (Token.balance ctxt' src) >>=? fun (ctxt', bal_src') -> - wrap (Token.balance ctxt dest) >>=? fun (_, bal_dest) -> - wrap (Token.balance ctxt' dest) >>=? fun (_, bal_dest') -> - bal_src' +? amount >>?= fun add_bal_src'_amount -> - bal_dest +? amount >>?= fun add_bal_dest_amount -> - Assert.equal_tez ~loc:__LOC__ bal_src add_bal_src'_amount >>=? fun () -> - Assert.equal_tez ~loc:__LOC__ bal_dest' add_bal_dest_amount + wrap (Token.transfer ctxt giver receiver amount) >>=? fun (ctxt', _) -> + wrap (Token.balance ctxt giver) >>=? fun (ctxt, bal_giver) -> + wrap (Token.balance ctxt' giver) >>=? fun (ctxt', bal_giver') -> + wrap (Token.balance ctxt receiver) >>=? fun (_, bal_receiver) -> + wrap (Token.balance ctxt' receiver) >>=? fun (_, bal_receiver') -> + bal_giver' +? amount >>?= fun add_bal_giver'_amount -> + bal_receiver +? amount >>?= fun add_bal_receiver_amount -> + Assert.equal_tez ~loc:__LOC__ bal_giver add_bal_giver'_amount >>=? fun () -> + Assert.equal_tez ~loc:__LOC__ bal_receiver' add_bal_receiver_amount (** Check balance updates for a simple transfer from [bootstrap] to new [Implicit]. *) @@ -77,78 +77,83 @@ let test_simple_balance_updates () = let open Lwt_result_wrap_syntax in Random.init 0 ; create_context () >>=? fun (ctxt, pkh) -> - let src = Contract.Implicit pkh in + let giver = Contract.Implicit pkh in let pkh, _pk, _sk = Signature.generate_key () in - let dest = Contract.Implicit pkh in + let receiver = Contract.Implicit pkh in let amount = Tez.one in - wrap (Token.transfer ctxt (`Contract src) (`Contract dest) amount) + wrap (Token.transfer ctxt (`Contract giver) (`Contract receiver) amount) >>=? fun (_, bal_updates) -> Alcotest.( check bool - "Missing balance update for source contract." + "Missing balance update for giver contract." (List.mem ~equal:( = ) - Receipt.(Contract src, Debited amount, Block_application) + Receipt.(Contract giver, Debited amount, Block_application) bal_updates) true) ; Alcotest.( check bool - "Missing balance update for destination contract." + "Missing balance update for receiver contract." (List.mem ~equal:( = ) - Receipt.(Contract dest, Credited amount, Block_application) + Receipt.(Contract receiver, Credited amount, Block_application) bal_updates) true) ; return_unit -let test_allocated_and_deallocated ctxt dest initial_status status_when_empty = +let test_allocated_and_deallocated ctxt receiver initial_status + status_when_empty = let open Lwt_result_wrap_syntax in - wrap (Token.allocated ctxt dest) >>=? fun (ctxt, allocated) -> + wrap (Token.allocated ctxt receiver) >>=? fun (ctxt, allocated) -> Assert.equal_bool ~loc:__LOC__ allocated initial_status >>=? fun () -> let amount = Tez.one in - wrap (Token.transfer ctxt `Minted dest amount) >>=? fun (ctxt', _) -> - wrap (Token.allocated ctxt' dest) >>=? fun (ctxt', allocated) -> + wrap (Token.transfer ctxt `Minted receiver amount) >>=? fun (ctxt', _) -> + wrap (Token.allocated ctxt' receiver) >>=? fun (ctxt', allocated) -> Assert.equal_bool ~loc:__LOC__ allocated true >>=? fun () -> - wrap (Token.balance ctxt' dest) >>=? fun (ctxt', bal_dest') -> - wrap (Token.transfer ctxt' dest `Burned bal_dest') >>=? fun (ctxt', _) -> - wrap (Token.allocated ctxt' dest) >>=? fun (_, allocated) -> + wrap (Token.balance ctxt' receiver) >>=? fun (ctxt', bal_receiver') -> + wrap (Token.transfer ctxt' receiver `Burned bal_receiver') + >>=? fun (ctxt', _) -> + wrap (Token.allocated ctxt' receiver) >>=? fun (_, allocated) -> Assert.equal_bool ~loc:__LOC__ allocated status_when_empty >>=? fun () -> return_unit -let test_allocated_and_deallocated_when_empty ctxt dest = - test_allocated_and_deallocated ctxt dest false false +let test_allocated_and_deallocated_when_empty ctxt receiver = + test_allocated_and_deallocated ctxt receiver false false -let test_allocated_and_still_allocated_when_empty ctxt dest initial_status = - test_allocated_and_deallocated ctxt dest initial_status true +let test_allocated_and_still_allocated_when_empty ctxt receiver initial_status = + test_allocated_and_deallocated ctxt receiver initial_status true let test_allocated () = Random.init 0 ; create_context () >>=? fun (ctxt, pkh) -> - let dest = `Delegate_balance pkh in - test_allocated_and_still_allocated_when_empty ctxt dest true >>=? fun () -> + let receiver = `Delegate_balance pkh in + test_allocated_and_still_allocated_when_empty ctxt receiver true + >>=? fun () -> let pkh, _pk, _sk = Signature.generate_key () in - let dest = `Contract (Contract.Implicit pkh) in - test_allocated_and_deallocated_when_empty ctxt dest >>=? fun () -> - let dest = `Collected_commitments Blinded_public_key_hash.zero in - test_allocated_and_deallocated_when_empty ctxt dest >>=? fun () -> - let dest = `Frozen_deposits pkh in - test_allocated_and_still_allocated_when_empty ctxt dest false >>=? fun () -> - let dest = `Block_fees in - test_allocated_and_still_allocated_when_empty ctxt dest true >>=? fun () -> - let dest = + let receiver = `Contract (Contract.Implicit pkh) in + test_allocated_and_deallocated_when_empty ctxt receiver >>=? fun () -> + let receiver = `Collected_commitments Blinded_public_key_hash.zero in + test_allocated_and_deallocated_when_empty ctxt receiver >>=? fun () -> + let receiver = `Frozen_deposits pkh in + test_allocated_and_still_allocated_when_empty ctxt receiver false + >>=? fun () -> + let receiver = `Block_fees in + test_allocated_and_still_allocated_when_empty ctxt receiver true + >>=? fun () -> + let receiver = let bond_id = Bond_id.Sc_rollup_bond_id (sc_rollup ()) in `Frozen_bonds (Contract.Implicit pkh, bond_id) in - test_allocated_and_deallocated_when_empty ctxt dest + test_allocated_and_deallocated_when_empty ctxt receiver -let check_sink_balances ctxt ctxt' dest amount = +let check_receiver_balances ctxt ctxt' receiver amount = let open Lwt_result_wrap_syntax in - wrap (Token.balance ctxt dest) >>=? fun (_, bal_dest) -> - wrap (Token.balance ctxt' dest) >>=? fun (_, bal_dest') -> - bal_dest +? amount >>?= fun add_bal_dest_amount -> - Assert.equal_tez ~loc:__LOC__ bal_dest' add_bal_dest_amount + wrap (Token.balance ctxt receiver) >>=? fun (_, bal_receiver) -> + wrap (Token.balance ctxt' receiver) >>=? fun (_, bal_receiver') -> + bal_receiver +? amount >>?= fun add_bal_receiver_amount -> + Assert.equal_tez ~loc:__LOC__ bal_receiver' add_bal_receiver_amount (* Accounts of the form (`DelegateBalance pkh) are not allocated when they receive funds for the first time. To force allocation, we transfer to @@ -161,42 +166,43 @@ let force_allocation_if_need_be ctxt account = wrap (Token.transfer ctxt `Minted account Tez.one_mutez) >|=? fst | _ -> return ctxt -let test_transferring_to_sink ctxt sink amount expected_bupds = +let test_transferring_to_receiver ctxt receiver amount expected_bupds = let open Lwt_result_wrap_syntax in (* Transferring zero must be a noop, and must not return balance updates. *) - wrap (Token.transfer ctxt `Minted sink Tez.zero) >>=? fun (ctxt', bupds) -> + wrap (Token.transfer ctxt `Minted receiver Tez.zero) + >>=? fun (ctxt', bupds) -> Assert.equal_bool ~loc:__LOC__ (ctxt == ctxt' && bupds = []) true >>=? fun () -> - (* Force the allocation of [dest] if need be. *) - force_allocation_if_need_be ctxt sink >>=? fun ctxt -> + (* Force the allocation of [receiver] if need be. *) + force_allocation_if_need_be ctxt receiver >>=? fun ctxt -> (* Test transferring a non null amount. *) - wrap (Token.transfer ctxt `Minted sink amount) >>=? fun (ctxt', bupds) -> - check_sink_balances ctxt ctxt' sink amount >>=? fun () -> + wrap (Token.transfer ctxt `Minted receiver amount) >>=? fun (ctxt', bupds) -> + check_receiver_balances ctxt ctxt' receiver amount >>=? fun () -> let expected_bupds = Receipt.(Minted, Debited amount, Block_application) :: expected_bupds in Alcotest.( check bool "Balance updates do not match." (bupds = expected_bupds) true) ; (* Test transferring to go beyond capacity. *) - wrap (Token.balance ctxt' sink) >>=? fun (ctxt', bal) -> + wrap (Token.balance ctxt' receiver) >>=? fun (ctxt', bal) -> let amount = Tez.of_mutez_exn Int64.max_int -! bal +! Tez.one_mutez in - wrap (Token.transfer ctxt' `Minted sink amount) >>= fun res -> + wrap (Token.transfer ctxt' `Minted receiver amount) >>= fun res -> Assert.proto_error_with_info ~loc:__LOC__ res "Overflowing tez addition" let test_transferring_to_contract ctxt = let pkh, _pk, _sk = Signature.generate_key () in - let dest = Contract.Implicit pkh in + let receiver = Contract.Implicit pkh in let amount = random_amount () in - test_transferring_to_sink + test_transferring_to_receiver ctxt - (`Contract dest) + (`Contract receiver) amount - [(Contract dest, Credited amount, Block_application)] + [(Contract receiver, Credited amount, Block_application)] let test_transferring_to_collected_commitments ctxt = let amount = random_amount () in let bpkh = Blinded_public_key_hash.zero in - test_transferring_to_sink + test_transferring_to_receiver ctxt (`Collected_commitments bpkh) amount @@ -204,18 +210,18 @@ let test_transferring_to_collected_commitments ctxt = let test_transferring_to_delegate_balance ctxt = let pkh, _pk, _sk = Signature.generate_key () in - let dest = Contract.Implicit pkh in + let receiver = Contract.Implicit pkh in let amount = random_amount () in - test_transferring_to_sink + test_transferring_to_receiver ctxt (`Delegate_balance pkh) amount - [(Contract dest, Credited amount, Block_application)] + [(Contract receiver, Credited amount, Block_application)] let test_transferring_to_frozen_deposits ctxt = let pkh, _pk, _sk = Signature.generate_key () in let amount = random_amount () in - test_transferring_to_sink + test_transferring_to_receiver ctxt (`Frozen_deposits pkh) amount @@ -223,7 +229,7 @@ let test_transferring_to_frozen_deposits ctxt = let test_transferring_to_collected_fees ctxt = let amount = random_amount () in - test_transferring_to_sink + test_transferring_to_receiver ctxt `Block_fees amount @@ -287,13 +293,13 @@ let test_transferring_to_frozen_bonds ctxt = let sc_rollup = sc_rollup () in let bond_id = Bond_id.Sc_rollup_bond_id sc_rollup in let amount = random_amount () in - test_transferring_to_sink + test_transferring_to_receiver ctxt (`Frozen_bonds (contract, bond_id)) amount [(Frozen_bonds (contract, bond_id), Credited amount, Block_application)] -let test_transferring_to_sink () = +let test_transferring_to_receiver () = Random.init 0 ; create_context () >>=? fun (ctxt, _) -> test_transferring_to_contract ctxt >>=? fun () -> @@ -304,21 +310,21 @@ let test_transferring_to_sink () = test_transferring_to_burned ctxt >>=? fun () -> test_transferring_to_frozen_bonds ctxt -let check_src_balances ctxt ctxt' src amount = +let check_giver_balances ctxt ctxt' giver amount = let open Lwt_result_wrap_syntax in - wrap (Token.balance ctxt src) >>=? fun (_, bal_src) -> - wrap (Token.balance ctxt' src) >>=? fun (_, bal_src') -> - bal_src' +? amount >>?= fun add_bal_src'_amount -> - Assert.equal_tez ~loc:__LOC__ bal_src add_bal_src'_amount + wrap (Token.balance ctxt giver) >>=? fun (_, bal_giver) -> + wrap (Token.balance ctxt' giver) >>=? fun (_, bal_giver') -> + bal_giver' +? amount >>?= fun add_bal_giver'_amount -> + Assert.equal_tez ~loc:__LOC__ bal_giver add_bal_giver'_amount -let test_transferring_from_unbounded_source ctxt src expected_bupds = +let test_transferring_from_infinite_source ctxt giver expected_bupds = let open Lwt_result_wrap_syntax in (* Transferring zero must not return balance updates. *) - wrap (Token.transfer ctxt src `Burned Tez.zero) >>=? fun (_, bupds) -> + wrap (Token.transfer ctxt giver `Burned Tez.zero) >>=? fun (_, bupds) -> Assert.equal_bool ~loc:__LOC__ (bupds = []) true >>=? fun () -> (* Test transferring a non null amount. *) let amount = random_amount () in - wrap (Token.transfer ctxt src `Burned amount) >>=? fun (_, bupds) -> + wrap (Token.transfer ctxt giver `Burned amount) >>=? fun (_, bupds) -> let expected_bupds = expected_bupds amount @ Receipt.[(Burned, Credited amount, Block_application)] @@ -334,14 +340,14 @@ let balance_no_fail ctxt account = if allocated then wrap (Token.balance ctxt account) else return (ctxt, Tez.zero) -let test_transferring_from_bounded_source ctxt src amount expected_bupds = +let test_transferring_from_container ctxt giver amount expected_bupds = let open Lwt_result_wrap_syntax in - balance_no_fail ctxt src >>=? fun (ctxt, balance) -> + balance_no_fail ctxt giver >>=? fun (ctxt, balance) -> Assert.equal_tez ~loc:__LOC__ balance Tez.zero >>=? fun () -> (* Test transferring from an empty account. *) - wrap (Token.transfer ctxt src `Burned Tez.one) >>= fun res -> + wrap (Token.transfer ctxt giver `Burned Tez.one) >>= fun res -> let error_title = - match src with + match giver with | `Contract _ -> "Balance too low" | `Delegate_balance _ | `Frozen_deposits _ | `Frozen_bonds _ -> "Storage error (fatal internal error)" @@ -349,36 +355,36 @@ let test_transferring_from_bounded_source ctxt src amount expected_bupds = in Assert.proto_error_with_info ~loc:__LOC__ res error_title >>=? fun () -> (* Transferring zero must be a noop, and must not return balance updates. *) - wrap (Token.transfer ctxt src `Burned Tez.zero) >>=? fun (ctxt', bupds) -> + wrap (Token.transfer ctxt giver `Burned Tez.zero) >>=? fun (ctxt', bupds) -> Assert.equal_bool ~loc:__LOC__ (ctxt == ctxt' && bupds = []) true >>=? fun () -> - (* Force the allocation of [dest] if need be. *) - force_allocation_if_need_be ctxt src >>=? fun ctxt -> + (* Force the allocation of [giver] if need be. *) + force_allocation_if_need_be ctxt giver >>=? fun ctxt -> (* Test transferring everything. *) - wrap (Token.transfer ctxt `Minted src amount) >>=? fun (ctxt, _) -> - wrap (Token.transfer ctxt src `Burned amount) >>=? fun (ctxt', bupds) -> - check_src_balances ctxt ctxt' src amount >>=? fun () -> + wrap (Token.transfer ctxt `Minted giver amount) >>=? fun (ctxt, _) -> + wrap (Token.transfer ctxt giver `Burned amount) >>=? fun (ctxt', bupds) -> + check_giver_balances ctxt ctxt' giver amount >>=? fun () -> let expected_bupds = expected_bupds @ Receipt.[(Burned, Credited amount, Block_application)] in Assert.equal_bool ~loc:__LOC__ (bupds = expected_bupds) true >>=? fun () -> (* Test transferring a smaller amount. *) - wrap (Token.transfer ctxt `Minted src amount) >>=? fun (ctxt, _) -> - (match src with + wrap (Token.transfer ctxt `Minted giver amount) >>=? fun (ctxt, _) -> + (match giver with | `Frozen_bonds _ -> - wrap (Token.transfer ctxt src `Burned amount) >>= fun res -> + wrap (Token.transfer ctxt giver `Burned amount) >>= fun res -> let error_title = "Partial spending of frozen bonds" in Assert.proto_error_with_info ~loc:__LOC__ res error_title | _ -> - wrap (Token.transfer ctxt src `Burned amount) >>=? fun (ctxt', bupds) -> - check_src_balances ctxt ctxt' src amount >>=? fun () -> + wrap (Token.transfer ctxt giver `Burned amount) >>=? fun (ctxt', bupds) -> + check_giver_balances ctxt ctxt' giver amount >>=? fun () -> Assert.equal_bool ~loc:__LOC__ (bupds = expected_bupds) true) >>=? fun () -> (* Test transferring more than available. *) - wrap (Token.balance ctxt src) >>=? fun (ctxt, balance) -> - wrap (Token.transfer ctxt src `Burned (balance +! Tez.one)) >>= fun res -> + wrap (Token.balance ctxt giver) >>=? fun (ctxt, balance) -> + wrap (Token.transfer ctxt giver `Burned (balance +! Tez.one)) >>= fun res -> let error_title = - match src with + match giver with | `Contract _ -> "Balance too low" | `Frozen_bonds _ -> "Partial spending of frozen bonds" | _ -> "Underflowing tez subtraction" @@ -387,18 +393,18 @@ let test_transferring_from_bounded_source ctxt src amount expected_bupds = let test_transferring_from_contract ctxt = let pkh, _pk, _sk = Signature.generate_key () in - let src = Contract.Implicit pkh in + let giver = Contract.Implicit pkh in let amount = random_amount () in - test_transferring_from_bounded_source + test_transferring_from_container ctxt - (`Contract src) + (`Contract giver) amount - [(Contract src, Debited amount, Block_application)] + [(Contract giver, Debited amount, Block_application)] let test_transferring_from_collected_commitments ctxt = let amount = random_amount () in let bpkh = Blinded_public_key_hash.zero in - test_transferring_from_bounded_source + test_transferring_from_container ctxt (`Collected_commitments bpkh) amount @@ -407,17 +413,17 @@ let test_transferring_from_collected_commitments ctxt = let test_transferring_from_delegate_balance ctxt = let pkh, _pk, _sk = Signature.generate_key () in let amount = random_amount () in - let src = Contract.Implicit pkh in - test_transferring_from_bounded_source + let giver = Contract.Implicit pkh in + test_transferring_from_container ctxt (`Delegate_balance pkh) amount - [(Contract src, Debited amount, Block_application)] + [(Contract giver, Debited amount, Block_application)] let test_transferring_from_frozen_deposits ctxt = let pkh, _pk, _sk = Signature.generate_key () in let amount = random_amount () in - test_transferring_from_bounded_source + test_transferring_from_container ctxt (`Frozen_deposits pkh) amount @@ -425,7 +431,7 @@ let test_transferring_from_frozen_deposits ctxt = let test_transferring_from_collected_fees ctxt = let amount = random_amount () in - test_transferring_from_bounded_source + test_transferring_from_container ctxt `Block_fees amount @@ -437,46 +443,46 @@ let test_transferring_from_frozen_bonds ctxt = let sc_rollup = sc_rollup () in let bond_id = Bond_id.Sc_rollup_bond_id sc_rollup in let amount = random_amount () in - test_transferring_from_bounded_source + test_transferring_from_container ctxt (`Frozen_bonds (contract, bond_id)) amount [(Frozen_bonds (contract, bond_id), Debited amount, Block_application)] -let test_transferring_from_source () = +let test_transferring_from_giver () = Random.init 0 ; create_context () >>=? fun (ctxt, _) -> - test_transferring_from_unbounded_source ctxt `Invoice (fun am -> + test_transferring_from_infinite_source ctxt `Invoice (fun am -> [(Invoice, Debited am, Block_application)]) >>=? fun () -> - test_transferring_from_unbounded_source ctxt `Bootstrap (fun am -> + test_transferring_from_infinite_source ctxt `Bootstrap (fun am -> [(Bootstrap, Debited am, Block_application)]) >>=? fun () -> - test_transferring_from_unbounded_source ctxt `Initial_commitments (fun am -> + test_transferring_from_infinite_source ctxt `Initial_commitments (fun am -> [(Initial_commitments, Debited am, Block_application)]) >>=? fun () -> - test_transferring_from_unbounded_source ctxt `Revelation_rewards (fun am -> + test_transferring_from_infinite_source ctxt `Revelation_rewards (fun am -> [(Nonce_revelation_rewards, Debited am, Block_application)]) >>=? fun () -> - test_transferring_from_unbounded_source + test_transferring_from_infinite_source ctxt `Double_signing_evidence_rewards (fun am -> [(Double_signing_evidence_rewards, Debited am, Block_application)]) >>=? fun () -> - test_transferring_from_unbounded_source ctxt `Endorsing_rewards (fun am -> + test_transferring_from_infinite_source ctxt `Endorsing_rewards (fun am -> [(Endorsing_rewards, Debited am, Block_application)]) >>=? fun () -> - test_transferring_from_unbounded_source ctxt `Baking_rewards (fun am -> + test_transferring_from_infinite_source ctxt `Baking_rewards (fun am -> [(Baking_rewards, Debited am, Block_application)]) >>=? fun () -> - test_transferring_from_unbounded_source ctxt `Baking_bonuses (fun am -> + test_transferring_from_infinite_source ctxt `Baking_bonuses (fun am -> [(Baking_bonuses, Debited am, Block_application)]) >>=? fun () -> - test_transferring_from_unbounded_source ctxt `Minted (fun am -> + test_transferring_from_infinite_source ctxt `Minted (fun am -> [(Minted, Debited am, Block_application)]) >>=? fun () -> - test_transferring_from_unbounded_source + test_transferring_from_infinite_source ctxt `Liquidity_baking_subsidies (fun am -> [(Liquidity_baking_subsidies, Debited am, Block_application)]) @@ -538,7 +544,7 @@ let build_test_cases () = let bond_id2 = Bond_id.Sc_rollup_bond_id sc_rollup2 in let user1ic = Contract.Implicit user1 in let baker2ic = Contract.Implicit baker2 in - let src_list = + let giver_list = [ (`Invoice, random_amount ()); (`Bootstrap, random_amount ()); @@ -557,7 +563,7 @@ let build_test_cases () = (`Frozen_bonds (baker2ic, bond_id2), random_amount ()); ] in - let dest_list = + let receiver_list = [ `Collected_commitments Blinded_public_key_hash.zero; `Delegate_balance baker1; @@ -572,54 +578,54 @@ let build_test_cases () = `Burned; ] in - return (ctxt, List.product src_list dest_list) + return (ctxt, List.product giver_list receiver_list) -let check_src_balances ctxt ctxt' src amount = - match cast_to_container_type src with +let check_giver_balances ctxt ctxt' giver amount = + match cast_to_container_type giver with | None -> return_unit - | Some src -> check_src_balances ctxt ctxt' src amount + | Some giver -> check_giver_balances ctxt ctxt' giver amount -let check_sink_balances ctxt ctxt' dest amount = - match cast_to_container_type dest with +let check_receiver_balances ctxt ctxt' receiver amount = + match cast_to_container_type receiver with | None -> return_unit - | Some dest -> check_sink_balances ctxt ctxt' dest amount + | Some receiver -> check_receiver_balances ctxt ctxt' receiver amount -let rec check_balances ctxt ctxt' src dest amount = +let rec check_balances ctxt ctxt' giver receiver amount = let open Lwt_result_wrap_syntax in - match (cast_to_container_type src, cast_to_container_type dest) with + match (cast_to_container_type giver, cast_to_container_type receiver) with | None, None -> return_unit | ( Some (`Delegate_balance d), Some (`Contract (Contract.Implicit c) as contract) ) | ( Some (`Contract (Contract.Implicit c) as contract), Some (`Delegate_balance d) ) when d = c -> - (* src and dest are in fact referring to the same contract *) + (* giver and receiver are in fact referring to the same contract *) check_balances ctxt ctxt' contract contract amount - | Some src, Some dest when src = dest -> - (* src and dest are the same contract *) - wrap (Token.balance ctxt dest) >>=? fun (_, bal_dest) -> - wrap (Token.balance ctxt' dest) >>=? fun (_, bal_dest') -> - Assert.equal_tez ~loc:__LOC__ bal_dest bal_dest' - | Some src, None -> check_src_balances ctxt ctxt' src amount - | None, Some dest -> check_sink_balances ctxt ctxt' dest amount - | Some src, Some dest -> - check_src_balances ctxt ctxt' src amount >>=? fun () -> - check_sink_balances ctxt ctxt' dest amount - -let test_all_combinations_of_sources_and_sinks () = + | Some giver, Some receiver when giver = receiver -> + (* giver and receiver are the same contract *) + wrap (Token.balance ctxt receiver) >>=? fun (_, bal_receiver) -> + wrap (Token.balance ctxt' receiver) >>=? fun (_, bal_receiver') -> + Assert.equal_tez ~loc:__LOC__ bal_receiver bal_receiver' + | Some giver, None -> check_giver_balances ctxt ctxt' giver amount + | None, Some receiver -> check_receiver_balances ctxt ctxt' receiver amount + | Some giver, Some receiver -> + check_giver_balances ctxt ctxt' giver amount >>=? fun () -> + check_receiver_balances ctxt ctxt' receiver amount + +let test_all_combinations_of_givers_and_receivers () = let open Lwt_result_wrap_syntax in Random.init 0 ; build_test_cases () >>=? fun (ctxt, cases) -> List.iter_es - (fun ((src, amount), dest) -> - (match cast_to_container_type src with + (fun ((giver, amount), receiver) -> + (match cast_to_container_type giver with | None -> return ctxt - | Some src -> - wrap (Token.transfer ctxt `Minted src amount) >>=? fun (ctxt, _) -> + | Some giver -> + wrap (Token.transfer ctxt `Minted giver amount) >>=? fun (ctxt, _) -> return ctxt) >>=? fun ctxt -> - wrap (Token.transfer ctxt src dest amount) >>=? fun (ctxt', _) -> - check_balances ctxt ctxt' src dest amount) + wrap (Token.transfer ctxt giver receiver amount) >>=? fun (ctxt', _) -> + check_balances ctxt ctxt' giver receiver amount) cases (** [coalesce (account, Credited am1, origin) (account, Credited am2, origin) @@ -662,16 +668,16 @@ let check_balances_are_consistent ctxt1 ctxt2 elt = return_unit (** Test that [transfer_n] is equivalent to n debits followed by n credits. *) -let test_transfer_n ctxt src dest = +let test_transfer_n ctxt giver receiver = (* Run transfer_n. *) - Token.transfer_n ctxt src dest >>=? fun (ctxt1, bal_updates1) -> - (* Debit all sources. *) + Token.transfer_n ctxt giver receiver >>=? fun (ctxt1, bal_updates1) -> + (* Debit all givers. *) List.fold_left_es - (fun (ctxt, bal_updates) (src, am) -> - Token.transfer ctxt src `Burned am >>=? fun (ctxt, debit_logs) -> + (fun (ctxt, bal_updates) (giver, am) -> + Token.transfer ctxt giver `Burned am >>=? fun (ctxt, debit_logs) -> return (ctxt, bal_updates @ debit_logs)) (ctxt, []) - src + giver >>=? fun (ctxt, debit_logs) -> (* remove burning balance updates *) let debit_logs = @@ -679,13 +685,13 @@ let test_transfer_n ctxt src dest = (fun b -> match b with Receipt.Burned, _, _ -> false | _ -> true) debit_logs in - (* Credit the sink for each source. *) + (* Credit the receiver for each giver. *) List.fold_left_es (fun (ctxt, bal_updates) (_, am) -> - Token.transfer ctxt `Minted dest am >>=? fun (ctxt, credit_logs) -> + Token.transfer ctxt `Minted receiver am >>=? fun (ctxt, credit_logs) -> return (ctxt, bal_updates @ credit_logs)) (ctxt, []) - src + giver >>=? fun (ctxt2, credit_logs) -> (* remove minting balance updates *) let credit_logs = @@ -701,18 +707,18 @@ let test_transfer_n ctxt src dest = in assert (bal_updates1 = debit_logs @ credit_logs) ; (* Check balances are the same in ctxt1 and ctxt2. *) - List.(iter_es (check_balances_are_consistent ctxt1 ctxt2) (map fst src)) - >>=? fun () -> check_balances_are_consistent ctxt1 ctxt2 dest + List.(iter_es (check_balances_are_consistent ctxt1 ctxt2) (map fst giver)) + >>=? fun () -> check_balances_are_consistent ctxt1 ctxt2 receiver -let test_transfer_n_with_empty_source () = +let test_transfer_n_with_no_giver () = let open Lwt_result_wrap_syntax in Random.init 0 ; create_context () >>=? fun (ctxt, pkh) -> wrap (test_transfer_n ctxt [] `Block_fees) >>=? fun () -> - let dest = `Delegate_balance pkh in - wrap (test_transfer_n ctxt [] dest) + let receiver = `Delegate_balance pkh in + wrap (test_transfer_n ctxt [] receiver) -let test_transfer_n_with_non_empty_source () = +let test_transfer_n_with_several_givers () = let open Lwt_result_wrap_syntax in Random.init 0 ; create_context () >>=? fun (ctxt, pkh) -> @@ -734,15 +740,15 @@ let test_transfer_n_with_non_empty_source () = wrap (Token.transfer ctxt origin user3c amount) >>=? fun (ctxt, _) -> wrap (Token.transfer ctxt origin user4c (random_amount ())) >>=? fun (ctxt, _) -> - let sources = + let givers = [ (user2c, random_amount ()); (user3c, random_amount ()); (user4c, random_amount ()); ] in - wrap (test_transfer_n ctxt sources user1c) >>=? fun () -> - wrap (test_transfer_n ctxt ((user1c, random_amount ()) :: sources) user1c) + wrap (test_transfer_n ctxt givers user1c) >>=? fun () -> + wrap (test_transfer_n ctxt ((user1c, random_amount ()) :: givers) user1c) let tests = Tztest. @@ -750,21 +756,24 @@ let tests = tztest "transfer - balances" `Quick test_simple_balances; tztest "transfer - balance updates" `Quick test_simple_balance_updates; tztest "transfer - test allocated" `Quick test_allocated; - tztest "transfer - test transfer to sink" `Quick test_transferring_to_sink; tztest - "transfer - test transfer from source" + "transfer - test transfer to receiver" + `Quick + test_transferring_to_receiver; + tztest + "transfer - test transfer from giver" `Quick - test_transferring_from_source; + test_transferring_from_giver; tztest - "transfer - test all (sources x sinks)" + "transfer - test all (givers x receivers)" `Quick - test_all_combinations_of_sources_and_sinks; + test_all_combinations_of_givers_and_receivers; tztest - "transfer - test from empty sources to a destination" + "transfer - test from no giver to a receiver" `Quick - test_transfer_n_with_empty_source; + test_transfer_n_with_no_giver; tztest - "transfer - test from n sources to a destination" + "transfer - test from n givers to a receiver" `Quick - test_transfer_n_with_non_empty_source; + test_transfer_n_with_several_givers; ] diff --git a/src/proto_alpha/lib_protocol/token.ml b/src/proto_alpha/lib_protocol/token.ml index 072cb8e262a423bab337a3d4a82af49b31418356..d1c4d97667cb8a958d27849cfa03493f997cfeaa 100644 --- a/src/proto_alpha/lib_protocol/token.ml +++ b/src/proto_alpha/lib_protocol/token.ml @@ -45,7 +45,7 @@ type infinite_source = | `Tx_rollup_rejection_rewards | `Sc_rollup_refutation_rewards ] -type source = [infinite_source | container] +type giver = [infinite_source | container] type infinite_sink = [ `Storage_fees @@ -55,7 +55,7 @@ type infinite_sink = | `Sc_rollup_refutation_punishments | `Burned ] -type sink = [infinite_sink | container] +type receiver = [infinite_sink | container] let allocated ctxt stored = match stored with @@ -104,9 +104,9 @@ let balance ctxt stored = >|=? fun (ctxt, balance_opt) -> (ctxt, Option.value ~default:Tez_repr.zero balance_opt) -let credit ctxt dest amount origin = +let credit ctxt receiver amount origin = let open Receipt_repr in - (match dest with + (match receiver with | #infinite_sink as infinite_sink -> let sink = match infinite_sink with @@ -120,9 +120,9 @@ let credit ctxt dest amount origin = return (ctxt, sink) | #container as container -> ( match container with - | `Contract dest -> - Contract_storage.credit_only_call_from_token ctxt dest amount - >|=? fun ctxt -> (ctxt, Contract dest) + | `Contract receiver -> + Contract_storage.credit_only_call_from_token ctxt receiver amount + >|=? fun ctxt -> (ctxt, Contract receiver) | `Collected_commitments bpkh -> Commitment_storage.increase_commitment_only_call_from_token ctxt @@ -136,8 +136,8 @@ let credit ctxt dest amount origin = contract amount >|=? fun ctxt -> (ctxt, Contract contract) - | `Frozen_deposits delegate as dest -> - allocated ctxt dest >>=? fun (ctxt, allocated) -> + | `Frozen_deposits delegate as receiver -> + allocated ctxt receiver >>=? fun (ctxt, allocated) -> (if not allocated then Frozen_deposits_storage.init ctxt delegate else return ctxt) >>=? fun ctxt -> @@ -158,9 +158,9 @@ let credit ctxt dest amount origin = >>=? fun ctxt -> return (ctxt, Frozen_bonds (contract, bond_id)))) >|=? fun (ctxt, balance) -> (ctxt, (balance, Credited amount, origin)) -let spend ctxt src amount origin = +let spend ctxt giver amount origin = let open Receipt_repr in - (match src with + (match giver with | #infinite_source as infinite_source -> let src = match infinite_source with @@ -180,9 +180,9 @@ let spend ctxt src amount origin = return (ctxt, src) | #container as container -> ( match container with - | `Contract src -> - Contract_storage.spend_only_call_from_token ctxt src amount - >|=? fun ctxt -> (ctxt, Contract src) + | `Contract giver -> + Contract_storage.spend_only_call_from_token ctxt giver amount + >|=? fun ctxt -> (ctxt, Contract giver) | `Collected_commitments bpkh -> Commitment_storage.decrease_commitment_only_call_from_token ctxt @@ -214,40 +214,41 @@ let spend ctxt src amount origin = >>=? fun ctxt -> return (ctxt, Frozen_bonds (contract, bond_id)))) >|=? fun (ctxt, balance) -> (ctxt, (balance, Debited amount, origin)) -let transfer_n ?(origin = Receipt_repr.Block_application) ctxt src dest = - let sources = List.filter (fun (_, am) -> Tez_repr.(am <> zero)) src in - match sources with +let transfer_n ?(origin = Receipt_repr.Block_application) ctxt givers receiver = + let givers = List.filter (fun (_, am) -> Tez_repr.(am <> zero)) givers in + match givers with | [] -> (* Avoid accessing context data when there is nothing to transfer. *) return (ctxt, []) | _ :: _ -> - (* Withdraw from sources. *) + (* Withdraw from givers. *) List.fold_left_es - (fun (ctxt, total, debit_logs) (source, amount) -> - spend ctxt source amount origin >>=? fun (ctxt, debit_log) -> + (fun (ctxt, total, debit_logs) (giver, amount) -> + spend ctxt giver amount origin >>=? fun (ctxt, debit_log) -> Tez_repr.(amount +? total) >>?= fun total -> return (ctxt, total, debit_log :: debit_logs)) (ctxt, Tez_repr.zero, []) - sources + givers >>=? fun (ctxt, amount, debit_logs) -> - credit ctxt dest amount origin >>=? fun (ctxt, credit_log) -> + credit ctxt receiver amount origin >>=? fun (ctxt, credit_log) -> (* Deallocate implicit contracts with no stake. This must be done after spending and crediting. If done in between then a transfer of all the balance from (`Contract c) to (`Frozen_bonds (c,_)) would leave the contract c unallocated. *) List.fold_left_es - (fun ctxt (source, _amount) -> - match source with + (fun ctxt (giver, _amount) -> + match giver with | `Contract contract | `Frozen_bonds (contract, _) -> Contract_storage.ensure_deallocated_if_empty ctxt contract - | #source -> return ctxt) + | #giver -> return ctxt) ctxt - sources + givers >|=? fun ctxt -> (* Make sure the order of balance updates is : debit logs in the order of - of the parameter [src], and then the credit log. *) + of the parameter [givers], and then the credit log. *) let balance_updates = List.rev (credit_log :: debit_logs) in (ctxt, balance_updates) -let transfer ?(origin = Receipt_repr.Block_application) ctxt src dest amount = - transfer_n ~origin ctxt [(src, amount)] dest +let transfer ?(origin = Receipt_repr.Block_application) ctxt giver receiver + amount = + transfer_n ~origin ctxt [(giver, amount)] receiver diff --git a/src/proto_alpha/lib_protocol/token.mli b/src/proto_alpha/lib_protocol/token.mli index 0e6595f90b8bf8fb6d163974edb92f5f21d6a0b3..3b75692e1cf77cf2b98cfc99b600c2d87f64c964 100644 --- a/src/proto_alpha/lib_protocol/token.mli +++ b/src/proto_alpha/lib_protocol/token.mli @@ -24,15 +24,15 @@ (*****************************************************************************) (** The aim of this module is to manage operations involving tokens such as - minting, transferring, and burning. Every constructor of the types [source], - [container], or [sink] represents a kind of account that holds a given (or + minting, transferring, and burning. Every constructor of the types [giver], + [container], or [receiver] represents a kind of account that holds a given (or possibly infinite) amount of tokens. - Tokens can be transferred from a [source] to a [sink]. To uniformly handle - all cases, special constructors of sources and sinks may be used. For - example, the source [`Minted] is used to express a transfer of minted tokens - to a destination, and the sink [`Burned] is used to express the action of - burning a given amount of tokens taken from a source. Thanks to uniformity, + Tokens can be transferred from a [giver] to a [receiver]. To uniformly handle + all cases, special constructors of givers and receivers may be used. For + example, the giver [`Minted] is used to express a transfer of minted tokens + to a receiver, and the receiver [`Burned] is used to express the action of + burning a given amount of tokens taken from a giver. Thanks to uniformity, it is easier to track transfers of tokens throughout the protocol by running [grep -R "Token.transfer" src/proto_alpha]. @@ -76,7 +76,7 @@ type container = (** Frozen tokens of a contract for bond deposits (currently used by rollups) *) ] -(** [infinite_source] defines types of tokens provides which are considered to be +(** [infinite_source] defines types of tokens providers which are considered to be ** of infinite capacity. *) type infinite_source = [ `Invoice @@ -98,9 +98,9 @@ type infinite_source = | `Sc_rollup_refutation_rewards (** Sc_rollup refutation rewards (slashing redistribution) *) ] -(** [source] is the type of token providers. Token providers that are not +(** [giver] is the type of token providers. Token providers that are not containers are considered to have infinite capacity. *) -type source = [infinite_source | container] +type giver = [infinite_source | container] type infinite_sink = [ `Storage_fees (** Fees burnt to compensate storage usage *) @@ -112,9 +112,9 @@ type infinite_sink = | `Sc_rollup_refutation_punishments (** Smart rollups refutation slashing *) | `Burned (** Generic sink mainly for test purpose *) ] -(** [sink] is the type of token receivers. Token receivers that are not +(** [receiver] is the type of token receivers. Token receivers that are not containers are considered to have infinite capacity. *) -type sink = [infinite_sink | container] +type receiver = [infinite_sink | container] (** [allocated ctxt container] returns a new context because of possible access to carbonated data, and a boolean that is [true] when @@ -134,46 +134,46 @@ val allocated : val balance : Raw_context.t -> container -> (Raw_context.t * Tez_repr.t) tzresult Lwt.t -(** [transfer_n ?origin ctxt sources dest] transfers [amount] Tez from [src] to - [dest] for each [(src, amount)] pair in [sources], and returns a new +(** [transfer_n ?origin ctxt givers receiver] transfers [amount] Tez from [giver] to + [receiver] for each [(giver, amount)] pair in [givers], and returns a new context, and the list of corresponding balance updates. The function behaves - as though [transfer src dest amount] was invoked for each pair - [(src, amount)] in [sources], however a single balance update is generated - for the total amount transferred to [dest]. - When [sources] is an empty list, the function does nothing to the context, + as though [transfer ?origin ctxt giver receiver amount] was invoked for each pair + [(giver, amount)] in [givers], however a single balance update is generated + for the total amount transferred to [receiver]. + When [givers] is an empty list, the function does nothing to the context, and returns an empty list of balance updates. *) val transfer_n : ?origin:Receipt_repr.update_origin -> Raw_context.t -> - ([< source] * Tez_repr.t) list -> - [< sink] -> + ([< giver] * Tez_repr.t) list -> + [< receiver] -> (Raw_context.t * Receipt_repr.balance_updates) tzresult Lwt.t -(** [transfer ?origin ctxt src dest amount] transfers [amount] Tez from source - [src] to destination [dest], and returns a new context, and the list of +(** [transfer ?origin ctxt giver receiver amount] transfers [amount] Tez from giver + [giver] to receiver [receiver], and returns a new context, and the list of corresponding balance updates tagged with [origin]. By default, [~origin] is set to [Receipt_repr.Block_application]. - Returns {!Storage_Error Missing_key} if [src] refers to a contract that is + Returns {!Storage_Error Missing_key} if [giver] refers to a contract that is not allocated. - Returns a [Balance_too_low] error if [src] refers to a contract whose + Returns a [Balance_too_low] error if [giver] refers to a contract whose balance is less than [amount]. - Returns a [Subtraction_underflow] error if [src] refers to a source that is - not a contract and whose balance is less than [amount]. - Returns a [Empty_implicit_delegated_contract] error if [src] is an + Returns a [Subtraction_underflow] error if [giver] is + not a contract and its balance is less than [amount]. + Returns a [Empty_implicit_delegated_contract] error if [giver] is an implicit contract that delegates to a different contract, and whose balance is equal to [amount]. Returns a [Non_existing_contract] error if - [dest] refers to an originated contract that is not allocated. + [receiver] refers to an originated contract that is not allocated. Returns a [Non_existing_contract] error if [amount <> Tez_repr.zero], and - [dest] refers to an originated contract that is not allocated. - Returns a [Addition_overflow] error if [dest] refers to a sink whose balance + [receiver] refers to an originated contract that is not allocated. + Returns a [Addition_overflow] error if [receiver] refers to a receiver whose balance is greater than [Int64.max - amount]. - Returns a [Wrong_level] error if [src] or [dest] refer to a level that is + Returns a [Wrong_level] error if [src] or [receiver] refer to a level that is not the current level. *) val transfer : ?origin:Receipt_repr.update_origin -> Raw_context.t -> - [< source] -> - [< sink] -> + [< giver] -> + [< receiver] -> Tez_repr.t -> (Raw_context.t * Receipt_repr.balance_updates) tzresult Lwt.t