> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lfg.rich/llms.txt
> Use this file to discover all available pages before exploring further.

# Contract Reference

> Main LFG.RICH V5 contract addresses, integration notes, and readable ABI string constants.

This page gives developers the public contract information needed to integrate with LFG.RICH. Users do **not** need access to the site source code. The readable ABI arrays below can be copied directly into Ethers, Viem `parseAbi`, Web3.js, or Web3.py integrations.

<CardGroup cols={2}>
  <Card title="Factory" icon="industry">
    Creates official LFG.RICH tokens and registers them with the Hook.
  </Card>

  <Card title="Uniswap V4 Hook" icon="anchor">
    Handles pricing, floors, reserves, fees, collateral, borrowing, and hook callbacks.
  </Card>

  <Card title="Swap Router" icon="route">
    Provides simple buy and sell functions for users and integrations.
  </Card>

  <Card title="Token" icon="coin">
    ERC20-compatible token contract created by the Factory.
  </Card>

  <Card title="Pool Manager" icon="layer-group">
    Uniswap V4 Pool Manager used by the Hook and Router flow.
  </Card>

  <Card title="Referral and Treasury" icon="people-arrows">
    Handles invite bindings, referral reward routing, and platform-side accounting.
  </Card>
</CardGroup>

<Warning>
  Use the V5 signatures shown on this page. Older examples that call `createToken(name, symbol, totalFeeBps)`, `estimateBuy(poolId, ethIn)`, or `estimateSell(poolId, tokenAmount)` are outdated.
</Warning>

## BNB Smart Chain V5 addresses

| Contract          | Address                                      |
| ----------------- | -------------------------------------------- |
| Factory           | `0x429a7ef0129649a97bb3f1e961dd56d9bd4ac01f` |
| Uniswap V4 Hook   | `0xc18e6e1926113cdcf53f3ec1a89d3eb84cc6a888` |
| Swap Router       | `0x4018abd5d24ee48c642e7e518a8aef03b59ec150` |
| Referral / Invite | `0x162e11887f6788ac9625a980e68044bee7f9d746` |
| Treasury          | `0xdb5b8aa5cecf7a6fe1812fb2ccc37723076b19d9` |
| Pool Manager      | `0x28e2Ea090877bF75740558f6BFB36A5ffeE9e9dF` |

## Network constants

| Value                                    | Meaning                                      |
| ---------------------------------------- | -------------------------------------------- |
| Chain ID                                 | `56`                                         |
| Native currency                          | BNB                                          |
| Pool fee                                 | `3000`                                       |
| Tick spacing                             | `60`                                         |
| Native currency address inside `PoolKey` | `0x0000000000000000000000000000000000000000` |
| ABI version                              | `v5`                                         |

## Important V5 interaction rules

Every token created on LFG.RICH has its own `poolId` and its own Uniswap V4 `PoolKey`.

For reliable integrations:

<Steps>
  <Step title="Load the token">
    Start from the public API or from Factory-created token data.
  </Step>

  <Step title="Resolve the poolId">
    Use `token.pool_id`, `token.poolId`, or `hook.tokenToPoolId(tokenAddress)`.
  </Step>

  <Step title="Resolve or build the PoolKey">
    Prefer `factory.getPoolKey(tokenAddress)` when available.
  </Step>

  <Step title="Quote through the Hook">
    Use `poolId` and the wallet address for V5 buy/sell estimates.
  </Step>

  <Step title="Execute swaps through the Swap Router">
    Buy and sell calls use the token-specific PoolKey.
  </Step>

  <Step title="Execute lending through the Hook">
    Borrow, borrow more, repay, and price reads use `poolId`.
  </Step>
</Steps>

<Info>
  The API token object normally includes `pool_id`. You can use that value, but external tools should still know how to resolve the same value from `hook.tokenToPoolId(tokenAddress)` or `factory.getTokenInfo(tokenAddress).poolId`.
</Info>

## Factory ABI

The Factory creates official LFG.RICH tokens, stores token metadata, stores creator ownership, and exposes `PoolKey` data for each token.

```ts theme={null}
export const FACTORY_V5_ABI = [
  "function owner() view returns (address)",
  "function poolManager() view returns (address)",
  "function hook() view returns (address)",
  "function creationFee() view returns (uint256)",
  "function POOL_FEE() view returns (uint24)",
  "function TICK_SPACING() view returns (int24)",
  "function INIT_SQRT_PRICE() view returns (uint160)",
  "function allTokens(uint256) view returns (address)",
  "function tokenToCreator(address) view returns (address)",
  "function tokenInfoMap(address) view returns (address tokenAddress, uint256 tokenId, address creator, string name, string symbol, bytes32 poolId)",
  "function setInviteContract(address _invite)",
  "function setInviteRewardsEnabled(bool _enabled)",
  "function createToken(string name, string symbol, uint256 devBuyEth) payable returns (address token, bytes32 poolId)",
  "function setCreationFee(uint256 newFee)",
  "function transferOwnership(address newOwner)",
  "function withdrawAll(address to)",
  "function updateCreator(address token, address newCreator)",
  "function totalTokens() view returns (uint256)",
  "function isOfficialToken(address token) view returns (bool)",
  "function getTokenInfo(address token) view returns (tuple(address tokenAddress, uint256 tokenId, address creator, string name, string symbol, bytes32 poolId))",
  "function getUserTokens(address user) view returns (address[])",
  "function getPoolKey(address token) view returns (tuple(address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks))",
  "event TokenCreated(address indexed token, uint256 indexed tokenId, address indexed creator, string name, string symbol, bytes32 poolId)",
  "event DevBuy(address indexed token, address indexed creator, uint256 ethAmount, bytes32 poolId)",
  "event CreationFeeUpdated(uint256 oldFee, uint256 newFee)",
  "event Withdrawn(address indexed to, uint256 amount)",
  "event CreatorUpdated(address indexed token, address indexed oldCreator, address indexed newCreator)",
  "event InviteContractUpdated(address indexed inviteContract)",
  "event InviteRewardsToggled(bool enabled)"
] as const;
```

### Factory notes

`createToken(name, symbol, devBuyEth)` creates the token and optionally performs an initial creator buy. The transaction value must cover `creationFee + devBuyEth`. Token description, logo, website, X/Twitter, Telegram, QQ group, and other metadata are saved through the public application API after the token is created.

## Uniswap V4 Hook ABI

The Hook contains the LFG.RICH protocol logic for token state, price estimates, fees, floor price support, borrowing, borrow more, repayment, and events.

```ts theme={null}
export const HOOK_V5_ABI = [
  "function BPS_DENOMINATOR() view returns (uint256)",
  "function TOTAL_FEE_BPS() view returns (uint256)",
  "function PLATFORM_FEE_BPS() view returns (uint256)",
  "function INVITER_FEE_BPS() view returns (uint256)",
  "function BORROW_FEE_BPS() view returns (uint256)",
  "function BORROW_PLATFORM_FEE_BPS() view returns (uint256)",
  "function BORROW_PARENT_FEE_BPS() view returns (uint256)",
  "function COLLATERAL_RATIO_BPS() view returns (uint256)",
  "function DUST_THRESHOLD() view returns (uint256)",
  "function MIN_SWEEP_AMOUNT() view returns (uint256)",
  "function DEFAULT_AUTO_FLOOR_PCT_BPS() view returns (uint256)",
  "function POOL_FEE() view returns (uint24)",
  "function POOL_MANAGER() view returns (address)",
  "function TREASURY() view returns (address)",
  "function FACTORY() view returns (address)",
  "function K() view returns (uint256)",
  "function inviteContract() view returns (address)",
  "function inviteRewardsEnabled() view returns (bool)",
  "function tokenStates(bytes32) view returns (address token, address creator, uint256 floorPrice, uint256 realETH, uint256 virtualETH, uint256 totalBorrowedETH, uint256 collateralSupply, uint256 allTimeHighPrice, uint256 k, uint256 autoFloorPctBps, bool initialized)",
  "function tokenToPoolId(address) view returns (bytes32)",
  "function borrowedETH(bytes32, address) view returns (uint256)",
  "function collateralBalance(bytes32, address) view returns (uint256)",
  "function totalPurchasedETH(address) view returns (uint256)",
  "function effectiveETH(bytes32 poolId) view returns (uint256)",
  "function getEffectivePrice(bytes32 poolId) view returns (uint256)",
  "function circulatingSupply(bytes32 poolId) view returns (uint256)",
  "function maxFloorPrice(bytes32 poolId) view returns (uint256)",
  "function getTokenK(bytes32 poolId) view returns (uint256)",
  "function getAutoFloorPct(bytes32 poolId) view returns (uint256)",
  "function estimateBuy(bytes32 poolId, uint256 ethIn, address buyer) view returns (uint256 tokensOut, uint256 platformFee, uint256 inviterFee)",
  "function estimateSell(bytes32 poolId, uint256 tokenAmount, address seller) view returns (uint256 ethOut, uint256 platformFee, uint256 inviterFee)",
  "function estimateBorrowMore(bytes32 poolId, address user) view returns (uint256 additionalEth, uint256 fee)",
  "function getHookPermissions() pure returns (tuple(bool beforeInitialize, bool afterInitialize, bool beforeAddLiquidity, bool afterAddLiquidity, bool beforeRemoveLiquidity, bool afterRemoveLiquidity, bool beforeSwap, bool afterSwap, bool beforeDonate, bool afterDonate, bool beforeSwapReturnDelta, bool afterSwapReturnDelta, bool afterAddLiquidityReturnDelta, bool afterRemoveLiquidityReturnDelta))",
  "function registerToken(address token, bytes32 poolId, address creator)",
  "function updateCreator(bytes32 poolId, address newCreator)",
  "function setInviteContract(address _invite)",
  "function setInviteRewardsEnabled(bool _enabled)",
  "function borrow(bytes32 poolId, uint256 amount)",
  "function borrowMore(bytes32 poolId)",
  "function repay(bytes32 poolId) payable",
  "function devMint(bytes32 poolId, address dev) payable",
  "function beforeInitialize(address, tuple(address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks) key, uint160) returns (bytes4)",
  "function afterInitialize(address, tuple(address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks), uint160, int24) pure returns (bytes4)",
  "function beforeAddLiquidity(address, tuple(address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks), tuple(int24 tickLower, int24 tickUpper, int256 liquidityDelta, bytes32 salt), bytes) returns (bytes4)",
  "function afterAddLiquidity(address, tuple(address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks), tuple(int24 tickLower, int24 tickUpper, int256 liquidityDelta, bytes32 salt), int256, int256, bytes) pure returns (bytes4, int256)",
  "function beforeRemoveLiquidity(address, tuple(address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks), tuple(int24 tickLower, int24 tickUpper, int256 liquidityDelta, bytes32 salt), bytes) pure returns (bytes4)",
  "function afterRemoveLiquidity(address, tuple(address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks), tuple(int24 tickLower, int24 tickUpper, int256 liquidityDelta, bytes32 salt), int256, int256, bytes) pure returns (bytes4, int256)",
  "function beforeSwap(address, tuple(address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks) key, tuple(bool zeroForOne, int256 amountSpecified, uint160 sqrtPriceLimitX96) params, bytes hookData) returns (bytes4 selector, int256 delta, uint24 lpFeeOverride)",
  "function afterSwap(address, tuple(address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks), tuple(bool zeroForOne, int256 amountSpecified, uint160 sqrtPriceLimitX96), int256, bytes) pure returns (bytes4, int128)",
  "function beforeDonate(address, tuple(address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks), uint256, uint256, bytes) pure returns (bytes4)",
  "function afterDonate(address, tuple(address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks), uint256, uint256, bytes) pure returns (bytes4)",
  "event TokenRegistered(address indexed token, bytes32 indexed poolId, address creator)",
  "event Buy(bytes32 indexed poolId, address indexed buyer, uint256 ethIn, uint256 tokensOut, uint256 newPrice)",
  "event Sell(bytes32 indexed poolId, address indexed seller, uint256 tokensIn, uint256 ethOut, uint256 newPrice)",
  "event FloorRaised(bytes32 indexed poolId, uint256 oldFloor, uint256 newFloor)",
  "event ATHUpdated(bytes32 indexed poolId, uint256 oldATH, uint256 newATH)",
  "event KUpdated(bytes32 indexed poolId, uint256 oldK, uint256 newK)",
  "event Borrow(bytes32 indexed poolId, address indexed user, uint256 tokensLocked, uint256 ethBorrowed, uint256 fee)",
  "event BorrowMore(bytes32 indexed poolId, address indexed user, uint256 additionalEth, uint256 fee)",
  "event Repay(bytes32 indexed poolId, address indexed user, uint256 ethRepaid, uint256 tokensUnlocked)",
  "event Sweep(bytes32 indexed poolId, uint256 amount)",
  "event DustCollected(bytes32 indexed poolId, uint256 amount)",
  "event CreatorUpdated(bytes32 indexed poolId, address indexed oldCreator, address indexed newCreator)",
  "event InviteContractUpdated(address indexed oldInvite, address indexed newInvite)",
  "event InviteRewardsToggled(bool enabled)"
] as const;
```

### Hook notes

`estimateBuy` and `estimateSell` include the user address because referral state can change the fee split. If the wallet is not connected, use the zero address only for display-only estimates. Real trading tools should estimate again after the wallet is connected.

`tokenStates(poolId)` in V5 returns `floorPrice`, `realETH`, `virtualETH`, `totalBorrowedETH`, `collateralSupply`, `allTimeHighPrice`, `k`, and `autoFloorPctBps`. Older fields such as `floorBoostPool` or `totalReserveAccumulated` are not part of the V5 Hook state.

## Swap Router ABI

The Swap Router is the user-facing contract for buys and sells.

```ts theme={null}
export const SWAP_ROUTER_V5_ABI = [
  "function poolManager() view returns (address)",
  "function buy(tuple(address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks) key, uint256 minTokensOut) payable",
  "function sell(tuple(address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks) key, uint256 tokenAmount, uint256 minEthOut)",
  "function unlockCallback(bytes data) returns (bytes)"
] as const;
```

## Token ABI

Every token created by the Factory is an ERC-20 token controlled by the Hook for protocol mint and burn operations.

```ts theme={null}
export const TOKEN_V5_ABI = [
  "function name() view returns (string)",
  "function symbol() view returns (string)",
  "function decimals() view returns (uint8)",
  "function totalSupply() view returns (uint256)",
  "function balanceOf(address account) view returns (uint256)",
  "function transfer(address to, uint256 amount) returns (bool)",
  "function approve(address spender, uint256 amount) returns (bool)",
  "function transferFrom(address from, address to, uint256 amount) returns (bool)",
  "function allowance(address owner, address spender) view returns (uint256)",
  "function increaseAllowance(address spender, uint256 addedValue) returns (bool)",
  "function decreaseAllowance(address spender, uint256 subtractedValue) returns (bool)",
  "function FACTORY() view returns (address)",
  "function hook() view returns (address)",
  "function hookLocked() view returns (bool)",
  "function setHook(address _hook)",
  "function mint(address to, uint256 amount)",
  "function burn(address from, uint256 amount)",
  "event Transfer(address indexed from, address indexed to, uint256 value)",
  "event Approval(address indexed owner, address indexed spender, uint256 value)"
] as const;
```

## Referral ABI

The Referral contract stores invitation relationships used by the V5 fee system.

```ts theme={null}
export const REFERRAL_V5_ABI = [
  "function owner() view returns (address)",
  "function isWhitelist(address) view returns (bool)",
  "function initialInviter(address) view returns (address)",
  "function parent(address) view returns (address)",
  "function inviteCount(address) view returns (uint256)",
  "function isBound(address) view returns (bool)",
  "function transferOwnership(address newOwner)",
  "function setWhitelist(address[] addrs, bool status)",
  "function bind(address inviter)",
  "function getInfo(address user) view returns (address _initialInviter, address _parent, uint256 _inviteCount, bool _isBound)",
  "event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)",
  "event WhitelistUpdated(address indexed addr, bool status)",
  "event Bound(address indexed user, address indexed inviter, address indexed initialInv)"
] as const;
```

## Treasury ABI

The Treasury receives protocol funds that can be flushed to the configured recipient.

```ts theme={null}
export const TREASURY_ABI = [
  "function owner() view returns (address)",
  "function recipient() view returns (address)",
  "function setRecipient(address _recipient)",
  "function flush()"
] as const;
```

## Recommended public config endpoint

For integrations that do not want to hardcode addresses and ABIs, fetch the public config endpoint:

```js theme={null}
const res = await fetch('https://lfg.rich/api/bsc/tokens/config/contracts');
const json = await res.json();

console.log(json.data.factoryAddress);
console.log(json.data.hookAddress);
console.log(json.data.swapRouterAddress);
console.log(json.data.factoryABI);
console.log(json.data.hookABI);
```

Use `/jsonconfig/contracts` only if your tooling needs canonical JSON ABI objects instead of human-readable ABI strings.
