mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
update
This commit is contained in:
parent
62899b3a6a
commit
86ea7dd608
|
@ -1,6 +1,7 @@
|
||||||
pragma solidity ^0.7.6;
|
pragma solidity ^0.7.6;
|
||||||
pragma abicoder v2;
|
pragma abicoder v2;
|
||||||
|
|
||||||
|
import "hardhat/console.sol";
|
||||||
import {UniswapV3Pool, ISwapRouter} from "./interface.sol";
|
import {UniswapV3Pool, ISwapRouter} from "./interface.sol";
|
||||||
import {SqrtPriceMath} from "./libraries/SqrtPriceMath.sol";
|
import {SqrtPriceMath} from "./libraries/SqrtPriceMath.sol";
|
||||||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||||
|
@ -106,15 +107,18 @@ contract Helpers {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function approveTransfer(
|
function approveTransfer(address tokenIn, uint256 amountIn) public {
|
||||||
address tokenIn,
|
console.log(IERC20(tokenIn).balanceOf(msg.sender));
|
||||||
address sender,
|
IERC20(tokenIn).safeApprove(address(router), amountIn);
|
||||||
address recipient,
|
}
|
||||||
uint256 amountIn
|
|
||||||
) public {
|
|
||||||
IERC20(tokenIn).safeTransferFrom(sender, recipient, 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)
|
function swapSingleInput(ISwapRouter.ExactInputSingleParams memory params)
|
||||||
|
|
|
@ -12,11 +12,16 @@ contract uniswapSellBeta is Helpers {
|
||||||
uint256 amountOutMinimum,
|
uint256 amountOutMinimum,
|
||||||
bool zeroForOne
|
bool zeroForOne
|
||||||
) public payable returns (uint256 amountOut) {
|
) 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(
|
amountOut = swapSingleInput(
|
||||||
getParams(
|
getParams(
|
||||||
tokenIn,
|
tokenA,
|
||||||
tokenOut,
|
tokenB,
|
||||||
msg.sender,
|
msg.sender,
|
||||||
fee,
|
fee,
|
||||||
amountIn,
|
amountIn,
|
||||||
|
|
|
@ -2,14 +2,6 @@ const { expect } = require("chai");
|
||||||
const hre = require("hardhat");
|
const hre = require("hardhat");
|
||||||
const { web3, deployments, waffle, ethers } = hre;
|
const { web3, deployments, waffle, ethers } = hre;
|
||||||
const { provider, deployContract } = waffle;
|
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 = {
|
const FeeAmount = {
|
||||||
LOW: 500,
|
LOW: 500,
|
||||||
|
@ -29,7 +21,7 @@ const WETH_ADDR = "0x82af49447d8a07e3bd95bd0d56f35241523fbab1";
|
||||||
describe("Uniswap-sell-beta", function() {
|
describe("Uniswap-sell-beta", function() {
|
||||||
let UniswapSellBeta, uniswapSellBeta;
|
let UniswapSellBeta, uniswapSellBeta;
|
||||||
before(async () => {
|
before(async () => {
|
||||||
const account = "0x36cc7B13029B5DEe4034745FB4F24034f3F2ffc6";
|
const account = "0xce2cc46682e9c6d5f174af598fb4931a9c0be68e";
|
||||||
[owner, add1, add2] = await ethers.getSigners();
|
[owner, add1, add2] = await ethers.getSigners();
|
||||||
|
|
||||||
const tokenArtifact = await artifacts.readArtifact(
|
const tokenArtifact = await artifacts.readArtifact(
|
||||||
|
@ -54,7 +46,7 @@ describe("Uniswap-sell-beta", function() {
|
||||||
const signer = await ethers.getSigner(account);
|
const signer = await ethers.getSigner(account);
|
||||||
|
|
||||||
const token = new ethers.Contract(
|
const token = new ethers.Contract(
|
||||||
WETH_ADDR,
|
USDC_ADDR,
|
||||||
tokenArtifact.abi,
|
tokenArtifact.abi,
|
||||||
ethers.provider
|
ethers.provider
|
||||||
);
|
);
|
||||||
|
@ -63,7 +55,7 @@ describe("Uniswap-sell-beta", function() {
|
||||||
|
|
||||||
await token
|
await token
|
||||||
.connect(signer)
|
.connect(signer)
|
||||||
.transfer(owner.address, ethers.utils.parseEther("10"));
|
.transfer(owner.address, ethers.utils.parseUnits("100", 6));
|
||||||
|
|
||||||
await hre.network.provider.request({
|
await hre.network.provider.request({
|
||||||
method: "hardhat_stopImpersonatingAccount",
|
method: "hardhat_stopImpersonatingAccount",
|
||||||
|
@ -82,13 +74,29 @@ describe("Uniswap-sell-beta", function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should Perfrom a swap", async () => {
|
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(
|
const tx = await uniswapSellBeta.sell(
|
||||||
WETH_ADDR,
|
WETH_ADDR,
|
||||||
USDC_ADDR,
|
USDC_ADDR,
|
||||||
3000,
|
3000,
|
||||||
ethers.utils.parseUnits("1.0", 18),
|
ethers.utils.parseUnits("10.0", 6),
|
||||||
0,
|
0,
|
||||||
true
|
false
|
||||||
);
|
);
|
||||||
console.log(tx);
|
console.log(tx);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user