Skip to content

Commit 6aaee8b

Browse files
committed
Merge branch 'master' into development
2 parents 0978098 + 4c7adf1 commit 6aaee8b

File tree

12 files changed

+387
-18
lines changed

12 files changed

+387
-18
lines changed

src/api/routes/swap/swapRouter.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ import {
1010
} from "@/common/utils/httpHandlers"
1111
import { findSwaps } from "@/swapService/runner"
1212
import type { SwapParams } from "@/swapService/types"
13-
import { ApiError, findToken, getSwapper } from "@/swapService/utils"
13+
import {
14+
ApiError,
15+
findToken,
16+
getSwapper,
17+
parseHrtimeToSeconds,
18+
} from "@/swapService/utils"
1419
import { StatusCodes } from "http-status-codes"
1520
import { InvalidAddressError } from "viem"
1621
import { z } from "zod"
@@ -66,7 +71,28 @@ swapRouter.get(
6671
validateRequest(getSwapSchema),
6772
async (req: Request, res: Response) => {
6873
try {
69-
const swaps = await findSwaps(parseRequest(req))
74+
const startTime = process.hrtime()
75+
const swapParams = parseRequest(req)
76+
const swaps = await findSwaps(swapParams)
77+
const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(startTime))
78+
console.log("ROUTE EXECUTING")
79+
if (elapsedSeconds > 10) {
80+
console.log(
81+
`SLOW ROUTE [10]: ${swapParams.swapperMode} ${elapsedSeconds}s`,
82+
)
83+
} else if (elapsedSeconds > 5) {
84+
console.log(
85+
`SLOW ROUTE [5]: ${swapParams.swapperMode} ${elapsedSeconds}s`,
86+
)
87+
} else if (elapsedSeconds > 3) {
88+
console.log(
89+
`SLOW ROUTE [3]: ${swapParams.swapperMode} ${elapsedSeconds}s`,
90+
)
91+
} else if (elapsedSeconds > 1) {
92+
console.log(
93+
`SLOW ROUTE [1]: ${swapParams.swapperMode} ${elapsedSeconds}s`,
94+
)
95+
}
7096
return handleServiceResponse(
7197
ServiceResponse.success<SwapResponse>(swaps),
7298
res,

src/swapService/config/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export const SWAP_DEFAULT_DEADLINE = 1800n
22
export const BINARY_SEARCH_TIMEOUT_SECONDS = 30
3+
export const LOG_SLOW_QUERY_TIMEOUT_SECONDS = 10

src/swapService/config/default.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ const defaultRoutingConfig: ChainRoutingConfig = [
2323
"li-fi",
2424
"open-ocean",
2525
"uniswap",
26-
"0x",
2726
"oku",
2827
"magpie",
28+
"enso",
2929
],
3030
},
3131
},

src/swapService/config/mainnet.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ const mainnetRoutingConfig: ChainRoutingConfig = [
7171
"li-fi",
7272
"open-ocean",
7373
"magpie",
74-
"0x",
7574
],
7675
},
7776
},
@@ -86,13 +85,11 @@ const mainnetRoutingConfig: ChainRoutingConfig = [
8685
sourcesFilter: {
8786
includeSources: [
8887
"kyberswap",
89-
// "paraswap",
9088
"odos",
9189
"1inch",
9290
"li-fi",
9391
"open-ocean",
9492
"magpie",
95-
"0x",
9693
"enso",
9794
"pendle",
9895
],
@@ -125,13 +122,11 @@ const mainnetRoutingConfig: ChainRoutingConfig = [
125122
sourcesFilter: {
126123
includeSources: [
127124
"kyberswap",
128-
// "paraswap",
129125
"odos",
130126
"1inch",
131127
"li-fi",
132128
"open-ocean",
133129
"magpie",
134-
"0x",
135130
"enso",
136131
"pendle",
137132
],

src/swapService/runner.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { SwapResponse } from "@/api/routes/swap/swapModel"
21
import { StatusCodes } from "http-status-codes"
32
import { isHex } from "viem"
43
import { getRoutingConfig } from "./config"
@@ -74,6 +73,7 @@ export async function runPipeline(
7473
// )
7574

7675
// console.log('finalResult.quotes: ', JSON.stringify(finalResult.quotes, null, 2));
76+
7777
return finalResult.quotes
7878
}
7979

@@ -95,10 +95,3 @@ export async function findSwaps(swapParams: SwapParams) {
9595

9696
return quotes
9797
}
98-
99-
// TODO timeouts on balmy
100-
// TODO review and add sources
101-
// TODO tokenlist, interfaces
102-
// TODO price impact
103-
// TODO logging - detect when fallback kicks
104-
// In wreapper strategy return dust to the original wrapper asset - deposit for EOA owner

src/swapService/strategies/balmySDK/customSourceList.ts

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
import type { IFetchService, IProviderService } from "@balmy/sdk"
1+
import { LOG_SLOW_QUERY_TIMEOUT_SECONDS } from "@/swapService/config/constants"
2+
import { parseHrtimeToSeconds } from "@/swapService/utils"
3+
import type {
4+
IFetchService,
5+
IProviderService,
6+
SourceId,
7+
SourceListQuoteRequest,
8+
SourceListQuoteResponse,
9+
} from "@balmy/sdk"
210
import { LocalSourceList } from "@balmy/sdk/dist/services/quotes/source-lists/local-source-list"
11+
import { stringify } from "viem"
12+
import { CustomKyberswapQuoteSource } from "./sources/kyberswapQuoteSource"
313
import { CustomLiFiQuoteSource } from "./sources/lifiQuoteSource"
414
import { CustomMagpieQuoteSource } from "./sources/magpieQuoteSource"
515
import { CustomNeptuneQuoteSource } from "./sources/neptuneQuoteSource"
@@ -26,6 +36,7 @@ const customSources = {
2636
oogabooga: new CustomOogaboogaQuoteSource(),
2737
uniswap: new CustomUniswapQuoteSource(),
2838
magpie: new CustomMagpieQuoteSource(),
39+
kyberswap: new CustomKyberswapQuoteSource(),
2940
oku_bob_icecreamswap: new CustomOkuQuoteSource(
3041
"icecreamswap",
3142
"IceCreamSwap",
@@ -43,5 +54,58 @@ export class CustomSourceList extends LocalSourceList {
4354
...customSources,
4455
}
4556
delete mutableThis.sources.balmy
57+
58+
// wrap getQuote in timer
59+
const getQuoteSuper = mutableThis.getQuote.bind(this)
60+
61+
mutableThis.getQuote = async (
62+
request: SourceListQuoteRequest,
63+
sourceId: SourceId,
64+
): Promise<SourceListQuoteResponse> => {
65+
const startTime = process.hrtime()
66+
const result = await getQuoteSuper(request, sourceId)
67+
const elapsedSeconds = parseHrtimeToSeconds(process.hrtime(startTime))
68+
// if (elapsedSeconds > LOG_SLOW_QUERY_TIMEOUT_SECONDS) {
69+
// const { chainId, sellToken, buyToken, order } = request
70+
// const requestGist = {
71+
// chainId,
72+
// sellToken,
73+
// buyToken,
74+
// order,
75+
// }
76+
// console.log(
77+
// `SLOW QUERY: ${sourceId} ${elapsedSeconds}s ${stringify(requestGist)}`,
78+
// )
79+
// }
80+
const { chainId, sellToken, buyToken, order } = request
81+
const requestGist = {
82+
chainId,
83+
sellToken,
84+
buyToken,
85+
order,
86+
}
87+
console.log(
88+
`QUERY EXECUTING: ${sourceId} ${elapsedSeconds}s ${stringify(requestGist)}`,
89+
)
90+
if (elapsedSeconds > 10) {
91+
console.log(
92+
`SLOW QUERY [10]: ${sourceId} ${elapsedSeconds}s ${stringify(requestGist)}`,
93+
)
94+
} else if (elapsedSeconds > 5) {
95+
console.log(
96+
`SLOW QUERY [5]: ${sourceId} ${elapsedSeconds}s ${stringify(requestGist)}`,
97+
)
98+
} else if (elapsedSeconds > 3) {
99+
console.log(
100+
`SLOW QUERY [3]: ${sourceId} ${elapsedSeconds}s ${stringify(requestGist)}`,
101+
)
102+
} else if (elapsedSeconds > 1) {
103+
console.log(
104+
`SLOW QUERY [1]: ${sourceId} ${elapsedSeconds}s ${stringify(requestGist)}`,
105+
)
106+
}
107+
108+
return result
109+
}
46110
}
47111
}

0 commit comments

Comments
 (0)