Alien Worlds is a blockchain-based metaverse that simulates economic cooperation and competition among players. This repository contains the core smart contracts that power the Alien Worlds ecosystem on the WAX blockchain.
These smart contracts form the backbone of various game mechanics including mining, staking, governance, and NFT management, enabling players to mine Trilium (TLM), participate in Planet DAOs, and engage in various in-game activities.
- Mining System: Handles resource mining mechanics and rewards distribution
- NFT Management: Powered by AtomicAssets for in-game items
- Planetary Governance: DAO structure for planet management
- Token System: TLM token management and distribution
- Staking Mechanics: Token staking and rewards
- Game Features: Competitions, gladiator battles, and more
The Alien Worlds ecosystem is built on a sophisticated network of interconnected smart contracts. The system architecture is visualized in the following diagram:
graph TD
%% Define styles for better clarity
classDef primary fill:#f9f,stroke:#333,stroke-width:2px;
classDef secondary fill:#ffe6cc,stroke:#333,stroke-width:1px;
classDef voting fill:#e6e6fa,stroke:#333,stroke-width:1px;
classDef interaction fill:#b3d9ff,stroke:#333,stroke-width:1px;
%% Main Nodes
C[FEDERATION CONTRACT]:::primary
K[INFLATION CONTRACT]:::primary
D[PLANET ACCOUNT authority]:::secondary
E[DAC VOTING CONTRACT]:::voting
H[token.worlds TOKEN CONTRACT]:::secondary
J[Player]:::interaction
F[index.worlds]:::voting
G[msig.worlds]:::voting
I[alien.worlds]:::interaction
%% Connections and Processes
D -->|Calls claim daily| K
K -->|Distributes inflation: DTAP, DTAL, DTAS, DTAB| H
K -->|Transfers to planet reserve and fills mining| D
D -->|Update auth on new period| E
E --> F
E --> G
C -->|Stake action: Trillium is sent to the federation| H
H -->|Contains DAC tokens only| H
H -->|Federation Contract has permission to issue DAC tokens for each planet| I
H -->|Planet DAC Tokens are issued to Player| J
J -->|Vote Action| E
%% Styling and grouping
subgraph Contracts and Authorities
C
K
D
H
end
subgraph Voting Flow
E
F
G
end
subgraph Player Interaction
J
I
end
The architecture illustrates the following key components and their interactions:
- Mining Contract (
m.federation): Central gameplay mechanics - Federation Contract (
federation): Game-wide governance - Planets Contract: Planetary management and governance
- Inflation Contract (
infl/, account:inflt.worlds): Daily TLM inflation and planet claims
- TLM Token (
alien.worlds): Native cryptocurrency - AtomicAssets (
atomicassets): NFT standard implementation
- Competitions: Tournament and event management
- Gladiator System: Combat mechanics
- Staking: Token staking and rewards
- Landholders (
contracts/landholders/, account:awlndratings): Land ownership, commissions, attributes - Landboost (
contracts/landboost/, account:boost.worlds): Land enhancement mechanics and boost durations
- User Points (
uspts.worlds): Point tracking system - Points Proxy: External point system integration
- Random Generator (
orng.wax): Verifiable randomness - Scheduled Payments: Automated reward distribution
- NFT Mint Controller: Minting rules and distribution
- Pack Opener: NFT pack mechanics
The system is designed with modularity in mind, allowing for:
- Independent component scaling
- Feature isolation
- Clear responsibility boundaries
- Efficient resource management
- Secure cross-contract communication
The Alien Worlds ecosystem is built on a sophisticated network of interconnected smart contracts, each serving specific functions in the game's economy and mechanics:
- Purpose: Manages the core mining gameplay mechanics
- Key Features:
- Mining rewards calculation and distribution
- Tool/NFT usage tracking and cooldowns
- Land commission system
- Anti-bot protection mechanisms
- Mining difficulty adjustments
- Rarity-based reward pools
- Key Actions:
mine,claimmines,setbag,setland
- Purpose: Handles planetary governance and management
- Key Features:
- Planet registration and management
- Land mapping system (x,y coordinates)
- Planetary stake tracking
- NFT multiplier management
- Planet metadata management
- Key Actions:
addplanet,updateplanet,setmap
- Purpose: Manages the Trilium (TLM) cryptocurrency
- Features:
- Token transfers
- Balance tracking
- Token emission controls
- Purpose: NFT management system
- Features:
- NFT minting and burning
- Asset transfers
- Metadata management
- Template management
- Purpose: Manages game-wide governance and mechanics
- Features:
- Global parameters
- Cross-planetary interactions
- Federation-level decision making
- Purpose: Calculates and mints daily Trilium inflation, and manages planet claims
- Features:
inflate: Computes daily inflation capped byDAILY_INFLATION_CAP_UNITSand splits into DTAP (planets), DTAL (landowners), DTAS (satellites), DTAB- Tracks per-planet payouts in
payoutsand per-DAC payouts indacpayouts claim: Called by planet accounts to receive reserve and mining allocations; triggersmining.fillfor the mining portion
- Purpose: Handles token staking mechanics
- Features:
- Stake management
- Reward distribution
- Planetary governance weight
- Unstaking timelock
- Purpose: Manages in-game competitions and events
- Features:
- Competition creation and management
- Reward distribution
- Leaderboard tracking
- Purpose: Combat and event mechanics
- Features:
- Battle flows and rewards
- Administration actions for events
- Purpose: Power accrual and related configuration
- Features:
- Power per day configuration
- Progression tracking
- Purpose: Manages land ownership and properties
- Features:
- Land ownership tracking
- Commission management
- Land attributes and metadata
- Purpose: Handles land enhancement mechanics
- Features:
- Land attribute boosting
- Temporary power-ups
- Boost duration tracking
- Purpose: Controls NFT minting processes
- Features:
- Minting rules and limits
- Rarity distribution
- Template management
- Purpose: Handles NFT pack opening mechanics
- Features:
- Pack contents generation
- Rarity calculations
- Reward distribution
- Purpose: Item enhancement/shining flows
- Features:
- Shining actions and validation
- Reward and result management
- Purpose: Provides verifiable randomness
- Features:
- Random number generation
- Seed management
- Verification system
- Purpose: Manages scheduled payments and rewards
- Features:
- Automated payments
- Payment scheduling
- Distribution tracking
- Purpose: Cross-contract notification utilities
- Features:
- Notification hooks
- Integration points for events
- Purpose: Teleport trigger and testing helpers
- Features:
- Scheduled/triggered teleport actions
- Test scaffolding via mock contract
- Purpose: Lightweight market utilities for tests
- Features:
- Simplified market operations for testing scenarios
- Purpose: Manages user point system
- Features:
- Point tracking
- Reward calculations
- Achievement system
- Purpose: Interfaces with external point systems
- Features:
- Cross-platform point integration
- Point conversion
- External system communication
- Purpose: Shared utilities and helpers
- Features:
- Common data structures
- Shared functions
- Helper utilities
- Purpose: Vendor governance modules used by Planet DAOs
- Notes:
- Tests are excluded by default in this repository (see
.lamingtonrc)
- Tests are excluded by default in this repository (see
Each contract is designed to be modular and interoperable, allowing for flexible game mechanics and future expansions.
- Blockchain: EOSIO/Antelope/Leap
- Development Framework: Lamington
- Testing: Chai/Mocha
- Smart Contract Language: C++
- Build System: EOSIO.CDT
- Node.js 18 (use
nvm useto select the version from.nvmrc) - Docker (for local development)
- Clone the repository:
git clone --recursive https://github.com/Alien-Worlds/alienworlds-contracts.git
cd alienworlds-contracts- Install dependencies:
npm install# Husky hooks install automatically via npm prepare
npm install
# Verify formatting on staged files
npx lint-staged --debugnpm run buildnpm testThe build process uses Lamington, which provides a streamlined way to compile and test EOSIO smart contracts. The configuration can be found in .lamingtonrc.
Note: when adding a new contract, append its .cpp filename to the .lamingtonrc include list so it is compiled.
- Ubuntu 18.04 or higher (recommended) / macOS
- At least 8GB RAM
- 50GB available disk space
- Docker installed and running
- Node.js 18
# Remove old versions
sudo apt-get remove docker docker-engine docker.io containerd runc
# Update package index
sudo apt-get update
# Install dependencies
sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release
# Add Docker's official GPG key
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
# Set up repository
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Install Docker Engine
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
# Start Docker
sudo systemctl start docker
# Enable Docker to start on boot
sudo systemctl enable docker
# Add your user to docker group (to run docker without sudo)
sudo usermod -aG docker $USER- Download Docker Desktop for Mac from Docker Hub
- Double-click
Docker.dmgto open the installer - Drag Docker to Applications
- Start Docker from Applications folder
Important Note for Apple Silicon Users:
- If you are getting
Runtime Error Processing WASMerrors during testing, turn off "Use Rosetta for x86_64/amd64 emulation on Apple Silicon" in Docker Desktop settings.
# Check Docker version
docker --version
# Verify Docker is running
docker run hello-world-
Docker Desktop (macOS)
- Open preferences/settings
- Go to Resources
- Allocate at least 4GB RAM
- Allocate at least 50GB disk space
-
Linux Configuration
- Edit
/etc/docker/daemon.json:{ "memory": "4g" }
- Edit
Reference compose file: a sample docker-compose.yml for operational tooling is available at scripts/docker-compose.yml. Lamington manages its own local node for tests.
-
Docker Service Issues
# Check Docker status sudo systemctl status docker # View Docker logs sudo journalctl -fu docker
# Use the correct Node.js version
nvm use
# Install dependencies
npm install-
Clean Build
# Fresh build intended for production npm run build -- -f # Or simply yarn build -f
-
Development Build
# Build with test configuration intended for local development npm run dev_build -
Individual Contract Build
# Build specific contracts using Lamington npm run build -- -p <contract name> -f # Or simply yarn build -p <contract name> -f
-
Staging/Test-Deploy Build
# Build with staging flags intended for test deployments npm run test_build -
Stop Local Node
npm run stop
Artifacts are written under artifacts/compiled_contracts/:
- Production builds:
artifacts/compiled_contracts/contracts/<contract>/<contract>.{wasm,abi} - Development builds (
-DIS_DEV):artifacts/compiled_contracts/IS_DEV/contracts/<contract>/<contract>.{wasm,abi}
Each contract produces:
.abifiles: Contract ABI definitions.wasmfiles: WebAssembly bytecode
- Run All Tests
npm test - Run Specific Contract Tests
So for example to run all tests in the
npm test -- -G <regex of mocha describe block> # Or simply yarn test -G <regex of mocha describe block>
miningcontract you would use:npm run test -- -g Mining # Or simply yarn test -G Mining
To force recompilation of the contracts before testing, use the -f flag:
npm run test -- -G Mining -f
# Or simply
yarn test -G Mining -fTo force recompilation of only the mining contract before testing, use the -f flag:
npm run test -- -G Mining -p mining -f
# Or simply
yarn test -G Mining -p mining -f- Make changes to contract source files
- Run tests to verify changes
- Build live version of contracts
- Deploy contracts
Tests are written using Chai and can be found alongside the contract implementations. Use the test command to run the full test suite:
npm run test
# Or simply
yarn test- Tests run via Lamington with Mocha/Chai. The local chain state is shared across
describe/context/itblocks (no rollback between tests). - Simulating time:
- Use
await sleep(5)to advance wall time. - In
-DIS_DEVbuilds, time-dependent actions expose an extratime_point_secparameter so tests can pass a simulated timestamp. In production builds the same actions computecurrent_time_point()internally.
- Use
Example (C++):
#ifdef IS_DEV
ACTION mycontract::someaction(name user, time_point_sec current_time) {
#else
ACTION mycontract::someaction(name user) {
const auto current_time = time_point_sec(current_time_point());
#endif
// ...
}Example (TypeScript test; build with npm run dev_build):
const simulated = new Date('2025-01-01T00:00:00Z');
await contracts.mycontract.contract.someaction(user.name, simulated, {
from: user,
});- Test exclusions:
contracts/eosdac-contracts/**tests are excluded by default via.lamingtonrc.
We welcome contributions from the community! Here's how you can help:
- Fork the repository
- Create a feature branch (`git checkout -b feature/amazing-feature`)
- Commit your changes (`git commit -m 'Add amazing feature'`)
- Push to the branch (`git push origin feature/amazing-feature`)
- Open a Pull Request
Please report security vulnerabilities to security@alienworlds.io. We will respond as quickly as possible to address any concerns.
This project is licensed under the MIT License - see the LICENSE file for details.
- Join our Discord for community discussions
- Visit the Alien Worlds Website for the latest news
- Follow us on X for updates
- The Alien Worlds Community
- Contributors and Developers
- AtomicAssets Team
- WAX Blockchain Community
Built with ❤️ by the Alien Worlds Team
