diff --git a/.changeset/fluffy-ideas-speak.md b/.changeset/fluffy-ideas-speak.md new file mode 100644 index 0000000..9b4e714 --- /dev/null +++ b/.changeset/fluffy-ideas-speak.md @@ -0,0 +1,5 @@ +--- +"@yieldxyz/sdk": patch +--- + +feat: add abort signal support + schema changes diff --git a/src/api-client.ts b/src/api-client.ts index aae034e..e2c0822 100644 --- a/src/api-client.ts +++ b/src/api-client.ts @@ -1,20 +1,21 @@ import { sdkConfig } from "./sdk-config"; -export const customFetch = async ({ - url, - method, - params, - headers, - data, - signal, -}: { - url: string; - method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH"; - params?: unknown; - data?: unknown; - headers?: Record; - signal?: AbortSignal; -}): Promise => { +export const customFetch = async ( + { + url, + method, + params, + headers, + data, + }: { + url: string; + method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH"; + params?: unknown; + data?: unknown; + headers?: Record; + }, + options?: { signal?: AbortSignal }, +): Promise => { const { apiKey, baseURL = "https://api.yield.xyz/", @@ -26,7 +27,7 @@ export const customFetch = async ({ const requestInit: RequestInit = { method, headers: { ...headers, "X-API-KEY": apiKey }, - signal, + signal: options?.signal, ...(!!data && { body: JSON.stringify(data) }), }; diff --git a/src/api/index.msw.ts b/src/api/index.msw.ts index 34c04c8..5726217 100644 --- a/src/api/index.msw.ts +++ b/src/api/index.msw.ts @@ -78,6 +78,7 @@ export const getYieldsControllerGetYieldsResponseMock = "viction", "core", "sonic", + "katana", "agoric", "akash", "axelar", @@ -182,6 +183,7 @@ export const getYieldsControllerGetYieldsResponseMock = "viction", "core", "sonic", + "katana", "agoric", "akash", "axelar", @@ -302,6 +304,7 @@ export const getYieldsControllerGetYieldsResponseMock = "viction", "core", "sonic", + "katana", "agoric", "akash", "axelar", @@ -424,6 +427,7 @@ export const getYieldsControllerGetYieldsResponseMock = "viction", "core", "sonic", + "katana", "agoric", "akash", "axelar", @@ -564,6 +568,7 @@ export const getYieldsControllerGetYieldsResponseMock = "viction", "core", "sonic", + "katana", "agoric", "akash", "axelar", @@ -749,6 +754,7 @@ export const getYieldsControllerGetYieldsResponseMock = "viction", "core", "sonic", + "katana", "agoric", "akash", "axelar", @@ -1371,6 +1377,7 @@ export const getYieldsControllerGetAggregateBalancesResponseMock = ( "viction", "core", "sonic", + "katana", "agoric", "akash", "axelar", @@ -1525,6 +1532,7 @@ export const getYieldsControllerGetAggregateBalancesResponseMock = ( "viction", "core", "sonic", + "katana", "agoric", "akash", "axelar", @@ -1736,6 +1744,7 @@ export const getYieldsControllerGetAggregateBalancesResponseMock = ( "viction", "core", "sonic", + "katana", "agoric", "akash", "axelar", @@ -1927,6 +1936,7 @@ export const getYieldsControllerGetYieldResponseMock = ( "viction", "core", "sonic", + "katana", "agoric", "akash", "axelar", @@ -2031,6 +2041,7 @@ export const getYieldsControllerGetYieldResponseMock = ( "viction", "core", "sonic", + "katana", "agoric", "akash", "axelar", @@ -2148,6 +2159,7 @@ export const getYieldsControllerGetYieldResponseMock = ( "viction", "core", "sonic", + "katana", "agoric", "akash", "axelar", @@ -2270,6 +2282,7 @@ export const getYieldsControllerGetYieldResponseMock = ( "viction", "core", "sonic", + "katana", "agoric", "akash", "axelar", @@ -2408,6 +2421,7 @@ export const getYieldsControllerGetYieldResponseMock = ( "viction", "core", "sonic", + "katana", "agoric", "akash", "axelar", @@ -2584,6 +2598,7 @@ export const getYieldsControllerGetYieldResponseMock = ( "viction", "core", "sonic", + "katana", "agoric", "akash", "axelar", @@ -3140,6 +3155,7 @@ export const getYieldsControllerGetYieldBalancesResponseMock = ( "viction", "core", "sonic", + "katana", "agoric", "akash", "axelar", @@ -3292,6 +3308,7 @@ export const getYieldsControllerGetYieldBalancesResponseMock = ( "viction", "core", "sonic", + "katana", "agoric", "akash", "axelar", @@ -3499,6 +3516,7 @@ export const getYieldsControllerGetYieldBalancesResponseMock = ( "viction", "core", "sonic", + "katana", "agoric", "akash", "axelar", @@ -3741,6 +3759,7 @@ export const getYieldsControllerGetYieldValidatorsResponseMock = "viction", "core", "sonic", + "katana", "agoric", "akash", "axelar", @@ -3982,6 +4001,7 @@ export const getActionsControllerGetActionsResponseMock = "viction", "core", "sonic", + "katana", "agoric", "akash", "axelar", @@ -4263,6 +4283,7 @@ export const getActionsControllerGetActionResponseMock = ( "viction", "core", "sonic", + "katana", "agoric", "akash", "axelar", @@ -4537,6 +4558,7 @@ export const getActionsControllerEnterYieldResponseMock = ( "viction", "core", "sonic", + "katana", "agoric", "akash", "axelar", @@ -4811,6 +4833,7 @@ export const getActionsControllerExitYieldResponseMock = ( "viction", "core", "sonic", + "katana", "agoric", "akash", "axelar", @@ -5085,6 +5108,7 @@ export const getActionsControllerManageYieldResponseMock = ( "viction", "core", "sonic", + "katana", "agoric", "akash", "axelar", @@ -5319,6 +5343,7 @@ export const getTransactionsControllerSubmitTransactionHashResponseMock = ( "viction", "core", "sonic", + "katana", "agoric", "akash", "axelar", @@ -5529,6 +5554,7 @@ export const getTransactionsControllerGetTransactionResponseMock = ( "viction", "core", "sonic", + "katana", "agoric", "akash", "axelar", @@ -5739,6 +5765,7 @@ export const getNetworksControllerGetNetworksResponseMock = (): NetworkDto[] => "viction", "core", "sonic", + "katana", "agoric", "akash", "axelar", diff --git a/src/api/index.ts b/src/api/index.ts index 096c5c3..7fb7001 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -23,16 +23,20 @@ import type { YieldsControllerGetYieldValidatorsParams, } from "./schemas"; +type SecondParameter unknown> = Parameters[1]; + /** * Retrieve a paginated list of available yield opportunities across all supported networks and protocols. * @summary List all yield opportunities */ -export const getYields = (params?: YieldsControllerGetYieldsParams) => { - return customFetch({ - url: `/v1/yields`, - method: "GET", - params, - }); +export const getYields = ( + params?: YieldsControllerGetYieldsParams, + options?: SecondParameter, +) => { + return customFetch( + { url: `/v1/yields`, method: "GET", params }, + options, + ); }; /** @@ -41,21 +45,31 @@ export const getYields = (params?: YieldsControllerGetYieldsParams) => { */ export const getAggregateBalances = ( balancesRequestDto: BalancesRequestDto, + options?: SecondParameter, ) => { - return customFetch({ - url: `/v1/yields/balances`, - method: "POST", - headers: { "Content-Type": "application/json" }, - data: balancesRequestDto, - }); + return customFetch( + { + url: `/v1/yields/balances`, + method: "POST", + headers: { "Content-Type": "application/json" }, + data: balancesRequestDto, + }, + options, + ); }; /** * Retrieve detailed information about a specific yield opportunity including APY, tokens, protocol details, and more. * @summary Get yield metadata */ -export const getYield = (yieldId: string) => { - return customFetch({ url: `/v1/yields/${yieldId}`, method: "GET" }); +export const getYield = ( + yieldId: string, + options?: SecondParameter, +) => { + return customFetch( + { url: `/v1/yields/${yieldId}`, method: "GET" }, + options, + ); }; /** @@ -65,12 +79,12 @@ export const getYield = (yieldId: string) => { export const getYieldBalances = ( yieldId: string, params: YieldsControllerGetYieldBalancesParams, + options?: SecondParameter, ) => { - return customFetch({ - url: `/v1/yields/${yieldId}/balances`, - method: "GET", - params, - }); + return customFetch( + { url: `/v1/yields/${yieldId}/balances`, method: "GET", params }, + options, + ); }; /** @@ -80,74 +94,97 @@ export const getYieldBalances = ( export const getYieldValidators = ( yieldId: string, params?: YieldsControllerGetYieldValidatorsParams, + options?: SecondParameter, ) => { - return customFetch({ - url: `/v1/yields/${yieldId}/validators`, - method: "GET", - params, - }); + return customFetch( + { url: `/v1/yields/${yieldId}/validators`, method: "GET", params }, + options, + ); }; /** * Retrieve all actions performed by a user, with optional filtering by yield, status, category, etc. In the future, this may include personalized action recommendations. * @summary Get user actions */ -export const getActions = (params: ActionsControllerGetActionsParams) => { - return customFetch({ - url: `/v1/actions`, - method: "GET", - params, - }); +export const getActions = ( + params: ActionsControllerGetActionsParams, + options?: SecondParameter, +) => { + return customFetch( + { url: `/v1/actions`, method: "GET", params }, + options, + ); }; /** * Retrieve detailed information about a specific action including current status, transactions, and execution details. * @summary Get action details */ -export const getAction = (actionId: string) => { - return customFetch({ - url: `/v1/actions/${actionId}`, - method: "GET", - }); +export const getAction = ( + actionId: string, + options?: SecondParameter, +) => { + return customFetch( + { url: `/v1/actions/${actionId}`, method: "GET" }, + options, + ); }; /** * Generate the transactions needed to enter a yield position with the provided parameters. * @summary Enter a yield */ -export const enterYield = (createActionDto: CreateActionDto) => { - return customFetch({ - url: `/v1/actions/enter`, - method: "POST", - headers: { "Content-Type": "application/json" }, - data: createActionDto, - }); +export const enterYield = ( + createActionDto: CreateActionDto, + options?: SecondParameter, +) => { + return customFetch( + { + url: `/v1/actions/enter`, + method: "POST", + headers: { "Content-Type": "application/json" }, + data: createActionDto, + }, + options, + ); }; /** * Generate the transactions needed to exit a yield position with the provided parameters. * @summary Exit a yield */ -export const exitYield = (createActionDto: CreateActionDto) => { - return customFetch({ - url: `/v1/actions/exit`, - method: "POST", - headers: { "Content-Type": "application/json" }, - data: createActionDto, - }); +export const exitYield = ( + createActionDto: CreateActionDto, + options?: SecondParameter, +) => { + return customFetch( + { + url: `/v1/actions/exit`, + method: "POST", + headers: { "Content-Type": "application/json" }, + data: createActionDto, + }, + options, + ); }; /** * Generate the transactions needed to perform management actions on a yield position. * @summary Manage a yield */ -export const manageYield = (createManageActionDto: CreateManageActionDto) => { - return customFetch({ - url: `/v1/actions/manage`, - method: "POST", - headers: { "Content-Type": "application/json" }, - data: createManageActionDto, - }); +export const manageYield = ( + createManageActionDto: CreateManageActionDto, + options?: SecondParameter, +) => { + return customFetch( + { + url: `/v1/actions/manage`, + method: "POST", + headers: { "Content-Type": "application/json" }, + data: createManageActionDto, + }, + options, + ); }; /** @@ -157,32 +194,42 @@ export const manageYield = (createManageActionDto: CreateManageActionDto) => { export const submitTransactionHash = ( transactionId: string, submitHashDto: SubmitHashDto, + options?: SecondParameter, ) => { - return customFetch({ - url: `/v1/transactions/${transactionId}/submit-hash`, - method: "PUT", - headers: { "Content-Type": "application/json" }, - data: submitHashDto, - }); + return customFetch( + { + url: `/v1/transactions/${transactionId}/submit-hash`, + method: "PUT", + headers: { "Content-Type": "application/json" }, + data: submitHashDto, + }, + options, + ); }; /** * Retrieve detailed information about a specific transaction including current status, hash, and execution details. * @summary Get transaction details */ -export const getTransaction = (transactionId: string) => { - return customFetch({ - url: `/v1/transactions/${transactionId}`, - method: "GET", - }); +export const getTransaction = ( + transactionId: string, + options?: SecondParameter, +) => { + return customFetch( + { url: `/v1/transactions/${transactionId}`, method: "GET" }, + options, + ); }; /** * Retrieve a list of all supported networks that can be used for filtering yields and other operations. * @summary List all available networks */ -export const getNetworks = () => { - return customFetch({ url: `/v1/networks`, method: "GET" }); +export const getNetworks = (options?: SecondParameter) => { + return customFetch( + { url: `/v1/networks`, method: "GET" }, + options, + ); }; /** @@ -191,31 +238,37 @@ export const getNetworks = () => { */ export const getProviders = ( params?: ProvidersControllerGetProvidersParams, + options?: SecondParameter, ) => { - return customFetch({ - url: `/v1/providers`, - method: "GET", - params, - }); + return customFetch( + { url: `/v1/providers`, method: "GET", params }, + options, + ); }; /** * Returns detailed information about a specific provider. * @summary Get provider by ID */ -export const getProvider = (providerId: string) => { - return customFetch({ - url: `/v1/providers/${providerId}`, - method: "GET", - }); +export const getProvider = ( + providerId: string, + options?: SecondParameter, +) => { + return customFetch( + { url: `/v1/providers/${providerId}`, method: "GET" }, + options, + ); }; /** * Get the health status of the yield API with current timestamp * @summary Health check */ -export const health = () => { - return customFetch({ url: `/health`, method: "GET" }); +export const health = (options?: SecondParameter) => { + return customFetch( + { url: `/health`, method: "GET" }, + options, + ); }; export type GetYieldsResult = NonNullable< diff --git a/src/api/schemas/networkDtoId.ts b/src/api/schemas/networkDtoId.ts index 5eb66b9..ebf450c 100644 --- a/src/api/schemas/networkDtoId.ts +++ b/src/api/schemas/networkDtoId.ts @@ -33,6 +33,7 @@ export const NetworkDtoId = { viction: "viction", core: "core", sonic: "sonic", + katana: "katana", agoric: "agoric", akash: "akash", axelar: "axelar", diff --git a/src/api/schemas/networks.ts b/src/api/schemas/networks.ts index 14bd8aa..5bd9d4c 100644 --- a/src/api/schemas/networks.ts +++ b/src/api/schemas/networks.ts @@ -33,6 +33,7 @@ export const Networks = { viction: "viction", core: "core", sonic: "sonic", + katana: "katana", agoric: "agoric", akash: "akash", axelar: "axelar", diff --git a/src/api/schemas/tokenDtoNetwork.ts b/src/api/schemas/tokenDtoNetwork.ts index 829dc69..42fb89d 100644 --- a/src/api/schemas/tokenDtoNetwork.ts +++ b/src/api/schemas/tokenDtoNetwork.ts @@ -34,6 +34,7 @@ export const TokenDtoNetwork = { viction: "viction", core: "core", sonic: "sonic", + katana: "katana", agoric: "agoric", akash: "akash", axelar: "axelar", diff --git a/src/api/schemas/transactionDtoNetwork.ts b/src/api/schemas/transactionDtoNetwork.ts index 3eb3288..9339e3a 100644 --- a/src/api/schemas/transactionDtoNetwork.ts +++ b/src/api/schemas/transactionDtoNetwork.ts @@ -34,6 +34,7 @@ export const TransactionDtoNetwork = { viction: "viction", core: "core", sonic: "sonic", + katana: "katana", agoric: "agoric", akash: "akash", axelar: "axelar", diff --git a/src/api/schemas/yieldDtoNetwork.ts b/src/api/schemas/yieldDtoNetwork.ts index b927549..733a202 100644 --- a/src/api/schemas/yieldDtoNetwork.ts +++ b/src/api/schemas/yieldDtoNetwork.ts @@ -34,6 +34,7 @@ export const YieldDtoNetwork = { viction: "viction", core: "core", sonic: "sonic", + katana: "katana", agoric: "agoric", akash: "akash", axelar: "axelar", diff --git a/src/api/schemas/yieldQueryDtoNetwork.ts b/src/api/schemas/yieldQueryDtoNetwork.ts index 67368c0..35d6495 100644 --- a/src/api/schemas/yieldQueryDtoNetwork.ts +++ b/src/api/schemas/yieldQueryDtoNetwork.ts @@ -34,6 +34,7 @@ export const YieldQueryDtoNetwork = { viction: "viction", core: "core", sonic: "sonic", + katana: "katana", agoric: "agoric", akash: "akash", axelar: "axelar", diff --git a/src/api/schemas/yieldsControllerGetYieldsNetwork.ts b/src/api/schemas/yieldsControllerGetYieldsNetwork.ts index 1e45676..90039dc 100644 --- a/src/api/schemas/yieldsControllerGetYieldsNetwork.ts +++ b/src/api/schemas/yieldsControllerGetYieldsNetwork.ts @@ -31,6 +31,7 @@ export const YieldsControllerGetYieldsNetwork = { viction: "viction", core: "core", sonic: "sonic", + katana: "katana", agoric: "agoric", akash: "akash", axelar: "axelar",