From 62899b3a6a16588bd1ba4b4b689749f7223c9ae0 Mon Sep 17 00:00:00 2001 From: pradyuman-verma Date: Sat, 20 Nov 2021 01:59:08 +0530 Subject: [PATCH] fix --- .../connectors/uniswap-sell-beta/helpers.sol | 2 +- .../libraries/TransferHelper.sol | 79 ------------------- test/uniswap-sell-beta/uniswap-sell-beta.js | 31 +++++--- 3 files changed, 23 insertions(+), 89 deletions(-) delete mode 100644 contracts/arbitrum/connectors/uniswap-sell-beta/libraries/TransferHelper.sol diff --git a/contracts/arbitrum/connectors/uniswap-sell-beta/helpers.sol b/contracts/arbitrum/connectors/uniswap-sell-beta/helpers.sol index 8bc1b65e..1171156c 100644 --- a/contracts/arbitrum/connectors/uniswap-sell-beta/helpers.sol +++ b/contracts/arbitrum/connectors/uniswap-sell-beta/helpers.sol @@ -114,7 +114,7 @@ contract Helpers { ) public { IERC20(tokenIn).safeTransferFrom(sender, recipient, amountIn); - IERC20(tokenIn).safeApprove(address(router), amountIn); + IERC20(tokenIn).safeApprove(recipient, amountIn); } function swapSingleInput(ISwapRouter.ExactInputSingleParams memory params) diff --git a/contracts/arbitrum/connectors/uniswap-sell-beta/libraries/TransferHelper.sol b/contracts/arbitrum/connectors/uniswap-sell-beta/libraries/TransferHelper.sol deleted file mode 100644 index b381b6f6..00000000 --- a/contracts/arbitrum/connectors/uniswap-sell-beta/libraries/TransferHelper.sol +++ /dev/null @@ -1,79 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -pragma solidity >=0.6.0; - -import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; - -library TransferHelper { - /// @notice Transfers tokens from the targeted address to the given destination - /// @notice Errors with 'STF' if transfer fails - /// @param token The contract address of the token to be transferred - /// @param from The originating address from which the tokens will be transferred - /// @param to The destination address of the transfer - /// @param value The amount to be transferred - function safeTransferFrom( - address token, - address from, - address to, - uint256 value - ) internal { - (bool success, bytes memory data) = token.call( - abi.encodeWithSelector( - IERC20.transferFrom.selector, - from, - to, - value - ) - ); - require( - success && (data.length == 0 || abi.decode(data, (bool))), - "STF" - ); - } - - /// @notice Transfers tokens from msg.sender to a recipient - /// @dev Errors with ST if transfer fails - /// @param token The contract address of the token which will be transferred - /// @param to The recipient of the transfer - /// @param value The value of the transfer - function safeTransfer( - address token, - address to, - uint256 value - ) internal { - (bool success, bytes memory data) = token.call( - abi.encodeWithSelector(IERC20.transfer.selector, to, value) - ); - require( - success && (data.length == 0 || abi.decode(data, (bool))), - "ST" - ); - } - - /// @notice Approves the stipulated contract to spend the given allowance in the given token - /// @dev Errors with 'SA' if transfer fails - /// @param token The contract address of the token to be approved - /// @param to The target of the approval - /// @param value The amount of the given token the target will be allowed to spend - function safeApprove( - address token, - address to, - uint256 value - ) internal { - (bool success, bytes memory data) = token.call( - abi.encodeWithSelector(IERC20.approve.selector, to, value) - ); - require( - success && (data.length == 0 || abi.decode(data, (bool))), - "SA" - ); - } - - /// @notice Transfers ETH to the recipient address - /// @dev Fails with `STE` - /// @param to The destination of the transfer - /// @param value The value to be transferred - function safeTransferETH(address to, uint256 value) internal { - (bool success, ) = to.call{value: value}(new bytes(0)); - require(success, "STE"); - } -} diff --git a/test/uniswap-sell-beta/uniswap-sell-beta.js b/test/uniswap-sell-beta/uniswap-sell-beta.js index 2996cc9c..0d185a6e 100644 --- a/test/uniswap-sell-beta/uniswap-sell-beta.js +++ b/test/uniswap-sell-beta/uniswap-sell-beta.js @@ -29,17 +29,22 @@ const WETH_ADDR = "0x82af49447d8a07e3bd95bd0d56f35241523fbab1"; describe("Uniswap-sell-beta", function() { let UniswapSellBeta, uniswapSellBeta; before(async () => { - const account = "0xa067668661c84476afcdc6fa5d758c4c01c34352"; + const account = "0x36cc7B13029B5DEe4034745FB4F24034f3F2ffc6"; [owner, add1, add2] = await ethers.getSigners(); const tokenArtifact = await artifacts.readArtifact( "@openzeppelin/contracts/token/ERC20/IERC20.sol:IERC20" ); - const token = new ethers.Contract( - WETH_ADDR, - tokenArtifact.abi, - ethers.provider - ); + + await network.provider.send("hardhat_setBalance", [ + owner.address, + ethers.utils.parseEther("10.0").toHexString(), + ]); + + await network.provider.send("hardhat_setBalance", [ + account, + ethers.utils.parseEther("10.0").toHexString(), + ]); await hre.network.provider.request({ method: "hardhat_impersonateAccount", @@ -47,10 +52,18 @@ describe("Uniswap-sell-beta", function() { }); const signer = await ethers.getSigner(account); - console.log(await token.connect(signer).balanceOf(account)); + + const token = new ethers.Contract( + WETH_ADDR, + tokenArtifact.abi, + ethers.provider + ); + + console.log((await token.balanceOf(account)).toString()); + await token .connect(signer) - .transfer(owner.address, ethers.utils.parseUnits("0.00000001", 18)); + .transfer(owner.address, ethers.utils.parseEther("10")); await hre.network.provider.request({ method: "hardhat_stopImpersonatingAccount", @@ -73,7 +86,7 @@ describe("Uniswap-sell-beta", function() { WETH_ADDR, USDC_ADDR, 3000, - ethers.utils.parseUnits("10.0"), + ethers.utils.parseUnits("1.0", 18), 0, true );