@hot-pot/hotpot-sdk-ts 0.0.2 → 0.0.4

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.
@@ -53,7 +53,7 @@ export declare class HotPotApiClient {
53
53
  * @param active Whether to show only active swaps (default: false)
54
54
  * @returns A promise that resolves to a paginated response of PublicSwapWithAdditionalInfo objects
55
55
  */
56
- listRetailUserHistory(walletAddressOrRetailId: string, limit?: number, offset?: number, active?: boolean): Promise<PaginatedResponse<PublicSwapWithAdditionalInfo>>;
56
+ listRetailUserHistory(walletAddresses: string[], retailId: string | null, limit?: number, offset?: number, active?: boolean): Promise<PaginatedResponse<PublicSwapWithAdditionalInfo>>;
57
57
  /**
58
58
  * Retrieves swap details by intent ID
59
59
  * @param intentId The intent ID to retrieve swap details for
package/dist/apiClient.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import axios from 'axios';
2
+ import { MissingRequiredQueryParamsError } from 'errors';
2
3
  export class HotPotApiClient {
3
4
  client;
4
5
  constructor(apiUrl, apiKey, axiosInstance, config) {
@@ -26,7 +27,7 @@ export class HotPotApiClient {
26
27
  * @returns A promise that resolves to the Quote object
27
28
  */
28
29
  async getQuote(sourceChain, sourceToken, destChain, destToken, amount, slippageBps, swapType, retailUserId = null, depositType) {
29
- const response = await this.client.post('/quotes/best', {
30
+ const response = await this.client.post('/v1/quotes/best', {
30
31
  source_chain: sourceChain,
31
32
  source_token: sourceToken,
32
33
  dest_chain: destChain,
@@ -49,7 +50,7 @@ export class HotPotApiClient {
49
50
  * @returns A promise that resolves to the CreateIntentData object
50
51
  */
51
52
  async createIntent(quoteId, userSourcePublicKey, userSourceAddress, userDestinationAddress, refundAddress) {
52
- const response = await this.client.post('/intents', {
53
+ const response = await this.client.post('/v1/intents', {
53
54
  quote_id: quoteId,
54
55
  user_source_public_key: userSourcePublicKey,
55
56
  user_source_address: userSourceAddress,
@@ -64,7 +65,7 @@ export class HotPotApiClient {
64
65
  * @param intentId The intent ID to add the approval to
65
66
  */
66
67
  async addApproval(signedData, intentId) {
67
- await this.client.post(`/intents/${intentId}/approvals`, signedData);
68
+ await this.client.post(`/v1/intents/${intentId}/approvals`, signedData);
68
69
  }
69
70
  /**
70
71
  * Retrieves details of a specific intent
@@ -72,7 +73,7 @@ export class HotPotApiClient {
72
73
  * @returns A promise that resolves to the PublicSwapWithAdditionalInfo object
73
74
  */
74
75
  async getIntent(intentId) {
75
- const response = await this.client.get(`/intents/${intentId}`);
76
+ const response = await this.client.get(`/v1/intents/${intentId}`);
76
77
  return response.data;
77
78
  }
78
79
  /**
@@ -81,7 +82,7 @@ export class HotPotApiClient {
81
82
  * @returns A promise that resolves to the IntentStatus
82
83
  */
83
84
  async getIntentStatus(intentId) {
84
- const response = await this.client.get(`/intents/${intentId}/status`);
85
+ const response = await this.client.get(`/v1/intents/${intentId}/status`);
85
86
  return response.data.status;
86
87
  }
87
88
  /**
@@ -92,8 +93,28 @@ export class HotPotApiClient {
92
93
  * @param active Whether to show only active swaps (default: false)
93
94
  * @returns A promise that resolves to a paginated response of PublicSwapWithAdditionalInfo objects
94
95
  */
95
- async listRetailUserHistory(walletAddressOrRetailId, limit = 20, offset = 0, active = false) {
96
- const response = await this.client.get(`/swaps/history/${walletAddressOrRetailId}?limit=${limit}&offset=${offset}&active=${active}`);
96
+ async listRetailUserHistory(walletAddresses, retailId, limit = 20, offset = 0, active = false) {
97
+ if (walletAddresses.length <= 0 && !retailId) {
98
+ throw new MissingRequiredQueryParamsError();
99
+ }
100
+ let url = '/v1/swaps/history';
101
+ let walletAddressesQuery;
102
+ if (walletAddresses.length > 0) {
103
+ walletAddressesQuery = '?wallet=' + walletAddresses.join('&wallet=');
104
+ }
105
+ else {
106
+ walletAddressesQuery = '';
107
+ }
108
+ url += walletAddressesQuery;
109
+ if (retailId) {
110
+ if (walletAddressesQuery !== '') {
111
+ url += `&retail_id=${retailId}`;
112
+ }
113
+ else {
114
+ url += `?retail_id=${retailId}`;
115
+ }
116
+ }
117
+ const response = await this.client.get(`${url}&limit=${limit}&offset=${offset}&active=${active}`);
97
118
  return response.data;
98
119
  }
99
120
  /**
@@ -102,7 +123,7 @@ export class HotPotApiClient {
102
123
  * @returns A promise that resolves to the PublicSwapWithAdditionalInfo object
103
124
  */
104
125
  async getSwapByIntentId(intentId) {
105
- const response = await this.client.get(`/swaps/intents/${intentId}`);
126
+ const response = await this.client.get(`/v1/swaps/intents/${intentId}`);
106
127
  return response.data;
107
128
  }
108
129
  /**
@@ -111,7 +132,7 @@ export class HotPotApiClient {
111
132
  * @returns A promise that resolves to an array of Network objects
112
133
  */
113
134
  async listNetworks(token) {
114
- const endpoint = token ? `/networks?token=${token}` : '/networks';
135
+ const endpoint = token ? `/v1/networks?token=${token}` : '/v1/networks';
115
136
  const response = await this.client.get(endpoint);
116
137
  return response.data;
117
138
  }
@@ -124,7 +145,7 @@ export class HotPotApiClient {
124
145
  * @returns A promise that resolves to a paginated response of Token objects
125
146
  */
126
147
  async listTokens(limit = 20, offset = 0, q, networkId) {
127
- let endpoint = `/tokens?limit=${limit}&offset=${offset}`;
148
+ let endpoint = `/v1/tokens?limit=${limit}&offset=${offset}`;
128
149
  if (q) {
129
150
  endpoint += `&q=${q}`;
130
151
  }
package/dist/errors.d.ts CHANGED
@@ -12,3 +12,6 @@ export declare class InsufficientAllowanceError extends Error {
12
12
  entity: string;
13
13
  constructor(apiError: ApiError);
14
14
  }
15
+ export declare class MissingRequiredQueryParamsError extends Error {
16
+ constructor();
17
+ }
package/dist/errors.js CHANGED
@@ -11,3 +11,9 @@ export class InsufficientAllowanceError extends Error {
11
11
  this.entity = apiError.entity;
12
12
  }
13
13
  }
14
+ export class MissingRequiredQueryParamsError extends Error {
15
+ constructor() {
16
+ super('Missing required query parameters');
17
+ this.name = 'MissingRequiredQueryParamsError';
18
+ }
19
+ }
@@ -1,6 +1,6 @@
1
1
  import { HotPotApiClient } from '../../src/apiClient.js';
2
2
  import { preparePermit2Approval } from '../../src/approvals.js';
3
- import { SwapType } from '../../src/types.js';
3
+ import { type DepositType, SwapType } from '../../src/types.js';
4
4
 
5
5
  async function main() {
6
6
  // Initialize the HotPot API client with the API key from environment variables
@@ -19,6 +19,7 @@ async function main() {
19
19
  const amount = 1_000_000; // Amount in USD (or base units depending on token)
20
20
  const slippageBps = 50n; // 0.5% slippage
21
21
  const swapType = SwapType.Optimized;
22
+ const depositType: DepositType = 'escrowed';
22
23
 
23
24
  // Get a quote for the swap
24
25
  console.log('Getting quote...');
@@ -30,6 +31,8 @@ async function main() {
30
31
  amount,
31
32
  slippageBps,
32
33
  swapType,
34
+ null,
35
+ depositType,
33
36
  );
34
37
  console.log('Quote received:', quote);
35
38
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hot-pot/hotpot-sdk-ts",
3
3
  "private": false,
4
- "version": "0.0.2",
4
+ "version": "0.0.4",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist",
package/src/apiClient.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
2
2
  import axios from 'axios';
3
+ import { MissingRequiredQueryParamsError } from 'errors';
3
4
 
4
5
  import type {
5
6
  CreateIntentData,
@@ -58,7 +59,7 @@ export class HotPotApiClient {
58
59
  retailUserId: string | null = null,
59
60
  depositType: DepositType,
60
61
  ): Promise<Quote> {
61
- const response: AxiosResponse<Quote> = await this.client.post('/quotes/best', {
62
+ const response: AxiosResponse<Quote> = await this.client.post('/v1/quotes/best', {
62
63
  source_chain: sourceChain,
63
64
  source_token: sourceToken,
64
65
  dest_chain: destChain,
@@ -89,7 +90,7 @@ export class HotPotApiClient {
89
90
  userDestinationAddress: string,
90
91
  refundAddress: string,
91
92
  ): Promise<CreateIntentData> {
92
- const response: AxiosResponse<CreateIntentData> = await this.client.post('/intents', {
93
+ const response: AxiosResponse<CreateIntentData> = await this.client.post('/v1/intents', {
93
94
  quote_id: quoteId,
94
95
  user_source_public_key: userSourcePublicKey,
95
96
  user_source_address: userSourceAddress,
@@ -106,7 +107,7 @@ export class HotPotApiClient {
106
107
  * @param intentId The intent ID to add the approval to
107
108
  */
108
109
  async addApproval(signedData: SignedApproval, intentId: string): Promise<void> {
109
- await this.client.post(`/intents/${intentId}/approvals`, signedData);
110
+ await this.client.post(`/v1/intents/${intentId}/approvals`, signedData);
110
111
  }
111
112
 
112
113
  /**
@@ -116,7 +117,7 @@ export class HotPotApiClient {
116
117
  */
117
118
  async getIntent(intentId: string): Promise<PublicSwapWithAdditionalInfo> {
118
119
  const response: AxiosResponse<PublicSwapWithAdditionalInfo> = await this.client.get(
119
- `/intents/${intentId}`,
120
+ `/v1/intents/${intentId}`,
120
121
  );
121
122
 
122
123
  return response.data;
@@ -129,7 +130,7 @@ export class HotPotApiClient {
129
130
  */
130
131
  async getIntentStatus(intentId: string): Promise<IntentStatus> {
131
132
  const response: AxiosResponse<{ status: IntentStatus }> = await this.client.get(
132
- `/intents/${intentId}/status`,
133
+ `/v1/intents/${intentId}/status`,
133
134
  );
134
135
 
135
136
  return response.data.status;
@@ -144,15 +145,37 @@ export class HotPotApiClient {
144
145
  * @returns A promise that resolves to a paginated response of PublicSwapWithAdditionalInfo objects
145
146
  */
146
147
  async listRetailUserHistory(
147
- walletAddressOrRetailId: string,
148
+ walletAddresses: string[],
149
+ retailId: string | null,
148
150
  limit: number = 20,
149
151
  offset: number = 0,
150
152
  active: boolean = false,
151
153
  ): Promise<PaginatedResponse<PublicSwapWithAdditionalInfo>> {
154
+ if (walletAddresses.length <= 0 && !retailId) {
155
+ throw new MissingRequiredQueryParamsError();
156
+ }
157
+
158
+ let url = '/v1/swaps/history';
159
+
160
+ let walletAddressesQuery;
161
+ if (walletAddresses.length > 0) {
162
+ walletAddressesQuery = '?wallet=' + walletAddresses.join('&wallet=');
163
+ } else {
164
+ walletAddressesQuery = '';
165
+ }
166
+
167
+ url += walletAddressesQuery;
168
+
169
+ if (retailId) {
170
+ if (walletAddressesQuery !== '') {
171
+ url += `&retail_id=${retailId}`;
172
+ } else {
173
+ url += `?retail_id=${retailId}`;
174
+ }
175
+ }
176
+
152
177
  const response: AxiosResponse<PaginatedResponse<PublicSwapWithAdditionalInfo>> =
153
- await this.client.get(
154
- `/swaps/history/${walletAddressOrRetailId}?limit=${limit}&offset=${offset}&active=${active}`,
155
- );
178
+ await this.client.get(`${url}&limit=${limit}&offset=${offset}&active=${active}`);
156
179
 
157
180
  return response.data;
158
181
  }
@@ -164,7 +187,7 @@ export class HotPotApiClient {
164
187
  */
165
188
  async getSwapByIntentId(intentId: string): Promise<PublicSwapWithAdditionalInfo> {
166
189
  const response: AxiosResponse<PublicSwapWithAdditionalInfo> = await this.client.get(
167
- `/swaps/intents/${intentId}`,
190
+ `/v1/swaps/intents/${intentId}`,
168
191
  );
169
192
 
170
193
  return response.data;
@@ -176,7 +199,7 @@ export class HotPotApiClient {
176
199
  * @returns A promise that resolves to an array of Network objects
177
200
  */
178
201
  async listNetworks(token?: string): Promise<Network[]> {
179
- const endpoint = token ? `/networks?token=${token}` : '/networks';
202
+ const endpoint = token ? `/v1/networks?token=${token}` : '/v1/networks';
180
203
  const response: AxiosResponse<Network[]> = await this.client.get(endpoint);
181
204
 
182
205
  return response.data;
@@ -196,7 +219,7 @@ export class HotPotApiClient {
196
219
  q?: string,
197
220
  networkId?: number,
198
221
  ): Promise<PaginatedResponse<Token>> {
199
- let endpoint = `/tokens?limit=${limit}&offset=${offset}`;
222
+ let endpoint = `/v1/tokens?limit=${limit}&offset=${offset}`;
200
223
  if (q) {
201
224
  endpoint += `&q=${q}`;
202
225
  }
package/src/errors.ts CHANGED
@@ -21,3 +21,10 @@ export class InsufficientAllowanceError extends Error {
21
21
  this.entity = apiError.entity;
22
22
  }
23
23
  }
24
+
25
+ export class MissingRequiredQueryParamsError extends Error {
26
+ constructor() {
27
+ super('Missing required query parameters');
28
+ this.name = 'MissingRequiredQueryParamsError';
29
+ }
30
+ }