diff --git a/src/api/info/_methods/usdcRouting.ts b/src/api/info/_methods/usdcRouting.ts new file mode 100644 index 00000000..a9539772 --- /dev/null +++ b/src/api/info/_methods/usdcRouting.ts @@ -0,0 +1,75 @@ +import * as v from "@valibot/valibot"; + +// ============================================================ +// API Schemas +// ============================================================ + +/** + * Request USDC transfer routing. + * @see null + */ +export const UsdcRoutingRequest = /* @__PURE__ */ (() => { + return v.object({ + /** Type of request. */ + type: v.literal("usdcRouting"), + }); +})(); +export type UsdcRoutingRequest = v.InferOutput; + +/** + * Routes currently used to move USDC in and out of the platform. + * @see null + */ +export type UsdcRoutingResponse = { + /** + * Route used for deposits: + * - `"bridge"`: Hyperliquid USDC bridge. + * - `"cctp"`: Circle Cross-Chain Transfer Protocol. + */ + depositRoute: "bridge" | "cctp"; + /** + * Route used for withdrawals: + * - `"bridge"`: Hyperliquid USDC bridge. + * - `"cctp"`: Circle Cross-Chain Transfer Protocol. + */ + withdrawalRoute: "bridge" | "cctp"; +}; + +// ============================================================ +// Execution Logic +// ============================================================ + +import { parse } from "../../../_base.ts"; +import type { InfoConfig } from "./_base/mod.ts"; + +/** + * Request USDC transfer routing. + * + * @param config General configuration for Info API requests. + * @param signal {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | AbortSignal} to cancel the request. + * @return Routes currently used to move USDC in and out of the platform. + * + * @throws {ValidationError} When the request parameters fail validation (before sending). + * @throws {TransportError} When the transport layer throws an error. + * + * @example + * ```ts + * import { HttpTransport } from "@nktkas/hyperliquid"; + * import { usdcRouting } from "@nktkas/hyperliquid/api/info"; + * + * const transport = new HttpTransport(); // or `WebSocketTransport` + * + * const data = await usdcRouting({ transport }); + * ``` + * + * @see null + */ +export function usdcRouting( + config: InfoConfig, + signal?: AbortSignal, +): Promise { + const request = parse(UsdcRoutingRequest, { + type: "usdcRouting", + }); + return config.transport.request("info", request, signal); +} diff --git a/src/api/info/client.ts b/src/api/info/client.ts index eb282888..189609d6 100644 --- a/src/api/info/client.ts +++ b/src/api/info/client.ts @@ -151,6 +151,7 @@ import { subAccounts, type SubAccountsParameters, type SubAccountsResponse } fro import { subAccounts2, type SubAccounts2Parameters, type SubAccounts2Response } from "./_methods/subAccounts2.ts"; import { tokenDetails, type TokenDetailsParameters, type TokenDetailsResponse } from "./_methods/tokenDetails.ts"; import { twapHistory, type TwapHistoryParameters, type TwapHistoryResponse } from "./_methods/twapHistory.ts"; +import { usdcRouting, type UsdcRoutingResponse } from "./_methods/usdcRouting.ts"; import { userAbstraction, type UserAbstractionParameters, @@ -1899,6 +1900,33 @@ export class InfoClient { return twapHistory(this.config_, params, signal); } + /** + * Request USDC transfer routing. + * + * @param signal {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | AbortSignal} to cancel the request. + * @return Routes currently used to move USDC in and out of the platform. + * + * @throws {ValidationError} When the request parameters fail validation (before sending). + * @throws {TransportError} When the transport layer throws an error. + * + * @example + * ```ts + * import * as hl from "@nktkas/hyperliquid"; + * + * const transport = new hl.HttpTransport(); // or `WebSocketTransport` + * const client = new hl.InfoClient({ transport }); + * + * const data = await client.usdcRouting(); + * ``` + * + * @see null + */ + usdcRouting( + signal?: AbortSignal, + ): Promise { + return usdcRouting(this.config_, signal); + } + /** * Request user abstraction state. * @@ -2528,6 +2556,7 @@ export type { SubAccountsParameters, SubAccountsResponse } from "./_methods/subA export type { SubAccounts2Parameters, SubAccounts2Response } from "./_methods/subAccounts2.ts"; export type { TokenDetailsParameters, TokenDetailsResponse } from "./_methods/tokenDetails.ts"; export type { TwapHistoryParameters, TwapHistoryResponse } from "./_methods/twapHistory.ts"; +export type { UsdcRoutingResponse } from "./_methods/usdcRouting.ts"; export type { UserAbstractionParameters, UserAbstractionResponse } from "./_methods/userAbstraction.ts"; export type { UserBorrowLendInterestParameters, diff --git a/src/api/info/mod.ts b/src/api/info/mod.ts index e54cabbb..0463b5fe 100644 --- a/src/api/info/mod.ts +++ b/src/api/info/mod.ts @@ -81,6 +81,7 @@ export * from "./_methods/subAccounts.ts"; export * from "./_methods/subAccounts2.ts"; export * from "./_methods/tokenDetails.ts"; export * from "./_methods/twapHistory.ts"; +export * from "./_methods/usdcRouting.ts"; export * from "./_methods/userAbstraction.ts"; export * from "./_methods/userBorrowLendInterest.ts"; export * from "./_methods/userDexAbstraction.ts"; diff --git a/tests/api/info/usdcRouting.test.ts b/tests/api/info/usdcRouting.test.ts new file mode 100644 index 00000000..be6c1cb2 --- /dev/null +++ b/tests/api/info/usdcRouting.test.ts @@ -0,0 +1,18 @@ +import { schemaCoverage } from "../_utils/schemaCoverage.ts"; +import { typeToJsonSchema } from "../_utils/typeToJsonSchema.ts"; +import { runTest } from "./_t.ts"; + +const sourceFile = new URL("../../../src/api/info/_methods/usdcRouting.ts", import.meta.url).pathname; +const responseSchema = typeToJsonSchema(sourceFile, "UsdcRoutingResponse"); + +runTest({ + name: "usdcRouting", + codeTestFn: async (_t, client) => { + const data = await Promise.all([client.usdcRouting()]); + + schemaCoverage(responseSchema, data, [ + "#/properties/depositRoute/enum/0", + "#/properties/withdrawalRoute/enum/0", + ]); + }, +});