> For the complete documentation index, see [llms.txt](https://docs.yuzu.finance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.yuzu.finance/move.fun/technical/coin-amm/bonding-curve.md).

# Bonding Curve

### **Contract Info**

* **Contract Name**: `move_fun::bonding_curve`
* **Contract Address**: \[tba]

### Resources

***

#### **BondingCurve**

Represents a bonding curve for a token.

```move
struct BondingCurve has key, drop {
    initial_price_numerator: u128,
    initial_price_denominator: u128,
    growth_constant: u128
}
```

| Name                        | Type | Description                                                           |
| --------------------------- | ---- | --------------------------------------------------------------------- |
| initial\_price\_numerator   | u128 | Initial price numerator for the token.                                |
| initial\_price\_denominator | u128 | Initial price denominator for the token.                              |
| growth\_constant            | u128 | Growth constant (k) that determines how the price scales with supply. |

***

### Public Functions

***

#### **Initialize**

Initializes the bonding curve with initial price and growth constant.

```move
public(friend) fun initialize(
    signer_ref: &signer,
    initial_price_numerator: u128,
    initial_price_denominator: u128,
    growth_constant: u128
)
```

| Input Values                | Type   | Description                                    |
| --------------------------- | ------ | ---------------------------------------------- |
| signer\_ref                 | signer | The signer's reference.                        |
| initial\_price\_numerator   | u128   | The initial numerator for the token price.     |
| initial\_price\_denominator | u128   | The initial denominator for the token price.   |
| growth\_constant            | u128   | The growth constant (k) for the bonding curve. |

***

#### **Calculate Growth Constant**

Calculates the growth constant ( k ) based on the bonding curve parameters.

```move
public(friend) fun calculate_k(
    initial_price_numerator: u128,
    initial_price_denominator: u128,
    target_price_numerator: u128,
    target_supply: u128,
    max_supply: u128
): u128
```

| Input Values                | Type | Description                |
| --------------------------- | ---- | -------------------------- |
| initial\_price\_numerator   | u128 | Initial price numerator.   |
| initial\_price\_denominator | u128 | Initial price denominator. |
| target\_price\_numerator    | u128 | Target price numerator.    |
| target\_supply              | u128 | Target supply amount.      |
| max\_supply                 | u128 | Maximum supply amount.     |

***

#### **Calculate Price**

Calculates the token price based on the supply and bonding curve parameters.

```move
public(friend) fun calculate_price(
    curve: &BondingCurve,
    max_supply: u128,
    decimals: u128,
    new_supply_base_value: u128,
    new_supply_exponent_value: u128
): u128
```

| Input Values                 | Type           | Description                              |
| ---------------------------- | -------------- | ---------------------------------------- |
| curve                        | \&BondingCurve | The bonding curve reference.             |
| max\_supply                  | u128           | Maximum supply of the token.             |
| decimals                     | u128           | Number of decimals to use for precision. |
| new\_supply\_base\_value     | u128           | The new supply base value.               |
| new\_supply\_exponent\_value | u128           | The new supply exponent value.           |

***

#### **Set Market Cap Goal**

Adjusts the bonding curve based on a new target market cap.

```move
public(friend) fun set_market_cap_goal(
    coin_addr: address, 
    initial_price_numerator: u128,
    initial_price_denominator: u128,
    target_price_numerator: u128,
    target_supply: u128,
    max_supply: u128
): u128 acquires BondingCurve
```

| Input Values                | Type    | Description                |
| --------------------------- | ------- | -------------------------- |
| coin\_addr                  | address | Address of the token.      |
| initial\_price\_numerator   | u128    | Initial price numerator.   |
| initial\_price\_denominator | u128    | Initial price denominator. |
| target\_price\_numerator    | u128    | Target price numerator.    |
| target\_supply              | u128    | Target supply amount.      |
| max\_supply                 | u128    | Maximum supply amount.     |

***

### View Functions

***

#### **Initial Price**

Returns the initial price of the bonding curve for a token.

```move
public fun initial_price<CoinType>(): (u128, u128) acquires BondingCurve
```

| Return Values               | Type | Description                             |
| --------------------------- | ---- | --------------------------------------- |
| initial\_price\_numerator   | u128 | Initial price numerator of the token.   |
| initial\_price\_denominator | u128 | Initial price denominator of the token. |

***

#### **Growth Constant**

Returns the growth constant ( k ) for the bonding curve of a token.

```move
public fun growth_constant<CoinType>(): u128 acquires BondingCurve
```

| Return Values    | Type | Description                                 |
| ---------------- | ---- | ------------------------------------------- |
| growth\_constant | u128 | Growth constant ( k ) of the bonding curve. |
