# API Reference

Complete reference for all LiquidLaunch contract functions, events, and constants.

## Contract Address

* **LiquidLaunch**: `0xDEC3540f5BA6f2aa3764583A9c29501FeB020030`

## Functions

### Token Creation

#### createToken

```solidity
function createToken(
    string memory name,
    string memory symbol,
    string memory image_uri,
    string memory description,
    string memory website,
    string memory twitter,
    string memory telegram,
    string memory discord,
    uint8 dexIndex
) external payable returns (address tokenAddress)
```

Creates a new token with bonding curve trading. Any HYPE sent with this transaction will be automatically used to purchase tokens for the creator as anti-sniper protection. Use `dexIndex` 0.

### Trading Functions

#### buyTokens

```solidity
function buyTokens(address token) external payable
```

Purchase tokens by sending HYPE. 1% fee applies (50/50 split: creator and protocol).

#### sellTokens

```solidity
function sellTokens(address token, uint256 tokenAmount) external
```

Sell tokens back to the bonding curve. 1% fee applies (50/50 split: creator and protocol). No approval required.

### Liquidity & Price Functions

#### getLiquidity

```solidity
function getLiquidity(address token) public view returns (uint256 hypeReserve, uint256 tokenReserve)
```

Get current virtual reserves for a token.

#### estimateBuy

```solidity
function estimateBuy(address token, uint256 hypeAmount) public view returns (uint256)
```

Estimate tokens received for HYPE input (includes 1% fee deduction).

#### estimateSell

```solidity
function estimateSell(address token, uint256 tokenAmount) public view returns (uint256)
```

Estimate HYPE received for token input (includes 1% fee deduction).

### Token Information

#### getTokenMetadata

```solidity
function getTokenMetadata(address token) external view returns (TokenMetadata memory)
```

Get complete token metadata and state.

#### getTokenCreator

```solidity
function getTokenCreator(address tokenAddress) external view returns (address)
```

Get the creator address for a token.

#### getTokenCount

```solidity
function getTokenCount() external view returns (uint256)
```

Get total number of tokens created.

#### getPaginatedTokensWithMetadata

```solidity
function getPaginatedTokensWithMetadata(uint256 start, uint256 limit) 
    external view returns (address[] memory tokens, TokenMetadata[] memory metadata)
```

Get tokens and metadata with pagination.

### Fee Functions

#### claimFees

```solidity
function claimFees(address token) external returns (uint256 whypeReceived)
```

Distributes accumulated fees for a token. **Anyone can call**; only the protocol and the token creator receive the 50/50 split. The caller does not receive fees.

#### previewClaimFees

```solidity
function previewClaimFees(address token) external returns (uint256 whypeAmount, uint256 tokensAmount)
```

Preview fees available for claiming. Must be called using a static call.

#### getClaimedFeesAndBurnedTokens

```solidity
function getClaimedFeesAndBurnedTokens(address token) 
    external view returns (uint256 claimedFees, uint256 burnedTokens)
```

Get total fees claimed and tokens burned for a token.

## Events

### Token Lifecycle

#### TokenCreated

```solidity
event TokenCreated(
    address indexed token,
    address indexed creator,
    string name,
    string symbol,
    string image_uri,
    string description,
    string website,
    string twitter,
    string telegram,
    string discord,
    uint256 creationTimestamp,
    uint256 startingLiquidity,
    uint256 currentHypeReserves,
    uint256 currentTokenReserves,
    uint256 totalSupply,
    uint256 currentPrice,
    uint256 initialPurchaseAmount
);
```

### Trading Events

#### TokensPurchased

```solidity
event TokensPurchased(
    address indexed token,
    address indexed buyer,
    uint256 hypeIn,
    uint256 tokensOut,
    uint256 price,
    uint256 timestamp,
    uint256 hypeReserves,
    uint256 tokenReserves,
    uint256 totalSupply,
    string name,
    string symbol
);
```

#### TokensSold

```solidity
event TokensSold(
    address indexed token,
    address indexed seller,
    uint256 tokensIn,
    uint256 hypeOut,
    uint256 price,
    uint256 timestamp,
    uint256 hypeReserves,
    uint256 tokenReserves,
    uint256 totalSupply,
    string name,
    string symbol
);
```

### Metadata Events

#### TokenMetadataUpdated

```solidity
event TokenMetadataUpdated(
    address indexed token,
    address indexed creator,
    string name,
    string symbol,
    string image_uri,
    string description,
    string website,
    string twitter,
    string telegram,
    string discord,
    uint256 timestamp
);
```

## Data Structures

### TokenMetadata

```solidity
struct TokenMetadata {
    string name;
    string symbol;
    string image_uri;
    string description;
    string website;
    string twitter;
    string telegram;
    string discord;
    address creator;
    uint256 creationTimestamp;
    uint256 startingLiquidity;
    uint8 dexIndex;
}
```

## Constants

### Token Economics

```solidity
uint256 public constant VIRTUAL_HYPE_LIQUIDITY = 300 ether;
uint256 public constant TOTAL_SUPPLY = 1_000_000_000 * 10 ** 6;
uint256 public constant TOKENS_FOR_SALE = 649_300_000 * 10 ** 6;
```

## Error Codes

### General Errors

* `ZeroAddress()`: Address cannot be zero
* `ZeroAmount()`: Amount cannot be zero
* `EthTransferFailed()`: ETH transfer failed
* `TokenTransferFailed()`: Token transfer failed
* `InsufficientBalance()`: Insufficient balance

### Token Lifecycle Errors

* `TokenNotCreatedByFactory()`: Token not created by this factory
* `TokenCreationFailed()`: Token creation failed
* `TokenFrozen()`: Token is frozen
* `TokenNotFound()`: Token not found

### Trading Errors

* `TokenPurchaseFailed()`: Token purchase failed
* `InsufficientLiquidity()`: Insufficient liquidity
* `CreatorCannotSellYet()`: Creator cannot sell yet (1-hour lock)

### Authorization Errors

* `UnauthorizedMetadataUpdate()`: Unauthorized metadata update

This reference covers all publicly accessible functions and events in the LiquidLaunch contract.
