-
Notifications
You must be signed in to change notification settings - Fork 3
/
token-bridge-helper.tz
220 lines (219 loc) · 7.81 KB
/
token-bridge-helper.tz
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
{ parameter
(or (pair %withdraw (address %receiver) (ticket %ticket (pair nat (option bytes))))
(or (ticket %unwrap (pair nat (option bytes)))
(or (ticket %default (pair nat (option bytes)))
(pair %deposit (address %rollup) (bytes %receiver) (nat %amount))))) ;
storage
(pair (or %token (address %fa12) (pair %fa2 address nat))
(address %ticketer)
(bytes %erc_proxy)
(option %context (pair (bytes %receiver) (address %rollup)))
(big_map %metadata string bytes)) ;
code { PUSH string "INVALID_FA12" ;
PUSH string "INVALID_FA2" ;
LAMBDA
unit
unit
{ PUSH mutez 0 ;
AMOUNT ;
COMPARE ;
GT ;
IF { DROP ; PUSH string "XTZ_DEPOSIT_DISALLOWED" ; FAILWITH } {} } ;
LAMBDA
(pair address address (ticket (pair nat (option bytes))))
operation
{ UNPAIR ;
CONTRACT %withdraw
(pair (address %receiver) (ticket %ticket (pair nat (option bytes)))) ;
IF_NONE { PUSH string "ROUTER_ENTRYPOINT_NOT_FOUND" ; FAILWITH } {} ;
PUSH mutez 0 ;
DIG 2 ;
TRANSFER_TOKENS } ;
DIG 4 ;
UNPAIR ;
IF_LEFT
{ DIG 3 ;
DIG 4 ;
DIG 5 ;
DROP 3 ;
UNPAIR ;
SWAP ;
READ_TICKET ;
CAR ;
SWAP ;
DIG 2 ;
PAIR ;
SWAP ;
PAIR ;
DIG 2 ;
SWAP ;
EXEC ;
SWAP ;
NIL operation ;
DIG 2 ;
CONS ;
PAIR }
{ IF_LEFT
{ DIG 4 ;
DIG 5 ;
DROP 2 ;
UNIT ;
DIG 4 ;
SWAP ;
EXEC ;
DROP ;
SENDER ;
PAIR ;
DUP 2 ;
GET 3 ;
PAIR ;
DIG 2 ;
SWAP ;
EXEC ;
SWAP ;
NIL operation ;
DIG 2 ;
CONS ;
PAIR }
{ DIG 2 ;
DROP ;
IF_LEFT
{ DIG 3 ;
DIG 4 ;
DROP 2 ;
UNIT ;
DIG 3 ;
SWAP ;
EXEC ;
DROP ;
SENDER ;
DUP 3 ;
GET 3 ;
COMPARE ;
NEQ ;
IF { PUSH string "UNEXPECTED_SENDER" ; FAILWITH } {} ;
DUP 2 ;
GET 7 ;
IF_NONE
{ DROP 2 ; PUSH string "ROUTING_DATA_IS_NOT_SET" ; FAILWITH }
{ UNPAIR ;
DUP 4 ;
GET 5 ;
SWAP ;
CONCAT ;
PUSH nat 40 ;
DUP 2 ;
SIZE ;
COMPARE ;
NEQ ;
IF { PUSH string "WRONG_ROUTING_INFO_LENGTH" ; FAILWITH } {} ;
DIG 2 ;
SWAP ;
PAIR ;
LEFT bytes ;
LEFT bytes ;
SWAP ;
CONTRACT
(or (or (pair %deposit (bytes %routing_info) (ticket %ticket (pair nat (option bytes))))
(bytes %b))
(bytes %c)) ;
IF_NONE { PUSH string "ROLLUP_DEPOSIT_NOT_FOUND" ; FAILWITH } {} ;
PUSH mutez 0 ;
DIG 2 ;
TRANSFER_TOKENS ;
SWAP ;
NONE (pair bytes address) ;
UPDATE 7 ;
NIL operation ;
DIG 2 ;
CONS ;
PAIR } }
{ UNPAIR 3 ;
UNIT ;
DIG 5 ;
SWAP ;
EXEC ;
DROP ;
DUP 4 ;
CAR ;
DUP 5 ;
GET 3 ;
SENDER ;
SELF_ADDRESS ;
DUP 4 ;
IF_LEFT
{ CONTRACT %transfer (pair (address %from) (address %to) (nat %value)) ;
IF_NONE { DUP 10 ; FAILWITH } {} ;
PUSH mutez 0 ;
DUP 9 ;
DIG 3 ;
DIG 4 ;
PAIR 3 ;
TRANSFER_TOKENS }
{ UNPAIR ;
CONTRACT %transfer
(list (pair (address %from_) (list %txs (pair (address %to_) (nat %token_id) (nat %amount))))) ;
IF_NONE { DUP 10 ; FAILWITH } {} ;
PUSH mutez 0 ;
NIL (pair address (list (pair address nat nat))) ;
NIL (pair address nat nat) ;
DUP 12 ;
DIG 5 ;
DIG 6 ;
PAIR 3 ;
CONS ;
DIG 4 ;
PAIR ;
CONS ;
TRANSFER_TOKENS } ;
DUP 2 ;
CONTRACT %deposit nat ;
IF_NONE { PUSH string "TKTR_DEPOSIT_NOT_FOUND" ; FAILWITH } {} ;
PUSH mutez 0 ;
DUP 8 ;
TRANSFER_TOKENS ;
DIG 3 ;
IF_LEFT
{ DIG 8 ;
DROP ;
CONTRACT %approve (pair (address %spender) (nat %value)) ;
IF_NONE { DIG 7 ; FAILWITH } { DIG 8 ; DROP } ;
PUSH mutez 0 ;
DIG 7 ;
DIG 5 ;
PAIR ;
TRANSFER_TOKENS }
{ DIG 6 ;
DIG 9 ;
DROP 2 ;
UNPAIR ;
SELF_ADDRESS ;
NIL (or (pair address address nat) (pair address address nat)) ;
DIG 3 ;
DIG 6 ;
DIG 3 ;
PAIR 3 ;
LEFT (pair address address nat) ;
CONS ;
SWAP ;
CONTRACT %update_operators
(list (or (pair %add_operator (address %owner) (address %operator) (nat %token_id))
(pair %remove_operator (address %owner) (address %operator) (nat %token_id)))) ;
IF_NONE { DIG 6 ; FAILWITH } { DIG 7 ; DROP } ;
PUSH mutez 0 ;
DIG 2 ;
TRANSFER_TOKENS } ;
DIG 5 ;
DIG 4 ;
DIG 5 ;
PAIR ;
SOME ;
UPDATE 7 ;
NIL operation ;
DIG 3 ;
CONS ;
DIG 2 ;
CONS ;
DIG 2 ;
CONS ;
PAIR } } } } }