Commit b64cd760 authored by Miguel Cervera's avatar Miguel Cervera Committed by GitHub

Use default FACTORY_ADDRESS if the chain is not in the map (#160)

* Use default FACTORY_ADDRESS if the chain is not in the map

* Fix code style issues with Prettier

* test

* conflict

* Fix code style issues with Prettier

---------
Co-authored-by: default avatarLint Action <lint-action@samuelmeuli.com>
parent e1b062d2
import { BigNumber } from '@ethersproject/bignumber'
import { ChainId, CurrencyAmount, Price, Token, WETH9 } from '@uniswap/sdk-core' import { ChainId, CurrencyAmount, Price, Token, WETH9 } from '@uniswap/sdk-core'
import { FACTORY_ADDRESS } from '../constants'
import { InsufficientInputAmountError } from '../errors' import { InsufficientInputAmountError } from '../errors'
import { computePairAddress, Pair } from './pair' import { computePairAddress, Pair } from './pair'
import { BigNumber } from '@ethersproject/bignumber'
describe('computePairAddress', () => { describe('computePairAddress', () => {
it('should correctly compute the pool address', () => { it('should correctly compute the pool address', () => {
...@@ -42,6 +43,9 @@ describe('Pair', () => { ...@@ -42,6 +43,9 @@ describe('Pair', () => {
const USDC = new Token(1, '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 18, 'USDC', 'USD Coin') const USDC = new Token(1, '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 18, 'USDC', 'USD Coin')
const DAI = new Token(1, '0x6B175474E89094C44Da98b954EedeAC495271d0F', 18, 'DAI', 'DAI Stablecoin') const DAI = new Token(1, '0x6B175474E89094C44Da98b954EedeAC495271d0F', 18, 'DAI', 'DAI Stablecoin')
const USDC_SEPOLIA = new Token(11155111, '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 18, 'USDC', 'USD Coin')
const DAI_SEPOLIA = new Token(11155111, '0x6B175474E89094C44Da98b954EedeAC495271d0F', 18, 'DAI', 'DAI Stablecoin')
describe('constructor', () => { describe('constructor', () => {
it('cannot be used for tokens on different chains', () => { it('cannot be used for tokens on different chains', () => {
expect( expect(
...@@ -54,6 +58,10 @@ describe('Pair', () => { ...@@ -54,6 +58,10 @@ describe('Pair', () => {
it('returns the correct address', () => { it('returns the correct address', () => {
expect(Pair.getAddress(USDC, DAI)).toEqual('0xAE461cA67B15dc8dc81CE7615e0320dA1A9aB8D5') expect(Pair.getAddress(USDC, DAI)).toEqual('0xAE461cA67B15dc8dc81CE7615e0320dA1A9aB8D5')
}) })
it('returns the default address for a testnet not in the map', () => {
expect(Pair.getAddress(USDC_SEPOLIA, DAI_SEPOLIA)).toEqual(FACTORY_ADDRESS)
})
}) })
describe('#token0', () => { describe('#token0', () => {
......
import { BigintIsh, Price, sqrt, Token, CurrencyAmount, Percent } from '@uniswap/sdk-core'
import invariant from 'tiny-invariant'
import JSBI from 'jsbi'
import { pack, keccak256 } from '@ethersproject/solidity'
import { getCreate2Address } from '@ethersproject/address' import { getCreate2Address } from '@ethersproject/address'
import { BigNumber } from '@ethersproject/bignumber' import { BigNumber } from '@ethersproject/bignumber'
import { keccak256, pack } from '@ethersproject/solidity'
import { BigintIsh, CurrencyAmount, Percent, Price, sqrt, Token } from '@uniswap/sdk-core'
import JSBI from 'jsbi'
import invariant from 'tiny-invariant'
import { import {
_1000,
_997,
BASIS_POINTS,
FACTORY_ADDRESS,
FACTORY_ADDRESS_MAP, FACTORY_ADDRESS_MAP,
FIVE,
INIT_CODE_HASH, INIT_CODE_HASH,
MINIMUM_LIQUIDITY, MINIMUM_LIQUIDITY,
FIVE,
_997,
_1000,
ONE, ONE,
ZERO,
BASIS_POINTS,
ONE_HUNDRED_PERCENT, ONE_HUNDRED_PERCENT,
ZERO,
ZERO_PERCENT ZERO_PERCENT
} from '../constants' } from '../constants'
import { InsufficientReservesError, InsufficientInputAmountError } from '../errors' import { InsufficientInputAmountError, InsufficientReservesError } from '../errors'
export const computePairAddress = ({ export const computePairAddress = ({
factoryAddress, factoryAddress,
...@@ -41,7 +42,8 @@ export class Pair { ...@@ -41,7 +42,8 @@ export class Pair {
private readonly tokenAmounts: [CurrencyAmount<Token>, CurrencyAmount<Token>] private readonly tokenAmounts: [CurrencyAmount<Token>, CurrencyAmount<Token>]
public static getAddress(tokenA: Token, tokenB: Token): string { public static getAddress(tokenA: Token, tokenB: Token): string {
return computePairAddress({ factoryAddress: FACTORY_ADDRESS_MAP[tokenA.chainId], tokenA, tokenB }) const factoryAddress = FACTORY_ADDRESS_MAP[tokenA.chainId] ?? FACTORY_ADDRESS
return computePairAddress({ factoryAddress, tokenA, tokenB })
} }
public constructor(currencyAmountA: CurrencyAmount<Token>, tokenAmountB: CurrencyAmount<Token>) { public constructor(currencyAmountA: CurrencyAmount<Token>, tokenAmountB: CurrencyAmount<Token>) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment