Skip to content

Conversation

@ashwinrava
Copy link
Member

Following on from #1864, I want to refactor the routing rules in a way that makes it easy to add new rules. In the old approach, new rules could introduce more branching and duplication of conditions and was making the actual logic unreadable.

In this PR:

  • Refactor routeStrategyForCctp to use a decision table
  • Move routing related functions and types into separate file
  • Add generated tests for each possibility

@vercel
Copy link

vercel bot commented Oct 20, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
app-frontend-v3 Ready Ready Preview Comment Oct 21, 2025 3:53pm
sepolia-frontend-v3 Ready Ready Preview Comment Oct 21, 2025 3:53pm

💡 Enable Vercel Agent with $100 free credit for automated AI reviews

Copy link
Contributor

@NikolasHaimerl NikolasHaimerl left a comment

Choose a reason for hiding this comment

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

The new routeStrategyForCctp looks much better, great change.

Copy link
Contributor

@dohaki dohaki left a comment

Choose a reason for hiding this comment

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

Nice stuff! Left some questions

const ROUTING_RULES: RoutingRule[] = [
{
name: "non-usdc-route",
priority: 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we infer the priority based on the index in the array? Or would there be cases where we have same priority for a rule?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah good point. Thought it could be useful for readability but a top level comment would do.

Makes me think we can consider a field like group in the future though for better organization and less duplication. For example:

  {
    name: "fast-cctp-small-deposit",
    shouldApply: (data) =>
      data.isFastCctpEligible && !data.isInThreshold && !data.isLargeDeposit,
    getStrategy: getCctpBridgeStrategy,
    reason:
      "Fast CCTP eligible chains (Polygon/BSC/Solana) use CCTP for medium deposits (>$10K, <$1M)",
  },
  {
    name: "fast-cctp-threshold-or-large",
    shouldApply: (data) =>
      data.isFastCctpEligible && (data.isInThreshold || data.isLargeDeposit),
    getStrategy: getAcrossBridgeStrategy,
    reason:
      "Fast CCTP chains use Across for very small (<$10K) or very large (>$1M) deposits",
  },

We could have both of these be part of a "group" fast-cctp where the base condition is data.isFastCctpEligible and then rule 1: data.isInThreshold || data.isLargeDeposit and rule 2 (default): would return true. Will think about this.

reason: string;
};

const ROUTING_RULES: RoutingRule[] = [
Copy link
Contributor

Choose a reason for hiding this comment

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

How would this work with a separate branch of rules? Like for sponsorship eligibility? Would we use just a different set of rules?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah exactly. I think it would be cleaner as a separate set. I am working on the PR for that now with some placeholders for the eligibility module.

The new set would be compatible since getStrategy: () => BridgeStrategy; still holds true.

Copy link
Member Author

Choose a reason for hiding this comment

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

Implemented here: #1915

Lmk what you think @dohaki

@ashwinrava ashwinrava merged commit 293e5a6 into epic/sponsored-bridging-to-hypercore Oct 21, 2025
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants