@0x/swap-ts-sdk
Version:
0x Swap API TypeScript Client
1,043 lines (1,036 loc) • 302 kB
TypeScript
import { DataTransformerOptions, AnyRootConfig, BuildProcedure, inferParser, ProcedureRouterRecord, RootConfig, DefaultDataTransformer, TRPCError, ProcedureType, unsetMarker } from '@trpc/server';
import { TRPCErrorShape, TRPC_ERROR_CODE_NUMBER, TRPC_ERROR_CODE_KEY } from '@trpc/server/rpc';
import { OpenApiMeta } from 'trpc-openapi';
import { SomeZodObject, z } from 'zod';
import { RouterDef } from '@trpc/server/dist/core/router';
import { DefaultErrorData } from '@trpc/server/dist/error/formatter';
import * as _0x_utils from '@0x/utils';
import { ChainId as ChainId$1 } from '@0x/contract-addresses';
/**
* Setup interfaces for `initTRPC`
*/
interface RpcSetup {
ctx?: object;
errorData?: Record<string, unknown>;
meta?: object;
transformer?: DataTransformerOptions;
}
type UnsetMarker = typeof unsetMarker;
type Parser = any extends inferParser<infer X> ? X : never;
/**
* Define a procedure with a zod input and zod output
*/
type defineProcedure<TType extends 'query' | 'mutation', TInput, TOutput, TConfig extends AnyRootConfig> = BuildProcedure<TType, {
_config: TConfig;
_meta: any;
_ctx_out: any;
_input_in: TInput extends undefined ? UnsetMarker : TInput extends Parser ? inferParser<TInput>['in'] : TInput;
_input_out: TInput extends undefined ? UnsetMarker : TInput extends Parser ? inferParser<TInput>['out'] : TInput;
_output_in: TOutput extends undefined ? UnsetMarker : TOutput extends Parser ? inferParser<TOutput>['in'] : any;
_output_out: TOutput extends undefined ? UnsetMarker : TOutput extends Parser ? inferParser<TOutput>['out'] : any;
}, TOutput extends undefined ? void : TOutput extends Parser ? inferParser<TOutput>['out'] : TOutput>;
/**
* Define a router by specifying its procedures and
* RPC setup.
*/
type defineRouter<TProcedures extends ProcedureRouterRecord, TTrpcSetup extends RpcSetup> = {
_def: RouterDef<RootConfig<{
ctx: TTrpcSetup extends {
ctx: infer TCtx;
} ? TCtx : any;
meta: TTrpcSetup extends {
meta: infer TMeta;
} ? TMeta : any;
errorShape: TRPCErrorShape<TRPC_ERROR_CODE_NUMBER, inferErrorData<TTrpcSetup>>;
transformer: TTrpcSetup['transformer'] extends object ? TTrpcSetup['transformer'] : DefaultDataTransformer;
}>, TProcedures>;
createCaller: any;
getErrorShape: (opts: {
error: TRPCError;
type: ProcedureType | 'unknown';
path: string | undefined;
input: unknown;
ctx: undefined | TTrpcSetup extends {
ctx: infer TCtx;
} ? TCtx : undefined;
}) => TRPCErrorShape<TRPC_ERROR_CODE_NUMBER, inferErrorData<TTrpcSetup>>;
};
type inferErrorData<TRpcSetup extends RpcSetup> = TRpcSetup extends {
errorData: infer TErrorData;
} ? TErrorData extends Record<string, unknown> ? TErrorData : DefaultErrorData : DefaultErrorData;
type UvOpenApiMeta = NonNullable<OpenApiMeta['openapi']>;
type UvHeaders = UvOpenApiMeta['headers'];
/**
* Describes the error that can be returned in the http response on an endpoint.
* The response will the the HTTP version of `code` and the body will be a JSON object of:
* ```
* {
* name: string; // The name of the error
* message: string; // A human readable message generated at runtime
* data?: object; // Matches the output of `dataSchema`
* }
*/
type UvError = {
description: string;
dataSchema: SomeZodObject;
code: TRPC_ERROR_CODE_KEY;
};
/**
* The definition of an endpoint needed to generate an OpenAPI spec,
* create the type for a tRPC procedure, and create appropriate
* documentation.
*/
type UvEndpoint<TErrors extends Record</* error name, e.g. MY_ERROR */ string, UvError>> = {
input: z.ZodType;
output: z.ZodType;
enabledChainIds: number[];
openApiMeta: UvOpenApiMeta;
headers?: UvHeaders;
errorNames: (keyof TErrors)[];
};
/**
* A description of the endpoints that make up an API
*/
type UvEndpointTree<TErrors extends Record<string, UvError>> = {
[key: string]: UvEndpointTree<TErrors> | UvEndpoint<TErrors>;
};
/**
* Takes a router typescript definition and changes it to a TypeScript type
*/
type uvSpecToRouter<TProcedures extends UvEndpointTree<Record<string, UvError>>, TRpcSetup extends RpcSetup> = defineRouter<{
[TKey in keyof TProcedures]: TKey extends string ? TProcedures[TKey] extends infer TValue ? TValue extends UvEndpoint<Record<string, UvError>> ? defineProcedure<TValue['openApiMeta']['method'] extends 'GET' ? 'query' : 'mutation', TValue['input'], TValue['output'], RootConfig<{
ctx: TRpcSetup extends {
ctx: infer TCtx;
} ? TCtx : any;
meta: TRpcSetup extends {
meta: infer TMeta;
} ? TMeta : any;
errorShape: TRPCErrorShape<TRPC_ERROR_CODE_NUMBER, inferErrorData<TRpcSetup>>;
transformer: TRpcSetup extends {
transformer: infer TTransformer;
} ? TTransformer : DefaultDataTransformer;
}>> : TValue extends UvEndpointTree<Record<string, UvError>> ? uvSpecToRouter<TValue, TRpcSetup> : never : never : never;
}, TRpcSetup>;
type Eip712Object = {
[key: string]: string | string[] | number | number[] | boolean | boolean[] | Eip712Object | Eip712Object[];
};
/**
* Enum of chain ids used by 0x services
*/
declare enum ChainId {
Ethereum = 1,
Goerli = 5,
Optimism = 10,
BSC = 56,
Polygon = 137,
Fantom = 250,
Ganache = 1337,
Mantle = 5000,
Base = 8453,
Arbitrum = 42161,
Avalanche = 43114,
Celo = 42220,
Linea = 59144,
PolygonMumbai = 80001,
Blast = 81457,
Scroll = 534352,
Sepolia = 11155111
}
/**
* Supported chain ids for gasless v1
*/
declare const GASLESS_V1_CHAIN_IDS: ChainId$1[];
type GaslessV1ChainId = (typeof GASLESS_V1_CHAIN_IDS)[number];
/**
* Supported chain ids for swap v2 (permit2 and allowance holder)
*/
declare const SWAP_V2_CHAIN_IDS: ChainId[];
type SwapV2ChainId = (typeof SWAP_V2_CHAIN_IDS)[number];
/**
* Supported chain ids for gasless v2
*/
declare const GASLESS_V2_CHAIN_IDS: ChainId[];
type GaslessV2ChainId = (typeof GASLESS_V2_CHAIN_IDS)[number];
declare enum JobFailureReason {
TransactionSimulationFailed = "transaction_simulation_failed",
OrderExpired = "order_expired",
LastLookDeclined = "last_look_declined",// deprecated
TransactionReverted = "transaction_reverted",
MarketMakerSignatureError = "market_maker_sigature_error",
InvalidBalance = "invalid_balance",
InternalError = "internal_error"
}
declare const uv2routerDefinition: {
swap: {
permit2: {
getPrice: {
openApiMeta: {
method: "GET";
path: "/swap/permit2/price";
summary: string;
description: string;
headers: ({
description: string;
in: "header";
name: string;
required: true;
schema: {
type: "string";
example?: undefined;
};
} | {
description: string;
in: "header";
name: string;
required: true;
schema: {
type: "string";
example: string;
};
})[];
example: {
request: {
chainId: number;
sellToken: string;
buyToken: string;
sellAmount: string;
taker: string;
};
response: {
blockNumber: string;
buyAmount: string;
buyToken: string;
fees: {
integratorFee: null;
zeroExFee: null;
gasFee: null;
};
gas: string;
gasPrice: string;
issues: {
allowance: {
actual: string;
spender: string;
};
balance: {
token: string;
actual: string;
expected: string;
};
simulationIncomplete: boolean;
invalidSourcesPassed: never[];
};
liquidityAvailable: boolean;
minBuyAmount: string;
route: {
fills: {
from: string;
to: string;
source: string;
proportionBps: string;
}[];
tokens: {
address: string;
symbol: string;
}[];
};
sellAmount: string;
sellToken: string;
tokenMetadata: {
buyToken: {
buyTaxBps: string;
sellTaxBps: string;
};
sellToken: {
buyTaxBps: string;
sellTaxBps: string;
};
};
totalNetworkFee: string;
zid: string;
};
};
};
enabledChainIds: number[];
input: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodObject<{
chainId: z.ZodEffects<z.ZodNumber, ChainId, number>;
buyToken: z.ZodString;
sellToken: z.ZodString;
sellAmount: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodString, _0x_utils.BigNumber, string>, _0x_utils.BigNumber, string>, _0x_utils.BigNumber, unknown>;
taker: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
txOrigin: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
swapFeeRecipient: z.ZodOptional<z.ZodString>;
swapFeeBps: z.ZodOptional<z.ZodNumber>;
swapFeeToken: z.ZodOptional<z.ZodString>;
tradeSurplusRecipient: z.ZodOptional<z.ZodString>;
gasPrice: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodString, _0x_utils.BigNumber, string>, _0x_utils.BigNumber, string>, _0x_utils.BigNumber, unknown>>;
slippageBps: z.ZodDefault<z.ZodNumber>;
excludedSources: z.ZodOptional<z.ZodString>;
}, "strip", z.ZodTypeAny, {
chainId: ChainId;
sellToken: string;
buyToken: string;
sellAmount: _0x_utils.BigNumber;
slippageBps: number;
taker?: string | undefined;
txOrigin?: string | undefined;
swapFeeRecipient?: string | undefined;
swapFeeBps?: number | undefined;
swapFeeToken?: string | undefined;
tradeSurplusRecipient?: string | undefined;
gasPrice?: _0x_utils.BigNumber | undefined;
excludedSources?: string | undefined;
}, {
chainId: number;
sellToken: string;
buyToken: string;
sellAmount?: unknown;
taker?: string | undefined;
txOrigin?: string | undefined;
swapFeeRecipient?: string | undefined;
swapFeeBps?: number | undefined;
swapFeeToken?: string | undefined;
tradeSurplusRecipient?: string | undefined;
gasPrice?: unknown;
slippageBps?: number | undefined;
excludedSources?: string | undefined;
}>, {
chainId: ChainId;
sellToken: string;
buyToken: string;
sellAmount: _0x_utils.BigNumber;
slippageBps: number;
taker?: string | undefined;
txOrigin?: string | undefined;
swapFeeRecipient?: string | undefined;
swapFeeBps?: number | undefined;
swapFeeToken?: string | undefined;
tradeSurplusRecipient?: string | undefined;
gasPrice?: _0x_utils.BigNumber | undefined;
excludedSources?: string | undefined;
}, {
chainId: number;
sellToken: string;
buyToken: string;
sellAmount?: unknown;
taker?: string | undefined;
txOrigin?: string | undefined;
swapFeeRecipient?: string | undefined;
swapFeeBps?: number | undefined;
swapFeeToken?: string | undefined;
tradeSurplusRecipient?: string | undefined;
gasPrice?: unknown;
slippageBps?: number | undefined;
excludedSources?: string | undefined;
}>, {
chainId: ChainId;
sellToken: string;
buyToken: string;
sellAmount: _0x_utils.BigNumber;
slippageBps: number;
taker?: string | undefined;
txOrigin?: string | undefined;
swapFeeRecipient?: string | undefined;
swapFeeBps?: number | undefined;
swapFeeToken?: string | undefined;
tradeSurplusRecipient?: string | undefined;
gasPrice?: _0x_utils.BigNumber | undefined;
excludedSources?: string | undefined;
}, {
chainId: number;
sellToken: string;
buyToken: string;
sellAmount?: unknown;
taker?: string | undefined;
txOrigin?: string | undefined;
swapFeeRecipient?: string | undefined;
swapFeeBps?: number | undefined;
swapFeeToken?: string | undefined;
tradeSurplusRecipient?: string | undefined;
gasPrice?: unknown;
slippageBps?: number | undefined;
excludedSources?: string | undefined;
}>, {
chainId: ChainId;
sellToken: string;
buyToken: string;
sellAmount: _0x_utils.BigNumber;
slippageBps: number;
taker?: string | undefined;
txOrigin?: string | undefined;
swapFeeRecipient?: string | undefined;
swapFeeBps?: number | undefined;
swapFeeToken?: string | undefined;
tradeSurplusRecipient?: string | undefined;
gasPrice?: _0x_utils.BigNumber | undefined;
excludedSources?: string | undefined;
}, {
chainId: number;
sellToken: string;
buyToken: string;
sellAmount?: unknown;
taker?: string | undefined;
txOrigin?: string | undefined;
swapFeeRecipient?: string | undefined;
swapFeeBps?: number | undefined;
swapFeeToken?: string | undefined;
tradeSurplusRecipient?: string | undefined;
gasPrice?: unknown;
slippageBps?: number | undefined;
excludedSources?: string | undefined;
}>;
output: z.ZodDiscriminatedUnion<"liquidityAvailable", [z.ZodObject<{
blockNumber: z.ZodPipeline<z.ZodEffects<z.ZodType<_0x_utils.BigNumber, z.ZodTypeDef, _0x_utils.BigNumber>, _0x_utils.BigNumber, _0x_utils.BigNumber>, z.ZodString>;
buyAmount: z.ZodPipeline<z.ZodEffects<z.ZodType<_0x_utils.BigNumber, z.ZodTypeDef, _0x_utils.BigNumber>, _0x_utils.BigNumber, _0x_utils.BigNumber>, z.ZodString>;
buyToken: z.ZodString;
fees: z.ZodObject<{
integratorFee: z.ZodNullable<z.ZodObject<{
amount: z.ZodPipeline<z.ZodEffects<z.ZodType<_0x_utils.BigNumber, z.ZodTypeDef, _0x_utils.BigNumber>, _0x_utils.BigNumber, _0x_utils.BigNumber>, z.ZodString>;
token: z.ZodString;
type: z.ZodEnum<["volume"]>;
}, "strip", z.ZodTypeAny, {
amount: string;
type: "volume";
token: string;
}, {
amount: _0x_utils.BigNumber;
type: "volume";
token: string;
}>>;
zeroExFee: z.ZodNullable<z.ZodObject<{
amount: z.ZodPipeline<z.ZodEffects<z.ZodType<_0x_utils.BigNumber, z.ZodTypeDef, _0x_utils.BigNumber>, _0x_utils.BigNumber, _0x_utils.BigNumber>, z.ZodString>;
token: z.ZodString;
type: z.ZodEnum<["volume"]>;
}, "strip", z.ZodTypeAny, {
amount: string;
type: "volume";
token: string;
}, {
amount: _0x_utils.BigNumber;
type: "volume";
token: string;
}>>;
gasFee: z.ZodNullable<z.ZodObject<{
amount: z.ZodPipeline<z.ZodEffects<z.ZodType<_0x_utils.BigNumber, z.ZodTypeDef, _0x_utils.BigNumber>, _0x_utils.BigNumber, _0x_utils.BigNumber>, z.ZodString>;
token: z.ZodString;
type: z.ZodEnum<["gas"]>;
}, "strip", z.ZodTypeAny, {
amount: string;
type: "gas";
token: string;
}, {
amount: _0x_utils.BigNumber;
type: "gas";
token: string;
}>>;
}, "strip", z.ZodTypeAny, {
integratorFee: {
amount: string;
type: "volume";
token: string;
} | null;
zeroExFee: {
amount: string;
type: "volume";
token: string;
} | null;
gasFee: {
amount: string;
type: "gas";
token: string;
} | null;
}, {
integratorFee: {
amount: _0x_utils.BigNumber;
type: "volume";
token: string;
} | null;
zeroExFee: {
amount: _0x_utils.BigNumber;
type: "volume";
token: string;
} | null;
gasFee: {
amount: _0x_utils.BigNumber;
type: "gas";
token: string;
} | null;
}>;
gas: z.ZodNullable<z.ZodPipeline<z.ZodEffects<z.ZodType<_0x_utils.BigNumber, z.ZodTypeDef, _0x_utils.BigNumber>, _0x_utils.BigNumber, _0x_utils.BigNumber>, z.ZodString>>;
gasPrice: z.ZodPipeline<z.ZodEffects<z.ZodType<_0x_utils.BigNumber, z.ZodTypeDef, _0x_utils.BigNumber>, _0x_utils.BigNumber, _0x_utils.BigNumber>, z.ZodString>;
issues: z.ZodObject<{
allowance: z.ZodNullable<z.ZodObject<{
actual: z.ZodPipeline<z.ZodEffects<z.ZodType<_0x_utils.BigNumber, z.ZodTypeDef, _0x_utils.BigNumber>, _0x_utils.BigNumber, _0x_utils.BigNumber>, z.ZodString>;
spender: z.ZodString;
}, "strip", z.ZodTypeAny, {
spender: string;
actual: string;
}, {
spender: string;
actual: _0x_utils.BigNumber;
}>>;
balance: z.ZodNullable<z.ZodObject<{
token: z.ZodString;
actual: z.ZodPipeline<z.ZodEffects<z.ZodType<_0x_utils.BigNumber, z.ZodTypeDef, _0x_utils.BigNumber>, _0x_utils.BigNumber, _0x_utils.BigNumber>, z.ZodString>;
expected: z.ZodPipeline<z.ZodEffects<z.ZodType<_0x_utils.BigNumber, z.ZodTypeDef, _0x_utils.BigNumber>, _0x_utils.BigNumber, _0x_utils.BigNumber>, z.ZodString>;
}, "strip", z.ZodTypeAny, {
expected: string;
token: string;
actual: string;
}, {
expected: _0x_utils.BigNumber;
token: string;
actual: _0x_utils.BigNumber;
}>>;
simulationIncomplete: z.ZodBoolean;
invalidSourcesPassed: z.ZodArray<z.ZodString, "many">;
}, "strip", z.ZodTypeAny, {
balance: {
expected: string;
token: string;
actual: string;
} | null;
allowance: {
spender: string;
actual: string;
} | null;
simulationIncomplete: boolean;
invalidSourcesPassed: string[];
}, {
balance: {
expected: _0x_utils.BigNumber;
token: string;
actual: _0x_utils.BigNumber;
} | null;
allowance: {
spender: string;
actual: _0x_utils.BigNumber;
} | null;
simulationIncomplete: boolean;
invalidSourcesPassed: string[];
}>;
liquidityAvailable: z.ZodLiteral<true>;
minBuyAmount: z.ZodPipeline<z.ZodEffects<z.ZodType<_0x_utils.BigNumber, z.ZodTypeDef, _0x_utils.BigNumber>, _0x_utils.BigNumber, _0x_utils.BigNumber>, z.ZodString>;
route: z.ZodObject<{
fills: z.ZodArray<z.ZodObject<{
from: z.ZodString;
to: z.ZodString;
source: z.ZodString;
proportionBps: z.ZodPipeline<z.ZodEffects<z.ZodType<_0x_utils.BigNumber, z.ZodTypeDef, _0x_utils.BigNumber>, _0x_utils.BigNumber, _0x_utils.BigNumber>, z.ZodString>;
}, "strip", z.ZodTypeAny, {
from: string;
to: string;
source: string;
proportionBps: string;
}, {
from: string;
to: string;
source: string;
proportionBps: _0x_utils.BigNumber;
}>, "many">;
tokens: z.ZodArray<z.ZodObject<{
address: z.ZodString;
symbol: z.ZodString;
}, "strip", z.ZodTypeAny, {
symbol: string;
address: string;
}, {
symbol: string;
address: string;
}>, "many">;
}, "strip", z.ZodTypeAny, {
tokens: {
symbol: string;
address: string;
}[];
fills: {
from: string;
to: string;
source: string;
proportionBps: string;
}[];
}, {
tokens: {
symbol: string;
address: string;
}[];
fills: {
from: string;
to: string;
source: string;
proportionBps: _0x_utils.BigNumber;
}[];
}>;
sellAmount: z.ZodPipeline<z.ZodEffects<z.ZodType<_0x_utils.BigNumber, z.ZodTypeDef, _0x_utils.BigNumber>, _0x_utils.BigNumber, _0x_utils.BigNumber>, z.ZodString>;
sellToken: z.ZodString;
tokenMetadata: z.ZodObject<{
buyToken: z.ZodObject<{
buyTaxBps: z.ZodNullable<z.ZodPipeline<z.ZodEffects<z.ZodType<_0x_utils.BigNumber, z.ZodTypeDef, _0x_utils.BigNumber>, _0x_utils.BigNumber, _0x_utils.BigNumber>, z.ZodString>>;
sellTaxBps: z.ZodNullable<z.ZodPipeline<z.ZodEffects<z.ZodType<_0x_utils.BigNumber, z.ZodTypeDef, _0x_utils.BigNumber>, _0x_utils.BigNumber, _0x_utils.BigNumber>, z.ZodString>>;
}, "strip", z.ZodTypeAny, {
buyTaxBps: string | null;
sellTaxBps: string | null;
}, {
buyTaxBps: _0x_utils.BigNumber | null;
sellTaxBps: _0x_utils.BigNumber | null;
}>;
sellToken: z.ZodObject<{
buyTaxBps: z.ZodNullable<z.ZodPipeline<z.ZodEffects<z.ZodType<_0x_utils.BigNumber, z.ZodTypeDef, _0x_utils.BigNumber>, _0x_utils.BigNumber, _0x_utils.BigNumber>, z.ZodString>>;
sellTaxBps: z.ZodNullable<z.ZodPipeline<z.ZodEffects<z.ZodType<_0x_utils.BigNumber, z.ZodTypeDef, _0x_utils.BigNumber>, _0x_utils.BigNumber, _0x_utils.BigNumber>, z.ZodString>>;
}, "strip", z.ZodTypeAny, {
buyTaxBps: string | null;
sellTaxBps: string | null;
}, {
buyTaxBps: _0x_utils.BigNumber | null;
sellTaxBps: _0x_utils.BigNumber | null;
}>;
}, "strip", z.ZodTypeAny, {
sellToken: {
buyTaxBps: string | null;
sellTaxBps: string | null;
};
buyToken: {
buyTaxBps: string | null;
sellTaxBps: string | null;
};
}, {
sellToken: {
buyTaxBps: _0x_utils.BigNumber | null;
sellTaxBps: _0x_utils.BigNumber | null;
};
buyToken: {
buyTaxBps: _0x_utils.BigNumber | null;
sellTaxBps: _0x_utils.BigNumber | null;
};
}>;
totalNetworkFee: z.ZodNullable<z.ZodPipeline<z.ZodEffects<z.ZodType<_0x_utils.BigNumber, z.ZodTypeDef, _0x_utils.BigNumber>, _0x_utils.BigNumber, _0x_utils.BigNumber>, z.ZodString>>;
zid: z.ZodString;
}, "strip", z.ZodTypeAny, {
fees: {
integratorFee: {
amount: string;
type: "volume";
token: string;
} | null;
zeroExFee: {
amount: string;
type: "volume";
token: string;
} | null;
gasFee: {
amount: string;
type: "gas";
token: string;
} | null;
};
zid: string;
gas: string | null;
sellToken: string;
buyToken: string;
sellAmount: string;
minBuyAmount: string;
buyAmount: string;
blockNumber: string;
gasPrice: string;
route: {
tokens: {
symbol: string;
address: string;
}[];
fills: {
from: string;
to: string;
source: string;
proportionBps: string;
}[];
};
issues: {
balance: {
expected: string;
token: string;
actual: string;
} | null;
allowance: {
spender: string;
actual: string;
} | null;
simulationIncomplete: boolean;
invalidSourcesPassed: string[];
};
liquidityAvailable: true;
tokenMetadata: {
sellToken: {
buyTaxBps: string | null;
sellTaxBps: string | null;
};
buyToken: {
buyTaxBps: string | null;
sellTaxBps: string | null;
};
};
totalNetworkFee: string | null;
}, {
fees: {
integratorFee: {
amount: _0x_utils.BigNumber;
type: "volume";
token: string;
} | null;
zeroExFee: {
amount: _0x_utils.BigNumber;
type: "volume";
token: string;
} | null;
gasFee: {
amount: _0x_utils.BigNumber;
type: "gas";
token: string;
} | null;
};
zid: string;
gas: _0x_utils.BigNumber | null;
sellToken: string;
buyToken: string;
sellAmount: _0x_utils.BigNumber;
minBuyAmount: _0x_utils.BigNumber;
buyAmount: _0x_utils.BigNumber;
blockNumber: _0x_utils.BigNumber;
gasPrice: _0x_utils.BigNumber;
route: {
tokens: {
symbol: string;
address: string;
}[];
fills: {
from: string;
to: string;
source: string;
proportionBps: _0x_utils.BigNumber;
}[];
};
issues: {
balance: {
expected: _0x_utils.BigNumber;
token: string;
actual: _0x_utils.BigNumber;
} | null;
allowance: {
spender: string;
actual: _0x_utils.BigNumber;
} | null;
simulationIncomplete: boolean;
invalidSourcesPassed: string[];
};
liquidityAvailable: true;
tokenMetadata: {
sellToken: {
buyTaxBps: _0x_utils.BigNumber | null;
sellTaxBps: _0x_utils.BigNumber | null;
};
buyToken: {
buyTaxBps: _0x_utils.BigNumber | null;
sellTaxBps: _0x_utils.BigNumber | null;
};
};
totalNetworkFee: _0x_utils.BigNumber | null;
}>, z.ZodObject<{
liquidityAvailable: z.ZodLiteral<false>;
zid: z.ZodString;
}, "strip", z.ZodTypeAny, {
zid: string;
liquidityAvailable: false;
}, {
zid: string;
liquidityAvailable: false;
}>]>;
errorNames: ("INTERNAL_SERVER_ERROR" | "BUY_TOKEN_NOT_AUTHORIZED_FOR_TRADE" | "INPUT_INVALID" | "SELL_TOKEN_NOT_AUTHORIZED_FOR_TRADE" | "SWAP_VALIDATION_FAILED" | "TAKER_NOT_AUTHORIZED_FOR_TRADE" | "TOKEN_NOT_SUPPORTED" | "UNCATEGORIZED")[];
};
getQuote: {
openApiMeta: {
method: "GET";
path: "/swap/permit2/quote";
summary: string;
description: string;
headers: ({
description: string;
in: "header";
name: string;
required: true;
schema: {
type: "string";
example?: undefined;
};
} | {
description: string;
in: "header";
name: string;
required: true;
schema: {
type: "string";
example: string;
};
})[];
example: {
request: {
chainId: number;
sellToken: string;
buyToken: string;
sellAmount: string;
taker: string;
};
response: {
blockNumber: string;
buyAmount: string;
buyToken: string;
fees: {
integratorFee: null;
zeroExFee: null;
gasFee: null;
};
issues: {
allowance: {
actual: string;
spender: string;
};
balance: {
token: string;
actual: string;
expected: string;
};
simulationIncomplete: boolean;
invalidSourcesPassed: never[];
};
liquidityAvailable: boolean;
minBuyAmount: string;
permit2: {
type: string;
hash: string;
eip712: {
types: {
PermitTransferFrom: {
name: string;
type: string;
}[];
TokenPermissions: {
name: string;
type: string;
}[];
EIP712Domain: {
name: string;
type: string;
}[];
};
domain: {
name: string;
chainId: number;
verifyingContract: string;
};
message: {
permitted: {
token: string;
amount: string;
};
spender: string;
nonce: string;
deadline: string;
};
primaryType: string;
};
};
route: {
fills: {
from: string;
to: string;
source: string;
proportionBps: string;
}[];
tokens: {
address: string;
symbol: string;
}[];
};
sellAmount: string;
sellToken: string;
tokenMetadata: {
buyToken: {
buyTaxBps: string;
sellTaxBps: string;
};
sellToken: {
buyTaxBps: string;
sellTaxBps: string;
};
};
totalNetworkFee: string;
transaction: {
to: string;
data: string;
gas: string;
gasPrice: string;
value: string;
};
zid: string;
};
};
};
enabledChainIds: number[];
input: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodObject<{
chainId: z.ZodEffects<z.ZodNumber, ChainId, number>;
buyToken: z.ZodString;
sellToken: z.ZodString;
sellAmount: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodString, _0x_utils.BigNumber, string>, _0x_utils.BigNumber, string>, _0x_utils.BigNumber, unknown>;
taker: z.ZodEffects<z.ZodString, string, string>;
txOrigin: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
swapFeeRecipient: z.ZodOptional<z.ZodString>;
swapFeeBps: z.ZodOptional<z.ZodNumber>;
swapFeeToken: z.ZodOptional<z.ZodString>;
tradeSurplusRecipient: z.ZodOptional<z.ZodString>;
gasPrice: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodString, _0x_utils.BigNumber, string>, _0x_utils.BigNumber, string>, _0x_utils.BigNumber, unknown>>;
slippageBps: z.ZodDefault<z.ZodNumber>;
excludedSources: z.ZodOptional<z.ZodString>;
}, "strip", z.ZodTypeAny, {
taker: string;
chainId: ChainId;
sellToken: string;
buyToken: string;
sellAmount: _0x_utils.BigNumber;
slippageBps: number;
txOrigin?: string | undefined;
swapFeeRecipient?: string | undefined;
swapFeeBps?: number | undefined;
swapFeeToken?: string | undefined;
tradeSurplusRecipient?: string | undefined;
gasPrice?: _0x_utils.BigNumber | undefined;
excludedSources?: string | undefined;
}, {
taker: string;
chainId: number;
sellToken: string;
buyToken: string;
sellAmount?: unknown;
txOrigin?: string | undefined;
swapFeeRecipient?: string | undefined;
swapFeeBps?: number | undefined;
swapFeeToken?: string | undefined;
tradeSurplusRecipient?: string | undefined;
gasPrice?: unknown;
slippageBps?: number | undefined;
excludedSources?: string | undefined;
}>, {
taker: string;
chainId: ChainId;
sellToken: string;
buyToken: string;
sellAmount: _0x_utils.BigNumber;
slippageBps: number;
txOrigin?: string | undefined;
swapFeeRecipient?: string | undefined;
swapFeeBps?: number | undefined;
swapFeeToken?: string | undefined;
tradeSurplusRecipient?: string | undefined;
gasPrice?: _0x_utils.BigNumber | undefined;
excludedSources?: string | undefined;
}, {
taker: string;
chainId: number;
sellToken: string;
buyToken: string;
sellAmount?: unknown;
txOrigin?: string | undefined;
swapFeeRecipient?: string | undefined;
swapFeeBps?: number | undefined;
swapFeeToken?: string | undefined;
tradeSurplusRecipient?: string | undefined;
gasPrice?: unknown;
slippageBps?: number | undefined;
excludedSources?: string | undefined;
}>, {
taker: string;
chainId: ChainId;
sellToken: string;
buyToken: string;
sellAmount: _0x_utils.BigNumber;
slippageBps: number;
txOrigin?: string | undefined;
swapFeeRecipient?: string | undefined;
swapFeeBps?: number | undefined;
swapFeeToken?: string | undefined;
tradeSurplusRecipient?: string | undefined;
gasPrice?: _0x_utils.BigNumber | undefined;
excludedSources?: string | undefined;
}, {
taker: string;
chainId: number;
sellToken: string;
buyToken: string;
sellAmount?: unknown;
txOrigin?: string | undefined;
swapFeeRecipient?: string | undefined;
swapFeeBps?: number | undefined;
swapFeeToken?: string | undefined;
tradeSurplusRecipient?: string | undefined;
gasPrice?: unknown;
slippageBps?: number | undefined;
excludedSources?: string | undefined;
}>, {
taker: string;
chainId: ChainId;
sellToken: string;
buyToken: string;
sellAmount: _0x_utils.BigNumber;
slippageBps: number;
txOrigin?: string | undefined;
swapFeeRecipient?: string | undefined;
swapFeeBps?: number | undefined;
swapFeeToken?: string | undefined;
tradeSurplusRecipient?: string | undefined;
gasPrice?: _0x_utils.BigNumber | undefined;
excludedSources?: string | undefined;
}, {
taker: string;
chainId: number;
sellToken: string;
buyToken: string;
sellAmount?: unknown;
txOrigin?: string | undefined;
swapFeeRecipient?: string | undefined;
swapFeeBps?: number | undefined;
swapFeeToken?: string | undefined;
tradeSurplusRecipient?: string | undefined;
gasPrice?: unknown;
slippageBps?: number | undefined;
excludedSources?: string | undefined;
}>;
output: z.ZodDiscriminatedUnion<"liquidityAvailable", [z.ZodObject<{
blockNumber: z.ZodPipeline<z.ZodEffects<z.ZodType<_0x_utils.BigNumber, z.ZodTypeDef, _0x_utils.BigNumber>, _0x_utils.BigNumber, _0x_utils.BigNumber>, z.ZodString>;
buyAmount: z.ZodPipeline<z.ZodEffects<z.ZodType<_0x_utils.BigNumber, z.ZodTypeDef, _0x_utils.BigNumber>, _0x_utils.BigNumber, _0x_utils.BigNumber>, z.ZodString>;
buyToken: z.ZodString;
fees: z.ZodObject<{
integratorFee: z.ZodNullable<z.ZodObject<{
amount: z.ZodPipeline<z.ZodEffects<z.ZodType<_0x_utils.BigNumber, z.ZodTypeDef, _0x_utils.BigNumber>, _0x_utils.BigNumber, _0x_utils.BigNumber>, z.ZodString>;
token: z.ZodString;
type: z.ZodEnum<["volume"]>;
}, "strip", z.ZodTypeAny, {
amount: string;
type: "volume";
token: string;
}, {
amount: _0x_utils.BigNumber;
type: "volume";
token: string;
}>>;
zeroExFee: z.ZodNullable<z.ZodObject<{
amount: z.ZodPipeline<z.ZodEffects<z.ZodType<_0x_utils.BigNumber, z.ZodTypeDef, _0x_utils.BigNumber>, _0x_utils.BigNumber, _0x_utils.BigNumber>, z.ZodString>;
token: z.ZodString;
type: z.ZodEnum<["volume"]>;
}, "strip", z.ZodTypeAny, {
amount: string;
type: "volume";
token: string;
}, {
amount: _0x_utils.BigNumber;
type: "volume";
token: string;
}>>;
gasFee: z.ZodNullable<z.ZodObject<{
amount: z.ZodPipeline<z.ZodEffects<z.ZodType<_0x_utils.BigNumber, z.ZodTypeDef, _0x_utils.BigNumber>, _0x_utils.BigNumber, _0x_utils.BigNumber>, z.ZodString>;