Skip to content

Commit

Permalink
merge main/resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
xrsv committed Dec 18, 2024
2 parents e66623e + e44eb79 commit a0926b6
Show file tree
Hide file tree
Showing 14 changed files with 122 additions and 19 deletions.
2 changes: 1 addition & 1 deletion bin/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ export class RoutingAPIPipeline extends Stack {
'echo "ARCHIVE_NODE_RPC=${ARCHIVE_NODE_RPC}" >> .env',
'npm install',
'npm run build',
'npm run test:e2e',
'set NODE_OPTIONS=--max-old-space-size=4096 && npm run test:e2e',
],
})

Expand Down
2 changes: 1 addition & 1 deletion lib/config/rpcProviderProdConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"useMultiProviderProb": 1,
"latencyEvaluationSampleProb": 0,
"healthCheckSampleProb": 0,
"providerInitialWeights": [0.7, 0.3],
"providerInitialWeights": [0.75, 0.25],
"providerUrls": ["QUICKNODE_8453", "UNIRPC_0"],
"providerNames": ["QUICKNODE", "UNIRPC"]
},
Expand Down
2 changes: 2 additions & 0 deletions lib/graphql/token-fee-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ export class TokenFeeUtils {
'0xa4bb712b4ea05e74a9590ec550bd922cd857afcb',
'0xf2c5780e2dda407781c0c5eccc9320d5988ea0a6',
'0xa00453052a36d43a99ac1ca145dfe4a952ca33b8',
'0x42fa14d6e4642b3789d8b0272534a41d415663a9',
'0x89b69f2d1adffa9a253d40840b6baa7fc903d697',
])

static isDynamicFOT(address: string): boolean {
Expand Down
11 changes: 10 additions & 1 deletion lib/handlers/injector-sor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,16 @@ export abstract class InjectorSOR<Router, QueryParams> extends Injector<
// The timeout for the underlying axios call to Tenderly, measured in milliseconds.
2.5 * 1000,
TENDERLY_NEW_ENDPOINT_ROLLOUT_PERCENT[chainId],
[ChainId.MAINNET, ChainId.BASE]
[
ChainId.MAINNET,
ChainId.BASE,
ChainId.ARBITRUM_ONE,
ChainId.OPTIMISM,
ChainId.POLYGON,
ChainId.AVALANCHE,
ChainId.BLAST,
ChainId.WORLDCHAIN,
]
)

const ethEstimateGasSimulator = new EthEstimateGasSimulator(
Expand Down
3 changes: 3 additions & 0 deletions lib/handlers/quote/quote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,9 @@ export class QuoteHandler extends APIGLambdaHandler<
} else if (simulationStatus == SimulationStatus.SystemDown) {
metric.putMetric('SimulationSystemDown', 1, MetricLoggerUnit.Count)
metric.putMetric(`SimulationSystemDownChainId${chainId}`, 1, MetricLoggerUnit.Count)
} else if (simulationStatus == SimulationStatus.SlippageTooLow) {
metric.putMetric('SlippageTooLow', 1, MetricLoggerUnit.Count)
metric.putMetric(`SlippageTooLowChainId${chainId}`, 1, MetricLoggerUnit.Count)
}

const routeResponse: Array<SupportedPoolInRoute[]> = []
Expand Down
3 changes: 3 additions & 0 deletions lib/handlers/quote/util/simulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export enum RoutingApiSimulationStatus {
NOT_SUPPORTED = 'NOT_SUPPORTED',
NOT_APPROVED = 'NOT_APPROVED',
SYSTEM_DOWN = 'SYSTEM_DOWN',
SLIPPAGE_TOO_LOW = 'SLIPPAGE_TOO_LOW',
UNKNOWN = '',
}

Expand All @@ -31,6 +32,8 @@ export const simulationStatusTranslation = (
return RoutingApiSimulationStatus.NOT_APPROVED
case SimulationStatus.SystemDown:
return RoutingApiSimulationStatus.SYSTEM_DOWN
case SimulationStatus.SlippageTooLow:
return RoutingApiSimulationStatus.SLIPPAGE_TOO_LOW
default:
log.error(`Unknown simulation status ${simulationStatus}`)
return RoutingApiSimulationStatus.UNKNOWN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,50 @@ export class DynamoRouteCachingProvider extends IRouteCachingProvider {
let blockNumber: number = 0
let originalAmount: string = ''

// Log metrics how often we might be using expired cached routes when we shouldn't.
// Plan to fix this by filtering below, but for now we want to know how often this happens and where.
const numberOfExpiredCachedRoutes = cachedRoutesArr.filter(
(cachedRoutes) => !cachedRoutes.notExpired(currentBlockNumber, optimistic)
).length
const numberOfNotExpiredCachedRoutes = cachedRoutesArr.length - numberOfExpiredCachedRoutes
if (numberOfExpiredCachedRoutes > 0 && numberOfNotExpiredCachedRoutes > 0) {
metric.putMetric(`RoutesDbArrayWithMixedExpiredCachedRoutes_Opt_${optimistic}`, 1, MetricLoggerUnit.Count)
metric.putMetric(
`RoutesDbArrayWithMixedExpiredCachedRoutes_${ID_TO_NETWORK_NAME(chainId)}_Opt_${optimistic}`,
1,
MetricLoggerUnit.Count
)
// log number of expired cached routes
metric.putMetric(
`RoutesDbArrayWithMixedExpiredCachedRoutesCount_Opt_${optimistic}`,
numberOfExpiredCachedRoutes,
MetricLoggerUnit.Count
)
metric.putMetric(
`RoutesDbArrayWithMixedExpiredCachedRoutesCount_${ID_TO_NETWORK_NAME(chainId)}_Opt_${optimistic}`,
numberOfExpiredCachedRoutes,
MetricLoggerUnit.Count
)
// and total
metric.putMetric(
`RoutesDbArrayWithMixedExpiredCachedRoutesTotal_Opt_${optimistic}`,
cachedRoutesArr.length,
MetricLoggerUnit.Count
)
metric.putMetric(
`RoutesDbArrayWithMixedExpiredCachedRoutesTotal_${ID_TO_NETWORK_NAME(chainId)}_Opt_${optimistic}`,
cachedRoutesArr.length,
MetricLoggerUnit.Count
)
} else {
metric.putMetric(`RoutesDbArrayWithoutMixedExpiredCachedRoutes_Opt_${optimistic}`, 1, MetricLoggerUnit.Count)
metric.putMetric(
`RoutesDbArrayWithoutMixedExpiredCachedRoutes_${ID_TO_NETWORK_NAME(chainId)}_Opt_${optimistic}`,
1,
MetricLoggerUnit.Count
)
}

cachedRoutesArr.forEach((cachedRoutes) => {
metric.putMetric(`RoutesDbPerBlockFound`, cachedRoutes.routes.length, MetricLoggerUnit.Count)
cachedRoutes.routes.forEach((cachedRoute) => {
Expand Down
31 changes: 31 additions & 0 deletions lib/handlers/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,37 @@ export const DEFAULT_ROUTING_CONFIG_BY_CHAIN = (chainId: ChainId): AlphaRouterCo
forceCrossProtocol: false,
}
case ChainId.BASE:
return {
v2PoolSelection: {
topN: 3,
topNDirectSwaps: 1,
topNTokenInOut: 5,
topNSecondHop: 2,
topNWithEachBaseToken: 2,
topNWithBaseToken: 6,
},
v3PoolSelection: {
topN: 2,
topNDirectSwaps: 2,
topNTokenInOut: 2,
topNSecondHop: 1,
topNWithEachBaseToken: 3,
topNWithBaseToken: 3,
},
v4PoolSelection: {
topN: 2,
topNDirectSwaps: 2,
topNTokenInOut: 2,
topNSecondHop: 1,
topNWithEachBaseToken: 3,
topNWithBaseToken: 3,
},
maxSwapsPerPath: 3,
minSplits: 1,
maxSplits: 3,
distributionPercent: 20,
forceCrossProtocol: false,
}
case ChainId.OPTIMISM:
case ChainId.WORLDCHAIN:
case ChainId.UNICHAIN_SEPOLIA:
Expand Down
6 changes: 6 additions & 0 deletions lib/util/gasLimit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ export const CELO_UPPER_SWAP_GAS_LIMIT = BigNumber.from(5000000)
export const WORLDCHAIN_UPPER_SWAP_GAS_LIMIT = BigNumber.from(300000)
// https://github.com/Uniswap/routing-api/blob/fe410751985995cb2904837e24f22da7dca1f518/lib/util/onChainQuoteProviderConfigs.ts#L344 divivde by 10
export const UNICHAIN_SEPOLIA_UPPER_SWAP_GAS_LIMIT = BigNumber.from(300000)
// https://github.com/Uniswap/smart-order-router/blob/c77d04d334cc1c6694bd74d88287cc5b6e3a7425/src/util/onchainQuoteProviderConfigs.ts#L83 divide by 10
export const BNB_UPPER_SWAP_GAS_LIMIT = BigNumber.from(200000)
// https://github.com/Uniswap/smart-order-router/blob/c77d04d334cc1c6694bd74d88287cc5b6e3a7425/src/util/onchainQuoteProviderConfigs.ts#L83 divide by 10
export const ZORA_UPPER_SWAP_GAS_LIMIT = BigNumber.from(200000)

export const CHAIN_TO_GAS_LIMIT_MAP: { [chainId: number]: BigNumber } = {
[ChainId.ZKSYNC]: ZKSYNC_UPPER_SWAP_GAS_LIMIT,
[ChainId.CELO]: CELO_UPPER_SWAP_GAS_LIMIT,
[ChainId.CELO_ALFAJORES]: CELO_UPPER_SWAP_GAS_LIMIT,
[ChainId.UNICHAIN_SEPOLIA]: UNICHAIN_SEPOLIA_UPPER_SWAP_GAS_LIMIT,
[ChainId.BNB]: BNB_UPPER_SWAP_GAS_LIMIT,
[ChainId.ZORA]: ZORA_UPPER_SWAP_GAS_LIMIT,
}
12 changes: 6 additions & 6 deletions lib/util/tenderlyNewEndpointRolloutPercent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@ export const TENDERLY_NEW_ENDPOINT_ROLLOUT_PERCENT: { [chain in ChainId]: number
[ChainId.MAINNET]: 100,
[ChainId.GOERLI]: 0,
[ChainId.SEPOLIA]: 0,
[ChainId.OPTIMISM]: 0,
[ChainId.OPTIMISM]: 100,
[ChainId.OPTIMISM_GOERLI]: 0,
[ChainId.OPTIMISM_SEPOLIA]: 0,
[ChainId.ARBITRUM_ONE]: 0,
[ChainId.ARBITRUM_ONE]: 100,
[ChainId.ARBITRUM_GOERLI]: 0,
[ChainId.ARBITRUM_SEPOLIA]: 0,
[ChainId.POLYGON]: 0,
[ChainId.POLYGON]: 100,
[ChainId.POLYGON_MUMBAI]: 0,
[ChainId.CELO]: 0,
[ChainId.CELO_ALFAJORES]: 0,
[ChainId.GNOSIS]: 0,
[ChainId.MOONBEAM]: 0,
[ChainId.BNB]: 0,
[ChainId.AVALANCHE]: 0,
[ChainId.AVALANCHE]: 100,
[ChainId.BASE_GOERLI]: 0,
[ChainId.BASE]: 100,
[ChainId.ZORA]: 0,
[ChainId.ZORA_SEPOLIA]: 0,
[ChainId.ROOTSTOCK]: 0,
[ChainId.BLAST]: 0,
[ChainId.BLAST]: 100,
[ChainId.ZKSYNC]: 0,
[ChainId.WORLDCHAIN]: 0,
[ChainId.WORLDCHAIN]: 100,
[ChainId.UNICHAIN]: 0,
[ChainId.UNICHAIN_SEPOLIA]: 0,
}
12 changes: 6 additions & 6 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
Expand Up @@ -88,7 +88,7 @@
"@uniswap/permit2-sdk": "^1.3.0",
"@uniswap/router-sdk": "^1.15.0",
"@uniswap/sdk-core": "^6.0.0",
"@uniswap/smart-order-router": "file:/tmp/uniswap-smart-order-router-4.8.3.tgz",
"@uniswap/smart-order-router": "file:/tmp/uniswap-smart-order-router-4.9.2.tgz",
"@uniswap/token-lists": "^1.0.0-beta.33",
"@uniswap/universal-router-sdk": "^4.7.0",
"@uniswap/v2-sdk": "^4.7.0",
Expand Down
5 changes: 5 additions & 0 deletions test/jest/unit/handlers/util/simulation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ describe('simulation', () => {
const status = simulationStatusTranslation(SimulationStatus.SystemDown, log)
expect(status).toStrictEqual(RoutingApiSimulationStatus.SYSTEM_DOWN)
})

it('returns slippage too low for slippage too low simulation status', () => {
const status = simulationStatusTranslation(SimulationStatus.SlippageTooLow, log)
expect(status).toStrictEqual(RoutingApiSimulationStatus.SLIPPAGE_TOO_LOW)
})
})
6 changes: 3 additions & 3 deletions test/mocha/e2e/quote.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ describe('quote', function () {
: await getAmount(1, type, 'USDC', 'ETH', '100'),
type,
recipient: alice.address,
slippageTolerance: SLIPPAGE,
slippageTolerance: LARGE_SLIPPAGE,
deadline: '360',
algorithm,
enableUniversalRouter: true,
Expand Down Expand Up @@ -701,7 +701,7 @@ describe('quote', function () {
amount,
type,
recipient: alice.address,
slippageTolerance: SLIPPAGE,
slippageTolerance: LARGE_SLIPPAGE,
deadline: '360',
algorithm,
permitSignature: signature,
Expand Down Expand Up @@ -1733,7 +1733,7 @@ describe('quote', function () {
: await getAmount(1, type, 'USDC', 'ETH', '100'),
type,
recipient: alice.address,
slippageTolerance: SLIPPAGE,
slippageTolerance: LARGE_SLIPPAGE,
deadline: '360',
algorithm,
simulateFromAddress: '0xf584f8728b874a6a5c7a8d4d387c9aae9172d621',
Expand Down

0 comments on commit a0926b6

Please sign in to comment.