@@ -9,7 +9,12 @@ import {
9
9
import { buildFetchService } from "@balmy/sdk/dist/sdk/builders/fetch-builder"
10
10
import { buildProviderService } from "@balmy/sdk/dist/sdk/builders/provider-builder"
11
11
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"
13
18
import { SwapperMode } from "../interface"
14
19
import type { StrategyResult , SwapParams , SwapQuote } from "../types"
15
20
import {
@@ -27,6 +32,7 @@ import {
27
32
import { CustomSourceList } from "./balmySDK/customSourceList"
28
33
29
34
const DAO_MULTISIG = "0xcAD001c30E96765aC90307669d578219D4fb1DCe"
35
+ // TODO config
30
36
const BINARY_SEARCH_EXCLUDE_SOURCES = [ "paraswap" ] // paraswap is rate limited and fails if selected as best source for binary search
31
37
32
38
type SourcesFilter =
@@ -40,7 +46,15 @@ type SourcesFilter =
40
46
>
41
47
| undefined
42
48
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
+ } = {
44
58
referrer : {
45
59
address : DAO_MULTISIG ,
46
60
name : "euler" ,
@@ -226,12 +240,25 @@ export class StrategyBalmySDK {
226
240
swapperMode : SwapperMode . EXACT_IN ,
227
241
}
228
242
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 )
235
262
const estimatedAmountIn = reverseQuote . amountTo
236
263
if ( estimatedAmountIn === 0n ) throw new Error ( "quote not found" )
237
264
0 commit comments