Skip to content

Commit

Permalink
4.17.2 (#807)
Browse files Browse the repository at this point in the history
* 4.17.2

* mixed quoter v2 L1 address

* fix prettier
  • Loading branch information
jsy1218 authored Jan 30, 2025
1 parent 5a6d944 commit 55be8bb
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 19 deletions.
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.17.1",
"version": "4.17.2",
"description": "Uniswap Smart Order Router",
"main": "build/main/index.js",
"typings": "build/main/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/providers/on-chain-quote-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ export class OnChainQuoteProvider implements IOnChainQuoteProvider {

if (!quoterAddress) {
throw new Error(
`No address for the quoter contract on chain id: ${this.chainId}`
`No address for the quoter contract on chain id: ${this.chainId} ${useMixedRouteQuoter} ${mixedRouteContainsV4Pool} ${protocol}`
);
}
return quoterAddress;
Expand Down
70 changes: 61 additions & 9 deletions src/routers/alpha-router/alpha-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ import {
} from '../router';

import { UniversalRouterVersion } from '@uniswap/universal-router-sdk';
import { DEFAULT_BLOCKS_TO_LIVE } from '../../util/defaultBlocksToLive';
import { INTENT } from '../../util/intent';
import {
DEFAULT_ROUTING_CONFIG_BY_CHAIN,
Expand Down Expand Up @@ -1426,15 +1427,66 @@ export class AlphaRouter
// Fetch CachedRoutes
let cachedRoutes: CachedRoutes | undefined;
if (routingConfig.useCachedRoutes && cacheMode !== CacheMode.Darkmode) {
cachedRoutes = await this.routeCachingProvider?.getCachedRoute(
this.chainId,
amount,
quoteCurrency,
tradeType,
protocols,
await blockNumber,
routingConfig.optimisticCachedRoutes
);
if (
protocols.includes(Protocol.V4) &&
(currencyIn.isNative || currencyOut.isNative)
) {
const [wrappedNativeCachedRoutes, nativeCachedRoutes] =
await Promise.all([
this.routeCachingProvider?.getCachedRoute(
this.chainId,
CurrencyAmount.fromRawAmount(
amount.currency.wrapped,
amount.quotient
),
quoteCurrency.wrapped,
tradeType,
protocols,
await blockNumber,
routingConfig.optimisticCachedRoutes
),
this.routeCachingProvider?.getCachedRoute(
this.chainId,
amount,
quoteCurrency,
tradeType,
[Protocol.V4],
await blockNumber,
routingConfig.optimisticCachedRoutes
),
]);

cachedRoutes = new CachedRoutes({
routes: [
...(nativeCachedRoutes?.routes ?? []),
...(wrappedNativeCachedRoutes?.routes ?? []),
],
chainId: this.chainId,
currencyIn: currencyIn,
currencyOut: currencyOut,
protocolsCovered: protocols,
blockNumber: await blockNumber,
tradeType: tradeType,
originalAmount:
wrappedNativeCachedRoutes?.originalAmount ??
nativeCachedRoutes?.originalAmount ??
amount.quotient.toString(),
blocksToLive:
wrappedNativeCachedRoutes?.blocksToLive ??
nativeCachedRoutes?.blocksToLive ??
DEFAULT_BLOCKS_TO_LIVE[this.chainId],
});
} else {
cachedRoutes = await this.routeCachingProvider?.getCachedRoute(
this.chainId,
amount,
quoteCurrency,
tradeType,
protocols,
await blockNumber,
routingConfig.optimisticCachedRoutes
);
}
}

if (shouldWipeoutCachedRoutes(cachedRoutes, routingConfig)) {
Expand Down
19 changes: 13 additions & 6 deletions src/util/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,19 @@ export const NEW_QUOTER_V2_ADDRESSES: AddressMap = {
export const PROTOCOL_V4_QUOTER_ADDRESSES: AddressMap = {
...constructSameAddressMap('0xf3a39c86dbd13c45365e57fb90fe413371f65af8'),
[ChainId.SEPOLIA]: CHAIN_TO_ADDRESSES_MAP[ChainId.SEPOLIA].v4QuoterAddress,
[ChainId.ARBITRUM_ONE]: CHAIN_TO_ADDRESSES_MAP[ChainId.ARBITRUM_ONE].v4QuoterAddress,
[ChainId.ARBITRUM_ONE]:
CHAIN_TO_ADDRESSES_MAP[ChainId.ARBITRUM_ONE].v4QuoterAddress,
[ChainId.BASE]: CHAIN_TO_ADDRESSES_MAP[ChainId.BASE].v4QuoterAddress,
[ChainId.POLYGON]: CHAIN_TO_ADDRESSES_MAP[ChainId.POLYGON].v4QuoterAddress,
[ChainId.BNB]: CHAIN_TO_ADDRESSES_MAP[ChainId.BNB].v4QuoterAddress,
[ChainId.AVALANCHE]: CHAIN_TO_ADDRESSES_MAP[ChainId.AVALANCHE].v4QuoterAddress,
[ChainId.AVALANCHE]:
CHAIN_TO_ADDRESSES_MAP[ChainId.AVALANCHE].v4QuoterAddress,
[ChainId.OPTIMISM]: CHAIN_TO_ADDRESSES_MAP[ChainId.OPTIMISM].v4QuoterAddress,
[ChainId.WORLDCHAIN]: CHAIN_TO_ADDRESSES_MAP[ChainId.WORLDCHAIN].v4QuoterAddress,
[ChainId.WORLDCHAIN]:
CHAIN_TO_ADDRESSES_MAP[ChainId.WORLDCHAIN].v4QuoterAddress,
[ChainId.ZORA]: CHAIN_TO_ADDRESSES_MAP[ChainId.ZORA].v4QuoterAddress,
[ChainId.UNICHAIN_SEPOLIA]: CHAIN_TO_ADDRESSES_MAP[ChainId.UNICHAIN_SEPOLIA].v4QuoterAddress,
[ChainId.UNICHAIN_SEPOLIA]:
CHAIN_TO_ADDRESSES_MAP[ChainId.UNICHAIN_SEPOLIA].v4QuoterAddress,
[ChainId.UNICHAIN]: CHAIN_TO_ADDRESSES_MAP[ChainId.UNICHAIN].v4QuoterAddress,
[ChainId.BLAST]: CHAIN_TO_ADDRESSES_MAP[ChainId.BLAST].v4QuoterAddress,
[ChainId.MAINNET]: CHAIN_TO_ADDRESSES_MAP[ChainId.MAINNET].v4QuoterAddress,
Expand All @@ -142,6 +146,7 @@ export const MIXED_ROUTE_QUOTER_V1_ADDRESSES: AddressMap = {
export const MIXED_ROUTE_QUOTER_V2_ADDRESSES: AddressMap = {
[ChainId.SEPOLIA]:
CHAIN_TO_ADDRESSES_MAP[ChainId.SEPOLIA].mixedRouteQuoterV2Address,
[ChainId.MAINNET]: '0xE63C5F5005909E96b5aA9CE10744CCE70eC16CC3',
};

export const UNISWAP_MULTICALL_ADDRESSES: AddressMap = {
Expand Down Expand Up @@ -189,15 +194,17 @@ export const SWAP_ROUTER_02_ADDRESSES = (chainId: number): string => {
export const STATE_VIEW_ADDRESSES: AddressMap = {
...constructSameAddressMap('0x1F98415757620B543A52E61c46B32eB19261F984'),
[ChainId.SEPOLIA]: CHAIN_TO_ADDRESSES_MAP[ChainId.SEPOLIA].v4StateView,
[ChainId.ARBITRUM_ONE]: CHAIN_TO_ADDRESSES_MAP[ChainId.ARBITRUM_ONE].v4StateView,
[ChainId.ARBITRUM_ONE]:
CHAIN_TO_ADDRESSES_MAP[ChainId.ARBITRUM_ONE].v4StateView,
[ChainId.BASE]: CHAIN_TO_ADDRESSES_MAP[ChainId.BASE].v4StateView,
[ChainId.POLYGON]: CHAIN_TO_ADDRESSES_MAP[ChainId.POLYGON].v4StateView,
[ChainId.BNB]: CHAIN_TO_ADDRESSES_MAP[ChainId.BNB].v4StateView,
[ChainId.OPTIMISM]: CHAIN_TO_ADDRESSES_MAP[ChainId.OPTIMISM].v4StateView,
[ChainId.AVALANCHE]: CHAIN_TO_ADDRESSES_MAP[ChainId.AVALANCHE].v4StateView,
[ChainId.WORLDCHAIN]: CHAIN_TO_ADDRESSES_MAP[ChainId.WORLDCHAIN].v4StateView,
[ChainId.ZORA]: CHAIN_TO_ADDRESSES_MAP[ChainId.ZORA].v4StateView,
[ChainId.UNICHAIN_SEPOLIA]: CHAIN_TO_ADDRESSES_MAP[ChainId.UNICHAIN_SEPOLIA].v4StateView,
[ChainId.UNICHAIN_SEPOLIA]:
CHAIN_TO_ADDRESSES_MAP[ChainId.UNICHAIN_SEPOLIA].v4StateView,
[ChainId.UNICHAIN]: CHAIN_TO_ADDRESSES_MAP[ChainId.UNICHAIN].v4StateView,
[ChainId.BLAST]: CHAIN_TO_ADDRESSES_MAP[ChainId.BLAST].v4StateView,
[ChainId.MAINNET]: CHAIN_TO_ADDRESSES_MAP[ChainId.MAINNET].v4StateView,
Expand Down
48 changes: 48 additions & 0 deletions src/util/defaultBlocksToLive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { ChainId } from '@uniswap/sdk-core';

export const DEFAULT_BLOCKS_TO_LIVE: { [chain in ChainId]: number } = {
// (60 minutes) / (12 seconds)= 300
[ChainId.MAINNET]: 300,
[ChainId.GOERLI]: 300,
[ChainId.SEPOLIA]: 300,
// (60 minutes) / (2 seconds) = 1800
[ChainId.OPTIMISM]: 1800,
[ChainId.OPTIMISM_GOERLI]: 1800,
[ChainId.OPTIMISM_SEPOLIA]: 1800,
[ChainId.BASE]: 1800,
[ChainId.ZORA]: 1800,
[ChainId.BASE_GOERLI]: 1800,
[ChainId.BASE_SEPOLIA]: 1800,
[ChainId.ZORA_SEPOLIA]: 1800,
[ChainId.BLAST]: 1800,
// Note: Experiment with longer TTL
// (12 hours) / (2 seconds) = 21600
[ChainId.WORLDCHAIN]: 21600,
// (60 minutes) / (1 seconds) = 3600
[ChainId.UNICHAIN_SEPOLIA]: 3600,
[ChainId.UNICHAIN]: 3600,
[ChainId.MONAD_TESTNET]: 3600,
// (60 minutes) / (250 milliseconds) = 14400
[ChainId.ARBITRUM_ONE]: 14400,
[ChainId.ARBITRUM_GOERLI]: 14400,
[ChainId.ARBITRUM_SEPOLIA]: 14400,
// (60 minutes) / (2 seconds) = 1800
[ChainId.POLYGON]: 1800,
[ChainId.POLYGON_MUMBAI]: 1800,
// (60 minutes) / (5 seconds) = 720
[ChainId.CELO]: 720,
[ChainId.CELO_ALFAJORES]: 720,
// (60 minutes) / (5 seconds) = 720
[ChainId.GNOSIS]: 720,
// (60 minutes) / (6 seconds) = 600
[ChainId.MOONBEAM]: 600,
// (60 minutes) / (3 seconds) = 1200
[ChainId.BNB]: 1200,
// (60 minutes) / (3 seconds) = 1200
[ChainId.AVALANCHE]: 1200,
// (60 minutes) / (33 seconds) = 148
[ChainId.ROOTSTOCK]: 148,
// (60 minutes) / (1 seconds) = 3600
[ChainId.ZKSYNC]: 3600,
[ChainId.MONAD_TESTNET]: 3600,
};

0 comments on commit 55be8bb

Please sign in to comment.