|
1 | 1 | import { task, types } from "hardhat/config";
|
2 | 2 | import "@nomiclabs/hardhat-waffle";
|
3 | 3 | import { BigNumber } from "ethers";
|
4 |
| -import { getUniswapDeployments, getUSDC, getWETH } from "./utils"; |
5 |
| -import { |
6 |
| - abi as POOL_ABI, |
7 |
| - bytecode as POOL_BYTECODE, |
8 |
| - } from '@uniswap/v3-core/artifacts/contracts/UniswapV3Pool.sol/UniswapV3Pool.json' |
9 |
| -import { Oracle } from "../typechain"; |
| 4 | +import { getController, getEthUSDCPool, getOracle, getUSDC, getWETH } from "./utils"; |
10 | 5 | export const one = BigNumber.from(10).pow(18)
|
11 | 6 |
|
12 | 7 | // Example execution
|
13 | 8 | /**
|
14 |
| - npx hardhat addLiquidatableVault --input '50' --network ropsten |
| 9 | + npx hardhat addLiquidatableVault --input 50 --network ropsten |
15 | 10 | */
|
16 | 11 | task("addLiquidatableVault", "Add a short position with a 150% collateralization ratio")
|
17 |
| - .addParam('input', 'amount squeeth to mint', '50', types.string) |
| 12 | + .addParam('input', 'amount squeeth to mint', 50, types.string) |
18 | 13 | .setAction(async ({ input: squeethToMint }, hre) => {
|
19 |
| - |
20 |
| - // ROPSTEN CONSTANTS |
21 |
| - const ORACLE = "0xBD9F4bE886653177D22fA9c79FD0DFc41407fC89" |
22 |
| - const ETH_USDC_POOL = "0x8356AbC730a218c24446C2c85708F373f354F0D8" |
23 |
| - // const WETH = "0xc778417e063141139fce010982780140aa0cd5ab" |
24 |
| - // const USDC = "0x27415c30d8c87437becbd4f98474f26e712047f4" |
25 | 14 |
|
26 | 15 | const { getNamedAccounts, ethers, network } = hre;
|
27 | 16 | const { deployer } = await getNamedAccounts();
|
28 |
| - const controller = await ethers.getContract("Controller", deployer); |
29 |
| - const oracle = (await ethers.getContractAt("Oracle", ORACLE)) as Oracle |
30 |
| - const ethUsdcPool = await ethers.getContractAt(POOL_ABI, ETH_USDC_POOL); |
31 |
| - // const weth = await ethers.getContractAt("WETH9", WETH); |
| 17 | + const controller = await getController(ethers, deployer, network.name) |
| 18 | + const oracle = await getOracle(ethers, deployer, network.name) |
| 19 | + const ethUsdcPool = await getEthUSDCPool(ethers, deployer, network.name) |
32 | 20 | const weth = await getWETH(ethers, deployer, network.name)
|
33 |
| - // const usdc = await ethers.getContractAt("MockErc20", USDC) |
34 | 21 | const usdc = await getUSDC(ethers, deployer, network.name)
|
35 | 22 | const ethPrice = await oracle.getTwap(ethUsdcPool.address, weth.address, usdc.address, 420, true)
|
36 | 23 | const normFactor = await controller.normalizationFactor()
|
37 | 24 | const debtAmount = ethers.utils.parseUnits(squeethToMint)
|
38 | 25 | const mintRSqueethAmount = debtAmount.mul(normFactor).div(one)
|
39 | 26 | const scaledEthPrice = ethPrice.div(10000)
|
40 | 27 | const debtInEth = mintRSqueethAmount.mul(scaledEthPrice).div(one)
|
41 |
| - const collateralToDeposit = debtInEth.mul(1.5) |
| 28 | + const collateralToDeposit = debtInEth.mul(3).div(2) |
42 | 29 |
|
43 |
| - const vaultId = await controller.mintWPowerPerpAmount(0, debtAmount, 0, {value: collateralToDeposit}) |
44 |
| - console.log(`Added 150% collateralization vault with ID: `, vaultId) |
| 30 | + const shortPowerPerp = await ethers.getContractAt("ShortPowerPerp", (await controller.shortPowerPerp())) |
| 31 | + const oldVaultId = shortPowerPerp.nextId() |
| 32 | + let oldVaultIdInt; |
| 33 | + oldVaultId.then((value: any) => { |
| 34 | + oldVaultIdInt = value.toNumber() |
| 35 | + }).catch((err: any) => { |
| 36 | + console.log(err); |
| 37 | + }); |
| 38 | + const newVaultId = oldVaultIdInt ? (oldVaultId + 1): null |
| 39 | + const tx = await controller.mintWPowerPerpAmount(0, debtAmount, 0, {value: collateralToDeposit}) |
| 40 | + await ethers.provider.waitForTransaction(tx.hash, 1) |
| 41 | + console.log(`Added 150% collateralization vault with ID: `, newVaultId) |
45 | 42 | });
|
0 commit comments