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

# hATOM contract

> Reference for the hATOM contract: instantiate settings, execute messages and queries, with JSON examples.

The hATOM contract is the liquid staking token. It holds the delegations, mints and burns hATOM, compounds rewards and keeps the basket. See [Architecture](https://docs.hydro.markets/hatom/developers/architecture.md) for how the parts fit together.

## Links

* **Deployments:** [Contract addresses](https://docs.hydro.markets/hatom/developers/addresses.md)
* **Types:** [`contracts/hatom/src/msg.rs`](https://github.com/informalsystems/hatom-contracts/blob/main/contracts/hatom/src/msg.rs). The schema binary is in `contracts/hatom/src/bin`. TypeScript types are in [`ts_types/`](https://github.com/informalsystems/hatom-contracts/tree/main/ts_types), generated with ts-codegen 1.7.2.
* **Contract repository:** [informalsystems/hatom-contracts](https://github.com/informalsystems/hatom-contracts)
* **Audits:** [Security and audits](https://docs.hydro.markets/hatom/developers/security-and-audits.md)

## Conventions

* Amounts are strings in base units: `uatom` for ATOM (1 ATOM = 1,000,000 `uatom`), and the same 6 decimals for hATOM.
* `Decimal` and `Decimal256` values are strings, such as `"0.05"`.
* Timestamps are strings in nanoseconds since the Unix epoch.
* Basis points (bps): 10,000 bps is 100%.
* Optional fields can be left out.
* Only `MintFromNative`, `MintFromLsm` and `Burn` accept funds. Every other message refuses them.
* Every operation ends with an internal `AssertInvariants` message. If a check fails, the whole transaction reverts.
* `min_out` is your guard against a price change between your simulation and your transaction. Set it on every mint and burn.

## Instantiate

The funds sent are the tokenfactory's denom creation fee plus `initial_deposit`, both in ATOM. Read the fee with `gaiad q tokenfactory params`.

```json theme={null}
{
  "admin": "<admin>",
  "subdenom": "hatom",
  "name": "Staked ATOM",
  "symbol": "hATOM",
  "description": "Liquid staked ATOM",
  "basket": [
    { "validator": "<valoper address>", "weight_bps": 10000 }
  ],
  "fee_bps": 0,
  "fee_recipient": "<fee recipient>",
  "operators": ["<operator 1>", "<operator 2>"],
  "params": {
    "max_validator_commission": "0.05",
    "max_basket_size": null,
    "imbalance": {
      "lambda": "0.1",
      "max_fee_bps": 500,
      "max_rebate_bps": 100,
      "budget_cap_bps": 100
    },
    "rebate_cooldown_s": 604800,
    "unbonding_time_s": 1814400,
    "release_floor_s": 12600,
    "default_legs": 4,
    "max_legs": 50
  },
  "initial_deposit": "1000000"
}
```

The values shown are the ones recommended for the Hub in the repository's `deploy/` folder. The [deployed contract](https://docs.hydro.markets/hatom/developers/addresses.md) uses the same fee and `params`: `fee_bps` is 0, and every `params` field equals the example above. Its basket is the [current basket](https://docs.hydro.markets/hatom/users/what-is-hatom.md#the-current-basket), and its admin, operators and fee recipient are on [Contract addresses](https://docs.hydro.markets/hatom/developers/addresses.md).

| Field | Meaning |
| - | - |
| `admin` | the contract's admin. Not the wasm admin, which is set by `--admin` on `MsgInstantiateContract`. |
| `subdenom` | the hATOM denom is `factory/<contract>/<subdenom>`, created at instantiate. |
| `name`, `symbol`, `description` | the denom's metadata. The display unit is `subdenom`, with 6 decimals. |
| `basket` | validators and target weights in bps. Weights are above 0 and sum to 10,000. Each validator is bonded and at or under `max_validator_commission`. |
| `fee_bps` | the fee on rewards, in bps. |
| `fee_recipient` | receives the fee as hATOM, and the balances that `Sweep` sends. |
| `operators` | addresses that may pause. |
| `initial_deposit` | at least 1,000,000 (`MIN_INITIAL_DEPOSIT`, 1 ATOM). It is delegated and minted 1:1 to the contract itself, and never leaves it. The supply never returns to 0. |

`params` are fixed at instantiate. Only a migration can change them.

| Param | Bounds | Meaning |
| - | - | - |
| `max_validator_commission` | at most 50% | No new stake goes to a validator above it. Bonuses are off while a weighted validator is above it, and for a hold period after. |
| `max_basket_size` | `null` or at least 1 | Optional cap on the basket's size. |
| `imbalance.lambda` | at most 10 | Steepness of the imbalance fee. |
| `imbalance.max_fee_bps` | at most 2,000 | Entries with an imbalance fee above it are refused. |
| `imbalance.max_rebate_bps` | at most 500 | Largest bonus, per operation. |
| `imbalance.budget_cap_bps` | at most 1,000 | Cap of the imbalance pool, as a share of the delegations. Above it, the excess counts for holders. |
| `rebate_cooldown_s` | at most 30 days | Bonuses are off for this long after a basket change or a jail removal, and it is the commission hold's length. |
| `unbonding_time_s` | 1 s to 60 days | A copy of the Hub's unbonding time, set by hand, since contracts can't read the staking params. A jailed validator is removed after a third of it out of the bonded set. The wasm admin keeps it in sync by a migration when a governance change to the Hub's unbonding time passes. Until then, the removal delay is too short if the unbonding time grew, and too long if it shrank. |
| `release_floor_s` | 1 hour to 1 day | The shortest time a reward gain is released over. |
| `default_legs`, `max_legs` | 1 ≤ `default_legs` ≤ `max_legs` ≤ 50 | Validators a default mint, burn or `Compound` spreads over, and the cap on a caller's `max_legs`. |

## Execute messages

### `mint_from_native`

Send ATOM as funds. The contract delegates it and mints hATOM at the rate before the mint, less the imbalance fee or plus the bonus.

```json theme={null}
{
  "mint_from_native": {
    "validator": null,
    "recipient": "<address>",
    "max_legs": 4,
    "min_out": "9720000"
  }
}
```

| Field | Meaning |
| - | - |
| `validator` | delegate everything to this basket validator. Without it, the amount is spread over the `default_legs` (or `max_legs`) most under-weight bonded validators at or under the commission maximum. |
| `recipient` | receives the hATOM. Default: the sender. |
| `max_legs` | spread over this many validators, up to `Params.max_legs`. |
| `min_out` | the least hATOM minted, else the error `BelowMinimum`. |

Refused with `NoMintTarget` when no basket validator can take stake, and with `ImbalanceTooHigh` when the imbalance fee is above `max_fee_bps`. The response's data is `{ "minted": "<amount>" }`.

### `mint_from_lsm`

Send LSM shares as funds. Each share must be of a basket validator that is bonded and at or under the commission maximum. The contract redeems each share into its own delegation, prices the whole deposit once and mints once.

```json theme={null}
{
  "mint_from_lsm": {
    "recipient": "<address>",
    "min_out": "4860000"
  }
}
```

To get LSM shares from your own delegation, tokenize it first with the Hub's `MsgTokenizeShares`. See [Integration examples](https://docs.hydro.markets/hatom/developers/integration-examples.md#mint-with-staked-atom). The response's data is `{ "minted": "<amount>" }`.

### `burn`

Send hATOM as funds. The contract burns it and pays its value in LSM shares, tokenized from its delegations.

```json theme={null}
{
  "burn": {
    "recipient": "<address>",
    "share_owner": "<address>",
    "max_legs": null,
    "split": null,
    "min_out": "3980000"
  }
}
```

| Field | Meaning |
| - | - |
| `recipient` | receives the LSM shares. Default: the sender. |
| `share_owner` | owns the tokenize-share records of the shares paid out. Default: the recipient. The Hub pays the rewards the shares earn, until they are redeemed, to the record's owner, not to whoever holds the shares. |
| `max_legs` | the default plan's fan-out. Ignored with a `split`. |
| `split` | your own split: a list of `{ "validator", "weight_bps" }` summing to 10,000, 1 to 50 basket validators. The exact imbalance fee is charged and never refuses the burn. Fails with `InsufficientLeg` if a validator lacks the stake for its share. |
| `min_out` | the least ATOM value of the shares paid out, else `BelowMinimum`. |

Without a `split`, the contract takes from the most over-weight validators it holds stake with. It widens the plan until the fee is within `max_fee_bps`, or until the plan covers every candidate or 50 of them. A burn is never refused for its imbalance fee, and never paid in part. It is refused with `InsufficientDelegation` when the delegations it may take from cannot cover the payout.

The response's data is `{ "shares": [<coin>, ...] }`, the LSM shares sent. Each share is also in a `lsm_share` attribute of the `wasm` event. Redeem the shares with the Hub's `MsgRedeemTokensForShares` to hold the delegations in your own name.

### `compound`

Anyone can send it, at any time.

```json theme={null}
{ "compound": {} }
```

It reads every validator's pending rewards, claims them, takes `fee_bps` of them, and delegates the rest to the `default_legs` most under-weight bonded validators at or under the commission maximum. The fee is minted as hATOM to `fee_recipient`. The holders' gain is locked and released over time. It also records jail sightings and commission sightings for the basket.

### `report_jailed`

Anyone can send it.

```json theme={null}
{ "report_jailed": { "validator": "<valoper address>" } }
```

Records a sighting of a weighted basket validator in or out of the bonded set. Once a validator has been out for a third of `unbonding_time_s`, in sighted time, a report sets its weight to 0 and scales the other weights up pro rata. Once it has been bonded again for as long, its record clears. Refused with `NotJailed` for a bonded validator without a record.

### `sweep`

Anyone can send it.

```json theme={null}
{ "sweep": { "denom": "<denom>" } }
```

Sends the contract's whole balance of `denom` to the fee recipient. Never ATOM or hATOM. This is how rewards paid in other denoms leave the contract.

### Admin messages

| Message | Example | Effect |
| - | - | - |
| `set_basket` | `{ "set_basket": { "basket": [{ "validator": "<valoper>", "weight_bps": 10000 }] } }` | Replaces the basket. Validated like at instantiate. Validators left out keep their stake at weight 0 until burns drain it. Bonuses are off for `rebate_cooldown_s`. |
| `set_fee` | `{ "set_fee": { "fee_bps": 500, "fee_recipient": "<address>" } }` | Charges the old fee on idle rewards first, then sets both. The new fee applies to rewards claimed from then on. The rate doesn't move. |
| `set_operators` | `{ "set_operators": { "operators": ["<address>"] } }` | Replaces the list. |
| `transfer_admin` | `{ "transfer_admin": { "admin": "<address>" } }` | Proposes a new admin. The old one keeps every right until acceptance. |
| `accept_admin` | `{ "accept_admin": {} }` | The pending admin becomes the admin. |
| `pause` | `{ "pause": {} }` | Admin or operator. Refuses mints, burns, `Compound`, `ReportJailed` and the three simulations. |
| `unpause` | `{ "unpause": {} }` | Admin only. |

## Queries

### `rate`

The rate and supply, without querying the validators. The cheapest query.

```json Query theme={null}
{ "rate": {} }
```

```json Response theme={null}
{
  "exchange_rate": "1.023456789012345678",
  "supply": "1000000000000",
  "holders_value": "1023456789012"
}
```

`exchange_rate` is ATOM per hATOM. For exact amounts, `u` base units of hATOM are worth `floor(u × holders_value / supply)` `uatom`.

### `state`

The contract's books.

```json Query theme={null}
{ "state": {} }
```

```json Response theme={null}
{
  "bond_denom": "uatom",
  "supply": "1000000000000",
  "holders_value": "1023456789012",
  "exchange_rate": "1.023456789012345678",
  "delegated": "1023500000000",
  "idle": "1200000",
  "unfeed": "0",
  "imbalance_budget": "40000000",
  "locked": "3000000",
  "minted": "1200000000000",
  "burned": "200000000000",
  "last_compound": "1767225600000000000",
  "rebates_paused_until": "1766620800000000000",
  "commission_hold_open": false,
  "commission_hold_until": null,
  "rebates_paused": false,
  "paused": false
}
```

| Field | Meaning |
| - | - |
| `unfeed` | idle rewards not yet through the fee (`U` in the rate). |
| `imbalance_budget` | the imbalance pool, held for bonuses. |
| `locked` | the gain still to be released. |
| `rebates_paused` | whether bonuses are off now. |
| `rebates_paused_until` | end of the cooldown after the last basket change. |
| `commission_hold_open`, `commission_hold_until` | the commission hold: open, or its end while it runs. |
| `paused` | the admin's or an operator's pause. |

### `config`

The settings: `denom`, `admin`, `pending_admin`, `fee_bps`, `fee_recipient`, `operators`, `paused` and `params`.

```json theme={null}
{ "config": {} }
```

### `basket`

Every validator the contract tracks, with its weight, delegation and records.

```json Query theme={null}
{ "basket": {} }
```

```json Response theme={null}
{
  "validators": [
    {
      "validator": "<valoper address>",
      "weight_bps": 2500,
      "delegated": "255000000000",
      "expected": "255000000000",
      "jail": null,
      "above_max_seen_at": null,
      "hold_until": null
    }
  ]
}
```

A `weight_bps` of 0 means the validator is being removed: mints skip it and burns drain it first. `expected` is the delegation at the end of the last operation. A difference since then is the chain's: rounding dust if `delegated` is higher, a slash if it is lower. The contract re-syncs it at the start of the next operation. `jail` is the jail record, if any.

### `simulate_mint_native`

What `mint_from_native` would mint for `amount` of ATOM, in `uatom`. It uses the same pricing as the execution, on the same state.

```json Query theme={null}
{ "simulate_mint_native": { "amount": "10000000", "validator": null, "max_legs": null } }
```

```json Response theme={null}
{
  "minted": "9770000",
  "imbalance_fee": "1000",
  "imbalance_rebate": "0",
  "allocation": [
    { "validator": "<valoper address>", "amount": "5000000" },
    { "validator": "<valoper address>", "amount": "5000000" }
  ]
}
```

### `simulate_deposit`

What one `mint_from_lsm` would mint for these shares, given per validator as ATOM value. Quote one unit less per share: a share can redeem one unit short.

```json theme={null}
{ "simulate_deposit": { "shares": [{ "validator": "<valoper address>", "amount": "4999999" }] } }
```

Returns the same fields as `simulate_mint_native`.

### `simulate_burn`

What `burn` would pay for `amount` of hATOM.

```json Query theme={null}
{ "simulate_burn": { "amount": "4000000", "max_legs": null, "split": null } }
```

```json Response theme={null}
{
  "value": "4093827",
  "imbalance_fee": "0",
  "imbalance_rebate": "120",
  "out": "4093947",
  "allocation": [
    { "validator": "<valoper address>", "amount": "4093947" }
  ]
}
```

`value` is the hATOM's value at the rate. `out` is the ATOM value of the LSM shares paid. Use `out`, less a margin, as `min_out`.

> [!WARNING]
>
> The three simulations fail while the contract is paused. `rate`, `state`, `config` and `basket` still answer.

## Errors

| Error | When |
| - | - |
| `Paused` | the contract is paused |
| `Unauthorized` | the sender lacks the role |
| `BelowMinimum` | the output is below `min_out` |
| `NoMintTarget` | no basket validator can take new stake |
| `ImbalanceTooHigh` | an entry's imbalance fee is above `max_fee_bps` |
| `NotInBasket`, `NotBonded` | a pinned validator or a share's validator is not in the basket, not bonded, or above the commission maximum |
| `InsufficientDelegation` | the delegations a burn may take from cannot cover its payout |
| `InsufficientLeg` | a validator in a `split` lacks the stake for its share |
| `InvalidSplit`, `InvalidBasket` | a malformed split or basket |
| `FeeTooHigh` | `fee_bps` above 5,000 |
| `AmountTooSmall` | the operation would mint or pay 0 |
| `OpInProgress` | another operation on the contract is in progress |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.