Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
20 changes: 15 additions & 5 deletions lib/util/v4HooksPoolsFiltering.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { log, V4SubgraphPool } from '@uniswap/smart-order-router'
import { isPoolFeeDynamic, log, nativeOnChain, V4SubgraphPool } from '@uniswap/smart-order-router'
import { Hook } from '@uniswap/v4-sdk'
import { HOOKS_ADDRESSES_ALLOWLIST } from './hooksAddressesAllowlist'
import { ChainId } from '@uniswap/sdk-core'
import { ChainId, Currency, Token } from '@uniswap/sdk-core'
import { PriorityQueue } from '@datastructures-js/priority-queue'
import { BUNNI_POOLS_CONFIG } from './bunni-pools'
import { ADDRESS_ZERO } from '@uniswap/router-sdk'

type V4PoolGroupingKey = string
const TOP_GROUPED_V4_POOLS = 10
Expand All @@ -12,15 +13,24 @@ function convertV4PoolToGroupingKey(pool: V4SubgraphPool): V4PoolGroupingKey {
return pool.token0.id.concat(pool.token1.id).concat(pool.feeTier)
}

function isHooksPoolRoutable(pool: V4SubgraphPool): boolean {
function isHooksPoolRoutable(pool: V4SubgraphPool, chainId: ChainId): boolean {
const tokenA: Currency =
pool.token0.id === ADDRESS_ZERO
? nativeOnChain(chainId)
: new Token(chainId, pool.token0.id, pool.token0.decimals, pool.token0.symbol, pool.token0.name)
const tokenB: Currency =
pool.token1.id === ADDRESS_ZERO
? nativeOnChain(chainId)
: new Token(chainId, pool.token1.id, pool.token1.decimals, pool.token1.symbol, pool.token1.name)

return (
!Hook.hasSwapPermissions(pool.hooks) &&
// If the fee tier is smaller than or equal to 100%, it means the pool is not dynamic fee pool.
// Swap fee in total can be 100% (https://github.com/Uniswap/v4-core/blob/b619b6718e31aa5b4fa0286520c455ceb950276d/src/libraries/SwapMath.sol#L12)
// Dynamic fee is at 0x800000 or 838.8608% fee tier.
// Since pool manager doesn;t check the fee at 100% max during pool initialization (https://github.com/Uniswap/v4-core/blob/main/src/PoolManager.sol#L128)
// it's more defensive programming to ensure the fee tier is less than or equal to 100%
Number(pool.feeTier) <= 1000000
!isPoolFeeDynamic(tokenA, tokenB, pool)
)
}

Expand All @@ -33,7 +43,7 @@ export function v4HooksPoolsFiltering(chainId: ChainId, pools: Array<V4SubgraphP
const v4PoolsByTokenPairsAndFees: Record<V4PoolGroupingKey, PriorityQueue<V4SubgraphPool>> = {}

pools.forEach((pool: V4SubgraphPool) => {
if (isHooksPoolRoutable(pool)) {
if (isHooksPoolRoutable(pool, chainId)) {
const v4Pools =
v4PoolsByTokenPairsAndFees[convertV4PoolToGroupingKey(pool)] ??
new PriorityQueue<V4SubgraphPool>(V4SubgraphPoolComparator)
Expand Down
14 changes: 7 additions & 7 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": "^2.0.2",
"@uniswap/sdk-core": "^7.7.1",
"@uniswap/smart-order-router": "4.22.15",
"@uniswap/smart-order-router": "4.22.16",
"@uniswap/smart-wallet-sdk": "^2.1.1",
"@uniswap/token-lists": "^1.0.0-beta.33",
"@uniswap/universal-router-sdk": "^4.19.7",
Expand Down
Loading
Loading