> For the complete documentation index, see [llms.txt](https://docs.evently.market/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.evently.market/smart-contracts/architecture.md).

# Architecture Overview

## Contract System

evently is composed of independent smart contracts deployed on MegaETH mainnet.

```
+---------------------------+
|   EventlyProfiles.sol     |  ← Identity, stats, referrals, swap points
+------------+--------------+
             | reads/writes profile data
+------------v--------------+
|   EventlyMarkets.sol      |  ← Prediction markets (LMSR b=200 + CLOB)
|   Pending deployment      |    Pre-launch audit complete — 29 tools
+---------------------------+
```

The Markets contract is fully independent — it only reads USDm balances and approvals from the ERC-20 contract. The Profiles contract tracks identity and onchain social layer.

***

## Deployed Addresses (Mainnet — Chain ID 4326)

| Contract               | Address                                          |
| ---------------------- | ------------------------------------------------ |
| EventlyMarkets         | TBD (pending deployment post professional audit) |
| EventlyProfiles (v1.3) | `0x9F0708145BCCD1F5B16F610cB8a75A63fA4A9a24`     |
| USDm                   | `0xFAfDdbb3FC7688494971a79cc65DCa3EF82079E7`     |
| MegaNames              | `0x5B424C6CCba77b32b9625a6fd5A30D409d20d997`     |
| Admin wallet           | `0x21CbC99a2E8c68F1C2955991E07c0C22ea895Da1`     |

***

## Design Principles

* **Pull payment pattern** — winners pull funds via `redeemWinnings()` / `claimCancelRefund()`; no push transfers that can fail
* **Checks-Effects-Interactions (CEI)** — state reset before all external calls
* **ReentrancyGuard** — custom `_locked` mutex on all state-mutating external functions
* **No upgradeability** — contracts are immutable; new versions are redeployed
* **Transparency** — all events emitted for full on-chain auditability

***

## EventlyMarkets — Key Architecture

LMSR AMM (b=200 USDm) as market maker of last resort. CLOB (Central Limit Order Book) with bids and asks matched first at price-time priority.

```
BUY order  → CLOB asks filled first → remainder to LMSR AMM
SELL order → CLOB bids filled first → remainder rests as limit ask
           → OR: sellToAMM() for instant AMM execution
```

ERC-1155 shares: 1 winning share = 1 USDm at redemption. Solvency guaranteed by LMSR invariant: `poolBalance + subsidyDeposited >= total winning shares`.

Pre-launch audit complete (29 tools — 7 AI engines + 22 automated scanners). No blocking findings. Awaiting professional audit (two independent firms).

***

## Gas Configuration (MegaETH-Specific)

MegaETH has near-zero gas costs (\~10ms blocks, \~100K TPS). Transaction configuration in the frontend:

```ts
maxFeePerGas: 1_000_000n     // 1 gwei
maxPriorityFeePerGas: 0n
```

***

## Off-Chain Infrastructure

| Component     | Tech                         | Purpose                                             |
| ------------- | ---------------------------- | --------------------------------------------------- |
| Database      | Supabase (PostgreSQL)        | Market metadata, user profiles, trade history cache |
| Frontend      | Next.js + Tailwind + wagmi   | React app at evently.market                         |
| Real-time     | `watchContractEvent` (wagmi) | \~10ms block polling for live trade feed            |
| Bridge/Swap   | LiFi SDK                     | 60+ routes to MegaETH                               |
| Market import | Polymarket CLOB API          | Live odds comparison                                |
