Skip to content

Commit

Permalink
Use biome
Browse files Browse the repository at this point in the history
  • Loading branch information
prevostc committed Jun 22, 2024
1 parent f79cbe4 commit d0c562b
Show file tree
Hide file tree
Showing 64 changed files with 1,738 additions and 1,325 deletions.
5 changes: 0 additions & 5 deletions .editorconfig

This file was deleted.

3 changes: 0 additions & 3 deletions .prettierignore

This file was deleted.

8 changes: 0 additions & 8 deletions .prettierrc

This file was deleted.

4 changes: 1 addition & 3 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"recommendations": [
"esbenp.prettier-vscode"
]
"recommendations": ["biomejs.biome"]
}
20 changes: 0 additions & 20 deletions .vscode/launch.json

This file was deleted.

5 changes: 1 addition & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": false,
"prettier.configPath": "${workspaceFolder}/.prettierrc",
"prettier.prettierPath": "${workspaceFolder}/node_modules/.bin/prettier",
"editor.defaultFormatter": "biomejs.biome",
"githubPullRequests.ignoredPullRequestBranches": [
"main"
],
Expand Down
35 changes: 35 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.2/schema.json",
"formatter": {
"enabled": true,
"formatWithErrors": false,
"indentStyle": "space",
"indentWidth": 4,
"lineEnding": "lf",
"lineWidth": 120,
"attributePosition": "auto",
"ignore": [".idea/**", ".vscode/**", "node_modules/**"]
},
"organizeImports": {
"enabled": true,
"ignore": [".idea/**", ".vscode/**", "node_modules/**"]
},
"linter": {
"enabled": true,
"rules": { "recommended": true },
"ignore": [".idea/**", ".vscode/**", "node_modules/**"]
},
"javascript": {
"formatter": {
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"trailingCommas": "es5",
"semicolons": "always",
"arrowParentheses": "asNeeded",
"bracketSpacing": true,
"bracketSameLine": false,
"quoteStyle": "single",
"attributePosition": "auto"
}
}
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
"db:apply-retention": "TS_NODE_FILES=true TS_NODE_TRANSPILE_ONLY=true ts-node ./src/script/db/apply-retention.ts",
"lint:format": "yarn --silent lint:format:solidity && yarn --silent lint:format:typescript",
"lint:format:solidity": "forge fmt",
"lint:format:typescript": "prettier ./src --write --no-color --log-level silent",
"lint:format:typescript": "biome check --write --unsafe ./src",
"test:unit": "yarn --silent test:unit:typescript && yarn --silent test:unit:solidity",
"test:unit:typescript": "DATABASE_URL=ok LOG_LEVEL=error TZ=UTC jest --maxConcurrency=1 2>&1",
"test:unit:solidity": "NO_COLOR=1 forge test --match-contract BeefyHarvestLensTest -vvv",
"test:lint": "yarn --silent test:lint:typescript && yarn --silent test:lint:solidity",
"test:lint:typescript": "prettier ./src --check",
"test:lint:typescript": "biome check ./src",
"test:lint:solidity": "NO_COLOR=1 forge fmt --check",
"test:ts": "tsc --noEmit",
"test:outdated": "ncu",
Expand All @@ -55,6 +55,7 @@
"yargs": "^17.7.2"
},
"devDependencies": {
"@biomejs/biome": "1.8.2",
"@types/async-lock": "^1.4.0",
"@types/jest": "^29.5.4",
"@types/lodash": "^4.14.198",
Expand All @@ -67,14 +68,13 @@
"lint-staged": "^14.0.1",
"npm-check-updates": "^16.14.2",
"pino-pretty": "^10.2.0",
"prettier": "^3.0.3",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"ts-unused-exports": "^10.0.1",
"typescript": "^5.4.5"
},
"lint-staged": {
"*.{js,ts,json}": "prettier ./src --write",
"*.{js,ts,json}": "biome format --write ./src",
"*.sol": "forge fmt"
}
}
7 changes: 6 additions & 1 deletion src/abi/BeefyContractDeployerABI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ export const BeefyContractDeployerABI = [
anonymous: false,
inputs: [
{ indexed: true, internalType: 'bytes32', name: 'salt', type: 'bytes32' },
{ indexed: false, internalType: 'address', name: 'deploymentAddress', type: 'address' },
{
indexed: false,
internalType: 'address',
name: 'deploymentAddress',
type: 'address',
},
],
name: 'ContractDeployed',
type: 'event',
Expand Down
12 changes: 10 additions & 2 deletions src/abi/BeefyHarvestLensABI.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
export const BeefyHarvestLensABI = [
{
inputs: [
{ internalType: 'contract IStrategyV7', name: '_strategy', type: 'address' },
{ internalType: 'contract IERC20', name: '_rewardToken', type: 'address' },
{
internalType: 'contract IStrategyV7',
name: '_strategy',
type: 'address',
},
{
internalType: 'contract IERC20',
name: '_rewardToken',
type: 'address',
},
],
name: 'harvest',
outputs: [
Expand Down
8 changes: 7 additions & 1 deletion src/abi/IStrategyABI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,11 @@ export const IStrategyABI = [
stateMutability: 'nonpayable',
type: 'function',
},
{ inputs: [], name: 'harvest', outputs: [], stateMutability: 'nonpayable', type: 'function' },
{
inputs: [],
name: 'harvest',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
] as const;
4 changes: 2 additions & 2 deletions src/lib/addressbook.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as addressbook from 'blockchain-addressbook';
import { Chain } from './chain';
import { Hex } from 'viem';
import type { Hex } from 'viem';
import type { Chain } from './chain';

export function getChainWNativeTokenDecimals(chain: Chain): number {
if (chain === 'mode') {
Expand Down
8 changes: 6 additions & 2 deletions src/lib/collector-balance.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { WETHABI } from '../abi/WETHABI';
import { getChainWNativeTokenAddress } from './addressbook';
import { Chain } from './chain';
import type { Chain } from './chain';
import { getReadOnlyRpcClient, getWalletAccount } from './rpc-client';

export interface CollectorBalance {
Expand All @@ -23,5 +23,9 @@ export async function fetchCollectorBalance({ chain }: { chain: Chain }): Promis
args: [walletAccount.address],
}),
]);
return { balanceWei, wnativeBalanceWei, aggregatedBalanceWei: balanceWei + wnativeBalanceWei };
return {
balanceWei,
wnativeBalanceWei,
aggregatedBalanceWei: balanceWei + wnativeBalanceWei,
};
}
31 changes: 17 additions & 14 deletions src/lib/config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import dotenv from 'dotenv';
import { allChainIds, type Chain } from './chain';
import type { Hex } from 'viem';
import { bigintMultiplyFloat } from '../util/bigint';
import { allLogLevels } from '../util/logger-type';
import type { LogLevels } from '../util/logger-type';
import { type Chain, allChainIds } from './chain';
import type { RpcConfig } from './rpc-config';
import { Hex } from 'viem';
import { bigintMultiplyFloat } from '../util/bigint';
import { StrategyTypeId } from './vault';
import type { StrategyTypeId } from './vault';
dotenv.config();

const timezone = process.env.TZ;
Expand Down Expand Up @@ -34,7 +34,7 @@ export const DISABLE_COLLECTOR_FOR_CHAINS: Chain[] = (
).filter(chain => allChainIds.includes(chain as Chain)) as Chain[];
export const DISCORD_REPORT_WEBHOOK_URL = process.env.DISCORD_REPORT_WEBHOOK_URL || null;
export const DISCORD_REPORT_ONLY_FOR_CHAINS: Chain[] = ['fraxtal', 'mode', 'scroll'];
export const DISCORD_RATE_LIMIT_MIN_SECONDS_BETWEEN_REQUESTS = parseInt(
export const DISCORD_RATE_LIMIT_MIN_SECONDS_BETWEEN_REQUESTS = Number.parseInt(
process.env.DISCORD_RATE_LIMIT_MIN_SECONDS_BETWEEN_REQUESTS || '10',
10
);
Expand All @@ -46,24 +46,27 @@ export const DISCORD_PING_ROLE_IDS_ON_ERROR = process.env.DISCORD_PING_ROLE_IDS_

// retain all reports for 7 days and daily reports for 30 days
// we need to cleanup reports to avoid breaking heroku's 10k rows limit
export const DB_REPORTS_FULL_RETENTION_IN_DAYS = parseInt(process.env.DB_REPORTS_RETENTION_IN_DAYS || '7', 10);
export const DB_REPORTS_DAILY_RETENTION_IN_DAYS = parseInt(process.env.DB_REPORTS_DAILY_RETENTION_IN_DAYS || '30', 10);
export const DB_REPORTS_FULL_RETENTION_IN_DAYS = Number.parseInt(process.env.DB_REPORTS_RETENTION_IN_DAYS || '7', 10);
export const DB_REPORTS_DAILY_RETENTION_IN_DAYS = Number.parseInt(
process.env.DB_REPORTS_DAILY_RETENTION_IN_DAYS || '30',
10
);

export const REPORT_URL_TEMPLATE = process.env.REPORT_URL_TEMPLATE || 'https://localhost/report/{{reportId}}';
export const CENSOR_SECRETS_FROM_REPORTS = process.env.CENSOR_SECRETS_FROM_REPORTS
? process.env.CENSOR_SECRETS_FROM_REPORTS.split(',')
: [];

export const LENS_DEPLOY_GAS_MULTIPLIER = parseFloat(process.env.LENS_DEPLOY_GAS_MULTIPLIER || '1.3');
export const LENS_DEPLOY_GAS_MULTIPLIER = Number.parseFloat(process.env.LENS_DEPLOY_GAS_MULTIPLIER || '1.3');

const HARVEST_AT_LEAST_EVERY_HOURS = parseInt(process.env.HARVEST_AT_LEAST_EVERY_HOURS || '24', 10);
const HARVEST_GAS_PRICE_MULTIPLIER = parseFloat(process.env.HARVEST_GAS_PRICE_MULTIPLIER || '1.5');
const HARVEST_LIMIT_GAS_AMOUNT_MULTIPLIER = parseFloat(process.env.HARVEST_LIMIT_GAS_AMOUNT_MULTIPLIER || '2.5');
const UNWRAP_LIMIT_GAS_AMOUNT_MULTIPLIER = parseFloat(process.env.UNWRAP_LIMIT_GAS_AMOUNT_MULTIPLIER || '1.5');
const REVENUE_BRIDGE_HARVEST_LIMIT_GAS_AMOUNT_MULTIPLIER = parseFloat(
const HARVEST_AT_LEAST_EVERY_HOURS = Number.parseInt(process.env.HARVEST_AT_LEAST_EVERY_HOURS || '24', 10);
const HARVEST_GAS_PRICE_MULTIPLIER = Number.parseFloat(process.env.HARVEST_GAS_PRICE_MULTIPLIER || '1.5');
const HARVEST_LIMIT_GAS_AMOUNT_MULTIPLIER = Number.parseFloat(process.env.HARVEST_LIMIT_GAS_AMOUNT_MULTIPLIER || '2.5');
const UNWRAP_LIMIT_GAS_AMOUNT_MULTIPLIER = Number.parseFloat(process.env.UNWRAP_LIMIT_GAS_AMOUNT_MULTIPLIER || '1.5');
const REVENUE_BRIDGE_HARVEST_LIMIT_GAS_AMOUNT_MULTIPLIER = Number.parseFloat(
process.env.REVENUE_BRIDGE_HARVEST_LIMIT_GAS_AMOUNT_MULTIPLIER || '1.5'
);
const HARVEST_ENOUGH_GAS_CHECK_MULTIPLIER = parseFloat(process.env.HARVEST_ENOUGH_GAS_CHECK_MULTIPLIER || '2');
const HARVEST_ENOUGH_GAS_CHECK_MULTIPLIER = Number.parseFloat(process.env.HARVEST_ENOUGH_GAS_CHECK_MULTIPLIER || '2');

// some vaults don't get any rewards but are used as colateral by other protocols so we can't retire them
// some stargate vaults are not compatible with the lens since they don't send rewards to the caller immediately
Expand Down
30 changes: 21 additions & 9 deletions src/lib/db/db-report.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { rootLogger } from '../../util/logger';
import { DB_REPORTS_FULL_RETENTION_IN_DAYS, DB_REPORTS_DAILY_RETENTION_IN_DAYS } from '../config';
import { HarvestReport } from '../harvest-report';
import { DB_REPORTS_DAILY_RETENTION_IN_DAYS, DB_REPORTS_FULL_RETENTION_IN_DAYS } from '../config';
import type { HarvestReport } from '../harvest-report';
import { serializeReport } from '../reports';
import { RevenueBridgeHarvestReport } from '../revenue-bridge-harvest-report';
import { UnwrapReport } from '../unwrap-report';
import { AnyReport, ReportType } from './report-types';
import type { RevenueBridgeHarvestReport } from '../revenue-bridge-harvest-report';
import type { UnwrapReport } from '../unwrap-report';
import type { AnyReport, ReportType } from './report-types';
import { db_query, db_query_one } from './utils';

const logger = rootLogger.child({ module: 'db-report' });

export async function applyRetention() {
logger.debug({
msg: 'Applying retention',
data: { DB_REPORTS_FULL_RETENTION_IN_DAYS, DB_REPORTS_DAILY_RETENTION_IN_DAYS },
data: {
DB_REPORTS_FULL_RETENTION_IN_DAYS,
DB_REPORTS_DAILY_RETENTION_IN_DAYS,
},
});
await db_query(
`
Expand All @@ -27,7 +30,10 @@ export async function applyRetention() {
);
logger.info({
msg: 'Retention applied',
data: { DB_REPORTS_FULL_RETENTION_IN_DAYS, DB_REPORTS_DAILY_RETENTION_IN_DAYS },
data: {
DB_REPORTS_FULL_RETENTION_IN_DAYS,
DB_REPORTS_DAILY_RETENTION_IN_DAYS,
},
});
}

Expand All @@ -43,7 +49,10 @@ export function insertRevenueBridgeHarvestReport(report: RevenueBridgeHarvestRep
}

async function insertReport(reportType: ReportType, report: AnyReport): Promise<{ raw_report_id: number }> {
logger.debug({ msg: 'Inserting harvest reports', data: { chain: report.chain, reportType } });
logger.debug({
msg: 'Inserting harvest reports',
data: { chain: report.chain, reportType },
});
const res = await db_query_one<{ raw_report_id: number }>(
`
INSERT INTO raw_report (report_type, chain, datetime, report_content)
Expand All @@ -55,6 +64,9 @@ async function insertReport(reportType: ReportType, report: AnyReport): Promise<
if (!res) {
throw new Error('Failed to insert harvest report');
}
logger.info({ msg: 'Harvest reports inserted', data: { chain: report.chain, reportType } });
logger.info({
msg: 'Harvest reports inserted',
data: { chain: report.chain, reportType },
});
return res;
}
4 changes: 2 additions & 2 deletions src/lib/db/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export async function db_migrate() {
`);
}
for (const chain of allChainIds) {
await db_query(`ALTER TYPE chain_enum ADD VALUE IF NOT EXISTS %L`, [chain]);
await db_query('ALTER TYPE chain_enum ADD VALUE IF NOT EXISTS %L', [chain]);
}

if (!(await typeExists('evm_address_bytea'))) {
Expand Down Expand Up @@ -142,7 +142,7 @@ export async function db_migrate() {
await db_query(`CREATE TYPE report_type AS ENUM ('harvest');`);
}
for (const reportType of allReportTypes) {
await db_query(`ALTER TYPE report_type ADD VALUE IF NOT EXISTS %L`, [reportType]);
await db_query('ALTER TYPE report_type ADD VALUE IF NOT EXISTS %L', [reportType]);
}

await db_query(`
Expand Down
6 changes: 3 additions & 3 deletions src/lib/db/report-types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type HarvestReport } from '../harvest-report';
import { type RevenueBridgeHarvestReport } from '../revenue-bridge-harvest-report';
import { type UnwrapReport } from '../unwrap-report';
import type { HarvestReport } from '../harvest-report';
import type { RevenueBridgeHarvestReport } from '../revenue-bridge-harvest-report';
import type { UnwrapReport } from '../unwrap-report';

export type ReportType = 'harvest' | 'unwrap' | 'revenue-bridge-harvest';

Expand Down
Loading

0 comments on commit d0c562b

Please sign in to comment.