Why integrate hATOM
- One chain. hATOM is a token on the Cosmos Hub, issued by one contract on the Hub. Reading its rate, minting and burning are Hub queries and Hub transactions. There is no IBC channel, relayer or second chain to follow.
- A rate you can read on chain. The
Ratequery returns the exact value of hATOM in ATOM, from the contract’s own books. - An instant exit to staked ATOM. A burn pays LSM shares in the same transaction. Redeemed, they are delegations in the holder’s name.
- Simulations. Each mint and burn has a simulation query that runs the same pricing as the execution.
Setup
The examples use CosmJS 0.39 andmoonkittjs, a TypeScript library generated for the Cosmos Hub, including gaia’s x/liquid module. Messages to the hATOM contract are plain JSON sent with CosmJS execute. moonkittjs is only needed for the Hub’s x/liquid messages: tokenizing a delegation and redeeming LSM shares.
A Hydro JS library (planned) will cover these flows.
setup.ts
cosmos1uwn9dv2tqzw5kzqyvksjygukkguwdpqwyu5u0fn239jaeckczltq960spc. See Contract addresses for the denom and the other accounts.
Read the rate
Rate doesn’t query the validators, so it is the cheapest query. A read-only client is enough.
- Reward gains enter it at each
Compoundand are released over at leastrelease_floor_s, so it rises smoothly. - Rewards since the last
Compoundare not in it yet. - A slash lowers it. A plain bank transfer of ATOM to the contract raises it at once.
- Never compute the rate from bank balances. Use the query.
On-chain data
Every operation emits a
wasm event with an action attribute: mint_from_native, mint_from_lsm, burn, compound, report_jailed, sweep, set_basket, set_fee, and so on. A mint’s event has minted and recipient. A burn’s has burned, value, out and one lsm_share per share paid. A Compound’s has rewards, fee and fee_minted.
Mint with ATOM
Simulate first, then send the mint with amin_out a little below the simulation.
Mint with staked ATOM
Use this when you already have a delegation to a basket validator. You keep your stake with that validator and skip any unbonding.1
Tokenize the delegation
Send the Hub’s
MsgTokenizeShares with moonkittjs. The response carries the LSM share coin.2
Simulate the deposit
Quote one unit less than the tokens tokenized: a share can redeem one unit short.
3
Send the shares to the contract
basket query first.
Burn for staked ATOM
A burn pays LSM shares. Redeem them to hold the delegations in your own name. To get liquid ATOM, undelegate them afterwards and wait for the Hub’s unbonding period.1
Simulate and burn
2
Collect the shares paid
Each share paid is a
lsm_share attribute of the wasm event, as <amount><denom>.3
Redeem the shares
Send the Hub’s
MsgRedeemTokensForShares with moonkittjs, one per share.