> ## 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.

# MemeFactory

> MemeFactory 合约 ABI 参考

## 合约信息

| 属性     | 值                                         |
| ------ | ----------------------------------------- |
| **地址** | 见[合约地址](/zh/contracts/addresses)          |
| **网络** | Kasplex（见[合约地址](/zh/contracts/addresses)） |

## 写函数

### createToken

创建新代币。需要通过 [kas.fun](https://kas.fun) 获取的平台签名。

```solidity theme={null}
function createToken(CreateTokenParams params) external payable returns (uint256 tokenId, address token)
```

**CreateTokenParams：**

| 字段                 | 类型      | 说明              |
| ------------------ | ------- | --------------- |
| `name`             | string  | 代币名称            |
| `symbol`           | string  | 代币符号            |
| `metadataUri`      | string  | 元数据 URI         |
| `creatorBuyAmount` | uint256 | 可选的初始买入金额 (wei) |
| `salt`             | bytes32 | 确定性地址的 salt     |
| `nonce`            | uint256 | 防重放 nonce       |
| `deadline`         | uint256 | 签名过期时间戳         |
| `signature`        | bytes   | 平台 EIP-712 签名   |

**Value：** `creationFee + creatorBuyAmount`

***

### buy

用 KAS 买入代币。

```solidity theme={null}
function buy(address token, uint256 minTokensOut) external payable
```

| 参数             | 类型      | 说明             |
| -------------- | ------- | -------------- |
| `token`        | address | 要买入的代币         |
| `minTokensOut` | uint256 | 最少接收代币数量（滑点保护） |

**Value：** 花费的 KAS 数量 (wei)

***

### sell

卖出代币换回 KAS。需要先进行 ERC-20 授权。

```solidity theme={null}
function sell(address token, uint256 tokenAmount, uint256 minKasOut) external
```

| 参数            | 类型      | 说明                |
| ------------- | ------- | ----------------- |
| `token`       | address | 要卖出的代币            |
| `tokenAmount` | uint256 | 卖出的代币数量 (wei)     |
| `minKasOut`   | uint256 | 最少接收 KAS 数量（滑点保护） |

***

## 读函数

### getTokenInfo

```solidity theme={null}
function getTokenInfo(address token) external view returns (TokenInfo)
```

**返回 (TokenInfo)：**

| 字段              | 类型      | 说明                  |
| --------------- | ------- | ------------------- |
| `tokenId`       | uint256 | 代币 ID（未找到时为 0）      |
| `creator`       | address | 代币创建者               |
| `pool`          | address | 池地址                 |
| `tokenReserves` | uint256 | 池中代币储备 (wei)        |
| `kasReserves`   | uint256 | 池中 KAS 储备 (wei)     |
| `createdAt`     | uint256 | 创建时间戳               |
| `fulfilled`     | bool    | Bonding Curve 阈值已达到 |
| `graduated`     | bool    | 流动性已迁移到 DEX         |
| `metadataUri`   | string  | 元数据 URI             |
| `paramVersion`  | uint256 | 曲线参数版本              |

***

### getCurrentPrice

```solidity theme={null}
function getCurrentPrice(address token) external view returns (uint256)
```

返回当前 KAS/token 价格（18 位小数）。

***

### getBondingCurveProgress

```solidity theme={null}
function getBondingCurveProgress(address token) external view returns (uint256)
```

返回 `0` 到 `10000` 的进度值（表示 0.00% 到 100.00%）。

***

### getTokenParamVersion

```solidity theme={null}
function getTokenParamVersion(address token) external view returns (ParamVersion)
```

**返回 (ParamVersion)：**

| 字段                    | 类型      | 说明                          |
| --------------------- | ------- | --------------------------- |
| `graduationThreshold` | uint256 | 毕业所需 KAS 数量 (wei)           |
| `virtualToken`        | uint256 | 曲线虚拟代币储备                    |
| `virtualKas`          | uint256 | 曲线虚拟 KAS 储备                 |
| `sqrtPriceX96Token0`  | uint160 | Uniswap V3 sqrt 价格 (token0) |
| `sqrtPriceX96Token1`  | uint160 | Uniswap V3 sqrt 价格 (token1) |
| `active`              | bool    | 此参数版本是否激活                   |

***

### computeTokenAddress

```solidity theme={null}
function computeTokenAddress(bytes32 salt, address creator) external view returns (address)
```

创建前预测代币合约地址。

***

### bondingCurve

```solidity theme={null}
function bondingCurve() external view returns (address)
```

返回 BondingCurve 合约地址。

***

### creationFee

```solidity theme={null}
function creationFee() external view returns (uint256)
```

返回代币创建费用，单位 KAS (wei)。

***

### authorizedSigner

```solidity theme={null}
function authorizedSigner() external view returns (address)
```

返回平台授权签名者地址。

***

## 事件

### Created

```solidity theme={null}
event Created(
    address indexed token,
    address indexed creator,
    uint256 indexed tokenId,
    address pool,
    string name,
    string symbol
)
```

### Buy

```solidity theme={null}
event Buy(
    address indexed token,
    address indexed buyer,
    uint256 kasAmount,
    uint256 tokenAmount,
    uint256 fee
)
```

### Sell

```solidity theme={null}
event Sell(
    address indexed token,
    address indexed seller,
    uint256 tokenAmount,
    uint256 kasAmount,
    uint256 fee
)
```

## 完整 ABI (JSON)

<Accordion title="MemeFactory ABI JSON">
  ```json theme={null}
  [
    {
      "inputs": [{"components": [{"internalType": "string", "name": "name", "type": "string"}, {"internalType": "string", "name": "symbol", "type": "string"}, {"internalType": "string", "name": "metadataUri", "type": "string"}, {"internalType": "uint256", "name": "creatorBuyAmount", "type": "uint256"}, {"internalType": "bytes32", "name": "salt", "type": "bytes32"}, {"internalType": "uint256", "name": "nonce", "type": "uint256"}, {"internalType": "uint256", "name": "deadline", "type": "uint256"}, {"internalType": "bytes", "name": "signature", "type": "bytes"}], "internalType": "struct IMemeFactory.CreateTokenParams", "name": "params", "type": "tuple"}],
      "name": "createToken",
      "outputs": [{"internalType": "uint256", "name": "tokenId", "type": "uint256"}, {"internalType": "address", "name": "token", "type": "address"}],
      "stateMutability": "payable",
      "type": "function"
    },
    {
      "inputs": [{"internalType": "address", "name": "token", "type": "address"}, {"internalType": "uint256", "name": "minTokensOut", "type": "uint256"}],
      "name": "buy",
      "outputs": [],
      "stateMutability": "payable",
      "type": "function"
    },
    {
      "inputs": [{"internalType": "address", "name": "token", "type": "address"}, {"internalType": "uint256", "name": "tokenAmount", "type": "uint256"}, {"internalType": "uint256", "name": "minKasOut", "type": "uint256"}],
      "name": "sell",
      "outputs": [],
      "stateMutability": "nonpayable",
      "type": "function"
    },
    {
      "inputs": [{"internalType": "address", "name": "token", "type": "address"}],
      "name": "getTokenInfo",
      "outputs": [{"components": [{"internalType": "uint256", "name": "tokenId", "type": "uint256"}, {"internalType": "address", "name": "creator", "type": "address"}, {"internalType": "address", "name": "pool", "type": "address"}, {"internalType": "uint256", "name": "tokenReserves", "type": "uint256"}, {"internalType": "uint256", "name": "kasReserves", "type": "uint256"}, {"internalType": "uint256", "name": "createdAt", "type": "uint256"}, {"internalType": "bool", "name": "fulfilled", "type": "bool"}, {"internalType": "bool", "name": "graduated", "type": "bool"}, {"internalType": "string", "name": "metadataUri", "type": "string"}, {"internalType": "uint256", "name": "paramVersion", "type": "uint256"}], "internalType": "struct IMemeFactory.TokenInfo", "name": "", "type": "tuple"}],
      "stateMutability": "view",
      "type": "function"
    },
    {
      "inputs": [{"internalType": "address", "name": "token", "type": "address"}],
      "name": "getCurrentPrice",
      "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}],
      "stateMutability": "view",
      "type": "function"
    },
    {
      "inputs": [{"internalType": "address", "name": "token", "type": "address"}],
      "name": "getBondingCurveProgress",
      "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}],
      "stateMutability": "view",
      "type": "function"
    },
    {
      "inputs": [{"internalType": "address", "name": "token", "type": "address"}],
      "name": "getTokenParamVersion",
      "outputs": [{"components": [{"internalType": "uint256", "name": "graduationThreshold", "type": "uint256"}, {"internalType": "uint256", "name": "virtualToken", "type": "uint256"}, {"internalType": "uint256", "name": "virtualKas", "type": "uint256"}, {"internalType": "uint160", "name": "sqrtPriceX96Token0", "type": "uint160"}, {"internalType": "uint160", "name": "sqrtPriceX96Token1", "type": "uint160"}, {"internalType": "bool", "name": "active", "type": "bool"}], "internalType": "struct IMemeFactory.ParamVersion", "name": "", "type": "tuple"}],
      "stateMutability": "view",
      "type": "function"
    },
    {
      "inputs": [{"internalType": "bytes32", "name": "salt", "type": "bytes32"}, {"internalType": "address", "name": "creator", "type": "address"}],
      "name": "computeTokenAddress",
      "outputs": [{"internalType": "address", "name": "", "type": "address"}],
      "stateMutability": "view",
      "type": "function"
    },
    {
      "inputs": [],
      "name": "bondingCurve",
      "outputs": [{"internalType": "address", "name": "", "type": "address"}],
      "stateMutability": "view",
      "type": "function"
    },
    {
      "inputs": [],
      "name": "creationFee",
      "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}],
      "stateMutability": "view",
      "type": "function"
    },
    {
      "inputs": [],
      "name": "authorizedSigner",
      "outputs": [{"internalType": "address", "name": "", "type": "address"}],
      "stateMutability": "view",
      "type": "function"
    },
    {
      "anonymous": false,
      "inputs": [{"indexed": true, "internalType": "address", "name": "token", "type": "address"}, {"indexed": true, "internalType": "address", "name": "creator", "type": "address"}, {"indexed": true, "internalType": "uint256", "name": "tokenId", "type": "uint256"}, {"indexed": false, "internalType": "address", "name": "pool", "type": "address"}, {"indexed": false, "internalType": "string", "name": "name", "type": "string"}, {"indexed": false, "internalType": "string", "name": "symbol", "type": "string"}],
      "name": "Created",
      "type": "event"
    },
    {
      "anonymous": false,
      "inputs": [{"indexed": true, "internalType": "address", "name": "token", "type": "address"}, {"indexed": true, "internalType": "address", "name": "buyer", "type": "address"}, {"indexed": false, "internalType": "uint256", "name": "kasAmount", "type": "uint256"}, {"indexed": false, "internalType": "uint256", "name": "tokenAmount", "type": "uint256"}, {"indexed": false, "internalType": "uint256", "name": "fee", "type": "uint256"}],
      "name": "Buy",
      "type": "event"
    },
    {
      "anonymous": false,
      "inputs": [{"indexed": true, "internalType": "address", "name": "token", "type": "address"}, {"indexed": true, "internalType": "address", "name": "seller", "type": "address"}, {"indexed": false, "internalType": "uint256", "name": "tokenAmount", "type": "uint256"}, {"indexed": false, "internalType": "uint256", "name": "kasAmount", "type": "uint256"}, {"indexed": false, "internalType": "uint256", "name": "fee", "type": "uint256"}],
      "name": "Sell",
      "type": "event"
    }
  ]
  ```
</Accordion>
