Skip to content

refactor(sealevel-programs): sealevel token transfer remote deduplication for token and cc token [IGNORE FOR NOW]#8659

Draft
xeno097 wants to merge 2 commits intoxeno/sealevel-token-fee-supportfrom
xeno/sealevel-token-tranfer-remote-dedup
Draft

refactor(sealevel-programs): sealevel token transfer remote deduplication for token and cc token [IGNORE FOR NOW]#8659
xeno097 wants to merge 2 commits intoxeno/sealevel-token-fee-supportfrom
xeno/sealevel-token-tranfer-remote-dedup

Conversation

@xeno097
Copy link
Copy Markdown
Contributor

@xeno097 xeno097 commented Apr 22, 2026

Description

Deduplicates the transfer_remote dispatch logic across the shared token library and the cross-collateral token program.

The cross-collateral token's transfer_remote_to_remote (~200 lines) was a near-copy of the shared token library's transfer_remote, differing only in the mailbox dispatch recipient (target_router vs enrolled router). This PR
extracts the common logic into two reusable methods on HyperlaneSealevelToken<T>:

  1. transfer_remote_to — shared remote-dispatch tail: validates mailbox/IGP accounts, converts amounts, calls plugin transfer_in, dispatches via mailbox CPI, and optionally pays IGP. Takes an explicit router: H256 parameter
    instead of resolving from enrolled routers internally.

  2. convert_and_transfer_in — shared transfer-in prelude: converts amount_or_id to local/remote decimals and calls T::transfer_in. Used by both the remote dispatch path and CC's same-chain local path
    (transfer_remote_to_local).

The existing transfer_remote resolves the enrolled router then delegates to transfer_remote_to. The CC program validates its CC-specific prefix (cc_state, router authorization, local-vs-remote branching) then delegates to the same
helpers.

~180 lines removed from the CC processor. No account layout or ordering changes.

Drive-by changes

  • Cleaned up unused imports in CC processor (BorshDeserialize, mailbox/IGP instruction types, HyperlaneGasRouter, HyperlaneConnectionClient, get_return_data, invoke)
  • transfer_remote_to returns remote_amount so callers can include it in their log messages

Related issues

  • Prep work for warp route fee support. convert_and_transfer_in is the single insertion point where fee validation + QuoteFee CPI will be added.

Backward compatibility

Yes — no account layout changes, no instruction reordering, no public instruction changes. The only behavioral difference is that CC's amount overflow error changes from ProgramError::InvalidArgument to Error::IntegerOverflow
(aligning with the shared library); no test exercises this edge case.

Testing

Unit Tests — all existing tests pass:

  • hyperlane-sealevel-token (synthetic)
  • hyperlane-sealevel-token-collateral
  • hyperlane-sealevel-token-native
  • hyperlane-sealevel-token-cross-collateral (41 tests)
  • hyperlane-sealevel-hello-world (compilation check — uses dispatch traits)
  • Clippy clean across all modified crates

Open in Devin Review

xeno097 added 2 commits April 22, 2026 17:04
…helper

Extracted the common remote-dispatch tail (mailbox CPI, IGP payment,
amount conversion, plugin transfer_in) into a new `transfer_remote_to`
method on `HyperlaneSealevelToken<T>`. The existing `transfer_remote`
resolves the enrolled router then delegates, while the cross-collateral
token passes its explicit `target_router` directly.

~180 lines removed from the CC processor with no account layout or
ordering changes.
Extracted amount conversion + plugin transfer_in into
`convert_and_transfer_in` on `HyperlaneSealevelToken<T>`. Both the
remote dispatch path and CC's same-chain local path now delegate to it.

Also fixed transfer_remote_to to return remote_amount so callers can
restore the original log messages that were lost in the prior commit.
@xeno097 xeno097 requested review from tkporter and yjamin as code owners April 22, 2026 21:47
@github-project-automation github-project-automation Bot moved this to In Review in Hyperlane Tasks Apr 22, 2026
@xeno097 xeno097 marked this pull request as draft April 22, 2026 21:47
@xeno097 xeno097 removed the request for review from yjamin April 22, 2026 21:48
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 5 additional findings.

Open in Devin Review

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