Stack Exchange Network
Stack Exchange network consists of 183 Q&A communities including
Stack Overflow
, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack Exchange
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this community
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I was following
this tutorial
and then I followed
this tutorial
to mint a position on a Uniswap pool.
This is the final script I end up with:
import { ethers } from "ethers";
import { Pool } from "@uniswap/v3-sdk";
import { Token } from "@uniswap/sdk-core";
import { abi as IUniswapV3PoolABI } from "@uniswap/v3-core/artifacts/contracts/interfaces/IUniswapV3Pool.sol/IUniswapV3Pool.json";
const provider = new ethers.providers.JsonRpcProvider("http://127.0.0.1:8545/");
const poolAddress = "0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8";
const poolContract = new ethers.Contract(
poolAddress,
IUniswapV3PoolABI,
provider
interface Immutables {
factory: string;
token0: string;
token1: string;
fee: number;
tickSpacing: number;
maxLiquidityPerTick: ethers.BigNumber;
interface State {
liquidity: ethers.BigNumber;
sqrtPriceX96: ethers.BigNumber;
tick: number;
observationIndex: number;
observationCardinality: number;
observationCardinalityNext: number;
feeProtocol: number;
unlocked: boolean;
async function getPoolImmutables() {
const [factory, token0, token1, fee, tickSpacing, maxLiquidityPerTick] =
await Promise.all([
poolContract.factory(),
poolContract.token0(),
poolContract.token1(),
poolContract.fee(),
poolContract.tickSpacing(),
poolContract.maxLiquidityPerTick(),
const immutables: Immutables = {
factory,
token0,
token1,
tickSpacing,
maxLiquidityPerTick,
return immutables;
async function getPoolState() {
const [liquidity, slot] = await Promise.all([
poolContract.liquidity(),
poolContract.slot0(),
const PoolState: State = {
liquidity,
sqrtPriceX96: slot[0],
tick: slot[1],
observationIndex: slot[2],
observationCardinality: slot[3],
observationCardinalityNext: slot[4],
feeProtocol: slot[5],
unlocked: slot[6],
return PoolState;
async function main() {
const [immutables, state] = await Promise.all([
getPoolImmutables(),
getPoolState(),
const TokenA = new Token(3, immutables.token0, 6, "USDC", "USD Coin");
const TokenB = new Token(3, immutables.token1, 18, "WETH", "Wrapped Ether");
const poolExample = new Pool(
TokenA,
TokenB,
immutables.fee,
state.sqrtPriceX96.toString(),
state.liquidity.toString(),
state.tick
console.log(poolExample);
const position = new Position({
pool: poolExample,
liquidity: state.liquidity * 0.0002,
tickLower: nearestUsableTick(state.tick, immutables.tickSpacing) - immutables.tickSpacing * 2,
tickUpper: nearestUsableTick(state.tick, immutables.tickSpacing) + immutables.tickSpacing * 2
const deadline = block.timestamp + 200;
const { calldata, value } = NonfungiblePositionManager.addCallParameters(position, {
slippageTolerance: new Percent(50, 10_000),
recipient: sender,
deadline: deadline
main();
Here's my error log:
(base) john@johns-computer:~/Documents/Projects/Blockchain_projects/uniswap-example$ npx hardhat run scripts/interacting-with-pool-liqudity.ts
/home/john/Documents/Projects/Blockchain_projects/uniswap-example/node_modules/ts-node/src/index.ts:750
return new TSError(diagnosticText, diagnosticCodes);
TSError: ⨯ Unable to compile TypeScript:
scripts/interacting-with-pool-liqudity.ts:98:24 - error TS2552: Cannot find name 'Position'. Did you mean 'position'?
98 const position = new Position({
~~~~~~~~
scripts/interacting-with-pool-liqudity.ts:98:9
98 const position = new Position({
~~~~~~~~
'position' is declared here.
scripts/interacting-with-pool-liqudity.ts:100:16 - error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
100 liquidity: state.liquidity * 0.0002,
~~~~~~~~~~~~~~~
scripts/interacting-with-pool-liqudity.ts:101:16 - error TS2304: Cannot find name 'nearestUsableTick'.
101 tickLower: nearestUsableTick(state.tick, immutables.tickSpacing) - immutables.tickSpacing * 2,
~~~~~~~~~~~~~~~~~
scripts/interacting-with-pool-liqudity.ts:102:16 - error TS2304: Cannot find name 'nearestUsableTick'.
102 tickUpper: nearestUsableTick(state.tick, immutables.tickSpacing) + immutables.tickSpacing * 2
~~~~~~~~~~~~~~~~~
scripts/interacting-with-pool-liqudity.ts:105:20 - error TS2304: Cannot find name 'block'.
105 const deadline = block.timestamp + 200;
~~~~~
scripts/interacting-with-pool-liqudity.ts:107:31 - error TS2304: Cannot find name 'NonfungiblePositionManager'.
107 const { calldata, value } = NonfungiblePositionManager.addCallParameters(position, {
~~~~~~~~~~~~~~~~~~~~~~~~~~
scripts/interacting-with-pool-liqudity.ts:108:28 - error TS2304: Cannot find name 'Percent'.
108 slippageTolerance: new Percent(50, 10_000),
~~~~~~~
scripts/interacting-with-pool-liqudity.ts:109:16 - error TS2304: Cannot find name 'sender'.
109 recipient: sender,
~~~~~~
at createTSError (/home/john/Documents/Projects/Blockchain_projects/uniswap-example/node_modules/ts-node/src/index.ts:750:12)
at reportTSError (/home/john/Documents/Projects/Blockchain_projects/uniswap-example/node_modules/ts-node/src/index.ts:754:19)
at getOutput (/home/john/Documents/Projects/Blockchain_projects/uniswap-example/node_modules/ts-node/src/index.ts:941:36)
at Object.compile (/home/john/Documents/Projects/Blockchain_projects/uniswap-example/node_modules/ts-node/src/index.ts:1243:30)
at Module.m._compile (/home/john/Documents/Projects/Blockchain_projects/uniswap-example/node_modules/ts-node/src/index.ts:1370:30)
at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Object.require.extensions.<computed> [as .ts] (/home/john/Documents/Projects/Blockchain_projects/uniswap-example/node_modules/ts-node/src/index.ts:1374:12)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
diagnosticText: "\x1B[96mscripts/interacting-with-pool-liqudity.ts\x1B[0m:\x1B[93m98\x1B[0m:\x1B[93m24\x1B[0m - \x1B[91merror\x1B[0m\x1B[90m TS2552: \x1B[0mCannot find name 'Position'. Did you mean 'position'?\n" +
'\n' +
'\x1B[7m98\x1B[0m const position = new Position({\n' +
'\x1B[7m \x1B[0m \x1B[91m ~~~~~~~~\x1B[0m\n' +
'\n' +
' \x1B[96mscripts/interacting-with-pool-liqudity.ts\x1B[0m:\x1B[93m98\x1B[0m:\x1B[93m9\x1B[0m\n' +
' \x1B[7m98\x1B[0m const position = new Position({\n' +
' \x1B[7m \x1B[0m \x1B[96m ~~~~~~~~\x1B[0m\n' +
" 'position' is declared here.\n" +
"\x1B[96mscripts/interacting-with-pool-liqudity.ts\x1B[0m:\x1B[93m100\x1B[0m:\x1B[93m16\x1B[0m - \x1B[91merror\x1B[0m\x1B[90m TS2362: \x1B[0mThe left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.\n" +
'\n' +
'\x1B[7m100\x1B[0m liquidity: state.liquidity * 0.0002,\n' +
'\x1B[7m \x1B[0m \x1B[91m ~~~~~~~~~~~~~~~\x1B[0m\n' +
"\x1B[96mscripts/interacting-with-pool-liqudity.ts\x1B[0m:\x1B[93m101\x1B[0m:\x1B[93m16\x1B[0m - \x1B[91merror\x1B[0m\x1B[90m TS2304: \x1B[0mCannot find name 'nearestUsableTick'.\n" +
'\n' +
'\x1B[7m101\x1B[0m tickLower: nearestUsableTick(state.tick, immutables.tickSpacing) - immutables.tickSpacing * 2,\n' +
'\x1B[7m \x1B[0m \x1B[91m ~~~~~~~~~~~~~~~~~\x1B[0m\n' +
"\x1B[96mscripts/interacting-with-pool-liqudity.ts\x1B[0m:\x1B[93m102\x1B[0m:\x1B[93m16\x1B[0m - \x1B[91merror\x1B[0m\x1B[90m TS2304: \x1B[0mCannot find name 'nearestUsableTick'.\n" +
'\n' +
'\x1B[7m102\x1B[0m tickUpper: nearestUsableTick(state.tick, immutables.tickSpacing) + immutables.tickSpacing * 2\n' +
'\x1B[7m \x1B[0m \x1B[91m ~~~~~~~~~~~~~~~~~\x1B[0m\n' +
"\x1B[96mscripts/interacting-with-pool-liqudity.ts\x1B[0m:\x1B[93m105\x1B[0m:\x1B[93m20\x1B[0m - \x1B[91merror\x1B[0m\x1B[90m TS2304: \x1B[0mCannot find name 'block'.\n" +
'\n' +
'\x1B[7m105\x1B[0m const deadline = block.timestamp + 200;\n' +
'\x1B[7m \x1B[0m \x1B[91m ~~~~~\x1B[0m\n' +
"\x1B[96mscripts/interacting-with-pool-liqudity.ts\x1B[0m:\x1B[93m107\x1B[0m:\x1B[93m31\x1B[0m - \x1B[91merror\x1B[0m\x1B[90m TS2304: \x1B[0mCannot find name 'NonfungiblePositionManager'.\n" +
'\n' +
'\x1B[7m107\x1B[0m const { calldata, value } = NonfungiblePositionManager.addCallParameters(position, {\n' +
'\x1B[7m \x1B[0m \x1B[91m ~~~~~~~~~~~~~~~~~~~~~~~~~~\x1B[0m\n' +
"\x1B[96mscripts/interacting-with-pool-liqudity.ts\x1B[0m:\x1B[93m108\x1B[0m:\x1B[93m28\x1B[0m - \x1B[91merror\x1B[0m\x1B[90m TS2304: \x1B[0mCannot find name 'Percent'.\n" +
'\n' +
'\x1B[7m108\x1B[0m slippageTolerance: new Percent(50, 10_000),\n' +
'\x1B[7m \x1B[0m \x1B[91m ~~~~~~~\x1B[0m\n' +
"\x1B[96mscripts/interacting-with-pool-liqudity.ts\x1B[0m:\x1B[93m109\x1B[0m:\x1B[93m16\x1B[0m - \x1B[91merror\x1B[0m\x1B[90m TS2304: \x1B[0mCannot find name 'sender'.\n" +
'\n' +
'\x1B[7m109\x1B[0m recipient: sender,\n' +
'\x1B[7m \x1B[0m \x1B[91m ~~~~~~\x1B[0m\n',
diagnosticCodes: [
2552, 2362, 2304,
2304, 2304, 2304,
2304, 2304
I'm assuming I'm dealing with some import errors, but I don't know which ones. I googled the errors, but couldn't find the answer. Can someone tell me what's going on?
Thanks in advance!
EDIT: I was able to solve some of the errors (I updated the code and the error log), but some of the errors still persist. Namely, the error which says Cannot find name 'nearestUsableTick' persists, but I can see that it's defined in the Uniswap documentation here.
Any help on this?
Thanks for contributing an answer to Ethereum Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.