Skip to content

Refactor UI contract API into dedicated reporting, truth-auction, and fork modules#365

Merged
KillariDev merged 5 commits into
mainfrom
t3code/0189672f
Jun 23, 2026
Merged

Refactor UI contract API into dedicated reporting, truth-auction, and fork modules#365
KillariDev merged 5 commits into
mainfrom
t3code/0189672f

Conversation

@KillariDev

@KillariDev KillariDev commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Split monolithic ui/ts/contracts.ts into focused modules:
    • ui/ts/contracts/reporting.ts for reporting and fork-carried escalation logic.
    • ui/ts/contracts/truthAuctions.ts for truth-auction read helpers.
    • ui/ts/contracts/securityPoolActions.ts for shared security-pool action helpers.
  • Added ui/ts/contracts/decoders.ts for small shared runtime decoders at ABI/page-read boundaries.
  • Added ui/ts/contracts/forkData.ts so every current security-pool forkData read goes through one validated tuple decoder.
  • Preserved the existing public API surface through re-exports from ui/ts/contracts.ts.
  • Added regression coverage for malformed reporting, carry-leaf, truth-auction page, security-pool page fork-data, and fork-auction detail fork-data reads.

Behavior Change

  • Malformed ABI/page responses now fail loudly with Unexpected ... response errors instead of being silently filtered, dropped, or trusted through unchecked casts.
  • This is intentional: the UI contract layer is an integration boundary between generated artifacts, viem reads, contract domain data, and UI state. Strict decoding makes boundary regressions visible during development instead of hiding partial data loss.
  • Decoder errors now include field-level context for truth-auction and fork-data shape failures where practical.

Scope

  • This PR intentionally stops after the reporting/truth-auction split, shared decoder extraction, action helper split, and focused fork-data decoder cleanup.
  • The remaining contracts.ts domains, such as OpenOracle, trading, migration, and vault writes, are left for follow-up PRs to keep this review focused.

Testing

  • cd ui && bun x tsc --project tsconfig.json
  • bun run test -> 1360 pass, 11 skip, 0 fail
  • bun run format -> no fixes applied on final run
  • bun run check -> clean
  • bun run knip -> clean
  • git fetch origin main && git merge origin/main -> already up to date on final check

- Extracted reporting logic (deposits, escrow ops, and fork proof helpers) from `ui/ts/contracts.ts` into `ui/ts/contracts/reporting.ts`
- Moved truth-auction query helpers into `ui/ts/contracts/truthAuctions.ts`
- Moved fork-auction action execution helper into `ui/ts/contracts/securityPoolActions.ts`
- Added shared decoders/type helpers in `ui/ts/contracts/decoders.ts` and updated imports/exports in `ui/ts/contracts.ts`
- Updated `ui/ts/tests/contracts.test.ts` to match the reorganized contract module structure
- Add regression test ensuring `loadTruthAuctionTickBidPage` throws on invalid ABI-shaped bid page data
- Prevent trusting unchecked fields like malformed `refunded` in `getBidPageAtTick` responses
@KillariDev

Copy link
Copy Markdown
Collaborator Author

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI Agent Review

The refactoring extracts contract-interaction code from the monolithic contracts.ts into focused modules (reporting.ts, truthAuctions.ts, securityPoolActions.ts, decoders.ts) and replaces unsafe type assertions with runtime validation. One architectural concern remains: requireBigintValue is duplicated in both contracts.ts (local, still actively used) and the new decoders.ts (exported), and requireBigintArray was not extracted to decoders.ts at all, fragmenting the validation API surface across two locations.

Comment thread ui/ts/contracts.ts
return BigInt(pageIndex) * BigInt(pageSize)
}

function requireBigintValue(value: unknown, context: string) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

requireBigintValue is duplicated here and in the new decoders.ts (lines 19–22). Both implementations are byte-for-byte identical, but contracts.ts does not import from decoders.ts — the local copy is still actively used by loadOracleManagerDetails (4 calls to requireBigintValue, 1 call to requireBigintArray). Additionally, requireBigintArray was not extracted to decoders.ts at all, further splitting the validation API. Consider removing both functions from contracts.ts and importing them from decoders.ts to consolidate all response-validation primitives in a single module. As-is, any future change to validation logic must be applied in two places, and new code added to contracts.ts will naturally use the local copy rather than the centralized one.

@KillariDev

Copy link
Copy Markdown
Collaborator Author

Reviewer note: this PR intentionally makes malformed ABI/page reads fail loudly at the UI contract boundary. The latest follow-up also reuses a shared forkData decoder for both listed-pool and fork-auction reads, so the remaining current forkData tuple assumptions are covered by runtime validation.

@KillariDev

Copy link
Copy Markdown
Collaborator Author

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI Agent Review

No issues found. The refactoring decomposes contracts.ts into focused modules and replaces unsafe type casts with runtime validation — all four agents confirmed no architectural degradations, security vulnerabilities, runtime bugs, or backdoors.

@KillariDev
KillariDev merged commit 58f6527 into main Jun 23, 2026
1 of 2 checks passed
@KillariDev
KillariDev deleted the t3code/0189672f branch June 23, 2026 08:30
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