Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions src/api/info/_methods/usdcRouting.ts
Original file line number Diff line number Diff line change
@@ -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<typeof UsdcRoutingRequest>;

/**
* 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<UsdcRoutingResponse> {
const request = parse(UsdcRoutingRequest, {
type: "usdcRouting",
});
return config.transport.request("info", request, signal);
}
29 changes: 29 additions & 0 deletions src/api/info/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -1899,6 +1900,33 @@ export class InfoClient<C extends InfoConfig = InfoConfig> {
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<UsdcRoutingResponse> {
return usdcRouting(this.config_, signal);
}

/**
* Request user abstraction state.
*
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/api/info/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
18 changes: 18 additions & 0 deletions tests/api/info/usdcRouting.test.ts
Original file line number Diff line number Diff line change
@@ -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",
]);
},
});