Skip to content

Commit

Permalink
feat: use balmy for default strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
dglowinski committed Dec 6, 2024
1 parent ba444ba commit 047c769
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 24 deletions.
27 changes: 14 additions & 13 deletions src/swapService/config/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ const WSTUSR_MAINNET = "0x1202f5c7b4b9e47a1a484e8b270be34dbbc75055"

const mainnetRoutingConfig: ChainRoutingConfig = [
// WRAPPERS
{
strategy: StrategyERC4626Wrapper.name(),
match: {},
},
{
strategy: StrategyRepayWrapper.name(),
match: {
Expand All @@ -42,6 +38,12 @@ const mainnetRoutingConfig: ChainRoutingConfig = [
tokensInOrOut: [MTBILL_MAINNET],
},
},
{
strategy: StrategyERC4626Wrapper.name(),
match: {
tokensInOrOut: [WSTUSR_MAINNET],
},
},
{
strategy: StrategyBalmySDK.name(),
config: {
Expand All @@ -67,17 +69,11 @@ const mainnetRoutingConfig: ChainRoutingConfig = [
},
},
{
strategy: StrategyLifi.name(),
match: {
tokensInOrOut: [SUSDS_MAINNET],
},
},
{
// sUSDS fallback
// sUSDS
strategy: StrategyBalmySDK.name(),
config: {
sourcesFilter: {
includeSources: ["paraswap", "open-ocean"],
includeSources: ["paraswap", "open-ocean", "li-fi", "odos", "1inch"],
},
tryExactOut: true,
},
Expand All @@ -87,7 +83,12 @@ const mainnetRoutingConfig: ChainRoutingConfig = [
},
// DEFAULTS
{
strategy: Strategy1Inch.name(),
strategy: StrategyBalmySDK.name(),
config: {
sourcesFilter: {
includeSources: ["1inch"],
},
},
match: {
swapperModes: [SwapperMode.EXACT_IN],
},
Expand Down
1 change: 1 addition & 0 deletions src/swapService/quoters/quoterLifi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export async function fetchLiFiExactInQuote(
})

const url = `https://li.quest/v1/quote?${params.toString()}`
console.log("url: ", url)
const requestHeaders = new Headers()
if (process.env.LIFI_API_KEY)
requestHeaders.set("x-lifi-api-key", process.env.LIFI_API_KEY)
Expand Down
5 changes: 2 additions & 3 deletions src/swapService/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ export async function runPipeline(
return finalResult.response
}

// TODO timeouts on balmy
// TODO tokenlist, interfaces
// TODO price impact
// TODO error handling
// TODO npm interfaces, supported chains
// TODO cache pipeline
// TODO cache pipeline, tokenlists
// TODO logging
// TODO pendle rollover
43 changes: 35 additions & 8 deletions src/swapService/strategies/strategyBalmySDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import {
import { buildFetchService } from "@balmy/sdk/dist/sdk/builders/fetch-builder"
import { buildProviderService } from "@balmy/sdk/dist/sdk/builders/provider-builder"
import type { Either } from "@balmy/sdk/dist/utility-types"
import { type Hex, encodeAbiParameters, parseAbiParameters } from "viem"
import {
type Address,
type Hex,
encodeAbiParameters,
parseAbiParameters,
} from "viem"
import { SwapperMode } from "../interface"
import type { StrategyResult, SwapParams, SwapQuote } from "../types"
import {
Expand All @@ -27,6 +32,7 @@ import {
import { CustomSourceList } from "./balmySDK/customSourceList"

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

type SourcesFilter =
Expand All @@ -40,7 +46,15 @@ type SourcesFilter =
>
| undefined

export const defaultConfig = {
export const defaultConfig: {
referrer: {
address: Address
name: string
}
sourcesFilter: SourcesFilter
tryExactOut?: boolean
onlyExactOut?: boolean
} = {
referrer: {
address: DAO_MULTISIG,
name: "euler",
Expand Down Expand Up @@ -226,12 +240,25 @@ export class StrategyBalmySDK {
swapperMode: SwapperMode.EXACT_IN,
}

const reverseQuote = await fetchQuote(
reverseSwapParams,
this.config.sourcesFilter || {
excludeSources: BINARY_SEARCH_EXCLUDE_SOURCES,
},
) // TODO config
let sourcesFilter
if (this.config.sourcesFilter?.includeSources) {
sourcesFilter = {
includeSources: this.config.sourcesFilter.includeSources.filter(
(s) => !BINARY_SEARCH_EXCLUDE_SOURCES.includes(s),
),
}
} else if (this.config.sourcesFilter?.excludeSources) {
sourcesFilter = {
excludeSources: [
...this.config.sourcesFilter.excludeSources,
...BINARY_SEARCH_EXCLUDE_SOURCES,
],
}
} else {
sourcesFilter = { excludeSources: BINARY_SEARCH_EXCLUDE_SOURCES }
}

const reverseQuote = await fetchQuote(reverseSwapParams, sourcesFilter)
const estimatedAmountIn = reverseQuote.amountTo
if (estimatedAmountIn === 0n) throw new Error("quote not found")

Expand Down

0 comments on commit 047c769

Please sign in to comment.