Skip to content

Commit

Permalink
chore: tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewlilley committed Jan 11, 2022
1 parent 332513c commit 2498856
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
11 changes: 7 additions & 4 deletions tasks/add-liquidity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}`);

Expand Down
10 changes: 4 additions & 6 deletions tasks/erc20-approve.ts
Original file line number Diff line number Diff line change
@@ -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>("ERC20Mock", token);
return erc20.connect(dev).approve(spender, MaxUint256);
});
1 change: 1 addition & 0 deletions tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
10 changes: 3 additions & 7 deletions tasks/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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__factory>("BentoBoxV1");
try {
bentoBox = await ethers.getContract<BentoBoxV1>("BentoBoxV1");
} catch (error) {
bentoBox = BentoBox.attach(BENTOBOX_ADDRESS[chainId]);
}
bentoBox = (await ethers.getContractOrNull<BentoBoxV1>("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");
Expand Down

0 comments on commit 2498856

Please sign in to comment.