Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't use cachedRoutes if intent.caching (100%) #837

Merged
merged 2 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uniswap/smart-order-router",
"version": "4.20.0",
"version": "4.20.1",
"description": "Uniswap Smart Order Router",
"main": "build/main/index.js",
"typings": "build/main/index.d.ts",
Expand Down
17 changes: 2 additions & 15 deletions src/routers/alpha-router/alpha-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3201,22 +3201,9 @@ export class AlphaRouter
);
}

// Percentage of time we want to skip cached routes for the experiment.
// Starting with 50% to gradually roll out the change.
public static readonly CACHED_ROUTES_SKIP_EXPERIMENT_FLAG_PERCENTAGE = 0.5;

// We want to skip cached routes access whenever "intent === INTENT.CACHING".
// To verify this functionality though, we want to start by using a percentage of the time.
// We keep this method as we might want to add more conditions in the future.
public static isAllowedToEnterCachedRoutes(intent?: INTENT): boolean {
// Check if we should run the experiment
const shouldRunExperiment =
Math.random() < AlphaRouter.CACHED_ROUTES_SKIP_EXPERIMENT_FLAG_PERCENTAGE;
if (shouldRunExperiment) {
// For the experiment group, we want to skip the cached routes access if the intent is caching
return intent !== INTENT.CACHING;
}

// For the control group, we always allow access to cached routes.
return true;
return intent !== INTENT.CACHING;
}
}
8 changes: 0 additions & 8 deletions test/unit/routers/alpha-router/alpha-router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3101,14 +3101,6 @@ describe('alpha router', () => {
});

test('returns correct values based on random percentage and intent', () => {
// Test when random is above experiment threshold (control group - should always return true)
randomStub.returns(AlphaRouter.CACHED_ROUTES_SKIP_EXPERIMENT_FLAG_PERCENTAGE + 0.01);
expect(AlphaRouter.isAllowedToEnterCachedRoutes(INTENT.CACHING)).toBe(true);
expect(AlphaRouter.isAllowedToEnterCachedRoutes(INTENT.QUOTE)).toBe(true);
expect(AlphaRouter.isAllowedToEnterCachedRoutes(undefined)).toBe(true);

// Test when random is below experiment threshold (experiment group)
randomStub.returns(AlphaRouter.CACHED_ROUTES_SKIP_EXPERIMENT_FLAG_PERCENTAGE - 0.001);
// Should return false only for CACHING intent
expect(AlphaRouter.isAllowedToEnterCachedRoutes(INTENT.CACHING)).toBe(false);
// Should return true for other intents
Expand Down
Loading