# Core

## **Contract Info**

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

### Resources

***

#### **Info**

Represents the global storage for managing the legacy coin supply and details.

```move
struct Info<phantom BuyCoinType, phantom SellCoinType> has key {
    total_bound_supply: u64,
    liquidity_supply: Coin<BuyCoinType>,
    target_price_numerator: u64,
    target_price_denominator: u64,
    buy_coin_store: Coin<BuyCoinType>,
    sell_coin_store: Coin<SellCoinType>,
    virtual_balance_store: smart_table::SmartTable<address, Coin<BuyCoinType>>,
    max_wallet_balance: Option<u64>,
}
```

| Name                       | Type                                     | Description                                        |
| -------------------------- | ---------------------------------------- | -------------------------------------------------- |
| total\_bound\_supply       | u64                                      | Total supply bound to the bonding curve.           |
| liquidity\_supply          | Coin                                     | Supply allocated for liquidity.                    |
| target\_price\_numerator   | u64                                      | Target price numerator for the buy coin.           |
| target\_price\_denominator | u64                                      | Target price denominator for the buy coin.         |
| buy\_coin\_store           | Coin                                     | Coin supply available for selling.                 |
| sell\_coin\_store          | Coin                                     | Coin supply held for selling.                      |
| virtual\_balance\_store    | smart\_table::SmartTable\<address, Coin> | Virtual balance for storing coins during buy/sell. |
| max\_wallet\_balance       | Option                                   | Maximum allowed balance per wallet (optional).     |

***

#### **CoinMetadata**

Stores metadata for the legacy coin.

```move
struct CoinMetadata<phantom CoinType> has key, store {
    name: String,
    symbol: String,
    decimals: u8,
    max_supply: u64,
    logo: String,
    banner: String,
    description: String,
    links: vector<String>
}
```

| Name        | Type   | Description                            |
| ----------- | ------ | -------------------------------------- |
| name        | String | Name of the coin.                      |
| symbol      | String | Symbol of the coin.                    |
| decimals    | u8     | Number of decimal places for the coin. |
| max\_supply | u64    | Maximum supply of the coin.            |
| logo        | String | URL to the coin's logo.                |
| banner      | String | URL to the coin's banner.              |
| description | String | Description of the coin.               |
| links       | vector | List of links related to the coin.     |

***

### Events

***

#### **CoinDeployed**

Emitted when the coin is deployed.

```move
#[event]
struct CoinDeployed has drop, store {
    coin_address: String,
    name: String,
    symbol: String,
    decimals: u8,
    max_supply: u64,
    logo: String,
    banner: String,
    description: String,
    links: vector<String>
}
```

#### **CoinBought**

Emitted when coins are bought.

```move
#[event]
struct CoinBought has drop, store {
    buyer: address,
    coin: String,
    amount_base_value: u64,
    amount_exponent_value: u64,
    at_price_numerator: u64,
    at_price_denominator: u64,
    paid: u64,
    paid_coin: String,
    accumulated_sell_supply: u64,
    remaining_supply: u64,
}
```

#### **CoinSold**

Emitted when coins are sold.

```move
#[event]
struct CoinSold has drop, store {
    seller: address,
    coin: String,
    amount_base_value: u64,
    amount_exponent_value: u64,
    at_price_numerator: u64,
    at_price_denominator: u64,
    received: u64,
    received_coin: String,
    accumulated_sell_supply: u64,
    remaining_supply: u64,
}
```

***

### Public Functions

***

#### **Initialize Legacy Coin**

Initializes the legacy coin with bonding curve parameters and metadata.

```move
public(friend) fun initialize<BuyCoinType, SellCoinType>(
    signer_ref: &signer,
    max_supply: u64,
    initial_price_numerator: u64,
    initial_price_denominator: u64,
    target_price_numerator: u64,
    target_price_denominator: u64,
    bound_supply_percentage: u8,
    logo: String,
    banner: String,
    description: String,
    links: vector<String>,
    max_wallet_balance: Option<u64>
)
```

| Input Values                | Type   | Description                                                |
| --------------------------- | ------ | ---------------------------------------------------------- |
| signer\_ref                 | signer | The signer's reference.                                    |
| max\_supply                 | u64    | Maximum supply of the coin.                                |
| initial\_price\_numerator   | u64    | Initial price numerator for the coin.                      |
| initial\_price\_denominator | u64    | Initial price denominator for the coin.                    |
| target\_price\_numerator    | u64    | Target price numerator for the coin.                       |
| target\_price\_denominator  | u64    | Target price denominator for the coin.                     |
| bound\_supply\_percentage   | u8     | Percentage of the total supply bound to the bonding curve. |
| logo                        | String | URL to the coin's logo.                                    |
| banner                      | String | URL to the coin's banner.                                  |
| description                 | String | Description of the coin.                                   |
| links                       | vector | List of links related to the coin.                         |
| max\_wallet\_balance        | Option | Optional max wallet balance.                               |

***

#### **Buy Legacy Coin**

Allows users to buy coins based on the bonding curve.

```move
public(friend) fun buy<BuyCoinType, SellCoinType>(
    buyer: &signer,
    amount_base_value: u64,
    amount_exponent_value: u64
) acquires Info
```

| Input Values            | Type   | Description                          |
| ----------------------- | ------ | ------------------------------------ |
| buyer                   | signer | The buyer's reference.               |
| amount\_base\_value     | u64    | Base value of the amount to buy.     |
| amount\_exponent\_value | u64    | Exponent value of the amount to buy. |

***

#### **Sell Legacy Coin**

Allows users to sell coins back into the bonding curve.

```move
public(friend) fun sell<BuyCoinType, SellCoinType>(
    seller: &signer,
    amount_base_value: u64,
    amount_exponent_value: u64
) acquires Info
```

| Input Values            | Type   | Description                           |
| ----------------------- | ------ | ------------------------------------- |
| seller                  | signer | The seller's reference.               |
| amount\_base\_value     | u64    | Base value of the amount to sell.     |
| amount\_exponent\_value | u64    | Exponent value of the amount to sell. |

***

### View Functions

***

#### **Get Metadata**

Retrieves the metadata for the legacy coin.

```move
#[view]
public fun metadata<CoinType>(): (String, String, u8, u64, String, String, String, vector<String>) acquires CoinMetadata
```

| Return Values | Type   | Description                            |
| ------------- | ------ | -------------------------------------- |
| name          | String | Name of the coin.                      |
| symbol        | String | Symbol of the coin.                    |
| decimals      | u8     | Number of decimal places for the coin. |
| max\_supply   | u64    | Maximum supply of the coin.            |
| logo          | String | URL to the coin's logo.                |
| banner        | String | URL to the coin's banner.              |
| description   | String | Description of the coin.               |
| links         | vector | List of links related to the coin.     |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.yuzu.finance/move.fun/technical/coin-amm/core.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
