> For the complete documentation index, see [llms.txt](https://docs.fira.money/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.fira.money/developers/utility-contracts/libraries/helpers.md).

# Helpers

{% hint style="info" %}
**Source:** `src/fira_bonding/libraries/`
{% endhint %}

## Errors.sol

Central registry of all custom error types. Errors are prefixed by module (`Market*`, `YC*`, `FW*`, `Router*`). Using custom errors instead of string reverts saves gas and makes off-chain decoding straightforward.

## TokenHelper.sol

Safe ERC20 transfer wrappers with native ETH handling:

* `_transferIn(token, from, amount)` — Handles ETH by checking `msg.value` and wrapping via WETH
* `_transferOut(token, to, amount)` — Handles ETH by unwrapping WETH
* `_selfBalance(token)` — Balance accounting for native ETH
* `_safeApproveInf(token, spender)` — Infinite approval only if current allowance is low

The `NATIVE` sentinel address (`0x000...000`) represents ETH in `TokenInput`/`TokenOutput` structs.

## BoringOwnableUpgradeable.sol

Two-step ownership transfer: `transferOwnership(newOwner, direct, renounce)` either transfers immediately or sets a pending owner who must call `claimOwnership()`. Used by FW tokens and factories.

## BaseSplitCodeFactory / CodeDeployer

Works around the 24KB EVM contract size limit (EIP-170):

1. At factory deployment, creation bytecode is split into two chunks, each deployed as a "code storage" contract
2. At creation time, bytecode is concatenated in memory and deployed via CREATE2

Used by both `FiraMarketFactory` and `YieldContractFactory` since `FiraMarket` and `CouponToken` exceed the size limit.

## Other helpers

* **`MiniHelpers.sol`** — `isCurrentlyExpired(expiry)`, `ensureNotExpired()` — used everywhere for pre/post-expiry gating
* **`ExpiryUtilsLib.sol` / `StringLib.sol`** — Generate deterministic token names like `FW-USDC-BT-07MAY2026` from symbols and expiry timestamps
* **`ArrayLib.sol`** — `create(a, b)` returns a 2-element `address[]`; `sum(arr)` sums a `uint256[]`


---

# 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 dynamically by asking a question.

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

```
GET https://docs.fira.money/developers/utility-contracts/libraries/helpers.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
