# BurnHook recipes

Every recipe has the same shape: **Preconditions** (check with `eth_call`), **Transaction**
(what to send), **Verify** (how to confirm it worked). Addresses come from `Lens.addresses()`;
ABIs from `assets/contracts.json`. `wallet` is the user's address.

Before any recipe: the hard rules in `SKILL.md` apply — verify addresses once per session, read
state, simulate, then send. Estimate gas with `eth_estimateGas`; do not hard-code gas limits.

Contents: [Read state](#read-state) · [Mint](#mint) · [Referral rewards](#referral-rewards) · [Share and invite](#share-and-invite) ·
[Refund](#refund) · [Finalize](#finalize) · [Buy BURN](#buy-burn) · [Sell BURN](#sell-burn) ·
[Burn into xBURN](#burn-into-xburn) · [Claim dividends](#claim-dividends) ·
[Wrap / unwrap wxBURN](#wrap--unwrap-wxburn) · [Compound](#compound) · [Events](#events)

---

## Read state

All on `BurnHookLens`; none cost gas.

| Call | Returns |
|---|---|
| `addresses()` | `burnToken, burnHook, xBurn, wxBurn, router, wrappedNative, agentId, dev, poolManager`. `xBurn` is zero before finalize; `wxBurn` / `router` are zero until registered. |
| `constants()` | `mintPrice, mintAmount, maxMints, maxMintsPerWallet, mintDuration, blockDelay, minMintsToInvite, directRewardBps, indirectRewardBps, devRewardBps, lpReserve, totalSupplyCap`. Trust these over any number written in prose. |
| `protocolState()` | `phase`, block/time, mint progress (`mintCount, mintsRemaining, mintDeadline, timeRemaining, nativeRaised`), reserves (`totalReferralReward, devReward`), pool (`finalized, tradingStartBlock, sqrtPriceX96, poolLiquidity, nativePerBurn`), supply (`burnTotalSupply, burnBurned`), xBURN/wxBURN (`xBurnTotalSupply, dividendPool, wxBurnTotalAssets, wxBurnTotalSupply, vaultPendingDividend`). |
| `mintStatus(wallet, inviter)` | `canMint, code, reason, value, inviterToPass, inviterNeeded, walletMintsUsed, walletMintsLeft`. |
| `position(wallet)` | `nativeBalance, burnBalance, xBurnBalance, wxBurnBalance, wxBurnAsXBurn, pendingDividend, referralReward, referralClaimable, mintsOf, inviter, hasAgentId, canInvite, refundableBurn, refundableNative`. |

`nativePerBurn` is the pool's spot price in wei of WBNB per 1 BURN (1e18), before the 1% hook fee.
It is for display and sanity checks only — never compute a swap's minimum output from it.

If the Lens is unavailable, the same data is on the core contracts: `BurnToken.currentPhase()`,
`mintCount()`, `mintsRemaining()`, `timeRemaining()`, `mintsOf(a)`, `hasAgentId(a)`, `canInvite(a)`,
`inviter(a)`, `referralReward(a)`; `BurnHook.finalized()`, `xBurn()`; `XBurn.pendingDividend(a)`.

---

## Mint

One call mints once: 0.005 BNB → 1,000 BURN. To mint `n` times, send `n` transactions one after
another (each needs the previous one mined, or consecutive nonces).

**Preconditions** — call `Lens.mintStatus(wallet, inviter)`:

- `canMint` must be `true`. If not, `reason` says why:

  | reason | Meaning | Do |
  |---|---|---|
  | `NOT_MINTING` | Phase is not 1. | Stop; report the phase. |
  | `AGENT_ID_REQUIRED` | Wallet holds no Binance Agent ID. | Stop; the user must get one for this wallet. |
  | `WALLET_LIMIT` | Wallet already minted 100 times. | Stop. |
  | `SOLD_OUT` | No mints left. | Stop. |
  | `INVITER_REQUIRED` | First mint needs a referrer and none was given. | Ask the user for a referral address. |
  | `SELF_INVITE` | Referrer is the wallet itself. | Ask for a different one. |
  | `INVITER_NOT_QUALIFIED` | Referrer has minted fewer than 10 times. | Ask for a different one. |
  | `INSUFFICIENT_BALANCE` | Balance below 0.005 BNB. | Stop; the wallet also needs BNB for gas. |

- `walletMintsLeft` caps how many times you may loop.
- The referrer: a referral link looks like `https://<site>/?ref=0x…` — the `ref` value is the
  inviter address. It is needed only on a wallet's **first** mint and is permanent afterwards.

**Transaction**

```
to:    BurnToken
value: mintStatus.value            (5000000000000000 wei)
data:  mint(address inviter)       inviter = mintStatus.inviterToPass
```

Always pass `inviterToPass` exactly as returned (it is the zero address whenever no inviter is
needed).

**Verify** — `Lens.position(wallet).mintsOf` increased by 1 and `burnBalance` by `1000e18`. The
receipt contains `Minted(user, amount, mintCount)`.

**Tell the user** — minted BURN cannot be transferred or sold until phase 4 (it can be burned into
xBURN from phase 3). If the mint does not
fill within 3 days, they can refund 100%.

---

## Referral rewards

A referrer earns 10% of every mint by wallets they referred, and 5% of every mint by wallets those
wallets referred, paid in BNB. To be a referrer a wallet must have minted at least 10 times
(`canInvite`).

**Preconditions** — `Lens.position(wallet)`: `referralClaimable == true` (phase 2, 3 or 4 and
`referralReward > 0`). During phase 1 rewards are locked; in phase 5 they are void.

**Transaction**

```
to:   BurnToken
data: withdrawReferralReward()
```

**Verify** — the wallet's BNB balance rose by `referralReward` (minus gas) and `referralReward` is
now 0. Event: `ReferralRewardClaimed(beneficiary, amount)`.

---

## Share and invite

Gives the user (or you, on their behalf) an invite link and ready-to-post copy. No transaction is
involved. Do this when the user asks to share, invite, or "get my referral link" — never post
anywhere on your own initiative.

**The invite link**

```
{site}/?ref={wallet}
```

`{site}` is the official site origin and `{wallet}` is the inviter's address. The address is what an
invitee passes as `inviter` in `mint(address inviter)`; the link just carries it.

**Preconditions** — `Lens.position(wallet).canInvite` must be `true` (the wallet has minted at least
10 times). If it is `false`, still give the link but say clearly that mints using it will revert with
`InviterNotQualified()` until the wallet has minted 10 times (`mintsOf` shows progress). Referral
rewards only accrue during phase 1; in later phases the link earns nothing — say so.

**Get the content in one call**

```
GET {site}/api/share?ref={wallet}
```

Returns JSON: `inviteLink`, `texts.en` / `texts.zh` each with `short` (fits in one X post), `post`
(longer, for Telegram / Discord / forums) and `agentPrompt` (instructions to hand to another AI
agent), plus `shareUrls.x` and `shareUrls.telegram` — links that open a pre-filled post.

Offline alternative: `assets/share.json` holds the same templates with `{site}`, `{ref}` and `{link}`
placeholders; fill them in yourself.

**Use it**

- Give the user the link and the text that fits where they want to post. Offer the `shareUrls` link
  so they can post with one click; the user presses send, not you.
- To recruit another agent, hand over `agentPrompt`: it tells that agent to read this skill, verify
  addresses, and use the wallet as inviter.
- You may shorten or translate the copy, but keep it factual: do not add return promises or price
  predictions, and keep the lines saying returns are not guaranteed and burning is permanent
  (`references/why-burnhook.md`, section 4).
- Do not send the link to people who did not ask for it, and do not post it repeatedly.

**What the inviter earns** — 10% of every mint by wallets that used the link, and 5% of every mint
by wallets those wallets invite, in BNB, withdrawable after the mint succeeds (see below).

---

## Refund

Only when the mint failed (phase 5). Returns exactly 0.005 BNB per 1,000 BURN — the full mint price.
There is no deadline.

**Preconditions** — `Lens.position(wallet)`: `refundableBurn > 0`.

**Transaction**

```
to:   BurnToken
data: refund(uint256 amount)       amount = position.refundableBurn (a multiple of 1000e18)
```

**Verify** — BNB balance rose by `refundableNative` (minus gas); BURN balance fell by `amount`.
Event: `Refunded(user, tokenBurned, ethReturned)`.

---

## Finalize

Creates the pool. Anyone may call it once the mint has filled; there is no reward for calling, only
gas cost. Do it only if the user asks.

**Preconditions** — `protocolState().phase == 2` and `finalized == false`.

**Transaction**

```
to:   BurnHook
data: finalize()
```

This uses a lot of gas (it deploys xBURN and mints a V4 position); rely on `eth_estimateGas`.

**Verify** — `protocolState().finalized == true`, phase is 3, and `tradingStartBlock` is set.
Trading opens automatically at that block. `Lens.addresses().xBurn` is now non-zero.

---

## Buy BURN

**Preconditions** — phase 4; `Lens.addresses().router` is non-zero; wallet holds the BNB plus gas.

**Step 1 — simulate to get the real output.** `eth_call` with `from = wallet`:

```
to:    BurnSwapRouter
value: amountIn (wei of BNB)
data:  swapExactEthForBurn(uint256 minBurnOut, address to, uint256 deadline)
       minBurnOut = 0, to = wallet, deadline = 0          ← simulation only
```

The return value `burnOut` is the exact amount at current state, after the 1% hook fee and price
impact.

**Step 2 — compute the minimum.** `minBurnOut = burnOut × (10000 − slippageBps) / 10000`. Use 100 bps
(1%) unless the user chose another tolerance. Tell the user the effective price
(`amountIn / burnOut`) versus spot (`nativePerBurn`); if it is more than a few percent worse, the
trade is large relative to the pool — say so and suggest splitting it.

**Step 3 — send.**

```
to:    BurnSwapRouter
value: amountIn
data:  swapExactEthForBurn(minBurnOut, wallet, deadline)     deadline = now + 600 (unix seconds)
```

**Verify** — BURN balance rose by at least `minBurnOut`. Event: `Swap(sender, to, tokenIn, tokenOut,
amountIn, amountOut)`.

To pay with WBNB instead of BNB: `approve(router, amountIn)` on WBNB, then
`swapExactWethForBurn(amountIn, minBurnOut, to, deadline)` with no `value`.

---

## Sell BURN

**Preconditions** — phase 4; `position.burnBalance >= amountIn`.

**Step 1 — approve** (skip if `BurnToken.allowance(wallet, router) >= amountIn`):

```
to:   BurnToken
data: approve(address spender, uint256 amount)     spender = router, amount = amountIn
```

Wait for it to be mined. Approve the exact amount, not an unlimited one, unless the user asks.

**Step 2 — simulate** with `eth_call`, `from = wallet`:

```
to:   BurnSwapRouter
data: swapExactBurnForEth(uint256 amountIn, uint256 minEthOut, address to, uint256 deadline)
      minEthOut = 0, to = wallet, deadline = 0            ← simulation only
```

(The simulation reverts with `ERC20InsufficientAllowance` if step 1 is not mined yet. For a rough
figure before approving, `BurnSwapRouter.quoteExactInput(BurnToken, amountIn)` gives a spot estimate
that ignores price impact — fine to show the user, never to use as `minEthOut`.)

**Step 3 — send** the same call with `minEthOut = simulated × (10000 − slippageBps) / 10000` and
`deadline = now + 600`.

**Verify** — BNB balance rose by at least `minEthOut` (minus gas). To receive WBNB instead, use
`swapExactBurnForWeth` with the same arguments.

---

## Burn into xBURN

**Irreversible.** The BURN goes to the dead address and can never be recovered; xBURN cannot be
converted back. What the wallet gets is a permanent pro-rata share of the 1% swap fee from that
moment on. State this and get an explicit yes before sending.

**Preconditions** — phase 3 or 4; `position.burnBalance >= amount`. In phase 3 (the cooldown) this is
the only thing BURN can be used for; doing it then means the position already earns from the first
swap after trading opens, but the user commits before any market price exists — say both.

**Step 1 — approve** BURN to xBURN:

```
to:   BurnToken
data: approve(xBurn, amount)
```

**Step 2 — deposit**

```
to:   XBurn
data: deposit(uint256 assets, address receiver)     assets = amount, receiver = wallet
```

**Verify** — `position.xBurnBalance` rose by exactly `amount` (always 1:1) and `burnBalance` fell by
`amount`.

Never call `withdraw` or `redeem` on xBURN: they always revert (max is 0).

---

## Claim dividends

Dividends are WBNB. They accrue continuously; `position.pendingDividend` is the claimable amount.

**Preconditions** — `position.xBurnBalance >= 1` and `pendingDividend > 0`. Check that
`pendingDividend` is worth more than the gas.

**Transaction**

```
to:   XBurn
data: claim(uint256 xBurnAmount)     xBurnAmount = 1
```

`claim(n)` pays **all** pending WBNB and burns `n` wei of xBURN. Always pass `1` (one wei): passing
more destroys the user's xBURN for nothing. Only pass a larger `n` if the user explicitly wants to
give up that much of their position.

**Verify** — WBNB balance rose by the previous `pendingDividend`; `pendingDividend` is now 0.

Note: transferring xBURN also pays out both parties' pending dividends automatically.

---

## Wrap / unwrap wxBURN

wxBURN is an ERC4626 vault over xBURN. It auto-compounds (see below), so each wxBURN is redeemable for
a growing amount of xBURN. Use it when the user wants a token that is safe to trade or pool on a DEX,
or wants compounding instead of claiming WBNB. wxBURN has **21 decimals**.

**Wrap** — preconditions: phase 3 or 4, `Lens.addresses().wxBurn` non-zero, `position.xBurnBalance >=
amount`.

```
1. to: XBurn          data: approve(wxBurn, amount)
2. to: WrappedXBurn   data: deposit(uint256 assets, address receiver)   assets = amount, receiver = wallet
```

The deposit transfers xBURN, which first pays the wallet's pending WBNB dividends to the wallet — expected.
Preview the shares with `WrappedXBurn.previewDeposit(amount)`.

**Unwrap**

```
to:   WrappedXBurn
data: redeem(uint256 shares, address receiver, address owner)   receiver = owner = wallet
```

Preview with `previewRedeem(shares)`; `position.wxBurnAsXBurn` is the xBURN for the whole balance.

**Verify** — `position.wxBurnBalance` / `xBurnBalance` changed by the previewed amounts.

---

## Compound

Anyone may trigger the vault's compounding and keeps 0.5% of the harvested WBNB as a bounty. It
harvests the vault's dividends, buys BURN in the protocol pool and burns it into more xBURN for the
vault.

**Preconditions** — phase 4; `protocolState().vaultPendingDividend > 0`. The bounty is
`vaultPendingDividend × 50 / 10000`; only worth doing when that exceeds the gas cost — compare with
`eth_estimateGas × gasPrice`.

**Transaction**

```
to:   WrappedXBurn
data: compoundFromDividend(uint256 minBurnOut)     minBurnOut = 0
```

Passing 0 here is safe (and the one exception to hard rule 6): the contract itself enforces a 2%
maximum slippage against the pool's spot price and reverts with `Slippage()` otherwise. Simulate
first — the return values are `(burnOut, xBurnGained, bounty)`.

**Verify** — the wallet's WBNB balance rose by `bounty`; `wxBurnTotalAssets` rose by `xBurnGained`.
Event: `CompoundedFromDividend(caller, wethSwapped, burnOut, xBurnGained, bounty)`.

`compound(uint256 burnAmount)` is different: it **donates** the caller's BURN to the vault. Never call
it unless the user explicitly wants to donate.

---

## Events

Useful for confirming a transaction or watching the protocol.

| Contract | Event | When |
|---|---|---|
| BurnToken | `MintStarted(startTime, deadline)` | Mint opened. |
| BurnToken | `Minted(user, amount, mintCount)` | Each mint. |
| BurnToken | `InviterSet(user, inviter)` | A wallet's referrer was bound. |
| BurnToken | `ReferralRewardAccrued(beneficiary, source, amount, isDirect)` | Reward credited to a referrer. |
| BurnToken | `ReferralRewardClaimed(beneficiary, amount)` | Referrer withdrew. |
| BurnToken | `DevRewardClaimed(dev, amount)` | Dev share paid to the DEV address. |
| BurnToken | `MintFailed(finalMintCount)` · `Refunded(user, tokenBurned, ethReturned)` | Failure and refunds. |
| BurnToken | `Bonded(ethToLP, tokenToLP, lpTokenId)` | Liquidity handed to the hook at finalize. |
| BurnHook | `Finalized(pool, ethToLP, burnToLP, xBurnAddr)` · `LPBurned(tokenId)` | Pool created, LP locked. |
| BurnHook | `FeeCollected(amount)` | 1% fee taken on a swap. |
| XBurn | `DividendReceived(amount, dividendPool)` · `DividendSettled(user, amount)` | Fee arrived / paid out. |
| WrappedXBurn | `CompoundedFromDividend(caller, wethSwapped, burnOut, xBurnGained, bounty)` | Vault compounded. |
| BurnSwapRouter | `Swap(sender, to, tokenIn, tokenOut, amountIn, amountOut)` | Router swap. |
