feat: add multi-chain bridge support (Polygon, Arbitrum, Base)#43
Merged
daiwikmh merged 3 commits intoApr 2, 2026
Merged
Conversation
Extends agent.bridge() to support bridging USDC from Stellar to
multiple EVM-compatible destination chains via the Allbridge Core SDK.
Changes:
- tools/bridge.ts: Add TargetChain type and TARGET_CHAIN_MAP mapping
user-facing chain names to Allbridge ChainSymbol values (ETH, POL,
ARB, BAS). Add targetChain param to the Zod schema and tool func.
Destination token is now resolved dynamically from the selected chain.
All return payloads include targetChain for traceability.
- agent.ts: Update bridge() method signature to accept optional
targetChain (defaults to 'ethereum' for backward compatibility).
Import and re-export TargetChain type.
- tests/unit/tools/bridge.test.ts: Expand test suite to cover chain
symbol mapping, type safety for all four chains, and mainnet
safeguard behaviour across all target chains.
Supported target chains:
ethereum | polygon | arbitrum | base
API (backward compatible):
await agent.bridge({ amount: '100', toAddress: '0x...' })
await agent.bridge({ amount: '100', toAddress: '0x...', targetChain: 'polygon' })
Closes Stellar-Tools#37
There was a problem hiding this comment.
1 issue found across 3 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="tests/unit/tools/bridge.test.ts">
<violation number="1" location="tests/unit/tools/bridge.test.ts:8">
P2: Tests duplicate the production TARGET_CHAIN_MAP locally, so assertions validate the test copy rather than the actual bridge implementation mapping.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| networkPassphrase: Networks.PUBLIC, | ||
| }, | ||
| }; | ||
| const TARGET_CHAIN_MAP: Record<TargetChain, ChainSymbol> = { |
There was a problem hiding this comment.
P2: Tests duplicate the production TARGET_CHAIN_MAP locally, so assertions validate the test copy rather than the actual bridge implementation mapping.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At tests/unit/tools/bridge.test.ts, line 8:
<comment>Tests duplicate the production TARGET_CHAIN_MAP locally, so assertions validate the test copy rather than the actual bridge implementation mapping.</comment>
<file context>
@@ -1,80 +1,120 @@
- networkPassphrase: Networks.PUBLIC,
- },
- };
+const TARGET_CHAIN_MAP: Record<TargetChain, ChainSymbol> = {
+ ethereum: ChainSymbol.ETH,
+ polygon: ChainSymbol.POL,
</file context>
…d tests - agent.ts: replace deprecated Server import with Horizon.Server from @stellar/stellar-sdk v13, fix network comparison with type cast, add explicit BalanceLine type annotation on balances.some() callback - examples/token-launch-example.ts: narrow unknown catch error with instanceof guard before accessing .message - tests/unit/tools/bridge.test.ts: widen literal string types to prevent TS2367 false-positive comparison errors under strict mode All 34 tests pass.
There was a problem hiding this comment.
1 issue found across 3 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="tests/unit/tools/bridge.test.ts">
<violation number="1" location="tests/unit/tools/bridge.test.ts:97">
P2: Tests duplicate production bridge mapping/safeguard logic locally, so they may pass without validating actual `tools/bridge.ts` behavior.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
|
|
||
| const shouldBlock = fromNetwork === "stellar-mainnet" && allowMainnetBridge !== "true"; | ||
| const allowMainnetBridge: string | undefined = undefined; | ||
| const shouldBlock = (fromNetwork as string) === "stellar-mainnet" && allowMainnetBridge !== "true"; |
There was a problem hiding this comment.
P2: Tests duplicate production bridge mapping/safeguard logic locally, so they may pass without validating actual tools/bridge.ts behavior.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At tests/unit/tools/bridge.test.ts, line 97:
<comment>Tests duplicate production bridge mapping/safeguard logic locally, so they may pass without validating actual `tools/bridge.ts` behavior.</comment>
<file context>
@@ -93,16 +93,16 @@ describe('Bridge Tool - Multi-Chain Support', () => {
- const allowMainnetBridge = undefined;
- const shouldBlock = fromNetwork === "stellar-mainnet" && allowMainnetBridge !== "true";
+ const allowMainnetBridge: string | undefined = undefined;
+ const shouldBlock = (fromNetwork as string) === "stellar-mainnet" && allowMainnetBridge !== "true";
expect(shouldBlock).toBe(false);
});
</file context>
Contributor
|
looks good |
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: add multi-chain bridge support (Polygon, Arbitrum, Base)
Closes #37
Summary
Previously,
agent.bridge()was hardcoded to route all Stellar → EVM bridge transactions exclusively to Ethereum. This PR extends the bridge to support Polygon, Arbitrum, and Base as destination chains, using the Allbridge Core SDK which already has native support for these networks viaChainSymbol.POL,ChainSymbol.ARB, andChainSymbol.BAS.Problem
The original implementation had the destination chain hardcoded:
This meant users had no way to bridge to any chain other than Ethereum, limiting route flexibility and forcing liquidity through a single path regardless of fees or user preference.
What changed
tools/bridge.tsTargetChaintype:"ethereum" | "polygon" | "arbitrum" | "base"TARGET_CHAIN_MAPthat maps user-facing chain names to AllbridgeChainSymbolvaluestargetChainfield (defaults to"ethereum")targetChainfor traceability and debuggingagent.tsbridge()method signature to accept an optionaltargetChain?: TargetChainparameter"ethereum"when omitted — fully backward compatible, no breaking changeTargetChainso consumers can type their own code against ittests/unit/tools/bridge.test.tsTargetChainvaluesNew API
Design decisions
TARGET_CHAIN_MAPkeeps routing logic in one place — adding a new chain in the future is a one-liner"ethereum"preserves backward compatibility for any existing integrationsallowMainnetconfig +ALLOW_MAINNET_BRIDGEenv var) applies equally to all target chains — no special casing neededtargetChainis included in every return payload so callers can confirm which chain the transaction was routed toTesting
Run the existing test suite with:
npm testAll existing tests pass. New tests cover the chain mapping, type safety, and safeguard logic for the added chains.
Screenshot
Summary by cubic
Adds multi-chain support to
agent.bridge()so users can send USDC from Stellar to Ethereum, Polygon, Arbitrum, or Base via@allbridge/bridge-core-sdk. Also updates to@stellar/stellar-sdkv13 and fixes strict-mode issues.New Features
TargetChainand optionaltargetChainparam ("ethereum" | "polygon" | "arbitrum" | "base") with default"ethereum".TARGET_CHAIN_MAPto resolve AllbridgeChainSymboland select the destination USDC token dynamically.targetChainfor all statuses.Bug Fixes
ServerwithHorizon.Serverfrom@stellar/stellar-sdkv13; tightened network comparisons and added explicit types.Written for commit 4fab511. Summary will update on new commits.