From ff2da132026a9010ab0c99fe2fdf050181efa419 Mon Sep 17 00:00:00 2001 From: Naveed Elahi Date: Mon, 19 Aug 2024 15:29:02 +0800 Subject: [PATCH] add fee option to route method and build swap method --- src/routers/alpha-router/alpha-router.ts | 3 ++- src/routers/router.ts | 2 ++ src/util/methodParameters.ts | 7 ++++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/routers/alpha-router/alpha-router.ts b/src/routers/alpha-router/alpha-router.ts index 1d0946ce4..9ec604310 100644 --- a/src/routers/alpha-router/alpha-router.ts +++ b/src/routers/alpha-router/alpha-router.ts @@ -120,6 +120,7 @@ import { SwapAndAddConfig, SwapAndAddOptions, SwapAndAddParameters, + SwapConfig, SwapOptions, SwapRoute, SwapToRatioResponse, @@ -1082,7 +1083,7 @@ export class AlphaRouter amount: CurrencyAmount, quoteCurrency: Currency, tradeType: TradeType, - swapConfig?: SwapOptions, + swapConfig?: SwapConfig, partialRoutingConfig: Partial = {} ): Promise { const originalAmount = amount; diff --git a/src/routers/router.ts b/src/routers/router.ts index 2973c00ec..cc088e469 100644 --- a/src/routers/router.ts +++ b/src/routers/router.ts @@ -188,6 +188,8 @@ export type SwapOptionsSwapRouter02 = { export type SwapOptions = SwapOptionsUniversalRouter | SwapOptionsSwapRouter02; +export type SwapConfig = SwapOptions & { fee?: { fee: Percent; recipient: string } }; + // Config passed in to determine configurations on acceptable liquidity // to add to a position and max iterations on the route-finding algorithm export type SwapAndAddConfig = { diff --git a/src/util/methodParameters.ts b/src/util/methodParameters.ts index 57ae41376..fff152d44 100644 --- a/src/util/methodParameters.ts +++ b/src/util/methodParameters.ts @@ -20,7 +20,7 @@ import { MixedRouteWithValidQuote, RouteWithValidQuote, SWAP_ROUTER_02_ADDRESSES, - SwapOptions, + SwapConfig, SwapType, V2RouteWithValidQuote, V3RouteWithValidQuote, @@ -236,7 +236,7 @@ export function buildTrade( export function buildSwapMethodParameters( trade: Trade, - swapConfig: SwapOptions, + swapConfig: SwapConfig, chainId: ChainId ): MethodParameters { if (swapConfig.type == SwapType.UNIVERSAL_ROUTER) { @@ -245,7 +245,7 @@ export function buildSwapMethodParameters( to: UNIVERSAL_ROUTER_ADDRESS(chainId), }; } else if (swapConfig.type == SwapType.SWAP_ROUTER_02) { - const { recipient, slippageTolerance, deadline, inputTokenPermit } = + const { recipient, slippageTolerance, deadline, inputTokenPermit, fee } = swapConfig; return { @@ -254,6 +254,7 @@ export function buildSwapMethodParameters( slippageTolerance, deadlineOrPreviousBlockhash: deadline, inputTokenPermit, + fee }), to: SWAP_ROUTER_02_ADDRESSES(chainId), };