@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
package/dist/src/BitflowSDK.js
CHANGED
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.BitflowSDK = void 0;
|
|
36
|
+
exports.BitflowSDK = exports.safeStringify = void 0;
|
|
37
37
|
const network_1 = require("@stacks/network");
|
|
38
38
|
const fetchDataHelper_1 = require("./helpers/fetchDataHelper");
|
|
39
39
|
const callSwapHelper_1 = require("./helpers/callSwapHelper");
|
|
@@ -43,6 +43,10 @@ const getContractInterfaceAndFunction_1 = require("./helpers/getContractInterfac
|
|
|
43
43
|
const config_1 = require("./config");
|
|
44
44
|
const callGetSwapParams_1 = require("./helpers/callGetSwapParams");
|
|
45
45
|
const keeperAPI_1 = require("./keeper/keeperAPI");
|
|
46
|
+
const safeStringify = (obj, indent = 2) => {
|
|
47
|
+
return JSON.stringify(obj, (_, value) => (typeof value === 'bigint' ? value.toString() + 'n' : value), indent);
|
|
48
|
+
};
|
|
49
|
+
exports.safeStringify = safeStringify;
|
|
46
50
|
class BitflowSDK {
|
|
47
51
|
constructor(config) {
|
|
48
52
|
if (config)
|
|
@@ -58,19 +62,19 @@ class BitflowSDK {
|
|
|
58
62
|
this.initializeContext();
|
|
59
63
|
}
|
|
60
64
|
async loadConnectDependencies() {
|
|
61
|
-
if (typeof window ===
|
|
62
|
-
throw new Error(
|
|
65
|
+
if (typeof window === 'undefined') {
|
|
66
|
+
throw new Error('Connect features are only available in browser environments');
|
|
63
67
|
}
|
|
64
68
|
try {
|
|
65
|
-
const { getStacksProvider } = await Promise.resolve().then(() => __importStar(require(
|
|
69
|
+
const { getStacksProvider } = await Promise.resolve().then(() => __importStar(require('@stacks/connect')));
|
|
66
70
|
if (!this.stacksProvider) {
|
|
67
71
|
this.stacksProvider = await getStacksProvider();
|
|
68
72
|
}
|
|
69
73
|
return this.stacksProvider;
|
|
70
74
|
}
|
|
71
75
|
catch (error) {
|
|
72
|
-
console.error(
|
|
73
|
-
throw new Error(
|
|
76
|
+
console.error('Error loading Stacks Connect:', error);
|
|
77
|
+
throw new Error('Failed to load Stacks Connect dependencies');
|
|
74
78
|
}
|
|
75
79
|
}
|
|
76
80
|
async initializeContext() {
|
|
@@ -98,7 +102,7 @@ class BitflowSDK {
|
|
|
98
102
|
// Use a separate cache key for keeper routes
|
|
99
103
|
const cacheKey = `keeper_${tokenX}`;
|
|
100
104
|
if (!this.context.swapOptions[cacheKey]) {
|
|
101
|
-
this.context.swapOptions[cacheKey] = await (0, fetchPossibleSwap_1.fetchPossibleSwapsFromAPI)(tokenX,
|
|
105
|
+
this.context.swapOptions[cacheKey] = await (0, fetchPossibleSwap_1.fetchPossibleSwapsFromAPI)(tokenX, 'KEEPER');
|
|
102
106
|
}
|
|
103
107
|
return this.context.swapOptions[cacheKey];
|
|
104
108
|
}
|
|
@@ -134,40 +138,40 @@ class BitflowSDK {
|
|
|
134
138
|
console.warn(`Skipping route ${routeIndex + 1} due to missing required properties:`, route.quoteData);
|
|
135
139
|
continue;
|
|
136
140
|
}
|
|
137
|
-
const [contractDeployer, contractName] = contract.split(
|
|
141
|
+
const [contractDeployer, contractName] = contract.split('.');
|
|
138
142
|
if (!this.context.contractInterfaces[contract]) {
|
|
139
143
|
this.context.contractInterfaces[contract] =
|
|
140
144
|
await (0, getContractInterfaceAndFunction_1.getContractInterfaceAndFunction)(contractDeployer, contractName, functionName);
|
|
141
145
|
}
|
|
142
146
|
const { interface: contractInterface, functionArgs } = this.context.contractInterfaces[contract];
|
|
143
147
|
const params = { ...parameters };
|
|
144
|
-
if (
|
|
148
|
+
if ('dx' in params && params.dx === null) {
|
|
145
149
|
params.dx = amountInput;
|
|
146
150
|
}
|
|
147
|
-
else if (
|
|
151
|
+
else if ('dy' in params && params.dy === null) {
|
|
148
152
|
params.dy = amountInput;
|
|
149
153
|
}
|
|
150
|
-
else if (
|
|
154
|
+
else if ('amount' in params && params.amount === null) {
|
|
151
155
|
params.amount = amountInput;
|
|
152
156
|
}
|
|
153
|
-
else if (
|
|
154
|
-
params[
|
|
157
|
+
else if ('amt-in' in params && params['amt-in'] === null) {
|
|
158
|
+
params['amt-in'] = amountInput;
|
|
155
159
|
}
|
|
156
|
-
else if (
|
|
157
|
-
params[
|
|
160
|
+
else if ('amt-in-max' in params && params['amt-in-max'] === null) {
|
|
161
|
+
params['amt-in-max'] = amountInput;
|
|
158
162
|
}
|
|
159
|
-
else if (
|
|
160
|
-
params[
|
|
161
|
-
params[
|
|
163
|
+
else if ('y-amount' in params && params['y-amount'] === null) {
|
|
164
|
+
params['y-amount'] = amountInput;
|
|
165
|
+
params['x-amount'] = amountInput;
|
|
162
166
|
}
|
|
163
|
-
else if (
|
|
164
|
-
params[
|
|
167
|
+
else if ('x-amount' in params && params['x-amount'] === null) {
|
|
168
|
+
params['x-amount'] = amountInput;
|
|
165
169
|
}
|
|
166
170
|
else {
|
|
167
171
|
params.dx = amountInput;
|
|
168
172
|
}
|
|
169
173
|
const { convertedResult, rawResult, tokenXDecimals, tokenYDecimals } = await (0, callReadOnlyHelper_1.callReadOnlyFunctionHelper)(contractDeployer, contractName, functionName, params, contractDeployer, tokenX, tokenY, route.swapData, this.context);
|
|
170
|
-
if (typeof convertedResult ===
|
|
174
|
+
if (typeof convertedResult === 'number' && convertedResult > 0) {
|
|
171
175
|
const updatedQuoteData = {
|
|
172
176
|
...route.quoteData,
|
|
173
177
|
parameters: { ...params },
|
|
@@ -178,63 +182,63 @@ class BitflowSDK {
|
|
|
178
182
|
...route.swapData.parameters,
|
|
179
183
|
amount: params.amount ||
|
|
180
184
|
params.dx ||
|
|
181
|
-
params[
|
|
182
|
-
params[
|
|
183
|
-
params[
|
|
184
|
-
params[
|
|
185
|
+
params['amt-in'] ||
|
|
186
|
+
params['amt-in-max'] ||
|
|
187
|
+
params['y-amount'] ||
|
|
188
|
+
params['x-amount'] ||
|
|
185
189
|
params.dy,
|
|
186
190
|
dx: params.amount ||
|
|
187
191
|
params.dx ||
|
|
188
|
-
params[
|
|
189
|
-
params[
|
|
190
|
-
params[
|
|
191
|
-
params[
|
|
192
|
+
params['amt-in'] ||
|
|
193
|
+
params['amt-in-max'] ||
|
|
194
|
+
params['y-amount'] ||
|
|
195
|
+
params['x-amount'] ||
|
|
192
196
|
params.dy,
|
|
193
197
|
dy: params.amount ||
|
|
194
198
|
params.dx ||
|
|
195
|
-
params[
|
|
196
|
-
params[
|
|
197
|
-
params[
|
|
198
|
-
params[
|
|
199
|
+
params['amt-in'] ||
|
|
200
|
+
params['amt-in-max'] ||
|
|
201
|
+
params['y-amount'] ||
|
|
202
|
+
params['x-amount'] ||
|
|
199
203
|
params.dy,
|
|
200
|
-
|
|
204
|
+
'amt-in': params.amount ||
|
|
201
205
|
params.dx ||
|
|
202
|
-
params[
|
|
203
|
-
params[
|
|
204
|
-
params[
|
|
205
|
-
params[
|
|
206
|
+
params['amt-in'] ||
|
|
207
|
+
params['amt-in-max'] ||
|
|
208
|
+
params['y-amount'] ||
|
|
209
|
+
params['x-amount'] ||
|
|
206
210
|
params.dy,
|
|
207
|
-
|
|
211
|
+
'amt-in-max': params.amount ||
|
|
208
212
|
params.dx ||
|
|
209
|
-
params[
|
|
210
|
-
params[
|
|
211
|
-
params[
|
|
212
|
-
params[
|
|
213
|
+
params['amt-in'] ||
|
|
214
|
+
params['amt-in-max'] ||
|
|
215
|
+
params['y-amount'] ||
|
|
216
|
+
params['x-amount'] ||
|
|
213
217
|
params.dy,
|
|
214
|
-
|
|
218
|
+
'y-amount': params.amount ||
|
|
215
219
|
params.dx ||
|
|
216
|
-
params[
|
|
217
|
-
params[
|
|
218
|
-
params[
|
|
219
|
-
params[
|
|
220
|
+
params['amt-in'] ||
|
|
221
|
+
params['amt-in-max'] ||
|
|
222
|
+
params['y-amount'] ||
|
|
223
|
+
params['x-amount'] ||
|
|
220
224
|
params.dy,
|
|
221
|
-
|
|
225
|
+
'x-amount': params.amount ||
|
|
222
226
|
params.dx ||
|
|
223
|
-
params[
|
|
224
|
-
params[
|
|
225
|
-
params[
|
|
226
|
-
params[
|
|
227
|
+
params['amt-in'] ||
|
|
228
|
+
params['amt-in-max'] ||
|
|
229
|
+
params['y-amount'] ||
|
|
230
|
+
params['x-amount'] ||
|
|
227
231
|
params.dy,
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
232
|
+
'min-received': rawResult,
|
|
233
|
+
'min-dy': rawResult,
|
|
234
|
+
'min-dz': rawResult,
|
|
235
|
+
'min-dw': rawResult,
|
|
236
|
+
'amt-out': rawResult,
|
|
237
|
+
'amt-out-min': rawResult,
|
|
238
|
+
'min-x-amount': rawResult,
|
|
239
|
+
'min-dv': rawResult,
|
|
240
|
+
'min-y-amount': rawResult,
|
|
241
|
+
'min-dx': rawResult,
|
|
238
242
|
},
|
|
239
243
|
};
|
|
240
244
|
const quoteResult = {
|
|
@@ -255,7 +259,7 @@ class BitflowSDK {
|
|
|
255
259
|
allRoutes.push(quoteResult);
|
|
256
260
|
}
|
|
257
261
|
else {
|
|
258
|
-
throw new Error(
|
|
262
|
+
throw new Error('Invalid quote result');
|
|
259
263
|
}
|
|
260
264
|
}
|
|
261
265
|
catch (error) {
|
|
@@ -287,8 +291,8 @@ class BitflowSDK {
|
|
|
287
291
|
async getKeeperQuoteForRoute(tokenX, tokenY, amountInput) {
|
|
288
292
|
var _a;
|
|
289
293
|
const COMPATIBLE_DEX_PATHS = new Set([
|
|
290
|
-
|
|
291
|
-
|
|
294
|
+
'BITFLOW_STABLE_XY_2',
|
|
295
|
+
'BITFLOW_XYK_XY_2',
|
|
292
296
|
]);
|
|
293
297
|
const isCompatibleRoute = (dexPath) => {
|
|
294
298
|
return dexPath.every((path) => COMPATIBLE_DEX_PATHS.has(path));
|
|
@@ -308,40 +312,40 @@ class BitflowSDK {
|
|
|
308
312
|
console.warn(`Skipping route ${routeIndex + 1} due to missing required properties:`, route.quoteData);
|
|
309
313
|
continue;
|
|
310
314
|
}
|
|
311
|
-
const [contractDeployer, contractName] = contract.split(
|
|
315
|
+
const [contractDeployer, contractName] = contract.split('.');
|
|
312
316
|
if (!this.context.contractInterfaces[contract]) {
|
|
313
317
|
this.context.contractInterfaces[contract] =
|
|
314
318
|
await (0, getContractInterfaceAndFunction_1.getContractInterfaceAndFunction)(contractDeployer, contractName, functionName);
|
|
315
319
|
}
|
|
316
320
|
const { interface: contractInterface, functionArgs } = this.context.contractInterfaces[contract];
|
|
317
321
|
const params = { ...parameters };
|
|
318
|
-
if (
|
|
322
|
+
if ('dx' in params && params.dx === null) {
|
|
319
323
|
params.dx = amountInput;
|
|
320
324
|
}
|
|
321
|
-
else if (
|
|
325
|
+
else if ('dy' in params && params.dy === null) {
|
|
322
326
|
params.dy = amountInput;
|
|
323
327
|
}
|
|
324
|
-
else if (
|
|
328
|
+
else if ('amount' in params && params.amount === null) {
|
|
325
329
|
params.amount = amountInput;
|
|
326
330
|
}
|
|
327
|
-
else if (
|
|
328
|
-
params[
|
|
331
|
+
else if ('amt-in' in params && params['amt-in'] === null) {
|
|
332
|
+
params['amt-in'] = amountInput;
|
|
329
333
|
}
|
|
330
|
-
else if (
|
|
331
|
-
params[
|
|
334
|
+
else if ('amt-in-max' in params && params['amt-in-max'] === null) {
|
|
335
|
+
params['amt-in-max'] = amountInput;
|
|
332
336
|
}
|
|
333
|
-
else if (
|
|
334
|
-
params[
|
|
335
|
-
params[
|
|
337
|
+
else if ('y-amount' in params && params['y-amount'] === null) {
|
|
338
|
+
params['y-amount'] = amountInput;
|
|
339
|
+
params['x-amount'] = amountInput;
|
|
336
340
|
}
|
|
337
|
-
else if (
|
|
338
|
-
params[
|
|
341
|
+
else if ('x-amount' in params && params['x-amount'] === null) {
|
|
342
|
+
params['x-amount'] = amountInput;
|
|
339
343
|
}
|
|
340
344
|
else {
|
|
341
345
|
params.dx = amountInput;
|
|
342
346
|
}
|
|
343
347
|
const { convertedResult, rawResult, tokenXDecimals, tokenYDecimals } = await (0, callReadOnlyHelper_1.callReadOnlyFunctionHelper)(contractDeployer, contractName, functionName, params, contractDeployer, tokenX, tokenY, route.swapData, this.context);
|
|
344
|
-
if (typeof convertedResult ===
|
|
348
|
+
if (typeof convertedResult === 'number' && convertedResult > 0) {
|
|
345
349
|
const updatedQuoteData = {
|
|
346
350
|
...route.quoteData,
|
|
347
351
|
parameters: { ...params },
|
|
@@ -352,56 +356,56 @@ class BitflowSDK {
|
|
|
352
356
|
...route.swapData.parameters,
|
|
353
357
|
amount: params.amount ||
|
|
354
358
|
params.dx ||
|
|
355
|
-
params[
|
|
356
|
-
params[
|
|
357
|
-
params[
|
|
358
|
-
params[
|
|
359
|
+
params['amt-in'] ||
|
|
360
|
+
params['amt-in-max'] ||
|
|
361
|
+
params['y-amount'] ||
|
|
362
|
+
params['x-amount'] ||
|
|
359
363
|
params.dy,
|
|
360
364
|
dx: params.amount ||
|
|
361
365
|
params.dx ||
|
|
362
|
-
params[
|
|
363
|
-
params[
|
|
364
|
-
params[
|
|
365
|
-
params[
|
|
366
|
+
params['amt-in'] ||
|
|
367
|
+
params['amt-in-max'] ||
|
|
368
|
+
params['y-amount'] ||
|
|
369
|
+
params['x-amount'] ||
|
|
366
370
|
params.dy,
|
|
367
|
-
|
|
371
|
+
'amt-in': params.amount ||
|
|
368
372
|
params.dx ||
|
|
369
|
-
params[
|
|
370
|
-
params[
|
|
371
|
-
params[
|
|
372
|
-
params[
|
|
373
|
+
params['amt-in'] ||
|
|
374
|
+
params['amt-in-max'] ||
|
|
375
|
+
params['y-amount'] ||
|
|
376
|
+
params['x-amount'] ||
|
|
373
377
|
params.dy,
|
|
374
|
-
|
|
378
|
+
'amt-in-max': params.amount ||
|
|
375
379
|
params.dx ||
|
|
376
|
-
params[
|
|
377
|
-
params[
|
|
378
|
-
params[
|
|
379
|
-
params[
|
|
380
|
+
params['amt-in'] ||
|
|
381
|
+
params['amt-in-max'] ||
|
|
382
|
+
params['y-amount'] ||
|
|
383
|
+
params['x-amount'] ||
|
|
380
384
|
params.dy,
|
|
381
|
-
|
|
385
|
+
'y-amount': params.amount ||
|
|
382
386
|
params.dx ||
|
|
383
|
-
params[
|
|
384
|
-
params[
|
|
385
|
-
params[
|
|
386
|
-
params[
|
|
387
|
+
params['amt-in'] ||
|
|
388
|
+
params['amt-in-max'] ||
|
|
389
|
+
params['y-amount'] ||
|
|
390
|
+
params['x-amount'] ||
|
|
387
391
|
params.dy,
|
|
388
|
-
|
|
392
|
+
'x-amount': params.amount ||
|
|
389
393
|
params.dx ||
|
|
390
|
-
params[
|
|
391
|
-
params[
|
|
392
|
-
params[
|
|
393
|
-
params[
|
|
394
|
+
params['amt-in'] ||
|
|
395
|
+
params['amt-in-max'] ||
|
|
396
|
+
params['y-amount'] ||
|
|
397
|
+
params['x-amount'] ||
|
|
394
398
|
params.dy,
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
399
|
+
'min-received': rawResult,
|
|
400
|
+
'min-dy': rawResult,
|
|
401
|
+
'min-dz': rawResult,
|
|
402
|
+
'min-dw': rawResult,
|
|
403
|
+
'amt-out': rawResult,
|
|
404
|
+
'amt-out-min': rawResult,
|
|
405
|
+
'min-x-amount': rawResult,
|
|
406
|
+
'min-dv': rawResult,
|
|
407
|
+
'min-y-amount': rawResult,
|
|
408
|
+
'min-dx': rawResult,
|
|
405
409
|
},
|
|
406
410
|
};
|
|
407
411
|
const quoteResult = {
|
|
@@ -422,7 +426,174 @@ class BitflowSDK {
|
|
|
422
426
|
allRoutes.push(quoteResult);
|
|
423
427
|
}
|
|
424
428
|
else {
|
|
425
|
-
throw new Error(
|
|
429
|
+
throw new Error('Invalid quote result');
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
catch (error) {
|
|
433
|
+
console.warn(`Failed to get quote for route ${routeIndex + 1}:`, route, error);
|
|
434
|
+
allRoutes.push({
|
|
435
|
+
route,
|
|
436
|
+
quote: null,
|
|
437
|
+
params: route.quoteData
|
|
438
|
+
? { ...route.quoteData.parameters, amountInput }
|
|
439
|
+
: { amountInput },
|
|
440
|
+
quoteData: route.quoteData,
|
|
441
|
+
swapData: route.swapData,
|
|
442
|
+
dexPath: route.dex_path,
|
|
443
|
+
tokenPath: route.token_path,
|
|
444
|
+
tokenXDecimals: route.tokenXDecimals,
|
|
445
|
+
tokenYDecimals: route.tokenYDecimals,
|
|
446
|
+
error: error.message,
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
allRoutes.sort((a, b) => (b.quote || 0) - (a.quote || 0));
|
|
451
|
+
const result = {
|
|
452
|
+
bestRoute: ((_a = allRoutes[0]) === null || _a === void 0 ? void 0 : _a.quote) !== null ? allRoutes[0] : null,
|
|
453
|
+
allRoutes,
|
|
454
|
+
inputData: { tokenX, tokenY, amountInput },
|
|
455
|
+
};
|
|
456
|
+
return result;
|
|
457
|
+
}
|
|
458
|
+
async getKeeperQuoteForRouteWithoutScaling(tokenX, tokenY, amountInput) {
|
|
459
|
+
var _a;
|
|
460
|
+
const COMPATIBLE_DEX_PATHS = new Set([
|
|
461
|
+
'BITFLOW_STABLE_XY_2',
|
|
462
|
+
'BITFLOW_XYK_XY_2',
|
|
463
|
+
]);
|
|
464
|
+
const isCompatibleRoute = (dexPath) => {
|
|
465
|
+
return dexPath.every((path) => COMPATIBLE_DEX_PATHS.has(path));
|
|
466
|
+
};
|
|
467
|
+
let routes = await this.getAllPossibleTokenYRoutes(tokenX, tokenY);
|
|
468
|
+
routes = routes.filter((route) => isCompatibleRoute(route.dex_path));
|
|
469
|
+
const allRoutes = [];
|
|
470
|
+
for (let routeIndex = 0; routeIndex < routes.length; routeIndex++) {
|
|
471
|
+
const route = routes[routeIndex];
|
|
472
|
+
try {
|
|
473
|
+
if (!route.quoteData) {
|
|
474
|
+
console.warn(`Skipping route ${routeIndex + 1} due to null quoteData:`, route);
|
|
475
|
+
continue;
|
|
476
|
+
}
|
|
477
|
+
const { contract, function: functionName, parameters, } = route.quoteData;
|
|
478
|
+
if (!contract || !functionName || !parameters) {
|
|
479
|
+
console.warn(`Skipping route ${routeIndex + 1} due to missing required properties:`, route.quoteData);
|
|
480
|
+
continue;
|
|
481
|
+
}
|
|
482
|
+
const [contractDeployer, contractName] = contract.split('.');
|
|
483
|
+
if (!this.context.contractInterfaces[contract]) {
|
|
484
|
+
this.context.contractInterfaces[contract] =
|
|
485
|
+
await (0, getContractInterfaceAndFunction_1.getContractInterfaceAndFunction)(contractDeployer, contractName, functionName);
|
|
486
|
+
}
|
|
487
|
+
const { interface: contractInterface, functionArgs } = this.context.contractInterfaces[contract];
|
|
488
|
+
const params = { ...parameters };
|
|
489
|
+
if ('dx' in params && params.dx === null) {
|
|
490
|
+
params.dx = amountInput;
|
|
491
|
+
}
|
|
492
|
+
else if ('dy' in params && params.dy === null) {
|
|
493
|
+
params.dy = amountInput;
|
|
494
|
+
}
|
|
495
|
+
else if ('amount' in params && params.amount === null) {
|
|
496
|
+
params.amount = amountInput;
|
|
497
|
+
}
|
|
498
|
+
else if ('amt-in' in params && params['amt-in'] === null) {
|
|
499
|
+
params['amt-in'] = amountInput;
|
|
500
|
+
}
|
|
501
|
+
else if ('amt-in-max' in params && params['amt-in-max'] === null) {
|
|
502
|
+
params['amt-in-max'] = amountInput;
|
|
503
|
+
}
|
|
504
|
+
else if ('y-amount' in params && params['y-amount'] === null) {
|
|
505
|
+
params['y-amount'] = amountInput;
|
|
506
|
+
params['x-amount'] = amountInput;
|
|
507
|
+
}
|
|
508
|
+
else if ('x-amount' in params && params['x-amount'] === null) {
|
|
509
|
+
params['x-amount'] = amountInput;
|
|
510
|
+
}
|
|
511
|
+
else {
|
|
512
|
+
params.dx = amountInput;
|
|
513
|
+
}
|
|
514
|
+
const { convertedResult, rawResult, tokenXDecimals, tokenYDecimals } = await (0, callReadOnlyHelper_1.callReadOnlyFunctionHelperWithoutScaling)(contractDeployer, contractName, functionName, params, contractDeployer, tokenX, tokenY, route.swapData, this.context);
|
|
515
|
+
if (typeof convertedResult === 'number' && convertedResult > 0) {
|
|
516
|
+
const updatedQuoteData = {
|
|
517
|
+
...route.quoteData,
|
|
518
|
+
parameters: { ...params },
|
|
519
|
+
};
|
|
520
|
+
const updatedSwapData = {
|
|
521
|
+
...route.swapData,
|
|
522
|
+
parameters: {
|
|
523
|
+
...route.swapData.parameters,
|
|
524
|
+
amount: params.amount ||
|
|
525
|
+
params.dx ||
|
|
526
|
+
params['amt-in'] ||
|
|
527
|
+
params['amt-in-max'] ||
|
|
528
|
+
params['y-amount'] ||
|
|
529
|
+
params['x-amount'] ||
|
|
530
|
+
params.dy,
|
|
531
|
+
dx: params.amount ||
|
|
532
|
+
params.dx ||
|
|
533
|
+
params['amt-in'] ||
|
|
534
|
+
params['amt-in-max'] ||
|
|
535
|
+
params['y-amount'] ||
|
|
536
|
+
params['x-amount'] ||
|
|
537
|
+
params.dy,
|
|
538
|
+
'amt-in': params.amount ||
|
|
539
|
+
params.dx ||
|
|
540
|
+
params['amt-in'] ||
|
|
541
|
+
params['amt-in-max'] ||
|
|
542
|
+
params['y-amount'] ||
|
|
543
|
+
params['x-amount'] ||
|
|
544
|
+
params.dy,
|
|
545
|
+
'amt-in-max': params.amount ||
|
|
546
|
+
params.dx ||
|
|
547
|
+
params['amt-in'] ||
|
|
548
|
+
params['amt-in-max'] ||
|
|
549
|
+
params['y-amount'] ||
|
|
550
|
+
params['x-amount'] ||
|
|
551
|
+
params.dy,
|
|
552
|
+
'y-amount': params.amount ||
|
|
553
|
+
params.dx ||
|
|
554
|
+
params['amt-in'] ||
|
|
555
|
+
params['amt-in-max'] ||
|
|
556
|
+
params['y-amount'] ||
|
|
557
|
+
params['x-amount'] ||
|
|
558
|
+
params.dy,
|
|
559
|
+
'x-amount': params.amount ||
|
|
560
|
+
params.dx ||
|
|
561
|
+
params['amt-in'] ||
|
|
562
|
+
params['amt-in-max'] ||
|
|
563
|
+
params['y-amount'] ||
|
|
564
|
+
params['x-amount'] ||
|
|
565
|
+
params.dy,
|
|
566
|
+
'min-received': rawResult,
|
|
567
|
+
'min-dy': rawResult,
|
|
568
|
+
'min-dz': rawResult,
|
|
569
|
+
'min-dw': rawResult,
|
|
570
|
+
'amt-out': rawResult,
|
|
571
|
+
'amt-out-min': rawResult,
|
|
572
|
+
'min-x-amount': rawResult,
|
|
573
|
+
'min-dv': rawResult,
|
|
574
|
+
'min-y-amount': rawResult,
|
|
575
|
+
'min-dx': rawResult,
|
|
576
|
+
},
|
|
577
|
+
};
|
|
578
|
+
const quoteResult = {
|
|
579
|
+
route: {
|
|
580
|
+
...route,
|
|
581
|
+
quoteData: updatedQuoteData,
|
|
582
|
+
swapData: updatedSwapData,
|
|
583
|
+
},
|
|
584
|
+
quote: convertedResult,
|
|
585
|
+
params: params,
|
|
586
|
+
quoteData: updatedQuoteData,
|
|
587
|
+
swapData: updatedSwapData,
|
|
588
|
+
dexPath: route.dex_path,
|
|
589
|
+
tokenPath: route.token_path,
|
|
590
|
+
tokenXDecimals: tokenXDecimals,
|
|
591
|
+
tokenYDecimals: tokenYDecimals,
|
|
592
|
+
};
|
|
593
|
+
allRoutes.push(quoteResult);
|
|
594
|
+
}
|
|
595
|
+
else {
|
|
596
|
+
throw new Error('Invalid quote result');
|
|
426
597
|
}
|
|
427
598
|
}
|
|
428
599
|
catch (error) {
|
|
@@ -462,37 +633,37 @@ class BitflowSDK {
|
|
|
462
633
|
...route.swapData.parameters,
|
|
463
634
|
amount: route.swapData.parameters.amount ||
|
|
464
635
|
amount ||
|
|
465
|
-
route.swapData.parameters[
|
|
466
|
-
route.swapData.parameters[
|
|
467
|
-
route.swapData.parameters[
|
|
636
|
+
route.swapData.parameters['amt-in'] ||
|
|
637
|
+
route.swapData.parameters['amt-in-max'] ||
|
|
638
|
+
route.swapData.parameters['y-amount'],
|
|
468
639
|
dx: route.swapData.parameters.dx ||
|
|
469
640
|
amount ||
|
|
470
|
-
route.swapData.parameters[
|
|
471
|
-
route.swapData.parameters[
|
|
472
|
-
route.swapData.parameters[
|
|
473
|
-
|
|
641
|
+
route.swapData.parameters['amt-in'] ||
|
|
642
|
+
route.swapData.parameters['amt-in-max'] ||
|
|
643
|
+
route.swapData.parameters['y-amount'],
|
|
644
|
+
'amt-in': route.swapData.parameters.dx ||
|
|
474
645
|
amount ||
|
|
475
|
-
route.swapData.parameters[
|
|
476
|
-
route.swapData.parameters[
|
|
477
|
-
route.swapData.parameters[
|
|
646
|
+
route.swapData.parameters['amt-in'] ||
|
|
647
|
+
route.swapData.parameters['amt-in-max'] ||
|
|
648
|
+
route.swapData.parameters['y-amount'] ||
|
|
478
649
|
route.swapData.parameters.dy,
|
|
479
|
-
|
|
650
|
+
'amt-in-max': route.swapData.parameters.dx ||
|
|
480
651
|
amount ||
|
|
481
|
-
route.swapData.parameters[
|
|
482
|
-
route.swapData.parameters[
|
|
483
|
-
route.swapData.parameters[
|
|
652
|
+
route.swapData.parameters['amt-in'] ||
|
|
653
|
+
route.swapData.parameters['amt-in-max'] ||
|
|
654
|
+
route.swapData.parameters['y-amount'] ||
|
|
484
655
|
route.swapData.parameters.dy,
|
|
485
|
-
|
|
656
|
+
'y-amount': route.swapData.parameters.dx ||
|
|
486
657
|
amount ||
|
|
487
|
-
route.swapData.parameters[
|
|
488
|
-
route.swapData.parameters[
|
|
489
|
-
route.swapData.parameters[
|
|
658
|
+
route.swapData.parameters['amt-in'] ||
|
|
659
|
+
route.swapData.parameters['amt-in-max'] ||
|
|
660
|
+
route.swapData.parameters['y-amount'] ||
|
|
490
661
|
route.swapData.parameters.dy,
|
|
491
662
|
dy: route.swapData.parameters.dy ||
|
|
492
663
|
amount ||
|
|
493
|
-
route.swapData.parameters[
|
|
494
|
-
route.swapData.parameters[
|
|
495
|
-
route.swapData.parameters[
|
|
664
|
+
route.swapData.parameters['amt-in'] ||
|
|
665
|
+
route.swapData.parameters['amt-in-max'] ||
|
|
666
|
+
route.swapData.parameters['y-amount'] ||
|
|
496
667
|
route.swapData.parameters.dy,
|
|
497
668
|
},
|
|
498
669
|
},
|
|
@@ -505,10 +676,10 @@ class BitflowSDK {
|
|
|
505
676
|
}
|
|
506
677
|
async executeSwap(swapExecutionData, senderAddress, slippageTolerance = 0.015, stacksProvider, onFinish, onCancel) {
|
|
507
678
|
const swapParams = await this.getSwapParams(swapExecutionData, senderAddress, slippageTolerance);
|
|
508
|
-
if (typeof window ===
|
|
509
|
-
throw new Error(
|
|
510
|
-
|
|
511
|
-
|
|
679
|
+
if (typeof window === 'undefined') {
|
|
680
|
+
throw new Error('executeSwap is only available in browser environments. ' +
|
|
681
|
+
'For Node.js environments, use getSwapParams to get the transaction parameters ' +
|
|
682
|
+
'and handle the transaction execution separately.');
|
|
512
683
|
}
|
|
513
684
|
try {
|
|
514
685
|
let provider;
|
|
@@ -518,7 +689,7 @@ class BitflowSDK {
|
|
|
518
689
|
else {
|
|
519
690
|
const loadedProvider = await this.loadConnectDependencies();
|
|
520
691
|
if (!loadedProvider) {
|
|
521
|
-
throw new Error(
|
|
692
|
+
throw new Error('Failed to initialize Stacks provider');
|
|
522
693
|
}
|
|
523
694
|
provider = loadedProvider;
|
|
524
695
|
}
|
|
@@ -526,11 +697,11 @@ class BitflowSDK {
|
|
|
526
697
|
}
|
|
527
698
|
catch (error) {
|
|
528
699
|
if (error instanceof Error &&
|
|
529
|
-
error.message.includes(
|
|
700
|
+
error.message.includes('only available in browser environments')) {
|
|
530
701
|
throw error;
|
|
531
702
|
}
|
|
532
|
-
console.error(
|
|
533
|
-
throw new Error(`Failed to execute swap: ${error instanceof Error ? error.message :
|
|
703
|
+
console.error('Error executing swap:', error);
|
|
704
|
+
throw new Error(`Failed to execute swap: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
534
705
|
}
|
|
535
706
|
}
|
|
536
707
|
async prepareSwap(swapExecutionData, senderAddress, slippageTolerance = 0.015) {
|
|
@@ -541,7 +712,7 @@ class BitflowSDK {
|
|
|
541
712
|
return await (0, keeperAPI_1.getOrCreateKeeperContractAPI)(params);
|
|
542
713
|
}
|
|
543
714
|
catch (error) {
|
|
544
|
-
console.error(
|
|
715
|
+
console.error('Error in BitflowSDK.getOrCreateKeeperContract:', error);
|
|
545
716
|
throw error;
|
|
546
717
|
}
|
|
547
718
|
}
|
|
@@ -550,7 +721,7 @@ class BitflowSDK {
|
|
|
550
721
|
return await (0, keeperAPI_1.getOrderAPI)(orderId);
|
|
551
722
|
}
|
|
552
723
|
catch (error) {
|
|
553
|
-
console.error(
|
|
724
|
+
console.error('Error in BitflowSDK.getOrder:', error);
|
|
554
725
|
throw error;
|
|
555
726
|
}
|
|
556
727
|
}
|
|
@@ -559,7 +730,7 @@ class BitflowSDK {
|
|
|
559
730
|
return await (0, keeperAPI_1.getUserAPI)(stacksAddress);
|
|
560
731
|
}
|
|
561
732
|
catch (error) {
|
|
562
|
-
console.error(
|
|
733
|
+
console.error('Error in BitflowSDK.getUser:', error);
|
|
563
734
|
throw error;
|
|
564
735
|
}
|
|
565
736
|
}
|
|
@@ -568,7 +739,7 @@ class BitflowSDK {
|
|
|
568
739
|
return await (0, keeperAPI_1.createOrderAPI)(params);
|
|
569
740
|
}
|
|
570
741
|
catch (error) {
|
|
571
|
-
console.error(
|
|
742
|
+
console.error('Error in BitflowSDK.createOrder:', error);
|
|
572
743
|
throw error;
|
|
573
744
|
}
|
|
574
745
|
}
|
|
@@ -577,24 +748,10 @@ class BitflowSDK {
|
|
|
577
748
|
return await (0, keeperAPI_1.getQuoteAPI)(params);
|
|
578
749
|
}
|
|
579
750
|
catch (error) {
|
|
580
|
-
console.error(
|
|
751
|
+
console.error('Error in BitflowSDK.getQuote:', error);
|
|
581
752
|
throw error;
|
|
582
753
|
}
|
|
583
754
|
}
|
|
584
|
-
mapDexPathToActionTrait(dexPath) {
|
|
585
|
-
const isXYK = dexPath.some((d) => d.toLowerCase().includes("xyk"));
|
|
586
|
-
const isStable = dexPath.some((d) => d.toLowerCase().includes("stable"));
|
|
587
|
-
if (isXYK && !isStable) {
|
|
588
|
-
return "SM1793C4R5PZ4NS4VQ4WMP7SKKYVH8JZEWSZ9HCCR.keeper-action-1-v-1-1";
|
|
589
|
-
}
|
|
590
|
-
if (isXYK && isStable) {
|
|
591
|
-
return "SM1793C4R5PZ4NS4VQ4WMP7SKKYVH8JZEWSZ9HCCR.keeper-action-2-v-1-1";
|
|
592
|
-
}
|
|
593
|
-
if (!isXYK && isStable) {
|
|
594
|
-
return "SM1793C4R5PZ4NS4VQ4WMP7SKKYVH8JZEWSZ9HCCR.keeper-action-3-v-1-1";
|
|
595
|
-
}
|
|
596
|
-
throw new Error(`Unsupported DEX path: ${dexPath.join(", ")}`);
|
|
597
|
-
}
|
|
598
755
|
async transformRouteToActionArgs(route) {
|
|
599
756
|
const actionFunctionArgs = {
|
|
600
757
|
tokenList: {},
|
|
@@ -604,96 +761,139 @@ class BitflowSDK {
|
|
|
604
761
|
};
|
|
605
762
|
const swapData = route.swapData;
|
|
606
763
|
if (!swapData || !swapData.parameters) {
|
|
607
|
-
throw new Error(
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
764
|
+
throw new Error('Invalid route data - missing swapData or swapData.parameters');
|
|
765
|
+
}
|
|
766
|
+
try {
|
|
767
|
+
const availableTokens = await this.getAvailableTokens();
|
|
768
|
+
const tokenPath = route.tokenPath;
|
|
769
|
+
const expandedTokenPath = [];
|
|
770
|
+
// Expand token path
|
|
771
|
+
for (let i = 0; i < tokenPath.length - 1; i++) {
|
|
615
772
|
expandedTokenPath.push(tokenPath[i]);
|
|
773
|
+
if (i > 0 && i < tokenPath.length - 1) {
|
|
774
|
+
expandedTokenPath.push(tokenPath[i]);
|
|
775
|
+
}
|
|
616
776
|
}
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
777
|
+
expandedTokenPath.push(tokenPath[tokenPath.length - 1]);
|
|
778
|
+
// Map tokens to contract identifiers
|
|
779
|
+
const tokenList = {};
|
|
780
|
+
for (let index = 0; index < expandedTokenPath.length; index++) {
|
|
781
|
+
const tokenId = expandedTokenPath[index];
|
|
782
|
+
let contractIdentifier;
|
|
783
|
+
if (tokenId === 'token-stx') {
|
|
784
|
+
contractIdentifier =
|
|
785
|
+
'SM1793C4R5PZ4NS4VQ4WMP7SKKYVH8JZEWSZ9HCCR.token-stx-v-1-2';
|
|
786
|
+
}
|
|
787
|
+
else {
|
|
788
|
+
const token = availableTokens.find((t) => t.tokenId === tokenId);
|
|
789
|
+
if (!token || !token.tokenContract) {
|
|
790
|
+
throw new Error(`Could not find contract identifier for token ${tokenId}`);
|
|
791
|
+
}
|
|
792
|
+
contractIdentifier = token.tokenContract;
|
|
793
|
+
}
|
|
794
|
+
const key = String.fromCharCode(97 + index); // 97 = 'a'
|
|
795
|
+
tokenList[key] = contractIdentifier;
|
|
625
796
|
}
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
797
|
+
actionFunctionArgs.tokenList = tokenList;
|
|
798
|
+
// Determine if this is a stableswap or XYK route
|
|
799
|
+
const dexPath = route.dexPath;
|
|
800
|
+
const isStableswapRoute = dexPath.some((path) => path.toLowerCase().includes('stable'));
|
|
801
|
+
// Transform pool lists
|
|
802
|
+
const transformPoolList = (pools) => {
|
|
803
|
+
if (typeof pools === 'string') {
|
|
804
|
+
return { a: pools };
|
|
805
|
+
}
|
|
806
|
+
if (Array.isArray(pools)) {
|
|
807
|
+
const poolObject = {};
|
|
808
|
+
const letters = 'abcdefghijklmnopqrstuvwxyz';
|
|
809
|
+
pools.forEach((pool, index) => {
|
|
810
|
+
poolObject[letters[index]] = pool;
|
|
811
|
+
});
|
|
812
|
+
return poolObject;
|
|
813
|
+
}
|
|
814
|
+
if (typeof pools === 'object' && pools !== null) {
|
|
815
|
+
return pools;
|
|
816
|
+
}
|
|
817
|
+
return {};
|
|
818
|
+
};
|
|
819
|
+
// Handle pools based on whether they're stableswap or XYK
|
|
820
|
+
if (swapData.parameters['pool-trait']) {
|
|
821
|
+
const poolIdentifier = swapData.parameters['pool-trait'];
|
|
822
|
+
const transformedPool = transformPoolList(poolIdentifier);
|
|
823
|
+
// Check if the pool name contains 'stableswap'
|
|
824
|
+
if (isStableswapRoute ||
|
|
825
|
+
(typeof poolIdentifier === 'string' &&
|
|
826
|
+
poolIdentifier.toLowerCase().includes('stableswap'))) {
|
|
827
|
+
actionFunctionArgs.stableswapPoolList = transformedPool;
|
|
828
|
+
}
|
|
829
|
+
else {
|
|
830
|
+
actionFunctionArgs.xykPoolList = transformedPool;
|
|
630
831
|
}
|
|
631
|
-
contractIdentifier = token.tokenContract;
|
|
632
832
|
}
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
833
|
+
else {
|
|
834
|
+
// Handle specific pool types
|
|
835
|
+
if (swapData.parameters['xyk-pools']) {
|
|
836
|
+
actionFunctionArgs.xykPoolList = transformPoolList(swapData.parameters['xyk-pools']);
|
|
837
|
+
}
|
|
838
|
+
if (swapData.parameters['stableswap-pools']) {
|
|
839
|
+
actionFunctionArgs.stableswapPoolList = transformPoolList(swapData.parameters['stableswap-pools']);
|
|
840
|
+
}
|
|
640
841
|
}
|
|
641
|
-
if (
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
poolObject[letters[index]] = pool;
|
|
646
|
-
});
|
|
647
|
-
return poolObject;
|
|
842
|
+
if ('swaps-reversed' in swapData.parameters) {
|
|
843
|
+
actionFunctionArgs.boolList = {
|
|
844
|
+
a: swapData.parameters['swaps-reversed'].toString(),
|
|
845
|
+
};
|
|
648
846
|
}
|
|
649
|
-
|
|
650
|
-
|
|
847
|
+
else {
|
|
848
|
+
delete actionFunctionArgs.boolList;
|
|
651
849
|
}
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
actionFunctionArgs.xykPoolList = transformPoolList(swapData.parameters["xyk-pools"]);
|
|
850
|
+
const trait = this.mapDexPathToActionTrait(dexPath);
|
|
851
|
+
actionFunctionArgs.actionTrait = trait;
|
|
852
|
+
return actionFunctionArgs;
|
|
656
853
|
}
|
|
657
|
-
|
|
658
|
-
|
|
854
|
+
catch (error) {
|
|
855
|
+
throw error;
|
|
659
856
|
}
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
857
|
+
}
|
|
858
|
+
mapDexPathToActionTrait(dexPath) {
|
|
859
|
+
const isXYK = dexPath.some((d) => d.toLowerCase().includes('xyk'));
|
|
860
|
+
const isStable = dexPath.some((d) => d.toLowerCase().includes('stable'));
|
|
861
|
+
if (isXYK && !isStable) {
|
|
862
|
+
return 'SM1793C4R5PZ4NS4VQ4WMP7SKKYVH8JZEWSZ9HCCR.keeper-action-1-v-1-1';
|
|
663
863
|
}
|
|
664
|
-
if (
|
|
665
|
-
|
|
666
|
-
a: swapData.parameters["swaps-reversed"].toString(),
|
|
667
|
-
};
|
|
864
|
+
if (isXYK && isStable) {
|
|
865
|
+
return 'SM1793C4R5PZ4NS4VQ4WMP7SKKYVH8JZEWSZ9HCCR.keeper-action-2-v-1-1';
|
|
668
866
|
}
|
|
669
|
-
|
|
670
|
-
|
|
867
|
+
if (!isXYK && isStable) {
|
|
868
|
+
return 'SM1793C4R5PZ4NS4VQ4WMP7SKKYVH8JZEWSZ9HCCR.keeper-action-3-v-1-1';
|
|
671
869
|
}
|
|
672
|
-
|
|
673
|
-
const trait = this.mapDexPathToActionTrait(dexPath);
|
|
674
|
-
actionFunctionArgs.actionTrait = trait;
|
|
675
|
-
return actionFunctionArgs;
|
|
870
|
+
throw new Error(`Unsupported DEX path: ${dexPath.join(', ')}`);
|
|
676
871
|
}
|
|
677
872
|
async getKeeperAggregatorRouteData(tokenX, tokenY, amountX) {
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
!quoteResult
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
873
|
+
try {
|
|
874
|
+
const quoteResult = await this.getKeeperQuoteForRouteWithoutScaling(tokenX, tokenY, amountX);
|
|
875
|
+
if (!quoteResult ||
|
|
876
|
+
!quoteResult.allRoutes ||
|
|
877
|
+
quoteResult.allRoutes.length === 0) {
|
|
878
|
+
throw new Error('No routes found');
|
|
879
|
+
}
|
|
880
|
+
const { bestRoute } = quoteResult;
|
|
881
|
+
if (!bestRoute) {
|
|
882
|
+
throw new Error('No best route found for keeper-compatible DEX paths');
|
|
883
|
+
}
|
|
884
|
+
const actionFunctionArgs = await this.transformRouteToActionArgs(bestRoute);
|
|
885
|
+
return actionFunctionArgs;
|
|
886
|
+
}
|
|
887
|
+
catch (error) {
|
|
888
|
+
throw error;
|
|
889
|
+
}
|
|
690
890
|
}
|
|
691
891
|
async createGroupOrder(params) {
|
|
692
892
|
try {
|
|
693
893
|
return await (0, keeperAPI_1.createGroupOrderAPI)(params);
|
|
694
894
|
}
|
|
695
895
|
catch (error) {
|
|
696
|
-
console.error(
|
|
896
|
+
console.error('Error in BitflowSDK.createGroupOrder:', error);
|
|
697
897
|
throw error;
|
|
698
898
|
}
|
|
699
899
|
}
|
|
@@ -702,7 +902,7 @@ class BitflowSDK {
|
|
|
702
902
|
return await (0, keeperAPI_1.getGroupOrderAPI)(groupId, includeOrders);
|
|
703
903
|
}
|
|
704
904
|
catch (error) {
|
|
705
|
-
console.error(
|
|
905
|
+
console.error('Error in BitflowSDK.getGroupOrder:', error);
|
|
706
906
|
throw error;
|
|
707
907
|
}
|
|
708
908
|
}
|
|
@@ -711,7 +911,7 @@ class BitflowSDK {
|
|
|
711
911
|
return await (0, keeperAPI_1.cancelOrderAPI)(orderId);
|
|
712
912
|
}
|
|
713
913
|
catch (error) {
|
|
714
|
-
console.error(
|
|
914
|
+
console.error('Error in BitflowSDK.cancelOrder:', error);
|
|
715
915
|
throw error;
|
|
716
916
|
}
|
|
717
917
|
}
|
|
@@ -720,7 +920,7 @@ class BitflowSDK {
|
|
|
720
920
|
return await (0, keeperAPI_1.cancelGroupOrderAPI)(groupId);
|
|
721
921
|
}
|
|
722
922
|
catch (error) {
|
|
723
|
-
console.error(
|
|
923
|
+
console.error('Error in BitflowSDK.cancelGroupOrder:', error);
|
|
724
924
|
throw error;
|
|
725
925
|
}
|
|
726
926
|
}
|