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

Invalid import: #14047

Closed
codeWithDevMA opened this issue Mar 14, 2023 · 1 comment
Closed

Invalid import: #14047

codeWithDevMA opened this issue Mar 14, 2023 · 1 comment
Projects

Comments

@codeWithDevMA
Copy link

import "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol";
Invalid import: trying to use an unsupported protocolhardhat(406)
"devDependencies": {
"@nomicfoundation/hardhat-toolbox": "^2.0.2",
"@nomiclabs/hardhat-ethers": "^2.2.2",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"chai": "^4.3.7",
"ethereum-waffle": "^3.4.0",
"ethers": "^5.7.2",
"hardhat": "^2.13.0"
},
"dependencies": {
"@typechain/ethers-v5": "^10.2.0",
"@typechain/hardhat": "^6.1.5",
"@uniswap/v3-core": "^1.0.1",
"@uniswap/v3-periphery": "^1.4.3",
"chai-as-promised": "^7.1.1"
}
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity =0.8.19;
pragma abicoder v2;

import "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol";

interface IERC20 {
function balanceOf(address account) external view returns (uint256);

function transfer(address recipient, uint256 amount)
    external
    returns (bool);

function approve(address spender, uint256 amount) external returns (bool);

}

contract SingleSwap {
address public constant routerAddress =
0xE592427A0AEce92De3Edee1F18E0157C05861564;
ISwapRouter public immutable swapRouter = ISwapRouter(routerAddress);

address public constant LINK = 0x326C977E6efc84E512bB9C30f76E30c160eD06FB;
address public constant WETH = 0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6;

IERC20 public linkToken = IERC20(LINK);

// For this example, we will set the pool fee to 0.3%.
uint24 public constant poolFee = 3000;

constructor() {}

function swapExactInputSingle(uint256 amountIn)
    external
    returns (uint256 amountOut)
{
    linkToken.approve(address(swapRouter), amountIn);

    ISwapRouter.ExactInputSingleParams memory params = ISwapRouter
        .ExactInputSingleParams({
            tokenIn: LINK,
            tokenOut: WETH,
            fee: poolFee,
            recipient: address(this),
            deadline: block.timestamp,
            amountIn: amountIn,
            amountOutMinimum: 0,
            sqrtPriceLimitX96: 0
        });

    amountOut = swapRouter.exactInputSingle(params);
}

function swapExactOutputSingle(uint256 amountOut, uint256 amountInMaximum)
    external
    returns (uint256 amountIn)
{
    linkToken.approve(address(swapRouter), amountInMaximum);

    ISwapRouter.ExactOutputSingleParams memory params = ISwapRouter
        .ExactOutputSingleParams({
            tokenIn: LINK,
            tokenOut: WETH,
            fee: poolFee,
            recipient: address(this),
            deadline: block.timestamp,
            amountOut: amountOut,
            amountInMaximum: amountInMaximum,
            sqrtPriceLimitX96: 0
        });

    amountIn = swapRouter.exactOutputSingle(params);

    if (amountIn < amountInMaximum) {
        linkToken.approve(address(swapRouter), 0);
        linkToken.transfer(address(this), amountInMaximum - amountIn);
    }
}

}

@github-actions github-actions bot added this to Triage in Solidity Mar 14, 2023
@r0qs
Copy link
Member

r0qs commented Mar 15, 2023

@ghazali-web as far as I could see, your issue is not a solidity problem but rather a wrong use of it or of hardhat.

I suggest that you take a look at our documentation and the documentation of the tools that you are using, i.e. Hardhat. A better place to post such issues would be the Ethereum stack exchange.

Please, feel free to reopen the issue in case I misunderstood something and you indeed found an issue in the Solidity compiler.
Also, if you reopen it, please make sure you properly describe what is the problem, and use the markdown format appropriately for the code snippet. So it will be easier to understand the issue.

@r0qs r0qs closed this as completed Mar 15, 2023
Solidity automation moved this from Triage to Done Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Solidity
  
Done
Development

No branches or pull requests

2 participants