Skip to content

Commit

Permalink
fix(tasks): lint (#303)
Browse files Browse the repository at this point in the history
* fix(tasks): lint

* fix(sdk): fix strategy fetch script

* fix(optyfi-sdk): lint issue
  • Loading branch information
dhruvinparikh authored Mar 16, 2022
1 parent 506eb96 commit 83883a9
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 74 deletions.
1 change: 1 addition & 0 deletions cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ Options:
--vault required <address> the address of vault
--user required <address> account address of the user
--action required <string> "DEPOSIT" || "WITHDRAW" || "REBALANCE"
--merkle-proof required <string> merkle proofs in stringified form
--useall optional <bool> use whole balance (default: false)
--amount optional <number> amount of token (default: 0)
--network optional <string> name of the network provider (default: hardhat)
Expand Down
121 changes: 61 additions & 60 deletions scripts/optyfi-sdk.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import data from "../optyfi-sdk/config";
import { NETWORKS, NETWORKS_ID } from "../helpers/constants/network";
import { createDir, createFile, getMoralisConfig } from "../helpers/utils";
import { DEFI_POOL_DATA, STRATEGIES, STRATEGY_DATA } from "../helpers/type";
import { ETH } from "../helpers/constants/utils";
import { ESSENTIAL_CONTRACTS } from "../helpers/constants/essential-contracts-name";
import { DEFI_POOL_DATA /*STRATEGIES, STRATEGY_DATA*/ } from "../helpers/type";
// import { ETH } from "../helpers/constants/utils";
// import { ESSENTIAL_CONTRACTS } from "../helpers/constants/essential-contracts-name";

import { TypedTokens } from "../helpers/data";
import hre from "hardhat";
// import { TypedTokens } from "../helpers/data";
// import hre from "hardhat";

import { bold } from "./common";
import axios, { Method } from "axios";
Expand Down Expand Up @@ -54,66 +54,67 @@ async function main() {
console.log("--------------------------------");
}

if (networkData.strategies) {
console.log(bold("Fetching strategies"));
// TODO : fix strategy fetching
// if (networkData.strategies) {
// console.log(bold("Fetching strategies"));

const strategyPath = `${dirPath}/${network.network}/strategies`;
createDir(`/${strategyPath}`);
const tokens = Object.keys(networkData.strategies);
for (let i = 0; i < tokens.length; i++) {
const token = tokens[i];
console.log(`Fetching strategies for ${token} from Moralis...`);
const response = await axios(
getMoralisConfig("get" as Method, "getStrategiesForUnderlyingTokens", {
chain: "0x1",
underlyingTokens: [networkData.strategies[token]],
}),
);
const data = response.data.result;
const strategies: STRATEGIES = {};
for (let i = 0; i < data.length; i++) {
const steps = data[i].strategySteps;
// const strategyPath = `${dirPath}/${network.network}/strategies`;
// createDir(`/${strategyPath}`);
// const tokens = Object.keys(networkData.strategies);
// for (let i = 0; i < tokens.length; i++) {
// const token = tokens[i];
// console.log(`Fetching strategies for ${token} from Moralis...`);
// const response = await axios(
// getMoralisConfig("get" as Method, "getStrategiesForUnderlyingTokens", {
// chain: "0x1",
// underlyingTokens: [networkData.strategies[token]],
// }),
// );
// const data = response.data.result;
// const strategies: STRATEGIES = {};
// for (let i = 0; i < data.length; i++) {
// const steps = data[i].strategySteps;

let strategyName: string = token ? token : "";
const strategyData: STRATEGY_DATA[] = [];
for (let i = 0; i < steps.length; i++) {
const step = steps[i];
// let strategyName: string = token ? token : "";
// const strategyData: STRATEGY_DATA[] = [];
// for (let i = 0; i < steps.length; i++) {
// const step = steps[i];

const lpToken = step.lpToken === ETH ? TypedTokens["WETH"] : step.outputToken;
const lpContract = await hre.ethers.getContractAt(ESSENTIAL_CONTRACTS.ERC20, lpToken);
// const lpToken = step.lpToken === ETH ? TypedTokens["WETH"] : step.outputToken;
// const lpContract = await hre.ethers.getContractAt(ESSENTIAL_CONTRACTS.ERC20, lpToken);

let lpTokenSymbol = lpToken;
try {
lpTokenSymbol = lpToken !== hre.ethers.constants.AddressZero ? await lpContract.symbol() : "";
} catch (error: any) {
//A token like MKR does not return string type on call to symbol() or name() function
if (error.message !== "Transaction reverted without a reason string") {
throw error;
}
}
// let lpTokenSymbol = lpToken;
// try {
// lpTokenSymbol = lpToken !== hre.ethers.constants.AddressZero ? await lpContract.symbol() : "";
// } catch (error: any) {
// //A token like MKR does not return string type on call to symbol() or name() function
// if (error.message !== "Transaction reverted without a reason string") {
// throw error;
// }
// }

strategyName = `${strategyName}-${step.isBorrow ? "BORROW" : "DEPOSIT"}-${step.adapterName}${
lpTokenSymbol ? "-" + lpTokenSymbol : ""
}`;
strategyData.push({
contract: step.pool,
outputToken: step.outputToken,
isBorrow: step.isBorrow,
outputTokenSymbol: lpTokenSymbol,
adapterName: `${step.adapterName}Adapter`,
protocol: step.protocol,
});
}
strategies[strategyName] = {
strategyName,
token: networkData.strategies[token],
strategy: strategyData,
};
}
createFile(`${strategyPath}/${token}.json`, JSON.stringify(strategies));
console.log(`✅ Fetched strategies for ${token} successfully.`);
}
}
// strategyName = `${strategyName}-${step.isBorrow ? "BORROW" : "DEPOSIT"}-${step.adapterName}${
// lpTokenSymbol ? "-" + lpTokenSymbol : ""
// }`;
// strategyData.push({
// contract: step.pool,
// outputToken: step.outputToken,
// isBorrow: step.isBorrow,
// outputTokenSymbol: lpTokenSymbol,
// adapterName: `${step.adapterName}Adapter`,
// protocol: step.protocol,
// });
// }
// strategies[strategyName] = {
// strategyName,
// token: networkData.strategies[token],
// strategy: strategyData,
// };
// }
// createFile(`${strategyPath}/${token}.json`, JSON.stringify(strategies));
// console.log(`✅ Fetched strategies for ${token} successfully.`);
// }
// }
}
}
}
Expand Down
16 changes: 4 additions & 12 deletions tasks/actions/vault-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import TASKS from "../task-names";
import { getAddress } from "@ethersproject/address";
import { TypedTokens } from "../../helpers/data";
import { Vault } from "../../typechain";
import proofs from "../../scripts/merkleproofs.json";
import { getAllowWhitelistState } from "../../helpers/utils";

task(TASKS.ACTION_TASKS.VAULT_ACTIONS.NAME, TASKS.ACTION_TASKS.VAULT_ACTIONS.DESCRIPTION)
.addParam("vault", "the address of vault", "", types.string)
.addParam("action", "deposit, withdraw or rebalance", "DEPOSIT" || "WITHDRAW" || "REBALANCE", types.string)
.addParam("user", "account address of the user", "", types.string)
.addParam("merkleProof", "user merkle proof", "", types.string)
.addOptionalParam("useall", "use whole balance", false, types.boolean)
.addOptionalParam("amount", "amount of token", 0, types.int)
.setAction(async ({ vault, action, user, amount, useall }, hre) => {
.setAction(async ({ vault, action, user, amount, useall, merkleProof }, hre) => {
const ACTIONS = ["DEPOSIT", "WITHDRAW", "REBALANCE"];
if (vault === "") {
throw new Error("vault cannot be empty");
Expand Down Expand Up @@ -89,11 +89,7 @@ task(TASKS.ACTION_TASKS.VAULT_ACTIONS.NAME, TASKS.ACTION_TASKS.VAULT_ACTIONS.DES
if (getAllowWhitelistState(await vaultContract.vaultConfiguration())) {
const depositTx = await vaultContract
.connect(userSigner)
.userDepositVault(
checkedAmount,
proofs.filter(x => getAddress(x.account) == getAddress(userSigner.address))[0].proofs,
[],
);
.userDepositVault(checkedAmount, JSON.parse(merkleProof), []);
await depositTx.wait(1);
} else {
const depositTx = await vaultContract.connect(userSigner).userDepositVault(checkedAmount, [], []);
Expand Down Expand Up @@ -141,11 +137,7 @@ task(TASKS.ACTION_TASKS.VAULT_ACTIONS.NAME, TASKS.ACTION_TASKS.VAULT_ACTIONS.DES
if (getAllowWhitelistState(await vaultContract.vaultConfiguration())) {
const withdrawTx = await vaultContract
.connect(userSigner)
.userWithdrawVault(
checkedAmount,
proofs.filter(x => getAddress(x.account) == getAddress(userSigner.address))[0].proofs,
[],
);
.userWithdrawVault(checkedAmount, JSON.parse(merkleProof), []);
await withdrawTx.wait(1);
} else {
const withdrawTx = await vaultContract.connect(userSigner).userWithdrawVault(checkedAmount, [], []);
Expand Down
2 changes: 1 addition & 1 deletion tasks/deployment/deploy-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ task(TASKS.DEPLOYMENT_TASKS.DEPLOY_ADAPTER.NAME, TASKS.DEPLOYMENT_TASKS.DEPLOY_A
.addParam("registry", "the address of registry", "", types.string)
.addParam("name", "the name of adapter", "", types.string)
.addParam("deployedonce", "allow checking whether contracts were deployed previously", true, types.boolean)
.setAction(async ({ registry, name, deployedonce, insertindb }, hre) => {
.setAction(async ({ registry, name, deployedonce }, hre) => {
if (name === "") {
throw new Error("name cannot be empty");
}
Expand Down
2 changes: 1 addition & 1 deletion tasks/deployment/deploy-adapters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import TASKS from "../task-names";
task(TASKS.DEPLOYMENT_TASKS.DEPLOY_ADAPTERS.NAME, TASKS.DEPLOYMENT_TASKS.DEPLOY_ADAPTERS.DESCRIPTION)
.addParam("registry", "the address of registry", "", types.string)
.addParam("deployedonce", "allow checking whether contracts were deployed previously", true, types.boolean)
.setAction(async ({ registry, deployedonce, insertindb }, hre) => {
.setAction(async ({ registry, deployedonce }, hre) => {
if (registry === "") {
throw new Error("registry cannot be empty");
}
Expand Down

0 comments on commit 83883a9

Please sign in to comment.