Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]Adding tasks to test liquidity bot #500

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
16 changes: 8 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ jobs:
- run:
name: Compile Contracts
command: npx hardhat compile
- save_cache:
key: typechain-cache-{{ .Environment.CIRCLE_SHA1 }}
paths:
- typechain
- save_cache:
key: artifacts-cache-{{ .Environment.CIRCLE_SHA1 }}
paths:
- artifacts
# - save_cache:
# key: typechain-cache-{{ .Environment.CIRCLE_SHA1 }}
# paths:
# - typechain
# - save_cache:
# key: artifacts-cache-{{ .Environment.CIRCLE_SHA1 }}
# paths:
# - artifacts

lint:
working_directory: ~/squeeth/packages/hardhat
Expand Down
2 changes: 2 additions & 0 deletions packages/hardhat/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import './tasks/addWethLiquidity'
import './tasks/buySqueeth'
import './tasks/buyWeth'
import './tasks/increaseSlot'
import './tasks/addLiquidatableVault'
daryakaviani marked this conversation as resolved.
Show resolved Hide resolved
import './tasks/checkVaultStatus'

// Load env variables
dotenv.config()
Expand Down
45 changes: 45 additions & 0 deletions packages/hardhat/tasks/addLiquidatableVault.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { task, types } from "hardhat/config";
import "@nomiclabs/hardhat-waffle";
import { BigNumber } from "ethers";
import { getUniswapDeployments, getUSDC, getWETH } from "./utils";
import {
abi as POOL_ABI,
bytecode as POOL_BYTECODE,
} from '@uniswap/v3-core/artifacts/contracts/UniswapV3Pool.sol/UniswapV3Pool.json'
import { Oracle } from "../typechain";
export const one = BigNumber.from(10).pow(18)

// Example execution
/**
npx hardhat addLiquidatableVault --input '50' --network ropsten
daryakaviani marked this conversation as resolved.
Show resolved Hide resolved
*/
task("addLiquidatableVault", "Add a short position with a 150% collateralization ratio")
.addParam('input', 'amount squeeth to mint', '50', types.string)
.setAction(async ({ input: squeethToMint }, hre) => {

// ROPSTEN CONSTANTS
const ORACLE = "0xBD9F4bE886653177D22fA9c79FD0DFc41407fC89"
const ETH_USDC_POOL = "0x8356AbC730a218c24446C2c85708F373f354F0D8"
// const WETH = "0xc778417e063141139fce010982780140aa0cd5ab"
// const USDC = "0x27415c30d8c87437becbd4f98474f26e712047f4"
daryakaviani marked this conversation as resolved.
Show resolved Hide resolved

const { getNamedAccounts, ethers, network } = hre;
const { deployer } = await getNamedAccounts();
const controller = await ethers.getContract("Controller", deployer);
const oracle = (await ethers.getContractAt("Oracle", ORACLE)) as Oracle
const ethUsdcPool = await ethers.getContractAt(POOL_ABI, ETH_USDC_POOL);
// const weth = await ethers.getContractAt("WETH9", WETH);
const weth = await getWETH(ethers, deployer, network.name)
// const usdc = await ethers.getContractAt("MockErc20", USDC)
const usdc = await getUSDC(ethers, deployer, network.name)
const ethPrice = await oracle.getTwap(ethUsdcPool.address, weth.address, usdc.address, 420, true)
const normFactor = await controller.normalizationFactor()
const debtAmount = ethers.utils.parseUnits(squeethToMint)
const mintRSqueethAmount = debtAmount.mul(normFactor).div(one)
const scaledEthPrice = ethPrice.div(10000)
const debtInEth = mintRSqueethAmount.mul(scaledEthPrice).div(one)
const collateralToDeposit = debtInEth.mul(1.5)

const vaultId = await controller.mintWPowerPerpAmount(0, debtAmount, 0, {value: collateralToDeposit})
console.log(`Added 150% collateralization vault with ID: `, vaultId)
});
4 changes: 2 additions & 2 deletions packages/hardhat/tasks/addSqueethLiquidity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ task("addSqueethLiquidity", "Add liquidity to wsqueeth pool")
const { deployer } = await getNamedAccounts();
const { positionManager, uniswapFactory } = await getUniswapDeployments(ethers, deployer, network.name)

const controller = await ethers.getContractAt("Controller", deployer);
const wsqueeth = await ethers.getContractAt("WPowerPerp", deployer);
const controller = await ethers.getContract("Controller", deployer);
const wsqueeth = await ethers.getContract("WPowerPerp", deployer);
const weth = await getWETH(ethers, deployer, network.name)

const isWethToken0 = parseInt(weth.address, 16) < parseInt(wsqueeth.address, 16)
Expand Down
18 changes: 18 additions & 0 deletions packages/hardhat/tasks/checkVaultStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { task, types } from "hardhat/config";
import "@nomiclabs/hardhat-waffle";

// Example execution
/**
npx hardhat checkVaultStatus --input '0' --network ropsten
*/
task("checkVaultStatus", "Check if vault is liquidatable")
.addParam('input', 'vault id', 0, types.string)
.setAction(async ({ input: vaultId }, hre) => {

const { getNamedAccounts, ethers, network } = hre;
const { deployer } = await getNamedAccounts();
const controller = await ethers.getContract("Controller", deployer);

const isVaultSafe = await controller.isVaultSafe(vaultId)
console.log(`Whether inputted vault is safe: `, isVaultSafe)
});