Skip to content

Commit 9c61dd7

Browse files
committed
feat: add pendle rollover
1 parent cc66d6c commit 9c61dd7

File tree

9 files changed

+49
-34
lines changed

9 files changed

+49
-34
lines changed

src/swapService/config/mainnet.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const WUSDM_MAINNET = "0x57f5e098cad7a3d1eed53991d4d66c45c9af7812"
1919
const WUSDL_MAINNET = "0x7751E2F4b8ae93EF6B79d86419d42FE3295A4559"
2020
const WM_MAINNET = "0x437cc33344a0B27A429f795ff6B469C72698B291"
2121
const USD0PLUSPLUS_MAINNET = "0x35d8949372d46b7a3d5a56006ae77b215fc69bc0"
22+
const PT_WSTUSR1740182579 = "0xd0097149aa4cc0d0e1fc99b8bd73fc17dc32c1e9"
2223
// TEST mBASIS
2324

2425
const mainnetRoutingConfig: ChainRoutingConfig = [
@@ -47,7 +48,7 @@ const mainnetRoutingConfig: ChainRoutingConfig = [
4748
{
4849
strategy: StrategyERC4626Wrapper.name(),
4950
match: {
50-
tokensInOrOut: [WSTUSR_MAINNET, WUSDL_MAINNET],
51+
tokensInOrOut: [WSTUSR_MAINNET, WUSDL_MAINNET, PT_WSTUSR1740182579],
5152
},
5253
},
5354
{

src/swapService/quoters/quoterUniswap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export async function fetchUniswapQuote(
3030
})
3131

3232
const router = new AlphaRouter({
33-
chainId: swapParams.chainId as ChainId,
33+
chainId: swapParams.chainId,
3434
provider: provider,
3535
})
3636

src/swapService/runner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export async function runPipeline(
4444

4545
console.log(allResults)
4646

47-
const finalResult = allResults.pop()
47+
const finalResult = allResults.at(-1)
4848
if (!finalResult)
4949
throw new ApiError(
5050
StatusCodes.NOT_FOUND,

src/swapService/strategies/balmySDK/pendleQuoteSource.ts

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ export class CustomPendleQuoteSource
5050
params: QuoteParams<PendleSupport, PendleConfig>,
5151
): Promise<SourceQuoteResponse<PendleData>> {
5252
const { dstAmount, to, data } = await this.getQuote(params)
53-
console.log("pendle: ", dstAmount)
5453

5554
const quote = {
5655
sellAmount: params.request.order.sellAmount,
@@ -89,26 +88,48 @@ export class CustomPendleQuoteSource
8988
},
9089
config,
9190
}: QuoteParams<PendleSupport, PendleConfig>) {
92-
const queryParams = {
93-
receiver: recipient || takeFrom,
94-
slippage: slippagePercentage / 100, // 1 = 100%
95-
enableAggregator: true,
96-
tokenIn: sellToken,
97-
tokenOut: buyToken,
98-
amountIn: order.sellAmount.toString(),
99-
}
100-
101-
const queryString = qs.stringify(queryParams, {
102-
skipNulls: true,
103-
arrayFormat: "comma",
104-
})
10591
const tokenIn = findToken(chainId, getAddress(sellToken))
10692
const tokenOut = findToken(chainId, getAddress(buyToken))
10793

108-
const pendleMarket =
109-
tokenIn.meta?.pendleMarket || tokenOut.meta?.pendleMarket
94+
let url
95+
if (tokenIn?.meta?.isPendlePT && tokenOut?.meta?.isPendlePT) {
96+
// rollover
97+
const queryParams = {
98+
receiver: recipient || takeFrom,
99+
slippage: slippagePercentage / 100, // 1 = 100%
100+
dstMarket: tokenOut.meta.pendleMarket,
101+
ptAmount: order.sellAmount.toString(),
102+
}
103+
104+
const queryString = qs.stringify(queryParams, {
105+
skipNulls: true,
106+
arrayFormat: "comma",
107+
})
108+
109+
const pendleMarket = tokenIn.meta.pendleMarket
110+
url = `${getUrl()}/${chainId}/markets/${pendleMarket}/roll-over-pt?${queryString}`
111+
} else {
112+
// swap
113+
const queryParams = {
114+
receiver: recipient || takeFrom,
115+
slippage: slippagePercentage / 100, // 1 = 100%
116+
enableAggregator: true,
117+
tokenIn: sellToken,
118+
tokenOut: buyToken,
119+
amountIn: order.sellAmount.toString(),
120+
}
121+
122+
const queryString = qs.stringify(queryParams, {
123+
skipNulls: true,
124+
arrayFormat: "comma",
125+
})
126+
127+
const pendleMarket =
128+
tokenIn?.meta?.pendleMarket || tokenOut?.meta?.pendleMarket
129+
130+
url = `${getUrl()}/${chainId}/markets/${pendleMarket}/swap?${queryString}`
131+
}
110132

111-
const url = `${getUrl()}/${chainId}/markets/${pendleMarket}/swap?${queryString}`
112133
const response = await fetchService.fetch(url, {
113134
timeout,
114135
headers: getHeaders(config),
@@ -123,10 +144,12 @@ export class CustomPendleQuoteSource
123144
(await response.text()) || `Failed with status ${response.status}`,
124145
)
125146
}
147+
126148
const {
127-
data: { amountOut: dstAmount },
149+
data: { amountOut, amountPtOut },
128150
tx: { to, data },
129151
} = await response.json()
152+
const dstAmount = amountOut || amountPtOut
130153

131154
return { dstAmount, to, data }
132155
}

src/swapService/strategies/strategyPendle.ts renamed to src/swapService/strategies/deprecated/strategyPendle.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as chains from "viem/chains"
2-
import { SwapperMode } from "../interface"
3-
import { fetchPendleOverswapQuote, fetchPendleQuote } from "../quoters"
4-
import type { StrategyResult, SwapParams } from "../types"
2+
import { SwapperMode } from "../../interface"
3+
import { fetchPendleOverswapQuote, fetchPendleQuote } from "../../quoters"
4+
import type { StrategyResult, SwapParams } from "../../types"
55
import {
66
SWAPPER_HANDLER_GENERIC,
77
buildApiResponseExactInputFromQuote,
@@ -10,7 +10,7 @@ import {
1010
encodeSwapMulticallItem,
1111
isExactInRepay,
1212
matchParams,
13-
} from "../utils"
13+
} from "../../utils"
1414

1515
export const defaultConfig = {
1616
chainsSupported: [

src/swapService/strategies/index.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,21 @@
1-
import { Strategy1Inch } from "./strategy1Inch"
21
import { StrategyBalmySDK } from "./strategyBalmySDK"
32
import { StrategyCombinedUniswap } from "./strategyCombinedUniswap"
43
import { StrategyERC4626Wrapper } from "./strategyERC4626Wrapper"
5-
import { StrategyLifi } from "./strategyLifi"
64
import { StrategyMidas } from "./strategyMidas"
7-
import { StrategyPendle } from "./strategyPendle"
85
import { StrategyRepayWrapper } from "./strategyRepayWrapper"
96

107
export {
11-
Strategy1Inch,
128
StrategyCombinedUniswap,
139
StrategyMidas,
14-
StrategyPendle,
15-
StrategyLifi,
1610
StrategyRepayWrapper,
1711
StrategyBalmySDK,
1812
StrategyERC4626Wrapper,
1913
}
2014

2115
export const strategies = {
22-
[Strategy1Inch.name()]: Strategy1Inch,
23-
[StrategyPendle.name()]: StrategyPendle,
2416
[StrategyMidas.name()]: StrategyMidas,
2517
[StrategyCombinedUniswap.name()]: StrategyCombinedUniswap,
2618
[StrategyRepayWrapper.name()]: StrategyRepayWrapper,
2719
[StrategyBalmySDK.name()]: StrategyBalmySDK,
28-
[StrategyLifi.name()]: StrategyLifi,
2920
[StrategyERC4626Wrapper.name()]: StrategyERC4626Wrapper,
3021
}

0 commit comments

Comments
 (0)