From 249885694d355ff6ee1f44d2f0848e7f99520206 Mon Sep 17 00:00:00 2001 From: Matthew Lilley Date: Tue, 11 Jan 2022 03:10:07 +0000 Subject: [PATCH] chore: tasks --- tasks/add-liquidity.ts | 11 +++++++---- tasks/erc20-approve.ts | 10 ++++------ tasks/index.ts | 1 + tasks/strategy.ts | 10 +++------- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/tasks/add-liquidity.ts b/tasks/add-liquidity.ts index f3920ff6..6fb773cf 100644 --- a/tasks/add-liquidity.ts +++ b/tasks/add-liquidity.ts @@ -8,8 +8,8 @@ const { BigNumber } = ethers; task("add-liquidity", "Add liquidity") .addOptionalParam("tokenA", "Token A", WETH9_ADDRESS[ChainId.KOVAN], types.string) .addOptionalParam("tokenB", "Token B", USDC_ADDRESS[ChainId.KOVAN], types.string) - .addOptionalParam("pool", "Pool") - .addOptionalParam("minLiquidity", "Minimum Liquidity", BigNumber.from(10).pow(1).toString(), types.string) + .addOptionalParam("pool", "Pool", "0xb11d9FB782D0185e7D19C8127241398305B110Ed") + .addOptionalParam("minLiquidity", "Minimum Liquidity", BigNumber.from(10).pow(0).toString(), types.string) .addOptionalParam("recipient", "Recipient", "0xd198B08Fb9bfd659065D3c15FbcE14e44Ab54D42", types.string) // dev default .setAction( async ( @@ -63,19 +63,22 @@ task("add-liquidity", "Add liquidity") await run("whitelist"); if ((await token0.allowance(deployer, bentoBox.address)).lt(liquidityInput[0].amount)) { + console.log("Approving token0"); await run("erc20:approve", { token: liquidityInput[0].token, spender: bentoBox.address, }); + console.log("Approved token0"); } if ((await token1.allowance(deployer, bentoBox.address)).lt(liquidityInput[1].amount)) { + console.log("Approving token1"); await run("erc20:approve", { token: liquidityInput[1].token, spender: bentoBox.address, }); + console.log("Approved token1"); } - console.log("Approved both tokens"); console.log("Depositing 1st token", [liquidityInput[0].token, dev.address, dev.address, 0, liquidityInput[0].amount]); await bentoBox @@ -103,7 +106,7 @@ task("add-liquidity", "Add liquidity") console.log("Set master contract approval"); - const data = ethers.utils.defaultAbiCoder.encode(["address"], [recipient]); + const data = ethers.utils.defaultAbiCoder.encode(["address"], [dev.address]); console.log(`Adding minmimum of ${minLiquidity} liquidity to ${pool}`); diff --git a/tasks/erc20-approve.ts b/tasks/erc20-approve.ts index cee281c6..c7ef3057 100644 --- a/tasks/erc20-approve.ts +++ b/tasks/erc20-approve.ts @@ -1,16 +1,14 @@ import { task } from "hardhat/config"; import { constants } from "ethers"; +import { ERC20Mock } from "../types"; const { MaxUint256 } = constants; -task("erc20:approve", "ERC20 approve") +task("erc20-approve", "ERC20 approve") .addParam("token", "Token") .addParam("spender", "Spender") .setAction(async function ({ token, spender }, { ethers }, runSuper) { const dev = await ethers.getNamedSigner("dev"); - const erc20 = await ethers.getContractFactory("ERC20Mock"); - - const slp = erc20.attach(token); - - await (await slp.connect(dev).approve(spender, MaxUint256)).wait(); + const erc20 = await ethers.getContractAt("ERC20Mock", token); + return erc20.connect(dev).approve(spender, MaxUint256); }); diff --git a/tasks/index.ts b/tasks/index.ts index bb008b49..6e138177 100644 --- a/tasks/index.ts +++ b/tasks/index.ts @@ -2,6 +2,7 @@ import "./accounts"; import "./add-liquidity"; import "./cpp-address"; import "./cpp-deploy"; +import "./erc20-allowance"; import "./erc20-approve"; import "./strategy"; import "./whitelist"; diff --git a/tasks/strategy.ts b/tasks/strategy.ts index b51529c6..37605b6d 100644 --- a/tasks/strategy.ts +++ b/tasks/strategy.ts @@ -2,22 +2,18 @@ import { BENTOBOX_ADDRESS, ChainId, WETH9_ADDRESS } from "@sushiswap/core-sdk"; import { task } from "hardhat/config"; import { BentoBoxV1, BentoBoxV1__factory } from "../types"; -task("add:strategy", "Add strategy to BentoBox") +task("add-strategy", "Add strategy to BentoBox") .addOptionalParam("bentoBox", "BentoBox address", BENTOBOX_ADDRESS[ChainId.KOVAN]) .addOptionalParam("token", "Token of strategy", WETH9_ADDRESS[ChainId.KOVAN]) .addOptionalParam("strategy", "Strategy", "0x65E58C475e6f9CeF0d79371cC278E7827a72b19b") .setAction(async function ( { bentoBox, token, strategy }: { bentoBox: BentoBoxV1; token: string; strategy: string }, - { ethers, getChainId } + { ethers, getChainId, deployments } ) { const dev = await ethers.getNamedSigner("dev"); const chainId = await getChainId(); const BentoBox = await ethers.getContractFactory("BentoBoxV1"); - try { - bentoBox = await ethers.getContract("BentoBoxV1"); - } catch (error) { - bentoBox = BentoBox.attach(BENTOBOX_ADDRESS[chainId]); - } + bentoBox = (await ethers.getContractOrNull("BentoBoxV1")) ?? BentoBox.attach(BENTOBOX_ADDRESS[chainId]); await bentoBox.connect(dev).setStrategy(token, strategy); await bentoBox.connect(dev).setStrategy(token, strategy); // testing version of bentobox has a strategy delay of 0 await bentoBox.connect(dev).setStrategyTargetPercentage(token, "70");