This commit is contained in:
pradyuman-verma 2021-11-20 03:25:52 +05:30
parent 62899b3a6a
commit 86ea7dd608
No known key found for this signature in database
GPG Key ID: 03CEE9087D1D5E4C
3 changed files with 41 additions and 24 deletions

View File

@ -1,6 +1,7 @@
pragma solidity ^0.7.6;
pragma abicoder v2;
import "hardhat/console.sol";
import {UniswapV3Pool, ISwapRouter} from "./interface.sol";
import {SqrtPriceMath} from "./libraries/SqrtPriceMath.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
@ -106,15 +107,18 @@ contract Helpers {
});
}
function approveTransfer(
address tokenIn,
address sender,
address recipient,
uint256 amountIn
) public {
IERC20(tokenIn).safeTransferFrom(sender, recipient, amountIn);
function approveTransfer(address tokenIn, uint256 amountIn) public {
console.log(IERC20(tokenIn).balanceOf(msg.sender));
IERC20(tokenIn).safeApprove(address(router), amountIn);
}
IERC20(tokenIn).safeApprove(recipient, amountIn);
function SwapTokens(
address tokenIn,
address tokenOut,
bool zeroForOne
) public returns (address, address) {
if (!zeroForOne) return (tokenOut, tokenIn);
else return (tokenIn, tokenOut);
}
function swapSingleInput(ISwapRouter.ExactInputSingleParams memory params)

View File

@ -12,11 +12,16 @@ contract uniswapSellBeta is Helpers {
uint256 amountOutMinimum,
bool zeroForOne
) public payable returns (uint256 amountOut) {
approveTransfer(tokenIn, msg.sender, address(this), msg.value);
(address tokenA, address tokenB) = SwapTokens(
tokenIn,
tokenOut,
zeroForOne
);
approveTransfer(tokenA, amountIn);
amountOut = swapSingleInput(
getParams(
tokenIn,
tokenOut,
tokenA,
tokenB,
msg.sender,
fee,
amountIn,

View File

@ -2,14 +2,6 @@ const { expect } = require("chai");
const hre = require("hardhat");
const { web3, deployments, waffle, ethers } = hre;
const { provider, deployContract } = waffle;
const deployAndEnableConnector = require("../../scripts/deployAndEnableConnector.js");
const buildDSAv2 = require("../../scripts/buildDSAv2");
const encodeSpells = require("../../scripts/encodeSpells.js");
const addresses = require("../../scripts/constant/addresses");
const abis = require("../../scripts/constant/abis");
const UniswapSellBetaArtifacts = require("../../artifacts/contracts/arbitrum/connectors/uniswap-sell-beta/main.sol/UniswapSellBetaArbitrum.json");
const FeeAmount = {
LOW: 500,
@ -29,7 +21,7 @@ const WETH_ADDR = "0x82af49447d8a07e3bd95bd0d56f35241523fbab1";
describe("Uniswap-sell-beta", function() {
let UniswapSellBeta, uniswapSellBeta;
before(async () => {
const account = "0x36cc7B13029B5DEe4034745FB4F24034f3F2ffc6";
const account = "0xce2cc46682e9c6d5f174af598fb4931a9c0be68e";
[owner, add1, add2] = await ethers.getSigners();
const tokenArtifact = await artifacts.readArtifact(
@ -54,7 +46,7 @@ describe("Uniswap-sell-beta", function() {
const signer = await ethers.getSigner(account);
const token = new ethers.Contract(
WETH_ADDR,
USDC_ADDR,
tokenArtifact.abi,
ethers.provider
);
@ -63,7 +55,7 @@ describe("Uniswap-sell-beta", function() {
await token
.connect(signer)
.transfer(owner.address, ethers.utils.parseEther("10"));
.transfer(owner.address, ethers.utils.parseUnits("100", 6));
await hre.network.provider.request({
method: "hardhat_stopImpersonatingAccount",
@ -82,13 +74,29 @@ describe("Uniswap-sell-beta", function() {
});
it("Should Perfrom a swap", async () => {
const tokenArtifact = await artifacts.readArtifact(
"@openzeppelin/contracts/token/ERC20/IERC20.sol:IERC20"
);
const token = new ethers.Contract(
USDC_ADDR,
tokenArtifact.abi,
ethers.provider
);
const signer = await ethers.getSigner(owner.address);
await token
.connect(signer)
.transfer(uniswapSellBeta.address, ethers.utils.parseUnits("10.0", 6));
const tx = await uniswapSellBeta.sell(
WETH_ADDR,
USDC_ADDR,
3000,
ethers.utils.parseUnits("1.0", 18),
ethers.utils.parseUnits("10.0", 6),
0,
true
false
);
console.log(tx);
});