Alien Worlds engineers sharing the experience of creating smart contracts that foster effective decentralized governance.
Web3 is about empowering users, and as a Web3 gaming ecosystem, Dacoco is committed to keeping Alien Worlds and its processes decentralized and making sure the users get as much control as possible. With control comes transparency, so we would like to take the community through some of our technical thinking.
Our commitment to decentralization is embedded into the very architecture of Alien Worlds: the different planets that compose our metaverse are governed by DAOs (Planetary Syndicates), entrusted with taking planet-related decisions and using their treasuries to implement them.
In the spirit of Web3, we want our DAOs to enjoy a high level of autonomy and be able to define their own governance rules: voting periods, number of custodians, the quorum necessary to take different types of decisions…etc.
In other words, we want Alien Worlds’ DAOs to be able to run themselves and evolve according to the users’ will, allowing even further decentralization down the line. To achieve that, we must carefully design the DAOs’ smart contracts, ensuring that they are configurable and that the DAOs will be able to change their settings in the future.
In addition, we are dedicated to upholding one of the core principles of web3 — keeping the core actions and control of data decentralized, which also means keeping the maximum number of actions on-chain, including the DAOs voting process.
These intentions are not without their fair share of difficulties, but we have devised effective solutions to overcome them. Here are some examples.
One of the important programming approaches for achieving configurability is the avoidance of magic numbers.
Magic numbers are a software engineering term referring to arbitrary constant numbers used in the source code. Using magic numbers is a bad programming practice in general, impending future code modifications, but it is particularly detrimental when it comes to Web3.
The very purpose of Alien Worlds’ DAOs is to enable users to modify certain aspects of the game, so naturally, we paid special attention to avoiding magic numbers.
Instead of hardcoding game settings into the smart contracts, we have created tables inside the code, specifying different game features and assigning them customizable default values. These values can then be modified by the DAOs.
This approach allows for dynamic configuration and enhances code flexibility: if a DAO wishes to change, for example, the number of its custodians, the update is implemented without having to recompile the whole code but only by changing the option on the code as it runs.
Moreover, we made sure that even within the same smart contract, every DAO can have its own settings, isolated to its own memory space, allowing for all of them to work beside each other harmoniously.
Keeping Things On-chain
One of the distinctive features of Alien Worlds’ DAOs is that all their business logic happens on the blockchain.
Unlike many protocols that choose the easy option of moving the voting processes off-chain, often to Discord, we pride ourselves on keeping everything on-chain. This approach eliminates the single point of failure that centralized services can become and the resulting security threats (unfortunately, Discord channel hacks are common).
Naturally, the all-on-chain principle brings its own challenges.
For example, counting votes. The DAOs decisions are taken by a group of custodians, elected for a fixed period by the DAO members. For a smooth game experience, we need to always have an up-to-date sorted table ranking top custodian candidates. However, Alien Worlds is a popular metaverse, and constantly launching smart contracts tallying the votes can be very expensive from the computational perspective.
We were faced with quite a complicated engineering task of counting votes without congesting the blockchain, and we tackled it via a voting smart contract. We have structured it in a way that the sorting and the ranking of the highest-ordered candidates are updated in the very instance of voting.
This was made possible by using the multi-index sorting of table data — a feature unique to Antelope, the technology protocol underlying WAX blockchain. Whenever any of the rows in the tables holding the vote data are updated, the information is instantly sorted according to various criteria needed to rank the highest voted DAO candidates.
As a result, there’s no expensive and potentially troublesome counting operation that needs to ever happen: the votes are continually counting themselves.
Decentralized governance is one of the key features of Alien Worlds, and we are determined to ensure its effectiveness, all while staying true to the core tenets of web3.
(Reposted from this Medium article)