Skip to content

Commit 06a67b0

Browse files
committed
update config, improve binary search
1 parent 95d11d8 commit 06a67b0

File tree

5 files changed

+22
-38
lines changed

5 files changed

+22
-38
lines changed

src/swapService/config/base.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import {
55
StrategyRepayWrapper,
66
} from "../strategies"
77

8-
const CBBTC_BASE = "0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf"
9-
108
const baseRoutingConfig: ChainRoutingConfig = [
119
// WRAPPERS
1210
{
@@ -21,27 +19,6 @@ const baseRoutingConfig: ChainRoutingConfig = [
2119
strategy: StrategyMidas.name(),
2220
match: {}, // supports function will match mTokens
2321
},
24-
{
25-
strategy: StrategyBalmySDK.name(),
26-
config: {
27-
sourcesFilter: {
28-
includeSources: ["pendle", "li-fi", "open-ocean"],
29-
},
30-
},
31-
match: { isPendlePT: true },
32-
},
33-
// avoid 1inch because of InvalidatedOrder error. Kyberswap and li.fi also route through 1inch
34-
{
35-
strategy: StrategyBalmySDK.name(),
36-
config: {
37-
sourcesFilter: {
38-
includeSources: ["odos", "uniswap", "open-ocean"],
39-
},
40-
},
41-
match: {
42-
tokensInOrOut: [CBBTC_BASE],
43-
},
44-
},
4522
// DEFAULTS
4623
{
4724
strategy: StrategyBalmySDK.name(),
@@ -54,10 +31,9 @@ const baseRoutingConfig: ChainRoutingConfig = [
5431
"1inch",
5532
"li-fi",
5633
"open-ocean",
57-
// "conveyor",
5834
"uniswap",
5935
"magpie",
60-
"enso",
36+
"pendle",
6137
],
6238
},
6339
},

src/swapService/config/mainnet.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,6 @@ const mainnetRoutingConfig: ChainRoutingConfig = [
5959
excludeTokensInOrOut: [PT_WSTUSR_27MAR2025_MAINNET],
6060
},
6161
},
62-
{
63-
strategy: StrategyBalmySDK.name(),
64-
config: {
65-
sourcesFilter: {
66-
includeSources: ["pendle", "li-fi", "open-ocean"],
67-
},
68-
},
69-
match: { isPendlePT: true },
70-
},
7162
// WUSDL with paraswap
7263
{
7364
strategy: StrategyBalmySDK.name(),
@@ -80,7 +71,6 @@ const mainnetRoutingConfig: ChainRoutingConfig = [
8071
"1inch",
8172
"li-fi",
8273
"open-ocean",
83-
"uniswap",
8474
"magpie",
8575
"0x",
8676
],
@@ -114,10 +104,10 @@ const mainnetRoutingConfig: ChainRoutingConfig = [
114104
"1inch",
115105
"li-fi",
116106
"open-ocean",
117-
"uniswap",
118107
"magpie",
119108
"0x",
120109
"enso",
110+
"pendle",
121111
],
122112
},
123113
},
@@ -130,6 +120,7 @@ const mainnetRoutingConfig: ChainRoutingConfig = [
130120
match: {
131121
swapperModes: [SwapperMode.TARGET_DEBT],
132122
excludeTokensInOrOut: [RLP_MAINNET, SUSDS_MAINNET, WUSDL_MAINNET],
123+
notPendlePT: true,
133124
},
134125
},
135126
// FALLBACKS
@@ -152,9 +143,10 @@ const mainnetRoutingConfig: ChainRoutingConfig = [
152143
"1inch",
153144
"li-fi",
154145
"open-ocean",
155-
"uniswap",
156146
"magpie",
157147
"0x",
148+
"enso",
149+
"pendle",
158150
],
159151
},
160152
},

src/swapService/interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export interface StrategyMatchConfig {
6969
swapperModes?: SwapperMode[]
7070
isRepay?: boolean
7171
isPendlePT?: boolean
72+
notPendlePT?: boolean
7273
tokensInOrOut?: Address[]
7374
excludeTokensInOrOut?: Address[]
7475
repayVaults?: Address[]

src/swapService/strategies/balmySDK/sources/pendleQuoteSource.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ export class CustomPendleQuoteSource
116116
const tokenIn = findToken(chainId, getAddress(sellToken))
117117
const tokenOut = findToken(chainId, getAddress(buyToken))
118118
if (!tokenIn || !tokenOut) throw new Error("Missing token in or out")
119-
119+
if (!tokenIn.meta?.isPendlePT && !tokenOut.meta?.isPendlePT) {
120+
failed(PENDLE_METADATA, chainId, sellToken, buyToken, "Not PT tokens")
121+
}
120122
let url
121123
if (tokenIn.meta?.isPendlePT && tokenOut.meta?.isPendlePT) {
122124
// rollover

src/swapService/utils.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ export function matchParams(
8383
)
8484
return false
8585
}
86+
if (match.notPendlePT) {
87+
if (
88+
swapParams.tokenIn.meta?.isPendlePT ||
89+
swapParams.tokenOut.meta?.isPendlePT
90+
)
91+
return false
92+
}
8693
if (match.repayVaults) {
8794
if (
8895
!swapParams.isRepay ||
@@ -495,6 +502,7 @@ export async function binarySearchQuote(
495502
let quote
496503
let amountTo
497504
let prevAmountTo
505+
const initialAmountFrom = amountFrom
498506

499507
do {
500508
amountFrom = (amountFrom * percentageChange) / 10000n
@@ -524,6 +532,11 @@ export async function binarySearchQuote(
524532

525533
if (cnt++ === 15)
526534
throw new Error("Binary search not completed in 15 iterations")
535+
if (amountFrom > 2n * initialAmountFrom)
536+
// TODO fix, this is assuming estimated amount is provided
537+
throw new Error(
538+
"Amount from already 2x estimated, probably no liquidity to reach target",
539+
)
527540
} while (shouldContinue(amountTo))
528541

529542
return quote

0 commit comments

Comments
 (0)