-
Notifications
You must be signed in to change notification settings - Fork 442
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: exclude certain protocol versions from mixed routing (#686)
* feat: exclude certain protocol versions from mixed routing * feat: exclude certain protocol versions from mixed routing * fix: base gas deviation is 53% * only wipe out cached routes when intent=caching, meaning it's offline request * fix unit test
- Loading branch information
Showing
8 changed files
with
212 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
112 changes: 112 additions & 0 deletions
112
test/unit/routers/alpha-router/functions/routes.test.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { | ||
AlphaRouterConfig, | ||
CachedRoute, | ||
CachedRoutes, | ||
DAI_MAINNET, | ||
excludeProtocolPoolRouteFromMixedRoute, | ||
MixedRoute, | ||
shouldWipeoutCachedRoutes, | ||
USDC_MAINNET | ||
} from '../../../../../src'; | ||
import { Protocol } from '@uniswap/router-sdk'; | ||
import { ChainId, TradeType } from '@uniswap/sdk-core'; | ||
import { | ||
USDC_DAI, | ||
USDC_DAI_LOW, | ||
USDC_DAI_MEDIUM, | ||
USDC_DAI_V4_LOW | ||
} from '../../../../test-util/mock-data'; | ||
import { | ||
DEFAULT_ROUTING_CONFIG_BY_CHAIN | ||
} from '../../../../../src/routers/alpha-router/config'; | ||
|
||
describe('routes', () => { | ||
const mixedRoutes1 = new MixedRoute([USDC_DAI, USDC_DAI_LOW], USDC_MAINNET, DAI_MAINNET); | ||
const cachedRoute1 = new CachedRoute({ | ||
route: mixedRoutes1, | ||
percent: 50, | ||
}); | ||
const mixedRoutes2 = new MixedRoute([USDC_DAI_V4_LOW, USDC_DAI_LOW], USDC_MAINNET, DAI_MAINNET); | ||
const cachedRoute2 = new CachedRoute({ | ||
route: mixedRoutes2, | ||
percent: 50, | ||
}); | ||
const mixedRoutes3 = new MixedRoute([USDC_DAI, USDC_DAI_LOW, USDC_DAI_MEDIUM], USDC_MAINNET, DAI_MAINNET); | ||
const cachedRoute3 = new CachedRoute({ | ||
route: mixedRoutes3, | ||
percent: 50, | ||
}); | ||
|
||
const cachedRoutesIncludeRouteWithV4Pool = new CachedRoutes({ | ||
routes: [cachedRoute1, cachedRoute2], | ||
chainId: 1, | ||
tokenIn: USDC_MAINNET, | ||
tokenOut: DAI_MAINNET, | ||
protocolsCovered: [Protocol.V2, Protocol.V3, Protocol.V4, Protocol.MIXED], | ||
blockNumber: 1, | ||
tradeType: TradeType.EXACT_INPUT, | ||
originalAmount: '100', | ||
blocksToLive: 100 | ||
}); | ||
|
||
const cachedRoutesIncludeRouteWithoutV4Pool = new CachedRoutes({ | ||
routes: [cachedRoute1, cachedRoute3], | ||
chainId: 1, | ||
tokenIn: USDC_MAINNET, | ||
tokenOut: DAI_MAINNET, | ||
protocolsCovered: [Protocol.V2, Protocol.V3, Protocol.V4, Protocol.MIXED], | ||
blockNumber: 1, | ||
tradeType: TradeType.EXACT_INPUT, | ||
originalAmount: '100', | ||
blocksToLive: 100 | ||
}); | ||
|
||
test(`do not exclude any cached route for empty excluded protocols list`, async () => { | ||
const routingConfig: AlphaRouterConfig = { | ||
// @ts-ignore[TS7053] - complaining about switch being non exhaustive | ||
...DEFAULT_ROUTING_CONFIG_BY_CHAIN[ChainId.MAINNET], | ||
protocols: [Protocol.V2, Protocol.V3, Protocol.V4, Protocol.MIXED], | ||
excludedProtocolsFromMixed: [], | ||
optimisticCachedRoutes: false, | ||
}; | ||
|
||
expect(shouldWipeoutCachedRoutes(cachedRoutesIncludeRouteWithV4Pool, routingConfig)).toBeFalsy(); | ||
}); | ||
|
||
test(`exclude cached route for V4 protocol`, async () => { | ||
const routingConfig: AlphaRouterConfig = { | ||
// @ts-ignore[TS7053] - complaining about switch being non exhaustive | ||
...DEFAULT_ROUTING_CONFIG_BY_CHAIN[ChainId.MAINNET], | ||
protocols: [Protocol.V2, Protocol.V3, Protocol.V4, Protocol.MIXED], | ||
excludedProtocolsFromMixed: [Protocol.V4], | ||
optimisticCachedRoutes: false, | ||
}; | ||
expect(shouldWipeoutCachedRoutes(cachedRoutesIncludeRouteWithV4Pool, routingConfig)).toBeTruthy(); | ||
}); | ||
|
||
test(`do not exclude cached route for V4 protocol`, async () => { | ||
const routingConfig: AlphaRouterConfig = { | ||
// @ts-ignore[TS7053] - complaining about switch being non exhaustive | ||
...DEFAULT_ROUTING_CONFIG_BY_CHAIN[ChainId.MAINNET], | ||
protocols: [Protocol.V2, Protocol.V3, Protocol.V4, Protocol.MIXED], | ||
excludedProtocolsFromMixed: [Protocol.V4], | ||
optimisticCachedRoutes: false, | ||
}; | ||
expect(shouldWipeoutCachedRoutes(cachedRoutesIncludeRouteWithoutV4Pool, routingConfig)).toBeFalsy(); | ||
}); | ||
|
||
test(`do not exclude any mixed route for empty excluded protocols list`, async () => { | ||
const newMixedRoutes = excludeProtocolPoolRouteFromMixedRoute([mixedRoutes1, mixedRoutes2, mixedRoutes3], []); | ||
expect(newMixedRoutes).toStrictEqual([mixedRoutes1, mixedRoutes2, mixedRoutes3]); | ||
}); | ||
|
||
test(`exclude mixed route for V4 protocol`, async () => { | ||
const newMixedRoutes = excludeProtocolPoolRouteFromMixedRoute([mixedRoutes1, mixedRoutes2, mixedRoutes3], [Protocol.V4]); | ||
expect(newMixedRoutes).toStrictEqual([mixedRoutes1, mixedRoutes3]); | ||
}); | ||
|
||
test(`do not exclude mixed route for V4 protocol`, async () => { | ||
const newMixedRoutes = excludeProtocolPoolRouteFromMixedRoute([mixedRoutes1, mixedRoutes3], [Protocol.V4]); | ||
expect(newMixedRoutes).toStrictEqual([mixedRoutes1, mixedRoutes3]); | ||
}); | ||
}); |