@hot-pot/hotpot-sdk-ts 0.0.3 → 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.
- package/dist/apiClient.js +20 -11
- package/dist/errors.d.ts +3 -0
- package/dist/errors.js +6 -0
- package/package.json +1 -1
- package/src/apiClient.ts +24 -11
- package/src/errors.ts +7 -0
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
|
/**
|
|
@@ -93,17 +94,25 @@ export class HotPotApiClient {
|
|
|
93
94
|
* @returns A promise that resolves to a paginated response of PublicSwapWithAdditionalInfo objects
|
|
94
95
|
*/
|
|
95
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';
|
|
96
101
|
let walletAddressesQuery;
|
|
97
102
|
if (walletAddresses.length > 0) {
|
|
98
|
-
walletAddressesQuery = 'wallet=' + walletAddresses.join('&wallet=');
|
|
103
|
+
walletAddressesQuery = '?wallet=' + walletAddresses.join('&wallet=');
|
|
99
104
|
}
|
|
100
105
|
else {
|
|
101
106
|
walletAddressesQuery = '';
|
|
102
107
|
}
|
|
103
|
-
let url = '/swaps/history?';
|
|
104
108
|
url += walletAddressesQuery;
|
|
105
109
|
if (retailId) {
|
|
106
|
-
|
|
110
|
+
if (walletAddressesQuery !== '') {
|
|
111
|
+
url += `&retail_id=${retailId}`;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
url += `?retail_id=${retailId}`;
|
|
115
|
+
}
|
|
107
116
|
}
|
|
108
117
|
const response = await this.client.get(`${url}&limit=${limit}&offset=${offset}&active=${active}`);
|
|
109
118
|
return response.data;
|
|
@@ -114,7 +123,7 @@ export class HotPotApiClient {
|
|
|
114
123
|
* @returns A promise that resolves to the PublicSwapWithAdditionalInfo object
|
|
115
124
|
*/
|
|
116
125
|
async getSwapByIntentId(intentId) {
|
|
117
|
-
const response = await this.client.get(`/swaps/intents/${intentId}`);
|
|
126
|
+
const response = await this.client.get(`/v1/swaps/intents/${intentId}`);
|
|
118
127
|
return response.data;
|
|
119
128
|
}
|
|
120
129
|
/**
|
|
@@ -123,7 +132,7 @@ export class HotPotApiClient {
|
|
|
123
132
|
* @returns A promise that resolves to an array of Network objects
|
|
124
133
|
*/
|
|
125
134
|
async listNetworks(token) {
|
|
126
|
-
const endpoint = token ? `/networks?token=${token}` : '/networks';
|
|
135
|
+
const endpoint = token ? `/v1/networks?token=${token}` : '/v1/networks';
|
|
127
136
|
const response = await this.client.get(endpoint);
|
|
128
137
|
return response.data;
|
|
129
138
|
}
|
|
@@ -136,7 +145,7 @@ export class HotPotApiClient {
|
|
|
136
145
|
* @returns A promise that resolves to a paginated response of Token objects
|
|
137
146
|
*/
|
|
138
147
|
async listTokens(limit = 20, offset = 0, q, networkId) {
|
|
139
|
-
let endpoint = `/tokens?limit=${limit}&offset=${offset}`;
|
|
148
|
+
let endpoint = `/v1/tokens?limit=${limit}&offset=${offset}`;
|
|
140
149
|
if (q) {
|
|
141
150
|
endpoint += `&q=${q}`;
|
|
142
151
|
}
|
package/dist/errors.d.ts
CHANGED
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
|
+
}
|
package/package.json
CHANGED
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;
|
|
@@ -150,17 +151,29 @@ export class HotPotApiClient {
|
|
|
150
151
|
offset: number = 0,
|
|
151
152
|
active: boolean = false,
|
|
152
153
|
): Promise<PaginatedResponse<PublicSwapWithAdditionalInfo>> {
|
|
154
|
+
if (walletAddresses.length <= 0 && !retailId) {
|
|
155
|
+
throw new MissingRequiredQueryParamsError();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
let url = '/v1/swaps/history';
|
|
159
|
+
|
|
153
160
|
let walletAddressesQuery;
|
|
154
161
|
if (walletAddresses.length > 0) {
|
|
155
|
-
walletAddressesQuery = 'wallet=' + walletAddresses.join('&wallet=');
|
|
162
|
+
walletAddressesQuery = '?wallet=' + walletAddresses.join('&wallet=');
|
|
156
163
|
} else {
|
|
157
164
|
walletAddressesQuery = '';
|
|
158
165
|
}
|
|
159
|
-
|
|
166
|
+
|
|
160
167
|
url += walletAddressesQuery;
|
|
168
|
+
|
|
161
169
|
if (retailId) {
|
|
162
|
-
|
|
170
|
+
if (walletAddressesQuery !== '') {
|
|
171
|
+
url += `&retail_id=${retailId}`;
|
|
172
|
+
} else {
|
|
173
|
+
url += `?retail_id=${retailId}`;
|
|
174
|
+
}
|
|
163
175
|
}
|
|
176
|
+
|
|
164
177
|
const response: AxiosResponse<PaginatedResponse<PublicSwapWithAdditionalInfo>> =
|
|
165
178
|
await this.client.get(`${url}&limit=${limit}&offset=${offset}&active=${active}`);
|
|
166
179
|
|
|
@@ -174,7 +187,7 @@ export class HotPotApiClient {
|
|
|
174
187
|
*/
|
|
175
188
|
async getSwapByIntentId(intentId: string): Promise<PublicSwapWithAdditionalInfo> {
|
|
176
189
|
const response: AxiosResponse<PublicSwapWithAdditionalInfo> = await this.client.get(
|
|
177
|
-
`/swaps/intents/${intentId}`,
|
|
190
|
+
`/v1/swaps/intents/${intentId}`,
|
|
178
191
|
);
|
|
179
192
|
|
|
180
193
|
return response.data;
|
|
@@ -186,7 +199,7 @@ export class HotPotApiClient {
|
|
|
186
199
|
* @returns A promise that resolves to an array of Network objects
|
|
187
200
|
*/
|
|
188
201
|
async listNetworks(token?: string): Promise<Network[]> {
|
|
189
|
-
const endpoint = token ? `/networks?token=${token}` : '/networks';
|
|
202
|
+
const endpoint = token ? `/v1/networks?token=${token}` : '/v1/networks';
|
|
190
203
|
const response: AxiosResponse<Network[]> = await this.client.get(endpoint);
|
|
191
204
|
|
|
192
205
|
return response.data;
|
|
@@ -206,7 +219,7 @@ export class HotPotApiClient {
|
|
|
206
219
|
q?: string,
|
|
207
220
|
networkId?: number,
|
|
208
221
|
): Promise<PaginatedResponse<Token>> {
|
|
209
|
-
let endpoint = `/tokens?limit=${limit}&offset=${offset}`;
|
|
222
|
+
let endpoint = `/v1/tokens?limit=${limit}&offset=${offset}`;
|
|
210
223
|
if (q) {
|
|
211
224
|
endpoint += `&q=${q}`;
|
|
212
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
|
+
}
|