@0dotxyz/p0-ts-sdk 2.2.6 → 2.3.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/jupiter.cjs CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  // src/vendor/jupiter/client.ts
4
4
  var DEFAULT_BASE_PATH = "https://lite-api.jup.ag/swap/v1";
5
+ var DEFAULT_ROUTER_BASE_PATH = "https://api.jup.ag/swap/v2";
5
6
  var JupiterApiError = class _JupiterApiError extends Error {
6
7
  status;
7
8
  body;
@@ -27,10 +28,11 @@ function buildQuoteSearchParams(request) {
27
28
  }
28
29
  function createJupiterClient(config = {}) {
29
30
  const basePath = (config.basePath ?? DEFAULT_BASE_PATH).replace(/\/+$/, "");
31
+ const routerBasePath = (config.routerBasePath ?? DEFAULT_ROUTER_BASE_PATH).replace(/\/+$/, "");
30
32
  const baseHeaders = { ...config.headers };
31
33
  if (config.apiKey) baseHeaders["x-api-key"] = config.apiKey;
32
- const request = async (path, init) => {
33
- const response = await fetch(`${basePath}${path}`, init);
34
+ const requestAt = async (base, path, init) => {
35
+ const response = await fetch(`${base}${path}`, init);
34
36
  if (!response.ok) {
35
37
  const body = await response.text().catch(() => "");
36
38
  throw new JupiterApiError(response.status, body);
@@ -40,17 +42,24 @@ function createJupiterClient(config = {}) {
40
42
  return {
41
43
  quoteGet(quoteRequest) {
42
44
  const search = buildQuoteSearchParams(quoteRequest);
43
- return request(`/quote?${search.toString()}`, {
45
+ return requestAt(basePath, `/quote?${search.toString()}`, {
44
46
  method: "GET",
45
47
  headers: baseHeaders
46
48
  });
47
49
  },
48
50
  swapInstructionsPost({ swapRequest }) {
49
- return request(`/swap-instructions`, {
51
+ return requestAt(basePath, `/swap-instructions`, {
50
52
  method: "POST",
51
53
  headers: { ...baseHeaders, "content-type": "application/json" },
52
54
  body: JSON.stringify(swapRequest)
53
55
  });
56
+ },
57
+ buildGet(buildRequest) {
58
+ const search = buildQuoteSearchParams(buildRequest);
59
+ return requestAt(routerBasePath, `/build?${search.toString()}`, {
60
+ method: "GET",
61
+ headers: baseHeaders
62
+ });
54
63
  }
55
64
  };
56
65
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/vendor/jupiter/client.ts"],"names":[],"mappings":";;;AAiBA,IAAM,iBAAA,GAAoB,iCAAA;AAWnB,IAAM,eAAA,GAAN,MAAM,gBAAA,SAAwB,KAAA,CAAM;AAAA,EACzC,MAAA;AAAA,EACA,IAAA;AAAA,EAEA,WAAA,CAAY,QAAgB,IAAA,EAAc;AACxC,IAAA,KAAA,CAAM,CAAA,uCAAA,EAA0C,MAAM,CAAA,EAAA,EAAK,IAAI,CAAA,CAAE,CAAA;AACjE,IAAA,IAAA,CAAK,IAAA,GAAO,iBAAA;AACZ,IAAA,MAAA,CAAO,cAAA,CAAe,IAAA,EAAM,gBAAA,CAAgB,SAAS,CAAA;AACrD,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AACd,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,EACd;AACF;AAEA,SAAS,uBAAuB,OAAA,EAA2C;AACzE,EAAA,MAAM,MAAA,GAAS,IAAI,eAAA,EAAgB;AACnC,EAAA,KAAA,MAAW,CAAC,GAAA,EAAK,KAAK,KAAK,MAAA,CAAO,OAAA,CAAQ,OAAO,CAAA,EAAG;AAClD,IAAA,IAAI,KAAA,KAAU,MAAA,IAAa,KAAA,KAAU,IAAA,EAAM;AAE3C,IAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AACxB,MAAA,IAAI,KAAA,CAAM,SAAS,CAAA,EAAG,MAAA,CAAO,OAAO,GAAA,EAAK,KAAA,CAAM,IAAA,CAAK,GAAG,CAAC,CAAA;AACxD,MAAA;AAAA,IACF;AACA,IAAA,MAAA,CAAO,MAAA,CAAO,GAAA,EAAK,MAAA,CAAO,KAAK,CAAC,CAAA;AAAA,EAClC;AACA,EAAA,OAAO,MAAA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AA,QAC9D,IAAA,EAAM,IAAA,CAAK,SAAA,CAAU,WAAW;AAAA,OACjC,CAAA;AAAA,IACH;AAAA,GACF;AACF","file":"jupiter.cjs","sourcesContent":["// Minimal Jupiter Swap API client — replaces the runtime of @jup-ag/api.\n//\n// The generated @jup-ag/api client hardcodes the legacy\n// `https://quote-api.jup.ag/v6` base URL and ignores a caller-supplied\n// basePath, so we reimplement the two endpoints the SDK uses against Jupiter's\n// current Swap API (https://dev.jup.ag/docs/swap-api). Only `GET /quote` and\n// `POST /swap-instructions` are implemented.\n\nimport type {\n QuoteGetRequest,\n QuoteResponse,\n SwapInstructionsResponse,\n SwapRequest,\n} from \"./types\";\n\n// Free tier. Callers with an API key typically override this with the paid\n// base `https://api.jup.ag/swap/v1` via `basePath`.\nconst DEFAULT_BASE_PATH = \"https://lite-api.jup.ag/swap/v1\";\n\nexport interface JupiterClientConfig {\n /** Override the API base URL (e.g. the paid `https://api.jup.ag/swap/v1`). */\n basePath?: string;\n /** API key, sent as the `x-api-key` header. */\n apiKey?: string;\n /** Extra headers applied to every request. */\n headers?: Record<string, string>;\n}\n\nexport class JupiterApiError extends Error {\n status: number;\n body: string;\n\n constructor(status: number, body: string) {\n super(`Jupiter API request failed with status ${status}: ${body}`);\n this.name = \"JupiterApiError\";\n Object.setPrototypeOf(this, JupiterApiError.prototype);\n this.status = status;\n this.body = body;\n }\n}\n\nfunction buildQuoteSearchParams(request: QuoteGetRequest): URLSearchParams {\n const params = new URLSearchParams();\n for (const [key, value] of Object.entries(request)) {\n if (value === undefined || value === null) continue;\n // Arrays (dexes/excludeDexes) are comma-separated per the Jupiter spec.\n if (Array.isArray(value)) {\n if (value.length > 0) params.append(key, value.join(\",\"));\n continue;\n }\n params.append(key, String(value));\n }\n return params;\n}\n\nexport interface JupiterClient {\n quoteGet(request: QuoteGetRequest): Promise<QuoteResponse>;\n swapInstructionsPost(request: { swapRequest: SwapRequest }): Promise<SwapInstructionsResponse>;\n}\n\nexport function createJupiterClient(config: JupiterClientConfig = {}): JupiterClient {\n const basePath = (config.basePath ?? DEFAULT_BASE_PATH).replace(/\\/+$/, \"\");\n const baseHeaders: Record<string, string> = { ...config.headers };\n if (config.apiKey) baseHeaders[\"x-api-key\"] = config.apiKey;\n\n const request = async <T>(path: string, init: RequestInit): Promise<T> => {\n const response = await fetch(`${basePath}${path}`, init);\n if (!response.ok) {\n const body = await response.text().catch(() => \"\");\n throw new JupiterApiError(response.status, body);\n }\n return (await response.json()) as T;\n };\n\n return {\n quoteGet(quoteRequest) {\n const search = buildQuoteSearchParams(quoteRequest);\n return request<QuoteResponse>(`/quote?${search.toString()}`, {\n method: \"GET\",\n headers: baseHeaders,\n });\n },\n swapInstructionsPost({ swapRequest }) {\n return request<SwapInstructionsResponse>(`/swap-instructions`, {\n method: \"POST\",\n headers: { ...baseHeaders, \"content-type\": \"application/json\" },\n body: JSON.stringify(swapRequest),\n });\n },\n };\n}\n"]}
1
+ {"version":3,"sources":["../src/vendor/jupiter/client.ts"],"names":[],"mappings":";;;AAmBA,IAAM,iBAAA,GAAoB,iCAAA;AAI1B,IAAM,wBAAA,GAA2B,4BAAA;AAa1B,IAAM,eAAA,GAAN,MAAM,gBAAA,SAAwB,KAAA,CAAM;AAAA,EACzC,MAAA;AAAA,EACA,IAAA;AAAA,EAEA,WAAA,CAAY,QAAgB,IAAA,EAAc;AACxC,IAAA,KAAA,CAAM,CAAA,uCAAA,EAA0C,MAAM,CAAA,EAAA,EAAK,IAAI,CAAA,CAAE,CAAA;AACjE,IAAA,IAAA,CAAK,IAAA,GAAO,iBAAA;AACZ,IAAA,MAAA,CAAO,cAAA,CAAe,IAAA,EAAM,gBAAA,CAAgB,SAAS,CAAA;AACrD,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AACd,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,EACd;AACF;AAEA,SAAS,uBAAuB,OAAA,EAAkC;AAChE,EAAA,MAAM,MAAA,GAAS,IAAI,eAAA,EAAgB;A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CAAS,MAAA,EAAQ,IAAI,CAAA;AAAA,IACjD;AACA,IAAA,OAAQ,MAAM,SAAS,IAAA,EAAK;AAAA,EAC9B,CAAA;AAEA,EAAA,OAAO;AAAA,IACL,SAAS,YAAA,EAAc;AACrB,MAAA,MAAM,MAAA,GAAS,uBAAuB,YAAY,CAAA;AAClD,MAAA,OAAO,UAAyB,QAAA,EAAU,CAAA,OAAA,EAAU,MAAA,CAAO,QAAA,EAAU,CAAA,CAAA,EAAI;AAAA,QACvE,MAAA,EAAQ,KAAA;AAAA,QACR,OAAA,EAAS;AAAA,OACV,CAAA;AAAA,IACH,CAAA;AAAA,IACA,oBAAA,CAAqB,EAAE,WAAA,EAAY,EAAG;AACpC,MAAA,OAAO,SAAA,CAAoC,UAAU,CAAA,kBAAA,CAAA,EAAsB;AAAA,QACzE,MAAA,EAAQ,MAAA;AAAA,QACR,OAAA,EAAS,EAAE,GAAG,WAAA,EAAa,gBAAgB,kBAAA,EAAmB;AAAA,QAC9D,IAAA,EAAM,IAAA,CAAK,SAAA,CAAU,WAAW;AAAA,OACjC,CAAA;AAAA,IACH,CAAA;AAAA,IACA,SAAS,YAAA,EAAc;AACrB,MAAA,MAAM,MAAA,GAAS,uBAAuB,YAAY,CAAA;AAClD,MAAA,OAAO,UAAyB,cAAA,EAAgB,CAAA,OAAA,EAAU,MAAA,CAAO,QAAA,EAAU,CAAA,CAAA,EAAI;AAAA,QAC7E,MAAA,EAAQ,KAAA;AAAA,QACR,OAAA,EAAS;AAAA,OACV,CAAA;AAAA,IACH;AAAA,GACF;AACF","file":"jupiter.cjs","sourcesContent":["// Minimal Jupiter Swap API client — replaces the runtime of @jup-ag/api.\n//\n// The generated @jup-ag/api client hardcodes the legacy\n// `https://quote-api.jup.ag/v6` base URL and ignores a caller-supplied\n// basePath, so we reimplement the two endpoints the SDK uses against Jupiter's\n// current Swap API (https://dev.jup.ag/docs/swap-api). Only `GET /quote` and\n// `POST /swap-instructions` are implemented.\n\nimport type {\n BuildGetRequest,\n BuildResponse,\n QuoteGetRequest,\n QuoteResponse,\n SwapInstructionsResponse,\n SwapRequest,\n} from \"./types\";\n\n// Free tier. Callers with an API key typically override this with the paid\n// base `https://api.jup.ag/swap/v1` via `basePath`.\nconst DEFAULT_BASE_PATH = \"https://lite-api.jup.ag/swap/v1\";\n\n// Router base for the `/build` endpoint (paid). The Router lives under\n// `/swap/v2`, distinct from the Metis `/swap/v1` base above.\nconst DEFAULT_ROUTER_BASE_PATH = \"https://api.jup.ag/swap/v2\";\n\nexport interface JupiterClientConfig {\n /** Override the API base URL (e.g. the paid `https://api.jup.ag/swap/v1`). */\n basePath?: string;\n /** Override the Router base URL for `/build` (default `.../swap/v2`). */\n routerBasePath?: string;\n /** API key, sent as the `x-api-key` header. */\n apiKey?: string;\n /** Extra headers applied to every request. */\n headers?: Record<string, string>;\n}\n\nexport class JupiterApiError extends Error {\n status: number;\n body: string;\n\n constructor(status: number, body: string) {\n super(`Jupiter API request failed with status ${status}: ${body}`);\n this.name = \"JupiterApiError\";\n Object.setPrototypeOf(this, JupiterApiError.prototype);\n this.status = status;\n this.body = body;\n }\n}\n\nfunction buildQuoteSearchParams(request: object): URLSearchParams {\n const params = new URLSearchParams();\n for (const [key, value] of Object.entries(request)) {\n if (value === undefined || value === null) continue;\n // Arrays (dexes/excludeDexes) are comma-separated per the Jupiter spec.\n if (Array.isArray(value)) {\n if (value.length > 0) params.append(key, value.join(\",\"));\n continue;\n }\n params.append(key, String(value));\n }\n return params;\n}\n\nexport interface JupiterClient {\n quoteGet(request: QuoteGetRequest): Promise<QuoteResponse>;\n swapInstructionsPost(request: { swapRequest: SwapRequest }): Promise<SwapInstructionsResponse>;\n /** Router: one-call quote + raw instructions. ExactIn only. */\n buildGet(request: BuildGetRequest): Promise<BuildResponse>;\n}\n\nexport function createJupiterClient(config: JupiterClientConfig = {}): JupiterClient {\n const basePath = (config.basePath ?? DEFAULT_BASE_PATH).replace(/\\/+$/, \"\");\n const routerBasePath = (config.routerBasePath ?? DEFAULT_ROUTER_BASE_PATH).replace(/\\/+$/, \"\");\n const baseHeaders: Record<string, string> = { ...config.headers };\n if (config.apiKey) baseHeaders[\"x-api-key\"] = config.apiKey;\n\n const requestAt = async <T>(base: string, path: string, init: RequestInit): Promise<T> => {\n const response = await fetch(`${base}${path}`, init);\n if (!response.ok) {\n const body = await response.text().catch(() => \"\");\n throw new JupiterApiError(response.status, body);\n }\n return (await response.json()) as T;\n };\n\n return {\n quoteGet(quoteRequest) {\n const search = buildQuoteSearchParams(quoteRequest);\n return requestAt<QuoteResponse>(basePath, `/quote?${search.toString()}`, {\n method: \"GET\",\n headers: baseHeaders,\n });\n },\n swapInstructionsPost({ swapRequest }) {\n return requestAt<SwapInstructionsResponse>(basePath, `/swap-instructions`, {\n method: \"POST\",\n headers: { ...baseHeaders, \"content-type\": \"application/json\" },\n body: JSON.stringify(swapRequest),\n });\n },\n buildGet(buildRequest) {\n const search = buildQuoteSearchParams(buildRequest);\n return requestAt<BuildResponse>(routerBasePath, `/build?${search.toString()}`, {\n method: \"GET\",\n headers: baseHeaders,\n });\n },\n };\n}\n"]}
@@ -99,10 +99,54 @@ interface SwapInstructionsResponse {
99
99
  cleanupInstruction?: Instruction;
100
100
  addressLookupTableAddresses: Array<string>;
101
101
  }
102
+ /** Query parameters for `GET /swap/v2/build`. */
103
+ interface BuildGetRequest {
104
+ inputMint: string;
105
+ outputMint: string;
106
+ amount: number;
107
+ /** The account performing the swap (replaces Metis `userPublicKey`). */
108
+ taker: string;
109
+ slippageBps?: number;
110
+ /** "fast" trades route optimality for lower latency. */
111
+ mode?: "fast";
112
+ dexes?: Array<string>;
113
+ excludeDexes?: Array<string>;
114
+ platformFeeBps?: number;
115
+ feeAccount?: string;
116
+ maxAccounts?: number;
117
+ payer?: string;
118
+ wrapAndUnwrapSol?: boolean;
119
+ destinationTokenAccount?: string;
120
+ }
121
+ /** Response from `GET /swap/v2/build`. */
122
+ interface BuildResponse {
123
+ inputMint: string;
124
+ outputMint: string;
125
+ inAmount: string;
126
+ outAmount: string;
127
+ otherAmountThreshold: string;
128
+ swapMode: string;
129
+ slippageBps: number;
130
+ routePlan: Array<RoutePlanStep>;
131
+ computeBudgetInstructions: Array<Instruction>;
132
+ setupInstructions: Array<Instruction>;
133
+ swapInstruction: Instruction;
134
+ cleanupInstruction?: Instruction | null;
135
+ otherInstructions?: Array<Instruction>;
136
+ tipInstruction?: Instruction | null;
137
+ /** Map of ALT address -> the addresses stored inside it (in order). */
138
+ addressesByLookupTableAddress?: Record<string, string[]> | null;
139
+ blockhashWithMetadata?: {
140
+ blockhash: number[];
141
+ lastValidBlockHeight: number;
142
+ };
143
+ }
102
144
 
103
145
  interface JupiterClientConfig {
104
146
  /** Override the API base URL (e.g. the paid `https://api.jup.ag/swap/v1`). */
105
147
  basePath?: string;
148
+ /** Override the Router base URL for `/build` (default `.../swap/v2`). */
149
+ routerBasePath?: string;
106
150
  /** API key, sent as the `x-api-key` header. */
107
151
  apiKey?: string;
108
152
  /** Extra headers applied to every request. */
@@ -118,7 +162,9 @@ interface JupiterClient {
118
162
  swapInstructionsPost(request: {
119
163
  swapRequest: SwapRequest;
120
164
  }): Promise<SwapInstructionsResponse>;
165
+ /** Router: one-call quote + raw instructions. ExactIn only. */
166
+ buildGet(request: BuildGetRequest): Promise<BuildResponse>;
121
167
  }
122
168
  declare function createJupiterClient(config?: JupiterClientConfig): JupiterClient;
123
169
 
124
- export { type AccountMeta, type Instruction, type InstructionVersion, JupiterApiError, type JupiterClient, type JupiterClientConfig, type PlatformFee, type QuoteGetRequest, type QuoteResponse, type RoutePlanStep, type SwapInfo, type SwapInstructionsResponse, type SwapMode, type SwapRequest, createJupiterClient };
170
+ export { type AccountMeta, type BuildGetRequest, type BuildResponse, type Instruction, type InstructionVersion, JupiterApiError, type JupiterClient, type JupiterClientConfig, type PlatformFee, type QuoteGetRequest, type QuoteResponse, type RoutePlanStep, type SwapInfo, type SwapInstructionsResponse, type SwapMode, type SwapRequest, createJupiterClient };
package/dist/jupiter.d.ts CHANGED
@@ -99,10 +99,54 @@ interface SwapInstructionsResponse {
99
99
  cleanupInstruction?: Instruction;
100
100
  addressLookupTableAddresses: Array<string>;
101
101
  }
102
+ /** Query parameters for `GET /swap/v2/build`. */
103
+ interface BuildGetRequest {
104
+ inputMint: string;
105
+ outputMint: string;
106
+ amount: number;
107
+ /** The account performing the swap (replaces Metis `userPublicKey`). */
108
+ taker: string;
109
+ slippageBps?: number;
110
+ /** "fast" trades route optimality for lower latency. */
111
+ mode?: "fast";
112
+ dexes?: Array<string>;
113
+ excludeDexes?: Array<string>;
114
+ platformFeeBps?: number;
115
+ feeAccount?: string;
116
+ maxAccounts?: number;
117
+ payer?: string;
118
+ wrapAndUnwrapSol?: boolean;
119
+ destinationTokenAccount?: string;
120
+ }
121
+ /** Response from `GET /swap/v2/build`. */
122
+ interface BuildResponse {
123
+ inputMint: string;
124
+ outputMint: string;
125
+ inAmount: string;
126
+ outAmount: string;
127
+ otherAmountThreshold: string;
128
+ swapMode: string;
129
+ slippageBps: number;
130
+ routePlan: Array<RoutePlanStep>;
131
+ computeBudgetInstructions: Array<Instruction>;
132
+ setupInstructions: Array<Instruction>;
133
+ swapInstruction: Instruction;
134
+ cleanupInstruction?: Instruction | null;
135
+ otherInstructions?: Array<Instruction>;
136
+ tipInstruction?: Instruction | null;
137
+ /** Map of ALT address -> the addresses stored inside it (in order). */
138
+ addressesByLookupTableAddress?: Record<string, string[]> | null;
139
+ blockhashWithMetadata?: {
140
+ blockhash: number[];
141
+ lastValidBlockHeight: number;
142
+ };
143
+ }
102
144
 
103
145
  interface JupiterClientConfig {
104
146
  /** Override the API base URL (e.g. the paid `https://api.jup.ag/swap/v1`). */
105
147
  basePath?: string;
148
+ /** Override the Router base URL for `/build` (default `.../swap/v2`). */
149
+ routerBasePath?: string;
106
150
  /** API key, sent as the `x-api-key` header. */
107
151
  apiKey?: string;
108
152
  /** Extra headers applied to every request. */
@@ -118,7 +162,9 @@ interface JupiterClient {
118
162
  swapInstructionsPost(request: {
119
163
  swapRequest: SwapRequest;
120
164
  }): Promise<SwapInstructionsResponse>;
165
+ /** Router: one-call quote + raw instructions. ExactIn only. */
166
+ buildGet(request: BuildGetRequest): Promise<BuildResponse>;
121
167
  }
122
168
  declare function createJupiterClient(config?: JupiterClientConfig): JupiterClient;
123
169
 
124
- export { type AccountMeta, type Instruction, type InstructionVersion, JupiterApiError, type JupiterClient, type JupiterClientConfig, type PlatformFee, type QuoteGetRequest, type QuoteResponse, type RoutePlanStep, type SwapInfo, type SwapInstructionsResponse, type SwapMode, type SwapRequest, createJupiterClient };
170
+ export { type AccountMeta, type BuildGetRequest, type BuildResponse, type Instruction, type InstructionVersion, JupiterApiError, type JupiterClient, type JupiterClientConfig, type PlatformFee, type QuoteGetRequest, type QuoteResponse, type RoutePlanStep, type SwapInfo, type SwapInstructionsResponse, type SwapMode, type SwapRequest, createJupiterClient };
package/dist/jupiter.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // src/vendor/jupiter/client.ts
2
2
  var DEFAULT_BASE_PATH = "https://lite-api.jup.ag/swap/v1";
3
+ var DEFAULT_ROUTER_BASE_PATH = "https://api.jup.ag/swap/v2";
3
4
  var JupiterApiError = class _JupiterApiError extends Error {
4
5
  status;
5
6
  body;
@@ -25,10 +26,11 @@ function buildQuoteSearchParams(request) {
25
26
  }
26
27
  function createJupiterClient(config = {}) {
27
28
  const basePath = (config.basePath ?? DEFAULT_BASE_PATH).replace(/\/+$/, "");
29
+ const routerBasePath = (config.routerBasePath ?? DEFAULT_ROUTER_BASE_PATH).replace(/\/+$/, "");
28
30
  const baseHeaders = { ...config.headers };
29
31
  if (config.apiKey) baseHeaders["x-api-key"] = config.apiKey;
30
- const request = async (path, init) => {
31
- const response = await fetch(`${basePath}${path}`, init);
32
+ const requestAt = async (base, path, init) => {
33
+ const response = await fetch(`${base}${path}`, init);
32
34
  if (!response.ok) {
33
35
  const body = await response.text().catch(() => "");
34
36
  throw new JupiterApiError(response.status, body);
@@ -38,17 +40,24 @@ function createJupiterClient(config = {}) {
38
40
  return {
39
41
  quoteGet(quoteRequest) {
40
42
  const search = buildQuoteSearchParams(quoteRequest);
41
- return request(`/quote?${search.toString()}`, {
43
+ return requestAt(basePath, `/quote?${search.toString()}`, {
42
44
  method: "GET",
43
45
  headers: baseHeaders
44
46
  });
45
47
  },
46
48
  swapInstructionsPost({ swapRequest }) {
47
- return request(`/swap-instructions`, {
49
+ return requestAt(basePath, `/swap-instructions`, {
48
50
  method: "POST",
49
51
  headers: { ...baseHeaders, "content-type": "application/json" },
50
52
  body: JSON.stringify(swapRequest)
51
53
  });
54
+ },
55
+ buildGet(buildRequest) {
56
+ const search = buildQuoteSearchParams(buildRequest);
57
+ return requestAt(routerBasePath, `/build?${search.toString()}`, {
58
+ method: "GET",
59
+ headers: baseHeaders
60
+ });
52
61
  }
53
62
  };
54
63
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/vendor/jupiter/client.ts"],"names":[],"mappings":";AAiBA,IAAM,iBAAA,GAAoB,iCAAA;AAWnB,IAAM,eAAA,GAAN,MAAM,gBAAA,SAAwB,KAAA,CAAM;AAAA,EACzC,MAAA;AAAA,EACA,IAAA;AAAA,EAEA,WAAA,CAAY,QAAgB,IAAA,EAAc;AACxC,IAAA,KAAA,CAAM,CAAA,uCAAA,EAA0C,MAAM,CAAA,EAAA,EAAK,IAAI,CAAA,CAAE,CAAA;AACjE,IAAA,IAAA,CAAK,IAAA,GAAO,iBAAA;AACZ,IAAA,MAAA,CAAO,cAAA,CAAe,IAAA,EAAM,gBAAA,CAAgB,SAAS,CAAA;AACrD,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AACd,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,EACd;AACF;AAEA,SAAS,uBAAuB,OAAA,EAA2C;AACzE,EAAA,MAAM,MAAA,GAAS,IAAI,eAAA,EAAgB;AACnC,EAAA,KAAA,MAAW,CAAC,GAAA,EAAK,KAAK,KAAK,MAAA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M,MAAA,GAAS,uBAAuB,YAAY,CAAA;AAClD,MAAA,OAAO,OAAA,CAAuB,CAAA,OAAA,EAAU,MAAA,CAAO,QAAA,EAAU,CAAA,CAAA,EAAI;AAAA,QAC3D,MAAA,EAAQ,KAAA;AAAA,QACR,OAAA,EAAS;AAAA,OACV,CAAA;AAAA,IACH,CAAA;AAAA,IACA,oBAAA,CAAqB,EAAE,WAAA,EAAY,EAAG;AACpC,MAAA,OAAO,QAAkC,CAAA,kBAAA,CAAA,EAAsB;AAAA,QAC7D,MAAA,EAAQ,MAAA;AAAA,QACR,OAAA,EAAS,EAAE,GAAG,WAAA,EAAa,gBAAgB,kBAAA,EAAmB;AAAA,QAC9D,IAAA,EAAM,IAAA,CAAK,SAAA,CAAU,WAAW;AAAA,OACjC,CAAA;AAAA,IACH;AAAA,GACF;AACF","file":"jupiter.js","sourcesContent":["// Minimal Jupiter Swap API client — replaces the runtime of @jup-ag/api.\n//\n// The generated @jup-ag/api client hardcodes the legacy\n// `https://quote-api.jup.ag/v6` base URL and ignores a caller-supplied\n// basePath, so we reimplement the two endpoints the SDK uses against Jupiter's\n// current Swap API (https://dev.jup.ag/docs/swap-api). Only `GET /quote` and\n// `POST /swap-instructions` are implemented.\n\nimport type {\n QuoteGetRequest,\n QuoteResponse,\n SwapInstructionsResponse,\n SwapRequest,\n} from \"./types\";\n\n// Free tier. Callers with an API key typically override this with the paid\n// base `https://api.jup.ag/swap/v1` via `basePath`.\nconst DEFAULT_BASE_PATH = \"https://lite-api.jup.ag/swap/v1\";\n\nexport interface JupiterClientConfig {\n /** Override the API base URL (e.g. the paid `https://api.jup.ag/swap/v1`). */\n basePath?: string;\n /** API key, sent as the `x-api-key` header. */\n apiKey?: string;\n /** Extra headers applied to every request. */\n headers?: Record<string, string>;\n}\n\nexport class JupiterApiError extends Error {\n status: number;\n body: string;\n\n constructor(status: number, body: string) {\n super(`Jupiter API request failed with status ${status}: ${body}`);\n this.name = \"JupiterApiError\";\n Object.setPrototypeOf(this, JupiterApiError.prototype);\n this.status = status;\n this.body = body;\n }\n}\n\nfunction buildQuoteSearchParams(request: QuoteGetRequest): URLSearchParams {\n const params = new URLSearchParams();\n for (const [key, value] of Object.entries(request)) {\n if (value === undefined || value === null) continue;\n // Arrays (dexes/excludeDexes) are comma-separated per the Jupiter spec.\n if (Array.isArray(value)) {\n if (value.length > 0) params.append(key, value.join(\",\"));\n continue;\n }\n params.append(key, String(value));\n }\n return params;\n}\n\nexport interface JupiterClient {\n quoteGet(request: QuoteGetRequest): Promise<QuoteResponse>;\n swapInstructionsPost(request: { swapRequest: SwapRequest }): Promise<SwapInstructionsResponse>;\n}\n\nexport function createJupiterClient(config: JupiterClientConfig = {}): JupiterClient {\n const basePath = (config.basePath ?? DEFAULT_BASE_PATH).replace(/\\/+$/, \"\");\n const baseHeaders: Record<string, string> = { ...config.headers };\n if (config.apiKey) baseHeaders[\"x-api-key\"] = config.apiKey;\n\n const request = async <T>(path: string, init: RequestInit): Promise<T> => {\n const response = await fetch(`${basePath}${path}`, init);\n if (!response.ok) {\n const body = await response.text().catch(() => \"\");\n throw new JupiterApiError(response.status, body);\n }\n return (await response.json()) as T;\n };\n\n return {\n quoteGet(quoteRequest) {\n const search = buildQuoteSearchParams(quoteRequest);\n return request<QuoteResponse>(`/quote?${search.toString()}`, {\n method: \"GET\",\n headers: baseHeaders,\n });\n },\n swapInstructionsPost({ swapRequest }) {\n return request<SwapInstructionsResponse>(`/swap-instructions`, {\n method: \"POST\",\n headers: { ...baseHeaders, \"content-type\": \"application/json\" },\n body: JSON.stringify(swapRequest),\n });\n },\n };\n}\n"]}
1
+ {"version":3,"sources":["../src/vendor/jupiter/client.ts"],"names":[],"mappings":";AAmBA,IAAM,iBAAA,GAAoB,iCAAA;AAI1B,IAAM,wBAAA,GAA2B,4BAAA;AAa1B,IAAM,eAAA,GAAN,MAAM,gBAAA,SAAwB,KAAA,CAAM;AAAA,EACzC,MAAA;AAAA,EACA,IAAA;AAAA,EAEA,WAAA,CA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OAAA,EAAU,MAAA,CAAO,QAAA,EAAU,CAAA,CAAA,EAAI;AAAA,QAC7E,MAAA,EAAQ,KAAA;AAAA,QACR,OAAA,EAAS;AAAA,OACV,CAAA;AAAA,IACH;AAAA,GACF;AACF","file":"jupiter.js","sourcesContent":["// Minimal Jupiter Swap API client — replaces the runtime of @jup-ag/api.\n//\n// The generated @jup-ag/api client hardcodes the legacy\n// `https://quote-api.jup.ag/v6` base URL and ignores a caller-supplied\n// basePath, so we reimplement the two endpoints the SDK uses against Jupiter's\n// current Swap API (https://dev.jup.ag/docs/swap-api). Only `GET /quote` and\n// `POST /swap-instructions` are implemented.\n\nimport type {\n BuildGetRequest,\n BuildResponse,\n QuoteGetRequest,\n QuoteResponse,\n SwapInstructionsResponse,\n SwapRequest,\n} from \"./types\";\n\n// Free tier. Callers with an API key typically override this with the paid\n// base `https://api.jup.ag/swap/v1` via `basePath`.\nconst DEFAULT_BASE_PATH = \"https://lite-api.jup.ag/swap/v1\";\n\n// Router base for the `/build` endpoint (paid). The Router lives under\n// `/swap/v2`, distinct from the Metis `/swap/v1` base above.\nconst DEFAULT_ROUTER_BASE_PATH = \"https://api.jup.ag/swap/v2\";\n\nexport interface JupiterClientConfig {\n /** Override the API base URL (e.g. the paid `https://api.jup.ag/swap/v1`). */\n basePath?: string;\n /** Override the Router base URL for `/build` (default `.../swap/v2`). */\n routerBasePath?: string;\n /** API key, sent as the `x-api-key` header. */\n apiKey?: string;\n /** Extra headers applied to every request. */\n headers?: Record<string, string>;\n}\n\nexport class JupiterApiError extends Error {\n status: number;\n body: string;\n\n constructor(status: number, body: string) {\n super(`Jupiter API request failed with status ${status}: ${body}`);\n this.name = \"JupiterApiError\";\n Object.setPrototypeOf(this, JupiterApiError.prototype);\n this.status = status;\n this.body = body;\n }\n}\n\nfunction buildQuoteSearchParams(request: object): URLSearchParams {\n const params = new URLSearchParams();\n for (const [key, value] of Object.entries(request)) {\n if (value === undefined || value === null) continue;\n // Arrays (dexes/excludeDexes) are comma-separated per the Jupiter spec.\n if (Array.isArray(value)) {\n if (value.length > 0) params.append(key, value.join(\",\"));\n continue;\n }\n params.append(key, String(value));\n }\n return params;\n}\n\nexport interface JupiterClient {\n quoteGet(request: QuoteGetRequest): Promise<QuoteResponse>;\n swapInstructionsPost(request: { swapRequest: SwapRequest }): Promise<SwapInstructionsResponse>;\n /** Router: one-call quote + raw instructions. ExactIn only. */\n buildGet(request: BuildGetRequest): Promise<BuildResponse>;\n}\n\nexport function createJupiterClient(config: JupiterClientConfig = {}): JupiterClient {\n const basePath = (config.basePath ?? DEFAULT_BASE_PATH).replace(/\\/+$/, \"\");\n const routerBasePath = (config.routerBasePath ?? DEFAULT_ROUTER_BASE_PATH).replace(/\\/+$/, \"\");\n const baseHeaders: Record<string, string> = { ...config.headers };\n if (config.apiKey) baseHeaders[\"x-api-key\"] = config.apiKey;\n\n const requestAt = async <T>(base: string, path: string, init: RequestInit): Promise<T> => {\n const response = await fetch(`${base}${path}`, init);\n if (!response.ok) {\n const body = await response.text().catch(() => \"\");\n throw new JupiterApiError(response.status, body);\n }\n return (await response.json()) as T;\n };\n\n return {\n quoteGet(quoteRequest) {\n const search = buildQuoteSearchParams(quoteRequest);\n return requestAt<QuoteResponse>(basePath, `/quote?${search.toString()}`, {\n method: \"GET\",\n headers: baseHeaders,\n });\n },\n swapInstructionsPost({ swapRequest }) {\n return requestAt<SwapInstructionsResponse>(basePath, `/swap-instructions`, {\n method: \"POST\",\n headers: { ...baseHeaders, \"content-type\": \"application/json\" },\n body: JSON.stringify(swapRequest),\n });\n },\n buildGet(buildRequest) {\n const search = buildQuoteSearchParams(buildRequest);\n return requestAt<BuildResponse>(routerBasePath, `/build?${search.toString()}`, {\n method: \"GET\",\n headers: baseHeaders,\n });\n },\n };\n}\n"]}
package/dist/vendor.cjs CHANGED
@@ -32378,6 +32378,143 @@ async function resolveLookupTables(connection, lutPubkeys) {
32378
32378
  });
32379
32379
  }).filter((account) => account !== null);
32380
32380
  }
32381
+ var msgpackEncoder = new msgpack.Encoder({ useBigInt64: true });
32382
+ function instructionToTitanWire(ix) {
32383
+ return {
32384
+ p: ix.programId.toBytes(),
32385
+ a: ix.keys.map((k) => ({
32386
+ p: k.pubkey.toBytes(),
32387
+ s: k.isSigner,
32388
+ w: k.isWritable
32389
+ })),
32390
+ d: Uint8Array.from(ix.data)
32391
+ };
32392
+ }
32393
+ function lutToTitanWire(lut) {
32394
+ return {
32395
+ p: lut.key.toBytes(),
32396
+ a: lut.state.addresses.map((a) => a.toBytes())
32397
+ };
32398
+ }
32399
+ function buildTitanTemplate(footprint) {
32400
+ return {
32401
+ i: footprint.instructions.map(instructionToTitanWire),
32402
+ a: footprint.luts.map(lutToTitanWire),
32403
+ m: (footprint.extraAccountMetas ?? []).map((m) => ({
32404
+ p: m.pubkey.toBytes(),
32405
+ s: m.isSigner,
32406
+ w: m.isWritable
32407
+ }))
32408
+ };
32409
+ }
32410
+ function encodeTitanTemplate(template) {
32411
+ return Buffer.from(msgpackEncoder.encode(template)).toString("base64");
32412
+ }
32413
+ async function fetchTitanQuoteSwapV3(params) {
32414
+ const {
32415
+ basePath,
32416
+ apiKey,
32417
+ headers,
32418
+ inputMint,
32419
+ outputMint,
32420
+ amount,
32421
+ userPublicKey,
32422
+ outputAccount,
32423
+ slippageBps,
32424
+ swapMode,
32425
+ dexes,
32426
+ excludeDexes,
32427
+ onlyDirectRoutes,
32428
+ providers,
32429
+ transactionTemplate,
32430
+ addSizeConstraint,
32431
+ sizeConstraint,
32432
+ accountsLimitTotal,
32433
+ accountsLimitWritable,
32434
+ feeBps,
32435
+ feeAccount
32436
+ } = params;
32437
+ const query = new URLSearchParams({
32438
+ inputMint,
32439
+ outputMint,
32440
+ amount: String(amount),
32441
+ userPublicKey,
32442
+ outputAccount,
32443
+ titanSwapVersion: "3",
32444
+ simulate: "false"
32445
+ });
32446
+ if (slippageBps !== void 0) query.set("slippageBps", String(slippageBps));
32447
+ if (swapMode) query.set("swapMode", swapMode);
32448
+ if (dexes?.length) query.set("dexes", dexes.join(","));
32449
+ if (excludeDexes?.length) query.set("excludeDexes", excludeDexes.join(","));
32450
+ if (providers?.length) query.set("providers", providers.join(","));
32451
+ if (onlyDirectRoutes) query.set("onlyDirectRoutes", "true");
32452
+ if (transactionTemplate) {
32453
+ query.set("transactionTemplate", transactionTemplate);
32454
+ } else {
32455
+ if (addSizeConstraint) query.set("addSizeConstraint", "true");
32456
+ if (sizeConstraint !== void 0) query.set("sizeConstraint", String(sizeConstraint));
32457
+ if (accountsLimitTotal !== void 0) {
32458
+ query.set("accountsLimitTotal", String(accountsLimitTotal));
32459
+ }
32460
+ if (accountsLimitWritable !== void 0) {
32461
+ query.set("accountsLimitWritable", String(accountsLimitWritable));
32462
+ }
32463
+ }
32464
+ if (feeBps !== void 0 && feeAccount) {
32465
+ query.set("feeBps", String(feeBps));
32466
+ query.set("feeAccount", feeAccount);
32467
+ }
32468
+ const response = await fetch(`${basePath}/quote/swap?${query.toString()}`, {
32469
+ method: "GET",
32470
+ headers: {
32471
+ Accept: "application/vnd.msgpack",
32472
+ ...apiKey ? { Authorization: `Bearer ${apiKey}` } : {},
32473
+ ...headers ?? {}
32474
+ }
32475
+ });
32476
+ if (!response.ok) {
32477
+ const text = await response.text().catch(() => "");
32478
+ throw new Error(`Titan gateway error (${response.status}): ${text || response.statusText}`);
32479
+ }
32480
+ let raw;
32481
+ try {
32482
+ raw = msgpack.decode(new Uint8Array(await response.arrayBuffer()));
32483
+ } catch {
32484
+ throw new Error(`Titan gateway returned an undecodable response for ${inputMint} -> ${outputMint}`);
32485
+ }
32486
+ const route = selectGatewayRoute(raw, swapMode ?? "ExactIn");
32487
+ if (!route) {
32488
+ throw new Error(`No Titan V3 route found for ${inputMint} -> ${outputMint}`);
32489
+ }
32490
+ return { route, raw };
32491
+ }
32492
+ function isViableRoute(route, swapMode) {
32493
+ return swapMode === "ExactIn" ? route.outAmount > 0 : route.inAmount > 0;
32494
+ }
32495
+ function selectGatewayRoute(raw, swapMode) {
32496
+ const viable = Object.values(raw.quotes ?? {}).filter((r) => isViableRoute(r, swapMode));
32497
+ if (viable.length === 0) return null;
32498
+ const winnerId = raw.metadata?.ExpectedWinner;
32499
+ if (winnerId) {
32500
+ const winner = raw.quotes[winnerId];
32501
+ if (winner && isViableRoute(winner, swapMode)) return winner;
32502
+ }
32503
+ return viable.reduce(
32504
+ (best, route) => swapMode === "ExactIn" ? route.outAmount > best.outAmount ? route : best : route.inAmount < best.inAmount ? route : best
32505
+ );
32506
+ }
32507
+ function deserializeTitanWireInstruction(ix) {
32508
+ return new web3_js.TransactionInstruction({
32509
+ programId: new web3_js.PublicKey(ix.p),
32510
+ keys: ix.a.map((account) => ({
32511
+ pubkey: new web3_js.PublicKey(account.p),
32512
+ isSigner: account.s,
32513
+ isWritable: account.w
32514
+ })),
32515
+ data: Buffer.from(ix.d)
32516
+ });
32517
+ }
32381
32518
 
32382
32519
  exports.ACCOUNT_SIZE = ACCOUNT_SIZE;
32383
32520
  exports.ACCOUNT_TYPE_SIZE = ACCOUNT_TYPE_SIZE;
@@ -32486,6 +32623,7 @@ exports.ZERO = ZERO;
32486
32623
  exports.addSigners = addSigners;
32487
32624
  exports.approveInstructionData = approveInstructionData;
32488
32625
  exports.buildSwapQuoteResult = buildSwapQuoteResult;
32626
+ exports.buildTitanTemplate = buildTitanTemplate;
32489
32627
  exports.calculateAPYFromAPR = calculateAPYFromAPR;
32490
32628
  exports.calculateDriftBorrowAPR = calculateDriftBorrowAPR;
32491
32629
  exports.calculateDriftBorrowAPY = calculateDriftBorrowAPY;
@@ -32562,6 +32700,7 @@ exports.deriveShortUrl = deriveShortUrl;
32562
32700
  exports.deriveUserMetadata = deriveUserMetadata;
32563
32701
  exports.deriveUserState = deriveUserState;
32564
32702
  exports.deserializeSerializedInstruction = deserializeSerializedInstruction;
32703
+ exports.deserializeTitanWireInstruction = deserializeTitanWireInstruction;
32565
32704
  exports.driftRewardsRawToDto = driftRewardsRawToDto;
32566
32705
  exports.driftSpotMarketRawToDto = driftSpotMarketRawToDto;
32567
32706
  exports.driftStateRawToDto = driftStateRawToDto;
@@ -32579,7 +32718,9 @@ exports.dtoToJupRateModelRaw = dtoToJupRateModelRaw;
32579
32718
  exports.dtoToJupTokenReserveRaw = dtoToJupTokenReserveRaw;
32580
32719
  exports.dtoToObligationRaw = dtoToObligationRaw;
32581
32720
  exports.dtoToReserveRaw = dtoToReserveRaw;
32721
+ exports.encodeTitanTemplate = encodeTitanTemplate;
32582
32722
  exports.farmRawToDto = farmRawToDto;
32723
+ exports.fetchTitanQuoteSwapV3 = fetchTitanQuoteSwapV3;
32583
32724
  exports.findMplMetadataAddress = findMplMetadataAddress;
32584
32725
  exports.findPoolAddress = findPoolAddress;
32585
32726
  exports.findPoolMintAddress = findPoolMintAddress;
@@ -32617,6 +32758,7 @@ exports.getSwitchboardProgram = getSwitchboardProgram;
32617
32758
  exports.initializeAccountInstructionData = initializeAccountInstructionData;
32618
32759
  exports.initializeStakedPoolIxs = initializeStakedPoolIxs;
32619
32760
  exports.initializeStakedPoolTx = initializeStakedPoolTx;
32761
+ exports.instructionToTitanWire = instructionToTitanWire;
32620
32762
  exports.interpolateLinear = interpolateLinear;
32621
32763
  exports.isSpotBalanceTypeVariant = isSpotBalanceTypeVariant;
32622
32764
  exports.jupLendingRewardsRateModelRawToDto = jupLendingRewardsRateModelRawToDto;
@@ -32624,6 +32766,7 @@ exports.jupLendingStateRawToDto = jupLendingStateRawToDto;
32624
32766
  exports.jupRateModelRawToDto = jupRateModelRawToDto;
32625
32767
  exports.jupTokenReserveRawToDto = jupTokenReserveRawToDto;
32626
32768
  exports.layout = layout;
32769
+ exports.lutToTitanWire = lutToTitanWire;
32627
32770
  exports.makeRefreshObligationIx = makeRefreshObligationIx;
32628
32771
  exports.makeRefreshReservesBatchIx = makeRefreshReservesBatchIx;
32629
32772
  exports.makeRefreshingIxs = makeRefreshingIxs;
@@ -32639,6 +32782,7 @@ exports.reserveRawToDto = reserveRawToDto;
32639
32782
  exports.resolveLookupTables = resolveLookupTables;
32640
32783
  exports.scaledSupplies = scaledSupplies;
32641
32784
  exports.selectBestRoute = selectBestRoute;
32785
+ exports.selectGatewayRoute = selectGatewayRoute;
32642
32786
  exports.slotAdjustmentFactor = slotAdjustmentFactor;
32643
32787
  exports.switchboardAccountCoder = switchboardAccountCoder;
32644
32788
  exports.syncNativeInstructionData = syncNativeInstructionData;