Skip to content

fix(config): drop 5 malformed addresses + add shape-guard test - #15

Merged
Hiksang merged 1 commit into
mainfrom
fix/hybra-malformed-address
May 6, 2026
Merged

fix(config): drop 5 malformed addresses + add shape-guard test#15
Hiksang merged 1 commit into
mainfrom
fix/hybra-malformed-address

Conversation

@Hiksang

@Hiksang Hiksang commented May 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

defi --chain hyperevm status --verify flagged hybra.rewards_distributor as NO_CODE during the 2026-05-07 multi-chain sweep. Inspecting the TOML revealed the address was malformed — 37 hex chars after 0x instead of 40 — clear data-entry truncation. A follow-up regex sweep across ts/config/ turned up 4 sibling cases in nest.toml, each a per-pool gauge field at 39 hex chars. nest is is_active = false so the entries were silently filtered out before status verification, but they're still time bombs the next time anyone re-activates.

Fix

File Change
ts/config/protocols/dex/hybra.toml Drop the orphan rewards_distributor line. No adapter code referenced it. Probed rewards_distributor(), rewardsDistributor(), distributor(), rewardDistributor() getters on minter / voter / ve contracts — all reverted, so re-discovering the correct address is non-trivial and out of scope here.
ts/config/protocols/dex/nest.toml Drop the 4 malformed pool gauge fields. The pool addresses themselves stayed valid; PoolInfo.gauge is optional, so the pools remain valid TOML entries.
ts/packages/defi-cli/src/qa/address-shape.test.ts (new) Walks every TOML file in ts/config/ and rejects any "0x..." literal whose length isn't exactly 42 (0x + 40 hex). Includes a self-test of the regex so future refactors can't silently make the guard permissive.

This is a config-only fix — no adapter behaviour changes. The removed entries were never readable by code in the first place (viem rejects sub-42-char addresses).

Why a test, not a parser-level reject?

The runtime Registry.loadProtocols() swallows malformed-TOML exceptions with a /* skip invalid protocol files */ comment, so a per-address throw would silently disable an entire protocol on a typo. A pre-merge unit test that lists offenders gives a much clearer signal (file:line + length diff) than a swallowed runtime crash.

Test plan

  • pnpm -C ts -r build — clean.
  • pnpm -C ts -r lint — 3 packages, tsc --noEmit clean.
  • pnpm -C ts -r test — defi-core 32/32, defi-protocols 43/43, defi-cli 89/89 (+2 address-shape tests; existing 87 unchanged).
  • The new shape-guard test passes on this branch; pre-fix it would have rejected all 5 of the addresses removed here.
  • Reviewer: confirm nest.toml is the right file to drop the gauge fields from, vs. trying to recover the correct addresses (nest is currently inactive so the gauge data is unreachable either way).

Out of scope

  • Re-running status --verify against a live RPC after the fix. The contract addresses left in hybra.toml are unchanged from the prior verified-79 set; only the malformed line was removed.
  • Recovering the correct hybra rewards_distributor address. Tracked separately if/when the adapter starts using it.

🤖 Generated with Claude Code

Discovered 2026-05-07 during the multi-chain `status --verify` sweep
on HyperEVM: hybra.rewards_distributor was reported as `NO_CODE` even
though hybra is otherwise healthy. Inspecting the TOML revealed the
address was malformed — only 37 hex chars after `0x` (should be 40),
i.e. data-entry truncation that pre-dated the active config baseline.

A regex sweep across `ts/config/` then turned up four sibling cases
in `nest.toml` (each a per-pool `gauge` field at 39 hex chars). Nest
is currently `is_active = false` so those entries were filtered out
of `getProtocolsForChain()` before reaching `status --verify`, but
they were still ticking time bombs for the day someone re-activates.

Fix:
  1. `protocols/dex/hybra.toml`: drop the orphan `rewards_distributor`
     line (no adapter code referenced it; tried `rewards_distributor()`,
     `rewardsDistributor()`, `distributor()`, `rewardDistributor()`
     getters on the minter / voter / ve contracts — all reverted, so
     re-discovering the correct address is non-trivial and out of
     scope for this fix).
  2. `protocols/dex/nest.toml`: drop the four malformed pool gauge
     fields. The pool addresses themselves stayed valid — only the
     gauge field was truncated. `PoolInfo.gauge` is optional, so the
     pools remain valid TOML entries.
  3. New test `src/qa/address-shape.test.ts` walks every TOML file in
     `ts/config/` and rejects any `"0x..."` literal whose length is
     not exactly 42 (0x + 40 hex). Also includes a self-test for the
     regex so future refactors can't silently make the guard
     permissive.

This is a config-only fix — no adapter behaviour changes. The
removed entries were never readable by code in the first place
(viem rejects sub-42-char addresses).

Verified:
  - pnpm -C ts -r build  — clean.
  - pnpm -C ts -r lint   — 3 packages, tsc --noEmit clean.
  - pnpm -C ts -r test   — defi-core 32/32, defi-protocols 43/43,
                           defi-cli 89/89 (+2 address-shape tests).
  - The new shape-guard test passes; pre-fix it would have rejected
    all 5 of the addresses removed in this commit.

Out of scope:
  - Re-running `status --verify` against a live RPC after the fix.
    The contract addresses left in hybra.toml are unchanged from the
    prior verified-79 set; only the malformed line was removed.
@Hiksang
Hiksang merged commit 8a2f83d into main May 6, 2026
4 checks passed
@Hiksang
Hiksang deleted the fix/hybra-malformed-address branch May 6, 2026 17:08
Hiksang added a commit that referenced this pull request May 6, 2026
… in DEX adapter tests (#17)

Four DEX adapter test files (uniswap_v3, algebra_v3, balancer_v3,
thena_cl) constructed ProtocolEntry fixtures with `chain: "test"`,
which doesn't exist in any registry. Each replacement uses a real
chain that the adapter is in fact deployed on:

  uniswap_v3.test.ts → "hyperevm" (hyperswap-v3, project-x, ramses-cl)
  algebra_v3.test.ts → "hyperevm" (kittenswap)
  thena_cl.test.ts   → "bnb"      (thena-fusion-bnb)
  balancer_v3.test.ts → "hyperevm" (no registered protocol; chosen for
                                    consistency with the other V3-style
                                    adapters)

The change is fixture-only — no registry lookups happen in these
tests, so behaviour is identical. The benefit is forward-looking:
any future test that crosschecks a fixture's chain against
Registry.loadEmbedded() (e.g. address-shape PR #15's pattern) will
find the chain and not silently skip the assertion.

Verified:
  - pnpm -C ts -r build  — clean.
  - pnpm -C ts -r lint   — 3 packages, tsc --noEmit clean.
  - pnpm -C ts -r test   — defi-core 32/32, defi-protocols 43/43
                           (unchanged), defi-cli 89/89 (unchanged).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant