feat: superbridge integration#21
Open
OWK50GA wants to merge 3 commits into
Open
Conversation
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.
feat: cross-chain bridging via Superbridge — IBridgeClient, SuperbridgeClient, BridgeSettler
What this does
Adds full cross-chain settlement to Griffin. When a user submits an intent where
fromChain !== toChain, the newBridgeSettlerroutes it through Superbridge, executing each step of the bridge transaction on-chain and waiting for destination-chain confirmation before marking the intent complete.New files
src/blockchain/IBridgeClient.tsThe bridge provider interface — same design discipline as
IChainClientandIDexClient. Defines three types and one interface:BridgeRoute— one provider's offer: amounts, fees, estimated time, ordered stepsBridgeStep— a single on-chain action within a route (approval, bridge tx)BridgeStepTransaction— raw calldata to submit for one stepIBridgeClient—getRoutes(),getStepTransaction(),waitForCompletion()BridgeSettlerdepends only on this interface. Adding Across, Hop, or any other bridge means implementingIBridgeClientand registering it — nothing else changes.src/blockchain/superbridge/SuperbridgeClient.tsImplements
IBridgeClientagainst the Superbridge HTTP API. The@superbridge/sdknpm package is not yet publicly available, so this usesfetchdirectly — mirroring the official SDK examples exactly. When the SDK ships, thepost()/get()calls can be swapped in with no interface changes.Key behaviours:
"eip155:133"chain ID format to the numeric IDs Superbridge expectsrouteIdsogetStepTransaction()can look them up without a second API call/v1/get_step_transactionwith the correctrecipientat execution timewaitForCompletion()polls/v1/activity, respectsnextCheckTimestampfrom the API, and times out after 60 pollssrc/settlement/BridgeSettler.tsImplements
ISettlerwithtype = SettlerType.BRIDGE.canSettle()checks three things in order:fromChain !== toChain— bridge is cross-chain only; same-chain intents are declined immediatelysettle()finds the best route across all registered providers (highestamountOut), then executes each step sequentially: fetches calldata viagetStepTransaction(), submits via the chain client's signer, waits for on-chain confirmation, then callswaitForCompletion()for destination-chain finality.src/tests/settlement/BridgeSettler.test.ts16 unit tests covering all
canSettleandsettlepaths — same-chain decline, missing chain client, no routes, multi-provider fallback, best route selection, approval step ordering, error propagation.src/tests/blockchain/SuperbridgeClient.test.ts18 unit tests covering route mapping, step list construction, approval calldata (no API call), bridge step transaction fetching, chain ID conversion, cache miss handling, and API error propagation. All tests mock
fetch— no real API key required.Modified files
src/settlement/ISettler.tsAdded
BRIDGE = "bridge"toSettlerType.src/settlement/SwapSettler.tsAdded an early return in
canSettle()for cross-chain intents:Previously
SwapSettlerwould attempt to swap cross-chain, which is semantically wrong. Now it declines cleanly and the engine falls through toBridgeSettler.src/blockchain/index.tsExports
IBridgeClient,BridgeRoute,BridgeStep,BridgeStepTransaction,SuperbridgeClient, andSuperbridgeClientConfig.src/config/index.tsAdded
external.superbridge.apiKeyreading fromSUPERBRIDGE_API_KEY.src/app.tsComposition root now instantiates
SuperbridgeClientand registersBridgeSettleras the third settler. MissingSUPERBRIDGE_API_KEYlogs a warning andBridgeSettlergracefully declines all cross-chain intents rather than crashing..env.example/packages/orchestrator/.env.exampleAdded
SUPERBRIDGE_API_KEY.Settlement priority after this PR
What is not in this PR
IBridgeClient, register inapp.tssendTransaction(to, data, value)onIChainClient— currently duck-typed to accessEvmClient.signerdirectly; tracked as a TODO for the next interface revision