├── .gitattributes
├── .gitignore
├── LICENSE.md
├── README.md
├── abi
├── uniswap_exchange.json
└── uniswap_factory.json
├── bytecode
├── exchange.txt
└── factory.txt
├── contracts
├── test_contracts
│ └── ERC20.vy
├── uniswap_exchange.vy
└── uniswap_factory.vy
├── requirements.txt
└── tests
├── __init__.py
├── conftest.py
├── constants.py
└── exchange
├── test_ERC20.py
├── test_eth_to_token.py
├── test_factory.py
├── test_liquidity_pool.py
├── test_token_to_eth.py
├── test_token_to_exchange.py
└── test_token_to_token.py
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.vy linguist-language=Python
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | __pycache__/
2 | *.pyc
3 | *.pyo
4 | .DS_Store
5 | .cache
6 | .pytest_cache/
7 | env/
8 | vyper/
9 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | * Website: [uniswap.io/](https://uniswap.io/)
2 | * Docs: [docs.uniswap.io/](https://docs.uniswap.io/)
3 | * Twitter: [@UniswapExchange](https://twitter.com/UniswapExchange)
4 | * Reddit: [/r/Uniswap/](https://www.reddit.com/r/UniSwap/)
5 | * Email: [contact@uniswap.io](mailto:contact@uniswap.io)
6 | * Slack: [uni-swap.slack.com/](https://join.slack.com/t/uni-swap/shared_invite/enQtNDYwMjg1ODc5ODA4LWEyYmU0OGU1ZGQ3NjE4YzhmNzcxMDAyM2ExNzNkZjZjZjcxYTkwNzU0MGE3M2JkNzMxOTA2MzE2ZWM0YWQwNjU)
7 | * Whitepaper: [Link](https://hackmd.io/C-DvwDSfSxuh-Gd4WKE_ig)
8 |
9 | ## Installation:
10 |
11 | #### Requires [Python 3](https://www.python.org/download/releases/3.0/)
12 |
13 | 1) Clone Uniswap
14 | ```
15 | $ git clone https://github.com/Uniswap/contracts-vyper
16 | $ cd contracts-vyper
17 | ```
18 |
19 | 2) Setup virtual environment
20 | ```
21 | $ pip3 install virtualenv
22 | $ virtualenv -p python3 env
23 | $ source env/bin/activate
24 | ```
25 |
26 | 3) Install dependencies
27 | ```
28 | pip install -r requirements.txt
29 | ```
30 |
31 | 4) (Optional) Switch Vyper compiler to version used in Uniswap [verification](https://github.com/runtimeverification/verified-smart-contracts/tree/uniswap/uniswap)
32 | ```
33 | cd vyper
34 | git reset --hard 35038d20bd9946a35261c4c4fbcb27fe61e65f78
35 | cd ..
36 | ```
37 |
38 | 5) Run tests
39 | ```
40 | $ pytest -v tests/
41 | ```
42 |
--------------------------------------------------------------------------------
/abi/uniswap_exchange.json:
--------------------------------------------------------------------------------
1 | [{"name": "TokenPurchase", "inputs": [{"type": "address", "name": "buyer", "indexed": true}, {"type": "uint256", "name": "eth_sold", "indexed": true}, {"type": "uint256", "name": "tokens_bought", "indexed": true}], "anonymous": false, "type": "event"}, {"name": "EthPurchase", "inputs": [{"type": "address", "name": "buyer", "indexed": true}, {"type": "uint256", "name": "tokens_sold", "indexed": true}, {"type": "uint256", "name": "eth_bought", "indexed": true}], "anonymous": false, "type": "event"}, {"name": "AddLiquidity", "inputs": [{"type": "address", "name": "provider", "indexed": true}, {"type": "uint256", "name": "eth_amount", "indexed": true}, {"type": "uint256", "name": "token_amount", "indexed": true}], "anonymous": false, "type": "event"}, {"name": "RemoveLiquidity", "inputs": [{"type": "address", "name": "provider", "indexed": true}, {"type": "uint256", "name": "eth_amount", "indexed": true}, {"type": "uint256", "name": "token_amount", "indexed": true}], "anonymous": false, "type": "event"}, {"name": "Transfer", "inputs": [{"type": "address", "name": "_from", "indexed": true}, {"type": "address", "name": "_to", "indexed": true}, {"type": "uint256", "name": "_value", "indexed": false}], "anonymous": false, "type": "event"}, {"name": "Approval", "inputs": [{"type": "address", "name": "_owner", "indexed": true}, {"type": "address", "name": "_spender", "indexed": true}, {"type": "uint256", "name": "_value", "indexed": false}], "anonymous": false, "type": "event"}, {"name": "setup", "outputs": [], "inputs": [{"type": "address", "name": "token_addr"}], "constant": false, "payable": false, "type": "function", "gas": 175875}, {"name": "addLiquidity", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [{"type": "uint256", "name": "min_liquidity"}, {"type": "uint256", "name": "max_tokens"}, {"type": "uint256", "name": "deadline"}], "constant": false, "payable": true, "type": "function", "gas": 82616}, {"name": "removeLiquidity", "outputs": [{"type": "uint256", "name": "out"}, {"type": "uint256", "name": "out"}], "inputs": [{"type": "uint256", "name": "amount"}, {"type": "uint256", "name": "min_eth"}, {"type": "uint256", "name": "min_tokens"}, {"type": "uint256", "name": "deadline"}], "constant": false, "payable": false, "type": "function", "gas": 116814}, {"name": "__default__", "outputs": [], "inputs": [], "constant": false, "payable": true, "type": "function"}, {"name": "ethToTokenSwapInput", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [{"type": "uint256", "name": "min_tokens"}, {"type": "uint256", "name": "deadline"}], "constant": false, "payable": true, "type": "function", "gas": 12757}, {"name": "ethToTokenTransferInput", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [{"type": "uint256", "name": "min_tokens"}, {"type": "uint256", "name": "deadline"}, {"type": "address", "name": "recipient"}], "constant": false, "payable": true, "type": "function", "gas": 12965}, {"name": "ethToTokenSwapOutput", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [{"type": "uint256", "name": "tokens_bought"}, {"type": "uint256", "name": "deadline"}], "constant": false, "payable": true, "type": "function", "gas": 50463}, {"name": "ethToTokenTransferOutput", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [{"type": "uint256", "name": "tokens_bought"}, {"type": "uint256", "name": "deadline"}, {"type": "address", "name": "recipient"}], "constant": false, "payable": true, "type": "function", "gas": 50671}, {"name": "tokenToEthSwapInput", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [{"type": "uint256", "name": "tokens_sold"}, {"type": "uint256", "name": "min_eth"}, {"type": "uint256", "name": "deadline"}], "constant": false, "payable": false, "type": "function", "gas": 47503}, {"name": "tokenToEthTransferInput", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [{"type": "uint256", "name": "tokens_sold"}, {"type": "uint256", "name": "min_eth"}, {"type": "uint256", "name": "deadline"}, {"type": "address", "name": "recipient"}], "constant": false, "payable": false, "type": "function", "gas": 47712}, {"name": "tokenToEthSwapOutput", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [{"type": "uint256", "name": "eth_bought"}, {"type": "uint256", "name": "max_tokens"}, {"type": "uint256", "name": "deadline"}], "constant": false, "payable": false, "type": "function", "gas": 50175}, {"name": "tokenToEthTransferOutput", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [{"type": "uint256", "name": "eth_bought"}, {"type": "uint256", "name": "max_tokens"}, {"type": "uint256", "name": "deadline"}, {"type": "address", "name": "recipient"}], "constant": false, "payable": false, "type": "function", "gas": 50384}, {"name": "tokenToTokenSwapInput", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [{"type": "uint256", "name": "tokens_sold"}, {"type": "uint256", "name": "min_tokens_bought"}, {"type": "uint256", "name": "min_eth_bought"}, {"type": "uint256", "name": "deadline"}, {"type": "address", "name": "token_addr"}], "constant": false, "payable": false, "type": "function", "gas": 51007}, {"name": "tokenToTokenTransferInput", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [{"type": "uint256", "name": "tokens_sold"}, {"type": "uint256", "name": "min_tokens_bought"}, {"type": "uint256", "name": "min_eth_bought"}, {"type": "uint256", "name": "deadline"}, {"type": "address", "name": "recipient"}, {"type": "address", "name": "token_addr"}], "constant": false, "payable": false, "type": "function", "gas": 51098}, {"name": "tokenToTokenSwapOutput", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [{"type": "uint256", "name": "tokens_bought"}, {"type": "uint256", "name": "max_tokens_sold"}, {"type": "uint256", "name": "max_eth_sold"}, {"type": "uint256", "name": "deadline"}, {"type": "address", "name": "token_addr"}], "constant": false, "payable": false, "type": "function", "gas": 54928}, {"name": "tokenToTokenTransferOutput", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [{"type": "uint256", "name": "tokens_bought"}, {"type": "uint256", "name": "max_tokens_sold"}, {"type": "uint256", "name": "max_eth_sold"}, {"type": "uint256", "name": "deadline"}, {"type": "address", "name": "recipient"}, {"type": "address", "name": "token_addr"}], "constant": false, "payable": false, "type": "function", "gas": 55019}, {"name": "tokenToExchangeSwapInput", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [{"type": "uint256", "name": "tokens_sold"}, {"type": "uint256", "name": "min_tokens_bought"}, {"type": "uint256", "name": "min_eth_bought"}, {"type": "uint256", "name": "deadline"}, {"type": "address", "name": "exchange_addr"}], "constant": false, "payable": false, "type": "function", "gas": 49342}, {"name": "tokenToExchangeTransferInput", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [{"type": "uint256", "name": "tokens_sold"}, {"type": "uint256", "name": "min_tokens_bought"}, {"type": "uint256", "name": "min_eth_bought"}, {"type": "uint256", "name": "deadline"}, {"type": "address", "name": "recipient"}, {"type": "address", "name": "exchange_addr"}], "constant": false, "payable": false, "type": "function", "gas": 49532}, {"name": "tokenToExchangeSwapOutput", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [{"type": "uint256", "name": "tokens_bought"}, {"type": "uint256", "name": "max_tokens_sold"}, {"type": "uint256", "name": "max_eth_sold"}, {"type": "uint256", "name": "deadline"}, {"type": "address", "name": "exchange_addr"}], "constant": false, "payable": false, "type": "function", "gas": 53233}, {"name": "tokenToExchangeTransferOutput", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [{"type": "uint256", "name": "tokens_bought"}, {"type": "uint256", "name": "max_tokens_sold"}, {"type": "uint256", "name": "max_eth_sold"}, {"type": "uint256", "name": "deadline"}, {"type": "address", "name": "recipient"}, {"type": "address", "name": "exchange_addr"}], "constant": false, "payable": false, "type": "function", "gas": 53423}, {"name": "getEthToTokenInputPrice", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [{"type": "uint256", "name": "eth_sold"}], "constant": true, "payable": false, "type": "function", "gas": 5542}, {"name": "getEthToTokenOutputPrice", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [{"type": "uint256", "name": "tokens_bought"}], "constant": true, "payable": false, "type": "function", "gas": 6872}, {"name": "getTokenToEthInputPrice", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [{"type": "uint256", "name": "tokens_sold"}], "constant": true, "payable": false, "type": "function", "gas": 5637}, {"name": "getTokenToEthOutputPrice", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [{"type": "uint256", "name": "eth_bought"}], "constant": true, "payable": false, "type": "function", "gas": 6897}, {"name": "tokenAddress", "outputs": [{"type": "address", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 1413}, {"name": "factoryAddress", "outputs": [{"type": "address", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 1443}, {"name": "balanceOf", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [{"type": "address", "name": "_owner"}], "constant": true, "payable": false, "type": "function", "gas": 1645}, {"name": "transfer", "outputs": [{"type": "bool", "name": "out"}], "inputs": [{"type": "address", "name": "_to"}, {"type": "uint256", "name": "_value"}], "constant": false, "payable": false, "type": "function", "gas": 75034}, {"name": "transferFrom", "outputs": [{"type": "bool", "name": "out"}], "inputs": [{"type": "address", "name": "_from"}, {"type": "address", "name": "_to"}, {"type": "uint256", "name": "_value"}], "constant": false, "payable": false, "type": "function", "gas": 110907}, {"name": "approve", "outputs": [{"type": "bool", "name": "out"}], "inputs": [{"type": "address", "name": "_spender"}, {"type": "uint256", "name": "_value"}], "constant": false, "payable": false, "type": "function", "gas": 38769}, {"name": "allowance", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [{"type": "address", "name": "_owner"}, {"type": "address", "name": "_spender"}], "constant": true, "payable": false, "type": "function", "gas": 1925}, {"name": "name", "outputs": [{"type": "bytes32", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 1623}, {"name": "symbol", "outputs": [{"type": "bytes32", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 1653}, {"name": "decimals", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 1683}, {"name": "totalSupply", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 1713}]
2 |
--------------------------------------------------------------------------------
/abi/uniswap_factory.json:
--------------------------------------------------------------------------------
1 | [{"name": "NewExchange", "inputs": [{"type": "address", "name": "token", "indexed": true}, {"type": "address", "name": "exchange", "indexed": true}], "anonymous": false, "type": "event"}, {"name": "initializeFactory", "outputs": [], "inputs": [{"type": "address", "name": "template"}], "constant": false, "payable": false, "type": "function", "gas": 35725}, {"name": "createExchange", "outputs": [{"type": "address", "name": "out"}], "inputs": [{"type": "address", "name": "token"}], "constant": false, "payable": false, "type": "function", "gas": 187911}, {"name": "getExchange", "outputs": [{"type": "address", "name": "out"}], "inputs": [{"type": "address", "name": "token"}], "constant": true, "payable": false, "type": "function", "gas": 715}, {"name": "getToken", "outputs": [{"type": "address", "name": "out"}], "inputs": [{"type": "address", "name": "exchange"}], "constant": true, "payable": false, "type": "function", "gas": 745}, {"name": "getTokenWithId", "outputs": [{"type": "address", "name": "out"}], "inputs": [{"type": "uint256", "name": "token_id"}], "constant": true, "payable": false, "type": "function", "gas": 736}, {"name": "exchangeTemplate", "outputs": [{"type": "address", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 633}, {"name": "tokenCount", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 663}]
2 |
--------------------------------------------------------------------------------
/bytecode/exchange.txt:
--------------------------------------------------------------------------------
1 | 0x61309c56600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a0526366d38203600051141561013b57602060046101403734156100b457600080fd5b60043560205181106100c557600080fd5b506000610140511415600654156007541516166100e157600080fd5b33600755610140516006557f556e6973776170205631000000000000000000000000000000000000000000006000557f554e492d563100000000000000000000000000000000000000000000000000006001556012600255005b63422f104360005114156105ab5760606004610140376000341160006101605111164261018051111661016d57600080fd5b6003546101a05260006101a051111561043e576000610140511161019057600080fd5b343031101561019e57600080fd5b343031036103a0526006543b6101b357600080fd5b6006543014156101c257600080fd5b602061046060246370a082316103e05230610400526103fc6006545afa6101e857600080fd5b600050610460516103c0526103a05161020057600080fd5b6103a05134151561021257600061022f565b6103c051346103c0513402041461022857600080fd5b6103c05134025b0460016103a05161023f57600080fd5b6103a05134151561025157600061026e565b6103c051346103c0513402041461026757600080fd5b6103c05134025b0401101561027b57600080fd5b60016103a05161028a57600080fd5b6103a05134151561029c5760006102b9565b6103c051346103c051340204146102b257600080fd5b6103c05134025b0401610480526103a0516102cc57600080fd5b6103a0513415156102de5760006102fb565b6101a051346101a051340204146102f457600080fd5b6101a05134025b046104a052610140516104a0511015610480516101605110151661031e57600080fd5b60043360e05260c052604060c02080546104a051825401101561034057600080fd5b6104a0518154018155506101a0516104a0516101a05101101561036257600080fd5b6104a0516101a051016003556006543b61037b57600080fd5b60065430141561038a57600080fd5b602061058060646323b872dd6104c052336104e052306105005261048051610520526104dc60006006545af16103bf57600080fd5b600050610580516103cf57600080fd5b6104805134337f06239653922ac7bea6aa2b19dc486b9361821d37712eb796adfd38d81de278ca60006000a46104a0516105a0523360007fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60206105a0a36104a05160005260206000f36105a9565b633b9aca003410156000600654141560006007541415161661045f57600080fd5b306007543b61046d57600080fd5b60075430141561047c57600080fd5b602061024060246306f2bf626101c0526006546101e0526101dc6007545afa6104a457600080fd5b60005061024051146104b557600080fd5b6101605161026052303161028052610280516003556102805160043360e05260c052604060c020556006543b6104ea57600080fd5b6006543014156104f957600080fd5b602061036060646323b872dd6102a052336102c052306102e05261026051610300526102bc60006006545af161052e57600080fd5b6000506103605161053e57600080fd5b6102605134337f06239653922ac7bea6aa2b19dc486b9361821d37712eb796adfd38d81de278ca60006000a461028051610380523360007fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef6020610380a36102805160005260206000f35b005b63f88bf15a600051141561084a57608060046101403734156105cc57600080fd5b600061018051116000610160511116426101a051116000610140511116166105f357600080fd5b6003546101c05260006101c0511161060a57600080fd5b6006543b61061757600080fd5b60065430141561062657600080fd5b602061028060246370a0823161020052306102205261021c6006545afa61064c57600080fd5b600050610280516101e0526101c05161066457600080fd5b6101c051610140511515610679576000610699565b30316101405130316101405102041461069157600080fd5b303161014051025b046102a0526101c0516106ab57600080fd5b6101c0516101405115156106c05760006106e6565b6101e051610140516101e051610140510204146106dc57600080fd5b6101e05161014051025b046102c052610180516102c0511015610160516102a05110151661070957600080fd5b60043360e05260c052604060c020610140518154101561072857600080fd5b61014051815403815550610140516101c051101561074557600080fd5b610140516101c0510360035560006000600060006102a051336000f161076a57600080fd5b6006543b61077757600080fd5b60065430141561078657600080fd5b6020610380604463a9059cbb6102e05233610300526102c051610320526102fc60006006545af16107b657600080fd5b600050610380516107c657600080fd5b6102c0516102a051337f0fbf06c058b90cb038a618f8c2acbf6145f8b3570fd1fa56abb8f0f3f05b36e860006000a4610140516103a0526000337fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60206103a0a360406103c0526103e06102a05181526102c0518160200152506103c0516103e0f3005b6000156109c6575b6101a05261014052610160526101805260006101805111600061016051111661087a57600080fd5b61014051151561088b5760006108ae565b6103e5610140516103e5610140510204146108a557600080fd5b6103e561014051025b6101c0526101c05115156108c35760006108e9565b610180516101c051610180516101c0510204146108df57600080fd5b610180516101c051025b6101e0526101605115156108fe576000610921565b6103e8610160516103e86101605102041461091857600080fd5b6103e861016051025b6101c051610160511515610936576000610959565b6103e8610160516103e86101605102041461095057600080fd5b6103e861016051025b01101561096557600080fd5b6101c05161016051151561097a57600061099d565b6103e8610160516103e86101605102041461099457600080fd5b6103e861016051025b0161020052610200516109af57600080fd5b610200516101e051046000526000516101a0515650005b600015610bf3575b6101a0526101405261016052610180526000610180511160006101605111166109f657600080fd5b610160511515610a07576000610a2d565b61014051610160516101405161016051020414610a2357600080fd5b6101405161016051025b1515610a3a576000610af6565b6103e8610160511515610a4e576000610a74565b61014051610160516101405161016051020414610a6a57600080fd5b6101405161016051025b6103e8610160511515610a88576000610aae565b61014051610160516101405161016051020414610aa457600080fd5b6101405161016051025b020414610aba57600080fd5b6103e8610160511515610ace576000610af4565b61014051610160516101405161016051020414610aea57600080fd5b6101405161016051025b025b6101c05261014051610180511015610b0d57600080fd5b6101405161018051031515610b23576000610b8e565b6103e561014051610180511015610b3957600080fd5b6101405161018051036103e561014051610180511015610b5857600080fd5b610140516101805103020414610b6d57600080fd5b6103e561014051610180511015610b8357600080fd5b610140516101805103025b6101e0526101e051610b9f57600080fd5b6101e0516101c0510460016101e051610bb757600080fd5b6101e0516101c05104011015610bcc57600080fd5b60016101e051610bdb57600080fd5b6101e0516101c05104016000526000516101a0515650005b600015610df4575b6101e0526101405261016052610180526101a0526101c0526000610160511160006101405111164261018051101516610c3357600080fd5b6006543b610c4057600080fd5b600654301415610c4f57600080fd5b60206102a060246370a0823161022052306102405261023c6006545afa610c7557600080fd5b6000506102a051610200526101405161016051610180516101a0516101c0516101e05161020051610220516102405161026051610280516102a0516102c0516389f2a8716102e05261014051610300526101405130311015610cd657600080fd5b6101405130310361032052610200516103405261034051610320516103005160065801610852565b6103a0526102c0526102a05261028052610260526102405261022052610200526101e0526101c0526101a0526101805261016052610140526103a0516102c052610160516102c0511015610d5157600080fd5b6006543b610d5e57600080fd5b600654301415610d6d57600080fd5b6020610460604463a9059cbb6103c0526101c0516103e0526102c051610400526103dc60006006545af1610da057600080fd5b60005061046051610db057600080fd5b6102c051610140516101a0517fcd60aa75dea3072fbc07ae6d7d856b5dc5f4eee88854f5b4abf7b680ef8bc50f60006000a46102c0516000526000516101e0515650005b63f39b5b9b6000511415610e715760406004610140376101405161016051638c717a3361018052346101a052610140516101c052610160516101e0523361020052336102205261022051610200516101e0516101c0516101a05160065801610bfb565b6102805261016052610140526102805160005260206000f3005b63ad65d76d6000511415610f245760606004610140376044356020518110610e9857600080fd5b5060006101805114153061018051141516610eb257600080fd5b610140516101605161018051638c717a336101a052346101c052610140516101e0526101605161020052336102205261018051610240526102405161022051610200516101e0516101c05160065801610bfb565b6102a0526101805261016052610140526102a05160005260206000f3005b60001561116c575b6101e0526101405261016052610180526101a0526101c0526000610160511160006101405111164261018051101516610f6457600080fd5b6006543b610f7157600080fd5b600654301415610f8057600080fd5b60206102a060246370a0823161022052306102405261023c6006545afa610fa657600080fd5b6000506102a051610200526101405161016051610180516101a0516101c0516101e05161020051610220516102405161026051610280516102a0516102c05163fd11c2236102e0526101405161030052610160513031101561100757600080fd5b61016051303103610320526102005161034052610340516103205161030051600658016109ce565b6103a0526102c0526102a05261028052610260526102405261022052610200526101e0526101c0526101a0526101805261016052610140526103a0516102c05260016102c051026103e0526103e05161016051101561108d57600080fd5b6103e05161016051036103c05260006103c05111156110c35760006000600060006103c0516101a0516000f16110c257600080fd5b5b6006543b6110d057600080fd5b6006543014156110df57600080fd5b60206104a0604463a9059cbb610400526101c05161042052610140516104405261041c60006006545af161111257600080fd5b6000506104a05161112257600080fd5b6101405160016102c051026101a0517fcd60aa75dea3072fbc07ae6d7d856b5dc5f4eee88854f5b4abf7b680ef8bc50f60006000a460016102c051026000526000516101e0515650005b636b1d4db760005114156111e95760406004610140376101405161016051632dff394e61018052610140516101a052346101c052610160516101e0523361020052336102205261022051610200516101e0516101c0516101a05160065801610f2c565b6102805261016052610140526102805160005260206000f3005b630b573638600051141561129c576060600461014037604435602051811061121057600080fd5b506000610180511415306101805114151661122a57600080fd5b610140516101605161018051632dff394e6101a052610140516101c052346101e0526101605161020052336102205261018051610240526102405161022051610200516101e0516101c05160065801610f2c565b6102a0526101805261016052610140526102a05160005260206000f3005b6000156114b3575b6101e0526101405261016052610180526101a0526101c05260006101605111600061014051111642610180511015166112dc57600080fd5b6006543b6112e957600080fd5b6006543014156112f857600080fd5b60206102a060246370a0823161022052306102405261023c6006545afa61131e57600080fd5b6000506102a051610200526101405161016051610180516101a0516101c0516101e05161020051610220516102405161026051610280516102a0516102c0516389f2a8716102e0526101405161030052610200516103205230316103405261034051610320516103005160065801610852565b6103a0526102c0526102a05261028052610260526102405261022052610200526101e0526101c0526101a0526101805261016052610140526103a0516102c05260016102c051026103c052610160516103c05110156113ef57600080fd5b60006000600060006103c0516101c0516000f161140b57600080fd5b6006543b61141857600080fd5b60065430141561142757600080fd5b60206104a060646323b872dd6103e0526101a05161040052306104205261014051610440526103fc60006006545af161145f57600080fd5b6000506104a05161146f57600080fd5b6103c051610140516101a0517f7f4091b46c33e918a0f3aa42307641d17bb67029427a5369e54b35398423870560006000a46103c0516000526000516101e0515650005b6395e3c50b600051141561154657606060046101403734156114d457600080fd5b61014051610160516101805163fa1bb7be6101a052610140516101c052610160516101e0526101805161020052336102205233610240526102405161022051610200516101e0516101c051600658016112a4565b6102a0526101805261016052610140526102a05160005260206000f3005b637237e031600051141561160f576080600461014037341561156757600080fd5b606435602051811061157857600080fd5b5060006101a0511415306101a05114151661159257600080fd5b6101405161016051610180516101a05163fa1bb7be6101c052610140516101e0526101605161020052610180516102205233610240526101a05161026052610260516102405161022051610200516101e051600658016112a4565b6102c0526101a0526101805261016052610140526102c05160005260206000f3005b600015611813575b6101e0526101405261016052610180526101a0526101c05260006101405111426101805110151661164757600080fd5b6006543b61165457600080fd5b60065430141561166357600080fd5b60206102a060246370a0823161022052306102405261023c6006545afa61168957600080fd5b6000506102a051610200526101405161016051610180516101a0516101c0516101e05161020051610220516102405161026051610280516102a0516102c05163fd11c2236102e05261014051610300526102005161032052303161034052610340516103205161030051600658016109ce565b6103a0526102c0526102a05261028052610260526102405261022052610200526101e0526101c0526101a0526101805261016052610140526103a0516102c0526102c05161016051101561174f57600080fd5b6000600060006000610140516101c0516000f161176b57600080fd5b6006543b61177857600080fd5b60065430141561178757600080fd5b602061048060646323b872dd6103c0526101a0516103e05230610400526102c051610420526103dc60006006545af16117bf57600080fd5b600050610480516117cf57600080fd5b610140516102c0516101a0517f7f4091b46c33e918a0f3aa42307641d17bb67029427a5369e54b35398423870560006000a46102c0516000526000516101e0515650005b63013efd8b60005114156118a6576060600461014037341561183457600080fd5b61014051610160516101805163984fe8f66101a052610140516101c052610160516101e0526101805161020052336102205233610240526102405161022051610200516101e0516101c05160065801611617565b6102a0526101805261016052610140526102a05160005260206000f3005b63d4e4841d600051141561196f57608060046101403734156118c757600080fd5b60643560205181106118d857600080fd5b5060006101a0511415306101a0511415166118f257600080fd5b6101405161016051610180516101a05163984fe8f66101c052610140516101e0526101605161020052610180516102205233610240526101a05161026052610260516102405161022051610200516101e05160065801611617565b6102c0526101a0526101805261016052610140526102c05160005260206000f3005b600015611c0a575b610220526101405261016052610180526101a0526101c0526101e0526102005260006101805111600061016051111660006101405111426101a051101516166119bf57600080fd5b600061020051141530610200511415166119d857600080fd5b6006543b6119e557600080fd5b6006543014156119f457600080fd5b60206102e060246370a0823161026052306102805261027c6006545afa611a1a57600080fd5b6000506102e051610240526101405161016051610180516101a0516101c0516101e05161020051610220516102405161026051610280516102a0516102c0516102e051610300516389f2a871610320526101405161034052610240516103605230316103805261038051610360516103405160065801610852565b6103e052610300526102e0526102c0526102a05261028052610260526102405261022052610200526101e0526101c0526101a0526101805261016052610140526103e05161030052600161030051026104005261018051610400511015611afb57600080fd5b6006543b611b0857600080fd5b600654301415611b1757600080fd5b60206104e060646323b872dd610420526101c051610440523061046052610140516104805261043c60006006545af1611b4f57600080fd5b6000506104e051611b5f57600080fd5b610200513b611b6d57600080fd5b61020051301415611b7d57600080fd5b60206105e0606463ad65d76d6105205261016051610540526101a051610560526101e0516105805261053c61040051610200515af1611bbb57600080fd5b6000506105e0516105005261040051610140516101c0517f7f4091b46c33e918a0f3aa42307641d17bb67029427a5369e54b35398423870560006000a461050051600052600051610220515650005b63ddf7e1a76000511415611d575760a06004610140373415611c2b57600080fd5b6084356020518110611c3c57600080fd5b506007543b611c4a57600080fd5b600754301415611c5957600080fd5b602061028060246306f2bf62610200526101c0516102205261021c6007545afa611c8257600080fd5b600050610280516101e0526101405161016051610180516101a0516101c0516101e051610200516102205161024051610260516102805163204ea33b6102a052610140516102c052610160516102e05261018051610300526101a05161032052336103405233610360526101e0516103805261038051610360516103405161032051610300516102e0516102c05160065801611977565b6103e05261028052610260526102405261022052610200526101e0526101c0526101a0526101805261016052610140526103e05160005260206000f3005b63f552d91b6000511415611ec15760c06004610140373415611d7857600080fd5b6084356020518110611d8957600080fd5b5060a4356020518110611d9b57600080fd5b506007543b611da957600080fd5b600754301415611db857600080fd5b60206102a060246306f2bf62610220526101e0516102405261023c6007545afa611de157600080fd5b6000506102a051610200526101405161016051610180516101a0516101c0516101e05161020051610220516102405161026051610280516102a05163204ea33b6102c052610140516102e052610160516103005261018051610320526101a0516103405233610360526101c05161038052610200516103a0526103a05161038051610360516103405161032051610300516102e05160065801611977565b610400526102a05261028052610260526102405261022052610200526101e0526101c0526101a0526101805261016052610140526104005160005260206000f3005b6000156121d7575b610220526101405261016052610180526101a0526101c0526101e05261020052600061018051116000610140511116426101a051101516611f0957600080fd5b60006102005114153061020051141516611f2257600080fd5b610200513b611f3057600080fd5b61020051301415611f4057600080fd5b60206102e060246359e9486261026052610140516102805261027c610200515afa611f6a57600080fd5b6000506102e051610240526006543b611f8257600080fd5b600654301415611f9157600080fd5b60206103a060246370a0823161032052306103405261033c6006545afa611fb757600080fd5b6000506103a051610300526101405161016051610180516101a0516101c0516101e05161020051610220516102405161026051610280516102a0516102c0516102e05161030051610320516103405161036051610380516103a0516103c05163fd11c2236103e05261024051610400526103005161042052303161044052610440516104205161040051600658016109ce565b6104a0526103c0526103a05261038052610360526103405261032052610300526102e0526102c0526102a05261028052610260526102405261022052610200526101e0526101c0526101a0526101805261016052610140526104a0516103c052610240516101805110156103c051610160511015166120c857600080fd5b6006543b6120d557600080fd5b6006543014156120e457600080fd5b602061058060646323b872dd6104c0526101c0516104e05230610500526103c051610520526104dc60006006545af161211c57600080fd5b6000506105805161212c57600080fd5b610200513b61213a57600080fd5b6102005130141561214a57600080fd5b60206106806064630b5736386105c052610140516105e0526101a051610600526101e051610620526105dc61024051610200515af161218857600080fd5b600050610680516105a052610240516103c0516101c0517f7f4091b46c33e918a0f3aa42307641d17bb67029427a5369e54b35398423870560006000a46103c051600052600051610220515650005b63b040d54560005114156123245760a060046101403734156121f857600080fd5b608435602051811061220957600080fd5b506007543b61221757600080fd5b60075430141561222657600080fd5b602061028060246306f2bf62610200526101c0516102205261021c6007545afa61224f57600080fd5b600050610280516101e0526101405161016051610180516101a0516101c0516101e0516102005161022051610240516102605161028051631a7b28f26102a052610140516102c052610160516102e05261018051610300526101a05161032052336103405233610360526101e0516103805261038051610360516103405161032051610300516102e0516102c05160065801611ec9565b6103e05261028052610260526102405261022052610200526101e0526101c0526101a0526101805261016052610140526103e05160005260206000f3005b63f3c0efe9600051141561248e5760c0600461014037341561234557600080fd5b608435602051811061235657600080fd5b5060a435602051811061236857600080fd5b506007543b61237657600080fd5b60075430141561238557600080fd5b60206102a060246306f2bf62610220526101e0516102405261023c6007545afa6123ae57600080fd5b6000506102a051610200526101405161016051610180516101a0516101c0516101e05161020051610220516102405161026051610280516102a051631a7b28f26102c052610140516102e052610160516103005261018051610320526101a0516103405233610360526101c05161038052610200516103a0526103a05161038051610360516103405161032051610300516102e05160065801611ec9565b610400526102a05261028052610260526102405261022052610200526101e0526101c0526101a0526101805261016052610140526104005160005260206000f3005b63b1cb43bf600051141561255b5760a060046101403734156124af57600080fd5b60843560205181106124c057600080fd5b506101405161016051610180516101a0516101c05163204ea33b6101e0526101405161020052610160516102205261018051610240526101a051610260523361028052336102a0526101c0516102c0526102c0516102a051610280516102605161024051610220516102005160065801611977565b610320526101c0526101a0526101805261016052610140526103205160005260206000f3005b63ec384a3e60005114156126555760c0600461014037341561257c57600080fd5b608435602051811061258d57600080fd5b5060a435602051811061259f57600080fd5b50306101c05114156125b057600080fd5b6101405161016051610180516101a0516101c0516101e05163204ea33b610200526101405161022052610160516102405261018051610260526101a05161028052336102a0526101c0516102c0526101e0516102e0526102e0516102c0516102a0516102805161026051610240516102205160065801611977565b610340526101e0526101c0526101a0526101805261016052610140526103405160005260206000f3005b63ea650c7d60005114156127225760a0600461014037341561267657600080fd5b608435602051811061268757600080fd5b506101405161016051610180516101a0516101c051631a7b28f26101e0526101405161020052610160516102205261018051610240526101a051610260523361028052336102a0526101c0516102c0526102c0516102a051610280516102605161024051610220516102005160065801611ec9565b610320526101c0526101a0526101805261016052610140526103205160005260206000f3005b63981a1327600051141561281c5760c0600461014037341561274357600080fd5b608435602051811061275457600080fd5b5060a435602051811061276657600080fd5b50306101c051141561277757600080fd5b6101405161016051610180516101a0516101c0516101e051631a7b28f2610200526101405161022052610160516102405261018051610260526101a05161028052336102a0526101c0516102c0526101e0516102e0526102e0516102c0516102a0516102805161026051610240516102205160065801611ec9565b610340526101e0526101c0526101a0526101805261016052610140526103405160005260206000f3005b63cd7724c36000511415612918576020600461014037341561283d57600080fd5b6000610140511161284d57600080fd5b6006543b61285a57600080fd5b60065430141561286957600080fd5b602061020060246370a0823161018052306101a05261019c6006545afa61288f57600080fd5b60005061020051610160526101405161016051610180516101a0516101c0516101e051610200516389f2a871610220526101405161024052303161026052610160516102805261028051610260516102405160065801610852565b6102e052610200526101e0526101c0526101a0526101805261016052610140526102e05160005260206000f3005b6359e948626000511415612a27576020600461014037341561293957600080fd5b6000610140511161294957600080fd5b6006543b61295657600080fd5b60065430141561296557600080fd5b602061020060246370a0823161018052306101a05261019c6006545afa61298b57600080fd5b60005061020051610160526101405161016051610180516101a0516101c0516101e051610200516102205163fd11c223610240526101405161026052303161028052610160516102a0526102a0516102805161026051600658016109ce565b6103005261022052610200526101e0526101c0526101a05261018052610160526101405261030051610220526001610220510260005260206000f3005b6395b68fe76000511415612b365760206004610140373415612a4857600080fd5b60006101405111612a5857600080fd5b6006543b612a6557600080fd5b600654301415612a7457600080fd5b602061020060246370a0823161018052306101a05261019c6006545afa612a9a57600080fd5b60005061020051610160526101405161016051610180516101a0516101c0516101e05161020051610220516389f2a871610240526101405161026052610160516102805230316102a0526102a051610280516102605160065801610852565b6103005261022052610200526101e0526101c0526101a05261018052610160526101405261030051610220526001610220510260005260206000f3005b632640f62c6000511415612c325760206004610140373415612b5757600080fd5b60006101405111612b6757600080fd5b6006543b612b7457600080fd5b600654301415612b8357600080fd5b602061020060246370a0823161018052306101a05261019c6006545afa612ba957600080fd5b60005061020051610160526101405161016051610180516101a0516101c0516101e0516102005163fd11c2236102205261014051610240526101605161026052303161028052610280516102605161024051600658016109ce565b6102e052610200526101e0526101c0526101a0526101805261016052610140526102e05160005260206000f3005b639d76ea586000511415612c58573415612c4b57600080fd5b60065460005260206000f3005b63966dae0e6000511415612c7e573415612c7157600080fd5b60075460005260206000f3005b6370a082316000511415612ccd5760206004610140373415612c9f57600080fd5b6004356020518110612cb057600080fd5b5060046101405160e05260c052604060c0205460005260206000f3005b63a9059cbb6000511415612d985760406004610140373415612cee57600080fd5b6004356020518110612cff57600080fd5b5060043360e05260c052604060c0206101605181541015612d1f57600080fd5b6101605181540381555060046101405160e05260c052604060c0208054610160518254011015612d4e57600080fd5b61016051815401815550610160516101805261014051337fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef6020610180a3600160005260206000f3005b6323b872dd6000511415612eb35760606004610140373415612db957600080fd5b6004356020518110612dca57600080fd5b506024356020518110612ddc57600080fd5b5060046101405160e05260c052604060c0206101805181541015612dff57600080fd5b6101805181540381555060046101605160e05260c052604060c0208054610180518254011015612e2e57600080fd5b6101805181540181555060056101405160e05260c052604060c0203360e05260c052604060c0206101805181541015612e6657600080fd5b61018051815403815550610180516101a05261016051610140517fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60206101a0a3600160005260206000f3005b63095ea7b36000511415612f485760406004610140373415612ed457600080fd5b6004356020518110612ee557600080fd5b506101605160053360e05260c052604060c0206101405160e05260c052604060c02055610160516101805261014051337f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9256020610180a3600160005260206000f3005b63dd62ed3e6000511415612fb85760406004610140373415612f6957600080fd5b6004356020518110612f7a57600080fd5b506024356020518110612f8c57600080fd5b5060056101405160e05260c052604060c0206101605160e05260c052604060c0205460005260206000f3005b6306fdde036000511415612fde573415612fd157600080fd5b60005460005260206000f3005b6395d89b416000511415613004573415612ff757600080fd5b60015460005260206000f3005b63313ce567600051141561302a57341561301d57600080fd5b60025460005260206000f3005b6318160ddd600051141561305057341561304357600080fd5b60035460005260206000f3005b638c717a33610140523461016052600161018052426101a052336101c052336101e0526101e0516101c0516101a051610180516101605160065801610bfb565b610240526102405b61000461309c0361000460003961000461309c036000f3
2 |
--------------------------------------------------------------------------------
/bytecode/factory.txt:
--------------------------------------------------------------------------------
1 | 0x6103f056600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a05263538a3f0e60005114156100ed57602060046101403734156100b457600080fd5b60043560205181106100c557600080fd5b50600054156100d357600080fd5b60006101405114156100e457600080fd5b61014051600055005b631648f38e60005114156102bf576020600461014037341561010e57600080fd5b600435602051811061011f57600080fd5b50600061014051141561013157600080fd5b6000600054141561014157600080fd5b60026101405160e05260c052604060c020541561015d57600080fd5b7f602e600c600039602e6000f33660006000376110006000366000730000000000610180526c010000000000000000000000006000540261019b527f5af41558576110006000f30000000000000000000000000000000000000000006101af5260406101806000f0806101cf57600080fd5b61016052610160513b6101e157600080fd5b610160513014156101f157600080fd5b6000600060246366d3820361022052610140516102405261023c6000610160515af161021c57600080fd5b6101605160026101405160e05260c052604060c020556101405160036101605160e05260c052604060c02055600154600160015401101561025c57600080fd5b6001600154016102a0526102a0516001556101405160046102a05160e05260c052604060c0205561016051610140517f9d42cb017eb05bd8944ab536a8b35bc68085931dd5f4356489801453923953f960006000a36101605160005260206000f3005b6306f2bf62600051141561030e57602060046101403734156102e057600080fd5b60043560205181106102f157600080fd5b5060026101405160e05260c052604060c0205460005260206000f3005b6359770438600051141561035d576020600461014037341561032f57600080fd5b600435602051811061034057600080fd5b5060036101405160e05260c052604060c0205460005260206000f3005b63aa65a6c0600051141561039a576020600461014037341561037e57600080fd5b60046101405160e05260c052604060c0205460005260206000f3005b631c2bbd1860005114156103c05734156103b357600080fd5b60005460005260206000f3005b639f181b5e60005114156103e65734156103d957600080fd5b60015460005260206000f3005b60006000fd5b6100046103f0036100046000396100046103f0036000f3
2 |
--------------------------------------------------------------------------------
/contracts/test_contracts/ERC20.vy:
--------------------------------------------------------------------------------
1 | # THIS CONTRACT IS FOR TESTING PURPOSES AND IS NOT PART OF THE PROJECT
2 |
3 | # Modified from: https://github.com/ethereum/vyper/blob/master/examples/tokens/ERC20_solidity_compatible/ERC20.v.py
4 |
5 | Transfer: event({_from: indexed(address), _to: indexed(address), _value: uint256(wei)})
6 | Approval: event({_owner: indexed(address), _spender: indexed(address), _value: uint256(wei)})
7 |
8 | name: public(bytes32)
9 | symbol: public(bytes32)
10 | decimals: public(uint256)
11 | balances: uint256(wei)[address]
12 | allowances: (uint256(wei)[address])[address]
13 | total_supply: uint256(wei)
14 |
15 | @public
16 | def __init__(_name: bytes32, _symbol: bytes32, _decimals: uint256, _supply: uint256(wei)):
17 | _sender: address = msg.sender
18 | self.name = _name
19 | self.symbol = _symbol
20 | self.decimals = _decimals
21 | self.balances[_sender] = _supply
22 | self.total_supply = _supply
23 | log.Transfer(ZERO_ADDRESS, _sender, _supply)
24 |
25 | @public
26 | @payable
27 | def deposit():
28 | _value: uint256(wei) = msg.value
29 | _sender: address = msg.sender
30 | self.balances[_sender] = self.balances[_sender] + _value
31 | self.total_supply = self.total_supply + _value
32 | log.Transfer(ZERO_ADDRESS, _sender, _value)
33 |
34 | @public
35 | def withdraw(_value : uint256(wei)) -> bool:
36 | _sender: address = msg.sender
37 | self.balances[_sender] = self.balances[_sender] - _value
38 | self.total_supply = self.total_supply - _value
39 | send(_sender, _value)
40 | log.Transfer(_sender, ZERO_ADDRESS, _value)
41 | return True
42 |
43 | @public
44 | @constant
45 | def totalSupply() -> uint256(wei):
46 | return self.total_supply
47 |
48 | @public
49 | @constant
50 | def balanceOf(_owner : address) -> uint256(wei):
51 | return self.balances[_owner]
52 |
53 | @public
54 | def transfer(_to : address, _value : uint256(wei)) -> bool:
55 | _sender: address = msg.sender
56 | self.balances[_sender] = self.balances[_sender] - _value
57 | self.balances[_to] = self.balances[_to] + _value
58 | log.Transfer(_sender, _to, _value)
59 | return True
60 |
61 | @public
62 | def transferFrom(_from : address, _to : address, _value : uint256(wei)) -> bool:
63 | _sender: address = msg.sender
64 | allowance: uint256(wei) = self.allowances[_from][_sender]
65 | self.balances[_from] = self.balances[_from] - _value
66 | self.balances[_to] = self.balances[_to] + _value
67 | self.allowances[_from][_sender] = allowance - _value
68 | log.Transfer(_from, _to, _value)
69 | return True
70 |
71 | @public
72 | def approve(_spender : address, _value : uint256(wei)) -> bool:
73 | _sender: address = msg.sender
74 | self.allowances[_sender][_spender] = _value
75 | log.Approval(_sender, _spender, _value)
76 | return True
77 |
78 | @public
79 | @constant
80 | def allowance(_owner : address, _spender : address) -> uint256(wei):
81 | return self.allowances[_owner][_spender]
82 |
--------------------------------------------------------------------------------
/contracts/uniswap_exchange.vy:
--------------------------------------------------------------------------------
1 | # @title Uniswap Exchange Interface V1
2 | # @notice Source code found at https://github.com/uniswap
3 | # @notice Use at your own risk
4 |
5 | contract Factory():
6 | def getExchange(token_addr: address) -> address: constant
7 |
8 | contract Exchange():
9 | def getEthToTokenOutputPrice(tokens_bought: uint256) -> uint256(wei): constant
10 | def ethToTokenTransferInput(min_tokens: uint256, deadline: timestamp, recipient: address) -> uint256: modifying
11 | def ethToTokenTransferOutput(tokens_bought: uint256, deadline: timestamp, recipient: address) -> uint256(wei): modifying
12 |
13 | TokenPurchase: event({buyer: indexed(address), eth_sold: indexed(uint256(wei)), tokens_bought: indexed(uint256)})
14 | EthPurchase: event({buyer: indexed(address), tokens_sold: indexed(uint256), eth_bought: indexed(uint256(wei))})
15 | AddLiquidity: event({provider: indexed(address), eth_amount: indexed(uint256(wei)), token_amount: indexed(uint256)})
16 | RemoveLiquidity: event({provider: indexed(address), eth_amount: indexed(uint256(wei)), token_amount: indexed(uint256)})
17 | Transfer: event({_from: indexed(address), _to: indexed(address), _value: uint256})
18 | Approval: event({_owner: indexed(address), _spender: indexed(address), _value: uint256})
19 |
20 | name: public(bytes32) # Uniswap V1
21 | symbol: public(bytes32) # UNI-V1
22 | decimals: public(uint256) # 18
23 | totalSupply: public(uint256) # total number of UNI in existence
24 | balances: uint256[address] # UNI balance of an address
25 | allowances: (uint256[address])[address] # UNI allowance of one address on another
26 | token: address(ERC20) # address of the ERC20 token traded on this contract
27 | factory: Factory # interface for the factory that created this contract
28 |
29 | # @dev This function acts as a contract constructor which is not currently supported in contracts deployed
30 | # using create_with_code_of(). It is called once by the factory during contract creation.
31 | @public
32 | def setup(token_addr: address):
33 | assert (self.factory == ZERO_ADDRESS and self.token == ZERO_ADDRESS) and token_addr != ZERO_ADDRESS
34 | self.factory = msg.sender
35 | self.token = token_addr
36 | self.name = 0x556e697377617020563100000000000000000000000000000000000000000000
37 | self.symbol = 0x554e492d56310000000000000000000000000000000000000000000000000000
38 | self.decimals = 18
39 |
40 | # @notice Deposit ETH and Tokens (self.token) at current ratio to mint UNI tokens.
41 | # @dev min_liquidity does nothing when total UNI supply is 0.
42 | # @param min_liquidity Minimum number of UNI sender will mint if total UNI supply is greater than 0.
43 | # @param max_tokens Maximum number of tokens deposited. Deposits max amount if total UNI supply is 0.
44 | # @param deadline Time after which this transaction can no longer be executed.
45 | # @return The amount of UNI minted.
46 | @public
47 | @payable
48 | def addLiquidity(min_liquidity: uint256, max_tokens: uint256, deadline: timestamp) -> uint256:
49 | assert deadline > block.timestamp and (max_tokens > 0 and msg.value > 0)
50 | total_liquidity: uint256 = self.totalSupply
51 | if total_liquidity > 0:
52 | assert min_liquidity > 0
53 | eth_reserve: uint256(wei) = self.balance - msg.value
54 | token_reserve: uint256 = self.token.balanceOf(self)
55 | token_amount: uint256 = msg.value * token_reserve / eth_reserve + 1
56 | liquidity_minted: uint256 = msg.value * total_liquidity / eth_reserve
57 | assert max_tokens >= token_amount and liquidity_minted >= min_liquidity
58 | self.balances[msg.sender] += liquidity_minted
59 | self.totalSupply = total_liquidity + liquidity_minted
60 | assert self.token.transferFrom(msg.sender, self, token_amount)
61 | log.AddLiquidity(msg.sender, msg.value, token_amount)
62 | log.Transfer(ZERO_ADDRESS, msg.sender, liquidity_minted)
63 | return liquidity_minted
64 | else:
65 | assert (self.factory != ZERO_ADDRESS and self.token != ZERO_ADDRESS) and msg.value >= 1000000000
66 | assert self.factory.getExchange(self.token) == self
67 | token_amount: uint256 = max_tokens
68 | initial_liquidity: uint256 = as_unitless_number(self.balance)
69 | self.totalSupply = initial_liquidity
70 | self.balances[msg.sender] = initial_liquidity
71 | assert self.token.transferFrom(msg.sender, self, token_amount)
72 | log.AddLiquidity(msg.sender, msg.value, token_amount)
73 | log.Transfer(ZERO_ADDRESS, msg.sender, initial_liquidity)
74 | return initial_liquidity
75 |
76 | # @dev Burn UNI tokens to withdraw ETH and Tokens at current ratio.
77 | # @param amount Amount of UNI burned.
78 | # @param min_eth Minimum ETH withdrawn.
79 | # @param min_tokens Minimum Tokens withdrawn.
80 | # @param deadline Time after which this transaction can no longer be executed.
81 | # @return The amount of ETH and Tokens withdrawn.
82 | @public
83 | def removeLiquidity(amount: uint256, min_eth: uint256(wei), min_tokens: uint256, deadline: timestamp) -> (uint256(wei), uint256):
84 | assert (amount > 0 and deadline > block.timestamp) and (min_eth > 0 and min_tokens > 0)
85 | total_liquidity: uint256 = self.totalSupply
86 | assert total_liquidity > 0
87 | token_reserve: uint256 = self.token.balanceOf(self)
88 | eth_amount: uint256(wei) = amount * self.balance / total_liquidity
89 | token_amount: uint256 = amount * token_reserve / total_liquidity
90 | assert eth_amount >= min_eth and token_amount >= min_tokens
91 | self.balances[msg.sender] -= amount
92 | self.totalSupply = total_liquidity - amount
93 | send(msg.sender, eth_amount)
94 | assert self.token.transfer(msg.sender, token_amount)
95 | log.RemoveLiquidity(msg.sender, eth_amount, token_amount)
96 | log.Transfer(msg.sender, ZERO_ADDRESS, amount)
97 | return eth_amount, token_amount
98 |
99 | # @dev Pricing function for converting between ETH and Tokens.
100 | # @param input_amount Amount of ETH or Tokens being sold.
101 | # @param input_reserve Amount of ETH or Tokens (input type) in exchange reserves.
102 | # @param output_reserve Amount of ETH or Tokens (output type) in exchange reserves.
103 | # @return Amount of ETH or Tokens bought.
104 | @private
105 | @constant
106 | def getInputPrice(input_amount: uint256, input_reserve: uint256, output_reserve: uint256) -> uint256:
107 | assert input_reserve > 0 and output_reserve > 0
108 | input_amount_with_fee: uint256 = input_amount * 997
109 | numerator: uint256 = input_amount_with_fee * output_reserve
110 | denominator: uint256 = (input_reserve * 1000) + input_amount_with_fee
111 | return numerator / denominator
112 |
113 | # @dev Pricing function for converting between ETH and Tokens.
114 | # @param output_amount Amount of ETH or Tokens being bought.
115 | # @param input_reserve Amount of ETH or Tokens (input type) in exchange reserves.
116 | # @param output_reserve Amount of ETH or Tokens (output type) in exchange reserves.
117 | # @return Amount of ETH or Tokens sold.
118 | @private
119 | @constant
120 | def getOutputPrice(output_amount: uint256, input_reserve: uint256, output_reserve: uint256) -> uint256:
121 | assert input_reserve > 0 and output_reserve > 0
122 | numerator: uint256 = input_reserve * output_amount * 1000
123 | denominator: uint256 = (output_reserve - output_amount) * 997
124 | return numerator / denominator + 1
125 |
126 | @private
127 | def ethToTokenInput(eth_sold: uint256(wei), min_tokens: uint256, deadline: timestamp, buyer: address, recipient: address) -> uint256:
128 | assert deadline >= block.timestamp and (eth_sold > 0 and min_tokens > 0)
129 | token_reserve: uint256 = self.token.balanceOf(self)
130 | tokens_bought: uint256 = self.getInputPrice(as_unitless_number(eth_sold), as_unitless_number(self.balance - eth_sold), token_reserve)
131 | assert tokens_bought >= min_tokens
132 | assert self.token.transfer(recipient, tokens_bought)
133 | log.TokenPurchase(buyer, eth_sold, tokens_bought)
134 | return tokens_bought
135 |
136 | # @notice Convert ETH to Tokens.
137 | # @dev User specifies exact input (msg.value).
138 | # @dev User cannot specify minimum output or deadline.
139 | @public
140 | @payable
141 | def __default__():
142 | self.ethToTokenInput(msg.value, 1, block.timestamp, msg.sender, msg.sender)
143 |
144 | # @notice Convert ETH to Tokens.
145 | # @dev User specifies exact input (msg.value) and minimum output.
146 | # @param min_tokens Minimum Tokens bought.
147 | # @param deadline Time after which this transaction can no longer be executed.
148 | # @return Amount of Tokens bought.
149 | @public
150 | @payable
151 | def ethToTokenSwapInput(min_tokens: uint256, deadline: timestamp) -> uint256:
152 | return self.ethToTokenInput(msg.value, min_tokens, deadline, msg.sender, msg.sender)
153 |
154 | # @notice Convert ETH to Tokens and transfers Tokens to recipient.
155 | # @dev User specifies exact input (msg.value) and minimum output
156 | # @param min_tokens Minimum Tokens bought.
157 | # @param deadline Time after which this transaction can no longer be executed.
158 | # @param recipient The address that receives output Tokens.
159 | # @return Amount of Tokens bought.
160 | @public
161 | @payable
162 | def ethToTokenTransferInput(min_tokens: uint256, deadline: timestamp, recipient: address) -> uint256:
163 | assert recipient != self and recipient != ZERO_ADDRESS
164 | return self.ethToTokenInput(msg.value, min_tokens, deadline, msg.sender, recipient)
165 |
166 | @private
167 | def ethToTokenOutput(tokens_bought: uint256, max_eth: uint256(wei), deadline: timestamp, buyer: address, recipient: address) -> uint256(wei):
168 | assert deadline >= block.timestamp and (tokens_bought > 0 and max_eth > 0)
169 | token_reserve: uint256 = self.token.balanceOf(self)
170 | eth_sold: uint256 = self.getOutputPrice(tokens_bought, as_unitless_number(self.balance - max_eth), token_reserve)
171 | # Throws if eth_sold > max_eth
172 | eth_refund: uint256(wei) = max_eth - as_wei_value(eth_sold, 'wei')
173 | if eth_refund > 0:
174 | send(buyer, eth_refund)
175 | assert self.token.transfer(recipient, tokens_bought)
176 | log.TokenPurchase(buyer, as_wei_value(eth_sold, 'wei'), tokens_bought)
177 | return as_wei_value(eth_sold, 'wei')
178 |
179 | # @notice Convert ETH to Tokens.
180 | # @dev User specifies maximum input (msg.value) and exact output.
181 | # @param tokens_bought Amount of tokens bought.
182 | # @param deadline Time after which this transaction can no longer be executed.
183 | # @return Amount of ETH sold.
184 | @public
185 | @payable
186 | def ethToTokenSwapOutput(tokens_bought: uint256, deadline: timestamp) -> uint256(wei):
187 | return self.ethToTokenOutput(tokens_bought, msg.value, deadline, msg.sender, msg.sender)
188 |
189 | # @notice Convert ETH to Tokens and transfers Tokens to recipient.
190 | # @dev User specifies maximum input (msg.value) and exact output.
191 | # @param tokens_bought Amount of tokens bought.
192 | # @param deadline Time after which this transaction can no longer be executed.
193 | # @param recipient The address that receives output Tokens.
194 | # @return Amount of ETH sold.
195 | @public
196 | @payable
197 | def ethToTokenTransferOutput(tokens_bought: uint256, deadline: timestamp, recipient: address) -> uint256(wei):
198 | assert recipient != self and recipient != ZERO_ADDRESS
199 | return self.ethToTokenOutput(tokens_bought, msg.value, deadline, msg.sender, recipient)
200 |
201 | @private
202 | def tokenToEthInput(tokens_sold: uint256, min_eth: uint256(wei), deadline: timestamp, buyer: address, recipient: address) -> uint256(wei):
203 | assert deadline >= block.timestamp and (tokens_sold > 0 and min_eth > 0)
204 | token_reserve: uint256 = self.token.balanceOf(self)
205 | eth_bought: uint256 = self.getInputPrice(tokens_sold, token_reserve, as_unitless_number(self.balance))
206 | wei_bought: uint256(wei) = as_wei_value(eth_bought, 'wei')
207 | assert wei_bought >= min_eth
208 | send(recipient, wei_bought)
209 | assert self.token.transferFrom(buyer, self, tokens_sold)
210 | log.EthPurchase(buyer, tokens_sold, wei_bought)
211 | return wei_bought
212 |
213 |
214 | # @notice Convert Tokens to ETH.
215 | # @dev User specifies exact input and minimum output.
216 | # @param tokens_sold Amount of Tokens sold.
217 | # @param min_eth Minimum ETH purchased.
218 | # @param deadline Time after which this transaction can no longer be executed.
219 | # @return Amount of ETH bought.
220 | @public
221 | def tokenToEthSwapInput(tokens_sold: uint256, min_eth: uint256(wei), deadline: timestamp) -> uint256(wei):
222 | return self.tokenToEthInput(tokens_sold, min_eth, deadline, msg.sender, msg.sender)
223 |
224 | # @notice Convert Tokens to ETH and transfers ETH to recipient.
225 | # @dev User specifies exact input and minimum output.
226 | # @param tokens_sold Amount of Tokens sold.
227 | # @param min_eth Minimum ETH purchased.
228 | # @param deadline Time after which this transaction can no longer be executed.
229 | # @param recipient The address that receives output ETH.
230 | # @return Amount of ETH bought.
231 | @public
232 | def tokenToEthTransferInput(tokens_sold: uint256, min_eth: uint256(wei), deadline: timestamp, recipient: address) -> uint256(wei):
233 | assert recipient != self and recipient != ZERO_ADDRESS
234 | return self.tokenToEthInput(tokens_sold, min_eth, deadline, msg.sender, recipient)
235 |
236 | @private
237 | def tokenToEthOutput(eth_bought: uint256(wei), max_tokens: uint256, deadline: timestamp, buyer: address, recipient: address) -> uint256:
238 | assert deadline >= block.timestamp and eth_bought > 0
239 | token_reserve: uint256 = self.token.balanceOf(self)
240 | tokens_sold: uint256 = self.getOutputPrice(as_unitless_number(eth_bought), token_reserve, as_unitless_number(self.balance))
241 | # tokens sold is always > 0
242 | assert max_tokens >= tokens_sold
243 | send(recipient, eth_bought)
244 | assert self.token.transferFrom(buyer, self, tokens_sold)
245 | log.EthPurchase(buyer, tokens_sold, eth_bought)
246 | return tokens_sold
247 |
248 | # @notice Convert Tokens to ETH.
249 | # @dev User specifies maximum input and exact output.
250 | # @param eth_bought Amount of ETH purchased.
251 | # @param max_tokens Maximum Tokens sold.
252 | # @param deadline Time after which this transaction can no longer be executed.
253 | # @return Amount of Tokens sold.
254 | @public
255 | def tokenToEthSwapOutput(eth_bought: uint256(wei), max_tokens: uint256, deadline: timestamp) -> uint256:
256 | return self.tokenToEthOutput(eth_bought, max_tokens, deadline, msg.sender, msg.sender)
257 |
258 | # @notice Convert Tokens to ETH and transfers ETH to recipient.
259 | # @dev User specifies maximum input and exact output.
260 | # @param eth_bought Amount of ETH purchased.
261 | # @param max_tokens Maximum Tokens sold.
262 | # @param deadline Time after which this transaction can no longer be executed.
263 | # @param recipient The address that receives output ETH.
264 | # @return Amount of Tokens sold.
265 | @public
266 | def tokenToEthTransferOutput(eth_bought: uint256(wei), max_tokens: uint256, deadline: timestamp, recipient: address) -> uint256:
267 | assert recipient != self and recipient != ZERO_ADDRESS
268 | return self.tokenToEthOutput(eth_bought, max_tokens, deadline, msg.sender, recipient)
269 |
270 | @private
271 | def tokenToTokenInput(tokens_sold: uint256, min_tokens_bought: uint256, min_eth_bought: uint256(wei), deadline: timestamp, buyer: address, recipient: address, exchange_addr: address) -> uint256:
272 | assert (deadline >= block.timestamp and tokens_sold > 0) and (min_tokens_bought > 0 and min_eth_bought > 0)
273 | assert exchange_addr != self and exchange_addr != ZERO_ADDRESS
274 | token_reserve: uint256 = self.token.balanceOf(self)
275 | eth_bought: uint256 = self.getInputPrice(tokens_sold, token_reserve, as_unitless_number(self.balance))
276 | wei_bought: uint256(wei) = as_wei_value(eth_bought, 'wei')
277 | assert wei_bought >= min_eth_bought
278 | assert self.token.transferFrom(buyer, self, tokens_sold)
279 | tokens_bought: uint256 = Exchange(exchange_addr).ethToTokenTransferInput(min_tokens_bought, deadline, recipient, value=wei_bought)
280 | log.EthPurchase(buyer, tokens_sold, wei_bought)
281 | return tokens_bought
282 |
283 | # @notice Convert Tokens (self.token) to Tokens (token_addr).
284 | # @dev User specifies exact input and minimum output.
285 | # @param tokens_sold Amount of Tokens sold.
286 | # @param min_tokens_bought Minimum Tokens (token_addr) purchased.
287 | # @param min_eth_bought Minimum ETH purchased as intermediary.
288 | # @param deadline Time after which this transaction can no longer be executed.
289 | # @param token_addr The address of the token being purchased.
290 | # @return Amount of Tokens (token_addr) bought.
291 | @public
292 | def tokenToTokenSwapInput(tokens_sold: uint256, min_tokens_bought: uint256, min_eth_bought: uint256(wei), deadline: timestamp, token_addr: address) -> uint256:
293 | exchange_addr: address = self.factory.getExchange(token_addr)
294 | return self.tokenToTokenInput(tokens_sold, min_tokens_bought, min_eth_bought, deadline, msg.sender, msg.sender, exchange_addr)
295 |
296 | # @notice Convert Tokens (self.token) to Tokens (token_addr) and transfers
297 | # Tokens (token_addr) to recipient.
298 | # @dev User specifies exact input and minimum output.
299 | # @param tokens_sold Amount of Tokens sold.
300 | # @param min_tokens_bought Minimum Tokens (token_addr) purchased.
301 | # @param min_eth_bought Minimum ETH purchased as intermediary.
302 | # @param deadline Time after which this transaction can no longer be executed.
303 | # @param recipient The address that receives output ETH.
304 | # @param token_addr The address of the token being purchased.
305 | # @return Amount of Tokens (token_addr) bought.
306 | @public
307 | def tokenToTokenTransferInput(tokens_sold: uint256, min_tokens_bought: uint256, min_eth_bought: uint256(wei), deadline: timestamp, recipient: address, token_addr: address) -> uint256:
308 | exchange_addr: address = self.factory.getExchange(token_addr)
309 | return self.tokenToTokenInput(tokens_sold, min_tokens_bought, min_eth_bought, deadline, msg.sender, recipient, exchange_addr)
310 |
311 | @private
312 | def tokenToTokenOutput(tokens_bought: uint256, max_tokens_sold: uint256, max_eth_sold: uint256(wei), deadline: timestamp, buyer: address, recipient: address, exchange_addr: address) -> uint256:
313 | assert deadline >= block.timestamp and (tokens_bought > 0 and max_eth_sold > 0)
314 | assert exchange_addr != self and exchange_addr != ZERO_ADDRESS
315 | eth_bought: uint256(wei) = Exchange(exchange_addr).getEthToTokenOutputPrice(tokens_bought)
316 | token_reserve: uint256 = self.token.balanceOf(self)
317 | tokens_sold: uint256 = self.getOutputPrice(as_unitless_number(eth_bought), token_reserve, as_unitless_number(self.balance))
318 | # tokens sold is always > 0
319 | assert max_tokens_sold >= tokens_sold and max_eth_sold >= eth_bought
320 | assert self.token.transferFrom(buyer, self, tokens_sold)
321 | eth_sold: uint256(wei) = Exchange(exchange_addr).ethToTokenTransferOutput(tokens_bought, deadline, recipient, value=eth_bought)
322 | log.EthPurchase(buyer, tokens_sold, eth_bought)
323 | return tokens_sold
324 |
325 | # @notice Convert Tokens (self.token) to Tokens (token_addr).
326 | # @dev User specifies maximum input and exact output.
327 | # @param tokens_bought Amount of Tokens (token_addr) bought.
328 | # @param max_tokens_sold Maximum Tokens (self.token) sold.
329 | # @param max_eth_sold Maximum ETH purchased as intermediary.
330 | # @param deadline Time after which this transaction can no longer be executed.
331 | # @param token_addr The address of the token being purchased.
332 | # @return Amount of Tokens (self.token) sold.
333 | @public
334 | def tokenToTokenSwapOutput(tokens_bought: uint256, max_tokens_sold: uint256, max_eth_sold: uint256(wei), deadline: timestamp, token_addr: address) -> uint256:
335 | exchange_addr: address = self.factory.getExchange(token_addr)
336 | return self.tokenToTokenOutput(tokens_bought, max_tokens_sold, max_eth_sold, deadline, msg.sender, msg.sender, exchange_addr)
337 |
338 | # @notice Convert Tokens (self.token) to Tokens (token_addr) and transfers
339 | # Tokens (token_addr) to recipient.
340 | # @dev User specifies maximum input and exact output.
341 | # @param tokens_bought Amount of Tokens (token_addr) bought.
342 | # @param max_tokens_sold Maximum Tokens (self.token) sold.
343 | # @param max_eth_sold Maximum ETH purchased as intermediary.
344 | # @param deadline Time after which this transaction can no longer be executed.
345 | # @param recipient The address that receives output ETH.
346 | # @param token_addr The address of the token being purchased.
347 | # @return Amount of Tokens (self.token) sold.
348 | @public
349 | def tokenToTokenTransferOutput(tokens_bought: uint256, max_tokens_sold: uint256, max_eth_sold: uint256(wei), deadline: timestamp, recipient: address, token_addr: address) -> uint256:
350 | exchange_addr: address = self.factory.getExchange(token_addr)
351 | return self.tokenToTokenOutput(tokens_bought, max_tokens_sold, max_eth_sold, deadline, msg.sender, recipient, exchange_addr)
352 |
353 | # @notice Convert Tokens (self.token) to Tokens (exchange_addr.token).
354 | # @dev Allows trades through contracts that were not deployed from the same factory.
355 | # @dev User specifies exact input and minimum output.
356 | # @param tokens_sold Amount of Tokens sold.
357 | # @param min_tokens_bought Minimum Tokens (token_addr) purchased.
358 | # @param min_eth_bought Minimum ETH purchased as intermediary.
359 | # @param deadline Time after which this transaction can no longer be executed.
360 | # @param exchange_addr The address of the exchange for the token being purchased.
361 | # @return Amount of Tokens (exchange_addr.token) bought.
362 | @public
363 | def tokenToExchangeSwapInput(tokens_sold: uint256, min_tokens_bought: uint256, min_eth_bought: uint256(wei), deadline: timestamp, exchange_addr: address) -> uint256:
364 | return self.tokenToTokenInput(tokens_sold, min_tokens_bought, min_eth_bought, deadline, msg.sender, msg.sender, exchange_addr)
365 |
366 | # @notice Convert Tokens (self.token) to Tokens (exchange_addr.token) and transfers
367 | # Tokens (exchange_addr.token) to recipient.
368 | # @dev Allows trades through contracts that were not deployed from the same factory.
369 | # @dev User specifies exact input and minimum output.
370 | # @param tokens_sold Amount of Tokens sold.
371 | # @param min_tokens_bought Minimum Tokens (token_addr) purchased.
372 | # @param min_eth_bought Minimum ETH purchased as intermediary.
373 | # @param deadline Time after which this transaction can no longer be executed.
374 | # @param recipient The address that receives output ETH.
375 | # @param exchange_addr The address of the exchange for the token being purchased.
376 | # @return Amount of Tokens (exchange_addr.token) bought.
377 | @public
378 | def tokenToExchangeTransferInput(tokens_sold: uint256, min_tokens_bought: uint256, min_eth_bought: uint256(wei), deadline: timestamp, recipient: address, exchange_addr: address) -> uint256:
379 | assert recipient != self
380 | return self.tokenToTokenInput(tokens_sold, min_tokens_bought, min_eth_bought, deadline, msg.sender, recipient, exchange_addr)
381 |
382 | # @notice Convert Tokens (self.token) to Tokens (exchange_addr.token).
383 | # @dev Allows trades through contracts that were not deployed from the same factory.
384 | # @dev User specifies maximum input and exact output.
385 | # @param tokens_bought Amount of Tokens (token_addr) bought.
386 | # @param max_tokens_sold Maximum Tokens (self.token) sold.
387 | # @param max_eth_sold Maximum ETH purchased as intermediary.
388 | # @param deadline Time after which this transaction can no longer be executed.
389 | # @param exchange_addr The address of the exchange for the token being purchased.
390 | # @return Amount of Tokens (self.token) sold.
391 | @public
392 | def tokenToExchangeSwapOutput(tokens_bought: uint256, max_tokens_sold: uint256, max_eth_sold: uint256(wei), deadline: timestamp, exchange_addr: address) -> uint256:
393 | return self.tokenToTokenOutput(tokens_bought, max_tokens_sold, max_eth_sold, deadline, msg.sender, msg.sender, exchange_addr)
394 |
395 | # @notice Convert Tokens (self.token) to Tokens (exchange_addr.token) and transfers
396 | # Tokens (exchange_addr.token) to recipient.
397 | # @dev Allows trades through contracts that were not deployed from the same factory.
398 | # @dev User specifies maximum input and exact output.
399 | # @param tokens_bought Amount of Tokens (token_addr) bought.
400 | # @param max_tokens_sold Maximum Tokens (self.token) sold.
401 | # @param max_eth_sold Maximum ETH purchased as intermediary.
402 | # @param deadline Time after which this transaction can no longer be executed.
403 | # @param recipient The address that receives output ETH.
404 | # @param token_addr The address of the token being purchased.
405 | # @return Amount of Tokens (self.token) sold.
406 | @public
407 | def tokenToExchangeTransferOutput(tokens_bought: uint256, max_tokens_sold: uint256, max_eth_sold: uint256(wei), deadline: timestamp, recipient: address, exchange_addr: address) -> uint256:
408 | assert recipient != self
409 | return self.tokenToTokenOutput(tokens_bought, max_tokens_sold, max_eth_sold, deadline, msg.sender, recipient, exchange_addr)
410 |
411 | # @notice Public price function for ETH to Token trades with an exact input.
412 | # @param eth_sold Amount of ETH sold.
413 | # @return Amount of Tokens that can be bought with input ETH.
414 | @public
415 | @constant
416 | def getEthToTokenInputPrice(eth_sold: uint256(wei)) -> uint256:
417 | assert eth_sold > 0
418 | token_reserve: uint256 = self.token.balanceOf(self)
419 | return self.getInputPrice(as_unitless_number(eth_sold), as_unitless_number(self.balance), token_reserve)
420 |
421 | # @notice Public price function for ETH to Token trades with an exact output.
422 | # @param tokens_bought Amount of Tokens bought.
423 | # @return Amount of ETH needed to buy output Tokens.
424 | @public
425 | @constant
426 | def getEthToTokenOutputPrice(tokens_bought: uint256) -> uint256(wei):
427 | assert tokens_bought > 0
428 | token_reserve: uint256 = self.token.balanceOf(self)
429 | eth_sold: uint256 = self.getOutputPrice(tokens_bought, as_unitless_number(self.balance), token_reserve)
430 | return as_wei_value(eth_sold, 'wei')
431 |
432 | # @notice Public price function for Token to ETH trades with an exact input.
433 | # @param tokens_sold Amount of Tokens sold.
434 | # @return Amount of ETH that can be bought with input Tokens.
435 | @public
436 | @constant
437 | def getTokenToEthInputPrice(tokens_sold: uint256) -> uint256(wei):
438 | assert tokens_sold > 0
439 | token_reserve: uint256 = self.token.balanceOf(self)
440 | eth_bought: uint256 = self.getInputPrice(tokens_sold, token_reserve, as_unitless_number(self.balance))
441 | return as_wei_value(eth_bought, 'wei')
442 |
443 | # @notice Public price function for Token to ETH trades with an exact output.
444 | # @param eth_bought Amount of output ETH.
445 | # @return Amount of Tokens needed to buy output ETH.
446 | @public
447 | @constant
448 | def getTokenToEthOutputPrice(eth_bought: uint256(wei)) -> uint256:
449 | assert eth_bought > 0
450 | token_reserve: uint256 = self.token.balanceOf(self)
451 | return self.getOutputPrice(as_unitless_number(eth_bought), token_reserve, as_unitless_number(self.balance))
452 |
453 | # @return Address of Token that is sold on this exchange.
454 | @public
455 | @constant
456 | def tokenAddress() -> address:
457 | return self.token
458 |
459 | # @return Address of factory that created this exchange.
460 | @public
461 | @constant
462 | def factoryAddress() -> address(Factory):
463 | return self.factory
464 |
465 | # ERC20 compatibility for exchange liquidity modified from
466 | # https://github.com/ethereum/vyper/blob/master/examples/tokens/ERC20.vy
467 | @public
468 | @constant
469 | def balanceOf(_owner : address) -> uint256:
470 | return self.balances[_owner]
471 |
472 | @public
473 | def transfer(_to : address, _value : uint256) -> bool:
474 | self.balances[msg.sender] -= _value
475 | self.balances[_to] += _value
476 | log.Transfer(msg.sender, _to, _value)
477 | return True
478 |
479 | @public
480 | def transferFrom(_from : address, _to : address, _value : uint256) -> bool:
481 | self.balances[_from] -= _value
482 | self.balances[_to] += _value
483 | self.allowances[_from][msg.sender] -= _value
484 | log.Transfer(_from, _to, _value)
485 | return True
486 |
487 | @public
488 | def approve(_spender : address, _value : uint256) -> bool:
489 | self.allowances[msg.sender][_spender] = _value
490 | log.Approval(msg.sender, _spender, _value)
491 | return True
492 |
493 | @public
494 | @constant
495 | def allowance(_owner : address, _spender : address) -> uint256:
496 | return self.allowances[_owner][_spender]
497 |
--------------------------------------------------------------------------------
/contracts/uniswap_factory.vy:
--------------------------------------------------------------------------------
1 | contract Exchange():
2 | def setup(token_addr: address): modifying
3 |
4 | NewExchange: event({token: indexed(address), exchange: indexed(address)})
5 |
6 | exchangeTemplate: public(address)
7 | tokenCount: public(uint256)
8 | token_to_exchange: address[address]
9 | exchange_to_token: address[address]
10 | id_to_token: address[uint256]
11 |
12 | @public
13 | def initializeFactory(template: address):
14 | assert self.exchangeTemplate == ZERO_ADDRESS
15 | assert template != ZERO_ADDRESS
16 | self.exchangeTemplate = template
17 |
18 | @public
19 | def createExchange(token: address) -> address:
20 | assert token != ZERO_ADDRESS
21 | assert self.exchangeTemplate != ZERO_ADDRESS
22 | assert self.token_to_exchange[token] == ZERO_ADDRESS
23 | exchange: address = create_with_code_of(self.exchangeTemplate)
24 | Exchange(exchange).setup(token)
25 | self.token_to_exchange[token] = exchange
26 | self.exchange_to_token[exchange] = token
27 | token_id: uint256 = self.tokenCount + 1
28 | self.tokenCount = token_id
29 | self.id_to_token[token_id] = token
30 | log.NewExchange(token, exchange)
31 | return exchange
32 |
33 | @public
34 | @constant
35 | def getExchange(token: address) -> address:
36 | return self.token_to_exchange[token]
37 |
38 | @public
39 | @constant
40 | def getToken(exchange: address) -> address:
41 | return self.exchange_to_token[exchange]
42 |
43 | @public
44 | @constant
45 | def getTokenWithId(token_id: uint256) -> address:
46 | return self.id_to_token[token_id]
47 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | vyper==0.1.0b4
2 | web3==4.4.1
3 | eth-tester[py-evm]==0.1.0b33
4 | pytest
5 |
--------------------------------------------------------------------------------
/tests/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Uniswap/v1-contracts/c10c08d81d6114f694baa8bd32f555a40f6264da/tests/__init__.py
--------------------------------------------------------------------------------
/tests/conftest.py:
--------------------------------------------------------------------------------
1 | import os
2 | import pytest
3 | from pytest import raises
4 |
5 | from web3 import Web3
6 | from web3.contract import ConciseContract
7 | import eth_tester
8 | from eth_tester import EthereumTester, PyEVMBackend
9 | from eth_tester.exceptions import TransactionFailed
10 | from vyper import compiler
11 |
12 | from tests.constants import (
13 | ETH_RESERVE,
14 | HAY_RESERVE,
15 | DEN_RESERVE,
16 | DEADLINE,
17 | )
18 |
19 | '''
20 | # run tests with: python -m pytest -v
21 | '''
22 |
23 | setattr(eth_tester.backends.pyevm.main, 'GENESIS_GAS_LIMIT', 10**9)
24 | setattr(eth_tester.backends.pyevm.main, 'GENESIS_DIFFICULTY', 1)
25 |
26 | @pytest.fixture
27 | def tester():
28 | return EthereumTester(backend=PyEVMBackend())
29 |
30 | @pytest.fixture
31 | def w3(tester):
32 | w3 = Web3(Web3.EthereumTesterProvider(tester))
33 | w3.eth.setGasPriceStrategy(lambda web3, params: 0)
34 | w3.eth.defaultAccount = w3.eth.accounts[0]
35 | return w3
36 |
37 | @pytest.fixture
38 | def pad_bytes32():
39 | def pad_bytes32(instr):
40 | """ Pad a string \x00 bytes to return correct bytes32 representation. """
41 | bstr = instr.encode()
42 | return bstr + (32 - len(bstr)) * b'\x00'
43 | return pad_bytes32
44 |
45 | # @pytest.fixture
46 | def create_contract(w3, path):
47 | wd = os.path.dirname(os.path.realpath(__file__))
48 | with open(os.path.join(wd, os.pardir, path)) as f:
49 | source = f.read()
50 | bytecode = '0x' + compiler.compile(source).hex()
51 | abi = compiler.mk_full_signature(source)
52 | return w3.eth.contract(abi=abi, bytecode=bytecode)
53 |
54 | @pytest.fixture
55 | def exchange_template(w3):
56 | deploy = create_contract(w3, 'contracts/uniswap_exchange.vy')
57 | tx_hash = deploy.constructor().transact()
58 | tx_receipt = w3.eth.getTransactionReceipt(tx_hash)
59 | return ConciseContract(w3.eth.contract(
60 | address=tx_receipt.contractAddress,
61 | abi=deploy.abi
62 | ))
63 |
64 | @pytest.fixture
65 | def HAY_token(w3):
66 | deploy = create_contract(w3, 'contracts/test_contracts/ERC20.vy')
67 | tx_hash = deploy.constructor(b'HAY Token', b'HAY', 18, 100000*10**18).transact()
68 | tx_receipt = w3.eth.getTransactionReceipt(tx_hash)
69 | return ConciseContract(w3.eth.contract(
70 | address=tx_receipt.contractAddress,
71 | abi=deploy.abi
72 | ))
73 |
74 | @pytest.fixture
75 | def DEN_token(w3):
76 | deploy = create_contract(w3, 'contracts/test_contracts/ERC20.vy')
77 | tx_hash = deploy.constructor(b'DEN Token', b'DEN', 18, 100000*10**18).transact()
78 | tx_receipt = w3.eth.getTransactionReceipt(tx_hash)
79 | return ConciseContract(w3.eth.contract(
80 | address=tx_receipt.contractAddress,
81 | abi=deploy.abi
82 | ))
83 |
84 | @pytest.fixture
85 | def factory(w3, exchange_template):
86 | deploy = create_contract(w3, 'contracts/uniswap_factory.vy')
87 | tx_hash = deploy.constructor().transact()
88 | tx_receipt = w3.eth.getTransactionReceipt(tx_hash)
89 | contract = ConciseContract(w3.eth.contract(
90 | address=tx_receipt.contractAddress,
91 | abi=deploy.abi
92 | ))
93 | contract.initializeFactory(exchange_template.address, transact={})
94 | return contract
95 |
96 | @pytest.fixture
97 | def exchange_abi():
98 | wd = os.path.dirname(os.path.realpath(__file__))
99 | code = open(os.path.join(wd, os.pardir, 'contracts/uniswap_exchange.vy')).read()
100 | return compiler.mk_full_signature(code)
101 |
102 | @pytest.fixture
103 | def HAY_exchange(w3, exchange_abi, factory, HAY_token):
104 | factory.createExchange(HAY_token.address, transact={})
105 | exchange_address = factory.getExchange(HAY_token.address)
106 | exchange = ConciseContract(w3.eth.contract(
107 | address=exchange_address,
108 | abi=exchange_abi
109 | ))
110 | HAY_token.approve(exchange_address, HAY_RESERVE, transact={})
111 | exchange.addLiquidity(0, HAY_RESERVE, DEADLINE, transact={'value': ETH_RESERVE})
112 | return exchange
113 |
114 | @pytest.fixture
115 | def DEN_exchange(w3, exchange_abi, factory, DEN_token):
116 | factory.createExchange(DEN_token.address, transact={})
117 | exchange_address = factory.getExchange(DEN_token.address)
118 | exchange = ConciseContract(w3.eth.contract(
119 | address=exchange_address,
120 | abi=exchange_abi
121 | ))
122 | DEN_token.approve(exchange_address, DEN_RESERVE, transact={})
123 | exchange.addLiquidity(0, DEN_RESERVE, DEADLINE, transact={'value': ETH_RESERVE})
124 | return exchange
125 |
126 |
127 | @pytest.fixture
128 | def swap_input():
129 | def swap_input(input_amount, input_reserve, output_reserve):
130 | input_amount_with_fee = input_amount * 997
131 | numerator = input_amount_with_fee * output_reserve
132 | denominator = input_reserve * 1000 + input_amount_with_fee
133 | return numerator // denominator
134 | return swap_input
135 |
136 | @pytest.fixture
137 | def swap_output():
138 | def swap_output(output_amount, input_reserve, output_reserve):
139 | numerator = input_reserve * output_amount * 1000
140 | denominator = (output_reserve - output_amount) * 997
141 | return numerator // denominator + 1
142 | return swap_output
143 |
144 | @pytest.fixture
145 | def assert_fail():
146 | def assert_fail(func):
147 | with raises(Exception):
148 | func()
149 | return assert_fail
150 |
--------------------------------------------------------------------------------
/tests/constants.py:
--------------------------------------------------------------------------------
1 | ZERO_ADDR = '0x0000000000000000000000000000000000000000'
2 | # Initial ETH balance of buyer
3 | INITIAL_ETH = 1*10**24
4 | # Passing deadline
5 | DEADLINE = 1742680400 # deadline = w3.eth.getBlock(w3.eth.blockNumber).timestamp
6 | # INITIAL RESERVE SIZE
7 | ETH_RESERVE = 5*10**18
8 | HAY_RESERVE = 10*10**18
9 | DEN_RESERVE = 20*10**18
10 | # ETH to ERC20 swap input
11 | ETH_SOLD = 1*10**18
12 | MIN_HAY_BOUGHT = 1
13 | # ETH to ERC20 swap output
14 | HAY_BOUGHT = 1662497915624478906
15 | MAX_ETH_SOLD = 2*10**18
16 | # ERC20 to ETH swap input
17 | HAY_SOLD = 2*10**18
18 | MIN_ETH_BOUGHT = 1
19 | # ERC20 to ETH swap output
20 | ETH_BOUGHT = 831248957812239453
21 | MAX_HAY_SOLD = 3*10**18
22 | # ERC20 to ERC20
23 | MIN_DEN_BOUGHT = 1
24 | DEN_BOUGHT = 2843678215834080602
25 |
--------------------------------------------------------------------------------
/tests/exchange/test_ERC20.py:
--------------------------------------------------------------------------------
1 | def test_ERC20(w3, HAY_token, pad_bytes32):
2 | a0, a1 = w3.eth.accounts[:2]
3 | assert HAY_token.name() == pad_bytes32('HAY Token')
4 | assert HAY_token.symbol() == pad_bytes32('HAY')
5 | assert HAY_token.decimals() == 18
6 | assert HAY_token.totalSupply() == 100000*10**18
7 | assert HAY_token.balanceOf(a0) == 100000*10**18
8 | HAY_token.transfer(a1, 1*10**18, transact={})
9 | assert HAY_token.balanceOf(a0) == 100000*10**18 - 1*10**18
10 | assert HAY_token.balanceOf(a1) == 1*10**18
11 |
--------------------------------------------------------------------------------
/tests/exchange/test_eth_to_token.py:
--------------------------------------------------------------------------------
1 | from tests.constants import (
2 | ETH_RESERVE,
3 | HAY_RESERVE,
4 | ETH_SOLD,
5 | MIN_HAY_BOUGHT,
6 | HAY_BOUGHT,
7 | MAX_ETH_SOLD,
8 | INITIAL_ETH,
9 | DEADLINE,
10 | ZERO_ADDR,
11 | )
12 |
13 | def test_swap_default(w3, HAY_token, HAY_exchange, swap_input, assert_fail):
14 | a0, a1, a2 = w3.eth.accounts[:3]
15 | HAY_PURCHASED = swap_input(ETH_SOLD, ETH_RESERVE, HAY_RESERVE)
16 | # msg.value == 0
17 | assert_fail(lambda: w3.eth.sendTransaction({'to': HAY_exchange.address, 'value': 0, 'from': a1}))
18 | # BUYER converts ETH to UNI
19 | w3.eth.sendTransaction({'to': HAY_exchange.address, 'value': ETH_SOLD, 'from': a1})
20 | # Updated balances of UNI exchange
21 | assert w3.eth.getBalance(HAY_exchange.address) == ETH_RESERVE + ETH_SOLD
22 | assert HAY_token.balanceOf(HAY_exchange.address) == HAY_RESERVE - HAY_PURCHASED
23 | # Updated balances of BUYER
24 | assert HAY_token.balanceOf(a1) == HAY_PURCHASED
25 | assert w3.eth.getBalance(a1) == INITIAL_ETH - ETH_SOLD
26 |
27 | def test_swap_input(w3, HAY_token, HAY_exchange, swap_input, assert_fail):
28 | a0, a1, a2 = w3.eth.accounts[:3]
29 | HAY_PURCHASED = swap_input(ETH_SOLD, ETH_RESERVE, HAY_RESERVE)
30 | assert HAY_exchange.getEthToTokenInputPrice(ETH_SOLD) == HAY_PURCHASED
31 | # eth sold == 0
32 | assert_fail(lambda: HAY_exchange.ethToTokenSwapInput(MIN_HAY_BOUGHT, DEADLINE, transact={'value': 0, 'from': a1}))
33 | # min tokens == 0
34 | assert_fail(lambda: HAY_exchange.ethToTokenSwapInput(0, DEADLINE, transact={'value': ETH_SOLD, 'from': a1}))
35 | # min tokens > tokens purchased
36 | assert_fail(lambda: HAY_exchange.ethToTokenSwapInput(HAY_PURCHASED + 1, DEADLINE, transact={'value': ETH_SOLD, 'from': a1}))
37 | # deadline < block.timestamp
38 | assert_fail(lambda: HAY_exchange.ethToTokenSwapInput(MIN_HAY_BOUGHT, 1, transact={'value': ETH_SOLD, 'from': a1}))
39 | # BUYER converts ETH to UNI
40 | HAY_exchange.ethToTokenSwapInput(MIN_HAY_BOUGHT, DEADLINE, transact={'value': ETH_SOLD, 'from': a1})
41 | # Updated balances of UNI exchange
42 | assert w3.eth.getBalance(HAY_exchange.address) == ETH_RESERVE + ETH_SOLD
43 | assert HAY_token.balanceOf(HAY_exchange.address) == HAY_RESERVE - HAY_PURCHASED
44 | # Updated balances of BUYER
45 | assert HAY_token.balanceOf(a1) == HAY_PURCHASED
46 | assert w3.eth.getBalance(a1) == INITIAL_ETH - ETH_SOLD
47 |
48 | def test_transfer_input(w3, HAY_token, HAY_exchange, swap_input, assert_fail):
49 | a0, a1, a2 = w3.eth.accounts[:3]
50 | HAY_PURCHASED = swap_input(ETH_SOLD, ETH_RESERVE, HAY_RESERVE)
51 | # recipient == ZERO_ADDR
52 | assert_fail(lambda: HAY_exchange.ethToTokenTransferInput(MIN_HAY_BOUGHT, DEADLINE, ZERO_ADDR, transact={'value': ETH_SOLD, 'from': a1}))
53 | # recipient == exchange
54 | assert_fail(lambda: HAY_exchange.ethToTokenTransferInput(MIN_HAY_BOUGHT, DEADLINE, HAY_exchange.address, transact={'value': ETH_SOLD, 'from': a1}))
55 | # BUYER converts ETH to UNI
56 | HAY_exchange.ethToTokenTransferInput(MIN_HAY_BOUGHT, DEADLINE, a2, transact={'value': ETH_SOLD, 'from': a1})
57 | # Updated balances of UNI exchange
58 | assert w3.eth.getBalance(HAY_exchange.address) == ETH_RESERVE + ETH_SOLD
59 | assert HAY_token.balanceOf(HAY_exchange.address) == HAY_RESERVE - HAY_PURCHASED
60 | # Updated balances of BUYER
61 | assert HAY_token.balanceOf(a1) == 0
62 | assert w3.eth.getBalance(a1) == INITIAL_ETH - ETH_SOLD
63 | # Updated balances of RECIPIENT
64 | assert HAY_token.balanceOf(a2) == HAY_PURCHASED
65 | assert w3.eth.getBalance(a2) == INITIAL_ETH
66 |
67 |
68 | def test_swap_output(w3, HAY_token, HAY_exchange, swap_output, assert_fail):
69 | a0, a1, a2 = w3.eth.accounts[:3]
70 | ETH_COST = swap_output(HAY_BOUGHT, ETH_RESERVE, HAY_RESERVE)
71 | assert HAY_exchange.getEthToTokenOutputPrice(HAY_BOUGHT) == ETH_COST
72 | # max eth < ETH_COST
73 | assert_fail(lambda: HAY_exchange.ethToTokenSwapOutput(HAY_BOUGHT, DEADLINE, transact={'value': ETH_COST - 1, 'from': a1}))
74 | # tokens bought == 0
75 | assert_fail(lambda: HAY_exchange.ethToTokenSwapOutput(0, DEADLINE, transact={'value': MAX_ETH_SOLD, 'from': a1}))
76 | # deadline < block.timestamp
77 | assert_fail(lambda: HAY_exchange.ethToTokenSwapOutput(HAY_BOUGHT, 1, transact={'value': MAX_ETH_SOLD, 'from': a1}))
78 | # BUYER converts ETH to UNI
79 | HAY_exchange.ethToTokenSwapOutput(HAY_BOUGHT, DEADLINE, transact={'value': MAX_ETH_SOLD, 'from': a1})
80 | # Updated balances of UNI exchange
81 | assert w3.eth.getBalance(HAY_exchange.address) == ETH_RESERVE + ETH_COST
82 | assert HAY_token.balanceOf(HAY_exchange.address) == HAY_RESERVE - HAY_BOUGHT
83 | # Updated balances of BUYER
84 | assert HAY_token.balanceOf(a1) == HAY_BOUGHT
85 | assert w3.eth.getBalance(a1) == INITIAL_ETH - ETH_COST
86 |
87 | def test_transfer_output(w3, HAY_token, HAY_exchange, swap_output, assert_fail):
88 | a0, a1, a2 = w3.eth.accounts[:3]
89 | ETH_COST = swap_output(HAY_BOUGHT, ETH_RESERVE, HAY_RESERVE)
90 | # recipient == ZERO_ADDR
91 | assert_fail(lambda: HAY_exchange.ethToTokenTransferOutput(HAY_BOUGHT, DEADLINE, ZERO_ADDR, transact={'value': MAX_ETH_SOLD, 'from': a1}))
92 | # recipient == exchange
93 | assert_fail(lambda: HAY_exchange.ethToTokenTransferOutput(HAY_BOUGHT, DEADLINE, HAY_exchange.address, transact={'value': MAX_ETH_SOLD, 'from': a1}))
94 | # BUYER converts ETH to UNI
95 | HAY_exchange.ethToTokenTransferOutput(HAY_BOUGHT, DEADLINE, a2, transact={'value': MAX_ETH_SOLD, 'from': a1})
96 | # Updated balances of UNI exchange
97 | assert w3.eth.getBalance(HAY_exchange.address) == ETH_RESERVE + ETH_COST
98 | assert HAY_token.balanceOf(HAY_exchange.address) == HAY_RESERVE - HAY_BOUGHT
99 | # Updated balances of BUYER
100 | assert HAY_token.balanceOf(a1) == 0
101 | assert w3.eth.getBalance(a1) == INITIAL_ETH - ETH_COST
102 | # Updated balances of RECIPIENT
103 | assert HAY_token.balanceOf(a2) == HAY_BOUGHT
104 | assert w3.eth.getBalance(a2) == INITIAL_ETH
105 |
--------------------------------------------------------------------------------
/tests/exchange/test_factory.py:
--------------------------------------------------------------------------------
1 | from pytest import raises
2 | from web3.contract import ConciseContract
3 | from eth_tester.exceptions import TransactionFailed
4 |
5 | def test_factory(w3, exchange_template, HAY_token, factory, pad_bytes32, exchange_abi, assert_fail):
6 | a0, a1 = w3.eth.accounts[:2]
7 | # Can't call initializeFactory on factory twice
8 | with raises(TransactionFailed):
9 | factory.initializeFactory(HAY_token.address)
10 | # Factory initial state
11 | assert factory.exchangeTemplate() == exchange_template.address
12 | assert factory.getExchange(HAY_token.address) == None
13 | # Create Exchange for UNI Token
14 | factory.createExchange(HAY_token.address, transact={})
15 | HAY_exchange_address = factory.getExchange(HAY_token.address)
16 | assert HAY_exchange_address != None
17 | HAY_exchange = ConciseContract(w3.eth.contract(address=HAY_exchange_address, abi=exchange_abi))
18 | assert factory.getToken(HAY_exchange.address) == HAY_token.address
19 | assert factory.tokenCount() == 1
20 | assert factory.getTokenWithId(1) == HAY_token.address
21 | # Exchange already exists
22 | with raises(TransactionFailed):
23 | factory.createExchange(HAY_token.address)
24 | # Can't call setup on exchange
25 | assert_fail(lambda: HAY_exchange.setup(factory.address))
26 | # Exchange initial state
27 | assert HAY_exchange.name() == pad_bytes32('Uniswap V1')
28 | assert HAY_exchange.symbol() == pad_bytes32('UNI-V1')
29 | assert HAY_exchange.decimals() == 18
30 | assert HAY_exchange.totalSupply() == 0
31 | assert HAY_exchange.tokenAddress() == HAY_token.address
32 | assert HAY_exchange.factoryAddress() == factory.address
33 | assert w3.eth.getBalance(HAY_exchange.address) == 0
34 | assert HAY_token.balanceOf(HAY_exchange.address) == 0
35 |
--------------------------------------------------------------------------------
/tests/exchange/test_liquidity_pool.py:
--------------------------------------------------------------------------------
1 | from tests.constants import (
2 | ETH_RESERVE,
3 | HAY_RESERVE,
4 | DEN_RESERVE,
5 | INITIAL_ETH,
6 | DEADLINE,
7 | )
8 |
9 | def test_initial_balances(w3, HAY_token, HAY_exchange, DEN_token, DEN_exchange):
10 | a0, a1, a2 = w3.eth.accounts[:3]
11 | # BUYER
12 | assert HAY_token.balanceOf(a1) == 0
13 | assert DEN_token.balanceOf(a1) == 0
14 | assert w3.eth.getBalance(a1) == INITIAL_ETH
15 | # RECIPIENT
16 | assert HAY_token.balanceOf(a2) == 0
17 | assert DEN_token.balanceOf(a2) == 0
18 | assert w3.eth.getBalance(a2) == INITIAL_ETH
19 | # HAY exchange
20 | assert w3.eth.getBalance(HAY_exchange.address) == ETH_RESERVE
21 | assert HAY_token.balanceOf(HAY_exchange.address) == HAY_RESERVE
22 | assert DEN_token.balanceOf(HAY_exchange.address) == 0
23 | # DEN exchange
24 | assert w3.eth.getBalance(DEN_exchange.address) == ETH_RESERVE
25 | assert HAY_token.balanceOf(DEN_exchange.address) == 0
26 | assert DEN_token.balanceOf(DEN_exchange.address) == DEN_RESERVE
27 |
28 | def test_liquidity_pool(w3, HAY_token, factory, HAY_exchange, assert_fail):
29 | a0, a1, a2 = w3.eth.accounts[:3]
30 | HAY_token.transfer(a1, 15*10**18, transact={})
31 | HAY_token.approve(HAY_exchange.address, 15*10**18, transact={'from': a1})
32 | assert HAY_token.balanceOf(a1) == 15*10**18
33 | # First liquidity provider (t.a0) adds liquidity (in conftest.py)
34 | assert HAY_exchange.totalSupply() == ETH_RESERVE
35 | assert HAY_exchange.balanceOf(a0) == ETH_RESERVE
36 | assert w3.eth.getBalance(HAY_exchange.address) == ETH_RESERVE
37 | assert HAY_token.balanceOf(HAY_exchange.address) == HAY_RESERVE
38 | ETH_ADDED = 25*10**17
39 | HAY_ADDED = 5*10**18
40 | # min_liquidity == 0 (while totalSupply > 0)
41 | assert_fail(lambda: HAY_exchange.addLiquidity(0, 15*10**18, DEADLINE, transact={'value': ETH_ADDED, 'from': a1}))
42 | # max_tokens < tokens needed
43 | assert_fail(lambda: HAY_exchange.addLiquidity(1, HAY_ADDED - 1, DEADLINE, transact={'value': ETH_ADDED, 'from': a1}))
44 | # deadline < block.timestamp
45 | assert_fail(lambda: HAY_exchange.addLiquidity(1, 15*10**18, 1, transact={'value': ETH_ADDED, 'from': a1}))
46 | # Second liquidity provider (a1) adds liquidity
47 | HAY_exchange.addLiquidity(1, 15*10**18, DEADLINE, transact={'value': ETH_ADDED, 'from': a1})
48 | assert HAY_exchange.totalSupply() == ETH_RESERVE + ETH_ADDED
49 | assert HAY_exchange.balanceOf(a0) == ETH_RESERVE
50 | assert HAY_exchange.balanceOf(a1) == ETH_ADDED
51 | assert w3.eth.getBalance(HAY_exchange.address) == ETH_RESERVE + ETH_ADDED
52 | assert HAY_token.balanceOf(HAY_exchange.address) == HAY_RESERVE + HAY_ADDED + 1
53 | # Can't transfer more liquidity than owned
54 | assert_fail(lambda: HAY_exchange.transfer(a2, ETH_ADDED + 1, transact={'from': a1}))
55 | # Second liquidity provider (a1) transfers liquidity to third liquidity provider (a2)
56 | HAY_exchange.transfer(a2, 1*10**18, transact={'from': a1})
57 | assert HAY_exchange.balanceOf(a0) == ETH_RESERVE
58 | assert HAY_exchange.balanceOf(a1) == ETH_ADDED - 1*10**18
59 | assert HAY_exchange.balanceOf(a2) == 1*10**18
60 | assert w3.eth.getBalance(HAY_exchange.address) == ETH_RESERVE + ETH_ADDED
61 | assert HAY_token.balanceOf(HAY_exchange.address) == HAY_RESERVE + HAY_ADDED + 1
62 | # amount == 0
63 | assert_fail(lambda: HAY_exchange.removeLiquidity(0, 1, 1, DEADLINE, transact={'from': a2}))
64 | # amount > owned (liquidity)
65 | assert_fail(lambda: HAY_exchange.removeLiquidity(1*10**18 + 1, 1, 1, DEADLINE, transact={'from': a2}))
66 | # min eth > eth divested
67 | assert_fail(lambda: HAY_exchange.removeLiquidity(1*10**18, 1*10**18 + 1, 1, DEADLINE, transact={'from': a2}))
68 | # min tokens > tokens divested
69 | assert_fail(lambda: HAY_exchange.removeLiquidity(1*10**18, 1, 2*10**18 + 1, DEADLINE, transact={'from': a2}))
70 | # deadline < block.timestamp
71 | assert_fail(lambda: HAY_exchange.removeLiquidity(1*10**18, 1, 1, 1, transact={'from': a2}))
72 | # First, second and third liquidity providers remove their remaining liquidity
73 | HAY_exchange.removeLiquidity(ETH_RESERVE, 1, 1, DEADLINE, transact={})
74 | HAY_exchange.removeLiquidity(ETH_ADDED - 1*10**18, 1, 1, DEADLINE, transact={'from': a1})
75 | HAY_exchange.removeLiquidity(1*10**18, 1, 1, DEADLINE, transact={'from': a2})
76 | assert HAY_exchange.totalSupply() == 0
77 | assert HAY_exchange.balanceOf(a0) == 0
78 | assert HAY_exchange.balanceOf(a1) == 0
79 | assert HAY_exchange.balanceOf(a2) == 0
80 | assert HAY_token.balanceOf(a1) == 13*10**18 - 1
81 | assert HAY_token.balanceOf(a2) == 2*10**18 + 1
82 | assert w3.eth.getBalance(HAY_exchange.address) == 0
83 | assert HAY_token.balanceOf(HAY_exchange.address) == 0
84 | # Can add liquidity again after all liquidity is divested
85 | HAY_token.approve(HAY_exchange.address, 100*10**18, transact={})
86 | HAY_exchange.addLiquidity(0, HAY_RESERVE, DEADLINE, transact={'value': ETH_RESERVE})
87 |
--------------------------------------------------------------------------------
/tests/exchange/test_token_to_eth.py:
--------------------------------------------------------------------------------
1 | from tests.constants import (
2 | ETH_RESERVE,
3 | HAY_RESERVE,
4 | HAY_SOLD,
5 | MIN_ETH_BOUGHT,
6 | ETH_BOUGHT,
7 | MAX_HAY_SOLD,
8 | INITIAL_ETH,
9 | DEADLINE,
10 | ZERO_ADDR,
11 | )
12 |
13 | def test_swap_input(w3, HAY_token, HAY_exchange, swap_input, assert_fail):
14 | a0, a1, a2 = w3.eth.accounts[:3]
15 | ETH_PURCHASED = swap_input(HAY_SOLD, HAY_RESERVE, ETH_RESERVE)
16 | # Transfer HAY to BUYER
17 | HAY_token.transfer(a1, HAY_SOLD, transact={})
18 | HAY_token.approve(HAY_exchange.address, HAY_SOLD, transact={'from': a1})
19 | assert HAY_token.balanceOf(a1) == HAY_SOLD
20 | # tokens sold == 0
21 | assert_fail(lambda: HAY_exchange.tokenToEthSwapInput(0, MIN_ETH_BOUGHT, DEADLINE, transact={'from': a1}))
22 | # min eth == 0
23 | assert_fail(lambda: HAY_exchange.tokenToEthSwapInput(HAY_SOLD, 0, DEADLINE, transact={'from': a1}))
24 | # min eth > eth purchased
25 | assert_fail(lambda: HAY_exchange.tokenToEthSwapInput(HAY_SOLD, ETH_PURCHASED + 1, DEADLINE, transact={'from': a1}))
26 | # deadline < block.timestamp
27 | assert_fail(lambda: HAY_exchange.tokenToEthSwapInput(HAY_SOLD, MIN_ETH_BOUGHT, 1, transact={'from': a1}))
28 | # BUYER converts ETH to UNI
29 | HAY_exchange.tokenToEthSwapInput(HAY_SOLD, MIN_ETH_BOUGHT, DEADLINE, transact={'from': a1})
30 | # Updated balances of UNI exchange
31 | assert w3.eth.getBalance(HAY_exchange.address) == ETH_RESERVE - ETH_PURCHASED
32 | assert HAY_token.balanceOf(HAY_exchange.address) == HAY_RESERVE + HAY_SOLD
33 | # Updated balances of BUYER
34 | assert HAY_token.balanceOf(a1) == 0
35 | assert w3.eth.getBalance(a1) == INITIAL_ETH + ETH_PURCHASED
36 |
37 | def test_transfer_input(w3, HAY_token, HAY_exchange, swap_input, assert_fail):
38 | a0, a1, a2 = w3.eth.accounts[:3]
39 | ETH_PURCHASED = swap_input(HAY_SOLD, HAY_RESERVE, ETH_RESERVE)
40 | # Transfer HAY to BUYER
41 | HAY_token.transfer(a1, HAY_SOLD, transact={})
42 | HAY_token.approve(HAY_exchange.address, HAY_SOLD, transact={'from': a1})
43 | assert HAY_token.balanceOf(a1) == HAY_SOLD
44 | # recipient == ZERO_ADDR
45 | assert_fail(lambda: HAY_exchange.tokenToEthTransferInput(HAY_SOLD, 1, DEADLINE, ZERO_ADDR, transact={'from': a1}))
46 | # recipient == exchange
47 | assert_fail(lambda: HAY_exchange.tokenToEthTransferInput(HAY_SOLD, 1, DEADLINE, HAY_exchange.address, transact={'from': a1}))
48 | # BUYER converts ETH to UNI
49 | HAY_exchange.tokenToEthTransferInput(HAY_SOLD, 1, DEADLINE, a2, transact={'from': a1})
50 | # Updated balances of UNI exchange
51 | assert w3.eth.getBalance(HAY_exchange.address) == ETH_RESERVE - ETH_PURCHASED
52 | assert HAY_token.balanceOf(HAY_exchange.address) == HAY_RESERVE + HAY_SOLD
53 | # Updated balances of BUYER
54 | assert HAY_token.balanceOf(a1) == 0
55 | assert w3.eth.getBalance(a1) == INITIAL_ETH
56 | # Updated balances of RECIPIENT
57 | assert HAY_token.balanceOf(a2) == 0
58 | assert w3.eth.getBalance(a2) == INITIAL_ETH + ETH_PURCHASED
59 |
60 | def test_swap_output(w3, HAY_token, HAY_exchange, swap_output, assert_fail):
61 | a0, a1, a2 = w3.eth.accounts[:3]
62 | HAY_COST = swap_output(ETH_BOUGHT, HAY_RESERVE, ETH_RESERVE)
63 | # Transfer HAY to BUYER
64 | HAY_token.transfer(a1, MAX_HAY_SOLD, transact={})
65 | HAY_token.approve(HAY_exchange.address, MAX_HAY_SOLD, transact={'from': a1})
66 | assert HAY_token.balanceOf(a1) == MAX_HAY_SOLD
67 | # tokens bought == 0
68 | assert_fail(lambda: HAY_exchange.tokenToEthSwapOutput(0, MAX_HAY_SOLD, DEADLINE, transact={'from': a1}))
69 | # max tokens < token cost
70 | assert_fail(lambda: HAY_exchange.tokenToEthSwapOutput(ETH_BOUGHT, HAY_COST - 1, DEADLINE, transact={'from': a1}))
71 | # deadline < block.timestamp
72 | assert_fail(lambda: HAY_exchange.tokenToEthSwapOutput(ETH_BOUGHT, MAX_HAY_SOLD, 1, transact={'from': a1}))
73 | # BUYER converts ETH to UNI
74 | HAY_exchange.tokenToEthSwapOutput(ETH_BOUGHT, MAX_HAY_SOLD, DEADLINE, transact={'from': a1})
75 | # Updated balances of UNI exchange
76 | assert w3.eth.getBalance(HAY_exchange.address) == ETH_RESERVE - ETH_BOUGHT
77 | assert HAY_token.balanceOf(HAY_exchange.address) == HAY_RESERVE + HAY_COST
78 | # Updated balances of BUYER
79 | assert HAY_token.balanceOf(a1) == MAX_HAY_SOLD - HAY_COST
80 | assert w3.eth.getBalance(a1) == INITIAL_ETH + ETH_BOUGHT
81 |
82 | def test_transfer_output(w3, HAY_token, HAY_exchange, swap_output, assert_fail):
83 | a0, a1, a2 = w3.eth.accounts[:3]
84 | HAY_COST = swap_output(ETH_BOUGHT, HAY_RESERVE, ETH_RESERVE)
85 | # Transfer HAY to BUYER
86 | HAY_token.transfer(a1, MAX_HAY_SOLD, transact={})
87 | HAY_token.approve(HAY_exchange.address, MAX_HAY_SOLD, transact={'from': a1})
88 | assert HAY_token.balanceOf(a1) == MAX_HAY_SOLD
89 | # recipient == ZERO_ADDR
90 | assert_fail(lambda: HAY_exchange.tokenToEthTransferOutput(ETH_BOUGHT, MAX_HAY_SOLD, DEADLINE, ZERO_ADDR, transact={'from': a1}))
91 | # recipient == exchange
92 | assert_fail(lambda: HAY_exchange.tokenToEthTransferOutput(ETH_BOUGHT, MAX_HAY_SOLD, DEADLINE, HAY_exchange.address, transact={'from': a1}))
93 | # BUYER converts ETH to UNI
94 | HAY_exchange.tokenToEthTransferOutput(ETH_BOUGHT, MAX_HAY_SOLD, DEADLINE, a2, transact={'from': a1})
95 | # Updated balances of UNI exchange
96 | assert w3.eth.getBalance(HAY_exchange.address) == ETH_RESERVE - ETH_BOUGHT
97 | assert HAY_token.balanceOf(HAY_exchange.address) == HAY_RESERVE + HAY_COST
98 | # Updated balances of BUYER
99 | assert HAY_token.balanceOf(a1) == MAX_HAY_SOLD - HAY_COST
100 | assert w3.eth.getBalance(a1) == INITIAL_ETH
101 | # Updated balances of RECIPIENT
102 | assert HAY_token.balanceOf(a2) == 0
103 | assert w3.eth.getBalance(a2) == INITIAL_ETH + ETH_BOUGHT
104 |
--------------------------------------------------------------------------------
/tests/exchange/test_token_to_exchange.py:
--------------------------------------------------------------------------------
1 | from tests.constants import (
2 | ETH_RESERVE,
3 | HAY_RESERVE,
4 | DEN_RESERVE,
5 | HAY_SOLD,
6 | MIN_ETH_BOUGHT,
7 | MIN_DEN_BOUGHT,
8 | DEN_BOUGHT,
9 | MAX_HAY_SOLD,
10 | MAX_ETH_SOLD,
11 | INITIAL_ETH,
12 | DEADLINE,
13 | )
14 |
15 | def test_swap_input(w3, HAY_token, DEN_token, HAY_exchange, DEN_exchange, swap_input):
16 | a0, a1, a2 = w3.eth.accounts[:3]
17 | ETH_PURCHASED = swap_input(HAY_SOLD, HAY_RESERVE, ETH_RESERVE)
18 | DEN_PURCHASED = swap_input(ETH_PURCHASED, ETH_RESERVE, DEN_RESERVE)
19 | # Transfer HAY to BUYER
20 | HAY_token.transfer(a1, HAY_SOLD, transact={})
21 | HAY_token.approve(HAY_exchange.address, HAY_SOLD, transact={'from': a1})
22 | assert HAY_token.balanceOf(a1) == HAY_SOLD
23 | # BUYER converts ETH to UNI
24 | HAY_exchange.tokenToExchangeSwapInput(HAY_SOLD, MIN_DEN_BOUGHT, MIN_ETH_BOUGHT, DEADLINE, DEN_exchange.address, transact={'from': a1})
25 | # Updated balances of UNI exchange
26 | assert w3.eth.getBalance(HAY_exchange.address) == ETH_RESERVE - ETH_PURCHASED
27 | assert HAY_token.balanceOf(HAY_exchange.address) == HAY_RESERVE + HAY_SOLD
28 | # Updated balances of SWAP exchange
29 | assert w3.eth.getBalance(DEN_exchange.address) == ETH_RESERVE + ETH_PURCHASED
30 | assert DEN_token.balanceOf(DEN_exchange.address) == DEN_RESERVE - DEN_PURCHASED
31 | # Updated balances of BUYER
32 | assert HAY_token.balanceOf(a1) == 0
33 | assert DEN_token.balanceOf(a1) == DEN_PURCHASED
34 | assert w3.eth.getBalance(a1) == INITIAL_ETH
35 |
36 | def test_transfer_input(w3, HAY_token, DEN_token, HAY_exchange, DEN_exchange, swap_input):
37 | a0, a1, a2 = w3.eth.accounts[:3]
38 | ETH_PURCHASED = swap_input(HAY_SOLD, HAY_RESERVE, ETH_RESERVE)
39 | DEN_PURCHASED = swap_input(ETH_PURCHASED, ETH_RESERVE, DEN_RESERVE)
40 | # Transfer HAY to BUYER
41 | HAY_token.transfer(a1, HAY_SOLD, transact={})
42 | HAY_token.approve(HAY_exchange.address, HAY_SOLD, transact={'from': a1})
43 | assert HAY_token.balanceOf(a1) == HAY_SOLD
44 | # BUYER converts ETH to UNI
45 | HAY_exchange.tokenToExchangeTransferInput(HAY_SOLD, MIN_DEN_BOUGHT, MIN_ETH_BOUGHT, DEADLINE, a2, DEN_exchange.address, transact={'from': a1})
46 | # Updated balances of UNI exchange
47 | assert w3.eth.getBalance(HAY_exchange.address) == ETH_RESERVE - ETH_PURCHASED
48 | assert HAY_token.balanceOf(HAY_exchange.address) == HAY_RESERVE + HAY_SOLD
49 | # Updated balances of SWAP exchange
50 | assert w3.eth.getBalance(DEN_exchange.address) == ETH_RESERVE + ETH_PURCHASED
51 | assert DEN_token.balanceOf(DEN_exchange.address) == DEN_RESERVE - DEN_PURCHASED
52 | # Updated balances of BUYER
53 | assert HAY_token.balanceOf(a1) == 0
54 | assert DEN_token.balanceOf(a1) == 0
55 | assert w3.eth.getBalance(a1) == INITIAL_ETH
56 | # Updated balances of RECIPIENT
57 | assert HAY_token.balanceOf(a2) == 0
58 | assert DEN_token.balanceOf(a2) == DEN_PURCHASED
59 | assert w3.eth.getBalance(a2) == INITIAL_ETH
60 |
61 | def test_swap_output(w3, HAY_token, DEN_token, HAY_exchange, DEN_exchange, swap_output):
62 | a0, a1, a2 = w3.eth.accounts[:3]
63 | ETH_COST = swap_output(DEN_BOUGHT, ETH_RESERVE, DEN_RESERVE)
64 | HAY_COST = swap_output(ETH_COST, HAY_RESERVE, ETH_RESERVE)
65 | # Transfer HAY to BUYER
66 | HAY_token.transfer(a1, MAX_HAY_SOLD, transact={})
67 | HAY_token.approve(HAY_exchange.address, MAX_HAY_SOLD, transact={'from': a1})
68 | assert HAY_token.balanceOf(a1) == MAX_HAY_SOLD
69 | # BUYER converts ETH to UNI
70 | HAY_exchange.tokenToExchangeSwapOutput(DEN_BOUGHT, MAX_HAY_SOLD, MAX_ETH_SOLD, DEADLINE, DEN_exchange.address, transact={'from': a1})
71 | # Updated balances of UNI exchange
72 | assert w3.eth.getBalance(HAY_exchange.address) == ETH_RESERVE - ETH_COST
73 | assert HAY_token.balanceOf(HAY_exchange.address) == HAY_RESERVE + HAY_COST
74 | # Updated balances of SWAP exchange
75 | assert w3.eth.getBalance(DEN_exchange.address) == ETH_RESERVE + ETH_COST
76 | assert DEN_token.balanceOf(DEN_exchange.address) == DEN_RESERVE - DEN_BOUGHT
77 | # Updated balances of BUYER
78 | assert HAY_token.balanceOf(a1) == MAX_HAY_SOLD - HAY_COST
79 | assert DEN_token.balanceOf(a1) == DEN_BOUGHT
80 | assert w3.eth.getBalance(a1) == INITIAL_ETH
81 |
82 | def test_transfer_output(w3, HAY_token, DEN_token, HAY_exchange, DEN_exchange, swap_output):
83 | a0, a1, a2 = w3.eth.accounts[:3]
84 | ETH_COST = swap_output(DEN_BOUGHT, ETH_RESERVE, DEN_RESERVE)
85 | HAY_COST = swap_output(ETH_COST, HAY_RESERVE, ETH_RESERVE)
86 | # Transfer HAY to BUYER
87 | HAY_token.transfer(a1, MAX_HAY_SOLD, transact={})
88 | HAY_token.approve(HAY_exchange.address, MAX_HAY_SOLD, transact={'from': a1})
89 | assert HAY_token.balanceOf(a1) == MAX_HAY_SOLD
90 | # BUYER converts ETH to UNI
91 | HAY_exchange.tokenToExchangeTransferOutput(DEN_BOUGHT, MAX_HAY_SOLD, MAX_ETH_SOLD, DEADLINE, a2, DEN_exchange.address, transact={'from': a1})
92 | # Updated balances of UNI exchange
93 | assert w3.eth.getBalance(HAY_exchange.address) == ETH_RESERVE - ETH_COST
94 | assert HAY_token.balanceOf(HAY_exchange.address) == HAY_RESERVE + HAY_COST
95 | # Updated balances of SWAP exchange
96 | assert w3.eth.getBalance(DEN_exchange.address) == ETH_RESERVE + ETH_COST
97 | assert DEN_token.balanceOf(DEN_exchange.address) == DEN_RESERVE - DEN_BOUGHT
98 | # Updated balances of BUYER
99 | assert HAY_token.balanceOf(a1) == MAX_HAY_SOLD - HAY_COST
100 | assert DEN_token.balanceOf(a1) == 0
101 | assert w3.eth.getBalance(a1) == INITIAL_ETH
102 | # Updated balances of RECIPIENT
103 | assert HAY_token.balanceOf(a2) == 0
104 | assert DEN_token.balanceOf(a2) == DEN_BOUGHT
105 | assert w3.eth.getBalance(a2) == INITIAL_ETH
106 |
--------------------------------------------------------------------------------
/tests/exchange/test_token_to_token.py:
--------------------------------------------------------------------------------
1 | from tests.constants import (
2 | ETH_RESERVE,
3 | HAY_RESERVE,
4 | DEN_RESERVE,
5 | HAY_SOLD,
6 | MIN_ETH_BOUGHT,
7 | MIN_DEN_BOUGHT,
8 | DEN_BOUGHT,
9 | MAX_HAY_SOLD,
10 | MAX_ETH_SOLD,
11 | INITIAL_ETH,
12 | DEADLINE,
13 | ZERO_ADDR,
14 | )
15 |
16 | def test_swap_input(w3, HAY_token, DEN_token, HAY_exchange, DEN_exchange, swap_input, assert_fail):
17 | a0, a1, a2 = w3.eth.accounts[:3]
18 | ETH_PURCHASED = swap_input(HAY_SOLD, HAY_RESERVE, ETH_RESERVE)
19 | DEN_PURCHASED = swap_input(ETH_PURCHASED, ETH_RESERVE, DEN_RESERVE)
20 | # Transfer HAY to BUYER
21 | HAY_token.transfer(a1, HAY_SOLD, transact={})
22 | HAY_token.approve(HAY_exchange.address, HAY_SOLD, transact={'from': a1})
23 | assert HAY_token.balanceOf(a1) == HAY_SOLD
24 | # tokens sold == 0
25 | assert_fail(lambda: HAY_exchange.tokenToTokenSwapInput(0, MIN_DEN_BOUGHT, MIN_ETH_BOUGHT, DEADLINE, DEN_token.address, transact={'from': a1}))
26 | # min tokens bought == 0
27 | assert_fail(lambda: HAY_exchange.tokenToTokenSwapInput(HAY_SOLD, 0, MIN_ETH_BOUGHT, DEADLINE, DEN_token.address, transact={'from': a1}))
28 | # min tokens bought > tokens bought
29 | assert_fail(lambda: HAY_exchange.tokenToTokenSwapInput(HAY_SOLD, DEN_PURCHASED + 1, MIN_ETH_BOUGHT, DEADLINE, DEN_token.address, transact={'from': a1}))
30 | # min eth bought == 0
31 | assert_fail(lambda: HAY_exchange.tokenToTokenSwapInput(HAY_SOLD, MIN_DEN_BOUGHT, 0, DEADLINE, DEN_token.address, transact={'from': a1}))
32 | # min eth bought > eth bought
33 | assert_fail(lambda: HAY_exchange.tokenToTokenSwapInput(HAY_SOLD, MIN_DEN_BOUGHT, ETH_PURCHASED + 1, DEADLINE, DEN_token.address, transact={'from': a1}))
34 | # deadline < block.timestamp
35 | assert_fail(lambda: HAY_exchange.tokenToTokenSwapInput(HAY_SOLD, MIN_DEN_BOUGHT, MIN_ETH_BOUGHT, 1, DEN_token.address, transact={'from': a1}))
36 | # output token == input token
37 | assert_fail(lambda: HAY_exchange.tokenToTokenSwapInput(HAY_SOLD, MIN_DEN_BOUGHT, MIN_ETH_BOUGHT, DEADLINE, HAY_token.address, transact={'from': a1}))
38 | # output token == input exchange
39 | assert_fail(lambda: HAY_exchange.tokenToTokenSwapInput(HAY_SOLD, MIN_DEN_BOUGHT, MIN_ETH_BOUGHT, DEADLINE, HAY_exchange.address, transact={'from': a1}))
40 | # output token == ZERO_ADDR
41 | assert_fail(lambda: HAY_exchange.tokenToTokenSwapInput(HAY_SOLD, MIN_DEN_BOUGHT, MIN_ETH_BOUGHT, DEADLINE, ZERO_ADDR, transact={'from': a1}))
42 | # BUYER converts ETH to UNI
43 | HAY_exchange.tokenToTokenSwapInput(HAY_SOLD, MIN_DEN_BOUGHT, MIN_ETH_BOUGHT, DEADLINE, DEN_token.address, transact={'from': a1})
44 | # Updated balances of UNI exchange
45 | assert w3.eth.getBalance(HAY_exchange.address) == ETH_RESERVE - ETH_PURCHASED
46 | assert HAY_token.balanceOf(HAY_exchange.address) == HAY_RESERVE + HAY_SOLD
47 | # Updated balances of SWAP exchange
48 | assert w3.eth.getBalance(DEN_exchange.address) == ETH_RESERVE + ETH_PURCHASED
49 | assert DEN_token.balanceOf(DEN_exchange.address) == DEN_RESERVE - DEN_PURCHASED
50 | # Updated balances of BUYER
51 | assert HAY_token.balanceOf(a1) == 0
52 | assert DEN_token.balanceOf(a1) == DEN_PURCHASED
53 | assert w3.eth.getBalance(a1) == INITIAL_ETH
54 |
55 | def test_transfer_input(w3, HAY_token, DEN_token, HAY_exchange, DEN_exchange, swap_input, assert_fail):
56 | a0, a1, a2 = w3.eth.accounts[:3]
57 | ETH_PURCHASED = swap_input(HAY_SOLD, HAY_RESERVE, ETH_RESERVE)
58 | DEN_PURCHASED = swap_input(ETH_PURCHASED, ETH_RESERVE, DEN_RESERVE)
59 | # Transfer HAY to BUYER
60 | HAY_token.transfer(a1, HAY_SOLD, transact={})
61 | HAY_token.approve(HAY_exchange.address, HAY_SOLD, transact={'from': a1})
62 | assert HAY_token.balanceOf(a1) == HAY_SOLD
63 | # recipient == ZERO_ADDR
64 | assert_fail(lambda: HAY_exchange.tokenToTokenTransferInput(HAY_SOLD, MIN_DEN_BOUGHT, MIN_ETH_BOUGHT, DEADLINE, ZERO_ADDR, DEN_token.address, transact={'from': a1}))
65 | # recipient == output exchange
66 | assert_fail(lambda: HAY_exchange.tokenToTokenTransferInput(HAY_SOLD, MIN_DEN_BOUGHT, MIN_ETH_BOUGHT, DEADLINE, DEN_exchange.address, DEN_token.address, transact={'from': a1}))
67 | # BUYER converts ETH to UNI
68 | HAY_exchange.tokenToTokenTransferInput(HAY_SOLD, MIN_DEN_BOUGHT, MIN_ETH_BOUGHT, DEADLINE, a2, DEN_token.address, transact={'from': a1})
69 | # Updated balances of UNI exchange
70 | assert w3.eth.getBalance(HAY_exchange.address) == ETH_RESERVE - ETH_PURCHASED
71 | assert HAY_token.balanceOf(HAY_exchange.address) == HAY_RESERVE + HAY_SOLD
72 | # Updated balances of SWAP exchange
73 | assert w3.eth.getBalance(DEN_exchange.address) == ETH_RESERVE + ETH_PURCHASED
74 | assert DEN_token.balanceOf(DEN_exchange.address) == DEN_RESERVE - DEN_PURCHASED
75 | # Updated balances of BUYER
76 | assert HAY_token.balanceOf(a1) == 0
77 | assert DEN_token.balanceOf(a1) == 0
78 | assert w3.eth.getBalance(a1) == INITIAL_ETH
79 | # Updated balances of RECIPIENT
80 | assert HAY_token.balanceOf(a2) == 0
81 | assert DEN_token.balanceOf(a2) == DEN_PURCHASED
82 | assert w3.eth.getBalance(a2) == INITIAL_ETH
83 |
84 | def test_swap_output(w3, HAY_token, DEN_token, HAY_exchange, DEN_exchange, swap_output, assert_fail):
85 | a0, a1, a2 = w3.eth.accounts[:3]
86 | ETH_COST = swap_output(DEN_BOUGHT, ETH_RESERVE, DEN_RESERVE)
87 | HAY_COST = swap_output(ETH_COST, HAY_RESERVE, ETH_RESERVE)
88 | # Transfer HAY to BUYER
89 | HAY_token.transfer(a1, MAX_HAY_SOLD, transact={})
90 | HAY_token.approve(HAY_exchange.address, MAX_HAY_SOLD, transact={'from': a1})
91 | assert HAY_token.balanceOf(a1) == MAX_HAY_SOLD
92 | # tokens bought == 0
93 | assert_fail(lambda: HAY_exchange.tokenToTokenSwapOutput(0, MAX_HAY_SOLD, MAX_ETH_SOLD, DEADLINE, DEN_token.address, transact={'from': a1}))
94 | # max tokens < token cost
95 | assert_fail(lambda: HAY_exchange.tokenToTokenSwapOutput(DEN_BOUGHT, HAY_COST - 1, MAX_ETH_SOLD, DEADLINE, DEN_token.address, transact={'from': a1}))
96 | # max eth < token cost
97 | assert_fail(lambda: HAY_exchange.tokenToTokenSwapOutput(DEN_BOUGHT, MAX_HAY_SOLD, ETH_COST - 1, DEADLINE, DEN_token.address, transact={'from': a1}))
98 | # deadline < block.timestamp
99 | assert_fail(lambda: HAY_exchange.tokenToTokenSwapOutput(DEN_BOUGHT, MAX_HAY_SOLD, MAX_ETH_SOLD, 1, DEN_token.address, transact={'from': a1}))
100 | # output token == input token
101 | assert_fail(lambda: HAY_exchange.tokenToTokenSwapOutput(DEN_BOUGHT, MAX_HAY_SOLD, MAX_ETH_SOLD, DEADLINE, HAY_token.address, transact={'from': a1}))
102 | # output token == input exchange
103 | assert_fail(lambda: HAY_exchange.tokenToTokenSwapOutput(DEN_BOUGHT, MAX_HAY_SOLD, MAX_ETH_SOLD, DEADLINE, HAY_exchange.address, transact={'from': a1}))
104 | # output token == ZERO_ADDR
105 | assert_fail(lambda: HAY_exchange.tokenToTokenSwapOutput(DEN_BOUGHT, MAX_HAY_SOLD, MAX_ETH_SOLD, DEADLINE, ZERO_ADDR, transact={'from': a1}))
106 | # BUYER converts ETH to UNI
107 | HAY_exchange.tokenToTokenSwapOutput(DEN_BOUGHT, MAX_HAY_SOLD, MAX_ETH_SOLD, DEADLINE, DEN_token.address, transact={'from': a1})
108 | # Updated balances of UNI exchange
109 | assert w3.eth.getBalance(HAY_exchange.address) == ETH_RESERVE - ETH_COST
110 | assert HAY_token.balanceOf(HAY_exchange.address) == HAY_RESERVE + HAY_COST
111 | # Updated balances of SWAP exchange
112 | assert w3.eth.getBalance(DEN_exchange.address) == ETH_RESERVE + ETH_COST
113 | assert DEN_token.balanceOf(DEN_exchange.address) == DEN_RESERVE - DEN_BOUGHT
114 | # Updated balances of BUYER
115 | assert HAY_token.balanceOf(a1) == MAX_HAY_SOLD - HAY_COST
116 | assert DEN_token.balanceOf(a1) == DEN_BOUGHT
117 | assert w3.eth.getBalance(a1) == INITIAL_ETH
118 |
119 | def test_transfer_output(w3, HAY_token, DEN_token, HAY_exchange, DEN_exchange, swap_output, assert_fail):
120 | a0, a1, a2 = w3.eth.accounts[:3]
121 | ETH_COST = swap_output(DEN_BOUGHT, ETH_RESERVE, DEN_RESERVE)
122 | HAY_COST = swap_output(ETH_COST, HAY_RESERVE, ETH_RESERVE)
123 | # Transfer HAY to BUYER
124 | HAY_token.transfer(a1, MAX_HAY_SOLD, transact={})
125 | HAY_token.approve(HAY_exchange.address, MAX_HAY_SOLD, transact={'from': a1})
126 | assert HAY_token.balanceOf(a1) == MAX_HAY_SOLD
127 | # recipient == ZERO_ADDR
128 | assert_fail(lambda: HAY_exchange.tokenToTokenTransferOutput(DEN_BOUGHT, MAX_HAY_SOLD, MAX_ETH_SOLD, DEADLINE, ZERO_ADDR, DEN_token.address, transact={'from': a1}))
129 | # recipient == output exchange
130 | assert_fail(lambda: HAY_exchange.tokenToTokenTransferOutput(DEN_BOUGHT, MAX_HAY_SOLD, MAX_ETH_SOLD, DEADLINE, DEN_exchange.address, DEN_token.address, transact={'from': a1}))
131 | # BUYER converts ETH to UNI
132 | HAY_exchange.tokenToTokenTransferOutput(DEN_BOUGHT, MAX_HAY_SOLD, MAX_ETH_SOLD, DEADLINE, a2, DEN_token.address, transact={'from': a1})
133 | # Updated balances of UNI exchange
134 | assert w3.eth.getBalance(HAY_exchange.address) == ETH_RESERVE - ETH_COST
135 | assert HAY_token.balanceOf(HAY_exchange.address) == HAY_RESERVE + HAY_COST
136 | # Updated balances of SWAP exchange
137 | assert w3.eth.getBalance(DEN_exchange.address) == ETH_RESERVE + ETH_COST
138 | assert DEN_token.balanceOf(DEN_exchange.address) == DEN_RESERVE - DEN_BOUGHT
139 | # Updated balances of BUYER
140 | assert HAY_token.balanceOf(a1) == MAX_HAY_SOLD - HAY_COST
141 | assert DEN_token.balanceOf(a1) == 0
142 | assert w3.eth.getBalance(a1) == INITIAL_ETH
143 | # Updated balances of RECIPIENT
144 | assert HAY_token.balanceOf(a2) == 0
145 | assert DEN_token.balanceOf(a2) == DEN_BOUGHT
146 | assert w3.eth.getBalance(a2) == INITIAL_ETH
147 |
--------------------------------------------------------------------------------