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

# BondingCurve

> BondingCurve 合约 ABI 参考

## 合约信息

| 属性     | 值                                                                                  |
| ------ | ---------------------------------------------------------------------------------- |
| **地址** | 通过 `MemeFactory.bondingCurve()` 读取（MemeFactory 地址见[合约地址](/zh/contracts/addresses)） |
| **网络** | Kasplex（见[合约地址](/zh/contracts/addresses)）                                          |

<Tip>
  所有计算函数都是 `pure` 的——不读取也不修改状态。你可以在链下调用它们进行免 gas 的价格查询。
</Tip>

## 函数

### calculateBuyReturnWithParams

计算给定 KAS 数量能获得多少代币。

```solidity theme={null}
function calculateBuyReturnWithParams(
    uint256 kasIn,
    uint256 tokenReserves,
    uint256 kasReserves,
    uint256 vToken,
    uint256 vKas
) external pure returns (uint256 tokensOut)
```

| 参数              | 类型      | 说明                                 |
| --------------- | ------- | ---------------------------------- |
| `kasIn`         | uint256 | 花费的 KAS 数量 (wei)                   |
| `tokenReserves` | uint256 | 当前代币储备，来自 `getTokenInfo()`         |
| `kasReserves`   | uint256 | 当前 KAS 储备，来自 `getTokenInfo()`      |
| `vToken`        | uint256 | 虚拟代币，来自 `getTokenParamVersion()`   |
| `vKas`          | uint256 | 虚拟 KAS，来自 `getTokenParamVersion()` |

***

### calculateSellReturnWithParams

计算卖出代币能获得多少 KAS。

```solidity theme={null}
function calculateSellReturnWithParams(
    uint256 tokensIn,
    uint256 tokenReserves,
    uint256 kasReserves,
    uint256 vToken,
    uint256 vKas
) external pure returns (uint256 kasOut)
```

| 参数              | 类型      | 说明                                 |
| --------------- | ------- | ---------------------------------- |
| `tokensIn`      | uint256 | 卖出的代币数量 (wei)                      |
| `tokenReserves` | uint256 | 当前代币储备，来自 `getTokenInfo()`         |
| `kasReserves`   | uint256 | 当前 KAS 储备，来自 `getTokenInfo()`      |
| `vToken`        | uint256 | 虚拟代币，来自 `getTokenParamVersion()`   |
| `vKas`          | uint256 | 虚拟 KAS，来自 `getTokenParamVersion()` |

***

### calculateBuyCostWithParams

计算要获得指定数量代币需要花费多少 KAS。

```solidity theme={null}
function calculateBuyCostWithParams(
    uint256 tokensOut,
    uint256 tokenReserves,
    uint256 kasReserves,
    uint256 vToken,
    uint256 vKas
) external pure returns (uint256 kasIn)
```

| 参数              | 类型      | 说明                                 |
| --------------- | ------- | ---------------------------------- |
| `tokensOut`     | uint256 | 期望的代币数量 (wei)                      |
| `tokenReserves` | uint256 | 当前代币储备，来自 `getTokenInfo()`         |
| `kasReserves`   | uint256 | 当前 KAS 储备，来自 `getTokenInfo()`      |
| `vToken`        | uint256 | 虚拟代币，来自 `getTokenParamVersion()`   |
| `vKas`          | uint256 | 虚拟 KAS，来自 `getTokenParamVersion()` |

***

### getCurrentPrice

获取当前现货价格。

```solidity theme={null}
function getCurrentPrice(
    uint256 tokenReserves,
    uint256 kasReserves
) external view returns (uint256 price)
```

***

### virtualToken / virtualKas

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

BondingCurve 合约中配置的默认虚拟储备。注意：各代币可能通过 `getTokenParamVersion()` 使用不同的值。

***

### curveType

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

返回曲线类型标识符。

***

## 完整 ABI (JSON)

<Accordion title="BondingCurve ABI JSON">
  ```json theme={null}
  [
    {
      "inputs": [{"internalType": "uint256", "name": "kasIn", "type": "uint256"}, {"internalType": "uint256", "name": "tokenReserves", "type": "uint256"}, {"internalType": "uint256", "name": "kasReserves", "type": "uint256"}, {"internalType": "uint256", "name": "vToken", "type": "uint256"}, {"internalType": "uint256", "name": "vKas", "type": "uint256"}],
      "name": "calculateBuyReturnWithParams",
      "outputs": [{"internalType": "uint256", "name": "tokensOut", "type": "uint256"}],
      "stateMutability": "pure",
      "type": "function"
    },
    {
      "inputs": [{"internalType": "uint256", "name": "tokensOut", "type": "uint256"}, {"internalType": "uint256", "name": "tokenReserves", "type": "uint256"}, {"internalType": "uint256", "name": "kasReserves", "type": "uint256"}, {"internalType": "uint256", "name": "vToken", "type": "uint256"}, {"internalType": "uint256", "name": "vKas", "type": "uint256"}],
      "name": "calculateBuyCostWithParams",
      "outputs": [{"internalType": "uint256", "name": "kasIn", "type": "uint256"}],
      "stateMutability": "pure",
      "type": "function"
    },
    {
      "inputs": [{"internalType": "uint256", "name": "tokensIn", "type": "uint256"}, {"internalType": "uint256", "name": "tokenReserves", "type": "uint256"}, {"internalType": "uint256", "name": "kasReserves", "type": "uint256"}, {"internalType": "uint256", "name": "vToken", "type": "uint256"}, {"internalType": "uint256", "name": "vKas", "type": "uint256"}],
      "name": "calculateSellReturnWithParams",
      "outputs": [{"internalType": "uint256", "name": "kasOut", "type": "uint256"}],
      "stateMutability": "pure",
      "type": "function"
    },
    {
      "inputs": [{"internalType": "uint256", "name": "tokenReserves", "type": "uint256"}, {"internalType": "uint256", "name": "kasReserves", "type": "uint256"}],
      "name": "getCurrentPrice",
      "outputs": [{"internalType": "uint256", "name": "price", "type": "uint256"}],
      "stateMutability": "view",
      "type": "function"
    },
    {
      "inputs": [],
      "name": "virtualToken",
      "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}],
      "stateMutability": "view",
      "type": "function"
    },
    {
      "inputs": [],
      "name": "virtualKas",
      "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}],
      "stateMutability": "view",
      "type": "function"
    },
    {
      "inputs": [],
      "name": "curveType",
      "outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}],
      "stateMutability": "view",
      "type": "function"
    }
  ]
  ```
</Accordion>
