From ac84b36144f746662e5ddb984d283e053c7d06ba Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 5 Jul 2017 12:28:15 +0200 Subject: Added various contracts for testing. --- test/compilationTests/corion/LICENSE | 674 +++++++++++++++++ test/compilationTests/corion/README.md | 3 + test/compilationTests/corion/announcementTypes.sol | 35 + test/compilationTests/corion/ico.sol | 376 ++++++++++ test/compilationTests/corion/module.sol | 143 ++++ test/compilationTests/corion/moduleHandler.sol | 448 ++++++++++++ test/compilationTests/corion/multiOwner.sol | 83 +++ test/compilationTests/corion/owned.sol | 28 + test/compilationTests/corion/premium.sol | 346 +++++++++ test/compilationTests/corion/provider.sol | 797 +++++++++++++++++++++ test/compilationTests/corion/publisher.sol | 278 +++++++ test/compilationTests/corion/safeMath.sol | 33 + test/compilationTests/corion/schelling.sol | 577 +++++++++++++++ test/compilationTests/corion/token.sol | 518 +++++++++++++ test/compilationTests/corion/tokenDB.sol | 77 ++ 15 files changed, 4416 insertions(+) create mode 100644 test/compilationTests/corion/LICENSE create mode 100644 test/compilationTests/corion/README.md create mode 100644 test/compilationTests/corion/announcementTypes.sol create mode 100644 test/compilationTests/corion/ico.sol create mode 100644 test/compilationTests/corion/module.sol create mode 100644 test/compilationTests/corion/moduleHandler.sol create mode 100644 test/compilationTests/corion/multiOwner.sol create mode 100644 test/compilationTests/corion/owned.sol create mode 100644 test/compilationTests/corion/premium.sol create mode 100644 test/compilationTests/corion/provider.sol create mode 100644 test/compilationTests/corion/publisher.sol create mode 100644 test/compilationTests/corion/safeMath.sol create mode 100644 test/compilationTests/corion/schelling.sol create mode 100644 test/compilationTests/corion/token.sol create mode 100644 test/compilationTests/corion/tokenDB.sol (limited to 'test/compilationTests/corion') diff --git a/test/compilationTests/corion/LICENSE b/test/compilationTests/corion/LICENSE new file mode 100644 index 00000000..9cecc1d4 --- /dev/null +++ b/test/compilationTests/corion/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + {one line to give the program's name and a brief idea of what it does.} + Copyright (C) {year} {name of author} + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + {project} Copyright (C) {year} {fullname} + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/test/compilationTests/corion/README.md b/test/compilationTests/corion/README.md new file mode 100644 index 00000000..f0bb8ea8 --- /dev/null +++ b/test/compilationTests/corion/README.md @@ -0,0 +1,3 @@ +CORION contracts, originally from + +https://github.com/CORIONplatform/solidity diff --git a/test/compilationTests/corion/announcementTypes.sol b/test/compilationTests/corion/announcementTypes.sol new file mode 100644 index 00000000..f31d580e --- /dev/null +++ b/test/compilationTests/corion/announcementTypes.sol @@ -0,0 +1,35 @@ +pragma solidity ^0.4.11; + +contract announcementTypes { + + enum announcementType { + /* + type of announcements + */ + newModule, + dropModule, + replaceModule, + replaceModuleHandler, + question, + transactionFeeRate, + transactionFeeMin, + transactionFeeMax, + transactionFeeBurn, + providerPublicFunds, + providerPrivateFunds, + providerPrivateClientLimit, + providerPublicMinRate, + providerPublicMaxRate, + providerPrivateMinRate, + providerPrivateMaxRate, + providerGasProtect, + providerInterestMinFunds, + providerRentRate, + schellingRoundBlockDelay, + schellingCheckRounds, + schellingCheckAboves, + schellingRate, + publisherMinAnnouncementDelay, + publisherOppositeRate + } +} \ No newline at end of file diff --git a/test/compilationTests/corion/ico.sol b/test/compilationTests/corion/ico.sol new file mode 100644 index 00000000..6c9f8cb2 --- /dev/null +++ b/test/compilationTests/corion/ico.sol @@ -0,0 +1,376 @@ +pragma solidity ^0.4.11; + +import "./safeMath.sol"; +import "./token.sol"; +import "./premium.sol"; +import "./moduleHandler.sol"; + +contract ico is safeMath { + + struct icoLevels_s { + uint256 block; + uint8 rate; + } + struct affiliate_s { + uint256 weight; + uint256 paid; + } + struct interest_s { + uint256 amount; + bool empty; + } + struct brought_s { + uint256 eth; + uint256 cor; + uint256 corp; + } + + uint256 constant oneSegment = 40320; + + address public owner; + address public tokenAddr; + address public premiumAddr; + uint256 public startBlock; + uint256 public icoDelay; + address public foundationAddress; + address public icoEtcPriceAddr; + uint256 public icoExchangeRate; + uint256 public icoExchangeRateSetBlock; + uint256 constant icoExchangeRateM = 1e4; + uint256 constant interestOnICO = 25; + uint256 constant interestOnICOM = 1e3; + uint256 constant interestBlockDelay = 720; + uint256 constant exchangeRateDelay = 125; + bool public aborted; + bool public closed; + icoLevels_s[] public icoLevels; + mapping (address => affiliate_s) public affiliate; + mapping (address => brought_s) public brought; + mapping (address => mapping(uint256 => interest_s)) public interestDB; + uint256 public totalMint; + uint256 public totalPremiumMint; + + function ico(address foundation, address priceSet, uint256 exchangeRate, uint256 startBlockNum, address[] genesisAddr, uint256[] genesisValue) { + /* + Installation function. + + @foundation The ETC address of the foundation + @priceSet The address which will be able to make changes on the rate later on. + @exchangeRate The current ETC/USD rate multiplied by 1e4. For example: 2.5 USD/ETC = 25000 + @startBlockNum The height (level) of the beginning of the ICO. If it is 0 then it will be the current array’s height. + @genesisAddr Array of Genesis addresses + @genesisValue Array of balance of genesis addresses + */ + foundationAddress = foundation; + icoExchangeRate = exchangeRate; + icoExchangeRateSetBlock = block.number + exchangeRateDelay; + icoEtcPriceAddr = priceSet; + owner = msg.sender; + if ( startBlockNum > 0 ) { + require( startBlockNum >= block.number ); + startBlock = startBlockNum; + } else { + startBlock = block.number; + } + icoLevels.push(icoLevels_s(startBlock + oneSegment * 1, 3)); + icoLevels.push(icoLevels_s(startBlock + oneSegment / 7, 5)); + icoLevels.push(icoLevels_s(startBlock, 10)); + icoDelay = startBlock + oneSegment * 3; + for ( uint256 a=0 ; a icoLevels[a].block ) { + return icoLevels[a].rate; + } + } + } + + function setInterestDB(address addr, uint256 balance) external returns(bool success) { + /* + Setting interest database. It can be requested by Token contract only. + A database has to be built in order that after ICO closed everybody can get their compound interest on their capital accumulated + + @addr Sender + @balance Quantity + + @success Was the process successful or not + */ + require( msg.sender == tokenAddr ); + uint256 _num = (block.number - startBlock) / interestBlockDelay; + interestDB[addr][_num].amount = balance; + if ( balance == 0 ) { + interestDB[addr][_num].empty = true; + } + return true; + } + + function checkInterest(address addr) public constant returns(uint256 amount) { + /* + Query of compound interest + + @addr Address + + @amount Amount of compound interest + */ + uint256 _lastBal; + uint256 _tamount; + bool _empty; + interest_s memory _idb; + uint256 _to = (block.number - startBlock) / interestBlockDelay; + + if ( _to == 0 || aborted ) { return 0; } + + for ( uint256 r=0 ; r < _to ; r++ ) { + if ( r*interestBlockDelay+startBlock >= icoDelay ) { break; } + _idb = interestDB[addr][r]; + if ( _idb.amount > 0 ) { + if ( _empty ) { + _lastBal = _idb.amount + amount; + } else { + _lastBal = _idb.amount; + } + } + if ( _idb.empty ) { + _lastBal = 0; + _empty = _idb.empty; + } + _lastBal += _tamount; + _tamount = _lastBal * interestOnICO / interestOnICOM / 100; + amount += _tamount; + } + } + + function getInterest(address beneficiary) external { + /* + Request of compound interest. This is deleted from the database after the ICO closed and following the query of the compound interest. + + @beneficiary Beneficiary who will receive the interest + */ + uint256 _lastBal; + uint256 _tamount; + uint256 _amount; + bool _empty; + interest_s memory _idb; + address _addr = beneficiary; + uint256 _to = (block.number - startBlock) / interestBlockDelay; + if ( _addr == 0x00 ) { _addr = msg.sender; } + + require( block.number > icoDelay ); + require( ! aborted ); + + for ( uint256 r=0 ; r < _to ; r++ ) { + if ( r*interestBlockDelay+startBlock >= icoDelay ) { break; } + _idb = interestDB[msg.sender][r]; + if ( _idb.amount > 0 ) { + if ( _empty ) { + _lastBal = _idb.amount + _amount; + } else { + _lastBal = _idb.amount; + } + } + if ( _idb.empty ) { + _lastBal = 0; + _empty = _idb.empty; + } + _lastBal += _tamount; + _tamount = _lastBal * interestOnICO / interestOnICOM / 100; + _amount += _tamount; + delete interestDB[msg.sender][r]; + } + + require( _amount > 0 ); + token(tokenAddr).mint(_addr, _amount); + } + + function setICOEthPrice(uint256 value) external { + /* + Setting of the ICO ETC USD rates which can only be calle by a pre-defined address. + After this function is completed till the call of the next function (which is at least an exchangeRateDelay array) this rate counts. + With this process avoiding the sudden rate changes. + + @value The ETC/USD rate multiplied by 1e4. For example: 2.5 USD/ETC = 25000 + */ + require( isICO() ); + require( icoEtcPriceAddr == msg.sender ); + require( icoExchangeRateSetBlock < block.number); + icoExchangeRateSetBlock = block.number + exchangeRateDelay; + icoExchangeRate = value; + } + + function extendICO() external { + /* + Extend the period of the ICO with one segment. + + It is only possible during the ICO and only callable by the owner. + */ + require( isICO() ); + require( msg.sender == owner ); + icoDelay += oneSegment; + } + + function closeICO() external { + /* + Closing the ICO. + It is only possible when the ICO period passed and only by the owner. + The 96% of the whole amount of the token is generated to the address of the fundation. + Ethers which are situated in this contract will be sent to the address of the fundation. + */ + require( msg.sender == owner ); + require( block.number > icoDelay ); + require( ! closed ); + closed = true; + require( ! aborted ); + require( token(tokenAddr).mint(foundationAddress, token(tokenAddr).totalSupply() * 96 / 100) ); + require( premium(premiumAddr).mint(foundationAddress, totalMint / 5000 - totalPremiumMint) ); + require( foundationAddress.send(this.balance) ); + require( token(tokenAddr).closeIco() ); + require( premium(premiumAddr).closeIco() ); + } + + function abortICO() external { + /* + Withdrawal of the ICO. + It is only possible during the ICO period. + Only callable by the owner. + After this process only the receiveFunds function will be available for the customers. + */ + require( isICO() ); + require( msg.sender == owner ); + aborted = true; + } + + function connectTokens(address tokenContractAddr, address premiumContractAddr) external { + /* + Installation function which joins the two token contracts with this contract. + Only callable by the owner + + @tokenContractAddr Address of the corion token contract. + @premiumContractAddr Address of the corion premium token contract + */ + require( msg.sender == owner ); + require( tokenAddr == 0x00 && premiumAddr == 0x00 ); + tokenAddr = tokenContractAddr; + premiumAddr = premiumContractAddr; + } + + function receiveFunds() external { + /* + Refund the amount which was purchased during the ICO period. + This one is only callable if the ICO is withdrawn. + In this case the address gets back the 90% of the amount which was spent for token during the ICO period. + */ + require( aborted ); + require( brought[msg.sender].eth > 0 ); + uint256 _val = brought[msg.sender].eth * 90 / 100; + delete brought[msg.sender]; + require( msg.sender.send(_val) ); + } + + function () payable { + /* + Callback function. Simply calls the buy function as a beneficiary and there is no affilate address. + If they call the contract without any function then this process will be taken place. + */ + require( isICO() ); + require( buy(msg.sender, 0x00) ); + } + + function buy(address beneficiaryAddress, address affilateAddress) payable returns (bool success) { + /* + Buying a token + + If there is not at least 0.2 ether balance on the beneficiaryAddress then the amount of the ether which was intended for the purchase will be reduced by 0.2 and that will be sent to the address of the beneficiary. + From the remaining amount calculate the reward with the help of the getIcoReward function. + Only that affilate address is valid which has some token on it’s account. + If there is a valid affilate address then calculate and credit the reward as well in the following way: + With more than 1e12 token contract credit 5% reward based on the calculation that how many tokens did they buy when he was added as an affilate. + More than 1e11 token: 4% + More than 1e10 token: 3% + More than 1e9 token: 2% below 1% + @beneficiaryAddress The address of the accredited where the token will be sent. + @affilateAddress The address of the person who offered who will get the referral reward. It can not be equal with the beneficiaryAddress. + */ + require( isICO() ); + if ( beneficiaryAddress == 0x00) { beneficiaryAddress = msg.sender; } + if ( beneficiaryAddress == affilateAddress ) { + affilateAddress = 0x00; + } + uint256 _value = msg.value; + if ( beneficiaryAddress.balance < 0.2 ether ) { + require( beneficiaryAddress.send(0.2 ether) ); + _value = safeSub(_value, 0.2 ether); + } + var _reward = getIcoReward(_value); + require( _reward > 0 ); + require( token(tokenAddr).mint(beneficiaryAddress, _reward) ); + brought[beneficiaryAddress].eth = safeAdd(brought[beneficiaryAddress].eth, _value); + brought[beneficiaryAddress].cor = safeAdd(brought[beneficiaryAddress].cor, _reward); + totalMint = safeAdd(totalMint, _reward); + require( foundationAddress.send(_value * 10 / 100) ); + uint256 extra; + if ( affilateAddress != 0x00 && ( brought[affilateAddress].eth > 0 || interestDB[affilateAddress][0].amount > 0 ) ) { + affiliate[affilateAddress].weight = safeAdd(affiliate[affilateAddress].weight, _reward); + extra = affiliate[affilateAddress].weight; + uint256 rate; + if (extra >= 1e12) { + rate = 5; + } else if (extra >= 1e11) { + rate = 4; + } else if (extra >= 1e10) { + rate = 3; + } else if (extra >= 1e9) { + rate = 2; + } else { + rate = 1; + } + extra = safeSub(extra * rate / 100, affiliate[affilateAddress].paid); + affiliate[affilateAddress].paid = safeAdd(affiliate[affilateAddress].paid, extra); + token(tokenAddr).mint(affilateAddress, extra); + } + checkPremium(beneficiaryAddress); + EICO(beneficiaryAddress, _reward, affilateAddress, extra); + return true; + } + + function checkPremium(address owner) internal { + /* + Crediting the premium token + + @owner The corion token balance of this address will be set based on the calculation which shows that how many times can be the amount of the purchased tokens devided by 5000. So after each 5000 token we give 1 premium token. + */ + uint256 _reward = (brought[owner].cor / 5e9) - brought[owner].corp; + if ( _reward > 0 ) { + require( premium(premiumAddr).mint(owner, _reward) ); + brought[owner].corp = safeAdd(brought[owner].corp, _reward); + totalPremiumMint = safeAdd(totalPremiumMint, _reward); + } + } + + function getIcoReward(uint256 value) public constant returns (uint256 reward) { + /* + Expected token volume at token purchase + + @value The amount of ether for the purchase + @reward Amount of the token + x = (value * 1e6 * USD_ETC_exchange rate / 1e4 / 1e18) * bonus percentage + 2.700000 token = (1e18 * 1e6 * 22500 / 1e4 / 1e18) * 1.20 + */ + reward = (value * 1e6 * icoExchangeRate / icoExchangeRateM / 1 ether) * (ICObonus() + 100) / 100; + if ( reward < 5e6) { return 0; } + } + + function isICO() public constant returns (bool success) { + return startBlock <= block.number && block.number <= icoDelay && ( ! aborted ) && ( ! closed ); + } + + event EICO(address indexed Address, uint256 indexed value, address Affilate, uint256 AffilateValue); +} diff --git a/test/compilationTests/corion/module.sol b/test/compilationTests/corion/module.sol new file mode 100644 index 00000000..d64044cb --- /dev/null +++ b/test/compilationTests/corion/module.sol @@ -0,0 +1,143 @@ +pragma solidity ^0.4.11; + +contract abstractModuleHandler { + function transfer(address from, address to, uint256 value, bool fee) external returns (bool success) {} + function balanceOf(address owner) public constant returns (bool success, uint256 value) {} +} + +contract module { + /* + Module + */ + + enum status { + New, + Connected, + Disconnected, + Disabled + } + + status public moduleStatus; + uint256 public disabledUntil; + address public moduleHandlerAddress; + + function disableModule(bool forever) external onlyForModuleHandler returns (bool success) { + _disableModule(forever); + return true; + } + function _disableModule(bool forever) internal { + /* + Disable the module for one week, if the forever true then for forever. + This function calls the Publisher module. + + @forever For forever or not + */ + if ( forever ) { moduleStatus = status.Disabled; } + else { disabledUntil = block.number + 5760; } + } + + function replaceModuleHandler(address newModuleHandlerAddress) external onlyForModuleHandler returns (bool success) { + _replaceModuleHandler(newModuleHandlerAddress); + return true; + } + function _replaceModuleHandler(address newModuleHandlerAddress) internal { + /* + Replace the ModuleHandler address. + This function calls the Publisher module. + + @newModuleHandlerAddress New module handler address + */ + require( moduleStatus == status.Connected ); + moduleHandlerAddress = newModuleHandlerAddress; + } + + function connectModule() external onlyForModuleHandler returns (bool success) { + _connectModule(); + return true; + } + function _connectModule() internal { + /* + Registering and/or connecting-to ModuleHandler. + This function is called by ModuleHandler load or by Publisher. + */ + require( moduleStatus == status.New ); + moduleStatus = status.Connected; + } + + function disconnectModule() external onlyForModuleHandler returns (bool success) { + _disconnectModule(); + return true; + } + function _disconnectModule() internal { + /* + Disconnect the module from the ModuleHandler. + This function calls the Publisher module. + */ + require( moduleStatus != status.New && moduleStatus != status.Disconnected ); + moduleStatus = status.Disconnected; + } + + function replaceModule(address newModuleAddress) external onlyForModuleHandler returns (bool success) { + _replaceModule(newModuleAddress); + return true; + } + function _replaceModule(address newModuleAddress) internal { + /* + Replace the module for an another new module. + This function calls the Publisher module. + We send every Token and ether to the new module. + + @newModuleAddress New module handler address + */ + require( moduleStatus != status.New && moduleStatus != status.Disconnected); + var (_success, _balance) = abstractModuleHandler(moduleHandlerAddress).balanceOf(address(this)); + require( _success ); + if ( _balance > 0 ) { + require( abstractModuleHandler(moduleHandlerAddress).transfer(address(this), newModuleAddress, _balance, false) ); + } + if ( this.balance > 0 ) { + require( newModuleAddress.send(this.balance) ); + } + moduleStatus = status.Disconnected; + } + + function transferEvent(address from, address to, uint256 value) external onlyForModuleHandler returns (bool success) { + return true; + } + function newSchellingRoundEvent(uint256 roundID, uint256 reward) external onlyForModuleHandler returns (bool success) { + return true; + } + + function registerModuleHandler(address _moduleHandlerAddress) internal { + /* + Module constructor function for registering ModuleHandler address. + */ + moduleHandlerAddress = _moduleHandlerAddress; + } + function isModuleHandler(address addr) internal returns (bool ret) { + /* + Test for ModuleHandler address. + If the module is not connected then returns always false. + + @addr Address to check + + @ret This is the module handler address or not + */ + if ( moduleHandlerAddress == 0x00 ) { return true; } + if ( moduleStatus != status.Connected ) { return false; } + return addr == moduleHandlerAddress; + } + function isActive() public constant returns (bool success, bool active) { + /* + Check self for ready for functions or not. + + @success Function call was successfull or not + @active Ready for functions or not + */ + return (true, moduleStatus == status.Connected && block.number >= disabledUntil); + } + modifier onlyForModuleHandler() { + require( msg.sender == moduleHandlerAddress ); + _; + } +} diff --git a/test/compilationTests/corion/moduleHandler.sol b/test/compilationTests/corion/moduleHandler.sol new file mode 100644 index 00000000..682f81dd --- /dev/null +++ b/test/compilationTests/corion/moduleHandler.sol @@ -0,0 +1,448 @@ +pragma solidity ^0.4.11; + +import "./module.sol"; +import "./announcementTypes.sol"; +import "./multiOwner.sol"; + +import "./publisher.sol"; +import "./token.sol"; +import "./provider.sol"; +import "./schelling.sol"; +import "./premium.sol"; +import "./ico.sol"; + +contract abstractModule { + function connectModule() external returns (bool success) {} + function disconnectModule() external returns (bool success) {} + function replaceModule(address addr) external returns (bool success) {} + function disableModule(bool forever) external returns (bool success) {} + function isActive() public constant returns (bool success) {} + function replaceModuleHandler(address newHandler) external returns (bool success) {} + function transferEvent(address from, address to, uint256 value) external returns (bool success) {} + function newSchellingRoundEvent(uint256 roundID, uint256 reward) external returns (bool success) {} +} + +contract moduleHandler is multiOwner, announcementTypes { + + struct modules_s { + address addr; + bytes32 name; + bool schellingEvent; + bool transferEvent; + } + + modules_s[] public modules; + address public foundationAddress; + uint256 debugModeUntil = block.number + 1000000; + + function moduleHandler(address[] newOwners) multiOwner(newOwners) {} + + function load(address foundation, bool forReplace, address Token, address Premium, address Publisher, address Schelling, address Provider) { + /* + Loading modulest to ModuleHandler. + + This module can be called only once and only by the owner, if every single module and its database are already put on the blockchain. + If forReaplace is true, than the ModuleHandler will be replaced. Before the publishing of its replace, the new contract must be already on the blockchain. + + @foundation Address of foundation. + @forReplace Is it for replace or not. If not, it will be connected to the module. + @Token address of token. + @Publisher address of publisher. + @Schelling address of Schelling. + @Provider address of provider + */ + require( owners[msg.sender] ); + require( modules.length == 0 ); + foundationAddress = foundation; + addModule( modules_s(Token, sha3('Token'), false, false), ! forReplace); + addModule( modules_s(Premium, sha3('Premium'), false, false), ! forReplace); + addModule( modules_s(Publisher, sha3('Publisher'), false, true), ! forReplace); + addModule( modules_s(Schelling, sha3('Schelling'), false, true), ! forReplace); + addModule( modules_s(Provider, sha3('Provider'), true, true), ! forReplace); + } + function addModule(modules_s input, bool call) internal { + /* + Inside function for registration of the modules in the database. + If the call is false, wont happen any direct call. + + @input _Structure of module. + @call Is connect to the module or not. + */ + if ( call ) { require( abstractModule(input.addr).connectModule() ); } + var (success, found, id) = getModuleIDByAddress(input.addr); + require( success && ! found ); + (success, found, id) = getModuleIDByHash(input.name); + require( success && ! found ); + (success, found, id) = getModuleIDByAddress(0x00); + require( success ); + if ( ! found ) { + id = modules.length; + modules.length++; + } + modules[id] = input; + } + function getModuleAddressByName(string name) public constant returns( bool success, bool found, address addr ) { + /* + Search by name for module. The result is an Ethereum address. + + @name Name of module. + @addr Address of module. + @found Is there any result. + @success Was the transaction succesfull or not. + */ + var (_success, _found, _id) = getModuleIDByName(name); + if ( _success && _found ) { return (true, true, modules[_id].addr); } + return (true, false, 0x00); + } + function getModuleIDByHash(bytes32 hashOfName) public constant returns( bool success, bool found, uint256 id ) { + /* + Search by hash of name in the module array. The result is an index array. + + @name Name of module. + @id Index of module. + @found Was there any result or not. + */ + for ( uint256 a=0 ; a bool) public owners; + uint256 public ownerCount; + + mapping(bytes32 => address[]) public doDB; + + /* + Constructor + */ + function multiOwner(address[] newOwners) { + for ( uint256 a=0 ; a 0; + } + /* + Internals + */ + function insertAndCheckDo(bytes32 doHash) internal returns (bool success) { + require( owners[msg.sender] ); + if (doDB[doHash].length >= ownersForChange()) { + delete doDB[doHash]; + return true; + } + for ( uint256 a=0 ; a= ownersForChange() ) { + delete doDB[doHash]; + return true; + } else { + doDB[doHash].push(msg.sender); + return false; + } + } + /* + Privates + */ + function _addOwner(address addr) private { + if ( owners[addr] ) { return; } + owners[addr] = true; + ownerCount = safeAdd(ownerCount, 1); + } + function _delOwner(address addr) private { + if ( ! owners[addr] ) { return; } + delete owners[addr]; + ownerCount = safeSub(ownerCount, 1); + } +} diff --git a/test/compilationTests/corion/owned.sol b/test/compilationTests/corion/owned.sol new file mode 100644 index 00000000..bd187775 --- /dev/null +++ b/test/compilationTests/corion/owned.sol @@ -0,0 +1,28 @@ +pragma solidity ^0.4.11; + +contract ownedDB { + address private owner; + + function replaceOwner(address newOwner) external returns(bool) { + /* + Owner replace. + + @newOwner Address of new owner. + */ + require( isOwner() ); + owner = newOwner; + return true; + } + + function isOwner() internal returns(bool) { + /* + Check of owner address. + + @bool Owner has called the contract or not + */ + if ( owner == 0x00 ) { + return true; + } + return owner == msg.sender; + } +} diff --git a/test/compilationTests/corion/premium.sol b/test/compilationTests/corion/premium.sol new file mode 100644 index 00000000..be2c5de0 --- /dev/null +++ b/test/compilationTests/corion/premium.sol @@ -0,0 +1,346 @@ +pragma solidity ^0.4.11; + +import "./safeMath.sol"; +import "./tokenDB.sol"; +import "./module.sol"; + +contract thirdPartyPContractAbstract { + function receiveCorionPremiumToken(address, uint256, bytes) external returns (bool, uint256) {} + function approvedCorionPremiumToken(address, uint256, bytes) external returns (bool) {} +} + +contract ptokenDB is tokenDB {} + +contract premium is module, safeMath { + function replaceModule(address addr) external returns (bool success) { + require( super.isModuleHandler(msg.sender) ); + require( db.replaceOwner(addr) ); + super._replaceModule(addr); + return true; + } + modifier isReady { + var (_success, _active) = super.isActive(); + require( _success && _active ); + _; + } + /** + * + * @title Corion Platform Premium Token + * @author iFA @ Corion Platform + * + */ + + string public name = "Corion Premium"; + string public symbol = "CORP"; + uint8 public decimals = 0; + + address public icoAddr; + tokenDB public db; + bool public isICO; + + mapping(address => bool) public genesis; + + function premium(bool forReplace, address moduleHandler, address dbAddress, address icoContractAddr, address[] genesisAddr, uint256[] genesisValue) { + /* + Setup function. + If an ICOaddress is defined then the balance of the genesis addresses will be set as well. + + @forReplace This address will be replaced with the old one or not. + @moduleHandler Modulhandler’s address + @dbAddress Address of database + @icoContractAddr Address of ico contract. + @genesisAddr Array of the genesis addresses. + @genesisValue Array of the balance of the genesis addresses + */ + super.registerModuleHandler(moduleHandler); + require( dbAddress != 0x00 ); + db = ptokenDB(dbAddress); + if ( ! forReplace ) { + require( db.replaceOwner(this) ); + isICO = true; + icoAddr = icoContractAddr; + assert( genesisAddr.length == genesisValue.length ); + for ( uint256 a=0 ; a= amount ); + require( db.setAllowance(msg.sender, spender, amount, nonce) ); + Approval(msg.sender, spender, amount); + } + + function allowance(address owner, address spender) constant returns (uint256 remaining, uint256 nonce) { + /* + Get the quantity of tokens given to be used + + @owner Authorising address + @spender Authorised address + + @remaining Tokens to be spent + @nonce Transaction count + */ + var (_success, _remaining, _nonce) = db.getAllowance(owner, spender); + require( _success ); + return (_remaining, _nonce); + } + + /** + * @notice Send `amount` Corion tokens to `to` from `msg.sender` + * @param to The address of the recipient + * @param amount The amount of tokens to be transferred + * @return Whether the transfer was successful or not + */ + function transfer(address to, uint256 amount) isReady external returns (bool success) { + /* + Launch a transaction where the token is sent from the sender’s address to the receiver’s address. + Transaction fee is going to be added as well. + If the receiver is not a natural address but also a person then she/he will be invited as well. + + @to For who + @amount Amount + + @success Was the function successful? + */ + bytes memory _data; + if ( isContract(to) ) { + transferToContract(msg.sender, to, amount, _data); + } else { + _transfer(msg.sender, to, amount); + } + Transfer(msg.sender, to, amount, _data); + return true; + } + + /** + * @notice Send `amount` tokens to `to` from `from` on the condition it is approved by `from` + * @param from The address holding the tokens being transferred + * @param to The address of the recipient + * @param amount The amount of tokens to be transferred + * @return True if the transfer was successful + */ + function transferFrom(address from, address to, uint256 amount) isReady external returns (bool success) { + /* + Launch a transaction where we transfer from a given address to another one. It can only be called by an address which was allowed before. + Transaction fee will be charged too. + If the receiver is not a natural address but also a person then she/he will be invited as well + + @from From who? + @to For who? + @amount Amount + + @success If the function was successful. + */ + if ( from != msg.sender ) { + var (_success, _reamining, _nonce) = db.getAllowance(from, msg.sender); + require( _success ); + _reamining = safeSub(_reamining, amount); + _nonce = safeAdd(_nonce, 1); + require( db.setAllowance(from, msg.sender, _reamining, _nonce) ); + AllowanceUsed(msg.sender, from, amount); + } + bytes memory _data; + if ( isContract(to) ) { + transferToContract(from, to, amount, _data); + } else { + _transfer( from, to, amount); + } + Transfer(from, to, amount, _data); + return true; + } + + /** + * @notice Send `amount` Corion tokens to `to` from `msg.sender` and notify the receiver from your transaction with your `extraData` data + * @param to The contract address of the recipient + * @param amount The amount of tokens to be transferred + * @param extraData Data to give forward to the receiver + * @return Whether the transfer was successful or not + */ + function transfer(address to, uint256 amount, bytes extraData) isReady external returns (bool success) { + /* + Launch a transaction where we transfer from a given address to another one. + After thetransaction the approvedCorionPremiumToken function of the receiver’s address is going to be called with the given data. + + @to For who? + @amount Amount + @extraData Extra data that will be given to the receiver + + @success If the function was successful. + */ + if ( isContract(to) ) { + transferToContract(msg.sender, to, amount, extraData); + } else { + _transfer( msg.sender, to, amount); + } + Transfer(msg.sender, to, amount, extraData); + return true; + } + + function transferToContract(address from, address to, uint256 amount, bytes extraData) internal { + /* + Inner function in order to transact a contract. + + @to For who? + @amount Amount + @extraData Extra data that will be given to the receiver + */ + _transfer(from, to, amount); + var (_success, _back) = thirdPartyPContractAbstract(to).receiveCorionPremiumToken(from, amount, extraData); + require( _success ); + require( amount > _back ); + if ( _back > 0 ) { + _transfer(to, from, _back); + } + } + + function _transfer(address from, address to, uint256 amount) isReady internal { + /* + Inner function to launch a transaction. + During the ICO transactions are only possible from the genesis address. + 0xa636a97578d26a3b76b060bbc18226d954cf3757 address is blacklisted. + + @from From how? + @to For who? + @amount Amount + */ + require( from != 0x00 && to != 0x00 && to != 0xa636a97578d26a3b76b060bbc18226d954cf3757 ); + require( ( ! isICO) || genesis[from] ); + require( db.decrease(from, amount) ); + require( db.increase(to, amount) ); + } + + function mint(address owner, uint256 value) external returns (bool success) { + /* + Generating tokens. It can be called only by ICO contract. + + @owner Address + @value Amount. + + @success Was the Function successful? + */ + require( msg.sender == icoAddr || isICO ); + _mint(owner, value); + return true; + } + + function _mint(address owner, uint256 value) isReady internal { + /* + Inner function to create a token. + + @owner Address of crediting the token. + @value Amount + */ + require( db.increase(owner, value) ); + Mint(owner, value); + } + + function isContract(address addr) internal returns (bool success) { + /* + Inner function in order to check if the given address is a natural address or a contract. + + @addr The address which is needed to be checked. + + @success Is the address crontact or not + */ + uint256 _codeLength; + assembly { + _codeLength := extcodesize(addr) + } + return _codeLength > 0; + } + + function balanceOf(address owner) constant returns (uint256 value) { + /* + Token balance query + + @owner Address + @value Balance of address + */ + return db.balanceOf(owner); + } + + function totalSupply() constant returns (uint256 value) { + /* + Total token quantity query + + @value Total token quantity + */ + return db.totalSupply(); + } + + event AllowanceUsed(address indexed spender, address indexed owner, uint256 indexed value); + event Mint(address indexed addr, uint256 indexed value); + event Burn(address indexed addr, uint256 indexed value); + event Approval(address indexed _owner, address indexed _spender, uint256 _value); + event Transfer(address indexed _from, address indexed _to, uint256 _value, bytes _extraData); +} diff --git a/test/compilationTests/corion/provider.sol b/test/compilationTests/corion/provider.sol new file mode 100644 index 00000000..5fa90fcd --- /dev/null +++ b/test/compilationTests/corion/provider.sol @@ -0,0 +1,797 @@ +pragma solidity ^0.4.11; + +import "./module.sol"; +import "./moduleHandler.sol"; +import "./safeMath.sol"; +import "./announcementTypes.sol"; + +contract provider is module, safeMath, announcementTypes { + /* + module callbacks + */ + function connectModule() external returns (bool success) { + require( super.isModuleHandler(msg.sender) ); + super._connectModule(); + var (_success, currentSchellingRound) = moduleHandler(moduleHandlerAddress).getCurrentSchellingRoundID(); + require( _success ); + return true; + } + function transferEvent(address from, address to, uint256 value) external returns (bool success) { + /* + Transaction completed. This function is ony available for the modulehandler. + It should be checked if the sender or the acceptor does not connect to the provider or it is not a provider itself if so than the change should be recorded. + + @from From whom? + @to For who? + @value amount + @bool Was the function successful? + */ + require( super.isModuleHandler(msg.sender) ); + transferEvent_(from, value, true); + transferEvent_(to, value, false); + return true; + } + function newSchellingRoundEvent(uint256 roundID, uint256 reward) external returns (bool success) { + /* + New schelling round. This function is only available for the moduleHandler. + We are recording the new schelling round and we are storing the whole current quantity of the tokens. + We generate a reward quantity of tokens directed to the providers address. The collected interest will be tranfered from this contract. + + @roundID Number of the schelling round. + @reward token emission + @bool Was the function successful? + */ + require( super.isModuleHandler(msg.sender) ); + globalFunds[roundID].reward = reward; + globalFunds[roundID].supply = globalFunds[roundID-1].supply; + currentSchellingRound = roundID; + require( moduleHandler(moduleHandlerAddress).mint(address(this), reward) ); + return true; + } + modifier isReady { + var (_success, _active) = super.isActive(); + require( _success && _active ); + _; + } + /* + Provider module + */ + uint256 private minFundsForPublic = 3000; + uint256 private minFundsForPrivate = 8000; + uint256 private privateProviderLimit = 250; + uint8 private publicMinRate = 30; + uint8 private privateMinRate = 0; + uint8 private publicMaxRate = 70; + uint8 private privateMaxRate = 100; + uint256 private gasProtectMaxRounds = 630; + uint256 private interestMinFunds = 25000; + uint256 private rentRate = 20; + + struct _rate { + uint8 value; + bool valid; + } + struct __providers { + address admin; + string name; + string website; + string country; + string info; + bool isForRent; + mapping(uint256 => _rate) rateHistory; + uint8 currentRate; + bool priv; + uint256 clientsCount; + mapping(address => bool) allowedUsers; + mapping(uint256 => uint256) supply; + uint256 lastSupplyID; + mapping(uint256 => uint256) ownSupply; + uint256 lastOwnSupplyID; + uint256 paidUpTo; + uint8 lastPaidRate; + uint256 create; + uint256 close; + bool valid; + } + struct _providers { + mapping(uint256 => __providers) data; + uint256 currentHeight; + } + mapping(address => _providers) private providers; + + struct _globalFunds { + uint256 reward; + uint256 supply; + } + mapping(uint256 => _globalFunds) private globalFunds; + + struct _client{ + address providerAddress; + uint256 providerHeight; + uint256 providerConnected; + uint8 lastRate; + mapping(uint256 => uint256) supply; + uint256 lastSupplyID; + uint256 paidUpTo; + } + mapping(address => _client) private clients; + + uint256 private currentSchellingRound = 1; + + function provider(address _moduleHandler) { + /* + Install function. + + @_moduleHandler Address of the moduleHandler. + */ + super.registerModuleHandler(_moduleHandler); + } + function configure(announcementType a, uint256 b) external returns(bool) { + /* + Configuration of the provider. Can be invited just by the moduleHandler. + + @a Type of the setting + @b value + */ + require( super.isModuleHandler(msg.sender) ); + if ( a == announcementType.providerPublicFunds ) { minFundsForPublic = b; } + else if ( a == announcementType.providerPrivateFunds ) { minFundsForPrivate = b; } + else if ( a == announcementType.providerPrivateClientLimit ) { privateProviderLimit = b; } + else if ( a == announcementType.providerPublicMinRate ) { publicMinRate = uint8(b); } + else if ( a == announcementType.providerPublicMaxRate ) { publicMaxRate = uint8(b); } + else if ( a == announcementType.providerPrivateMinRate ) { privateMinRate = uint8(b); } + else if ( a == announcementType.providerPrivateMaxRate ) { privateMaxRate = uint8(b); } + else if ( a == announcementType.providerGasProtect ) { gasProtectMaxRounds = b; } + else if ( a == announcementType.providerInterestMinFunds ) { interestMinFunds = b; } + else if ( a == announcementType.providerRentRate ) { rentRate = b; } + else { return false; } + return true; + } + function getUserDetails(address addr, uint256 schellingRound) public constant returns (address ProviderAddress, uint256 ProviderHeight, uint256 ConnectedOn, uint256 value) { + /* + Collecting the datas of the client. + + @addr Address of the client. + @schellingRound Number of the schelling round. If it is not defined then the current one. + @ProviderAddress Address of the provider the one where connected to + @ProviderHeight The height (level) of the provider where is connected. + @ConnectedOn Time of connection + @value Quantity of the client’s token + */ + if ( schellingRound == 0 ) { + schellingRound = currentSchellingRound; + } + if ( clients[addr].providerAddress != 0 ) { + ProviderAddress = clients[addr].providerAddress; + ProviderHeight = clients[addr].providerHeight; + ConnectedOn = clients[addr].providerConnected; + value = clients[addr].supply[schellingRound]; + } + } + function rightForInterest(uint256 value, bool priv) internal returns (bool) { + /* + the share from the token emission. + In case is a private provider it has to be checked if it has enough connected capital to be able to accept share from the token emission. + The provider’s account counts as a capital for the emission as well. + + @value amount of the connected capital + @priv Is the provider private or not? + @bool Gets the share from the token emission. + */ + if ( priv ) { + return ( value >= interestMinFunds ); + } + return true; + } + function setRightForInterest(uint256 oldValue, uint256 newValue, bool priv) internal { + /* + It checks if the provider has enough connected captital to be able to get from the token emission. + In case the provider is not able to get the share from the token emission then the connected capital will not count to the value of the globalFunds, to the current schelling round. + + @oldValue old + @newValue new + @priv Is the provider private? + */ + var a = rightForInterest(oldValue, priv); + var b = rightForInterest(newValue, priv); + if ( a && b ) { + globalFunds[currentSchellingRound].supply = globalFunds[currentSchellingRound].supply - oldValue + newValue; + } else if ( a && ! b ) { + globalFunds[currentSchellingRound].supply -= oldValue; + } else if ( ! a && b ) { + globalFunds[currentSchellingRound].supply += newValue; + } + } + function checkCorrectRate(bool priv, uint8 rate) internal returns(bool) { + /* + Inner function which checks if the amount of interest what is given by the provider is fits to the criteria. + + @priv Is the provider private or not? + @rate Percentage/rate of the interest + @bool Correct or not? + */ + return ( ! priv && ( rate >= publicMinRate && rate <= publicMaxRate ) ) || + ( priv && ( rate >= privateMinRate && rate <= privateMaxRate ) ); + } + function createProvider(bool priv, string name, string website, string country, string info, uint8 rate, bool isForRent, address admin) isReady external { + /* + Creating a provider. + During the ICO its not allowed to create provider. + To one address only one provider can belong to. + Address, how is connected to the provider can not create a provider. + For opening, has to have enough capital. + All the functions of the provider except of the closing are going to be handled by the admin. + The provider can be start as a rent as well, in this case the isForRent has to be true/correct. In case it runs as a rent the 20% of the profit will belong to the leser and the rest goes to the admin. + + @priv Privat szolgaltato e. Is private provider? + @name Provider’s name. + @website Provider’s website + @country Provider’s country + @info Provider’s short introduction. + @rate Rate of the emission what is going to be transfered to the client by the provider. + @isForRent is for Rent or not? + @admin The admin’s address + */ + require( ! providers[msg.sender].data[providers[msg.sender].currentHeight].valid ); + require( clients[msg.sender].providerAddress == 0x00 ); + require( ! checkICO() ); + if ( priv ) { + require( getTokenBalance(msg.sender) >= minFundsForPrivate ); + } else { + require( getTokenBalance(msg.sender) >= minFundsForPublic ); + } + require( checkCorrectRate(priv, rate) ); + + providers[msg.sender].currentHeight++; + var currHeight = providers[msg.sender].currentHeight; + providers[msg.sender].data[currHeight].valid = true; + if ( admin == 0x00 ) { + providers[msg.sender].data[currHeight].admin = msg.sender; + } else { + providers[msg.sender].data[currHeight].admin = admin; + } + providers[msg.sender].data[currHeight].name = name; + providers[msg.sender].data[currHeight].website = website; + providers[msg.sender].data[currHeight].isForRent = isForRent; + providers[msg.sender].data[currHeight].country = country; + providers[msg.sender].data[currHeight].info = info; + providers[msg.sender].data[currHeight].currentRate = rate; + providers[msg.sender].data[currHeight].create = now; + providers[msg.sender].data[currHeight].lastPaidRate = rate; + providers[msg.sender].data[currHeight].priv = priv; + providers[msg.sender].data[currHeight].lastSupplyID = currentSchellingRound; + providers[msg.sender].data[currHeight].paidUpTo = currentSchellingRound; + if ( priv ) { + providers[msg.sender].data[currHeight].supply[currentSchellingRound] = getTokenBalance(msg.sender); + providers[msg.sender].data[currHeight].ownSupply[currentSchellingRound] = getTokenBalance(msg.sender); + providers[msg.sender].data[currHeight].lastOwnSupplyID = currentSchellingRound; + } else { + delete providers[msg.sender].data[currHeight].supply[currentSchellingRound]; + } + EProviderOpen(msg.sender, currHeight); + } + function setProviderDetails(address addr, string website, string country, string info, uint8 rate, address admin) isReady external { + /* + Modifying the datas of the provider. + This can only be invited by the provider’s admin. + The emission rate is only valid for the next schelling round for this one it is not. + The admin can only be changed by the address of the provider. + + @addr Address of the provider. + @website Website. + @admin The new address of the admin. If we do not want to set it then we should enter 0X00. + @country Country + @info Short intro. + @rate Rate of the emission what will be given to the client. + */ + var currHeight = providers[addr].currentHeight; + require( providers[addr].data[currHeight].valid ); + require( checkCorrectRate(providers[addr].data[currHeight].priv, rate) ); + require( providers[addr].data[currHeight].admin == msg.sender || msg.sender == addr ); + if ( admin != 0x00 ) { + require( msg.sender == addr ); + providers[addr].data[currHeight].admin = admin; + } + providers[addr].data[currHeight].rateHistory[currentSchellingRound] = _rate( rate, true ); + providers[addr].data[currHeight].website = website; + providers[addr].data[currHeight].country = country; + providers[addr].data[currHeight].info = info; + providers[addr].data[currHeight].currentRate = rate; + EProviderDetailsChanged(addr, currHeight, website, country, info, rate, admin); + } + function getProviderInfo(address addr, uint256 height) public constant returns (string name, string website, string country, string info, uint256 create) { + /* + for the infos of the provider. + In case the height is unknown then the system will use the last known height. + + @addr Addr of the provider + @height Height + @name Name of the provider. + @website Website of the provider. + @country Country of the provider. + @info Short intro of the provider. + @create Timestamp of creating the provider + */ + if ( height == 0 ) { + height = providers[addr].currentHeight; + } + name = providers[addr].data[height].name; + website = providers[addr].data[height].website; + country = providers[addr].data[height].country; + info = providers[addr].data[height].info; + create = providers[addr].data[height].create; + } + function getProviderDetails(address addr, uint256 height) public constant returns (uint8 rate, bool isForRent, uint256 clientsCount, bool priv, bool getInterest, bool valid) { + /* + Asking for the datas of the provider. + In case the height is unknown then the system will use the last known height. + + @addr Address of the provider + @height Height + @rate The rate of the emission which will be transfered to the client. + @isForRent Rent or not. + @clientsCount Number of the clients. + @priv Private or not? + @getInterest Does get from the token emission? + @valid Is an active provider? + */ + if ( height == 0 ) { + height = providers[addr].currentHeight; + } + rate = providers[addr].data[height].currentRate; + isForRent = providers[addr].data[height].isForRent; + clientsCount = providers[addr].data[height].clientsCount; + priv = providers[addr].data[height].priv; + getInterest = rightForInterest(getProviderCurrentSupply(addr), providers[addr].data[height].priv ); + valid = providers[addr].data[height].valid; + } + function getProviderCurrentSupply(address addr) internal returns (uint256) { + /* + Inner function for polling the current height and the current quantity of the connected capital of the schelling round. + + @addr Provider’s address. + @uint256 Amount of the connected capital + */ + return providers[addr].data[providers[addr].currentHeight].supply[currentSchellingRound]; + } + function closeProvider() isReady external { + /* + Closing and inactivate the provider. + It is only possible to close that active provider which is owned by the sender itself after calling the whole share of the emission. + Whom were connected to the provider those clients will have to disconnect after they’ve called their share of emission which was not called before. + */ + var currHeight = providers[msg.sender].currentHeight; + require( providers[msg.sender].data[currHeight].valid ); + require( providers[msg.sender].data[currHeight].paidUpTo == currentSchellingRound ); + + providers[msg.sender].data[currHeight].valid = false; + providers[msg.sender].data[currHeight].close = currentSchellingRound; + setRightForInterest(getProviderCurrentSupply(msg.sender), 0, providers[msg.sender].data[currHeight].priv); + EProviderClose(msg.sender, currHeight); + } + function allowUsers(address provider, address[] addr) isReady external { + /* + Permition of the user to be able to connect to the provider. + This can only be invited by the provider’s admin. + With this kind of call only 100 address can be permited. + + @addr Array of the addresses for whom the connection is allowed. + */ + var currHeight = providers[provider].currentHeight; + require( providers[provider].data[currHeight].valid ); + require( providers[provider].data[currHeight].priv ); + require( providers[provider].data[currHeight].admin == msg.sender ); + require( addr.length <= 100 ); + + for ( uint256 a=0 ; a 0 ) { + providerHasClosed = true; + require( clients[msg.sender].paidUpTo == providers[provider].data[currHeight].close ); + } else { + require( clients[msg.sender].paidUpTo == currentSchellingRound ); + } + + var bal = getTokenBalance(msg.sender); + if ( ! providerHasClosed ) { + providers[provider].data[currHeight].clientsCount--; + checkFloatingSupply(provider, currHeight, true, bal); + } + delete clients[msg.sender].providerAddress; + delete clients[msg.sender].providerHeight; + delete clients[msg.sender].lastSupplyID; + delete clients[msg.sender].paidUpTo; + delete clients[msg.sender].lastRate; + delete clients[msg.sender].providerConnected; + EClientLost(msg.sender, provider, currHeight, bal); + } + function checkReward(address addr) public constant returns (uint256 reward) { + /* + Polling the share from the token emission for clients and for providers. + + @addr The address want to check. + @reward Accumulated amount. + */ + if ( providers[addr].data[providers[addr].currentHeight].valid ) { + uint256 a; + (reward, a) = getProviderReward(addr, 0); + } else if ( clients[addr].providerAddress != 0x0 ) { + reward = getClientReward(0); + } + } + function getReward(address beneficiary, uint256 limit, address provider) isReady external returns (uint256 reward) { + /* + Polling the share from the token emission token emission for clients and for providers. + + It is optionaly possible to give an address of a beneficiary for whom we can transfer the accumulated amount. In case we don’t enter any address then the amount will be transfered to the caller’s address. + As the interest should be checked at each schelling round in order to get the share from that so to avoid the overflow of the gas the number of the check-rounds should be limited. + Opcionalisan megadhato az ellenorzes koreinek szama. It is possible to enter optionaly the number of the check-rounds. If it is 0 then it is automatic. + Provider variable should only be entered if the real owner of the provider is not the caller’s address. + In case the client/provider was far behind then it is possible that this function should be called several times to check the total generated schelling rounds and to collect the share. + If is neighter a client nor a provider then the function is not available. + The tokens will be sent to the beneficiary from the address of the provider without any transaction fees. + + @beneficiary Address of the beneficiary + @limit Quota of the check-rounds. + @provider Address of the provider + @reward Accumulated amount from the previous rounds. + */ + var _limit = limit; + var _beneficiary = beneficiary; + var _provider = provider; + if ( _limit == 0 ) { _limit = gasProtectMaxRounds; } + if ( _beneficiary == 0x00 ) { _beneficiary = msg.sender; } + if ( _provider == 0x00 ) { _provider = msg.sender; } + uint256 clientReward; + uint256 providerReward; + if ( providers[_provider].data[providers[_provider].currentHeight].valid ) { + require( providers[_provider].data[providers[_provider].currentHeight].admin == msg.sender || msg.sender == _provider ); + (providerReward, clientReward) = getProviderReward(_provider, _limit); + } else if ( clients[msg.sender].providerAddress != 0x00 ) { + clientReward = getClientReward(_limit); + } else { + throw; + } + if ( clientReward > 0 ) { + require( moduleHandler(moduleHandlerAddress).transfer(address(this), _beneficiary, clientReward, false) ); + } + if ( providerReward > 0 ) { + require( moduleHandler(moduleHandlerAddress).transfer(address(this), provider, providerReward, false) ); + } + EReward(msg.sender, provider, clientReward, providerReward); + } + function getClientReward(uint256 limit) internal returns (uint256 reward) { + /* + Inner function for the client in order to collect the share from the token emission + + @limit Quota of checking the schelling-rounds. + @reward Collected token amount from the checked rounds. + */ + uint256 value; + uint256 steps; + address provAddr; + uint256 provHeight; + bool interest = false; + var rate = clients[msg.sender].lastRate; + for ( uint256 a = (clients[msg.sender].paidUpTo + 1) ; a <= currentSchellingRound ; a++ ) { + if (globalFunds[a].reward > 0 && globalFunds[a].supply > 0) { + provAddr = clients[msg.sender].providerAddress; + provHeight = clients[msg.sender].providerHeight; + if ( providers[provAddr].data[provHeight].rateHistory[a].valid ) { + rate = providers[provAddr].data[provHeight].rateHistory[a].value; + } + if ( rate > 0 ) { + if ( a > providers[provAddr].data[provHeight].lastSupplyID ) { + interest = rightForInterest(providers[provAddr].data[provHeight].supply[providers[provAddr].data[provHeight].lastSupplyID], providers[provAddr].data[provHeight].priv); + } else { + interest = rightForInterest(providers[provAddr].data[provHeight].supply[a], providers[provAddr].data[provHeight].priv); + } + if ( interest ) { + if ( limit > 0 && steps > limit ) { + a--; + break; + } + if (clients[msg.sender].lastSupplyID < a) { + value = clients[msg.sender].supply[clients[msg.sender].lastSupplyID]; + } else { + value = clients[msg.sender].supply[a]; + } + if ( globalFunds[a].supply > 0) { + reward += value * globalFunds[a].reward / globalFunds[a].supply * uint256(rate) / 100; + } + steps++; + } + } + } + } + clients[msg.sender].lastRate = rate; + clients[msg.sender].paidUpTo = a-1; + } + function getProviderReward(address addr, uint256 limit) internal returns (uint256 providerReward, uint256 adminReward) { + /* + Inner function for the provider in order to collect the share from the token emission + @addr Address of the provider. + @limit Quota of the check-rounds. + @providerReward The reward of the provider’s address from the checked rounds. + @adminReward Admin’s reward from the checked rounds. + */ + uint256 reward; + uint256 ownReward; + uint256 value; + uint256 steps; + uint256 currHeight = providers[addr].currentHeight; + uint256 LTSID = providers[addr].data[currHeight].lastSupplyID; + var rate = providers[addr].data[currHeight].lastPaidRate; + for ( uint256 a = (providers[addr].data[currHeight].paidUpTo + 1) ; a <= currentSchellingRound ; a++ ) { + if (globalFunds[a].reward > 0 && globalFunds[a].supply > 0) { + if ( providers[addr].data[currHeight].rateHistory[a].valid ) { + rate = providers[addr].data[currHeight].rateHistory[a].value; + } + if ( rate > 0 ) { + if ( ( a > LTSID && rightForInterest(providers[addr].data[currHeight].supply[LTSID], providers[addr].data[currHeight].priv) || + rightForInterest(providers[addr].data[currHeight].supply[a], providers[addr].data[currHeight].priv) ) ) { + if ( limit > 0 && steps > limit ) { + a--; + break; + } + if ( LTSID < a ) { + value = providers[addr].data[currHeight].supply[LTSID]; + } else { + value = providers[addr].data[currHeight].supply[a]; + } + if ( globalFunds[a].supply > 0) { + reward += value * globalFunds[a].reward / globalFunds[a].supply * ( 100 - uint256(rate) ) / 100; + if ( providers[addr].data[currHeight].priv ) { + LTSID = providers[addr].data[currHeight].lastOwnSupplyID; + if ( LTSID < a ) { + value = providers[addr].data[currHeight].ownSupply[LTSID]; + } else { + value = providers[addr].data[currHeight].ownSupply[a]; + } + ownReward += value * globalFunds[a].reward / globalFunds[a].supply; + } + } + steps++; + } + } + } + } + providers[addr].data[currHeight].lastPaidRate = uint8(rate); + providers[addr].data[currHeight].paidUpTo = a-1; + if ( providers[addr].data[currHeight].isForRent ) { + providerReward = reward * rentRate / 100; + adminReward = reward - providerReward; + if ( providers[addr].data[currHeight].priv ) { providerReward += ownReward; } + } else { + providerReward = reward + ownReward; + } + } + function checkFloatingSupply(address providerAddress, uint256 providerHeight, bool neg, uint256 value) internal { + /* + Inner function for updating the database when some token change has happened. + In this case we are checking if despite the changes the provider is still entitled to the token emission. In case the legitimacy changes then the global supply should be set as well. + + @providerAddress Provider address. + @providerHeight Provider height. + @neg the change was negative or not + @value Rate of the change + */ + uint256 LSID = providers[providerAddress].data[providerHeight].lastSupplyID; + if ( currentSchellingRound != LSID ) { + if ( neg ) { + setRightForInterest( + providers[providerAddress].data[providerHeight].supply[LSID], + providers[providerAddress].data[providerHeight].supply[LSID] - value, + providers[providerAddress].data[providerHeight].priv + ); + providers[providerAddress].data[providerHeight].supply[currentSchellingRound] = providers[providerAddress].data[providerHeight].supply[LSID] - value; + } else { + setRightForInterest( + providers[providerAddress].data[providerHeight].supply[LSID], + providers[providerAddress].data[providerHeight].supply[LSID] + value, + providers[providerAddress].data[providerHeight].priv + ); + providers[providerAddress].data[providerHeight].supply[currentSchellingRound] = providers[providerAddress].data[providerHeight].supply[LSID] + value; + } + providers[providerAddress].data[providerHeight].lastSupplyID = currentSchellingRound; + } else { + if ( neg ) { + setRightForInterest( + getProviderCurrentSupply(providerAddress), + getProviderCurrentSupply(providerAddress) - value, + providers[providerAddress].data[providerHeight].priv + ); + providers[providerAddress].data[providerHeight].supply[currentSchellingRound] -= value; + } else { + setRightForInterest( + getProviderCurrentSupply(providerAddress), + getProviderCurrentSupply(providerAddress) + value, + providers[providerAddress].data[providerHeight].priv + ); + providers[providerAddress].data[providerHeight].supply[currentSchellingRound] += value; + } + } + } + function checkFloatingOwnSupply(address providerAddress, uint256 providerHeight, bool neg, uint256 value) internal { + /* + Inner function for updating the database in case token change has happened. + In this case we check if the provider despite the changes is still entitled to the token emission. + We just call this only if the private provider and it’s own capital bears emission. + + @providerAddress Provider address. + @providerHeight Provider height. + @neg Was the change negative? + @value Rate of the change. + */ + uint256 LSID = providers[providerAddress].data[providerHeight].lastOwnSupplyID; + if ( currentSchellingRound != LSID ) { + if ( neg ) { + setRightForInterest( + providers[providerAddress].data[providerHeight].ownSupply[LSID], + providers[providerAddress].data[providerHeight].ownSupply[LSID] - value, + true + ); + providers[providerAddress].data[providerHeight].ownSupply[currentSchellingRound] = providers[providerAddress].data[providerHeight].ownSupply[LSID] - value; + } else { + setRightForInterest( + providers[providerAddress].data[providerHeight].ownSupply[LSID], + providers[providerAddress].data[providerHeight].ownSupply[LSID] + value, + true + ); + providers[providerAddress].data[providerHeight].ownSupply[currentSchellingRound] = providers[providerAddress].data[providerHeight].ownSupply[LSID] + value; + } + providers[providerAddress].data[providerHeight].lastOwnSupplyID = currentSchellingRound; + } else { + if ( neg ) { + setRightForInterest( + getProviderCurrentSupply(providerAddress), + getProviderCurrentSupply(providerAddress) - value, + true + ); + providers[providerAddress].data[providerHeight].ownSupply[currentSchellingRound] -= value; + } else { + setRightForInterest( + getProviderCurrentSupply(providerAddress), + getProviderCurrentSupply(providerAddress) + value, + true + ); + providers[providerAddress].data[providerHeight].ownSupply[currentSchellingRound] += value; + } + } + } + function TEMath(uint256 a, uint256 b, bool neg) internal returns (uint256) { + /* + Inner function for the changes of the numbers + + @a First number + @b 2nd number + @neg Operation with numbers. If it is TRUE then subtraction, if it is FALSE then addition. + */ + if ( neg ) { return a-b; } + else { return a+b; } + } + function transferEvent_(address addr, uint256 value, bool neg) internal { + /* + Inner function for perceiving the changes of the balance and updating the database. + If the address is a provider and the balance is decreasing than can not let it go under the minimum level. + + @addr The address where the change happened. + @value Rate of the change. + @neg ype of the change. If it is TRUE then the balance has been decreased if it is FALSE then it has been increased. + */ + if ( clients[addr].providerAddress != 0 ) { + checkFloatingSupply(clients[addr].providerAddress, providers[clients[addr].providerAddress].currentHeight, ! neg, value); + if (clients[addr].lastSupplyID != currentSchellingRound) { + clients[addr].supply[currentSchellingRound] = TEMath(clients[addr].supply[clients[addr].lastSupplyID], value, neg); + clients[addr].lastSupplyID = currentSchellingRound; + } else { + clients[addr].supply[currentSchellingRound] = TEMath(clients[addr].supply[currentSchellingRound], value, neg); + } + } else if ( providers[addr].data[providers[addr].currentHeight].valid ) { + var currentHeight = providers[addr].currentHeight; + if ( neg ) { + uint256 balance = getTokenBalance(addr); + if ( providers[addr].data[currentHeight].priv ) { + require( balance-value >= minFundsForPrivate ); + } else { + require( balance-value >= minFundsForPublic ); + } + } + if ( providers[addr].data[currentHeight].priv ) { + checkFloatingOwnSupply(addr, currentHeight, ! neg, value); + } + } + } + function getTokenBalance(address addr) internal returns (uint256 balance) { + /* + Inner function in order to poll the token balance of the address. + + @addr Address + + @balance Balance of the address. + */ + var (_success, _balance) = moduleHandler(moduleHandlerAddress).balanceOf(addr); + require( _success ); + return _balance; + } + function checkICO() internal returns (bool isICO) { + /* + Inner function to check the ICO status. + + @isICO Is the ICO in proccess or not? + */ + var (_success, _isICO) = moduleHandler(moduleHandlerAddress).isICO(); + require( _success ); + return _isICO; + } + event EProviderOpen(address addr, uint256 height); + event EClientLost(address indexed client, address indexed provider, uint256 height, uint256 indexed value); + event ENewClient(address indexed client, address indexed provider, uint256 height, uint256 indexed value); + event EProviderClose(address indexed addr, uint256 height); + event EProviderDetailsChanged(address indexed addr, uint256 height, string website, string country, string info, uint8 rate, address admin); + event EReward(address indexed client, address indexed provider, uint256 clientreward, uint256 providerReward); +} diff --git a/test/compilationTests/corion/publisher.sol b/test/compilationTests/corion/publisher.sol new file mode 100644 index 00000000..e94b9a92 --- /dev/null +++ b/test/compilationTests/corion/publisher.sol @@ -0,0 +1,278 @@ +pragma solidity ^0.4.11; + +import "./announcementTypes.sol"; +import "./module.sol"; +import "./moduleHandler.sol"; +import "./safeMath.sol"; + +contract publisher is announcementTypes, module, safeMath { + /* + module callbacks + */ + function transferEvent(address from, address to, uint256 value) external returns (bool success) { + /* + Transaction completed. This function is available only for moduleHandler + If a transaction is carried out from or to an address which participated in the objection of an announcement, its objection purport is automatically set + */ + require( super.isModuleHandler(msg.sender) ); + uint256 announcementID; + uint256 a; + // need reverse lookup + for ( a=0 ; a announcements_s) public announcements; + uint256 announcementsLength = 1; + + mapping (address => uint256[]) public opponents; + + function publisher(address moduleHandler) { + /* + Installation function. The installer will be registered in the admin list automatically + + @moduleHandler Address of moduleHandler + */ + super.registerModuleHandler(moduleHandler); + } + + function Announcements(uint256 id) public constant returns (uint256 Type, uint256 Start, uint256 End, bool Closed, string Announcement, string Link, bool Opposited, string _str, uint256 _uint, address _addr) { + /* + Announcement data query + + @id Its identification + + @Type Subject of announcement + @Start Height of announcement block + @End Planned completion of announcement + @Closed Closed or not + @Announcement Announcement text + @Link Link perhaps to a Forum + @Opposited Objected or not + @_str Text value + @_uint Number value + @_addr Address value + */ + Type = uint256(announcements[id].Type); + Start = announcements[id].start; + End = announcements[id].end; + Closed = ! announcements[id].open; + Announcement = announcements[id].announcement; + Link = announcements[id].link; + if ( checkOpposited(announcements[id].oppositionWeight, announcements[id].oppositable) ) { + Opposited = true; + } + _str = announcements[id]._str; + _uint = announcements[id]._uint; + _addr = announcements[id]._addr; + } + + function checkOpposited(uint256 weight, bool oppositable) public constant returns (bool success) { + /* + Veto check + + @weight Purport of objections so far + @oppositable Opposable at all + + @success Opposed or not + */ + if ( ! oppositable ) { return false; } + var (_success, _amount) = moduleHandler(moduleHandlerAddress).totalSupply(); + require( _success ); + return _amount * oppositeRate / 100 > weight; + } + + function newAnnouncement(announcementType Type, string Announcement, string Link, bool Oppositable, string _str, uint256 _uint, address _addr) onlyOwner external { + /* + New announcement. Can be called only by those in the admin list + + @Type Topic of announcement + @Start height of announcement block + @End planned completion of announcement + @Closed Completed or not + @Announcement Announcement text + @Link link to a Forum + @Opposition opposed or not + @_str text box + @_uint number box + @_addr address box + */ + announcementsLength++; + announcements[announcementsLength].Type = Type; + announcements[announcementsLength].start = block.number; + if ( checkICO() ) { + announcements[announcementsLength].end = block.number + minAnnouncementDelayOnICO; + } else { + announcements[announcementsLength].end = block.number + minAnnouncementDelay; + } + announcements[announcementsLength].open = true; + announcements[announcementsLength].announcement = Announcement; + announcements[announcementsLength].link = Link; + announcements[announcementsLength].oppositable = Oppositable; + announcements[announcementsLength].oppositionWeight = 0; + announcements[announcementsLength].result = false; + announcements[announcementsLength]._str = _str; + announcements[announcementsLength]._uint = _uint; + announcements[announcementsLength]._addr = _addr; + ENewAnnouncement(announcementsLength, Type); + } + + function closeAnnouncement(uint256 id) onlyOwner external { + /* + Close announcement. It can be closed only by those in the admin list. Windup is allowed only after the announcement is completed. + + @id Announcement identification + */ + require( announcements[id].open && announcements[id].end < block.number ); + if ( ! checkOpposited(announcements[id].oppositionWeight, announcements[id].oppositable) ) { + announcements[id].result = true; + if ( announcements[id].Type == announcementType.newModule ) { + require( moduleHandler(moduleHandlerAddress).newModule(announcements[id]._str, announcements[id]._addr, true, true) ); + } else if ( announcements[id].Type == announcementType.dropModule ) { + require( moduleHandler(moduleHandlerAddress).dropModule(announcements[id]._str, true) ); + } else if ( announcements[id].Type == announcementType.replaceModule ) { + require( moduleHandler(moduleHandlerAddress).replaceModule(announcements[id]._str, announcements[id]._addr, true) ); + } else if ( announcements[id].Type == announcementType.replaceModuleHandler) { + require( moduleHandler(moduleHandlerAddress).replaceModuleHandler(announcements[id]._addr) ); + } else if ( announcements[id].Type == announcementType.transactionFeeRate || + announcements[id].Type == announcementType.transactionFeeMin || + announcements[id].Type == announcementType.transactionFeeMax || + announcements[id].Type == announcementType.transactionFeeBurn ) { + require( moduleHandler(moduleHandlerAddress).configureModule("token", announcements[id].Type, announcements[id]._uint) ); + } else if ( announcements[id].Type == announcementType.providerPublicFunds || + announcements[id].Type == announcementType.providerPrivateFunds || + announcements[id].Type == announcementType.providerPrivateClientLimit || + announcements[id].Type == announcementType.providerPublicMinRate || + announcements[id].Type == announcementType.providerPublicMaxRate || + announcements[id].Type == announcementType.providerPrivateMinRate || + announcements[id].Type == announcementType.providerPrivateMaxRate || + announcements[id].Type == announcementType.providerGasProtect || + announcements[id].Type == announcementType.providerInterestMinFunds || + announcements[id].Type == announcementType.providerRentRate ) { + require( moduleHandler(moduleHandlerAddress).configureModule("provider", announcements[id].Type, announcements[id]._uint) ); + } else if ( announcements[id].Type == announcementType.schellingRoundBlockDelay || + announcements[id].Type == announcementType.schellingCheckRounds || + announcements[id].Type == announcementType.schellingCheckAboves || + announcements[id].Type == announcementType.schellingRate ) { + require( moduleHandler(moduleHandlerAddress).configureModule("schelling", announcements[id].Type, announcements[id]._uint) ); + } else if ( announcements[id].Type == announcementType.publisherMinAnnouncementDelay) { + minAnnouncementDelay = announcements[id]._uint; + } else if ( announcements[id].Type == announcementType.publisherOppositeRate) { + oppositeRate = uint8(announcements[id]._uint); + } + } + announcements[id].end = block.number; + announcements[id].open = false; + } + + function oppositeAnnouncement(uint256 id) external { + /* + Opposition of announcement + If announcement is opposable, anyone owning a token can oppose it + Opposition is automatically with the total amount of tokens + If the quantity of his tokens changes, the purport of his opposition changes automatically + The prime time is the windup of the announcement, because this is the moment when the number of tokens in opposition are counted. + One address is entitled to be in oppositon only once. An opposition cannot be withdrawn. + Running announcements can be opposed only. + + @id Announcement identification + */ + uint256 newArrayID = 0; + bool foundEmptyArrayID = false; + require( announcements[id].open ); + require( announcements[id].oppositable ); + for ( uint256 a=0 ; a 0); + if ( foundEmptyArrayID ) { + opponents[msg.sender][newArrayID] = id; + } else { + opponents[msg.sender].push(id); + } + announcements[id].oppositionWeight += _balance; + EOppositeAnnouncement(id, msg.sender, _balance); + } + + function invalidateAnnouncement(uint256 id) onlyOwner external { + /* + Withdraw announcement. Only those in the admin list can withdraw it. + + @id Announcement identification + */ + require( announcements[id].open ); + announcements[id].end = block.number; + announcements[id].open = false; + EInvalidateAnnouncement(id); + } + + modifier onlyOwner() { + /* + Only the owner is allowed to call it. + */ + require( moduleHandler(moduleHandlerAddress).owners(msg.sender) ); + _; + } + + function checkICO() internal returns (bool isICO) { + /* + Inner function to check the ICO status. + @bool Is the ICO in proccess or not? + */ + var (_success, _isICO) = moduleHandler(moduleHandlerAddress).isICO(); + require( _success ); + return _isICO; + } + + event ENewAnnouncement(uint256 id, announcementType typ); + event EOppositeAnnouncement(uint256 id, address addr, uint256 value); + event EInvalidateAnnouncement(uint256 id); + event ECloseAnnouncement(uint256 id); +} diff --git a/test/compilationTests/corion/safeMath.sol b/test/compilationTests/corion/safeMath.sol new file mode 100644 index 00000000..9e27d379 --- /dev/null +++ b/test/compilationTests/corion/safeMath.sol @@ -0,0 +1,33 @@ +pragma solidity ^0.4.11; + +contract safeMath { + function safeAdd(uint256 a, uint256 b) internal returns(uint256) { + /* + Biztonsagos hozzadas. Tulcsordulas elleni vedelem. + A vegeredmeny nem lehet kevesebb mint az @a, ha igen megall a kod. + + @a Amihez hozzaadni kell + @b Amennyit hozzaadni kell. + @uint256 Vegeredmeny. + */ + if ( b > 0 ) { + assert( a + b > a ); + } + return a + b; + } + + function safeSub(uint256 a, uint256 b) internal returns(uint256) { + /* + Biztonsagos kivonas. Tulcsordulas elleni vedelem. + A vegeredmeny nem lehet tobb mint az @a, ha igen megall a kod. + + @a Amibol kivonni kell. + @b Amennyit kivonni kell. + @uint256 Vegeredmeny. + */ + if ( b > 0 ) { + assert( a - b < a ); + } + return a - b; + } +} \ No newline at end of file diff --git a/test/compilationTests/corion/schelling.sol b/test/compilationTests/corion/schelling.sol new file mode 100644 index 00000000..8c8e093c --- /dev/null +++ b/test/compilationTests/corion/schelling.sol @@ -0,0 +1,577 @@ +pragma solidity ^0.4.11; + +import "./announcementTypes.sol"; +import "./module.sol"; +import "./moduleHandler.sol"; +import "./safeMath.sol"; + +contract schellingVars { + /* + Common enumerations and structures of the Schelling and Database contract. + */ + enum voterStatus { + base, + afterPrepareVote, + afterSendVoteOk, + afterSendVoteBad + } + struct _rounds { + uint256 totalAboveWeight; + uint256 totalBelowWeight; + uint256 reward; + uint256 blockHeight; + bool voted; + } + struct _voter { + uint256 roundID; + bytes32 hash; + voterStatus status; + bool voteResult; + uint256 rewards; + } +} + +contract schellingDB is safeMath, schellingVars { + /* + Schelling database contract. + */ + address private owner; + function replaceOwner(address newOwner) external returns(bool) { + require( owner == 0x00 || msg.sender == owner ); + owner = newOwner; + return true; + } + modifier isOwner { require( msg.sender == owner ); _; } + /* + Constructor + */ + function schellingDB() { + rounds.length = 2; + rounds[0].blockHeight = block.number; + currentSchellingRound = 1; + } + /* + Funds + */ + mapping(address => uint256) private funds; + function getFunds(address _owner) constant returns(bool, uint256) { + return (true, funds[_owner]); + } + function setFunds(address _owner, uint256 _amount) isOwner external returns(bool) { + funds[_owner] = _amount; + return true; + } + /* + Rounds + */ + _rounds[] private rounds; + function getRound(uint256 _id) constant returns(bool, uint256, uint256, uint256, uint256, bool) { + if ( rounds.length <= _id ) { return (false, 0, 0, 0, 0, false); } + else { return (true, rounds[_id].totalAboveWeight, rounds[_id].totalBelowWeight, rounds[_id].reward, rounds[_id].blockHeight, rounds[_id].voted); } + } + function pushRound(uint256 _totalAboveWeight, uint256 _totalBelowWeight, uint256 _reward, uint256 _blockHeight, bool _voted) isOwner external returns(bool, uint256) { + return (true, rounds.push(_rounds(_totalAboveWeight, _totalBelowWeight, _reward, _blockHeight, _voted))); + } + function setRound(uint256 _id, uint256 _totalAboveWeight, uint256 _totalBelowWeight, uint256 _reward, uint256 _blockHeight, bool _voted) isOwner external returns(bool) { + rounds[_id] = _rounds(_totalAboveWeight, _totalBelowWeight, _reward, _blockHeight, _voted); + return true; + } + function getCurrentRound() constant returns(bool, uint256) { + return (true, rounds.length-1); + } + /* + Voter + */ + mapping(address => _voter) private voter; + function getVoter(address _owner) constant returns(bool success, uint256 roundID, + bytes32 hash, voterStatus status, bool voteResult, uint256 rewards) { + roundID = voter[_owner].roundID; + hash = voter[_owner].hash; + status = voter[_owner].status; + voteResult = voter[_owner].voteResult; + rewards = voter[_owner].rewards; + success = true; + } + function setVoter(address _owner, uint256 _roundID, bytes32 _hash, voterStatus _status, bool _voteResult, uint256 _rewards) isOwner external returns(bool) { + voter[_owner] = _voter( + _roundID, + _hash, + _status, + _voteResult, + _rewards + ); + return true; + } + /* + Schelling Token emission + */ + mapping(uint256 => uint256) private schellingExpansion; + function getSchellingExpansion(uint256 _id) constant returns(bool, uint256) { + return (true, schellingExpansion[_id]); + } + function setSchellingExpansion(uint256 _id, uint256 _expansion) isOwner external returns(bool) { + schellingExpansion[_id] = _expansion; + return true; + } + /* + Current Schelling Round + */ + uint256 private currentSchellingRound; + function setCurrentSchellingRound(uint256 _id) isOwner external returns(bool) { + currentSchellingRound = _id; + return true; + } + function getCurrentSchellingRound() constant returns(bool, uint256) { + return (true, currentSchellingRound); + } +} + +contract schelling is module, announcementTypes, schellingVars { + /* + Schelling contract + */ + /* + module callbacks + */ + function replaceModule(address addr) external returns (bool) { + require( super.isModuleHandler(msg.sender) ); + require( db.replaceOwner(addr) ); + super._replaceModule(addr); + return true; + } + function transferEvent(address from, address to, uint256 value) external returns (bool) { + /* + Transaction completed. This function can be called only by the ModuleHandler. + If this contract is the receiver, the amount will be added to the prize pool of the current round. + + @from From who + @to To who + @value Amount + @bool Was the transaction succesfull? + */ + require( super.isModuleHandler(msg.sender) ); + if ( to == address(this) ) { + var currentRound = getCurrentRound(); + var round = getRound(currentRound); + round.reward += value; + setRound(currentRound, round); + } + return true; + } + modifier isReady { + var (_success, _active) = super.isActive(); + require( _success && _active ); + _; + } + /* + Schelling database functions. + */ + function getFunds(address addr) internal returns (uint256) { + var (a, b) = db.getFunds(addr); + require( a ); + return b; + } + function setFunds(address addr, uint256 amount) internal { + require( db.setFunds(addr, amount) ); + } + function setVoter(address owner, _voter voter) internal { + require( db.setVoter(owner, + voter.roundID, + voter.hash, + voter.status, + voter.voteResult, + voter.rewards + ) ); + } + function getVoter(address addr) internal returns (_voter) { + var (a, b, c, d, e, f) = db.getVoter(addr); + require( a ); + return _voter(b, c, d, e, f); + } + function setRound(uint256 id, _rounds round) internal { + require( db.setRound(id, + round.totalAboveWeight, + round.totalBelowWeight, + round.reward, + round.blockHeight, + round.voted + ) ); + } + function pushRound(_rounds round) internal returns (uint256) { + var (a, b) = db.pushRound( + round.totalAboveWeight, + round.totalBelowWeight, + round.reward, + round.blockHeight, + round.voted + ); + require( a ); + return b; + } + function getRound(uint256 id) internal returns (_rounds) { + var (a, b, c, d, e, f) = db.getRound(id); + require( a ); + return _rounds(b, c, d, e, f); + } + function getCurrentRound() internal returns (uint256) { + var (a, b) = db.getCurrentRound(); + require( a ); + return b; + } + function setCurrentSchellingRound(uint256 id) internal { + require( db.setCurrentSchellingRound(id) ); + } + function getCurrentSchellingRound() internal returns(uint256) { + var (a, b) = db.getCurrentSchellingRound(); + require( a ); + return b; + } + function setSchellingExpansion(uint256 id, uint256 amount) internal { + require( db.setSchellingExpansion(id, amount) ); + } + function getSchellingExpansion(uint256 id) internal returns(uint256) { + var (a, b) = db.getSchellingExpansion(id); + require( a ); + return b; + } + /* + Schelling module + */ + uint256 private roundBlockDelay = 720; + uint8 private interestCheckRounds = 7; + uint8 private interestCheckAboves = 4; + uint256 private interestRate = 300; + uint256 private interestRateM = 1e3; + + bytes1 public aboveChar = 0x31; + bytes1 public belowChar = 0x30; + schellingDB private db; + + function schelling(address _moduleHandler, address _db, bool _forReplace) { + /* + Installation function. + + @_moduleHandler Address of ModuleHandler. + @_db Address of the database. + @_forReplace This address will be replaced with the old one or not. + @_icoExpansionAddress This address can turn schelling runds during ICO. + */ + db = schellingDB(_db); + super.registerModuleHandler(_moduleHandler); + if ( ! _forReplace ) { + require( db.replaceOwner(this) ); + } + } + function configure(announcementType a, uint256 b) external returns(bool) { + /* + Can be called only by the ModuleHandler. + + @a Sort of configuration + @b Value + */ + require( super.isModuleHandler(msg.sender) ); + if ( a == announcementType.schellingRoundBlockDelay ) { roundBlockDelay = b; } + else if ( a == announcementType.schellingCheckRounds ) { interestCheckRounds = uint8(b); } + else if ( a == announcementType.schellingCheckAboves ) { interestCheckAboves = uint8(b); } + else if ( a == announcementType.schellingRate ) { interestRate = b; } + else { return false; } + return true; + } + function prepareVote(bytes32 votehash, uint256 roundID) isReady noContract external { + /* + Initializing manual vote. + Only the hash of vote will be sent. (Envelope sending). + The address must be in default state, that is there are no vote in progress. + Votes can be sent only on the actually Schelling round. + + @votehash Hash of the vote + @roundID Number of Schelling round + */ + nextRound(); + + var currentRound = getCurrentRound(); + var round = getRound(currentRound); + _voter memory voter; + uint256 funds; + + require( roundID == currentRound ); + + voter = getVoter(msg.sender); + funds = getFunds(msg.sender); + + require( funds > 0 ); + require( voter.status == voterStatus.base ); + voter.roundID = currentRound; + voter.hash = votehash; + voter.status = voterStatus.afterPrepareVote; + + setVoter(msg.sender, voter); + round.voted = true; + + setRound(currentRound, round); + } + function sendVote(string vote) isReady noContract external { + /* + Check vote (Envelope opening) + Only the sent “envelopes” can be opened. + Envelope opening only in the next Schelling round. + If the vote invalid, the deposit will be lost. + If the “envelope” was opened later than 1,5 Schelling round, the vote is automatically invalid, and deposit can be lost. + Lost deposits will be 100% burned. + + @vote Hash of the content of the vote. + */ + nextRound(); + + var currentRound = getCurrentRound(); + _rounds memory round; + _voter memory voter; + uint256 funds; + + bool lostEverything; + voter = getVoter(msg.sender); + round = getRound(voter.roundID); + funds = getFunds(msg.sender); + + require( voter.status == voterStatus.afterPrepareVote ); + require( voter.roundID < currentRound ); + if ( sha3(vote) == voter.hash ) { + delete voter.hash; + if (round.blockHeight+roundBlockDelay/2 >= block.number) { + if ( bytes(vote)[0] == aboveChar ) { + voter.status = voterStatus.afterSendVoteOk; + round.totalAboveWeight += funds; + voter.voteResult = true; + } else if ( bytes(vote)[0] == belowChar ) { + voter.status = voterStatus.afterSendVoteOk; + round.totalBelowWeight += funds; + } else { lostEverything = true; } + } else { + voter.status = voterStatus.afterSendVoteBad; + } + } else { lostEverything = true; } + if ( lostEverything ) { + require( moduleHandler(moduleHandlerAddress).burn(address(this), funds) ); + delete funds; + delete voter.status; + } + + setVoter(msg.sender, voter); + setRound(voter.roundID, round); + setFunds(msg.sender, funds); + } + function checkVote() isReady noContract external { + /* + Checking votes. + Vote checking only after the envelope opening Schelling round. + Deposit will be lost, if the vote wrong, or invalid. + The right votes take share of deposits. + */ + nextRound(); + + var currentRound = getCurrentRound(); + _rounds memory round; + _voter memory voter; + uint256 funds; + + voter = getVoter(msg.sender); + round = getRound(voter.roundID); + funds = getFunds(msg.sender); + + require( voter.status == voterStatus.afterSendVoteOk || + voter.status == voterStatus.afterSendVoteBad ); + if ( round.blockHeight+roundBlockDelay/2 <= block.number ) { + if ( isWinner(round, voter.voteResult) && voter.status == voterStatus.afterSendVoteOk ) { + voter.rewards += funds * round.reward / getRoundWeight(round.totalAboveWeight, round.totalBelowWeight); + } else { + require( moduleHandler(moduleHandlerAddress).burn(address(this), funds) ); + delete funds; + } + delete voter.status; + delete voter.roundID; + } else { throw; } + + setVoter(msg.sender, voter); + setFunds(msg.sender, funds); + } + function getRewards(address beneficiary) isReady noContract external { + /* + Redeem of prize. + The prizes will be collected here, and with this function can be transferred to the account of the user. + Optionally there can be an address of a beneficiary added, which address the prize will be sent to. Without beneficiary, the owner is the default address. + Prize will be sent from the Schelling address without any transaction fee. + + @beneficiary Address of the beneficiary + */ + var voter = getVoter(msg.sender); + var funds = getFunds(msg.sender); + + address _beneficiary = msg.sender; + if (beneficiary != 0x0) { _beneficiary = beneficiary; } + uint256 reward; + require( voter.rewards > 0 ); + require( voter.status == voterStatus.base ); + reward = voter.rewards; + delete voter.rewards; + require( moduleHandler(moduleHandlerAddress).transfer(address(this), _beneficiary, reward, false) ); + + setVoter(msg.sender, voter); + } + function checkReward() public constant returns (uint256 reward) { + /* + Withdraw of the amount of the prize (it’s only information). + + @reward Prize + */ + var voter = getVoter(msg.sender); + return voter.rewards; + } + function nextRound() internal returns (bool) { + /* + Inside function, checks the time of the Schelling round and if its needed, creates a new Schelling round. + */ + var currentRound = getCurrentRound(); + var round = getRound(currentRound); + _rounds memory newRound; + _rounds memory prevRound; + var currentSchellingRound = getCurrentSchellingRound(); + + if ( round.blockHeight+roundBlockDelay > block.number) { return false; } + + newRound.blockHeight = block.number; + if ( ! round.voted ) { + newRound.reward = round.reward; + } + uint256 aboves; + for ( uint256 a=currentRound ; a>=currentRound-interestCheckRounds ; a-- ) { + if (a == 0) { break; } + prevRound = getRound(a); + if ( prevRound.totalAboveWeight > prevRound.totalBelowWeight ) { aboves++; } + } + uint256 expansion; + if ( aboves >= interestCheckAboves ) { + expansion = getTotalSupply() * interestRate / interestRateM / 100; + } + + currentSchellingRound++; + + pushRound(newRound); + setSchellingExpansion(currentSchellingRound, expansion); + require( moduleHandler(moduleHandlerAddress).broadcastSchellingRound(currentSchellingRound, expansion) ); + return true; + } + function addFunds(uint256 amount) isReady noContract external { + /* + Deposit taking. + Every participant entry with his own deposit. + In case of wrong vote only this amount of deposit will be burn. + The deposit will be sent to the address of Schelling, charged with transaction fee. + + @amount Amount of deposit. + */ + var voter = getVoter(msg.sender); + var funds = getFunds(msg.sender); + + var (a, b) = moduleHandler(moduleHandlerAddress).isICO(); + require( b && b ); + require( voter.status == voterStatus.base ); + require( amount > 0 ); + require( moduleHandler(moduleHandlerAddress).transfer(msg.sender, address(this), amount, true) ); + funds += amount; + + setFunds(msg.sender, funds); + } + function getFunds() isReady noContract external { + /* + Deposit withdrawn. + If the deposit isn’t lost, it can be withdrawn. + By withdrawn, the deposit will be sent from Schelling address to the users address, charged with transaction fee.. + */ + var voter = getVoter(msg.sender); + var funds = getFunds(msg.sender); + + require( funds > 0 ); + require( voter.status == voterStatus.base ); + setFunds(msg.sender, 0); + + require( moduleHandler(moduleHandlerAddress).transfer(address(this), msg.sender, funds, true) ); + } + function getCurrentSchellingRoundID() public constant returns (uint256) { + /* + Number of actual Schelling round. + + @uint256 Schelling round. + */ + return getCurrentSchellingRound(); + } + function getSchellingRound(uint256 id) public constant returns (uint256 expansion) { + /* + Amount of token emission of the Schelling round. + + @id Number of Schelling round + @expansion Amount of token emission + */ + return getSchellingExpansion(id); + } + function getRoundWeight(uint256 aboveW, uint256 belowW) internal returns (uint256) { + /* + Inside function for calculating the weights of the votes. + + @aboveW Weight of votes: ABOVE + @belowW Weight of votes: BELOW + @uint256 Calculatet weight + */ + if ( aboveW == belowW ) { + return aboveW + belowW; + } else if ( aboveW > belowW ) { + return aboveW; + } else if ( aboveW < belowW) { + return belowW; + } + } + function isWinner(_rounds round, bool aboveVote) internal returns (bool) { + /* + Inside function for calculating the result of the game. + + @round Structure of Schelling round. + @aboveVote Is the vote = ABOVE or not + @bool Result + */ + if ( round.totalAboveWeight == round.totalBelowWeight || + ( round.totalAboveWeight > round.totalBelowWeight && aboveVote ) ) { + return true; + } + return false; + } + + function getTotalSupply() internal returns (uint256 amount) { + /* + Inside function for querying the whole amount of the tokens. + + @uint256 Whole token amount + */ + var (_success, _amount) = moduleHandler(moduleHandlerAddress).totalSupply(); + require( _success ); + return _amount; + } + + function getTokenBalance(address addr) internal returns (uint256 balance) { + /* + Inner function in order to poll the token balance of the address. + + @addr Address + + @balance Balance of the address. + */ + var (_success, _balance) = moduleHandler(moduleHandlerAddress).balanceOf(addr); + require( _success ); + return _balance; + } + + modifier noContract { + /* + Contract can’t call this function, only a natural address. + */ + require( msg.sender == tx.origin ); _; + } +} diff --git a/test/compilationTests/corion/token.sol b/test/compilationTests/corion/token.sol new file mode 100644 index 00000000..3aa0bf23 --- /dev/null +++ b/test/compilationTests/corion/token.sol @@ -0,0 +1,518 @@ +pragma solidity ^0.4.11; + +import "./announcementTypes.sol"; +import "./safeMath.sol"; +import "./module.sol"; +import "./moduleHandler.sol"; +import "./tokenDB.sol"; + +contract thirdPartyContractAbstract { + function receiveCorionToken(address, uint256, bytes) external returns (bool, uint256) {} + function approvedCorionToken(address, uint256, bytes) external returns (bool) {} +} + +contract token is safeMath, module, announcementTypes { + /* + module callbacks + */ + function replaceModule(address addr) external returns (bool success) { + require( super.isModuleHandler(msg.sender) ); + require( db.replaceOwner(addr) ); + super._replaceModule(addr); + return true; + } + modifier isReady { + var (_success, _active) = super.isActive(); + require( _success && _active ); + _; + } + /** + * + * @title Corion Platform Token + * @author iFA @ Corion Platform + * + */ + string public name = "Corion"; + string public symbol = "COR"; + uint8 public decimals = 6; + + tokenDB public db; + address public icoAddr; + uint256 public transactionFeeRate = 20; + uint256 public transactionFeeRateM = 1e3; + uint256 public transactionFeeMin = 20000; + uint256 public transactionFeeMax = 5000000; + uint256 public transactionFeeBurn = 80; + address public exchangeAddress; + bool public isICO = true; + + mapping(address => bool) public genesis; + + function token(bool forReplace, address moduleHandler, address dbAddr, address icoContractAddr, address exchangeContractAddress, address[] genesisAddr, uint256[] genesisValue) payable { + /* + Installation function + + When _icoAddr is defined, 0.2 ether has to be attached as many times as many genesis addresses are given + + @forReplace This address will be replaced with the old one or not. + @moduleHandler Modulhandler's address + @dbAddr Address of database + @icoContractAddr Address of ICO contract + @exchangeContractAddress Address of Market in order to buy gas during ICO + @genesisAddr Array of Genesis addresses + @genesisValue Array of balance of genesis addresses + */ + super.registerModuleHandler(moduleHandler); + require( dbAddr != 0x00 ); + require( icoContractAddr != 0x00 ); + require( exchangeContractAddress != 0x00 ); + db = tokenDB(dbAddr); + icoAddr = icoContractAddr; + exchangeAddress = exchangeContractAddress; + isICO = ! forReplace; + if ( ! forReplace ) { + require( db.replaceOwner(this) ); + assert( genesisAddr.length == genesisValue.length ); + require( this.balance >= genesisAddr.length * 0.2 ether ); + for ( uint256 a=0 ; a= amount ); + require( db.setAllowance(msg.sender, spender, amount, nonce) ); + Approval(msg.sender, spender, amount); + } + + function allowance(address owner, address spender) constant returns (uint256 remaining, uint256 nonce) { + /* + Get the quantity of tokens given to be used + + @owner Authorising address + @spender Authorised address + + @remaining Tokens to be spent + @nonce Transaction count + */ + var (_success, _remaining, _nonce) = db.getAllowance(owner, spender); + require( _success ); + return (_remaining, _nonce); + } + + /** + * @notice Send `amount` Corion tokens to `to` from `msg.sender` + * @param to The address of the recipient + * @param amount The amount of tokens to be transferred + * @return Whether the transfer was successful or not + */ + function transfer(address to, uint256 amount) isReady external returns (bool success) { + /* + Start transaction, token is sent from caller’s address to receiver’s address + Transaction fee is to be deducted. + If receiver is not a natural address but a person, he will be called + + @to To who + @amount Quantity + + @success Was the Function successful? + */ + bytes memory _data; + if ( isContract(to) ) { + _transferToContract(msg.sender, to, amount, _data); + } else { + _transfer( msg.sender, to, amount, true); + } + Transfer(msg.sender, to, amount, _data); + return true; + } + + /** + * @notice Send `amount` tokens to `to` from `from` on the condition it is approved by `from` + * @param from The address holding the tokens being transferred + * @param to The address of the recipient + * @param amount The amount of tokens to be transferred + * @return True if the transfer was successful + */ + function transferFrom(address from, address to, uint256 amount) isReady external returns (bool success) { + /* + Start transaction to send a quantity from a given address to another address. (approve / allowance). This can be called only by the address approved in advance + Transaction fee is to be deducted + If receiver is not a natural address but a person, he will be called + + @from From who. + @to To who + @amount Quantity + + @success Was the Function successful? + */ + if ( from != msg.sender ) { + var (_success, _reamining, _nonce) = db.getAllowance(from, msg.sender); + require( _success ); + _reamining = safeSub(_reamining, amount); + _nonce = safeAdd(_nonce, 1); + require( db.setAllowance(from, msg.sender, _reamining, _nonce) ); + AllowanceUsed(msg.sender, from, amount); + } + bytes memory _data; + if ( isContract(to) ) { + _transferToContract(from, to, amount, _data); + } else { + _transfer( from, to, amount, true); + } + Transfer(from, to, amount, _data); + return true; + } + + /** + * @notice Send `amount` tokens to `to` from `from` on the condition it is approved by `from` + * @param from The address holding the tokens being transferred + * @param to The address of the recipient + * @param amount The amount of tokens to be transferred + * @return True if the transfer was successful + */ + function transferFromByModule(address from, address to, uint256 amount, bool fee) isReady external returns (bool success) { + /* + Start transaction to send a quantity from a given address to another address + Only ModuleHandler can call it + + @from From who + @to To who. + @amount Quantity + @fee Deduct transaction fee - yes or no? + + @success Was the Function successful? + */ + bytes memory _data; + require( super.isModuleHandler(msg.sender) ); + _transfer( from, to, amount, fee); + Transfer(from, to, amount, _data); + return true; + } + + /** + * @notice Send `amount` Corion tokens to `to` from `msg.sender` and notify the receiver from your transaction with your `extraData` data + * @param to The contract address of the recipient + * @param amount The amount of tokens to be transferred + * @param extraData Data to give forward to the receiver + * @return Whether the transfer was successful or not + */ + function transfer(address to, uint256 amount, bytes extraData) isReady external returns (bool success) { + /* + Start transaction to send a quantity from a given address to another address + After transaction the function `receiveCorionToken`of the receiver is called by the given data + When sending an amount, it is possible the total amount cannot be processed, the remaining amount is sent back with no fee charged + + @to To who. + @amount Quantity + @extraData Extra data the receiver will get + + @success Was the Function successful? + */ + if ( isContract(to) ) { + _transferToContract(msg.sender, to, amount, extraData); + } else { + _transfer( msg.sender, to, amount, true); + } + Transfer(msg.sender, to, amount, extraData); + return true; + } + + function _transferToContract(address from, address to, uint256 amount, bytes extraData) internal { + /* + Internal function to start transactions to a contract + + @from From who + @to To who. + @amount Quantity + @extraData Extra data the receiver will get + */ + _transfer(from, to, amount, exchangeAddress == to); + var (_success, _back) = thirdPartyContractAbstract(to).receiveCorionToken(from, amount, extraData); + require( _success ); + require( amount > _back ); + if ( _back > 0 ) { + _transfer(to, from, _back, false); + } + _processTransactionFee(from, amount - _back); + } + + function _transfer(address from, address to, uint256 amount, bool fee) internal { + /* + Internal function to start transactions. When Tokens are sent, transaction fee is charged + During ICO transactions are allowed only from genesis addresses. + After sending the tokens, the ModuleHandler is notified and it will broadcast the fact among members + + The 0xa636a97578d26a3b76b060bbc18226d954cf3757 address are blacklisted. + + @from From who + @to To who + @amount Quantity + @fee Deduct transaction fee - yes or no? + */ + if( fee ) { + var (success, _fee) = getTransactionFee(amount); + require( success ); + require( db.balanceOf(from) >= amount + _fee ); + } + require( from != 0x00 && to != 0x00 && to != 0xa636a97578d26a3b76b060bbc18226d954cf3757 ); + require( ( ! isICO) || genesis[from] ); + require( db.decrease(from, amount) ); + require( db.increase(to, amount) ); + if ( fee ) { _processTransactionFee(from, amount); } + if ( isICO ) { + require( ico(icoAddr).setInterestDB(from, db.balanceOf(from)) ); + require( ico(icoAddr).setInterestDB(to, db.balanceOf(to)) ); + } + require( moduleHandler(moduleHandlerAddress).broadcastTransfer(from, to, amount) ); + } + + /** + * @notice Transaction fee will be deduced from `owner` for transacting `value` + * @param owner The address where will the transaction fee deduced + * @param value The base for calculating the fee + * @return True if the transfer was successful + */ + function processTransactionFee(address owner, uint256 value) isReady external returns (bool success) { + /* + Charge transaction fee. It can be called only by moduleHandler + + @owner From who. + @value Quantity to calculate the fee + + @success Was the Function successful? + */ + require( super.isModuleHandler(msg.sender) ); + _processTransactionFee(owner, value); + return true; + } + + function _processTransactionFee(address owner, uint256 value) internal { + /* + Internal function to charge the transaction fee. A certain quantity is burnt, the rest is sent to the Schelling game prize pool. + No transaction fee during ICO. + + @owner From who + @value Quantity to calculate the fee + */ + if ( isICO ) { return; } + var (_success, _fee) = getTransactionFee(value); + require( _success ); + uint256 _forBurn = _fee * transactionFeeBurn / 100; + uint256 _forSchelling = _fee - _forBurn; + bool _found; + address _schellingAddr; + (_success, _found, _schellingAddr) = moduleHandler(moduleHandlerAddress).getModuleAddressByName('Schelling'); + require( _success ); + if ( _schellingAddr != 0x00 && _found) { + require( db.decrease(owner, _forSchelling) ); + require( db.increase(_schellingAddr, _forSchelling) ); + _burn(owner, _forBurn); + bytes memory _data; + Transfer(owner, _schellingAddr, _forSchelling, _data); + require( moduleHandler(moduleHandlerAddress).broadcastTransfer(owner, _schellingAddr, _forSchelling) ); + } else { + _burn(owner, _fee); + } + } + + function getTransactionFee(uint256 value) public constant returns (bool success, uint256 fee) { + /* + Transaction fee query. + + @value Quantity to calculate the fee + + @success Was the Function successful? + @fee Amount of Transaction fee + */ + if ( isICO ) { return (true, 0); } + fee = value * transactionFeeRate / transactionFeeRateM / 100; + if ( fee > transactionFeeMax ) { fee = transactionFeeMax; } + else if ( fee < transactionFeeMin ) { fee = transactionFeeMin; } + return (true, fee); + } + + function mint(address owner, uint256 value) isReady external returns (bool success) { + /* + Generating tokens. It can be called only by ICO contract or the moduleHandler. + + @owner Address + @value Amount. + + @success Was the Function successful? + */ + require( super.isModuleHandler(msg.sender) || msg.sender == icoAddr ); + _mint(owner, value); + return true; + } + + function _mint(address owner, uint256 value) internal { + /* + Internal function to generate tokens + + @owner Token is credited to this address + @value Quantity + */ + require( db.increase(owner, value) ); + require( moduleHandler(moduleHandlerAddress).broadcastTransfer(0x00, owner, value) ); + if ( isICO ) { + require( ico(icoAddr).setInterestDB(owner, db.balanceOf(owner)) ); + } + Mint(owner, value); + } + + function burn(address owner, uint256 value) isReady external returns (bool success) { + /* + Burning the token. Can call only modulehandler + + @owner Burn the token from this address + @value Quantity + + @success Was the Function successful? + */ + require( super.isModuleHandler(msg.sender) ); + _burn(owner, value); + return true; + } + + function _burn(address owner, uint256 value) internal { + /* + Internal function to burn the token + + @owner Burn the token from this address + @value Quantity + */ + require( db.decrease(owner, value) ); + require( moduleHandler(moduleHandlerAddress).broadcastTransfer(owner, 0x00, value) ); + Burn(owner, value); + } + + function isContract(address addr) internal returns (bool success) { + /* + Internal function to check if the given address is natural, or a contract + + @addr Address to be checked + + @success Is the address crontact or not + */ + uint256 _codeLength; + assembly { + _codeLength := extcodesize(addr) + } + return _codeLength > 0; + } + + function balanceOf(address owner) constant returns (uint256 value) { + /* + Token balance query + + @owner Address + + @value Balance of address + */ + return db.balanceOf(owner); + } + + function totalSupply() constant returns (uint256 value) { + /* + Total token quantity query + + @value Total token quantity + */ + return db.totalSupply(); + } + + function configure(announcementType aType, uint256 value) isReady external returns(bool success) { + /* + Token settings configuration.It can be call only by moduleHandler + + @aType Type of setting + @value Value + + @success Was the Function successful? + */ + require( super.isModuleHandler(msg.sender) ); + if ( aType == announcementType.transactionFeeRate ) { transactionFeeRate = value; } + else if ( aType == announcementType.transactionFeeMin ) { transactionFeeMin = value; } + else if ( aType == announcementType.transactionFeeMax ) { transactionFeeMax = value; } + else if ( aType == announcementType.transactionFeeBurn ) { transactionFeeBurn = value; } + else { return false; } + return true; + } + + event AllowanceUsed(address indexed spender, address indexed owner, uint256 indexed value); + event Mint(address indexed addr, uint256 indexed value); + event Burn(address indexed addr, uint256 indexed value); + event Approval(address indexed _owner, address indexed _spender, uint256 _value); + event Transfer(address indexed _from, address indexed _to, uint256 indexed _value, bytes _extraData); +} diff --git a/test/compilationTests/corion/tokenDB.sol b/test/compilationTests/corion/tokenDB.sol new file mode 100644 index 00000000..6de1b6c3 --- /dev/null +++ b/test/compilationTests/corion/tokenDB.sol @@ -0,0 +1,77 @@ +pragma solidity ^0.4.11; + +import "./safeMath.sol"; +import "./owned.sol"; + +contract tokenDB is safeMath, ownedDB { + + struct allowance_s { + uint256 amount; + uint256 nonce; + } + + mapping(address => mapping(address => allowance_s)) public allowance; + mapping (address => uint256) public balanceOf; + uint256 public totalSupply; + + function increase(address owner, uint256 value) external returns(bool success) { + /* + Increase of balance of the address in database. Only owner can call it. + + @owner Address + @value Quantity + + @success Was the Function successful? + */ + require( isOwner() ); + balanceOf[owner] = safeAdd(balanceOf[owner], value); + totalSupply = safeAdd(totalSupply, value); + return true; + } + + function decrease(address owner, uint256 value) external returns(bool success) { + /* + Decrease of balance of the address in database. Only owner can call it. + + @owner Address + @value Quantity + + @success Was the Function successful? + */ + require( isOwner() ); + balanceOf[owner] = safeSub(balanceOf[owner], value); + totalSupply = safeSub(totalSupply, value); + return true; + } + + function setAllowance(address owner, address spender, uint256 amount, uint256 nonce) external returns(bool success) { + /* + Set allowance in the database. Only owner can call it. + + @owner Owner address + @spender Spender address + @amount Amount to set + @nonce Transaction count + + @success Was the Function successful? + */ + require( isOwner() ); + allowance[owner][spender].amount = amount; + allowance[owner][spender].nonce = nonce; + return true; + } + + function getAllowance(address owner, address spender) constant returns(bool success, uint256 remaining, uint256 nonce) { + /* + Get allowance from the database. + + @owner Owner address + @spender Spender address + + @success Was the Function successful? + @remaining Remaining amount of the allowance + @nonce Transaction count + */ + return ( true, allowance[owner][spender].amount, allowance[owner][spender].nonce ); + } +} -- cgit