@bitflowlabs/core-sdk 2.0.3 → 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/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/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 -83
- 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/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":";;;AAAA,6CAA0C;AAC1C,4DAA4B;AAE5B,gBAAM,CAAC,MAAM,EAAE,CAAC;AAEhB,KAAK,UAAU,WAAW;IACxB,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;IAE1C,4CAA4C;IAC5C,MAAM,GAAG,GAAG,IAAI,uBAAU,CAAC;QACzB,gBAAgB,EAAE,OAAO,CAAC,GAAG,CAAC,gBAAiB;QAC/C,eAAe,EAAE,OAAO,CAAC,GAAG,CAAC,eAAgB;QAC7C,sBAAsB,EAAE,OAAO,CAAC,GAAG,CAAC,sBAAuB;QAC3D,cAAc,EAAE,OAAO,CAAC,GAAG,CAAC,0BAA2B;QACvD,eAAe,EAAE,OAAO,CAAC,GAAG,CAAC,eAAgB;KAC9C,CAAC,CAAC;IAEH,0BAA0B;IAC1B,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;IAClD,IAAI,CAAC;QACH,MAAM,aAAa,GAAG,2CAA2C,CAAC;QAClE,OAAO,CAAC,GAAG,CAAC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OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,67 +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 testKeeperRoutes() {
|
|
8
|
-
var _a, _b;
|
|
9
|
-
const sdk = new BitflowSDK_1.BitflowSDK({
|
|
10
|
-
BITFLOW_API_HOST: process.env.BITFLOW_API_HOST,
|
|
11
|
-
BITFLOW_API_KEY: process.env.BITFLOW_API_KEY,
|
|
12
|
-
READONLY_CALL_API_HOST: process.env.READONLY_CALL_API_HOST,
|
|
13
|
-
});
|
|
14
|
-
console.log("Testing Keeper Routes Functionality...\n");
|
|
15
|
-
// Test 1: Regular routes (without keeper parameter)
|
|
16
|
-
console.log("1. Testing regular routes for token-aeusdc...");
|
|
17
|
-
try {
|
|
18
|
-
const regularRoutes = await sdk.getPossibleSwaps("token-stx");
|
|
19
|
-
console.log("Regular routes count:", Object.keys(regularRoutes).length);
|
|
20
|
-
console.log("Sample of regular routes:", JSON.stringify(Object.keys(regularRoutes).slice(0, 3), null, 2));
|
|
21
|
-
}
|
|
22
|
-
catch (error) {
|
|
23
|
-
console.error("Error fetching regular routes:", error);
|
|
24
|
-
}
|
|
25
|
-
console.log("----------------------------------------\n");
|
|
26
|
-
// Test 2: Keeper routes
|
|
27
|
-
console.log("2. Testing keeper routes for token-aeusdc...");
|
|
28
|
-
try {
|
|
29
|
-
const keeperRoutes = await sdk.getKeeperPossibleSwaps("token-stx");
|
|
30
|
-
console.log("Keeper routes count:", Object.keys(keeperRoutes).length);
|
|
31
|
-
console.log("Sample of keeper routes:", JSON.stringify(Object.keys(keeperRoutes).slice(0, 3), null, 2));
|
|
32
|
-
}
|
|
33
|
-
catch (error) {
|
|
34
|
-
console.error("Error fetching keeper routes:", error);
|
|
35
|
-
}
|
|
36
|
-
console.log("----------------------------------------\n");
|
|
37
|
-
// Test 3: Compare routes
|
|
38
|
-
console.log("3. Comparing regular vs keeper routes...");
|
|
39
|
-
try {
|
|
40
|
-
const regularRoutes = await sdk.getPossibleSwaps("token-stx");
|
|
41
|
-
const keeperRoutes = await sdk.getKeeperPossibleSwaps("token-stx");
|
|
42
|
-
console.log("Regular routes count:", Object.keys(regularRoutes).length);
|
|
43
|
-
console.log("Keeper routes count:", Object.keys(keeperRoutes).length);
|
|
44
|
-
// Compare the first route's structure
|
|
45
|
-
const firstRegularTokenY = Object.keys(regularRoutes)[0];
|
|
46
|
-
const firstKeeperTokenY = Object.keys(keeperRoutes)[0];
|
|
47
|
-
if (firstRegularTokenY && firstKeeperTokenY) {
|
|
48
|
-
console.log("\nSample Regular Route Structure:", {
|
|
49
|
-
tokenY: firstRegularTokenY,
|
|
50
|
-
routeCount: regularRoutes[firstRegularTokenY].length,
|
|
51
|
-
firstRouteDexPath: (_a = regularRoutes[firstRegularTokenY][0]) === null || _a === void 0 ? void 0 : _a.dex_path,
|
|
52
|
-
});
|
|
53
|
-
console.log("\nSample Keeper Route Structure:", {
|
|
54
|
-
tokenY: firstKeeperTokenY,
|
|
55
|
-
routeCount: keeperRoutes[firstKeeperTokenY].length,
|
|
56
|
-
firstRouteDexPath: (_b = keeperRoutes[firstKeeperTokenY][0]) === null || _b === void 0 ? void 0 : _b.dex_path,
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
catch (error) {
|
|
61
|
-
console.error("Error comparing routes:", error);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
testKeeperRoutes()
|
|
65
|
-
.then(() => console.log("\nAll tests completed"))
|
|
66
|
-
.catch(console.error);
|
|
67
|
-
//# sourceMappingURL=test-keeper-routes.js.map
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,kBAAkB;gBAC1B,UAAU,EAAE,aAAa,CAAC,kBAAkB,CAAC,CAAC,MAAM;gBACpD,iBAAiB,EAAE,MAAA,aAAa,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,0CAAE,QAAQ;aAClE,CAAC,CAAC;YAEH,OAAO,CAAC,GAAG,CAAC,kCAAkC,EAAE;gBAC9C,MAAM,EAAE,iBAAiB;gBACzB,UAAU,EAAE,YAAY,CAAC,iBAAiB,CAAC,CAAC,MAAM;gBAClD,iBAAiB,EAAE,MAAA,YAAY,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,0CAAE,QAAQ;aAChE,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;IAClD,CAAC;AACH,CAAC;AAED,gBAAgB,EAAE;KACf,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;KAChD,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC"}
|
package/dist/src/test-order.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/src/test-order.js
DELETED
|
@@ -1,71 +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 types_1 = require("./keeper/types");
|
|
6
|
-
const dotenv_1 = tslib_1.__importDefault(require("dotenv"));
|
|
7
|
-
dotenv_1.default.config();
|
|
8
|
-
async function testCreateOrder() {
|
|
9
|
-
console.log("Starting Order Creation Test...\n");
|
|
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.KEEPER_API_KEY,
|
|
15
|
-
});
|
|
16
|
-
try {
|
|
17
|
-
// First get a keeper contract
|
|
18
|
-
console.log("Getting keeper contract...");
|
|
19
|
-
const keeperContractResponse = await sdk.getOrCreateKeeperContract({
|
|
20
|
-
stacksAddress: "SP228WEAEMYX21RW0TT5T38THPNDYPPGGVW2RP570",
|
|
21
|
-
keeperType: types_1.KeeperType.MULTI_ACTION_V1,
|
|
22
|
-
allActionsApproved: true,
|
|
23
|
-
});
|
|
24
|
-
if (!keeperContractResponse.keeperContract.contractIdentifier) {
|
|
25
|
-
throw new Error("Failed to get keeper contract identifier");
|
|
26
|
-
}
|
|
27
|
-
console.log("\nCreating order with the following parameters:");
|
|
28
|
-
const orderParams = {
|
|
29
|
-
stacksAddress: "SP228WEAEMYX21RW0TT5T38THPNDYPPGGVW2RP570",
|
|
30
|
-
keeperType: types_1.KeeperType.MULTI_ACTION_V1,
|
|
31
|
-
contractIdentifier: keeperContractResponse.keeperContract.contractIdentifier,
|
|
32
|
-
actionAmount: "100000000", // 1 BTC
|
|
33
|
-
feeRecipient: "SP16BPKS1DN5AYQ5MDHFEYXTSP352QG6JS2E0N8YP",
|
|
34
|
-
actionType: types_1.ActionType.SWAP_XYK_SWAP_HELPER,
|
|
35
|
-
bitcoinTxId: "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
|
|
36
|
-
minReceived: {
|
|
37
|
-
amount: "0",
|
|
38
|
-
autoAdjust: true,
|
|
39
|
-
},
|
|
40
|
-
actionAggregatorTokens: {
|
|
41
|
-
tokenXId: "token-pbtc",
|
|
42
|
-
tokenYId: "token-stx",
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
console.log("Order Parameters:", JSON.stringify(orderParams, null, 2));
|
|
46
|
-
console.log("\nSubmitting order...");
|
|
47
|
-
const createOrderResponse = await sdk.createOrder(orderParams);
|
|
48
|
-
console.log("\nOrder Creation Response:", JSON.stringify(createOrderResponse, null, 2));
|
|
49
|
-
if (createOrderResponse.keeperOrder) {
|
|
50
|
-
console.log("\n✅ Order created successfully!");
|
|
51
|
-
console.log(`Order ID: ${createOrderResponse.keeperOrder.orderId}`);
|
|
52
|
-
console.log(`Status: ${createOrderResponse.keeperOrder.orderStatus}`);
|
|
53
|
-
console.log(`Creation Date: ${createOrderResponse.keeperOrder.creationDate}`);
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
console.log("\n❌ Failed to create order");
|
|
57
|
-
if (createOrderResponse.error) {
|
|
58
|
-
console.error("Error:", createOrderResponse.error);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
catch (error) {
|
|
63
|
-
console.error("\n❌ Test failed with error:", error);
|
|
64
|
-
throw error;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
// Run the test
|
|
68
|
-
testCreateOrder()
|
|
69
|
-
.then(() => console.log("\nTest execution completed"))
|
|
70
|
-
.catch(console.error);
|
|
71
|
-
//# sourceMappingURL=test-order.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"test-order.js","sourceRoot":"","sources":["../../src/test-order.ts"],"names":[],"mappings":";;;AAAA,6CAA0C;AAC1C,0CAA2E;AAC3E,4DAA4B;AAE5B,gBAAM,CAAC,MAAM,EAAE,CAAC;AAEhB,KAAK,UAAU,eAAe;IAC5B,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;IAEjD,MAAM,GAAG,GAAG,IAAI,uBAAU,CAAC;QACzB,gBAAgB,EAAE,OAAO,CAAC,GAAG,CAAC,gBAAiB;QAC/C,eAAe,EAAE,OAAO,CAAC,GAAG,CAAC,eAAgB;QAC7C,sBAAsB,EAAE,OAAO,CAAC,GAAG,CAAC,sBAAuB;QAC3D,cAAc,EAAE,OAAO,CAAC,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