Skip to content

Commit

Permalink
Merge pull request #29 from Gearbox-protocol/types_fix
Browse files Browse the repository at this point in the history
feat: copy only interface types from contracts
  • Loading branch information
0xmikko.eth authored Aug 29, 2022
2 parents dc21fc8 + 0c27ece commit 3b8d3ef
Show file tree
Hide file tree
Showing 620 changed files with 1,836 additions and 221,945 deletions.
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"build": "tsc",
"dev": "tsc -w",
"pub": "rm -rf ./src/types/hardhat.ts && cp ./src/types/*.d.ts ./lib/types && tsc && yarn publish",
"copyTypes": "node ./scripts/copyTypes.js",
"prepush": "yarn lint --max-warnings=0",
"prepare": "husky install",
"prettier": "prettier --write .",
Expand All @@ -31,8 +32,10 @@
"@commitlint/config-conventional": "^17.0.3",
"@gearbox-protocol/eslint-config": "^1.4.1",
"@gearbox-protocol/prettier-config": "^1.4.1",
"@typechain/ethers-v5": "10.0.0",
"@types/jest": "^28.1.7",
"@types/node": "^18.7.6",
"@types/rimraf": "^3.0.2",
"axios": "^0.27.2",
"dotenv": "^16.0.1",
"eslint": "^8.22.0",
Expand All @@ -41,16 +44,18 @@
"jest": "^28.1.3",
"lint-staged": ">=10",
"prettier": "^2.7.1",
"rimraf": "^3.0.2",
"ts-node": "^10.9.1",
"tslog": "^3.3.3",
"typechain": "^8.1.0",
"typescript": "^4.7.4"
},
"prettier": "@gearbox-protocol/prettier-config",
"lint-staged": {
"*.{ts,js}": [
"*.{ts}": [
"eslint --fix",
"prettier --write"
],
"*.{sol,json,md}": "prettier --write"
"*.{json,md}": "prettier --write"
}
}
35 changes: 35 additions & 0 deletions scripts/copyTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const { resolve } = require("path");
const { sync: rimraf } = require("rimraf");
const { glob, runTypeChain } = require("typechain");

/**
* This script copies required types from contracts repository
* Which is supposed to be available at `../contracts-v2`
*
* Untils contracts-v2 are published, we have to run it manually and commit src/types
*/
async function main() {
const src = resolve(process.cwd(), "../contracts-v2/artifacts");
const dst = resolve(process.cwd(), "src/types");
const allFiles = glob(src, [
// interfaces
"!(build-info)/**/I?([A-Z]|st)+([a-zA-Z0-9_]).json",
"**/interfaces/**/+([a-zA-Z0-9_]).json",
// temporary exceptions
"**/Multicall2.json",
]);

rimraf(dst);

const result = await runTypeChain({
cwd: process.cwd(),
filesToProcess: allFiles,
allFiles,
outDir: dst,
target: "ethers-v5",
});

console.info(`Copied ${result.filesGenerated} files`);
}

main().catch(console.error);
10 changes: 5 additions & 5 deletions src/apy/convexAPY.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import { ConvexPhantomTokenData } from "../tokens/convex";
import { CurveLPTokenData } from "../tokens/curveLP";
import { supportedTokens, tokenDataByNetwork } from "../tokens/token";
import {
CurveV1AdapterStETH,
CurveV1AdapterStETH__factory,
IBaseRewardPool,
IBaseRewardPool__factory,
IConvexToken,
IConvexToken__factory,
ICurvePool,
ICurvePool__factory,
} from "../types";
import { MCall, multicall } from "../utils/multicall";
import { AwaitedRes } from "../utils/types";
Expand Down Expand Up @@ -132,7 +132,7 @@ function getCVXMintAmount(crvAmount: BigNumber, cvxSupply: BigNumber) {

type IBaseRewardPoolInterface = IBaseRewardPool["interface"];
type IConvexTokenInterface = IConvexToken["interface"];
type CurveV1AdapterStETHInterface = CurveV1AdapterStETH["interface"];
type CurveV1AdapterStETHInterface = ICurvePool["interface"];

interface GetPoolDataProps {
basePoolAddress: string;
Expand Down Expand Up @@ -168,7 +168,7 @@ async function getPoolData({
},
{
address: swapPoolAddress,
interface: CurveV1AdapterStETH__factory.createInterface(),
interface: ICurvePool__factory.createInterface(),
method: "get_virtual_price()",
},
{
Expand All @@ -189,7 +189,7 @@ async function getPoolData({
[
AwaitedRes<IBaseRewardPool["rewardRate"]>,
AwaitedRes<IBaseRewardPool["totalSupply"]>,
AwaitedRes<CurveV1AdapterStETH["get_virtual_price"]>,
AwaitedRes<ICurvePool["get_virtual_price"]>,
AwaitedRes<IConvexToken["totalSupply"]>,
...Array<AwaitedRes<IBaseRewardPool["rewardRate"]>>,
]
Expand Down
4 changes: 2 additions & 2 deletions src/pathfinder/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from "../tokens/token";
import { TokenType } from "../tokens/tokenType";
import { YearnLPToken } from "../tokens/yearn";
import { SwapPathFinder__factory } from "../types";
import { ISwapPathFinder__factory } from "../types";
import { detectNetwork } from "../utils/network";
import { PartialRecord } from "../utils/types";
import { pathFindersByNetwork } from "./contracts";
Expand Down Expand Up @@ -113,7 +113,7 @@ export class Path {
});

const lpPaths = await initialPath.withdrawTokens();
const pathFinder = SwapPathFinder__factory.connect(
const pathFinder = ISwapPathFinder__factory.connect(
pathFindersByNetwork[networkType].PATH_FINDER,
provider,
);
Expand Down
2 changes: 1 addition & 1 deletion src/payload/creditAccount.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CreditAccountDataStruct } from "../types/contracts/core/DataCompressor";
import { CreditAccountDataStruct } from "../types/contracts/interfaces/IDataCompressor.sol/IDataCompressor";

export type TokenBalancePayload = CreditAccountDataStruct["balances"];

Expand Down
41 changes: 21 additions & 20 deletions src/strategies/convex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import { ConvexPhantomTokenData } from "../tokens/convex";
import { CurveLPTokenData } from "../tokens/curveLP";
import { supportedTokens, tokenDataByNetwork } from "../tokens/token";
import {
ConvexV1BaseRewardPoolAdapter__factory,
ConvexV1BoosterAdapter__factory,
ConvexV1ClaimZapAdapter__factory,
IBooster__factory,
IClaimZap__factory,
IConvexV1BaseRewardPoolAdapter__factory,
} from "../types";
import { MultiCallStruct } from "../types/contracts/interfaces/ICreditFacade.sol/ICreditFacade";
import { CurveStrategies } from "./curve";
Expand All @@ -26,28 +26,29 @@ export class ConvexBoosterCalls {
amount: BigNumberish,
stake: boolean,
) {
return ConvexV1BoosterAdapter__factory.createInterface().encodeFunctionData(
"deposit",
[pid, amount, stake],
);
return IBooster__factory.createInterface().encodeFunctionData("deposit", [
pid,
amount,
stake,
]);
}

public static depositAll(pid: BigNumberish, stake: boolean) {
return ConvexV1BoosterAdapter__factory.createInterface().encodeFunctionData(
return IBooster__factory.createInterface().encodeFunctionData(
"depositAll",
[pid, stake],
);
}

public static withdraw(pid: BigNumberish, amount: BigNumberish) {
return ConvexV1BoosterAdapter__factory.createInterface().encodeFunctionData(
"withdraw",
[pid, amount],
);
return IBooster__factory.createInterface().encodeFunctionData("withdraw", [
pid,
amount,
]);
}

public static withdrawAll(pid: BigNumberish) {
return ConvexV1BoosterAdapter__factory.createInterface().encodeFunctionData(
return IBooster__factory.createInterface().encodeFunctionData(
"withdrawAll",
[pid],
);
Expand All @@ -56,41 +57,41 @@ export class ConvexBoosterCalls {

export class ConvexPoolCalls {
public static stake(amount: BigNumberish) {
return ConvexV1BaseRewardPoolAdapter__factory.createInterface().encodeFunctionData(
return IConvexV1BaseRewardPoolAdapter__factory.createInterface().encodeFunctionData(
"stake",
[amount],
);
}

public static stakeAll() {
return ConvexV1BaseRewardPoolAdapter__factory.createInterface().encodeFunctionData(
return IConvexV1BaseRewardPoolAdapter__factory.createInterface().encodeFunctionData(
"stakeAll",
);
}

public static withdraw(amount: BigNumberish, claim: boolean) {
return ConvexV1BaseRewardPoolAdapter__factory.createInterface().encodeFunctionData(
return IConvexV1BaseRewardPoolAdapter__factory.createInterface().encodeFunctionData(
"withdraw",
[amount, claim],
);
}

public static withdrawAll(claim: boolean) {
return ConvexV1BaseRewardPoolAdapter__factory.createInterface().encodeFunctionData(
return IConvexV1BaseRewardPoolAdapter__factory.createInterface().encodeFunctionData(
"withdrawAll",
[claim],
);
}

public static withdrawAndUnwrap(amount: BigNumberish, claim: boolean) {
return ConvexV1BaseRewardPoolAdapter__factory.createInterface().encodeFunctionData(
return IConvexV1BaseRewardPoolAdapter__factory.createInterface().encodeFunctionData(
"withdrawAndUnwrap",
[amount, claim],
);
}

public static withdrawAllAndUnwrap(claim: boolean) {
return ConvexV1BaseRewardPoolAdapter__factory.createInterface().encodeFunctionData(
return IConvexV1BaseRewardPoolAdapter__factory.createInterface().encodeFunctionData(
"withdrawAllAndUnwrap",
[claim],
);
Expand All @@ -109,7 +110,7 @@ export class ConvexClaimZapCalls {
spendCvxAmount: BigNumberish,
options: BigNumberish,
) {
return ConvexV1ClaimZapAdapter__factory.createInterface().encodeFunctionData(
return IClaimZap__factory.createInterface().encodeFunctionData(
"claimRewards",
[
rewardContracts,
Expand Down
4 changes: 2 additions & 2 deletions src/strategies/creditFacade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export class CreditFacadeCalls {
minBalance: BigNumberish,
) {
return ICreditFacadeExtended__factory.createInterface().encodeFunctionData(
"revertIfBalanceLessThan",
[token, minBalance],
"revertIfGetLessThan",
[[{ token, balance: minBalance }]],
);
}

Expand Down
Loading

0 comments on commit 3b8d3ef

Please sign in to comment.