Skip to content

refactor: apply empirically validated comprehension improvements#41

Merged
timbrinded merged 3 commits into
mainfrom
refactor/empirical-comprehension-wins
Mar 19, 2026
Merged

refactor: apply empirically validated comprehension improvements#41
timbrinded merged 3 commits into
mainfrom
refactor/empirical-comprehension-wins

Conversation

@timbrinded

Copy link
Copy Markdown
Owner

Summary

This PR packages the code-only wins from the empirical code-comprehension pass into a single reviewable branch.

It intentionally excludes the autoresearch harness, logs, and ideas files, and it does not include any static-analysis-only follow-up fixes.

Included empirical wins

  • consolidate repeated CLI parsing/helpers for order flags, clients, resolvers, and shared info fetches
  • flatten large command handlers such as agent pnl, agent snapshot, order modify, and batch/order flows
  • split oversized files into focused units in cmd/, pkg/client, pkg/exchange, pkg/info, and pkg/resolver
  • remove duplicated command-layer validation already enforced in executor/package layers
  • simplify request/result assembly and small helper shapes where the changes stayed explicit and behavior-preserving

Validation

  • make check

Notes

This branch is derived from the empirically kept refactors only, squashed into one commit for a cleaner review against main.

Keep only the code refactors validated in the comprehension autoresearch pass, excluding autoresearch harness/log artifacts.

Highlights:
- consolidate shared CLI parsing, client, resolver, and fetch helpers
- flatten large command handlers and split oversized command files
- split large package files in client, exchange, info, and resolver into focused units
- remove duplicated command-layer validation already enforced downstream
- simplify request/result assembly while preserving behavior

Validation: make check
Copilot AI review requested due to automatic review settings March 19, 2026 10:10

Copilot AI 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.

Pull request overview

This PR refactors CLI, resolver, client, exchange executor, and info-response code to improve readability and reduce duplication by splitting large files into focused units and centralizing shared helper logic.

Changes:

  • Split and reorganize resolver metadata/spot mapping logic, and split pkg/info response parsing into focused files.
  • Consolidate CLI flag parsing, required-flag registration, shared client/resolver/executor builders, and dry-run/request assembly helpers across commands.
  • Extract client /exchange response validation and factor HTTP status handling into a dedicated helper.

Reviewed changes

Copilot reviewed 53 out of 53 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/signer/signer.go Minor struct literal formatting cleanup.
pkg/signer/phantom.go Refactor typed-data construction formatting.
pkg/signer/eip712.go Refactor domain/typed-data construction formatting.
pkg/resolver/spot_maps.go New: spot/perp map building + spot alias logic extracted.
pkg/resolver/resolver.go Removed inlined metadata/map logic after extraction to new files.
pkg/resolver/metadata.go New: core/HIP-3 metadata load/fetch/timeout helpers extracted.
pkg/resolver/cache.go Minor struct literal formatting cleanup.
pkg/output/errors.go Minor struct literal formatting cleanup.
pkg/info/responses_market.go New: market-related info response parsing + tabular output.
pkg/info/responses_funding.go New: funding-related info response parsing + APR helper.
pkg/info/responses_account.go New: account/state/open-orders/fills response parsing + tables.
pkg/info/responses.go Old monolithic responses file removed (now effectively empty).
pkg/exchange/executor_user_helpers.go New: shared user-signed action execution + payload assembly.
pkg/exchange/executor_user.go New: user-signed executor methods (transfer/withdraw/send/agent/etc.).
pkg/exchange/executor_orders.go New: order placement pipeline + market-order convenience logic.
pkg/exchange/executor_management.go New: leverage/margin/modify/cancel scheduling + shared L1 execution.
pkg/exchange/builder.go Minor struct literal formatting cleanup across action builders.
pkg/client/weight.go Minor cleanup in warning JSON construction and oldest tracking.
pkg/client/exchange_response.go New: extracted /exchange envelope/status validation.
pkg/client/client.go Refactor: extracted status-code handling + response validation helper.
cmd/position_margin.go Use shared parsing/helpers; simplify command handler.
cmd/position_leverage.go Use shared required-flag helper and input assembly.
cmd/position.go Use shared help-command-group constructor.
cmd/order_schedule_cancel.go Extract timeout parsing into helper; simplify handler.
cmd/order_place.go Centralize place-order input parsing; remove duplicated executor wiring.
cmd/order_modify.go Extract base parsing/backfill helpers; simplify handler.
cmd/order_market.go Centralize market-order input parsing; simplify handler.
cmd/order_cancel.go Refactor cancel/cancel-all flows; reuse shared helpers.
cmd/order_batch.go Extract batch file parsing + order param build helper.
cmd/order.go Use shared help-command-group constructor.
cmd/info_user.go Centralize address resolution; reuse fetch helpers.
cmd/info_market.go Extract parsing helpers; reuse fetch helpers.
cmd/info_lookup_score.go New: lookup scoring implementation extracted.
cmd/info_lookup_fetch.go New: lookup metadata fetching helpers extracted.
cmd/info_lookup_aliases.go New: lookup alias generation helpers extracted.
cmd/info_lookup.go Refactor lookup command to use extracted fetch/score/alias helpers.
cmd/info_funding.go Extract predicted funding flow helper; simplify handler.
cmd/info.go Use shared help-command-group constructor.
cmd/helpers.go New/expanded: shared builders (client/resolver/executor) + parsing helpers.
cmd/config.go Refactor config init/show/test output and connectivity probe helper.
cmd/agent_snapshot.go Extract dry-run payload + snapshot runner; simplify handler.
cmd/agent_pnl_calc.go New: extracted PnL calculation helpers.
cmd/agent_pnl.go Refactor PnL command to use extracted helpers and cleaner structure.
cmd/agent_bracket.go Reuse shared order input parsing + trigger validation helper.
cmd/agent.go Use shared help-command-group constructor.
cmd/account_withdraw.go Reuse shared parsing/confirm helper; simplify handler.
cmd/account_transfer.go Introduce reusable USD class transfer command factory.
cmd/account_set_abstraction.go Delegate validation to executor layer; simplify handler.
cmd/account_send_asset.go Reuse shared parsing/confirm helper; simplify handler.
cmd/account_class_transfer.go Convert to wrapper using shared USD class transfer command factory.
cmd/account_approve_agent.go Reuse shared confirm helper; simplify handler.
cmd/account.go Use shared help-command-group constructor.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread cmd/order_cancel.go
Comment on lines +141 to +145
assetInfo, err := buildResolver(cfg).ResolveAsset(cmd.Context(), order.Coin)
if err != nil {
return exchange.CancelWire{}, err
}
return exchange.CancelWire{A: assetInfo.AssetID, O: uint64(order.Oid)}, nil
@timbrinded

Copy link
Copy Markdown
Owner Author

Follow-up commit pushed: 85db866

Latest delta:

  • restored account approve-agent invalid-address validation precedence and added regression coverage
  • unified e2e key wiring so funded runs only need HL_TEST_PRIVATE_KEY
  • collapsed live integration inputs behind a single HL_TEST_LIVE_CONFIG_JSON blob
  • split safe vs explicit live integration entry points: make test-integration and make test-integration-live
  • aligned CI so the safe integration path maps HL_TEST_MASTER_KEY -> HL_TEST_PRIVATE_KEY, with a separate manual live job using HL_TEST_LIVE_CONFIG_JSON

Verification run locally:

  • make test
  • HL_TEST_PRIVATE_KEY="$DEPLOYER_PRIVATE_KEY" make test-integration
  • HL_TEST_PRIVATE_KEY="$DEPLOYER_PRIVATE_KEY" HL_TEST_LIVE_CONFIG_JSON=... make test-integration-live
  • full e2e suite passes with HL_TEST_PRIVATE_KEY, HL_E2E_WRITE=1, and HL_E2E_MAINNET=1

Current PR branch is up to date with these changes.

@timbrinded timbrinded merged commit 4238b4d into main Mar 19, 2026
5 checks passed
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.

2 participants