Skip to content

Commit b49305e

Browse files
committed
feat: add erc4626 wrapper strategy
1 parent 7205ea4 commit b49305e

File tree

15 files changed

+984
-35
lines changed

15 files changed

+984
-35
lines changed

.env.template

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Environment Configuration
22
NODE_ENV="development" # Options: 'development', 'production'
33
PORT="3001"
4-
HOST="localhost" # Hostname for the server
54

65
# CORS Settings
76
CORS_ORIGIN="*" # Allowed CORS origin, adjust as necessary

src/common/middleware/rateLimiter.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import type { Request } from "express"
22
import { rateLimit } from "express-rate-limit"
33

4-
import { env } from "@/common/utils/envConfig"
5-
64
const rateLimiter = rateLimit({
75
legacyHeaders: true,
8-
limit: env.COMMON_RATE_LIMIT_MAX_REQUESTS,
6+
limit: Number(process.env.COMMON_RATE_LIMIT_MAX_REQUESTS || 20),
97
message: "Too many requests, please try again later.",
108
standardHeaders: true,
11-
windowMs: env.COMMON_RATE_LIMIT_WINDOW_MS,
9+
windowMs: Number(process.env.COMMON_RATE_LIMIT_WINDOW_MS || 1000),
1210
keyGenerator: (req: Request) => req.ip as string,
1311
})
1412

src/common/middleware/requestLogger.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import { StatusCodes, getReasonPhrase } from "http-status-codes"
55
import type { LevelWithSilent } from "pino"
66
import { type CustomAttributeKeys, type Options, pinoHttp } from "pino-http"
77

8-
import { env } from "@/common/utils/envConfig"
9-
108
enum LogLevel {
119
Fatal = "fatal",
1210
Error = "error",
@@ -26,7 +24,7 @@ type PinoCustomProps = {
2624

2725
const requestLogger = (options?: Options): RequestHandler[] => {
2826
const pinoOptions: Options = {
29-
enabled: env.isProduction,
27+
enabled: !!process.env.isProduction,
3028
customProps: customProps as unknown as Options["customProps"],
3129
redact: [],
3230
genReqId,
@@ -56,7 +54,7 @@ const customProps = (req: Request, res: Response): PinoCustomProps => ({
5654
})
5755

5856
const responseBodyMiddleware: RequestHandler = (_req, res, next) => {
59-
const isNotProduction = !env.isProduction
57+
const isNotProduction = !!process.env.isProduction
6058
if (isNotProduction) {
6159
const originalSend = res.send
6260
res.send = (content) => {

src/common/utils/envConfig.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { env } from "@/common/utils/envConfig"
21
import { app, logger } from "@/server"
2+
import dotenv from "dotenv"
33

4-
const server = app.listen(env.PORT, () => {
5-
const { NODE_ENV, HOST, PORT } = env
6-
logger.info(`Server (${NODE_ENV}) running on port http://${HOST}:${PORT}`)
4+
dotenv.config()
5+
6+
const server = app.listen(process.env.PORT, () => {
7+
const { NODE_ENV, PORT } = process.env
8+
logger.info(`Server (${NODE_ENV}) running on port http://localhost:${PORT}`)
79
})
810

911
const onCloseSignal = () => {

src/server.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { swapRouter } from "@/api/routes/swap/swapRouter"
99
import errorHandler from "@/common/middleware/errorHandler"
1010
import rateLimiter from "@/common/middleware/rateLimiter"
1111
import requestLogger from "@/common/middleware/requestLogger"
12-
import { env } from "@/common/utils/envConfig"
1312

1413
const logger = pino({ name: "server start" })
1514
const app: Express = express()
@@ -20,7 +19,7 @@ const app: Express = express()
2019
// Middlewares
2120
app.use(express.json())
2221
app.use(express.urlencoded({ extended: true }))
23-
app.use(cors({ origin: env.CORS_ORIGIN, credentials: true }))
22+
app.use(cors({ origin: process.env.CORS_ORIGIN, credentials: true }))
2423
app.use(helmet())
2524
app.use(rateLimiter)
2625

src/swapService/config/mainnet.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
Strategy1Inch,
44
StrategyBalmySDK,
55
StrategyCombinedUniswap,
6+
StrategyERC4626Wrapper,
67
StrategyLifi,
78
StrategyMTBILL,
89
StrategyPendle,
@@ -15,9 +16,14 @@ const EBTC_MAINNET = "0x657e8c867d8b37dcc18fa4caead9c45eb088c642"
1516
const SCRVUSD_MAINNET = "0x0655977feb2f289a4ab78af67bab0d17aab84367"
1617
const USD3_MAINNET = "0x0d86883faf4ffd7aeb116390af37746f45b6f378"
1718
const EUSD_MAINNET = "0xa0d69e286b938e21cbf7e51d71f6a4c8918f482f"
19+
const WSTUSR_MAINNET = "0x1202f5c7b4b9e47a1a484e8b270be34dbbc75055"
1820

1921
const mainnetRoutingConfig: ChainRoutingConfig = [
2022
// WRAPPERS
23+
{
24+
strategy: StrategyERC4626Wrapper.name(),
25+
match: {},
26+
},
2127
{
2228
strategy: StrategyRepayWrapper.name(),
2329
match: {
@@ -56,6 +62,7 @@ const mainnetRoutingConfig: ChainRoutingConfig = [
5662
USD3_MAINNET,
5763
EUSD_MAINNET,
5864
SCRVUSD_MAINNET,
65+
WSTUSR_MAINNET,
5966
],
6067
},
6168
},
@@ -109,6 +116,20 @@ const mainnetRoutingConfig: ChainRoutingConfig = [
109116
// then anything available through balmy. Overswap exact out
110117
{
111118
strategy: StrategyBalmySDK.name(),
119+
config: {
120+
sourcesFilter: {
121+
includeSources: [
122+
"kyberswap",
123+
"paraswap",
124+
"odos",
125+
"1inch",
126+
"li-fi",
127+
"open-ocean",
128+
"conveyor",
129+
"uniswap",
130+
],
131+
},
132+
},
112133
match: {},
113134
},
114135
]

src/swapService/runner.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ export async function runPipeline(
6161
return finalResult.response
6262
}
6363

64+
// TODO tokenlist, interfaces
6465
// TODO error handling
6566
// TODO npm interfaces, supported chains
6667
// TODO cache pipeline
6768
// TODO env validation
6869
// TODO logging
70+
// TODO pendle rollover

src/swapService/strategies/balmySDK/customSourceList.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ export class CustomSourceList extends LocalSourceList {
2020
...mutableThis.sources,
2121
...customSources,
2222
}
23+
delete mutableThis.sources.balmy
2324
}
2425
}

src/swapService/strategies/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Strategy1Inch } from "./strategy1Inch"
22
import { StrategyBalmySDK } from "./strategyBalmySDK"
33
import { StrategyCombinedUniswap } from "./strategyCombinedUniswap"
4+
import { StrategyERC4626Wrapper } from "./strategyERC4626Wrapper"
45
import { StrategyLifi } from "./strategyLifi"
56
import { StrategyMTBILL } from "./strategyMTBILL"
67
import { StrategyPendle } from "./strategyPendle"
@@ -14,6 +15,7 @@ export {
1415
StrategyLifi,
1516
StrategyRepayWrapper,
1617
StrategyBalmySDK,
18+
StrategyERC4626Wrapper,
1719
}
1820

1921
export const strategies = {
@@ -24,4 +26,5 @@ export const strategies = {
2426
[StrategyRepayWrapper.name()]: StrategyRepayWrapper,
2527
[StrategyBalmySDK.name()]: StrategyBalmySDK,
2628
[StrategyLifi.name()]: StrategyLifi,
29+
[StrategyERC4626Wrapper.name()]: StrategyERC4626Wrapper,
2730
}

0 commit comments

Comments
 (0)