> For the complete documentation index, see [llms.txt](https://robinfun.gitbook.io/robinfun-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://robinfun.gitbook.io/robinfun-docs/contract-interface.md).

# contract interface

This page documents the on-chain interface of the RobinFun factory and the ROBINFUN staking pool, for developers who want to integrate directly. Addresses are listed in [Contract addresses](broken://pages/0b05183159c7a8fa30cd38d105dbe7b9aebf8d11).

All amounts are in wei (18 decimals) unless noted. USD-denominated values use 8 decimals.

## Factory — write functions

### `createToken`

Deploys a new token and its bonding curve in one transaction.

```solidity
function createToken(
    string  name,          // up to 32 characters
    string  symbol,        // up to 11 characters
    uint256 supply,        // 0 = default 1B; else 10,000e18..1,000,000,000e18 in steps of 10e18
    bool    stakingEnabled,// true reserves 10% of supply for a staking pool
    uint256 initialBuyEth, // optional self-buy executed in the same transaction
    address feeRecipient,  // receives the 0.5% creator fee; address(0) = caller
    bytes32 salt           // CREATE2 salt; the resulting address must end in 0x4663
) external payable returns (address token)
```

`msg.value` must cover `initialBuyEth` plus the creation fee, if one is configured; any excess is refunded. The app mines the vanity `salt` for you automatically.

### `buy`

```solidity
function buy(address token, uint256 minTokensOut) external payable returns (uint256 tokensOut)
```

Buys from the curve with the ETH sent as `msg.value`. A 1% fee is taken in ETH. If your ETH would push the curve past its raise target, the surplus is refunded. Reverts with `SLIPPAGE` if the output falls below `minTokensOut`.

### `sell`

```solidity
function sell(address token, uint256 tokensIn, uint256 minEthOut) external returns (uint256 ethOut)
```

Sells back into the curve. Requires a prior token approval to the factory. A 1% fee is taken from the ETH proceeds. Reverts with `SLIPPAGE` if the output falls below `minEthOut`.

### `graduate`

```solidity
function graduate(address token) external
```

Finalizes graduation once a curve is full. **Permissionless** — anyone may call it. Creates (or rebalances) the Uniswap V2 pair, adds liquidity, burns 100% of the LP, and pays the treasury share.

## Factory — read functions

| Function                                     | Returns                                                                                                                                                                     |
| -------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `quoteBuy(address token, uint256 ethIn)`     | Estimated tokens out for a buy (before slippage).                                                                                                                           |
| `quoteSell(address token, uint256 tokensIn)` | Estimated ETH out for a sell.                                                                                                                                               |
| `currentPrice(address token)`                | Current curve price, in wei per token.                                                                                                                                      |
| `curves(address token)`                      | Full curve state: `virtualEth`, `realEth`, `tokenReserve`, `raiseTarget`, `lpEth`, `treasuryEth`, `k`, `readyToGraduate`, `graduated`, `creator`, `feeRecipient`, `supply`. |
| `staking(address token)`                     | The token's staking pool, or `address(0)` when staking wasn't enabled.                                                                                                      |
| `ethUsdPrice()`                              | The ETH/USD price (8 decimals) used to snapshot new curves.                                                                                                                 |

## Factory — events

| Event                                                                                         | Emitted when                                         |
| --------------------------------------------------------------------------------------------- | ---------------------------------------------------- |
| `TokenCreated(token, creator, name, symbol, supply, ethUsdSnapshot, virtualEth, raiseTarget)` | A token is launched.                                 |
| `Buy(token, buyer, ethIn, tokensOut, newRealEth, newPriceWeiPerToken)`                        | A curve buy executes.                                |
| `Sell(token, seller, tokensIn, ethOut, newRealEth, newPriceWeiPerToken)`                      | A curve sell executes.                               |
| `ReadyToGraduate(token, realEth)`                                                             | A curve reaches its raise target.                    |
| `Graduated(token, pair, lpEth, lpTokens, treasuryEth, liquidityBurned)`                       | Graduation finalizes.                                |
| `StakingPoolCreated(token, pool, durationDays)` / `StakingFunded(token, pool, amount)`        | A staking-enabled launch deploys and funds its pool. |
| `FeeCollected(token, amount)`                                                                 | A trade fee is collected.                            |

## Factory — common revert codes

| Code                                    | Meaning                                                                   |
| --------------------------------------- | ------------------------------------------------------------------------- |
| `BAD_NAME` / `BAD_SYMBOL`               | Name over 32 chars, symbol over 11 chars, or empty.                       |
| `BAD_SUPPLY`                            | Supply outside 10,000–1,000,000,000.                                      |
| `SUPPLY_GRANULARITY`                    | Supply not a multiple of 10 tokens (`10e18` wei).                         |
| `BAD_SUFFIX`                            | The salt doesn't produce an address ending in `0x4663`.                   |
| `NOT_TRADABLE`                          | The token is graduated or awaiting graduation — trade on Uniswap instead. |
| `SLIPPAGE`                              | Output fell below your `minTokensOut` / `minEthOut`.                      |
| `ZERO_ETH` / `ZERO_TOKENS` / `ZERO_OUT` | Zero-value trade.                                                         |
| `NOT_READY`                             | `graduate` called before the curve is full.                               |

## ROBINFUN staking pool

The revenue-share pool is a standalone, immutable contract — no owner, no pause, no parameter setters.

### Write functions

```solidity
function stake(uint256 amount, uint256 lockDays) external returns (uint256 id)  // lockDays ∈ {14, 30, 45, 60}
function withdraw(uint256 id) external      // principal + reward, after the position's unlock
function getReward(uint256 id) external     // claim ETH only, after unlock
function claimOwed() external               // pull ETH that a previous payout deferred
```

### Read functions

| Function                                                                | Returns                             |
| ----------------------------------------------------------------------- | ----------------------------------- |
| `earned(address user, uint256 id)`                                      | ETH accrued by one position.        |
| `positions(address user, uint256 id)` / `positionsLength(address user)` | Position details / count.           |
| `stakedOf(address user)`                                                | Total ROBINFUN a wallet has staked. |
| `rewardPool()`                                                          | ETH available for future streams.   |
| `totalStaked()` / `totalWeight()` / `periodFinish()` / `rewardRate()`   | Pool-level stream state.            |

### Events

`Staked`, `Withdrawn`, `RewardPaid`, `RewardAdded`, `Funded`, `RewardDeferred`, `OwedClaimed`.

### Common revert codes

| Code                 | Meaning                                                                             |
| -------------------- | ----------------------------------------------------------------------------------- |
| `BAD_LOCK`           | `lockDays` not one of 14 / 30 / 45 / 60.                                            |
| `LOCKED`             | The position's lock hasn't expired yet.                                             |
| `STREAM_ENDED`       | The current reward stream has finished; staking reopens when a new stream is armed. |
| `TOO_MANY_POSITIONS` | The wallet already has 100 open positions.                                          |
| `NOTHING_OWED`       | `claimOwed` called with no deferred ETH.                                            |

> **Note**: Per-token staking pools (created for launches with staking enabled) expose the same position model — `stake(amount, lockDays)`, `withdraw(id)`, `getReward(id)` — with the launched token as both the staked and the reward asset.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://robinfun.gitbook.io/robinfun-docs/contract-interface.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
