Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

Commit

Permalink
factory address is conditional based on the chain ID
Browse files Browse the repository at this point in the history
  • Loading branch information
passabilities committed Nov 3, 2023
1 parent 81d6609 commit 1065bb8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
export const FACTORY_ADDRESS = '0x1F98431c8aD98523631AE4a59f267346ea31F984'

export const getChainFactoryAddress = (chainId?: number) => {
switch (chainId) {
case 8453:
return '0x33128a8fC17869897dcE68Ed026d694621f6FDfD'
case 11155111:
return '0x0227628f3F023bb0B980b67D528571c95c6DaC1c'
default:
return FACTORY_ADDRESS
}
}

export const ADDRESS_ZERO = '0x0000000000000000000000000000000000000000'

export const POOL_INIT_CODE_HASH = '0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54'
Expand Down
9 changes: 6 additions & 3 deletions src/entities/pool.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BigintIsh, CurrencyAmount, Price, Token } from '@uniswap/sdk-core'
import JSBI from 'jsbi'
import invariant from 'tiny-invariant'
import { FACTORY_ADDRESS, FeeAmount, TICK_SPACINGS } from '../constants'
import { FeeAmount, getChainFactoryAddress, TICK_SPACINGS } from '../constants'
import { NEGATIVE_ONE, ONE, Q192, ZERO } from '../internalConstants'
import { computePoolAddress } from '../utils/computePoolAddress'
import { LiquidityMath } from '../utils/liquidityMath'
Expand Down Expand Up @@ -46,10 +46,13 @@ export class Pool {
tokenB: Token,
fee: FeeAmount,
initCodeHashManualOverride?: string,
factoryAddressOverride?: string
chainIdOrFactoryAddressOverride?: number | string
): string {
const factoryAddress = typeof chainIdOrFactoryAddressOverride === 'string'
? chainIdOrFactoryAddressOverride
: getChainFactoryAddress(chainIdOrFactoryAddressOverride)
return computePoolAddress({
factoryAddress: factoryAddressOverride ?? FACTORY_ADDRESS,
factoryAddress: factoryAddress,
fee,
tokenA,
tokenB,
Expand Down

0 comments on commit 1065bb8

Please sign in to comment.