forked from tezos-checker/checker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfa2Interface.ml
More file actions
156 lines (129 loc) · 3.46 KB
/
fa2Interface.ml
File metadata and controls
156 lines (129 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
(*
* INTERFACE
*)
(*
Adapted from:
https://gitlab.com/tzip/tzip/-/blob/4b3c67aad5abbf04ec36caea4a1809e7b6e55bb8/proposals/tzip-12/fa2_interface.mligo
Currently we only implement the absolute requirements of the interface. We also:
* TODO should consider implementing permission policies
*)
[@@@coverage off]
type fa2_token_id = Ligo.nat
[@@deriving show]
type fa2_transfer_destination =
(* BEGIN_LIGO [@layout:comb] END_LIGO *)
{
to_ : Ligo.address;
token_id : fa2_token_id;
amount : Ligo.nat;
}
[@@deriving show]
type fa2_transfer =
(* BEGIN_LIGO [@layout:comb] END_LIGO *)
{
from_ : Ligo.address;
txs : fa2_transfer_destination list;
}
[@@deriving show]
type fa2_balance_of_request =
(* BEGIN_LIGO [@layout:comb] END_LIGO *)
{
owner : Ligo.address;
token_id : fa2_token_id;
}
[@@deriving show]
type fa2_balance_of_response =
(* BEGIN_LIGO [@layout:comb] END_LIGO *)
{
request : fa2_balance_of_request;
balance : Ligo.nat;
}
[@@deriving show]
type fa2_balance_of_param =
(* BEGIN_LIGO [@layout:comb] END_LIGO *)
{
requests : fa2_balance_of_request list;
callback : (fa2_balance_of_response list) Ligo.contract;
}
type fa2_operator_param =
(* BEGIN_LIGO [@layout:comb] END_LIGO *)
{
owner : Ligo.address;
operator : Ligo.address;
token_id: fa2_token_id;
}
type fa2_update_operator =
(* BEGIN_LIGO [@layout:comb] END_LIGO *)
| Add_operator of fa2_operator_param
| Remove_operator of fa2_operator_param
type token_metadata =
(* BEGIN_LIGO [@layout:comb] END_LIGO *)
{
token_id : fa2_token_id;
token_info : (string, Ligo.bytes) Ligo.map;
}
(*
One of the options to make token metadata discoverable is to declare
`token_metadata : token_metadata_storage` field inside the FA2 contract storage
*)
type token_metadata_storage = (fa2_token_id, token_metadata) Ligo.big_map
(**
Optional type to define view entry point to expose token_metadata on chain or
as an external view
*)
type token_metadata_param =
(* BEGIN_LIGO [@layout:comb] END_LIGO *)
{
token_ids : fa2_token_id list;
handler : (token_metadata list) -> unit;
}
(* Each FA2-compliant contract should implement the following entrypoints:
type fa2_entry_points =
| Transfer of fa2_transfer list
| Balance_of of fa2_balance_of_param
| Update_operators of fa2_update_operator list
*)
(*
TZIP-16 contract metadata storage field type.
The contract storage MUST have a field
`metadata : contract_metadata`
*)
type contract_metadata = (string, Ligo.bytes) Ligo.big_map
(*
(* FA2 hooks interface *)
type fa2_transfer_destination_descriptor =
(* BEGIN_LIGO [@layout:comb] END_LIGO *)
{
to_ : Ligo.address option;
token_id : fa2_token_id;
amount : Ligo.nat;
}
type fa2_transfer_descriptor =
(* BEGIN_LIGO [@layout:comb] END_LIGO *)
{
from_ : Ligo.address option;
txs : fa2_transfer_destination_descriptor list
}
type transfer_descriptor_param =
(* BEGIN_LIGO [@layout:comb] END_LIGO *)
{
batch : fa2_transfer_descriptor list;
operator : Ligo.address;
}
Entrypoints for sender/receiver hooks
type fa2_token_receiver =
...
| Tokens_received of transfer_descriptor_param
type fa2_token_sender =
...
| Tokens_sent of transfer_descriptor_param
*)
[@@@coverage on]
(* BEGIN_OCAML *)
[@@@coverage off]
type fa2_balance_of_response_list = fa2_balance_of_response list
[@@deriving show]
type fa2_transfer_list = fa2_transfer list
[@@deriving show]
[@@@coverage on]
(* END_OCAML *)