Inspiration
For the layman, investing in the stock market can spell terrible consequences if he or she does not have adequate knowledge and experience. A lack of awareness of market mechanics or of the quality of shares purchased mean that they are significantly disadvantaged, especially against more informed professional investors. Our team seeks to provide another form of financial products which anybody can invest in, is significantly divorced from the realm of wild price swings and one which offers a fairer playing field for people with expertise in different fields of knowledge.
What it does
The idea is simple: we enable our users, or our stakers, to stake on world events. These events can be related to global warming, such as the atmospheric temperature in 2025, to those involving politics, such as the next President of the United States. Stakers can invest in either “for” or “against '' a certain event happening, and if proven right after a specified deadline, they are rewarded. Invested stakes form two separate pools of funds. In this early iteration, we use a “losers pays winners” model, where the proportion of stake one has in the winning pool will equal the proportion he or she receives from the losing pool (also receive the initial principal amount in the winning pool).
How it was built
To enable the idea, we have decided to use smart contracts written in Clarity on the Stack 2.0 Blockchain and transact in STX. We built it by leveraging the map function of Clarity and its many other useful functions. These maps were used to keep track of individual events, stakes, and the link between events and stakes. This information can then be easily accessed by the functions. We also used the accessibility feature of Clarity extensively, keeping most functions private and only the most needed ones public. By segmenting large functions into smaller ones, made impressively easily by the Clarity language, we further improved the readability of the code. This, together with the easy to understand nature of the language, made the debugging process quick and efficient.
Challenges
The main challenge we faced when writing the smart contract was ensuring that the execution steps were logical, efficient, and most importantly, secure. As our product deals with actual STX once deployed on the main net, it is of utmost importance to make sure the smart contract does not have any obvious vulnerabilities susceptible to amateur, malicious attacks. Whilst keeping the data on the smart contract as lightweight as possible, we kept crucial information and specific boolean variables (such as if a STX was claimed before, if the results of the event had been announced by the administrator wtc.) to allow claims made by users to be validated. The order in which these assertions were made also had to be well-thought through, going in a systematic basis to prevent malicious public function calls in quick succession. While it might be an easy way out to offload this to the frontend of the application, we believe that the smart contract should be robust enough on its own.
Accomplishments and Lessons Learnt
We are particularly proud of our completion of the smart contract, which forms the bedrock of our product, especially after overcoming many setbacks, such as failed implementations and approaches. We also had to get used to a different programming paradigm in a short period of time, as we signed up for this late. Through this memorable experience, we have better understood the strengths and limitations of smart contracts, and the quirks of thinking functionally.
What's next for Clarity
Clarity is an interesting take on a smart contract programming language. While its Turing incompleteness might seem like a hassle at first, we have come to greatly appreciate its security and other benefits. We can see it becoming a more widely used language in the Web3.0 space, especially with the very innovative ‘Proof of Transaction’ model adopted by the Stack 2.0 Blockchain. As a relatively new language, we appreciate that Clarity is still maturing. There are certain enhancements that can be made to the language, such as to improve the handling of tuples (by allowing the ability to update multiple tuple fields together) or to add more support for data structures (inserting other complex types into hash maps, or even enumerating the hash map itself!).
With the recent cases of security breaches in smart contracts running on other blockchains, we foresee Clarity taking huge strides forward in its attempt at reinventing the concept of smart contracts.
Log in or sign up for Devpost to join the conversation.