diff --git a/.changeset/seven-numbers-rush.md b/.changeset/seven-numbers-rush.md new file mode 100644 index 00000000..6febeef7 --- /dev/null +++ b/.changeset/seven-numbers-rush.md @@ -0,0 +1,7 @@ +--- +'@reservoir0x/relay-kit-hooks': minor +'@reservoir0x/relay-sdk': minor +'@reservoir0x/relay-kit-ui': minor +--- + +Switch from execute/swap to quote api diff --git a/packages/hooks/src/hooks/useQuote.ts b/packages/hooks/src/hooks/useQuote.ts index 24812304..f726c118 100644 --- a/packages/hooks/src/hooks/useQuote.ts +++ b/packages/hooks/src/hooks/useQuote.ts @@ -16,26 +16,26 @@ import { useCallback, useMemo } from 'react' import type { WalletClient } from 'viem' import type { AxiosRequestConfig } from 'axios' -type ExecuteSwapBody = - paths['/execute/swap']['post']['requestBody']['content']['application/json'] +type QuoteBody = + paths['/quote']['post']['requestBody']['content']['application/json'] -export type ExecuteSwapResponse = - paths['/execute/swap']['post']['responses']['200']['content']['application/json'] +export type QuoteResponse = + paths['/quote']['post']['responses']['200']['content']['application/json'] type QueryType = typeof useQuery< - ExecuteSwapResponse, + QuoteResponse, DefaultError, - ExecuteSwapResponse, + QuoteResponse, QueryKey > type QueryOptions = Parameters['0'] export const queryQuote = function ( baseApiUrl: string = MAINNET_RELAY_API, - options?: ExecuteSwapBody + options?: QuoteBody ): Promise { return new Promise((resolve, reject) => { - const url = new URL(`${baseApiUrl}/execute/swap`) + const url = new URL(`${baseApiUrl}/quote`) axiosPostFetcher(url.href, options) .then((response) => { const request: AxiosRequestConfig = { @@ -59,7 +59,7 @@ export type onProgress = (data: ProgressData) => void export default function ( client?: RelayClient, wallet?: WalletClient | AdaptedWallet, - options?: ExecuteSwapBody, + options?: QuoteBody, onRequest?: () => void, onResponse?: (data: Execute) => void, queryOptions?: Partial @@ -68,8 +68,8 @@ export default function ( queryKey: ['useQuote', options], queryFn: () => { onRequest?.() - if (options && client?.source && !options.source) { - options.source = client.source + if (options && client?.source && !options.referrer) { + options.referrer = client.source } const promise = queryQuote(client?.baseApiUrl, options) promise.then((response: any) => { @@ -114,7 +114,7 @@ export default function ( data: response.error ? undefined : response.data, executeQuote } as Omit, 'data'> & { - data?: ExecuteSwapResponse + data?: QuoteResponse executeQuote: (onProgress: onProgress) => Promise | undefined }), [ diff --git a/packages/hooks/src/index.ts b/packages/hooks/src/index.ts index 3977f5bd..d21f3162 100644 --- a/packages/hooks/src/index.ts +++ b/packages/hooks/src/index.ts @@ -18,4 +18,4 @@ export { //types export type { CurrencyList, Currency } from './hooks/useTokenList.js' export type { PriceResponse } from './hooks/usePrice.js' -export type { ExecuteSwapResponse } from './hooks/useQuote.js' +export type { QuoteResponse } from './hooks/useQuote.js' diff --git a/packages/sdk/src/actions/getQuote.test.ts b/packages/sdk/src/actions/getQuote.test.ts index 340ad13e..d07a446d 100644 --- a/packages/sdk/src/actions/getQuote.test.ts +++ b/packages/sdk/src/actions/getQuote.test.ts @@ -66,7 +66,7 @@ describe('Should test the getQuote action.', () => { expect(axiosRequestSpy).toHaveBeenCalledWith( expect.objectContaining({ - url: expect.stringContaining('execute/swap'), + url: expect.stringContaining('quote'), data: expect.objectContaining({ user: '0x0000000000000000000000000000000000000000', destinationCurrency: '0x0000000000000000000000000000000000000000', @@ -104,7 +104,7 @@ describe('Should test the getQuote action.', () => { expect(axiosRequestSpy).toHaveBeenCalledWith( expect.objectContaining({ - url: expect.stringContaining('execute/swap'), + url: expect.stringContaining('quote'), data: expect.objectContaining({ user: '0x0000000000000000000000000000000000000000', destinationCurrency: '0x0000000000000000000000000000000000000000', diff --git a/packages/sdk/src/actions/getQuote.ts b/packages/sdk/src/actions/getQuote.ts index 9e061e4a..363ee3e6 100644 --- a/packages/sdk/src/actions/getQuote.ts +++ b/packages/sdk/src/actions/getQuote.ts @@ -12,11 +12,11 @@ import { isViemWalletClient } from '../utils/viemWallet.js' import { getClient } from '../client.js' import type { AdaptedWallet, Execute, paths } from '../types/index.js' -export type ExecuteBody = NonNullable< - paths['/execute/swap']['post']['requestBody']['content']['application/json'] +export type QuoteBody = NonNullable< + paths['/quote']['post']['requestBody']['content']['application/json'] > -export type ExecuteBodyOptions = Omit< - ExecuteBody, +export type QuoteBodyOptions = Omit< + QuoteBody, | 'destinationChainId' | 'originChainId' | 'originCurrency' @@ -30,12 +30,12 @@ export type GetQuoteParameters = { currency: string toChainId: number toCurrency: string - tradeType: ExecuteBodyOptions['tradeType'] + tradeType: QuoteBodyOptions['tradeType'] wallet?: AdaptedWallet | WalletClient amount?: string recipient?: Address - options?: Omit - txs?: (NonNullable[0] | SimulateContractRequest)[] + options?: Omit + txs?: (NonNullable[0] | SimulateContractRequest)[] } /** @@ -73,7 +73,7 @@ export async function getQuote( caller = await adaptedWallet.address() } - let preparedTransactions: ExecuteBody['txs'] + let preparedTransactions: QuoteBody['txs'] if (txs && txs.length > 0) { preparedTransactions = txs.map((tx) => { if (isSimulateContractRequest(tx)) { @@ -85,7 +85,7 @@ export async function getQuote( }) } - const query: ExecuteBody = { + const query: QuoteBody = { user: caller || zeroAddress, destinationCurrency: toCurrency, destinationChainId: toChainId, @@ -94,13 +94,13 @@ export async function getQuote( amount, recipient: recipient ? (recipient as string) : caller ?? zeroAddress, tradeType, - source: client.source || undefined, + referrer: client.source || undefined, txs: preparedTransactions, ...options } const request: AxiosRequestConfig = { - url: `${client.baseApiUrl}/execute/swap`, + url: `${client.baseApiUrl}/quote`, method: 'post', data: query } diff --git a/packages/sdk/src/types/Execute.ts b/packages/sdk/src/types/Execute.ts index c89c1cfc..26388658 100644 --- a/packages/sdk/src/types/Execute.ts +++ b/packages/sdk/src/types/Execute.ts @@ -11,8 +11,8 @@ export type CheckApi = NonNullable< paths['/execute/call/v2']['post']['responses']['200']['content']['application/json']['steps'] >['0']['items'] >[0]['check'] -export type ExecuteDetails = NonNullable< - paths['/execute/swap']['post']['responses']['200']['content']['application/json']['details'] +export type QuoteDetails = NonNullable< + paths['/quote']['post']['responses']['200']['content']['application/json']['details'] > export type TransactionStepState = 'confirming' | 'validating' | 'complete' @@ -26,7 +26,7 @@ export type Execute = { errors?: { message?: string; orderId?: string }[] fees?: CallFees breakdown?: CallBreakdown - details?: ExecuteDetails + details?: QuoteDetails error?: any // Manually added client error steps: { diff --git a/packages/ui/src/components/common/TransactionModal/TransactionModalRenderer.tsx b/packages/ui/src/components/common/TransactionModal/TransactionModalRenderer.tsx index e3a0db58..5ff9591c 100644 --- a/packages/ui/src/components/common/TransactionModal/TransactionModalRenderer.tsx +++ b/packages/ui/src/components/common/TransactionModal/TransactionModalRenderer.tsx @@ -181,7 +181,7 @@ export const TransactionModalRenderer: FC = ({ debouncedOutputAmountValue, toToken.decimals ).toString(), - source: relayClient?.source ?? undefined, + referrer: relayClient?.source ?? undefined, useExternalLiquidity } : undefined, diff --git a/packages/ui/src/providers/RelayKitProvider.tsx b/packages/ui/src/providers/RelayKitProvider.tsx index 8d9b17a4..894c9a9c 100644 --- a/packages/ui/src/providers/RelayKitProvider.tsx +++ b/packages/ui/src/providers/RelayKitProvider.tsx @@ -15,7 +15,7 @@ export type CoinGecko = { } export type AppFees = - paths['/execute/swap']['post']['requestBody']['content']['application/json']['appFees'] + paths['/quote']['post']['requestBody']['content']['application/json']['appFees'] type RelayKitProviderOptions = { appName?: string diff --git a/packages/ui/src/utils/quote.ts b/packages/ui/src/utils/quote.ts index e42d7f28..859401c0 100644 --- a/packages/ui/src/utils/quote.ts +++ b/packages/ui/src/utils/quote.ts @@ -6,7 +6,7 @@ import type { useQuote, PriceResponse } from '@reservoir0x/relay-kit-hooks' import type { ComponentPropsWithoutRef } from 'react' import type Text from '../components/primitives/Text.js' -type ExecuteSwapResponse = ReturnType['data'] +type QuoteResponse = ReturnType['data'] export const parseFees = ( selectedTo: RelayChain, @@ -144,9 +144,7 @@ export const parseFees = ( } } -export const calculateRelayerFeeProportionUsd = ( - quote?: ExecuteSwapResponse -) => { +export const calculateRelayerFeeProportionUsd = (quote?: QuoteResponse) => { const usdIn = quote?.details?.currencyIn?.amountUsd ? Number(quote.details.currencyIn.amountUsd) : null @@ -173,7 +171,7 @@ export const calculateRelayerFeeProportion = ( return 0n } -export const isHighRelayerServiceFeeUsd = (quote?: ExecuteSwapResponse) => { +export const isHighRelayerServiceFeeUsd = (quote?: QuoteResponse) => { const usdIn = quote?.details?.currencyIn?.amountUsd ? Number(quote.details.currencyIn.amountUsd) : null