Skip to content

Commit 047c769

Browse files
committed
feat: use balmy for default strategies
1 parent ba444ba commit 047c769

File tree

4 files changed

+52
-24
lines changed

4 files changed

+52
-24
lines changed

src/swapService/config/mainnet.ts

+14-13
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ const WSTUSR_MAINNET = "0x1202f5c7b4b9e47a1a484e8b270be34dbbc75055"
2020

2121
const mainnetRoutingConfig: ChainRoutingConfig = [
2222
// WRAPPERS
23-
{
24-
strategy: StrategyERC4626Wrapper.name(),
25-
match: {},
26-
},
2723
{
2824
strategy: StrategyRepayWrapper.name(),
2925
match: {
@@ -42,6 +38,12 @@ const mainnetRoutingConfig: ChainRoutingConfig = [
4238
tokensInOrOut: [MTBILL_MAINNET],
4339
},
4440
},
41+
{
42+
strategy: StrategyERC4626Wrapper.name(),
43+
match: {
44+
tokensInOrOut: [WSTUSR_MAINNET],
45+
},
46+
},
4547
{
4648
strategy: StrategyBalmySDK.name(),
4749
config: {
@@ -67,17 +69,11 @@ const mainnetRoutingConfig: ChainRoutingConfig = [
6769
},
6870
},
6971
{
70-
strategy: StrategyLifi.name(),
71-
match: {
72-
tokensInOrOut: [SUSDS_MAINNET],
73-
},
74-
},
75-
{
76-
// sUSDS fallback
72+
// sUSDS
7773
strategy: StrategyBalmySDK.name(),
7874
config: {
7975
sourcesFilter: {
80-
includeSources: ["paraswap", "open-ocean"],
76+
includeSources: ["paraswap", "open-ocean", "li-fi", "odos", "1inch"],
8177
},
8278
tryExactOut: true,
8379
},
@@ -87,7 +83,12 @@ const mainnetRoutingConfig: ChainRoutingConfig = [
8783
},
8884
// DEFAULTS
8985
{
90-
strategy: Strategy1Inch.name(),
86+
strategy: StrategyBalmySDK.name(),
87+
config: {
88+
sourcesFilter: {
89+
includeSources: ["1inch"],
90+
},
91+
},
9192
match: {
9293
swapperModes: [SwapperMode.EXACT_IN],
9394
},

src/swapService/quoters/quoterLifi.ts

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export async function fetchLiFiExactInQuote(
5454
})
5555

5656
const url = `https://li.quest/v1/quote?${params.toString()}`
57+
console.log("url: ", url)
5758
const requestHeaders = new Headers()
5859
if (process.env.LIFI_API_KEY)
5960
requestHeaders.set("x-lifi-api-key", process.env.LIFI_API_KEY)

src/swapService/runner.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,9 @@ export async function runPipeline(
6161
return finalResult.response
6262
}
6363

64+
// TODO timeouts on balmy
6465
// TODO tokenlist, interfaces
6566
// TODO price impact
66-
// TODO error handling
67-
// TODO npm interfaces, supported chains
68-
// TODO cache pipeline
67+
// TODO cache pipeline, tokenlists
6968
// TODO logging
7069
// TODO pendle rollover

src/swapService/strategies/strategyBalmySDK.ts

+35-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import {
99
import { buildFetchService } from "@balmy/sdk/dist/sdk/builders/fetch-builder"
1010
import { buildProviderService } from "@balmy/sdk/dist/sdk/builders/provider-builder"
1111
import type { Either } from "@balmy/sdk/dist/utility-types"
12-
import { type Hex, encodeAbiParameters, parseAbiParameters } from "viem"
12+
import {
13+
type Address,
14+
type Hex,
15+
encodeAbiParameters,
16+
parseAbiParameters,
17+
} from "viem"
1318
import { SwapperMode } from "../interface"
1419
import type { StrategyResult, SwapParams, SwapQuote } from "../types"
1520
import {
@@ -27,6 +32,7 @@ import {
2732
import { CustomSourceList } from "./balmySDK/customSourceList"
2833

2934
const DAO_MULTISIG = "0xcAD001c30E96765aC90307669d578219D4fb1DCe"
35+
// TODO config
3036
const BINARY_SEARCH_EXCLUDE_SOURCES = ["paraswap"] // paraswap is rate limited and fails if selected as best source for binary search
3137

3238
type SourcesFilter =
@@ -40,7 +46,15 @@ type SourcesFilter =
4046
>
4147
| undefined
4248

43-
export const defaultConfig = {
49+
export const defaultConfig: {
50+
referrer: {
51+
address: Address
52+
name: string
53+
}
54+
sourcesFilter: SourcesFilter
55+
tryExactOut?: boolean
56+
onlyExactOut?: boolean
57+
} = {
4458
referrer: {
4559
address: DAO_MULTISIG,
4660
name: "euler",
@@ -226,12 +240,25 @@ export class StrategyBalmySDK {
226240
swapperMode: SwapperMode.EXACT_IN,
227241
}
228242

229-
const reverseQuote = await fetchQuote(
230-
reverseSwapParams,
231-
this.config.sourcesFilter || {
232-
excludeSources: BINARY_SEARCH_EXCLUDE_SOURCES,
233-
},
234-
) // TODO config
243+
let sourcesFilter
244+
if (this.config.sourcesFilter?.includeSources) {
245+
sourcesFilter = {
246+
includeSources: this.config.sourcesFilter.includeSources.filter(
247+
(s) => !BINARY_SEARCH_EXCLUDE_SOURCES.includes(s),
248+
),
249+
}
250+
} else if (this.config.sourcesFilter?.excludeSources) {
251+
sourcesFilter = {
252+
excludeSources: [
253+
...this.config.sourcesFilter.excludeSources,
254+
...BINARY_SEARCH_EXCLUDE_SOURCES,
255+
],
256+
}
257+
} else {
258+
sourcesFilter = { excludeSources: BINARY_SEARCH_EXCLUDE_SOURCES }
259+
}
260+
261+
const reverseQuote = await fetchQuote(reverseSwapParams, sourcesFilter)
235262
const estimatedAmountIn = reverseQuote.amountTo
236263
if (estimatedAmountIn === 0n) throw new Error("quote not found")
237264

0 commit comments

Comments
 (0)