Skip to main content

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

The staxiq-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

Risk Levels

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
map
Maps wallet address (principal) to user profile data

2. Strategy History Map

Stores AI-generated strategy recommendations:
contracts/staxiq-user-profile.clar
map
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
This map provides O(1) lookup for strategy counts without iterating through all strategies.

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 using tx-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

Clarity contracts are immutable after deployment. There is no upgrade mechanism. This is a security feature that ensures users know exactly what code they’re interacting with.Any contract changes require deploying a new contract and migrating users.

Next Steps

User Profile Functions

Explore all available contract functions

Integration Guide

Learn how to call contracts from your app