Overview
The Staxiq smart contract architecture is built on Clarity, a decidable smart contract language designed for security and predictability on the Stacks blockchain.Contract Structure
Thestaxiq-user-profile contract is organized into distinct sections:
contracts/staxiq-user-profile.clar
Constants
The contract defines constants for error handling and risk level validation:contracts/staxiq-user-profile.clar
Error Codes
| Code | Constant | Description |
|---|---|---|
u404 | ERR-NOT-FOUND | User profile or strategy does not exist |
u400 | ERR-INVALID-RISK | Invalid risk level provided (must be 1, 2, or 3) |
u401 | ERR-UNAUTHORIZED | Unauthorized access attempt |
Risk Levels
| Value | Constant | Description |
|---|---|---|
u1 | RISK-CONSERVATIVE | Low-risk, stable strategies |
u2 | RISK-BALANCED | Moderate risk/reward balance |
u3 | RISK-AGGRESSIVE | High-risk, high-reward strategies |
Data Maps
The contract uses three primary data maps for storage:1. User Profiles Map
Stores core user profile information:contracts/staxiq-user-profile.clar
Maps wallet address (principal) to user profile data
2. Strategy History Map
Stores AI-generated strategy recommendations:contracts/staxiq-user-profile.clar
Maps (user address, strategy ID) tuple to strategy details
3. User Strategy Count Map
Tracks the total number of strategies per user:contracts/staxiq-user-profile.clar
Design Decisions
Clarity Language Benefits
Decidability
Clarity is decidable, meaning you can know precisely what a program will do before execution
No Reentrancy
Built-in protection against reentrancy attacks that plague Solidity contracts
Post-Conditions
Users can specify conditions that must be met for a transaction to succeed
Bitcoin Finality
Stacks settles to Bitcoin, inheriting Bitcoin’s security model
Architecture Principles
1. User Sovereignty
All data is keyed by wallet address (principal). Users have complete control over their profiles without admin intervention.
contracts/staxiq-user-profile.clar
2. Immutable History
Once a strategy is saved on-chain, it cannot be modified or deleted. This creates an audit trail.3. Gas Optimization
Read-only functions are free to call, encouraging data transparency without cost barriers.4. Validation First
All inputs are validated before state changes occur:contracts/staxiq-user-profile.clar
Data Flow
Setting Risk Profile
Saving Strategy
Block Heights as Timestamps
Clarity uses block heights instead of Unix timestamps:Stacks blocks are produced approximately every 10 minutes (tied to Bitcoin blocks). To convert to approximate time:
Time = (block_height_diff × 10 minutes)Security Considerations
Authentication
All public functions authenticate usingtx-sender, which is automatically set to the transaction signer:
Input Validation
All inputs are validated before state changes:- Risk levels must be 1, 2, or 3
- String lengths are constrained (64 chars for hash, 32 for protocol)
- Profile existence is checked before saving strategies
No Privileged Functions
The contract has no admin functions that could modify or delete user data after deployment.Upgradeability
Next Steps
User Profile Functions
Explore all available contract functions
Integration Guide
Learn how to call contracts from your app