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
Conversation
…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.
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.
Description
Deduplicates the
transfer_remotedispatch 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'stransfer_remote, differing only in the mailbox dispatch recipient (target_routervs enrolled router). This PRextracts the common logic into two reusable methods on
HyperlaneSealevelToken<T>:transfer_remote_to— shared remote-dispatch tail: validates mailbox/IGP accounts, converts amounts, calls plugintransfer_in, dispatches via mailbox CPI, and optionally pays IGP. Takes an explicitrouter: H256parameterinstead of resolving from enrolled routers internally.
convert_and_transfer_in— shared transfer-in prelude: convertsamount_or_idto local/remote decimals and callsT::transfer_in. Used by both the remote dispatch path and CC's same-chain local path(
transfer_remote_to_local).The existing
transfer_remoteresolves the enrolled router then delegates totransfer_remote_to. The CC program validates its CC-specific prefix (cc_state, router authorization, local-vs-remote branching) then delegates to the samehelpers.
~180 lines removed from the CC processor. No account layout or ordering changes.
Drive-by changes
BorshDeserialize, mailbox/IGP instruction types,HyperlaneGasRouter,HyperlaneConnectionClient,get_return_data,invoke)transfer_remote_toreturnsremote_amountso callers can include it in their log messagesRelated issues
convert_and_transfer_inis 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::InvalidArgumenttoError::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-collateralhyperlane-sealevel-token-nativehyperlane-sealevel-token-cross-collateral(41 tests)hyperlane-sealevel-hello-world(compilation check — uses dispatch traits)