Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: js-only project support #29

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions jest.config.js → jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ module.exports = {
'src/(.*)': '<rootDir>/src/$1',
// for esm modules in ts-jest
'^(\\.{1,2}/.*)\\.js$': '$1',
// for .js imports
'(.+)\\.js$': ['$1.js', '$1'],
},
extensionsToTreatAsEsm: ['.ts'],
}
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"publishConfig": {
"access": "public"
},
"version": "4.0.2",
"version": "4.0.3",
"description": "⚒️ An SDK for building applications on top of Uniswap V3",
koraykoska marked this conversation as resolved.
Show resolved Hide resolved
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand All @@ -25,7 +25,7 @@
"ethers": "^5.7.2",
"@ethersproject/abi": "^5.0.12",
"@ethersproject/solidity": "^5.0.9",
"@uniswap/sdk-core": "npm:@uniswapfoundation/sdk-core@^5.0.0",
"@uniswap/sdk-core": "npm:@uniswapfoundation/sdk-core@^5.0.1",
"@uniswap/swap-router-contracts": "^1.2.1",
"@uniswap/v3-periphery": "^1.1.1",
"@uniswap/v3-staker": "1.0.2",
Expand All @@ -50,5 +50,6 @@
"printWidth": 120,
"semi": false,
"singleQuote": true
}
},
"type": "module"
}
14 changes: 7 additions & 7 deletions src/entities/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './pool'
export * from './position'
export * from './route'
export * from './tick'
export * from './trade'
export * from './tickDataProvider'
export * from './tickListDataProvider'
export * from './pool.js'
export * from './position.js'
export * from './route.js'
export * from './tick.js'
export * from './trade.js'
export * from './tickDataProvider.js'
export * from './tickListDataProvider.js'
22 changes: 11 additions & 11 deletions src/entities/pool.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { BigintIsh, CurrencyAmount, Price, Token, V3_CORE_FACTORY_ADDRESSES } from '@uniswap/sdk-core'
import JSBI from 'jsbi'
import invariant from 'tiny-invariant'
import { FACTORY_ADDRESS, FeeAmount, TICK_SPACINGS } from '../constants'
import { Q192_BIGINT } from '../internalConstants'
import { computePoolAddress } from '../utils/computePoolAddress'
import { LiquidityMath } from '../utils/liquidityMath'
import { SwapMath } from '../utils/swapMath'
import { TickMath } from '../utils/tickMath'
import { Tick, TickConstructorArgs } from './tick'
import { NoTickDataProvider, TickDataProvider } from './tickDataProvider'
import { TickListDataProvider } from './tickListDataProvider'
import { bigIntFromBigintIsh } from '../utils/bigintIsh'
import { FACTORY_ADDRESS, FeeAmount, TICK_SPACINGS } from '../constants.js'
import { Q192_BIGINT } from '../internalConstants.js'
import { computePoolAddress } from '../utils/computePoolAddress.js'
import { LiquidityMath } from '../utils/liquidityMath.js'
import { SwapMath } from '../utils/swapMath.js'
import { TickMath } from '../utils/tickMath.js'
import { Tick, TickConstructorArgs } from './tick.js'
import { NoTickDataProvider, TickDataProvider } from './tickDataProvider.js'
import { TickListDataProvider } from './tickListDataProvider.js'
import { bigIntFromBigintIsh } from '../utils/bigintIsh.js'
import { ethers } from 'ethers'
import { RPCTickDataProvider } from './rpcTickDataProvider'
import { RPCTickDataProvider } from './rpcTickDataProvider.js'
import poolAbi from '@uniswap/v3-core/artifacts/contracts/UniswapV3Pool.sol/UniswapV3Pool.json'
import factoryAbi from '@uniswap/v3-core/artifacts/contracts/UniswapV3Factory.sol/UniswapV3Factory.json'

Expand Down
20 changes: 10 additions & 10 deletions src/entities/position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ import {
} from '@uniswap/sdk-core'
import JSBI from 'jsbi'
import invariant from 'tiny-invariant'
import { ZERO } from '../internalConstants'
import { maxLiquidityForAmounts } from '../utils/maxLiquidityForAmounts'
import { tickToPrice } from '../utils/priceTickConversions'
import { SqrtPriceMath } from '../utils/sqrtPriceMath'
import { TickMath } from '../utils/tickMath'
import { encodeSqrtRatioX96BigInt } from '../utils/encodeSqrtRatioX96'
import { Pool, TransactionOverrides } from './pool'
import { ZERO } from '../internalConstants.js'
import { maxLiquidityForAmounts } from '../utils/maxLiquidityForAmounts.js'
import { tickToPrice } from '../utils/priceTickConversions.js'
import { SqrtPriceMath } from '../utils/sqrtPriceMath.js'
import { TickMath } from '../utils/tickMath.js'
import { encodeSqrtRatioX96BigInt } from '../utils/encodeSqrtRatioX96.js'
import { Pool, TransactionOverrides } from './pool.js'
import { ethers } from 'ethers'
import INonfungiblePositionManager from '@uniswap/v3-periphery/artifacts/contracts/NonfungiblePositionManager.sol/NonfungiblePositionManager.json'
import { ERC20_ABI } from '../constants'
import { bigIntFromBigintIsh } from '../utils/bigintIsh'
import { ERC20_ABI } from '../constants.js'
import { bigIntFromBigintIsh } from '../utils/bigintIsh.js'
import {
CollectOptions,
IncreaseOptions,
MintOptions,
NonfungiblePositionManager,
RemoveLiquidityOptions,
} from '../nonfungiblePositionManager'
} from '../nonfungiblePositionManager.js'

interface PositionConstructorArgs {
pool: Pool
Expand Down
2 changes: 1 addition & 1 deletion src/entities/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import invariant from 'tiny-invariant'

import { Currency, Price, Token } from '@uniswap/sdk-core'
import { Pool } from './pool'
import { Pool } from './pool.js'

/**
* Represents a list of pools through which a swap can occur
Expand Down
10 changes: 5 additions & 5 deletions src/entities/rpcTickDataProvider.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { BigintIsh } from '@uniswap/sdk-core'
import { TickList } from '../utils/tickList'
import { Tick } from './tick'
import { TickDataProvider } from './tickDataProvider'
import { TickList } from '../utils/tickList.js'
import { Tick } from './tick.js'
import { TickDataProvider } from './tickDataProvider.js'
import { ethers } from 'ethers'
import { TickMath } from '../utils'
import { RPCPool } from '../utils/rpcPool'
import { TickMath } from '../utils/index.js'
import { RPCPool } from '../utils/rpcPool.js'

/**
* A data provider for ticks that is backed by an in-memory array of ticks.
Expand Down
4 changes: 2 additions & 2 deletions src/entities/tick.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import JSBI from 'jsbi'
import invariant from 'tiny-invariant'
import { BigintIsh } from '@uniswap/sdk-core'
import { TickMath } from '../utils'
import { bigIntFromBigintIsh } from '../utils/bigintIsh'
import { TickMath } from '../utils/index.js'
import { bigIntFromBigintIsh } from '../utils/bigintIsh.js'

export interface TickConstructorArgs {
index: number
Expand Down
6 changes: 3 additions & 3 deletions src/entities/tickListDataProvider.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BigintIsh } from '@uniswap/sdk-core'
import { TickList } from '../utils/tickList'
import { Tick, TickConstructorArgs } from './tick'
import { TickDataProvider } from './tickDataProvider'
import { TickList } from '../utils/tickList.js'
import { Tick, TickConstructorArgs } from './tick.js'
import { TickDataProvider } from './tickDataProvider.js'

/**
* A data provider for ticks that is backed by an in-memory array of ticks.
Expand Down
6 changes: 3 additions & 3 deletions src/entities/trade.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Currency, Fraction, Percent, Price, sortedInsert, CurrencyAmount, TradeType, Token } from '@uniswap/sdk-core'
import invariant from 'tiny-invariant'
import { ONE, ZERO } from '../internalConstants'
import { Pool } from './pool'
import { Route } from './route'
import { ONE, ZERO } from '../internalConstants.js'
import { Pool } from './pool.js'
import { Route } from './route.js'

/**
* Trades comparator, an extension of the input output comparator that also considers other dimensions of the trade in ranking them
Expand Down
20 changes: 10 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export * from './entities'
export * from './utils'
export * from './entities/index.js'
export * from './utils/index.js'

export * from './constants'
export * from './multicall'
export * from './nonfungiblePositionManager'
export * from './payments'
export * from './quoter'
export * from './selfPermit'
export * from './staker'
export * from './swapRouter'
export * from './constants.js'
export * from './multicall.js'
export * from './nonfungiblePositionManager.js'
export * from './payments.js'
export * from './quoter.js'
export * from './selfPermit.js'
export * from './staker.js'
export * from './swapRouter.js'
16 changes: 8 additions & 8 deletions src/nonfungiblePositionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import {
NONFUNGIBLE_POSITION_MANAGER_ADDRESSES,
} from '@uniswap/sdk-core'
import invariant from 'tiny-invariant'
import { Position } from './entities/position'
import { MethodParameters, toHex } from './utils/calldata'
import { Position } from './entities/position.js'
import { MethodParameters, toHex } from './utils/calldata.js'
import { Interface } from '@ethersproject/abi'
import INonfungiblePositionManager from '@uniswap/v3-periphery/artifacts/contracts/NonfungiblePositionManager.sol/NonfungiblePositionManager.json'
import { PermitOptions, SelfPermit } from './selfPermit'
import { ADDRESS_ZERO } from './constants'
import { Pool, TransactionOverrides } from './entities'
import { Multicall } from './multicall'
import { Payments } from './payments'
import { PermitOptions, SelfPermit } from './selfPermit.js'
import { ADDRESS_ZERO } from './constants.js'
import { Pool, TransactionOverrides } from './entities/index.js'
import { Multicall } from './multicall.js'
import { Payments } from './payments.js'
import { ethers } from 'ethers'
import { bigIntFromBigintIsh } from './utils/bigintIsh'
import { bigIntFromBigintIsh } from './utils/bigintIsh.js'

const MaxUint128 = `0x${(2n ** 128n - 1n).toString(16)}`

Expand Down
2 changes: 1 addition & 1 deletion src/payments.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Interface } from '@ethersproject/abi'
import IPeripheryPaymentsWithFee from '@uniswap/v3-periphery/artifacts/contracts/interfaces/IPeripheryPaymentsWithFee.sol/IPeripheryPaymentsWithFee.json'
import { BigintIsh, Percent, Token, validateAndParseAddress } from '@uniswap/sdk-core'
import { toHex } from './utils/calldata'
import { toHex } from './utils/calldata.js'

export interface FeeOptions {
/**
Expand Down
6 changes: 3 additions & 3 deletions src/quoter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import {
ChainId,
Token,
} from '@uniswap/sdk-core'
import { encodeRouteToPath, MethodParameters, toHex } from './utils'
import { encodeRouteToPath, MethodParameters, toHex } from './utils/index.js'
import IQuoter from '@uniswap/v3-periphery/artifacts/contracts/lens/Quoter.sol/Quoter.json'
import IQuoterV2 from '@uniswap/swap-router-contracts/artifacts/contracts/lens/QuoterV2.sol/QuoterV2.json'
import { Route } from './entities'
import { Route } from './entities/index.js'
import invariant from 'tiny-invariant'
import { FeeAmount } from './constants'
import { FeeAmount } from './constants.js'

/**
* Optional arguments to send to the quoter.
Expand Down
2 changes: 1 addition & 1 deletion src/selfPermit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BigintIsh, Token } from '@uniswap/sdk-core'
import { Interface } from '@ethersproject/abi'
import ISelfPermit from '@uniswap/v3-periphery/artifacts/contracts/interfaces/ISelfPermit.sol/ISelfPermit.json'
import { toHex } from './utils'
import { toHex } from './utils/index.js'

export interface StandardPermitArguments {
v: 0 | 1 | 27 | 28
Expand Down
6 changes: 3 additions & 3 deletions src/staker.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { BigintIsh, Token, validateAndParseAddress } from '@uniswap/sdk-core'
import { MethodParameters, toHex } from './utils/calldata'
import { MethodParameters, toHex } from './utils/calldata.js'
import { defaultAbiCoder, Interface } from '@ethersproject/abi'
import IUniswapV3Staker from '@uniswap/v3-staker/artifacts/contracts/UniswapV3Staker.sol/UniswapV3Staker.json'
import { Pool } from './entities'
import { Multicall } from './multicall'
import { Pool } from './entities/index.js'
import { Multicall } from './multicall.js'

export type FullWithdrawOptions = ClaimOptions & WithdrawOptions
/**
Expand Down
22 changes: 11 additions & 11 deletions src/swapRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ import {
ChainId,
} from '@uniswap/sdk-core'
import invariant from 'tiny-invariant'
import { BestTradeOptions, Trade } from './entities/trade'
import { ADDRESS_ZERO } from './constants'
import { PermitOptions, SelfPermit } from './selfPermit'
import { approveTokenTransfer, encodeRouteToPath, getAllowance } from './utils'
import { MethodParameters, toHex } from './utils/calldata'
import { BestTradeOptions, Trade } from './entities/trade.js'
import { ADDRESS_ZERO } from './constants.js'
import { PermitOptions, SelfPermit } from './selfPermit.js'
import { approveTokenTransfer, encodeRouteToPath, getAllowance } from './utils/index.js'
import { MethodParameters, toHex } from './utils/calldata.js'
import ISwapRouter from '@uniswap/v3-periphery/artifacts/contracts/SwapRouter.sol/SwapRouter.json'
import { Multicall } from './multicall'
import { FeeOptions, Payments } from './payments'
import { Pool } from './entities/pool'
import { Route } from './entities/route'
import { SwapQuoter } from './quoter'
import { fetchTickDataForAllPoolsInRoute } from './utils/fetchTicksForRoute'
import { Multicall } from './multicall.js'
import { FeeOptions, Payments } from './payments.js'
import { Pool } from './entities/pool.js'
import { Route } from './entities/route.js'
import { SwapQuoter } from './quoter.js'
import { fetchTickDataForAllPoolsInRoute } from './utils/fetchTicksForRoute.js'

/**
* Options for producing the arguments to send calls to the router.
Expand Down
2 changes: 1 addition & 1 deletion src/utils/approveTokenTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Signer } from '@ethersproject/abstract-signer'
import { Provider, TransactionReceipt, TransactionResponse } from '@ethersproject/abstract-provider'
import { Contract } from '@ethersproject/contracts'
import { BigintIsh } from '@uniswap/sdk-core'
import { ERC20_ABI } from '../constants'
import { ERC20_ABI } from '../constants.js'
import { BigNumber } from 'ethers'

/**
Expand Down
2 changes: 1 addition & 1 deletion src/utils/calldata.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BigintIsh } from '@uniswap/sdk-core'
import { bigIntFromBigintIsh } from './bigintIsh'
import { bigIntFromBigintIsh } from './bigintIsh.js'

/**
* Generated method parameters for executing a call.
Expand Down
2 changes: 1 addition & 1 deletion src/utils/computePoolAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defaultAbiCoder } from '@ethersproject/abi'
import { getCreate2Address } from '@ethersproject/address'
import { keccak256 } from '@ethersproject/solidity'
import { Token } from '@uniswap/sdk-core'
import { FeeAmount, POOL_INIT_CODE_HASH } from '../constants'
import { FeeAmount, POOL_INIT_CODE_HASH } from '../constants.js'

/**
* Computes a pool address
Expand Down
4 changes: 2 additions & 2 deletions src/utils/encodeRouteToPath.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { pack } from '@ethersproject/solidity'
import { Currency, Token } from '@uniswap/sdk-core'
import { Pool } from '../entities/pool'
import { Route } from '../entities/route'
import { Pool } from '../entities/pool.js'
import { Route } from '../entities/route.js'

/**
* Converts a route to a hex encoded path
Expand Down
2 changes: 1 addition & 1 deletion src/utils/encodeSqrtRatioX96.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import JSBI from 'jsbi'
import { BigintIsh, sqrt } from '@uniswap/sdk-core'
import { bigIntFromBigintIsh } from './bigintIsh'
import { bigIntFromBigintIsh } from './bigintIsh.js'

/**
* Returns the sqrt ratio as a Q64.96 corresponding to a given ratio of amount1 and amount0
Expand Down
4 changes: 2 additions & 2 deletions src/utils/fetchTicksForRoute.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Currency } from '@uniswap/sdk-core'
import { Route } from '../entities/route'
import { Route } from '../entities/route.js'
import { Provider } from '@ethersproject/abstract-provider'
import { NoTickDataProvider } from '../entities'
import { NoTickDataProvider } from '../entities/index.js'
import invariant from 'tiny-invariant'

export async function fetchTickDataForAllPoolsInRoute<TInput extends Currency, TOutput extends Currency>(
Expand Down
2 changes: 1 addition & 1 deletion src/utils/fullMath.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import JSBI from 'jsbi'
import { bigIntFromBigintIsh } from './bigintIsh'
import { bigIntFromBigintIsh } from './bigintIsh.js'

export abstract class FullMath {
/**
Expand Down
36 changes: 18 additions & 18 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
export * from './calldata'
export * from './computePoolAddress'
export * from './encodeRouteToPath'
export * from './encodeSqrtRatioX96'
export * from './fullMath'
export * from './isSorted'
export * from './liquidityMath'
export * from './maxLiquidityForAmounts'
export * from './mostSignificantBit'
export * from './nearestUsableTick'
export * from './position'
export * from './priceTickConversions'
export * from './sqrtPriceMath'
export * from './swapMath'
export * from './tickLibrary'
export * from './tickList'
export * from './tickMath'
export * from './approveTokenTransfer'
export * from './calldata.js'
export * from './computePoolAddress.js'
export * from './encodeRouteToPath.js'
export * from './encodeSqrtRatioX96.js'
export * from './fullMath.js'
export * from './isSorted.js'
export * from './liquidityMath.js'
export * from './maxLiquidityForAmounts.js'
export * from './mostSignificantBit.js'
export * from './nearestUsableTick.js'
export * from './position.js'
export * from './priceTickConversions.js'
export * from './sqrtPriceMath.js'
export * from './swapMath.js'
export * from './tickLibrary.js'
export * from './tickList.js'
export * from './tickMath.js'
export * from './approveTokenTransfer.js'
Loading
Loading