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 logic%%{init: {"themeVariables": {"noteBkgColor": "#ffffff", "noteTextColor": "#333333", "noteBorderColor": "#cccccc"}}}%% sequenceDiagram participant Ext as Client participant BSC as BridgeStatusController Ext->>BSC: submitTx Note left of BSC: pick one flow based on quote + client <br/>flags. each branch has its own step<br/> sequence and error handling alt non-EVM chains Note right of BSC: submitApproval if Tron Note right of BSC: submitTrade Note right of BSC: setTradeMeta Note right of BSC: publishFailedEvent when needed else gasless, STX or 7702 Note right of BSC: submitBatch Note right of BSC: setTradeMeta else EVM Note right of BSC: submitApproval Note right of BSC: addHistoryItem Note right of BSC: submitTrade Note right of BSC: rekeyHistoryItem Note right of BSC: setTradeMeta else shared Note right of BSC: startPolling if Tron or bridge tx Note right of BSC: addHistoryItem if non-EVM or gasless Note right of BSC: publishCompletedEvent if non-EVM swap end Ext->>BSC: submitIntent Note right of BSC: submitApproval Note right of BSC: sign EIP-712 intent payload Note right of BSC: submit intent order via IntentManager Note right of BSC: add a synthetic tx using <br/> orderId from order submission Note right of BSC: addHistoryItemAfter
This PR reorganizes tx submission into strategies (reduces quote-specific if conditions in the controller) and an action 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.
%%{init: {"flowchart": {"useMaxWidth": true, "padding": 16, "nodeSpacing": 32, "rankSpacing": 48}}}%% flowchart TB subgraph top[" "] direction LR SI["submitIntent entrypoint<br/>proxies to submitTx"] --> ST["submitTx orchestrates tracing,<br/>metrics, error handling,<br/>and strategy execution"] end REG["executeSubmitFlow picks <br/> a strategy based on <br/> quote and params"] subgraph s_non[" "] direction TB nn1["publishFailedEvent"] --> nn2["setTradeMeta"] --> nn3["addHistoryItem"] --> nn4["startPolling"] --> nn5["publishCompletedEvent<br/>(optional)"] end subgraph s_batch[" "] direction TB bb1["setTradeMeta"] --> bb2["addHistoryItem"] end subgraph s_intent[" "] direction TB ii1["setTradeMeta"] --> ii2["addHistoryItem"] --> ii3["startPolling"] end subgraph s_evm[" "] direction TB ee1["addHistoryItem"] --> ee2["rekeyHistoryItem"] --> ee3["setTradeMeta"] end ST --> REG REG --> lblNon["non-evm-strategy"] lblNon --> nn1 REG --> lblBatch["batch-strategy"] lblBatch --> bb1 REG --> lblIntent["intent-strategy"] lblIntent --> ii1 REG --> lblEvm["evm-strategy default"] lblEvm --> ee1 classDef stratLabel fill:#ffffff,stroke:#57606a,color:#1f2328 class lblNon,lblBatch,lblIntent,lblEvm stratLabelEach strategy is an async generator that yields step results for the BridgeStatusController to apply
%%{init: {"themeVariables": {"noteBkgColor": "#ffffff", "noteTextColor": "#333333", "noteBorderColor": "#cccccc"}}}%% sequenceDiagram participant BSC as submitTx participant IDX as executeSubmitFlow participant STR as strategy BSC->>IDX: starts executing submit strategy IDX->>STR: selects and executes strategy (async generator) Note over STR,IDX: Each strategy yields a subset of these steps in different orders STR-->>BSC: publishFailedEvent Note right of BSC: if any exception is thrown, the Failed metric is published STR-->>BSC: setTradeMeta Note right of BSC: set the tradeMeta to be returned to the client STR-->>BSC: addHistoryItem Note right of BSC: include metadata in action payload and update state STR-->>BSC: rekeyHistoryItem Note right of BSC: update state historyItem with trade metadata STR-->>BSC: startPolling Note right of BSC: starts polling by the provided key (actionId, orderId, tradeMetaId) STR-->>BSC: publishCompletedEvent Note right of BSC: call trackUnifiedSwapBridgeEvent with txHistory key STR-->>IDX: generator is done IDX-->>BSC: return Note right of BSC: return tradeMetaExample dev workflows
Add a step to some flows
SubmitStepResultwith a new variant describing the steputils(avoid bridge-status-controller.ts)submitTx's generator processing loopyieldthe newSubmitStepResultwhen it should run (order matters)Add a step that applies to all flows
utils(avoid bridge-status-controller.ts)submitTx, outside of the generator processing loopAdd logic that does not need BridgeStatusController state updates or events
These can stay within the relevant strategy as plain async code. No new
SubmitStepResulttype is needed if it doesn't touch bridge history, polling, or metrics publishingReferences
Checklist