> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tradmatrix.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How It Works

> Step-by-step guide to the Tradmatrix Asset trading process

## The Complete Flow

<Steps>
  <Step title="Asset Listing">
    Asset owner lists their asset on Tradmatrix with:

    * Asset details and images (up to 50 photos)
    * Total number of tokens
    * Price per token
    * Verification documents
  </Step>

  <Step title="Token Sales">
    Participants purchase tokens using USDC:

    * Connect Solana wallet
    * Buy 1 or multiple tokens
    * Each token = 1 entry
    * Sales tracked in real-time
  </Step>

  <Step title="Sold Out">
    When all tokens are sold:

    * Asset status changes to "Sold Out"
    * Funds held in escrow
    * Ready for winner selection
  </Step>

  <Step title="Winner Selection">
    Provably fair random selection:

    * Uses Entropy's provably fair algorithm
    * Cannot be manipulated
    * Transparent on-chain
    * Winner immediately notified
  </Step>

  <Step title="Settlement">
    Automatic fund distribution:

    * 98.5% → Asset Owner
    * 1.5% → Platform Fee
    * Winner receives asset ownership
  </Step>
</Steps>

## Detailed Process

### 1. Asset Listing

Asset owners create a listing by calling the `create_asset` instruction:

```typescript theme={null}
// Example: $500K asset with 5,000 tokens at $100 each
const assetParams = {
  numberOfTokens: 5000,
  tokenCost: 100_000_000, // 100 USDC (6 decimals)
  assetOwner: ownerPublicKey,
  platformAuthority: platformPublicKey
};
```

The platform creates:

* **Asset PDA**: Stores all asset information
* **Asset Vault**: Holds USDC from token sales
* **Unique Asset ID**: Auto-incrementing identifier

### 2. Token Purchase

Users buy tokens by calling the `buy_token` instruction:

```typescript theme={null}
// Purchase tokens
const tokenPurchase = {
  assetId: 0,
  quantity: 5, // Buy 5 tokens
  buyer: userPublicKey
};
```

Each purchase:

* Transfers USDC to asset vault
* Creates token PDA with unique number (0, 1, 2, ...)
* Updates asset's `tokensSold` counter
* Emits `TokenPurchased` event

### 3. Winner Selection

When sold out, admin calls `pick_winner` instruction:

The winner selection process is completely deterministic and transparent:

1. Entropy protocol generates a cryptographically secure random value
2. Calculates: `winningToken = randomValue % totalTokens`
3. Looks up token owner from on-chain PDA
4. Distributes funds automatically
5. Emits `WinnerSelected` event

## Probability Mechanics

### Fair Odds

Your winning probability is straightforward:

```
P(win) = (your tokens) / (total tokens)

Examples:
- 1 token of 5,000 = 0.02% chance
- 10 tokens of 5,000 = 0.2% chance
- 100 tokens of 5,000 = 2% chance
```

### Multiple Token Strategy

Buying more tokens increases your probability:

<Accordion title="Probability Calculator">
  ```
  Asset: 5,000 tokens @ $100 each
  Investment vs Probability:

  $100 (1 token)    → 0.02% chance
  $500 (5 tokens)   → 0.10% chance
  $1,000 (10 tokens) → 0.20% chance
  $5,000 (50 tokens) → 1.00% chance
  ```
</Accordion>

## Security Guarantees

<Warning>
  **Provably Fair Algorithm**: Tradmatrix uses Entropy's provably fair algorithm, which provides cryptographically secure randomness that cannot be predicted or manipulated by anyone, including platform operators.
</Warning>

### How Entropy's Algorithm Works

1. **Commitment**: Entropy provider commits to a secret seed before randomness is available
2. **Sampling**: Solana validators produce unpredictable randomness through slot hashing
3. **Revelation**: Pre-committed seed is revealed and verified on-chain
4. **Generation**: Final random value is derived from both sources, making it impossible for any party to control

This ensures:

* No single party can predict the outcome
* The platform cannot manipulate the result
* All participants have equal odds
* Process is completely transparent and verifiable on-chain

## What Happens Next?

After winning:

1. Winner notified via email/SMS/push notification
2. Asset ownership transfer process initiated
3. Legal documentation provided
4. Ownership transfer completed

<Card title="Next: Benefits" icon="star" href="/benefits">
  Learn about the benefits for asset owners and participants
</Card>
