@bitflowlabs/core-sdk 2.0.2 → 2.1.3
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/src/BitflowSDK.d.ts +6 -4
- package/dist/src/BitflowSDK.js +439 -239
- package/dist/src/BitflowSDK.js.map +1 -1
- package/dist/src/helpers/callReadOnlyHelper.d.ts +7 -1
- package/dist/src/helpers/callReadOnlyHelper.js +201 -26
- package/dist/src/helpers/callReadOnlyHelper.js.map +1 -1
- package/dist/src/keeper/keeperAPI.js +3 -48
- package/dist/src/keeper/keeperAPI.js.map +1 -1
- package/dist/src/keeper/types.d.ts +27 -10
- package/dist/src/keeper/types.js.map +1 -1
- package/dist/src/test/testMethods.js +10 -0
- package/dist/src/test/testMethods.js.map +1 -1
- package/package.json +2 -1
- package/src/BitflowSDK.ts +532 -269
- package/src/helpers/callReadOnlyHelper.ts +258 -32
- package/src/keeper/keeperAPI.ts +5 -68
- package/src/keeper/types.ts +28 -11
- package/src/test/testMethods.ts +19 -0
- package/dist/src/test-get-user.d.ts +0 -1
- package/dist/src/test-get-user.js +0 -77
- package/dist/src/test-get-user.js.map +0 -1
- package/dist/src/test-keeper-routes.d.ts +0 -1
- package/dist/src/test-keeper-routes.js +0 -67
- package/dist/src/test-keeper-routes.js.map +0 -1
- package/dist/src/test-order.d.ts +0 -1
- package/dist/src/test-order.js +0 -71
- package/dist/src/test-order.js.map +0 -1
- package/dist/src/test-raw-token-response.d.ts +0 -1
- package/dist/src/test-raw-token-response.js +0 -79
- package/dist/src/test-raw-token-response.js.map +0 -1
- package/dist/src/test-sdk.d.ts +0 -1
- package/dist/src/test-sdk.js +0 -229
- package/dist/src/test-sdk.js.map +0 -1
- package/dist/src/test-token.fetch.d.ts +0 -1
- package/dist/src/test-token.fetch.js +0 -63
- package/dist/src/test-token.fetch.js.map +0 -1
- package/src/test-get-user.ts +0 -87
- package/src/test-keeper-routes.ts +0 -76
- package/src/test-order.ts +0 -81
- package/src/test-raw-token-response.ts +0 -124
- package/src/test-sdk.ts +0 -262
- package/src/test-token.fetch.ts +0 -72
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { fetchCallReadOnlyFunction } from
|
|
2
|
-
import { SwapContext } from
|
|
3
|
-
import { getTokenDecimals } from
|
|
4
|
-
import { constructFunctionArgs } from
|
|
5
|
-
import { configs } from
|
|
6
|
-
import { getContractInterfaceAndFunction } from
|
|
7
|
-
import { handleResult } from
|
|
1
|
+
import { fetchCallReadOnlyFunction } from '@stacks/transactions';
|
|
2
|
+
import { SwapContext } from '../types';
|
|
3
|
+
import { getTokenDecimals } from './getTokenDecimalsHelper';
|
|
4
|
+
import { constructFunctionArgs } from './constructFunctionArgs';
|
|
5
|
+
import { configs } from '../config';
|
|
6
|
+
import { getContractInterfaceAndFunction } from './getContractInterfaceAndFunction';
|
|
7
|
+
import { handleResult } from './handleResultHelper';
|
|
8
8
|
|
|
9
9
|
export const stringifyWithBigInt = (obj: any): string => {
|
|
10
10
|
return JSON.stringify(obj, (_, v) =>
|
|
11
|
-
typeof v ===
|
|
11
|
+
typeof v === 'bigint' ? v.toString() : v
|
|
12
12
|
);
|
|
13
13
|
};
|
|
14
14
|
|
|
@@ -28,7 +28,7 @@ export const callReadOnlyFunctionHelper = async (
|
|
|
28
28
|
tokenXDecimals: number;
|
|
29
29
|
tokenYDecimals: number;
|
|
30
30
|
}> => {
|
|
31
|
-
const network =
|
|
31
|
+
const network = 'mainnet';
|
|
32
32
|
|
|
33
33
|
const client = {
|
|
34
34
|
baseUrl: configs.READONLY_CALL_API_HOST,
|
|
@@ -69,7 +69,7 @@ export const callReadOnlyFunctionHelper = async (
|
|
|
69
69
|
|
|
70
70
|
// Attempt to find matching token decimals from parameters
|
|
71
71
|
for (const key in parameters) {
|
|
72
|
-
if (typeof parameters[key] ===
|
|
72
|
+
if (typeof parameters[key] === 'object') {
|
|
73
73
|
for (const subKey in parameters[key]) {
|
|
74
74
|
const contractValue = parameters[key][subKey];
|
|
75
75
|
tokenXMatchingDecimal = tokenXDecimals.find(
|
|
@@ -77,7 +77,7 @@ export const callReadOnlyFunctionHelper = async (
|
|
|
77
77
|
);
|
|
78
78
|
if (tokenXMatchingDecimal) break;
|
|
79
79
|
}
|
|
80
|
-
} else if (typeof parameters[key] ===
|
|
80
|
+
} else if (typeof parameters[key] === 'string') {
|
|
81
81
|
tokenXMatchingDecimal = tokenXDecimals.find(
|
|
82
82
|
(d) => d.tokenContract === parameters[key]
|
|
83
83
|
);
|
|
@@ -89,7 +89,7 @@ export const callReadOnlyFunctionHelper = async (
|
|
|
89
89
|
if (!tokenXMatchingDecimal && swapData && swapData.parameters) {
|
|
90
90
|
const swapParameters = swapData.parameters;
|
|
91
91
|
for (const key in swapParameters) {
|
|
92
|
-
if (typeof swapParameters[key] ===
|
|
92
|
+
if (typeof swapParameters[key] === 'object') {
|
|
93
93
|
for (const subKey in swapParameters[key]) {
|
|
94
94
|
const contractValue = swapParameters[key][subKey];
|
|
95
95
|
tokenXMatchingDecimal = tokenXDecimals.find(
|
|
@@ -97,7 +97,7 @@ export const callReadOnlyFunctionHelper = async (
|
|
|
97
97
|
);
|
|
98
98
|
if (tokenXMatchingDecimal) break;
|
|
99
99
|
}
|
|
100
|
-
} else if (typeof swapParameters[key] ===
|
|
100
|
+
} else if (typeof swapParameters[key] === 'string') {
|
|
101
101
|
tokenXMatchingDecimal = tokenXDecimals.find(
|
|
102
102
|
(d) => d.tokenContract === swapParameters[key]
|
|
103
103
|
);
|
|
@@ -123,26 +123,26 @@ export const callReadOnlyFunctionHelper = async (
|
|
|
123
123
|
) {
|
|
124
124
|
parameters.amount = scaleAmount(parameters.amount);
|
|
125
125
|
} else if (
|
|
126
|
-
parameters[
|
|
127
|
-
parameters[
|
|
126
|
+
parameters['amt-in'] !== undefined &&
|
|
127
|
+
parameters['amt-in'] !== null
|
|
128
128
|
) {
|
|
129
|
-
parameters[
|
|
129
|
+
parameters['amt-in'] = scaleAmount(parameters['amt-in']);
|
|
130
130
|
} else if (
|
|
131
|
-
parameters[
|
|
132
|
-
parameters[
|
|
131
|
+
parameters['amt-in-max'] !== undefined &&
|
|
132
|
+
parameters['amt-in-max'] !== null
|
|
133
133
|
) {
|
|
134
|
-
parameters[
|
|
134
|
+
parameters['amt-in-max'] = scaleAmount(parameters['amt-in-max']);
|
|
135
135
|
} else if (
|
|
136
|
-
parameters[
|
|
137
|
-
parameters[
|
|
136
|
+
parameters['y-amount'] !== undefined &&
|
|
137
|
+
parameters['y-amount'] !== null
|
|
138
138
|
) {
|
|
139
|
-
parameters[
|
|
140
|
-
parameters[
|
|
139
|
+
parameters['y-amount'] = scaleAmount(parameters['y-amount']);
|
|
140
|
+
parameters['x-amount'] = scaleAmount(parameters['x-amount']);
|
|
141
141
|
} else if (
|
|
142
|
-
parameters[
|
|
143
|
-
parameters[
|
|
142
|
+
parameters['x-amount'] !== undefined &&
|
|
143
|
+
parameters['x-amount'] !== null
|
|
144
144
|
) {
|
|
145
|
-
parameters[
|
|
145
|
+
parameters['x-amount'] = scaleAmount(parameters['x-amount']);
|
|
146
146
|
} else if (parameters.dy !== undefined && parameters.dy !== null) {
|
|
147
147
|
parameters.dy = scaleAmount(parameters.dy);
|
|
148
148
|
}
|
|
@@ -175,7 +175,7 @@ export const callReadOnlyFunctionHelper = async (
|
|
|
175
175
|
| undefined;
|
|
176
176
|
|
|
177
177
|
for (const key in parameters) {
|
|
178
|
-
if (typeof parameters[key] ===
|
|
178
|
+
if (typeof parameters[key] === 'object') {
|
|
179
179
|
for (const subKey in parameters[key]) {
|
|
180
180
|
const contractValue = parameters[key][subKey];
|
|
181
181
|
tokenYMatchingDecimal = tokenYDecimals.find(
|
|
@@ -183,7 +183,7 @@ export const callReadOnlyFunctionHelper = async (
|
|
|
183
183
|
);
|
|
184
184
|
if (tokenYMatchingDecimal) break;
|
|
185
185
|
}
|
|
186
|
-
} else if (typeof parameters[key] ===
|
|
186
|
+
} else if (typeof parameters[key] === 'string') {
|
|
187
187
|
tokenYMatchingDecimal = tokenYDecimals.find(
|
|
188
188
|
(d) => d.tokenContract === parameters[key]
|
|
189
189
|
);
|
|
@@ -194,7 +194,7 @@ export const callReadOnlyFunctionHelper = async (
|
|
|
194
194
|
if (!tokenYMatchingDecimal && swapData && swapData.parameters) {
|
|
195
195
|
const swapParameters = swapData.parameters;
|
|
196
196
|
for (const key in swapParameters) {
|
|
197
|
-
if (typeof swapParameters[key] ===
|
|
197
|
+
if (typeof swapParameters[key] === 'object') {
|
|
198
198
|
for (const subKey in swapParameters[key]) {
|
|
199
199
|
const contractValue = swapParameters[key][subKey];
|
|
200
200
|
tokenYMatchingDecimal = tokenYDecimals.find(
|
|
@@ -202,7 +202,7 @@ export const callReadOnlyFunctionHelper = async (
|
|
|
202
202
|
);
|
|
203
203
|
if (tokenYMatchingDecimal) break;
|
|
204
204
|
}
|
|
205
|
-
} else if (typeof swapParameters[key] ===
|
|
205
|
+
} else if (typeof swapParameters[key] === 'string') {
|
|
206
206
|
tokenYMatchingDecimal = tokenYDecimals.find(
|
|
207
207
|
(d) => d.tokenContract === swapParameters[key]
|
|
208
208
|
);
|
|
@@ -211,7 +211,234 @@ export const callReadOnlyFunctionHelper = async (
|
|
|
211
211
|
}
|
|
212
212
|
}
|
|
213
213
|
|
|
214
|
-
if (tokenYMatchingDecimal && typeof convertedResult ===
|
|
214
|
+
if (tokenYMatchingDecimal && typeof convertedResult === 'number') {
|
|
215
|
+
const adjustedResult =
|
|
216
|
+
convertedResult / 10 ** tokenYMatchingDecimal.tokenDecimals;
|
|
217
|
+
return {
|
|
218
|
+
convertedResult: adjustedResult,
|
|
219
|
+
rawResult,
|
|
220
|
+
tokenXDecimals: tokenXMatchingDecimal?.tokenDecimals || 0,
|
|
221
|
+
tokenYDecimals: tokenYMatchingDecimal.tokenDecimals,
|
|
222
|
+
};
|
|
223
|
+
} else {
|
|
224
|
+
console.warn(
|
|
225
|
+
`No matching decimal found for tokenY: ${tokenYId} or result is not a number`
|
|
226
|
+
);
|
|
227
|
+
return {
|
|
228
|
+
convertedResult,
|
|
229
|
+
rawResult,
|
|
230
|
+
tokenXDecimals: tokenXMatchingDecimal?.tokenDecimals || 0,
|
|
231
|
+
tokenYDecimals: 0,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
} catch (error) {
|
|
235
|
+
console.warn(`Couldn't apply decimal conversion: ${error}`);
|
|
236
|
+
console.warn('Using raw result without decimal conversion');
|
|
237
|
+
return {
|
|
238
|
+
convertedResult,
|
|
239
|
+
rawResult,
|
|
240
|
+
tokenXDecimals: tokenXMatchingDecimal?.tokenDecimals || 0,
|
|
241
|
+
tokenYDecimals: 0,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
} catch (error) {
|
|
245
|
+
console.error(`Error calling read-only function ${functionName}:`, error);
|
|
246
|
+
throw error;
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
export const callReadOnlyFunctionHelperWithoutScaling = async (
|
|
251
|
+
contractDeployer: string,
|
|
252
|
+
contractName: string,
|
|
253
|
+
functionName: string,
|
|
254
|
+
parameters: any,
|
|
255
|
+
senderAddress: string,
|
|
256
|
+
tokenXId: string,
|
|
257
|
+
tokenYId: string,
|
|
258
|
+
swapData: any,
|
|
259
|
+
context: SwapContext
|
|
260
|
+
): Promise<{
|
|
261
|
+
convertedResult: number;
|
|
262
|
+
rawResult: number;
|
|
263
|
+
tokenXDecimals: number;
|
|
264
|
+
tokenYDecimals: number;
|
|
265
|
+
}> => {
|
|
266
|
+
const network = 'mainnet';
|
|
267
|
+
|
|
268
|
+
const client = {
|
|
269
|
+
baseUrl: configs.READONLY_CALL_API_HOST,
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
try {
|
|
273
|
+
const contractKey = `${contractDeployer}.${contractName}`;
|
|
274
|
+
let contractInterface = context.contractInterfaces[contractKey];
|
|
275
|
+
let functionArgsDefinition =
|
|
276
|
+
context.functionArgs[contractKey]?.[functionName];
|
|
277
|
+
|
|
278
|
+
if (!contractInterface || !functionArgsDefinition) {
|
|
279
|
+
const result = await getContractInterfaceAndFunction(
|
|
280
|
+
contractDeployer,
|
|
281
|
+
contractName,
|
|
282
|
+
functionName
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
if (!contractInterface) {
|
|
286
|
+
contractInterface = result.contractInterface;
|
|
287
|
+
context.contractInterfaces[contractKey] = contractInterface;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (!functionArgsDefinition) {
|
|
291
|
+
functionArgsDefinition = result.functionArgs;
|
|
292
|
+
if (!context.functionArgs[contractKey]) {
|
|
293
|
+
context.functionArgs[contractKey] = {};
|
|
294
|
+
}
|
|
295
|
+
context.functionArgs[contractKey][functionName] =
|
|
296
|
+
functionArgsDefinition;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const tokenXDecimals = getTokenDecimals(tokenXId, context);
|
|
301
|
+
let tokenXMatchingDecimal:
|
|
302
|
+
| { tokenContract: string; tokenDecimals: number }
|
|
303
|
+
| undefined;
|
|
304
|
+
|
|
305
|
+
// Attempt to find matching token decimals from parameters
|
|
306
|
+
for (const key in parameters) {
|
|
307
|
+
if (typeof parameters[key] === 'object') {
|
|
308
|
+
for (const subKey in parameters[key]) {
|
|
309
|
+
const contractValue = parameters[key][subKey];
|
|
310
|
+
tokenXMatchingDecimal = tokenXDecimals.find(
|
|
311
|
+
(d) => d.tokenContract === contractValue
|
|
312
|
+
);
|
|
313
|
+
if (tokenXMatchingDecimal) break;
|
|
314
|
+
}
|
|
315
|
+
} else if (typeof parameters[key] === 'string') {
|
|
316
|
+
tokenXMatchingDecimal = tokenXDecimals.find(
|
|
317
|
+
(d) => d.tokenContract === parameters[key]
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
if (tokenXMatchingDecimal) break;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// If not found yet, also check swapData parameters
|
|
324
|
+
if (!tokenXMatchingDecimal && swapData && swapData.parameters) {
|
|
325
|
+
const swapParameters = swapData.parameters;
|
|
326
|
+
for (const key in swapParameters) {
|
|
327
|
+
if (typeof swapParameters[key] === 'object') {
|
|
328
|
+
for (const subKey in swapParameters[key]) {
|
|
329
|
+
const contractValue = swapParameters[key][subKey];
|
|
330
|
+
tokenXMatchingDecimal = tokenXDecimals.find(
|
|
331
|
+
(d) => d.tokenContract === contractValue
|
|
332
|
+
);
|
|
333
|
+
if (tokenXMatchingDecimal) break;
|
|
334
|
+
}
|
|
335
|
+
} else if (typeof swapParameters[key] === 'string') {
|
|
336
|
+
tokenXMatchingDecimal = tokenXDecimals.find(
|
|
337
|
+
(d) => d.tokenContract === swapParameters[key]
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
if (tokenXMatchingDecimal) break;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// Skip scaling and use raw input values
|
|
345
|
+
// Just convert any numerical values to BigInt to maintain type compatibility
|
|
346
|
+
if (parameters.dx !== undefined && parameters.dx !== null) {
|
|
347
|
+
parameters.dx = BigInt(Math.floor(parameters.dx));
|
|
348
|
+
} else if (parameters.amount !== undefined && parameters.amount !== null) {
|
|
349
|
+
parameters.amount = BigInt(Math.floor(parameters.amount));
|
|
350
|
+
} else if (
|
|
351
|
+
parameters['amt-in'] !== undefined &&
|
|
352
|
+
parameters['amt-in'] !== null
|
|
353
|
+
) {
|
|
354
|
+
parameters['amt-in'] = BigInt(Math.floor(parameters['amt-in']));
|
|
355
|
+
} else if (
|
|
356
|
+
parameters['amt-in-max'] !== undefined &&
|
|
357
|
+
parameters['amt-in-max'] !== null
|
|
358
|
+
) {
|
|
359
|
+
parameters['amt-in-max'] = BigInt(Math.floor(parameters['amt-in-max']));
|
|
360
|
+
} else if (
|
|
361
|
+
parameters['y-amount'] !== undefined &&
|
|
362
|
+
parameters['y-amount'] !== null
|
|
363
|
+
) {
|
|
364
|
+
parameters['y-amount'] = BigInt(Math.floor(parameters['y-amount']));
|
|
365
|
+
if (
|
|
366
|
+
parameters['x-amount'] !== undefined &&
|
|
367
|
+
parameters['x-amount'] !== null
|
|
368
|
+
) {
|
|
369
|
+
parameters['x-amount'] = BigInt(Math.floor(parameters['x-amount']));
|
|
370
|
+
}
|
|
371
|
+
} else if (
|
|
372
|
+
parameters['x-amount'] !== undefined &&
|
|
373
|
+
parameters['x-amount'] !== null
|
|
374
|
+
) {
|
|
375
|
+
parameters['x-amount'] = BigInt(Math.floor(parameters['x-amount']));
|
|
376
|
+
} else if (parameters.dy !== undefined && parameters.dy !== null) {
|
|
377
|
+
parameters.dy = BigInt(Math.floor(parameters.dy));
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const functionArgs = constructFunctionArgs(
|
|
381
|
+
parameters,
|
|
382
|
+
functionArgsDefinition
|
|
383
|
+
);
|
|
384
|
+
|
|
385
|
+
const result = await fetchCallReadOnlyFunction({
|
|
386
|
+
contractAddress: contractDeployer,
|
|
387
|
+
contractName,
|
|
388
|
+
functionName,
|
|
389
|
+
functionArgs,
|
|
390
|
+
network,
|
|
391
|
+
client,
|
|
392
|
+
senderAddress: senderAddress,
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
const { rawResult, convertedResult } = handleResult(result);
|
|
396
|
+
|
|
397
|
+
try {
|
|
398
|
+
const tokenYDecimals = getTokenDecimals(tokenYId, context);
|
|
399
|
+
|
|
400
|
+
let tokenYMatchingDecimal:
|
|
401
|
+
| { tokenContract: string; tokenDecimals: number }
|
|
402
|
+
| undefined;
|
|
403
|
+
|
|
404
|
+
for (const key in parameters) {
|
|
405
|
+
if (typeof parameters[key] === 'object') {
|
|
406
|
+
for (const subKey in parameters[key]) {
|
|
407
|
+
const contractValue = parameters[key][subKey];
|
|
408
|
+
tokenYMatchingDecimal = tokenYDecimals.find(
|
|
409
|
+
(d) => d.tokenContract === contractValue
|
|
410
|
+
);
|
|
411
|
+
if (tokenYMatchingDecimal) break;
|
|
412
|
+
}
|
|
413
|
+
} else if (typeof parameters[key] === 'string') {
|
|
414
|
+
tokenYMatchingDecimal = tokenYDecimals.find(
|
|
415
|
+
(d) => d.tokenContract === parameters[key]
|
|
416
|
+
);
|
|
417
|
+
}
|
|
418
|
+
if (tokenYMatchingDecimal) break;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
if (!tokenYMatchingDecimal && swapData && swapData.parameters) {
|
|
422
|
+
const swapParameters = swapData.parameters;
|
|
423
|
+
for (const key in swapParameters) {
|
|
424
|
+
if (typeof swapParameters[key] === 'object') {
|
|
425
|
+
for (const subKey in swapParameters[key]) {
|
|
426
|
+
const contractValue = swapParameters[key][subKey];
|
|
427
|
+
tokenYMatchingDecimal = tokenYDecimals.find(
|
|
428
|
+
(d) => d.tokenContract === contractValue
|
|
429
|
+
);
|
|
430
|
+
if (tokenYMatchingDecimal) break;
|
|
431
|
+
}
|
|
432
|
+
} else if (typeof swapParameters[key] === 'string') {
|
|
433
|
+
tokenYMatchingDecimal = tokenYDecimals.find(
|
|
434
|
+
(d) => d.tokenContract === swapParameters[key]
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
if (tokenYMatchingDecimal) break;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
if (tokenYMatchingDecimal && typeof convertedResult === 'number') {
|
|
215
442
|
const adjustedResult =
|
|
216
443
|
convertedResult / 10 ** tokenYMatchingDecimal.tokenDecimals;
|
|
217
444
|
return {
|
|
@@ -233,7 +460,6 @@ export const callReadOnlyFunctionHelper = async (
|
|
|
233
460
|
}
|
|
234
461
|
} catch (error) {
|
|
235
462
|
console.warn(`Couldn't apply decimal conversion: ${error}`);
|
|
236
|
-
console.warn("Using raw result without decimal conversion");
|
|
237
463
|
return {
|
|
238
464
|
convertedResult,
|
|
239
465
|
rawResult,
|
package/src/keeper/keeperAPI.ts
CHANGED
|
@@ -91,12 +91,6 @@ export async function getOrderAPI(orderId: string): Promise<GetOrderResponse> {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
const data = await response.json();
|
|
94
|
-
|
|
95
|
-
if (data.order) {
|
|
96
|
-
data.order.creationDate = new Date(data.order.creationDate);
|
|
97
|
-
data.order.lastUpdated = new Date(data.order.lastUpdated);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
94
|
return data as GetOrderResponse;
|
|
101
95
|
} catch (error) {
|
|
102
96
|
console.error("Error in getOrder:", error);
|
|
@@ -126,32 +120,8 @@ export async function getUserAPI(
|
|
|
126
120
|
);
|
|
127
121
|
}
|
|
128
122
|
|
|
129
|
-
const data =
|
|
130
|
-
|
|
131
|
-
if (data.user) {
|
|
132
|
-
data.user.creationDate = new Date(data.user.creationDate);
|
|
133
|
-
data.user.lastUpdated = new Date(data.user.lastUpdated);
|
|
134
|
-
|
|
135
|
-
const contracts = data.user.keeperContracts as Record<
|
|
136
|
-
string,
|
|
137
|
-
KeeperContract
|
|
138
|
-
>;
|
|
139
|
-
for (const contractKey in contracts) {
|
|
140
|
-
const contract = contracts[contractKey];
|
|
141
|
-
if (contract.deploymentDate) {
|
|
142
|
-
contract.deploymentDate = new Date(contract.deploymentDate);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const orders = data.user.keeperOrders as Record<string, KeeperOrder>;
|
|
147
|
-
for (const orderKey in orders) {
|
|
148
|
-
const order = orders[orderKey];
|
|
149
|
-
order.creationDate = new Date(order.creationDate);
|
|
150
|
-
order.lastUpdated = new Date(order.lastUpdated);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return data;
|
|
123
|
+
const data = await response.json();
|
|
124
|
+
return data as GetUserResponse;
|
|
155
125
|
} catch (error) {
|
|
156
126
|
console.error("Error in getUser:", error);
|
|
157
127
|
throw error;
|
|
@@ -178,6 +148,7 @@ export async function createOrderAPI(
|
|
|
178
148
|
tokenOrder: params.tokenOrder || [],
|
|
179
149
|
actionType: params.actionType,
|
|
180
150
|
bitcoinTxId: params.bitcoinTxId,
|
|
151
|
+
fundingTokens: params.fundingTokens || {},
|
|
181
152
|
actionAggregatorTokens: params.actionAggregatorTokens || undefined,
|
|
182
153
|
};
|
|
183
154
|
|
|
@@ -194,14 +165,8 @@ export async function createOrderAPI(
|
|
|
194
165
|
);
|
|
195
166
|
}
|
|
196
167
|
|
|
197
|
-
const data =
|
|
198
|
-
|
|
199
|
-
if (data.order) {
|
|
200
|
-
data.order.creationDate = new Date(data.order.creationDate);
|
|
201
|
-
data.order.lastUpdated = new Date(data.order.lastUpdated);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
return data;
|
|
168
|
+
const data = await response.json();
|
|
169
|
+
return data as CreateOrderResponse;
|
|
205
170
|
} catch (error) {
|
|
206
171
|
console.error("Error in createOrder:", error);
|
|
207
172
|
throw error;
|
|
@@ -306,18 +271,6 @@ export async function createGroupOrderAPI(
|
|
|
306
271
|
}
|
|
307
272
|
|
|
308
273
|
const data = await response.json();
|
|
309
|
-
|
|
310
|
-
if (data.groupOrder) {
|
|
311
|
-
data.groupOrder.creationDate = new Date(data.groupOrder.creationDate);
|
|
312
|
-
data.groupOrder.lastUpdated = new Date(data.groupOrder.lastUpdated);
|
|
313
|
-
if (data.groupOrder.orders) {
|
|
314
|
-
data.groupOrder.orders.forEach((order: KeeperOrder) => {
|
|
315
|
-
order.creationDate = new Date(order.creationDate);
|
|
316
|
-
order.lastUpdated = new Date(order.lastUpdated);
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
274
|
return data as CreateGroupOrderResponse;
|
|
322
275
|
} catch (error) {
|
|
323
276
|
console.error("Error in createGroupOrder:", error);
|
|
@@ -352,22 +305,6 @@ export async function getGroupOrderAPI(
|
|
|
352
305
|
}
|
|
353
306
|
|
|
354
307
|
const data = await response.json();
|
|
355
|
-
|
|
356
|
-
if (data.groupOrder) {
|
|
357
|
-
data.groupOrder.creationDate = new Date(data.groupOrder.creationDate);
|
|
358
|
-
data.groupOrder.lastUpdated = new Date(data.groupOrder.lastUpdated);
|
|
359
|
-
data.groupOrder.nextExecutionAfter = new Date(
|
|
360
|
-
data.groupOrder.nextExecutionAfter
|
|
361
|
-
);
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
if (data.groupOrders && Array.isArray(data.groupOrders)) {
|
|
365
|
-
data.groupOrders.forEach((order: KeeperOrder) => {
|
|
366
|
-
order.creationDate = new Date(order.creationDate);
|
|
367
|
-
order.lastUpdated = new Date(order.lastUpdated);
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
|
|
371
308
|
return data as GetGroupOrderResponse;
|
|
372
309
|
} catch (error) {
|
|
373
310
|
console.error("Error in getGroupOrder:", error);
|
package/src/keeper/types.ts
CHANGED
|
@@ -89,14 +89,33 @@ export interface KeeperOrder {
|
|
|
89
89
|
actionAmount: string;
|
|
90
90
|
minReceived: MinReceived;
|
|
91
91
|
feeRecipient: string;
|
|
92
|
-
|
|
92
|
+
actionType: string;
|
|
93
|
+
actionAggregatorTokens: {
|
|
94
|
+
tokenXId: string;
|
|
95
|
+
tokenYId: string;
|
|
96
|
+
};
|
|
97
|
+
fundingTokens: Record<string, any>;
|
|
93
98
|
txIds: Record<string, string>;
|
|
94
|
-
|
|
99
|
+
txRetries: {
|
|
100
|
+
deploys: number;
|
|
101
|
+
actions: number;
|
|
102
|
+
};
|
|
95
103
|
requiresPontisTx: boolean;
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
104
|
+
keeperType: KeeperType;
|
|
105
|
+
orderStatus: string;
|
|
106
|
+
executeActionAfter: TimestampFormat;
|
|
107
|
+
creationDate: TimestampFormat;
|
|
108
|
+
lastUpdated: TimestampFormat;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
interface TimestampFormat {
|
|
112
|
+
_seconds: number;
|
|
113
|
+
_nanoseconds: number;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface CreateOrderResponse {
|
|
117
|
+
keeperOrder: KeeperOrder;
|
|
118
|
+
error?: string;
|
|
100
119
|
}
|
|
101
120
|
|
|
102
121
|
export interface GetOrderResponse {
|
|
@@ -132,6 +151,9 @@ export interface CreateOrderParams {
|
|
|
132
151
|
tokenOrder?: string[];
|
|
133
152
|
actionType: string;
|
|
134
153
|
bitcoinTxId: string;
|
|
154
|
+
fundingTokens?: {
|
|
155
|
+
[key: string]: string;
|
|
156
|
+
};
|
|
135
157
|
actionFunctionArgs?: {
|
|
136
158
|
tokenList?: Record<string, string>;
|
|
137
159
|
xykPoolList?: Record<string, string>;
|
|
@@ -145,11 +167,6 @@ export interface CreateOrderParams {
|
|
|
145
167
|
};
|
|
146
168
|
}
|
|
147
169
|
|
|
148
|
-
export interface CreateOrderResponse {
|
|
149
|
-
order: KeeperOrder;
|
|
150
|
-
error?: string;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
170
|
export interface ActionFunctionArgs {
|
|
154
171
|
actionTrait?: string;
|
|
155
172
|
tokenList?: Record<string, string>;
|
package/src/test/testMethods.ts
CHANGED
|
@@ -66,6 +66,25 @@ class BitflowSDKTest {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
public async testGetAllKeeperPossibleTokenYRoutes(
|
|
70
|
+
tokenXName: string,
|
|
71
|
+
tokenYName: string
|
|
72
|
+
): Promise<void> {
|
|
73
|
+
try {
|
|
74
|
+
console.log(`Fetching routes for ${tokenXName} to ${tokenYName}`);
|
|
75
|
+
const routes = await this.sdk.getAllKeeperPossibleTokenYRoutes(
|
|
76
|
+
tokenXName,
|
|
77
|
+
tokenYName
|
|
78
|
+
);
|
|
79
|
+
this.logRoutes(routes);
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error(
|
|
82
|
+
`Error fetching routes for ${tokenXName} to ${tokenYName}:`,
|
|
83
|
+
(error as Error).message
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
69
88
|
public async testGetQuoteForRoute(
|
|
70
89
|
tokenXName: string,
|
|
71
90
|
tokenYName: string,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const BitflowSDK_1 = require("./BitflowSDK");
|
|
5
|
-
const dotenv_1 = tslib_1.__importDefault(require("dotenv"));
|
|
6
|
-
dotenv_1.default.config();
|
|
7
|
-
async function testGetUser() {
|
|
8
|
-
console.log("Starting getUser Test...\n");
|
|
9
|
-
// Initialize SDK with environment variables
|
|
10
|
-
const sdk = new BitflowSDK_1.BitflowSDK({
|
|
11
|
-
BITFLOW_API_HOST: process.env.BITFLOW_API_HOST,
|
|
12
|
-
BITFLOW_API_KEY: process.env.BITFLOW_API_KEY,
|
|
13
|
-
READONLY_CALL_API_HOST: process.env.READONLY_CALL_API_HOST,
|
|
14
|
-
KEEPER_API_KEY: process.env.NEXT_PUBLIC_KEEPER_API_KEY,
|
|
15
|
-
KEEPER_API_HOST: process.env.KEEPER_API_HOST,
|
|
16
|
-
});
|
|
17
|
-
// Test case 1: Valid user
|
|
18
|
-
console.log("Test Case 1: Fetching a valid user");
|
|
19
|
-
try {
|
|
20
|
-
const stacksAddress = "SP3D03X5BHMNSAAW71NN7BQRMV4DW2G4JB3MZAGJ8";
|
|
21
|
-
console.log(`Fetching user data for address: ${stacksAddress}`);
|
|
22
|
-
const userResponse = await sdk.getUser(stacksAddress);
|
|
23
|
-
if (userResponse.user) {
|
|
24
|
-
console.log("\nUser data successfully retrieved:");
|
|
25
|
-
console.log(`Stack Address: ${userResponse.user.stacksAddress}`);
|
|
26
|
-
console.log(`Bitcoin Address: ${userResponse.user.bitcoinAddress}`);
|
|
27
|
-
console.log(`Creation Date: ${userResponse.user.creationDate}`);
|
|
28
|
-
console.log(`Last Updated: ${userResponse.user.lastUpdated}`);
|
|
29
|
-
// Log keeper contracts if any
|
|
30
|
-
const contractsCount = Object.keys(userResponse.user.keeperContracts).length;
|
|
31
|
-
console.log(`\nNumber of keeper contracts: ${contractsCount}`);
|
|
32
|
-
// Log keeper orders if any
|
|
33
|
-
const ordersCount = Object.keys(userResponse.user.keeperOrders).length;
|
|
34
|
-
console.log(`Number of keeper orders: ${ordersCount}`);
|
|
35
|
-
console.log("\n✅ Test Case 1: Passed");
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
console.log("\n❌ Test Case 1: Failed - No user data in response");
|
|
39
|
-
if (userResponse.error) {
|
|
40
|
-
console.error("Error:", userResponse.error);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
catch (error) {
|
|
45
|
-
console.error("\n❌ Test Case 1: Failed with error:", error);
|
|
46
|
-
}
|
|
47
|
-
// Test case 2: Invalid address
|
|
48
|
-
console.log("\nTest Case 2: Testing with invalid address");
|
|
49
|
-
try {
|
|
50
|
-
const invalidAddress = "SP000INVALID000ADDRESS";
|
|
51
|
-
console.log(`Attempting to fetch user data for invalid address: ${invalidAddress}`);
|
|
52
|
-
const userResponse = await sdk.getUser(invalidAddress);
|
|
53
|
-
console.log("Response:", userResponse);
|
|
54
|
-
}
|
|
55
|
-
catch (error) {
|
|
56
|
-
console.log("\n✅ Test Case 2: Passed - Properly handled invalid address");
|
|
57
|
-
console.log("Error message:", error.message);
|
|
58
|
-
}
|
|
59
|
-
// Test case 3: Empty address
|
|
60
|
-
console.log("\nTest Case 3: Testing with empty address");
|
|
61
|
-
try {
|
|
62
|
-
const emptyAddress = "";
|
|
63
|
-
console.log("Attempting to fetch user data with empty address");
|
|
64
|
-
const userResponse = await sdk.getUser(emptyAddress);
|
|
65
|
-
console.log("Response:", userResponse);
|
|
66
|
-
}
|
|
67
|
-
catch (error) {
|
|
68
|
-
console.log("\n✅ Test Case 3: Passed - Properly handled empty address");
|
|
69
|
-
console.log("Error message:", error.message);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
// Run the test
|
|
73
|
-
testGetUser()
|
|
74
|
-
.then(() => console.log("\nAll test cases completed"))
|
|
75
|
-
.catch(console.error)
|
|
76
|
-
.finally(() => console.log("\nTest execution finished"));
|
|
77
|
-
//# sourceMappingURL=test-get-user.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"test-get-user.js","sourceRoot":"","sources":["../../src/test-get-user.ts"],"names":[],"mappings":"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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|