Skip to content

Commit

Permalink
Merge pull request #2 from Web3Auth/feat/add-fee-for-swap
Browse files Browse the repository at this point in the history
Add option to specify fee and recipient when routing
  • Loading branch information
chaitanyapotti authored Aug 19, 2024
2 parents 7d166a0 + ff2da13 commit 9fba46d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/routers/alpha-router/alpha-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ import {
SwapAndAddConfig,
SwapAndAddOptions,
SwapAndAddParameters,
SwapConfig,
SwapOptions,
SwapRoute,
SwapToRatioResponse,
Expand Down Expand Up @@ -1082,7 +1083,7 @@ export class AlphaRouter
amount: CurrencyAmount,
quoteCurrency: Currency,
tradeType: TradeType,
swapConfig?: SwapOptions,
swapConfig?: SwapConfig,
partialRoutingConfig: Partial<AlphaRouterConfig> = {}
): Promise<SwapRoute | null> {
const originalAmount = amount;
Expand Down
2 changes: 2 additions & 0 deletions src/routers/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
7 changes: 4 additions & 3 deletions src/util/methodParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
MixedRouteWithValidQuote,
RouteWithValidQuote,
SWAP_ROUTER_02_ADDRESSES,
SwapOptions,
SwapConfig,
SwapType,
V2RouteWithValidQuote,
V3RouteWithValidQuote,
Expand Down Expand Up @@ -236,7 +236,7 @@ export function buildTrade<TTradeType extends TradeType>(

export function buildSwapMethodParameters(
trade: Trade<Currency, Currency, TradeType>,
swapConfig: SwapOptions,
swapConfig: SwapConfig,
chainId: ChainId
): MethodParameters {
if (swapConfig.type == SwapType.UNIVERSAL_ROUTER) {
Expand All @@ -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 {
Expand All @@ -254,6 +254,7 @@ export function buildSwapMethodParameters(
slippageTolerance,
deadlineOrPreviousBlockhash: deadline,
inputTokenPermit,
fee
}),
to: SWAP_ROUTER_02_ADDRESSES(chainId),
};
Expand Down

0 comments on commit 9fba46d

Please sign in to comment.