Reference
Learned on Hedera
Fourteen things Hedera testnet taught us while building Custos. Each one was hit or measured on testnet, and each one is handled in the code.
The Schedule Service (HIP-1215)#
1. A scheduled call runs as the contract itself
When the Schedule Service executes a call the contract booked, msg.sender and tx.origin are the contract's own address. Probed with a throwaway contract, 0xd603925b…a6143b(opens in a new tab).
What the code does: tick() accepts only msg.sender == address(this). Nobody can tick early, starve it of gas, or make the booked run revert, and Liquidated.byNetwork is exact.
2. Hedera holds the whole gas limit up front
A scheduled run only starts if the payer holds gasLimit × gasPrice. Proven: a 5,000,000-gas call on a contract holding 3.6 ℏ failed with INSUFFICIENT_PAYER_BALANCE (it needed 5M × 82 = 4.1 ℏ), even though the run itself would have cost far less (schedule 0.0.10832561(opens in a new tab)). The failed attempt still cost 0.018 ℏ.
The first Custos deploy broke this way: 5.02 ℏ in the reserve, a 6M-gas run at 85 tinybar needing 5.10 ℏ, and a runsLeft() that still said 3.
What the code does: runCostEstimate() = gasLimit × gasPrice, runsLeft() counts full holds, canPayNextRun() says whether the next run can start, and the default gas limit dropped from 6M to 3M.
3. tx.gasprice in a scheduled run is the network gas price, and it moves
Inside a scheduled run tx.gasprice is the network gas price in tinybars: 82 in the probe (0x2B8ac8aC…9b6d8e(opens in a new tab), 2026-10-02), 84 at the final deploy's first tick an hour later. It tracks Hedera's USD-denominated gas fee against the HBAR rate.
What the code does: every tick records it, so the run-cost estimate follows the real price. Values above 1,000,000 are ignored as nonsense.
4. Booking a schedule costs about 1.41M gas
Whatever gas limit it books (measured with 300k and 1M limits). An 800k total fails.
What the code does: the keeper holds back 1.6M gas from _work() so booking the next tick always fits, and rejects gas limits at or below that.
5. block.timestamp is the start of a 2 s block
block.timestamp is the start of Hedera's ~2 s block. A schedule that fired at its exact second ran in a block that started a second earlier, so the first version reverted TooEarly.
What the code does: tick() accepts up to 5 s early.
6. Capacity is per second
What the code does: hasScheduleCapacity is checked first; if the second is full the keeper tries the next one, up to 10 seconds. If all 10 are full or the booking fails, nextRunAt still moves forward and anyone can call revive() once the tick is 2 × interval overdue.
7. A failed run breaks the chain silently
Nothing books the next run, so the chain just stops.
What the code does: revive() (public, only when overdue), a self-call around _work() so a revert there still books the next tick, and canPayNextRun() for the app to warn early. See The keeper for funding and reviving.
Oracles and SaucerSwap#
8. SaucerSwap testnet's USDC pool is 22x off the oracle
1 HBAR buys 2.249 USDC there; Chainlink says $0.1025. A keeper that refuels at that pool overpays ~22x out of LP money. On an earlier deploy with a wide band this drained the LPs to a share price of 0.40.
What the code does: the keeper's refuel must fill within 3% of the oracle price, so on testnet refuels fail closed (the tick still sweeps and reschedules; not one micro-USDC leaves the pool) and the reserve is topped up with fund(). On mainnet, where SaucerSwap tracks the market, refuels go through.
9. Chainlink's testnet HBAR/USD goes hours between pushes
Seen 6.4 h and 3.7 h apart (it updates on deviation or a long heartbeat). With a 2 h staleness window the live market read Stale (close-only, sweeps skipped, deposits paused) for hours on 3 Oct.
What the code does: the live guard was raised to 12 h with setParams (0x51cf5b7f…6745fc(opens in a new tab)) and markets.json ships 43,200 s for HBAR-USD. The 5% deviation check against Supra still catches a wrong price.
10. Supra's testnet feeds update at very different speeds
HBAR/USDT (pair 75) pushes every few minutes to about hourly, and quotes USDT, so it can sit ~3% from Chainlink's HBAR/USD for a while. ETH/USDT (pair 19) was seen 8 h old (2026-10-03). Pairs 0 and 1 haven't updated in months; don't use them.
What the code does: deviation is 5% for HBAR-USD. A testnet ETH market needs the guard's maximum 1-day window (use about 1 h on mainnet); see Add a market.
The Token Service#
11. Creating an HTS token from a contract costs about 12 HBAR
12.14 ℏ measured, fee plus gas.
What the code does: createShareToken() takes it as msg.value and sends back what's left.
12. An account must be associated with an HTS token before it can receive it
What the code does: the pool associates itself with USDC (associate()); users associate with USDC and with cUSDC-LP through each token's HIP-719 associate(). To redeem, a user approves the pool on cUSDC-LP; the pool then pulls and burns the shares.
Tooling#
13. forge script can't deploy through the JSON-RPC relay
The relay rejects the EIP-1898 block parameter Foundry sends when forking, and forge script can't simulate HSS/HTS.
What the code does: yarn custos:deploy:testnet uses forge create and cast send.
14. The 24 KB contract size limit applies
PerpMarket was 26.7 KB unoptimized and the relay rejected it as CONTRACT_EXECUTION_EXCEPTION.
What the code does: the optimizer (200 runs) brings it to 17.4 KB.
What a tick costs#
| Item | Measured |
|---|---|
| Gas limit per tick (testnet deploy) | 3,000,000 |
| Gas price | 82 tinybar/gas (measured inside a scheduled run) |
| Held up front per run | 2.46 ℏ: the reserve must hold at least this or Hedera won't start the run |
| Charged per run | Gas used × gas price, not the limit. Final deploy, ticks 1–3 (funding + a 2-position sweep + booking the next tick): 1.58–1.62M gas, 1.31–1.36 ℏ. Tick 4, which also liquidated a position: 2,385,537 gas, 1.98 ℏ, still inside the 3M limit. |
| Failed start (reserve too low) | 0.018 ℏ, and the chain stops until fund() + revive() |
| Per day at a 30 min interval | 48 runs × ~1.36 ℏ ≈ 65 ℏ charged |
| Testnet reserve at deploy | 36 ℏ: runsLeft() says 14 (each counted at the full 2.46 ℏ hold); at ~1.36 ℏ actually charged it lasts ~25 runs, ~12 h |
So the gas limit decides how much HBAR must sit in the reserve, and the work actually done decides what each run costs. To run longer: fund more (fund() on the market, or send HBAR to it), or lengthen the interval. Lowering the gas limit shrinks the hold but not the charge (it must stay above 1.6M, and each extra position checked costs about 20–30k gas).