feat: deploy connectors from cmd and minor fix on uniswap v3 connector

This commit is contained in:
cryptoDev222 2021-09-17 14:44:09 -05:00
parent cf53215d13
commit 84075c39b6
6 changed files with 130 additions and 5 deletions

View File

@ -53,6 +53,18 @@ abstract contract Helpers is DSMath, Basic {
minAmt = convert18ToDec(token.decimals(), minAmt); minAmt = convert18ToDec(token.decimals(), minAmt);
} }
function sortTokenAddress(address _token0, address _token1)
internal
view
returns (address token0, address token1)
{
if (_token0 > _token1) {
(token0, token1) = (_token1, _token0);
} else {
(token0, token1) = (_token0, _token1);
}
}
/** /**
* @dev Mint function which interact with Uniswap v3 * @dev Mint function which interact with Uniswap v3
*/ */
@ -83,6 +95,17 @@ abstract contract Helpers is DSMath, Basic {
approve(_token0, address(nftManager), _amount0); approve(_token0, address(nftManager), _amount0);
approve(_token1, address(nftManager), _amount1); approve(_token1, address(nftManager), _amount1);
{
(address token0, ) = sortTokenAddress(
address(_token0),
address(_token1)
);
if (token0 != address(_token0)) {
(_token0, _token1) = (_token1, _token0);
(_amount0, _amount1) = (_amount1, _amount0);
}
}
uint256 _minAmt0 = getMinAmount(_token0, _amount0, params.slippage); uint256 _minAmt0 = getMinAmount(_token0, _amount0, params.slippage);
uint256 _minAmt1 = getMinAmount(_token1, _amount1, params.slippage); uint256 _minAmt1 = getMinAmount(_token1, _amount1, params.slippage);
@ -139,7 +162,6 @@ abstract contract Helpers is DSMath, Basic {
uint256 _amount0, uint256 _amount0,
uint256 _amount1 uint256 _amount1
) internal { ) internal {
bool isEth0 = _token0 == wethAddr; bool isEth0 = _token0 == wethAddr;
bool isEth1 = _token1 == wethAddr; bool isEth1 = _token1 == wethAddr;
convertEthToWeth(isEth0, TokenInterface(_token0), _amount0); convertEthToWeth(isEth0, TokenInterface(_token0), _amount0);

View File

@ -11,6 +11,7 @@ const { utils } = require("ethers");
const PRIVATE_KEY = process.env.PRIVATE_KEY; const PRIVATE_KEY = process.env.PRIVATE_KEY;
const ALCHEMY_ID = process.env.ALCHEMY_ID; const ALCHEMY_ID = process.env.ALCHEMY_ID;
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY;
if (!process.env.ALCHEMY_ID) { if (!process.env.ALCHEMY_ID) {
throw new Error("ENV Variable ALCHEMY_ID not set!"); throw new Error("ENV Variable ALCHEMY_ID not set!");
@ -54,6 +55,11 @@ module.exports = {
timeout: 150000, timeout: 150000,
gasPrice: parseInt(utils.parseUnits("30", "gwei")), gasPrice: parseInt(utils.parseUnits("30", "gwei")),
}, },
rinkeby: {
url: `https://eth-rinkeby.alchemyapi.io/v2/${ALCHEMY_ID}`,
accounts: [`0x${PRIVATE_KEY}`],
timeout: 150000,
},
hardhat: { hardhat: {
forking: { forking: {
url: `https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_ID}`, url: `https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_ID}`,
@ -70,7 +76,7 @@ module.exports = {
}, },
}, },
etherscan: { etherscan: {
apiKey: process.env.ETHERSCAN_API_KEY, apiKey: ETHERSCAN_API_KEY,
}, },
tenderly: { tenderly: {
project: process.env.TENDERLY_PROJECT, project: process.env.TENDERLY_PROJECT,

View File

@ -7,6 +7,7 @@
"test": "hardhat test", "test": "hardhat test",
"coverage": "./node_modules/.bin/solidity-coverage", "coverage": "./node_modules/.bin/solidity-coverage",
"check-husky": "node status-checks/huskyCheck.js", "check-husky": "node status-checks/huskyCheck.js",
"deploy": "node scripts/deployConnectorsFromCmd.js",
"build-contracts": "sol-merger \"./contracts/connectors/mock.sol\" ./contracts/build" "build-contracts": "sol-merger \"./contracts/connectors/mock.sol\" ./contracts/build"
}, },
"repository": { "repository": {

View File

@ -0,0 +1,12 @@
module.exports = {
connectors: {
uniswapV3: "ConnectV2UniswapV3",
"1inch": "ConnectV2OneInch",
"1proto": "ConnectV2OneProto",
aaveV1: "ConnectV2AaveV1",
aaveV2: "ConnectV2AaveV2",
authority: "ConnectV2Auth",
basic: "ConnectV2Basic",
comp: "ConnectV2COMP",
}
};

View File

@ -0,0 +1,84 @@
const hre = require("hardhat");
const { ethers } = hre;
const { connectors, networks } = require("./constant/cmdAssets");
let args = process.argv;
args = args.splice(2, args.length);
let params = {};
for (let i = 0; i < args.length; i += 2) {
if (args[i][0] !== "-" || args[i][1] !== "-") {
console.log("Please add '--' for the key");
process.exit(-1);
}
let key = args[i].slice(2, args[i].length);
params[key] = args[i + 1];
if (key === "connector") {
params[key] = connectors[args[i + 1]];
}
}
if (!params.hasOwnProperty('connector')) {
console.error("Should include connector params")
process.exit(-1);
}
if(params['connector'] === undefined || params['connector'] === null) {
console.error("Unsupported connector name");
const keys = Object.keys(connectors);
console.log("Currently supported connector names are: ", keys.join(","));
console.log("If you want to add, please edit scripts/constant/cmdAssets.js");
process.exit(1);
}
if (!params.hasOwnProperty('network')) {
console.error("Should include network params")
process.exit(-1);
}
if (!params.hasOwnProperty('gas')) {
console.error("Should include gas params")
process.exit(-1);
}
let privateKey = process.env.PRIVATE_KEY;
let provider = new ethers.providers.JsonRpcProvider(hre.config.networks[params['network']].url);
// let wallet = new ethers.Wallet("0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80", provider);
let wallet = new ethers.Wallet(privateKey, provider);
const connectorName = params['connector'];
hre.network.name = params['networkName'];
hre.network.config = hre.config.networks[params['networkName']];
hre.network.provider = provider;
const main = async () => {
const Connector = await ethers.getContractFactory(connectorName);
const connector = await Connector.connect(wallet).deploy({ gasPrice: ethers.utils.parseUnits(params['gas'], "gwei") });
await connector.deployed();
console.log(`${connectorName} Deployed: ${connector.address}`);
try {
await hre.run("verify:verify", {
address: connector.address,
constructorArguments: []
}
)
} catch (error) {
console.log(`Failed to verify: ${connectorName}@${connector.address}`)
console.log(error)
}
return connector.address
}
main()
.then(() => {
console.log("Done successfully");
process.exit(0)
})
.catch(err => {
console.log("error:", err);
process.exit(1);
})

View File

@ -16,7 +16,7 @@ const constants = require("../../scripts/constant/constant");
const tokens = require("../../scripts/constant/tokens"); const tokens = require("../../scripts/constant/tokens");
const { abi: nftManagerAbi } = require("@uniswap/v3-periphery/artifacts/contracts/NonfungiblePositionManager.sol/NonfungiblePositionManager.json") const { abi: nftManagerAbi } = require("@uniswap/v3-periphery/artifacts/contracts/NonfungiblePositionManager.sol/NonfungiblePositionManager.json")
const connectV2UniswapV3Artifacts = require("../../artifacts/contracts/mainnet/connectors/uniswapV3/main.sol/ConnectV2UniswapV3.json"); const connectV2UniswapV3Artifacts = require("../../artifacts/contracts/mainnet/connectors/uniswap/v3/main.sol/ConnectV2UniswapV3.json");
const { eth } = require("../../scripts/constant/tokens"); const { eth } = require("../../scripts/constant/tokens");
const { BigNumber } = require("ethers"); const { BigNumber } = require("ethers");
@ -112,13 +112,13 @@ describe("UniswapV3", function () {
connector: connectorName, connector: connectorName,
method: "mint", method: "mint",
args: [ args: [
DAI_ADDR,
ethAddress, ethAddress,
DAI_ADDR,
FeeAmount.MEDIUM, FeeAmount.MEDIUM,
getMinTick(TICK_SPACINGS[FeeAmount.MEDIUM]), getMinTick(TICK_SPACINGS[FeeAmount.MEDIUM]),
getMaxTick(TICK_SPACINGS[FeeAmount.MEDIUM]), getMaxTick(TICK_SPACINGS[FeeAmount.MEDIUM]),
daiAmount,
ethAmount, ethAmount,
daiAmount,
"500000000000000000", "500000000000000000",
getIds, getIds,
setId setId