Skip to content

Commit

Permalink
feat: migrate to viem
Browse files Browse the repository at this point in the history
BREAKING CHANGE: almost complete rewrite
  • Loading branch information
doomsower committed Jun 24, 2024
1 parent cd821a9 commit 686957f
Show file tree
Hide file tree
Showing 122 changed files with 7,820 additions and 4,094 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches:
- "main"
- "beta"
workflow_dispatch:
workflow_dispatch:

env:
HUSKY: 0
Expand Down
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"skipFiles": ["<node_internals>/**"],
"program": "${workspaceFolder}/build/index.js",
"preLaunchTask": "tsc: build - tsconfig.json",
"outFiles": ["${workspaceFolder}/build/**/*.js"]
"outFiles": ["${workspaceFolder}/build/**/*.js"],
"envFile": "${workspaceFolder}/.env"
}
]
}
17 changes: 12 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:20.11 as dev
FROM node:20.14 as dev

ENV YARN_CACHE_FOLDER=/root/.yarn

Expand All @@ -7,12 +7,12 @@ WORKDIR /app
COPY . .

RUN --mount=type=cache,id=yarn,target=/root/.yarn \
yarn install --frozen-lockfile \
yarn install --frozen-lockfile --ignore-engines \
&& yarn build

# Production npm modules

FROM node:20.11 as prod
FROM node:20.14 as prod

ENV YARN_CACHE_FOLDER=/root/.yarn

Expand All @@ -22,7 +22,13 @@ COPY --from=dev /app/package.json /app
COPY --from=dev /app/build/ /app/build

RUN --mount=type=cache,id=yarn,target=/root/.yarn \
yarn install --production --frozen-lockfile
yarn install --production --frozen-lockfile --ignore-engines

# Install foundy
ENV FOUNDRY_DIR=/root/.foundry
RUN mkdir ${FOUNDRY_DIR} && \
curl -L https://foundry.paradigm.xyz | bash && \
${FOUNDRY_DIR}/bin/foundryup

# Final image

Expand All @@ -33,4 +39,5 @@ LABEL org.opencontainers.image.version="${PACKAGE_VERSION}"

WORKDIR /app
COPY --from=prod /app /app
CMD ["/app/build/index.js"]
COPY --from=prod /root/.foundry/bin/cast /app
CMD ["--enable-source-maps", "/app/build/index.mjs"]
59 changes: 29 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,35 @@ This mode increases protocol security showing potential problems with liquidatio

Use environment variables to configure bot

| Variable | Required | Example | Description |
| ----------------------- | -------- | -------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| APP_NAME | | `Terminator2` | App name to use in logs |
| PORT | | `4000` | Healthcheck endpoint port |
| ADDRESS_PROVIDER || `0x95f4cea53121b8A2Cb783C6BFB0915cEc44827D3` | Override address provider address (defaults to address from SDK) |
| JSON_RPC_PROVIDERS || `https://goerli.infura.io/v3/<key>` | Comma-separated list of ethereum JSON RPC endpoints |
| FLASHBOTS_RPC | | `https://rpc.flashbots.net` | Optional flashbots RPC endpoint for frontrunning protection (https://docs.flashbots.net/flashbots-protect/overview) |
| JSON_RPC_TIMEOUT | | `240000` | JSONRPC calls timeout With freshly started fork first requests often fail with default ethers.js timeout of 120 seconds. In this case, increase this timeout (the value is in ms) |
| PRIVATE_KEY || `<private_key>` | Private key for core wallet |
| WALLET_PASSWORD || `<password>` | Password for keys storage |
| HF_TRESHOLD | | `9950` | Health factor threshold for liquidations |
| UNDERLYING | | `DAI` | If set, liquidator will only work with credit manager for this underlying token symbol |
| CLOUDAMQP_URL | | `amqps://host:port` | AMQP instance to send logs to |
| AMPQ_EXCHANGE | | `GOERLI` | AMQP exchange to send logs to |
| SKIP_BLOCKS | | `3` | How many block should be skipped before next check in normal mode |
| MULTICALL_CHUNK | | `30` | Multicall chunk size used when getting accounts data |
| KEY_PATH || `/foo/bar` | Directory with wallet keys. Either this or `KEY_SECRET` is required. |
| KEY_SECRET | | `<secret-id>` | AWS Secrets Manager secret id for wallet keys |
| OPTIMISTIC_LIQUIDATIONS | | `true` | Set to `true` to enable optimistic mode |
| EXECUTORS_QTY | | `3` | How many executors who send liquidation transactions in parallel |
| SWAP_TO_ETH | | `uniswap`/`1inch` | If set, will try to swap underlying token to ETH after liquidation (only in optimistic mode) |
| BALANCE_TO_NOTIFY | | `0` | Minimum balance (in wei), when signer has less, it will send notifications in AMPQ |
| SLIPPAGE | | `0` | Slippage for finding path [0;1] represents 0-100% |
| LOG_LEVEL | | `debug` | Min log level |
| OUT_SUFFIX | | `ts` | Output suffix to distinguish outputs of different liquidators |
| OUT_DIR | | `/foo/bar` | Directory to output logs, leave empty if you don't need file output. Only one of `OUT_DIR`, `OUT_ENDPOINT`, `OUT_S3_BUCKET` will be used |
| OUT_ENDPOINT | | `https://dump.logs.io/here` | Endpoint to send POST-request with output |
| OUT_HEADERS | | `{"Authorization": "Bearer XXX"}` | HTTP headers to send with POST request. Serialized as JSON: `{"header1": "value1", "header2": "value2"}` |
| OUT_S3_BUCKET | | `my_bucket` | S3 bucket to upload result to |
| OUT_S3_PREFIX | | `optimistc` | S3 path prefix |
| Environment Variable Name | Description |
| -------------------------------------- | --------------------------------------------------------------------------- |
| ADDRESS_PROVIDER | Address provider address override (optional) |
| APP_NAME | Application name, for logging |
| DEBUG_ACCOUNTS | Debug accounts (optional) |
| DEBUG_MANAGERS | Debug managers (optional) |
| CAST_BIN | Path to foundry/cast binary (optional) |
| DEPLOY_PARTIAL_LIQUIDATOR | Deploy partial liquidator contracts (optional) |
| JSON_RPC_PROVIDERS / JSON_RPC_PROVIDER | Ethereum provider RPCs (optional) |
| HF_TRESHOLD | HF threshold, default is 65536 |
| RESTAKING_WORKAROUND | Restaking workaround (optional) |
| MIN_BALANCE | Minimum balance for notification, default is 500000000000000000n (optional) |
| ONE_INCH_API_KEY | 1inch API key (optional) |
| OPTIMISTIC | Optimistic liquidations (optional) |
| OUT_DIR | Output directory, default is "." |
| OUT_ENDPOINT | Output endpoint URL (optional) |
| OUT_HEADERS | Output headers, default is "{}" |
| OUT_SUFFIX | Output suffix, default is "ts" |
| OUT_S3_BUCKET | Output S3 bucket (optional) |
| OUT_S3_PREFIX | Output S3 prefix, default is "" |
| PARTIAL_LIQUIDATOR_ADDRESS | Partial liquidator address (optional) |
| PRIVATE_KEY | Private key |
| PORT | Port number, default is 4000 |
| SLIPPAGE | Slippage, default is 50 |
| SWAP_TO_ETH | Swap to ETH method, can be "1inch" or "uniswap" (optional) |
| UNDERLYING | Underlying asset (optional) |
| TELEGRAM_BOT_TOKEN | Telegram bot token (optional) |
| TELEGRAM_NOTIFICATIONS_CHANNEL | Telegram notifications channel, must start with "-" (optional) |
| TELEGRAM_ALERTS_CHANNEL | Telegram alerts channel, must start with "-" (optional) |

## How to launch

Expand Down
27 changes: 27 additions & 0 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { build } from "esbuild";

build({
entryPoints: ["src/index.ts"],
outdir: "build",
bundle: true,
platform: "node",
format: "esm",
outExtension: { ".js": ".mjs" },
target: ["node20"],
sourcemap: "external",
dropLabels: ["DEV"],
banner: {
js: `
import { createRequire } from 'module';
import { fileURLToPath } from 'url';
const require = createRequire(import.meta.url);
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
`,
},
external: ["node-pty", "pino-pretty"],
}).catch(e => {
console.error(e);
process.exit(1);
});
72 changes: 32 additions & 40 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
"version": "1.0.0",
"license": "MIT",
"private": true,
"bin": {
"tsliq": "./lib/index.js"
},
"type": "module",
"scripts": {
"clean": "rm -rf build",
"build": "tsc --p tsconfig.build.json",
"start": "ts-node src/index.ts",
"build": "node esbuild.config.mjs",
"start": "tsx --env-file .env src/index.ts",
"prepare": "husky",
"prettier": "prettier --write .",
"prettier:ci": "npx prettier --check .",
Expand All @@ -20,50 +18,44 @@
"test": "vitest"
},
"dependencies": {
"@aws-sdk/client-s3": "3.572.0",
"@aws-sdk/client-secrets-manager": "3.572.0",
"@gearbox-protocol/devops": "^1.6.3",
"@gearbox-protocol/sdk": "3.0.0-next.178",
"@redstone-finance/evm-connector": "^0.3.6",
"@types/commander": "^2.12.2",
"@uniswap/sdk-core": "^4.2.0",
"@uniswap/v3-sdk": "^3.11.1",
"amqplib": "^0.10.3",
"async-mutex": "^0.4.1",
"axios": "^1.6.8",
"axios-retry": "^4.1.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"cors": "^2.8.5",
"date-fns": "^3.6.0",
"dotenv": "^16.4.5",
"ethers": "^5.7.1",
"lodash": "^4.17.21",
"p-retry": "4.6.2",
"pino": "^8.19.0",
"redstone-protocol": "^1.0.5",
"reflect-metadata": "^0.2.2",
"tslib": "^2.6.2",
"tslog": "^4.9.2",
"typedi": "^0.10.0"
"node-pty": "^1.0.0"
},
"devDependencies": {
"@aws-sdk/client-s3": "^3.600.0",
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"@flashbots/ethers-provider-bundle": "^1.0.0",
"@gearbox-protocol/eslint-config": "2.0.0-next.2",
"@gearbox-protocol/liquidator-v2-contracts": "^2.1.0-next.17",
"@gearbox-protocol/prettier-config": "2.0.0-next.0",
"@types/amqplib": "^0.10.5",
"@types/node": "^20.12.11",
"@gearbox-protocol/sdk-gov": "^2.8.1",
"@gearbox-protocol/types": "^1.9.2",
"@redstone-finance/evm-connector": "^0.5.4",
"@types/node": "^20.14.6",
"@uniswap/sdk-core": "^5.3.1",
"@uniswap/v3-sdk": "^3.13.1",
"@vlad-yakovlev/telegram-md": "^2.0.0",
"abitype": "^1.0.2",
"axios-retry": "^4.4.0",
"axios": "^1.7.2",
"date-fns": "^3.6.0",
"di-at-home": "^0.0.7",
"dotenv": "^16.4.5",
"esbuild": "^0.21.5",
"eslint": "^8.57.0",
"ethers": "^6.13.1",
"husky": "^9.0.11",
"lint-staged": "^15.2.2",
"prettier": "^3.2.5",
"ts-node": "^10.9.1",
"lint-staged": "^15.2.7",
"nanoid": "^5.0.7",
"node-pty": "^1.0.0",
"pino-pretty": "^11.2.1",
"pino": "^9.2.0",
"prettier": "^3.3.2",
"redstone-protocol": "^1.0.5",
"tsx": "^4.15.6",
"typescript": "^5.4.5",
"vitest": "^1.5.3"
},
"resolutions": {
"**/@gearbox-protocol/sdk-gov": "^1.69.2"
"viem": "^2.15.1",
"vitest": "^1.5.2"
},
"prettier": "@gearbox-protocol/prettier-config",
"lint-staged": {
Expand Down
Loading

0 comments on commit 686957f

Please sign in to comment.