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

# Contract Overview

> KasFun smart contract architecture

## Architecture

KasFun consists of three core contracts:

```mermaid theme={null}
graph TD
    MF["<b>MemeFactory</b><br/>createToken() · buy() · sell()<br/>getTokenInfo() · getCurrentPrice()"]
    BC["<b>BondingCurve</b><br/>(pure math)<br/>calculateBuyReturn · calculateSellReturn"]
    C["<b>Council V1</b><br/>(per-token, after graduation)<br/>Elections · Proposals · Voting"]
    TA["Token A<br/>(ERC-20)"]
    TB["Token B<br/>(ERC-20)"]

    MF --> TA
    MF --> TB
    MF -- reads --> BC
    TA -. graduated .-> C
    TB -. graduated .-> C
```

## MemeFactory

The central contract. All token creation and bonding curve trading goes through MemeFactory.

| Function                              | Description                                                   |
| ------------------------------------- | ------------------------------------------------------------- |
| `createToken(params)`                 | Create a new token (payable, requires platform signature)     |
| `buy(token, minTokensOut)`            | Buy tokens with KAS (payable)                                 |
| `sell(token, tokenAmount, minKasOut)` | Sell tokens for KAS (requires ERC-20 approval)                |
| `getTokenInfo(token)`                 | Get token state (reserves, graduated, etc.)                   |
| `getCurrentPrice(token)`              | Get current price in KAS                                      |
| `getBondingCurveProgress(token)`      | Get fundraising progress (0–10000 = 0–100%)                   |
| `getTokenParamVersion(token)`         | Get bonding curve parameters (virtualToken, virtualKas, etc.) |
| `bondingCurve()`                      | Get the BondingCurve contract address                         |

Each token created by MemeFactory is **ERC-20 compatible**.

## BondingCurve

A stateless math contract. All functions are `pure` or `view` — they don't modify state. Used by MemeFactory internally and available for external price calculations.

<Info>
  The BondingCurve contract address is not fixed — read it from `MemeFactory.bondingCurve()`.

  ```javascript theme={null}
  const bcAddress = await factory.bondingCurve();
  ```
</Info>

| Function                             | Description                          |
| ------------------------------------ | ------------------------------------ |
| `calculateBuyReturnWithParams(...)`  | KAS in → tokens out                  |
| `calculateSellReturnWithParams(...)` | Tokens in → KAS out                  |
| `calculateBuyCostWithParams(...)`    | Desired tokens out → required KAS in |

## Council V1

Per-token governance contract, activated after a token graduates. Each graduated token can have its own Council with elected members, proposals, and voting.

| Feature        | Description                                        |
| -------------- | -------------------------------------------------- |
| **Elections**  | Token holders vote to elect Council members        |
| **Proposals**  | Council members create proposals for the community |
| **Voting**     | Token holders vote on proposals by locking tokens  |
| **Tax Config** | Community can set token tax through proposals      |

<Info>
  Council addresses are per-token. You can find a token's Council address on its community page at [kas.fun](https://kas.fun).
</Info>

## Token Standards

* All tokens are **ERC-20** compatible (transfer, approve, balanceOf, etc.)
* Total supply: **1,000,000,000** (1 billion) tokens per token, all 18 decimals
* Tokens are minted entirely at creation. 80% goes into the bonding curve pool, 20% is reserved.
