refactor: apply empirically validated comprehension improvements#41
Merged
Conversation
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
There was a problem hiding this comment.
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/inforesponse 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
/exchangeresponse 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 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 |
Owner
Author
|
Follow-up commit pushed: Latest delta:
Verification run locally:
Current PR branch is up to date with these changes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
agent pnl,agent snapshot,order modify, and batch/order flowscmd/,pkg/client,pkg/exchange,pkg/info, andpkg/resolverValidation
make checkNotes
This branch is derived from the empirically kept refactors only, squashed into one commit for a cleaner review against
main.