merge conflicts

This commit is contained in:
pk1411 2022-03-08 10:57:33 +05:30
commit 5e1b4495f4
16 changed files with 363 additions and 15641 deletions

View File

@ -6,7 +6,7 @@ on:
jobs:
build:
runs-on: ubuntu-latest
permissions:
permissions:
contents: write
strategy:
matrix:
@ -32,12 +32,9 @@ jobs:
- name: Run status checks
id: status_check
run: |
mkdir -p pr
# Run status checks, Remove ANSI colors from the text
output=$(node ./status-checks | sed 's/\x1B\[[0-9;]\{1,\}[A-Za-z]//g')
# Escape newlines so _all_ the output is included in the set-output
output="${output//'%'/'%25'}"
output="${output//$'\n'/'%0A'}"
output="${output//$'\r'/'%0D'}"
output=$(npx ts-node ./status-checks/index.ts | sed 's/\x1B\[[0-9;]\{1,\}[A-Za-z]//g')
cat <<< "$output" > "./pr/status-check-output"
echo ${{ github.event.number }} > ./pr/number
- uses: actions/upload-artifact@v2

View File

@ -0,0 +1,12 @@
pragma solidity ^0.7.0;
contract Events {
event LogSwap(
address indexed buyToken,
address indexed sellToken,
uint256 buyAmt,
uint256 sellAmt,
uint256 getId,
uint256 setId
);
}

View File

@ -0,0 +1,80 @@
pragma solidity ^0.7.0;
import { TokenInterface } from "../../../common/interfaces.sol";
import { DSMath } from "../../../common/math.sol";
import { Basic } from "../../../common/basic.sol";
import { SwapData } from "./interface.sol";
abstract contract Helpers is DSMath, Basic {
/**
* @dev UniswapV3 Swap Router Address
*/
address internal constant V3_SWAP_ROUTER_ADDRESS =
0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45;
/**
* @dev UniswapV3 swapHelper
* @param swapData - Struct defined in interfaces.sol
*/
function _swapHelper(SwapData memory swapData)
internal
returns (uint256 buyAmt)
{
(uint256 _buyDec, uint256 _sellDec) = getTokensDec(
swapData.buyToken,
swapData.sellToken
);
uint256 _sellAmt18 = convertTo18(_sellDec, swapData._sellAmt);
uint256 _slippageAmt = convert18ToDec(
_buyDec,
wmul(swapData.unitAmt, _sellAmt18)
);
uint256 initalBal = getTokenBal(swapData.buyToken);
// solium-disable-next-line security/no-call-value
(bool success, ) = V3_SWAP_ROUTER_ADDRESS.call(swapData.callData);
if (!success) revert("uniswapV3-swap-failed");
uint256 finalBal = getTokenBal(swapData.buyToken);
buyAmt = sub(finalBal, initalBal);
require(_slippageAmt <= buyAmt, "Too much slippage");
}
/**
* @dev Gets the swapping data from auto router sdk
* @param swapData Struct with multiple swap data defined in interfaces.sol
* @param setId Set token amount at this ID in `InstaMemory` Contract.
*/
function _swap(SwapData memory swapData, uint256 setId)
internal
returns (SwapData memory)
{
bool isEthSellToken = address(swapData.sellToken) == ethAddr;
bool isEthBuyToken = address(swapData.buyToken) == ethAddr;
swapData.sellToken = isEthSellToken
? TokenInterface(wethAddr)
: swapData.sellToken;
swapData.buyToken = isEthBuyToken
? TokenInterface(wethAddr)
: swapData.buyToken;
convertEthToWeth(isEthSellToken, swapData.sellToken, swapData._sellAmt);
approve(
TokenInterface(swapData.sellToken),
V3_SWAP_ROUTER_ADDRESS,
swapData._sellAmt
);
swapData._buyAmt = _swapHelper(swapData);
convertWethToEth(isEthBuyToken, swapData.buyToken, swapData._buyAmt);
setUint(setId, swapData._buyAmt);
return swapData;
}
}

View File

@ -0,0 +1,12 @@
pragma solidity ^0.7.0;
import { TokenInterface } from "../../../common/interfaces.sol";
struct SwapData {
TokenInterface sellToken;
TokenInterface buyToken;
uint256 _sellAmt;
uint256 _buyAmt;
uint256 unitAmt;
bytes callData;
}

View File

@ -0,0 +1,64 @@
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
/**
* @title UniswapV3_autoRouter.
* @dev DEX.
*/
// import files from common directory
import { TokenInterface, MemoryInterface } from "../../../common/interfaces.sol";
import { Stores } from "../../../common/stores.sol";
import { SwapData } from "./interface.sol";
import { Helpers } from "./helpers.sol";
import { Events } from "./events.sol";
abstract contract AutoRouter is Helpers, Events {
/**
* @dev Sell ETH/ERC20_Token using uniswap v3 auto router.
* @notice Swap tokens from getting an optimized trade routes
* @param buyAddr The address of the token to buy.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param sellAddr The address of the token to sell.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param sellAmt The amount of the token to sell.
* @param unitAmt The amount of buyAmt/sellAmt with slippage.
* @param callData Data from Uniswap V3 auto router SDK.
* @param setId ID stores the amount of token brought.
*/
function sell(
address buyAddr,
address sellAddr,
uint256 sellAmt,
uint256 unitAmt,
bytes calldata callData,
uint256 setId
)
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
SwapData memory swapData = SwapData({
buyToken: TokenInterface(buyAddr),
sellToken: TokenInterface(sellAddr),
unitAmt: unitAmt,
callData: callData,
_sellAmt: sellAmt,
_buyAmt: 0
});
swapData = _swap(swapData, setId);
_eventName = "LogSwap(address,address,uint256,uint256,uint256,uint256)";
_eventParam = abi.encode(
buyAddr,
sellAddr,
swapData._buyAmt,
swapData._sellAmt,
0,
setId
);
}
}
contract ConnectV2UniswapV3AutoRouterArbitrum is AutoRouter {
string public name = "UniswapV3-Auto-Router-v1";
}

View File

@ -20,6 +20,7 @@ abstract contract SushipswapIncentiveResolver is Helpers, Events {
* @param amount amount of LP token
* @param getId ID to retrieve amount
* @param setId ID stores Pool ID
* @param data the metadata struct
*/
function deposit(
address token1,
@ -66,6 +67,7 @@ abstract contract SushipswapIncentiveResolver is Helpers, Events {
* @param amount amount of LP token
* @param getId ID to retrieve amount
* @param setId ID stores Pool ID
* @param data the metadata struct
*/
function withdraw(
address token1,
@ -104,6 +106,7 @@ abstract contract SushipswapIncentiveResolver is Helpers, Events {
* @param token1 token1 deposited of LP token
* @param token2 token2 deposited LP token
* @param setId ID stores Pool ID
* @param data the metadata struct
*/
function harvest(
address token1,
@ -143,6 +146,7 @@ abstract contract SushipswapIncentiveResolver is Helpers, Events {
* @param amount amount of LP token
* @param getId ID to retrieve amount
* @param setId ID stores Pool ID
* @param data the metadata struct
*/
function withdrawAndHarvest(
address token1,
@ -183,6 +187,7 @@ abstract contract SushipswapIncentiveResolver is Helpers, Events {
* @param token1 token1 deposited of LP token
* @param token2 token2 deposited LP token
* @param setId ID stores Pool ID
* @param data the metadata struct
*/
function emergencyWithdraw(
address token1,

View File

@ -0,0 +1,12 @@
pragma solidity ^0.7.0;
contract Events {
event LogSwap(
address indexed buyToken,
address indexed sellToken,
uint256 buyAmt,
uint256 sellAmt,
uint256 getId,
uint256 setId
);
}

View File

@ -0,0 +1,80 @@
pragma solidity ^0.7.0;
import { TokenInterface } from "../../../common/interfaces.sol";
import { DSMath } from "../../../common/math.sol";
import { Basic } from "../../../common/basic.sol";
import { SwapData } from "./interface.sol";
abstract contract Helpers is DSMath, Basic {
/**
* @dev UniswapV3 Swap Router Address
*/
address internal constant V3_SWAP_ROUTER_ADDRESS =
0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45;
/**
* @dev UniswapV3 swapHelper
* @param swapData - Struct defined in interfaces.sol
*/
function _swapHelper(SwapData memory swapData)
internal
returns (uint256 buyAmt)
{
(uint256 _buyDec, uint256 _sellDec) = getTokensDec(
swapData.buyToken,
swapData.sellToken
);
uint256 _sellAmt18 = convertTo18(_sellDec, swapData._sellAmt);
uint256 _slippageAmt = convert18ToDec(
_buyDec,
wmul(swapData.unitAmt, _sellAmt18)
);
uint256 initalBal = getTokenBal(swapData.buyToken);
// solium-disable-next-line security/no-call-value
(bool success, ) = V3_SWAP_ROUTER_ADDRESS.call(swapData.callData);
if (!success) revert("uniswapV3-swap-failed");
uint256 finalBal = getTokenBal(swapData.buyToken);
buyAmt = sub(finalBal, initalBal);
require(_slippageAmt <= buyAmt, "Too much slippage");
}
/**
* @dev Gets the swapping data from auto router sdk
* @param swapData Struct with multiple swap data defined in interfaces.sol
* @param setId Set token amount at this ID in `InstaMemory` Contract.
*/
function _swap(SwapData memory swapData, uint256 setId)
internal
returns (SwapData memory)
{
bool isEthSellToken = address(swapData.sellToken) == ethAddr;
bool isEthBuyToken = address(swapData.buyToken) == ethAddr;
swapData.sellToken = isEthSellToken
? TokenInterface(wethAddr)
: swapData.sellToken;
swapData.buyToken = isEthBuyToken
? TokenInterface(wethAddr)
: swapData.buyToken;
convertEthToWeth(isEthSellToken, swapData.sellToken, swapData._sellAmt);
approve(
TokenInterface(swapData.sellToken),
V3_SWAP_ROUTER_ADDRESS,
swapData._sellAmt
);
swapData._buyAmt = _swapHelper(swapData);
convertWethToEth(isEthBuyToken, swapData.buyToken, swapData._buyAmt);
setUint(setId, swapData._buyAmt);
return swapData;
}
}

View File

@ -0,0 +1,12 @@
pragma solidity ^0.7.0;
import { TokenInterface } from "../../../common/interfaces.sol";
struct SwapData {
TokenInterface sellToken;
TokenInterface buyToken;
uint256 _sellAmt;
uint256 _buyAmt;
uint256 unitAmt;
bytes callData;
}

View File

@ -0,0 +1,64 @@
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
/**
* @title UniswapV3_autoRouter.
* @dev DEX.
*/
// import files from common directory
import { TokenInterface, MemoryInterface } from "../../../common/interfaces.sol";
import { Stores } from "../../../common/stores.sol";
import { SwapData } from "./interface.sol";
import { Helpers } from "./helpers.sol";
import { Events } from "./events.sol";
abstract contract AutoRouter is Helpers, Events {
/**
* @dev Sell ETH/ERC20_Token using uniswap v3 auto router.
* @notice Swap tokens from getting an optimized trade routes
* @param buyAddr The address of the token to buy.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param sellAddr The address of the token to sell.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param sellAmt The amount of the token to sell.
* @param unitAmt The amount of buyAmt/sellAmt with slippage.
* @param callData Data from Uniswap V3 auto router SDK.
* @param setId ID stores the amount of token brought.
*/
function sell(
address buyAddr,
address sellAddr,
uint256 sellAmt,
uint256 unitAmt,
bytes calldata callData,
uint256 setId
)
external
payable
returns (string memory _eventName, bytes memory _eventParam)
{
SwapData memory swapData = SwapData({
buyToken: TokenInterface(buyAddr),
sellToken: TokenInterface(sellAddr),
unitAmt: unitAmt,
callData: callData,
_sellAmt: sellAmt,
_buyAmt: 0
});
swapData = _swap(swapData, setId);
_eventName = "LogSwap(address,address,uint256,uint256,uint256,uint256)";
_eventParam = abi.encode(
buyAddr,
sellAddr,
swapData._buyAmt,
swapData._sellAmt,
0,
setId
);
}
}
contract ConnectV2UniswapV3AutoRouterOptimism is AutoRouter {
string public name = "UniswapV3-Auto-Router-v1";
}

View File

@ -13,8 +13,12 @@ import { HardhatUserConfig } from "hardhat/config";
import { NetworkUserConfig } from "hardhat/types";
import { utils } from "ethers";
import Web3 from "web3";
<<<<<<< HEAD
import "./scripts/tests/tests-run"
=======
import { network } from "hardhat";
>>>>>>> origin/main
dotenvConfig({ path: resolve(__dirname, "./.env") });
@ -37,8 +41,8 @@ const PRIVATE_KEY = process.env.PRIVATE_KEY;
const ETHERSCAN_API = process.env.ETHERSCAN_API_KEY;
const POLYGONSCAN_API = process.env.POLYGON_API_KEY;
const ARBISCAN_API = process.env.ARBISCAN_API_KEY;
const SNOWTRACE_API = process.env.SNOWTRACE_API_KEY;
const OPTIMISM_API = process.env.OPTIMISM_API_KEY;
const SNOWTRACE_API = process.env.SNOWTRACE_API_KEY;
const FANTOM_API = process.env.FANTOM_API_KEY;
const mnemonic =
process.env.MNEMONIC ??
@ -56,6 +60,7 @@ function createConfig(network: string) {
url: getNetworkUrl(network),
accounts: !!PRIVATE_KEY ? [`0x${PRIVATE_KEY}`] : { mnemonic },
gasPrice: Number(networkGasPriceConfig[network])*1e9, // 0.0001 GWEI
};
}

2400
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -92,7 +92,7 @@ const checkEvents = async (connector: {
const eventsPath = `${connector.path}/events.sol`;
const mainPath = `${connector.path}/main.sol`;
if (connector.events.length) {
const eventNames = [];
const eventNames:string[] = [];
for (let i1 = 0; i1 < connector.mainEvents.length; i1++) {
const mainEvent = connector.mainEvents[i1];
const name = mainEvent.split("(")[0];
@ -131,7 +131,7 @@ const checkEvents = async (connector: {
}
}
if (connector.mainEvents.length < connector.events.length) {
const deprecatedEvents = connector.events.filter((e) => {
const deprecatedEvents = connector.events.filter((e: string) => {
let used = false;
for (let index = 0; index < eventNames.length; index++) {
if (e.split("(")[0].split(" ")[1] === eventNames[index])
@ -157,7 +157,7 @@ const checkEvents = async (connector: {
const getCommments = async (strs: string | any[]) => {
try {
const comments = [];
let type: string;
let type: string = '';
for (let index = strs.length - 1; index >= 0; index--) {
const str = strs[index];
if (!type) {
@ -194,9 +194,9 @@ const parseCode = async (connector: { path: any; code?: any }) => {
const eventsFirstLines = [];
let func = [];
let funcs = [];
let event = [];
let mainEvents = [];
let firstLine: number;
let event: string[] = [];
let mainEvents: string[] = [];
let firstLine: number = -1;
let mainEventsLines = [];
for (let index = 0; index < strs.length; index++) {
const str = strs[index];
@ -297,7 +297,7 @@ const parseCode = async (connector: { path: any; code?: any }) => {
}
};
const checkComments = async (connector) => {
const checkComments = async (connector:any) => {
try {
const errors = [];
for (let i1 = 0; i1 < connector.funcs.length; i1++) {
@ -317,7 +317,7 @@ const checkComments = async (connector) => {
}
const reqs = ["@dev", "@notice"];
for (let i3 = 0; i3 < reqs.length; i3++) {
if (!func.comments.some((comment) => comment.startsWith(reqs[i3]))) {
if (!func.comments.some((comment: string) => comment.startsWith(reqs[i3]))) {
errors.push(
`no ${reqs[i3]} for function ${func.name} at ${connector.path}/main.sol:${func.firstLine}`
);

View File

@ -3,7 +3,7 @@ import fetch from "node-fetch";
import checks from "./checks";
const [owner, repo] = process.env.GITHUB_REPOSITORY.split("/");
const [owner, repo] = String(process.env.GITHUB_REPOSITORY).split("/");
function getCurrentCommitSha() {
return cp
@ -11,6 +11,7 @@ function getCurrentCommitSha() {
.toString()
.trim();
}
// The SHA provied by GITHUB_SHA is the merge (PR) commit.
// We need to get the current commit sha ourself.
const sha = getCurrentCommitSha();
@ -45,7 +46,7 @@ async function setStatus(context: any, state: string, description: string) {
try {
const response = await callback();
await setStatus(name, "success", response);
} catch (err) {
} catch (err: any) {
const message = err ? err.message : "Something went wrong";
await setStatus(name, "failure", message);
}

View File

@ -21,6 +21,7 @@
"tasks/**/*",
"test/**/*",
"typechain/**/*",
"types/**/*"
"types/**/*",
"status-checks/*"
]
}

13223
yarn.lock

File diff suppressed because it is too large Load Diff