From 22649f1a5bd8ec386a6a57d21eae34752e2170fd Mon Sep 17 00:00:00 2001 From: Paul Cramer Date: Tue, 10 Sep 2024 09:18:57 -0700 Subject: [PATCH] clean --- src/api/buildSwapTransaction.ts | 28 ++++++++++++---------------- src/api/getSwapQuote.ts | 16 ++++++---------- src/api/types.ts | 2 -- 3 files changed, 18 insertions(+), 28 deletions(-) diff --git a/src/api/buildSwapTransaction.ts b/src/api/buildSwapTransaction.ts index ec2fc875d2..43b4cbb3da 100644 --- a/src/api/buildSwapTransaction.ts +++ b/src/api/buildSwapTransaction.ts @@ -1,7 +1,6 @@ import { CDP_GET_SWAP_TRADE } from '../network/definitions/swap'; import { sendRequest } from '../network/request'; import type { BuildSwapTransactionResponse } from '../swap'; -import { DEFAULT_MAX_SLIPPAGE } from '../swap/constants'; import type { SwapAPIResponse } from '../swap/types'; import { getSwapErrorCode } from '../swap/utils/getSwapErrorCode'; import type { @@ -18,12 +17,6 @@ import { getSwapTransaction } from './utils/getSwapTransaction'; export async function buildSwapTransaction( params: BuildSwapTransactionParams, ): Promise { - const lifeCycleStatus = params.lifeCycleStatus; - const maxSlippage = - lifeCycleStatus.statusName !== 'error' - ? lifeCycleStatus.statusData.maxSlippage - : DEFAULT_MAX_SLIPPAGE; - // Default parameters const defaultParams = { amountReference: 'from', @@ -45,16 +38,19 @@ export async function buildSwapTransaction( ...apiParams, }; } - let slippagePercentage = String(maxSlippage); - // Adjust slippage for V1 API (aggregator) - // V1 expects slippage in tenths of a percent (e.g., 30 = 3%) - if (params.useAggregator) { - slippagePercentage = (Number(maxSlippage) * 10).toString(); + if (params.maxSlippage) { + let slippagePercentage = params.maxSlippage; + // Adjust slippage for V1 API (aggregator) + // V1 expects slippage in tenths of a percent (e.g., 30 = 3%) + if (params.useAggregator) { + slippagePercentage = (Number(params.maxSlippage) * 10).toString(); + } + apiParams = { + slippagePercentage, + ...apiParams, + }; } - apiParams = { - slippagePercentage, - ...apiParams, - }; + try { const res = await sendRequest( CDP_GET_SWAP_TRADE, diff --git a/src/api/getSwapQuote.ts b/src/api/getSwapQuote.ts index 4b394a3b32..a708c2ee48 100644 --- a/src/api/getSwapQuote.ts +++ b/src/api/getSwapQuote.ts @@ -1,6 +1,5 @@ import { CDP_GET_SWAP_QUOTE } from '../network/definitions/swap'; import { sendRequest } from '../network/request'; -import { DEFAULT_MAX_SLIPPAGE } from '../swap/constants'; import type { SwapQuote } from '../swap/types'; import { getSwapErrorCode } from '../swap/utils/getSwapErrorCode'; import type { @@ -17,11 +16,6 @@ import { getAPIParamsForToken } from './utils/getAPIParamsForToken'; export async function getSwapQuote( params: GetSwapQuoteParams, ): Promise { - const lifeCycleStatus = params.lifeCycleStatus; - const maxSlippage = - lifeCycleStatus.statusName !== 'error' - ? lifeCycleStatus.statusData.maxSlippage - : DEFAULT_MAX_SLIPPAGE; // Default parameters const defaultParams = { amountReference: 'from', @@ -42,10 +36,12 @@ export async function getSwapQuote( ...apiParams, }; } - apiParams = { - slippagePercentage: String(maxSlippage), - ...apiParams, - }; + if (params.maxSlippage) { + apiParams = { + slippagePercentage: params.maxSlippage, + ...apiParams, + }; + } try { const res = await sendRequest( diff --git a/src/api/types.ts b/src/api/types.ts index d2978cc5e5..14a5adf245 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -1,6 +1,5 @@ import type { Address } from 'viem'; import type { SwapQuote } from '../swap/types'; -import type { LifeCycleStatus } from '../swap/types'; import type { Token } from '../token/types'; export type AddressOrETH = Address | 'ETH'; @@ -46,7 +45,6 @@ export type GetSwapQuoteParams = { amountReference?: string; // The reference amount for the swap from: Token; // The source token for the swap isAmountInDecimals?: boolean; // Whether the amount is in decimals - lifeCycleStatus: LifeCycleStatus; maxSlippage?: string; // The slippage of the swap to: Token; // The destination token for the swap useAggregator: boolean; // Whether to use a DEX aggregator