Skip to content

Fix mineHookAddress method for non-ETH numeraire support#12

Open
Segfaultd wants to merge 2 commits intowhetstoneresearch:mainfrom
Segfaultd:hotfix/mine-hook-address-non-eth-numeraire
Open

Fix mineHookAddress method for non-ETH numeraire support#12
Segfaultd wants to merge 2 commits intowhetstoneresearch:mainfrom
Segfaultd:hotfix/mine-hook-address-non-eth-numeraire

Conversation

@Segfaultd
Copy link
Contributor

Problem

The mineHookAddress method in DopplerFactory.ts only worked correctly with ETH (0x0000...) as numeraire but failed
with ERC20 tokens as numeraire due to incorrect token ordering logic.

Solution

  • Replaced simple zero-address check with proper BigInt address comparison
  • Implemented numeraireBigInt < tokenBigInt logic for correct token0/token1 ordering
  • Ensures proper Uniswap V4 pool creation regardless of numeraire type

Changes

  • src/entities/DopplerFactory.ts: Fixed mineHookAddress method token ordering logic
  • src/tests/entities/DopplerFactory.test.ts: Added comprehensive tests for both ETH and ERC20 numeraire scenarios

Before

const isToken0 = params.numeraire !== zeroAddress

After

  const numeraireBigInt = BigInt(params.numeraire)
  const halfMaxUint256 = (2n ** 255n) - 1n

  let isToken0: boolean
  if (numeraireBigInt === 0n) {
    isToken0 = false
  } else if (numeraireBigInt > halfMaxUint256) {
    isToken0 = true
  } else {
    isToken0 = false
  }

  // In mining loop: use numeraireBigInt < tokenBigInt for comparison

Testing

  • Added test that exercises actual mining logic via encodeCreateDynamicAuctionParams
  • Verifies different hook addresses generated for ETH vs ERC20 numeraire
  • All existing tests continue to pass (16/16)

References

Backports fix from previous SDK version PR #142

@Cooper-Kunz Cooper-Kunz requested a review from z80dev September 29, 2025 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants