Skip to content

feat(rebalancer): implement LayerZeroBridge IExternalBridge#8347

Draft
Mo-Hussain wants to merge 25 commits intomainfrom
feat/layerzero-bridge
Draft

feat(rebalancer): implement LayerZeroBridge IExternalBridge#8347
Mo-Hussain wants to merge 25 commits intomainfrom
feat/layerzero-bridge

Conversation

@Mo-Hussain
Copy link
Copy Markdown
Collaborator

Summary

  • Implements LayerZeroBridge as a new IExternalBridge that calls LayerZero OFT/Legacy Mesh contracts directly to bridge USDT between Ethereum (EID 30101), Arbitrum (EID 30110), Plasma (EID 30383), and Tron (EID 30420)
  • Wired into rebalancer config as ExternalBridgeType.LayerZero in RebalancerContextFactory
  • No LayerZero SDK dependency — raw contract calls + fetch for quotes and status

Details

New files:

  • LayerZeroBridge.ts (535 lines) — quote(), execute(), getStatus() implementing IExternalBridge
  • layerZeroUtils.ts (270 lines) — route config, ABI fragments, EID/chain mappings, helper functions
  • LayerZeroBridge.test.ts (525 lines) — 17 tests covering quote, execute, getStatus, error paths
  • layerZeroMocks.ts (189 lines) — test mocks for providers and TronWeb

Modified files:

  • config/types.ts — added ExternalBridgeType.LayerZero = 'layerzero' and LayerZeroExternalBridgeConfig
  • RebalancerContextFactory.ts — wired LayerZeroBridge into buildExternalBridgeRegistry()
  • package.json — added tronweb: "catalog:" dependency

Design decisions:

  • Tron support via lazy dynamic import('tronweb') (no top-level import)
  • Hardcoded route table (no auto-discovery) — Tron↔Plasma and Ethereum↔Plasma excluded
  • Retry logic only on API/fetch calls, not on-chain transactions
  • No changes to IExternalBridge interface or LiFiBridge.ts

@hyper-gonk
Copy link
Copy Markdown
Contributor

hyper-gonk Bot commented Mar 30, 2026

🦀 Rust Agent Docker Image Built Successfully

Service Tag
agent db5c926-20260330-160628
Full image paths
ghcr.io/hyperlane-xyz/hyperlane-agent:db5c926-20260330-160628

@Mo-Hussain Mo-Hussain force-pushed the feat/tron-rebalancer-support-v2 branch from 9508152 to c9dec3f Compare March 31, 2026 12:10
@Mo-Hussain Mo-Hussain force-pushed the feat/layerzero-bridge branch from db5c926 to 49851e3 Compare March 31, 2026 12:10
Comment thread typescript/rebalancer/src/bridges/LayerZeroBridge.ts Outdated
Comment thread typescript/rebalancer/src/bridges/LayerZeroBridge.ts Outdated
// Contract Addresses
// ============================================================================

export const OFT_CONTRACTS: Record<number, Record<number, string>> = {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there layerzero packages that we can import to provide these addresses?

Comment thread typescript/rebalancer/src/bridges/layerZeroUtils.ts
Comment thread typescript/rebalancer/src/bridges/layerZeroUtils.ts Outdated
Comment thread typescript/rebalancer/src/bridges/layerZeroUtils.ts
Comment thread typescript/rebalancer/src/bridges/layerZeroUtils.ts Outdated
Comment thread typescript/rebalancer/src/bridges/layerZeroUtils.ts Outdated
Comment thread typescript/rebalancer/src/bridges/layerZeroUtils.ts Outdated
Comment thread typescript/rebalancer/src/bridges/LayerZeroBridge.ts Outdated
@socket-security
Copy link
Copy Markdown

socket-security Bot commented Apr 11, 2026

All alerts resolved. Learn more about Socket for GitHub.

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

View full report

@Mo-Hussain Mo-Hussain force-pushed the feat/layerzero-bridge branch from 85e1b98 to 6d65b8a Compare April 13, 2026 08:44
@Mo-Hussain Mo-Hussain force-pushed the feat/tron-rebalancer-support-v2 branch from c9dec3f to 8681013 Compare April 13, 2026 09:51
@Mo-Hussain Mo-Hussain force-pushed the feat/layerzero-bridge branch 2 times, most recently from 43468ab to 88a1117 Compare April 13, 2026 09:59
@Mo-Hussain Mo-Hussain force-pushed the feat/tron-rebalancer-support-v2 branch from 5aa780b to bef9066 Compare April 21, 2026 16:45
@Mo-Hussain Mo-Hussain force-pushed the feat/layerzero-bridge branch 3 times, most recently from 66c84e8 to 526d128 Compare April 22, 2026 13:22
Base automatically changed from feat/tron-rebalancer-support-v2 to main April 22, 2026 13:28
Tron is not supported for rebalancing. Removed all Tron-specific code:
TronWebLike type, toTronHexAddress/toEvmAddress helpers, Tron branches
in quote()/execute(), waitForTronTx(), isTronChain(), normalizeTronAddress(),
Tron entries from chain/contract mappings, Tron tests, and tronweb dependency.
Replaced custom addressToBytes32 in layerZeroUtils with delegation to
@hyperlane-xyz/utils addressToBytes32. Removed custom toBigInt() helper
in favor of BigInt(value.toString()) which handles ethers BigNumber.
Replaced hardcoded route pairs with a lookup against OFT_CONTRACTS,
eliminating duplication between the route table and the validation check.
…mEID

These were not referenced outside layerZeroUtils.ts.
Tests and mocks used 7758 for Plasma but OFT_CONTRACTS uses 9745
(the Hyperlane domain ID). Fixed to match the route configuration.
The USDT0 OFT program on Solana uses a custom OFTStore layout where
tokenMint starts at byte 8 (immediately after the discriminator),
unlike the standard SDK layout which expects oftType + ld2sdRate first.
This caused the SDK's fetchOFTStore() to fail with
EnumDiscriminatorOutOfRangeError.

Replace the SDK deserializer with a raw account data read that extracts
tokenEscrow directly from its known offset (byte 40).
The LZ SDK's SendHelper.getQuoteAccounts/getSendAccounts fails when
passed web3.js PublicKey objects due to module instance mismatch with
the instanceof check. Convert to UMI public key strings before passing.
@Mo-Hussain Mo-Hussain force-pushed the feat/layerzero-bridge branch from 526d128 to ebc33dc Compare April 22, 2026 13:37
@hyper-gonk
Copy link
Copy Markdown
Contributor

hyper-gonk Bot commented Apr 22, 2026

Node Services Docker Image Built Successfully

Service Tag
node-services ebc33dc-20260422-145459
Full image paths
ghcr.io/hyperlane-xyz/hyperlane-node-services:ebc33dc-20260422-145459

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

1 participant