> For the complete documentation index, see [llms.txt](https://docs.hann.finance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hann.finance/developers/technical-overview.md). Agents can also search and read this documentation through its [MCP server](https://docs.hann.finance/~gitbook/mcp).

# Technical overview

Public contracts, asset accounting, and wallet transactions for lending, USDHN, staking, and swaps

Hann Finance combines lending markets, collateral-backed USDHN borrowing, liquid staking, and swaps. Each product has its own contracts for asset balances, debt, and position ownership. An integration reads those contracts through the selected chain's RPC and submits transactions from the user's wallet.

## Contract reads and wallet transactions

### Read contract state

```mermaid
flowchart TB
  INTEGRATION[Your integration] -->|Read-only call| RPC[Chain RPC]
  RPC --> CONTRACTS[Public product contracts]
```

### Wallet transactions

The integration prepares the contract call, and the wallet signs and submits it. Depending on the action, the destination is the Lending Pool, a CDP Zapper, the bKAIA or HNKAIA vault, or the StableSwap Router. CDP Zappers coordinate the borrowing and swap calls below.

```mermaid
flowchart TB
  APP[Your integration] -->|Request signature| WALLET[User wallet]
  WALLET --> ZAP[CDP Zappers]
  ZAP --> BO[BorrowerOperations]
  ZAP --> FLASH[FlashSwapper]
  BO --> TM[TroveManager]
  BO -->|Mint or burn| USDHN[USDHNToken]
  TM -->|Offset liquidated debt| SP[StabilityPool]
  FLASH --> POOL[Swap pools]
```

Read-only calls return balances, positions, prices, and quotes. Contracts enforce ownership, asset transfers, debt changes, and execution limits. Simulation evaluates a proposed call without submitting a transaction. The transaction receipt and its logs record the executed result; read the resulting balances and position state after confirmation.

| Product         | Accounting contracts                                                          | User result                                                                     |
| --------------- | ----------------------------------------------------------------------------- | ------------------------------------------------------------------------------- |
| Lending         | `Pool`, reserve aTokens, and debt tokens                                      | Supply assets, borrow from market liquidity, repay, and withdraw                |
| USDHN borrowing | A separate `BorrowerOperations` and `TroveManager` for each collateral branch | Lock collateral in a Trove and mint USDHN debt                                  |
| Earn            | Each branch's `StabilityPool`                                                 | Deposit USDHN; receive USDHN yield and collateral from liquidations             |
| bKAIA staking   | `LSTVault` and `LSTToken`                                                     | Deposit KAIA for bKAIA shares; request withdrawals and claim ready tickets      |
| HNKAIA          | `HNKAIA` and `HNKAIAAssetVault`                                               | Deposit supported staking assets for HNKAIA shares and redeem underlying assets |
| Swap and LP     | `StableSwap`, `StableSwapRouter`, LP token, and `RewardStaker`                | Exchange USDT and USDHN, supply liquidity, and stake LP tokens                  |

## USDHN collateral branches

USDHN borrowing has KAIA, HNKAIA, and earnUSDT collateral branches. The KAIA branch holds WKAIA; its Zapper wraps native KAIA before supplying collateral. The earnUSDT branch holds wEarnUSDT, the wrapped earnUSDT collateral token.

Each branch contains:

* `BorrowerOperations`, which opens, adjusts, and closes Troves and changes their interest-rate settings.
* `TroveManager`, which calculates current debt and collateral, handles liquidations and redemptions, and records Trove status.
* `TroveNFT`, which identifies the owner of each position, and `SortedTroves`, which orders positions by interest rate.
* `ActivePool`, `DefaultPool`, `CollSurplusPool`, and `GasPool`, which hold collateral and account for active debt, redistribution, surplus collateral, and gas compensation.
* `StabilityPool`, which burns deposited USDHN to offset liquidation debt and receives collateral.
* `PriceFeed` and `AddressesRegistry`, which supply the branch's price and contract configuration.

The shared `CollateralRegistry` routes USDHN redemptions across active, redeemable branches. `HintHelpers` supplies insertion hints; `RedemptionHelper` supplies redemption calculations. A Trove's latest debt includes pending interest, redistribution, and batch-management fees. Read `getLatestTroveData()` for current position values rather than treating its recorded debt as the full amount owed.

### Position health

For an open CDP position with debt, collateral ratio is collateral's USD value divided by the Trove's entire USDHN debt. The contract uses `1e18` units for collateral, debt, price, and the resulting ratio:

```
ICR18 = entireColl × price18 / entireDebt
```

The branch enforces `MCR` for individual collateral ratios, `CCR` for branch-wide borrowing and withdrawal constraints, `SCR` for shutdown, and additional limits for batched loans. CDP liquidation uses `ICR < MCR`. A normal redemption reduces debt and collateral in the selected Troves, starting with lower interest rates after checking any recorded small-debt Trove. Collateral charged as the redemption fee stays in the affected Trove. Liquidation offsets debt through the Stability Pool and redistributes the remainder within the branch.

Lending uses the account's health factor, calculated from enabled collateral, applicable liquidation thresholds, and total debt. `Pool.getUserAccountData()` returns that health factor at `1e18` precision. An account with a health factor below `1e18` is eligible for Lending liquidation. CDP and Lending maintain separate debt and liquidation rules.

## Zappers and flash execution

A Zapper collects the user's approved tokens or native KAIA, executes its configured route, and returns route leftovers to the receiver. Permit2 entrypoints use a signature alongside the token's allowance to Permit2; ordinary allowance paths remain separate.

| Contract                                                                | Operation                                                                                    |
| ----------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
| `WKAIAZapper`                                                           | Native KAIA and WKAIA collateral operations                                                  |
| `HNKAIAZapper`                                                          | HNKAIA collateral operations                                                                 |
| `EarnUSDTZapper`                                                        | earnUSDT wrapping and wrapped-collateral operations                                          |
| `LeverageWKAIAZapper`, `LeverageHNKAIAZapper`, `LeverageEarnUSDTZapper` | Open, increase, reduce, or close a flash-assisted position with the corresponding collateral |
| `FlashSwapper`                                                          | DEX flash-swap callback, StableSwap execution, and in-transaction settlement                 |
| `StableSwapZapper`                                                      | Liquidity operations and LP staking                                                          |

Flash-assisted execution hands Trove management to the authorized FlashSwapper for the callback and restores the management state afterward. The managed state includes the add manager, remove manager, and receiver. Callback authorization, expected-token checks, configured flash-fee caps, and final-debt checks bind the route to the submitted operation. Balance snapshots separate route leftovers from balances that were already present.

`openLeveragedTrove`, `leverUpTrove`, and `leverDownTrove` take `maxDebt`, the maximum final entire debt. `closeTroveByCollateral` sells collateral to repay the entire debt and returns remaining stable tokens; its parameter struct contains `troveId` and `profitReceiver`, with no user-supplied minimum-output field. Use each entrypoint's actual limits when preparing a transaction.

## Staking, swaps, and cross-chain transfers

Use the **`LSTVault` address** for bKAIA deposits, withdrawal requests, claims, and reads. `requestUnstakeByShares` creates withdrawal tickets for the amount accepted by the staking nodes. Unprocessed shares remain in the wallet. Tickets have separate readiness and claim times. `claimMany` processes submitted tickets, including partial results. `RequestUnstake`, `ClaimPayout`, `TicketStatusUpdated`, and `ClaimManySummary` record the opened requests, payouts, ticket states, and batch totals.

HNKAIA represents a share of the vault's supported staking tokens. `redeemProRata` burns HNKAIA and pays each token in proportion to its vault balance, rounding down in integer token units. This basket redemption has no redemption fee and remains available while priced deposit and single-asset redemption flows are paused. `RedeemProRata` and `RedeemProRataAsset` record the redeemed shares and token outputs.

StableSwap provides exact-input and exact-output quotes, liquidity quotes, execution deadlines, minimum outputs, and maximum inputs. `StableSwapRouter` validates its pools, token allowlist, and recipients. The pool accounts for reserves and fees; LP staking and rewards belong to `RewardStaker`. `LiquidityAdded` and `LiquidityRemoved` record router liquidity operations. `Stake`, `Unstake`, and `Claim` record RewardStaker operations.

`USDHNToken` implements ERC-20 and permit. `USDHNOFTAdapter` locks and unlocks the canonical token for LayerZero transfers; `USDHNOFT` mints and burns the remote-chain token. The app's Bridge flow transfers supported USDT or USDC source assets into Kaia USDT through Rhino.fi. A source-chain receipt confirms the source transaction; destination delivery has its own transaction and status.

## Read, simulate, submit, and confirm

1. Select the chain, contract address, and ABI from the [Smart Contracts reference](https://docs.hann.finance/developers/smart-contracts.md). Identify tokens by chain and address, including each receipt token and debt token.
2. Read the current balance, allowance, position, price, and quote used by the action. For a Trove, use its latest entire debt; for Lending, use the account-level collateral, debt, and health factor.
3. Prepare the required token approval, Permit2 signature, credit delegation, or manager/operator permission. Each permission authorizes the specified contract; the following action performs the asset or position change.
4. Simulate the action with the intended sender, calldata, native value, receiver, deadline, and amount limits. State changes between simulation and execution can cause the submitted transaction to revert.
5. Submit from the wallet, retain the transaction hash, and check the receipt on the same chain. A reverted action leaves that action's state changes unapplied and still consumes gas; earlier successful approvals remain set.
6. Decode logs using the emitting contract's ABI and address, then read the resulting position. Check processed amounts for staking tickets and redemptions; receipt success does not imply that the entire requested amount was processed.

## Networks and contract addresses

Kaia Mainnet uses chain ID `8217`; Kairos testnet uses `1001`. Hann Finance's mainnet contracts have not been deployed. Mainnet and testnet address records are separate in [Smart Contracts](https://docs.hann.finance/developers/smart-contracts.md). Use the recorded address for the intended network. A token symbol alone does not identify a contract across networks or across Lending, CDP, and staking.

The [Smart Contracts reference](https://docs.hann.finance/developers/smart-contracts.md) lists public contract names, functions, events, deployment status, and network address records. The [Integrator Guide](https://docs.hann.finance/developers/integrator-kit.md) describes wallet transactions and event processing. Trove status transitions are described in [Trove Manager](https://docs.hann.finance/developers/trove-manager.md), and route behavior in [Zapper](https://docs.hann.finance/protocol/zapper.md).


---

# 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://docs.hann.finance/developers/technical-overview.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.
