refactor: unify submitTx and submitIntent#8257
Draft
micaelae wants to merge 4 commits intoswaps4229-extract-controller-callsfrom
Draft
refactor: unify submitTx and submitIntent#8257micaelae wants to merge 4 commits intoswaps4229-extract-controller-callsfrom
micaelae wants to merge 4 commits intoswaps4229-extract-controller-callsfrom
Conversation
…itTx-strategy-refactor
4 tasks
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.
Explanation
Before
Currently,
submitTxandsubmitIntentare separate entry points that have overlapping logic. This obscures how the flows differ and some behaviors are inconsistent, although needed by both.submitTxinlines long branching for non-EVM, batch/STX/7702, and default EVM paths, with history, rekeying, polling, and analytics mixed into each branchsubmitIntentis a second large path: intent-specific steps (approval, signing, API submit, synthetic tx) with its own history and polling/intent-manager logicflowchart TB subgraph before["Before: two large entry points"] ST[submitTx] SI[submitIntent] ST --> B1{Branch on quote/flags} B1 --> N[Non-EVM path] B1 --> BA[Batch/STX/7702 path] B1 --> E[Default EVM path] N & BA & E --> X1[History, rekey, polling, metrics<br/>interleaved per branch] SI --> B2{Intent-specific branching} B2 --> I[Approval + sign + API + synthetic tx] I --> X2[History, polling, intent manager<br/>interleaved in method] endAfter
This PR reorganizes tx submission around a strategy (reduce the quote-specific if conditions in the controller) and a command stream (strategies yield step results, and the controller uses those to update history, poll, and publish metrics). Each strategy yields results in their own order.
executeSubmitFlowmethod executes the first strategy that matches the quote and submitTx paramssubmitIntent's signature has not changed, but it now forwards calls tosubmitTx. Intent submission logic is implemented in the intent strategy, not a parallel code pathNew shared submit flow
submitTx: orchestrates tracing, metrics, error handling and executes the strategy. EachSubmitStepResultyielded by the strategy is applied as a controller state update or a side effectstrategy/*-strategy.ts: async generators that define how each quote type should be processed, and yield order determines when the controller applies resultsutils/: lightweight modules implement calls to other contreollers and other shared logic and to keep strategies concise and readableExample dev workflows
Add a step that applies to every flow
SubmitStepResultinstrategy/types.tswith a new type describing the stepbridge-status-controller.ts, inside thefor awaitloop oversteps, handle thattype(private method or messenger call)evm-strategy,batch-strategy,intent-strategy,non-evm-strategy),yieldthe step when it should run (order matters)Add a step to a single flow
yieldthe step from the strategy file that needs it (e.g. onlyintent-strategy.ts)Add logic that does not need BridgeStatusController state updates or events
These can stay within the relevant strategy as plain async code (no new
SubmitStepResulttype) when it does not touch bridge history, polling, or metrics publishingReferences
Checklist