@bitflowlabs/core-sdk 1.0.1 → 2.0.0
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 +23 -2
- package/dist/src/BitflowSDK.js +536 -82
- package/dist/src/BitflowSDK.js.map +1 -1
- package/dist/src/config.d.ts +1 -1
- package/dist/src/config.js +6 -4
- package/dist/src/config.js.map +1 -1
- package/dist/src/helpers/callReadOnlyHelper.js +10 -4
- package/dist/src/helpers/callReadOnlyHelper.js.map +1 -1
- package/dist/src/helpers/callSwapHelper.d.ts +2 -2
- package/dist/src/helpers/callSwapHelper.js +48 -7
- package/dist/src/helpers/callSwapHelper.js.map +1 -1
- package/dist/src/helpers/fetchDataHelper.d.ts +1 -1
- package/dist/src/helpers/fetchDataHelper.js +50 -17
- package/dist/src/helpers/fetchDataHelper.js.map +1 -1
- package/dist/src/helpers/fetchPossibleSwap.d.ts +2 -2
- package/dist/src/helpers/fetchPossibleSwap.js +10 -2
- package/dist/src/helpers/fetchPossibleSwap.js.map +1 -1
- package/dist/src/helpers/handleResultHelper.js +15 -15
- package/dist/src/helpers/handleResultHelper.js.map +1 -1
- package/dist/src/helpers/newPostConditionsHelper.d.ts +2 -0
- package/dist/src/helpers/newPostConditionsHelper.js +145 -0
- package/dist/src/helpers/newPostConditionsHelper.js.map +1 -0
- package/dist/src/helpers/postConditionsHelper.js +38 -13
- package/dist/src/helpers/postConditionsHelper.js.map +1 -1
- package/dist/src/index.d.ts +3 -2
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/keeper/keeperAPI.d.ts +10 -0
- package/dist/src/keeper/keeperAPI.js +332 -0
- package/dist/src/keeper/keeperAPI.js.map +1 -0
- package/dist/src/keeper/types.d.ts +253 -0
- package/dist/src/keeper/types.js +65 -0
- package/dist/src/keeper/types.js.map +1 -0
- package/dist/src/test-keeper-routes.d.ts +1 -0
- package/dist/src/test-keeper-routes.js +67 -0
- package/dist/src/test-keeper-routes.js.map +1 -0
- package/dist/src/test-raw-token-response.d.ts +1 -0
- package/dist/src/test-raw-token-response.js +79 -0
- package/dist/src/test-raw-token-response.js.map +1 -0
- package/dist/src/test-sdk.d.ts +1 -0
- package/dist/src/test-sdk.js +229 -0
- package/dist/src/test-sdk.js.map +1 -0
- package/dist/src/test-token.fetch.d.ts +1 -0
- package/dist/src/test-token.fetch.js +63 -0
- package/dist/src/test-token.fetch.js.map +1 -0
- package/dist/src/types.d.ts +27 -2
- package/package.json +6 -5
- package/src/BitflowSDK.ts +675 -97
- package/src/config.ts +9 -6
- package/src/helpers/callReadOnlyHelper.ts +12 -7
- package/src/helpers/callSwapHelper.ts +21 -7
- package/src/helpers/fetchDataHelper.ts +58 -19
- package/src/helpers/fetchPossibleSwap.ts +18 -4
- package/src/helpers/handleResultHelper.ts +17 -16
- package/src/helpers/newPostConditionsHelper.ts +172 -0
- package/src/helpers/postConditionsHelper.ts +71 -19
- package/src/index.ts +3 -2
- package/src/keeper/keeperAPI.ts +435 -0
- package/src/keeper/types.ts +293 -0
- package/src/test-keeper-routes.ts +76 -0
- package/src/test-raw-token-response.ts +124 -0
- package/src/test-sdk.ts +262 -0
- package/src/test-token.fetch.ts +72 -0
- package/src/types.ts +29 -2
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ActionFunctionArgs,
|
|
3
|
+
CancelGroupOrderResponse,
|
|
4
|
+
CancelOrderResponse,
|
|
5
|
+
CreateGroupOrderParams,
|
|
6
|
+
CreateGroupOrderResponse,
|
|
7
|
+
CreateOrderParams,
|
|
8
|
+
CreateOrderResponse,
|
|
9
|
+
GetGroupOrderResponse,
|
|
10
|
+
GetKeeperContractParams,
|
|
11
|
+
GetKeeperContractResponse,
|
|
12
|
+
GetOrderResponse,
|
|
13
|
+
GetQuoteParams,
|
|
14
|
+
GetQuoteResponse,
|
|
15
|
+
GetUserResponse,
|
|
16
|
+
KEEPER_API_BASE_URL,
|
|
17
|
+
KeeperContract,
|
|
18
|
+
KeeperOrder,
|
|
19
|
+
} from "./types";
|
|
20
|
+
|
|
21
|
+
export async function getOrCreateKeeperContractAPI(
|
|
22
|
+
params: GetKeeperContractParams
|
|
23
|
+
): Promise<GetKeeperContractResponse> {
|
|
24
|
+
try {
|
|
25
|
+
const queryParams = new URLSearchParams({
|
|
26
|
+
stacksAddress: params.stacksAddress,
|
|
27
|
+
keeperType: params.keeperType,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
if (params.bitcoinAddress) {
|
|
31
|
+
queryParams.append("bitcoinAddress", params.bitcoinAddress);
|
|
32
|
+
}
|
|
33
|
+
if (typeof params.deployContract === "boolean") {
|
|
34
|
+
queryParams.append("deployContract", params.deployContract.toString());
|
|
35
|
+
}
|
|
36
|
+
if (typeof params.allActionsApproved === "boolean") {
|
|
37
|
+
queryParams.append(
|
|
38
|
+
"allActionsApproved",
|
|
39
|
+
params.allActionsApproved.toString()
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const url = `${KEEPER_API_BASE_URL}/getOrCreateKeeperContract?${queryParams.toString()}`;
|
|
44
|
+
|
|
45
|
+
const response = await fetch(url, {
|
|
46
|
+
method: "GET",
|
|
47
|
+
headers: {
|
|
48
|
+
Accept: "application/json",
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
if (!response.ok) {
|
|
53
|
+
const errorData = await response.json();
|
|
54
|
+
throw new Error(
|
|
55
|
+
errorData.error || `HTTP error! status: ${response.status}`
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const data = await response.json();
|
|
60
|
+
return data as GetKeeperContractResponse;
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.error("Error in getOrCreateKeeperContract:", error);
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export async function getOrderAPI(orderId: string): Promise<GetOrderResponse> {
|
|
68
|
+
try {
|
|
69
|
+
const queryParams = new URLSearchParams({
|
|
70
|
+
orderId: orderId,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const url = `${KEEPER_API_BASE_URL}/getOrder?${queryParams.toString()}`;
|
|
74
|
+
|
|
75
|
+
const response = await fetch(url, {
|
|
76
|
+
method: "GET",
|
|
77
|
+
headers: {
|
|
78
|
+
Accept: "application/json",
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
if (!response.ok) {
|
|
83
|
+
const errorData = await response.json();
|
|
84
|
+
throw new Error(
|
|
85
|
+
errorData.error || `HTTP error! status: ${response.status}`
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const data = await response.json();
|
|
90
|
+
|
|
91
|
+
if (data.order) {
|
|
92
|
+
data.order.creationDate = new Date(data.order.creationDate);
|
|
93
|
+
data.order.lastUpdated = new Date(data.order.lastUpdated);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return data as GetOrderResponse;
|
|
97
|
+
} catch (error) {
|
|
98
|
+
console.error("Error in getOrder:", error);
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export async function getUserAPI(
|
|
104
|
+
stacksAddress: string
|
|
105
|
+
): Promise<GetUserResponse> {
|
|
106
|
+
try {
|
|
107
|
+
const queryParams = new URLSearchParams({
|
|
108
|
+
stacksAddress: stacksAddress,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const url = `${KEEPER_API_BASE_URL}/getUser?${queryParams.toString()}`;
|
|
112
|
+
|
|
113
|
+
const response = await fetch(url, {
|
|
114
|
+
method: "GET",
|
|
115
|
+
headers: {
|
|
116
|
+
Accept: "application/json",
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
if (!response.ok) {
|
|
121
|
+
const errorData = await response.json();
|
|
122
|
+
throw new Error(
|
|
123
|
+
errorData.error || `HTTP error! status: ${response.status}`
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const data = (await response.json()) as GetUserResponse;
|
|
128
|
+
|
|
129
|
+
if (data.user) {
|
|
130
|
+
data.user.creationDate = new Date(data.user.creationDate);
|
|
131
|
+
data.user.lastUpdated = new Date(data.user.lastUpdated);
|
|
132
|
+
|
|
133
|
+
const contracts = data.user.keeperContracts as Record<
|
|
134
|
+
string,
|
|
135
|
+
KeeperContract
|
|
136
|
+
>;
|
|
137
|
+
for (const contractKey in contracts) {
|
|
138
|
+
const contract = contracts[contractKey];
|
|
139
|
+
if (contract.deploymentDate) {
|
|
140
|
+
contract.deploymentDate = new Date(contract.deploymentDate);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const orders = data.user.keeperOrders as Record<string, KeeperOrder>;
|
|
145
|
+
for (const orderKey in orders) {
|
|
146
|
+
const order = orders[orderKey];
|
|
147
|
+
order.creationDate = new Date(order.creationDate);
|
|
148
|
+
order.lastUpdated = new Date(order.lastUpdated);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return data;
|
|
153
|
+
} catch (error) {
|
|
154
|
+
console.error("Error in getUser:", error);
|
|
155
|
+
throw error;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export async function createOrderAPI(
|
|
160
|
+
params: CreateOrderParams
|
|
161
|
+
): Promise<CreateOrderResponse> {
|
|
162
|
+
try {
|
|
163
|
+
const url = `${KEEPER_API_BASE_URL}/createOrder`;
|
|
164
|
+
|
|
165
|
+
const requestBody = {
|
|
166
|
+
stacksAddress: params.stacksAddress,
|
|
167
|
+
keeperType: params.keeperType,
|
|
168
|
+
contractIdentifier: params.contractIdentifier,
|
|
169
|
+
bitcoinAddress: params.bitcoinAddress || "",
|
|
170
|
+
actionAmount: params.actionAmount || "",
|
|
171
|
+
minReceived: params.minReceived || {
|
|
172
|
+
amount: "",
|
|
173
|
+
autoAdjust: false,
|
|
174
|
+
},
|
|
175
|
+
feeRecipient: params.feeRecipient || "",
|
|
176
|
+
tokenOrder: params.tokenOrder || [],
|
|
177
|
+
actionType: params.actionType,
|
|
178
|
+
bitcoinTxId: params.bitcoinTxId,
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const response = await fetch(url, {
|
|
182
|
+
method: "POST",
|
|
183
|
+
headers: {
|
|
184
|
+
Accept: "application/json",
|
|
185
|
+
"Content-Type": "application/json",
|
|
186
|
+
},
|
|
187
|
+
body: JSON.stringify(requestBody),
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
if (!response.ok) {
|
|
191
|
+
const errorData = await response.json();
|
|
192
|
+
throw new Error(
|
|
193
|
+
errorData.error || `HTTP error! status: ${response.status}`
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const data = (await response.json()) as CreateOrderResponse;
|
|
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;
|
|
205
|
+
} catch (error) {
|
|
206
|
+
console.error("Error in createOrder:", error);
|
|
207
|
+
throw error;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export async function getQuoteAPI(
|
|
212
|
+
params: GetQuoteParams
|
|
213
|
+
): Promise<GetQuoteResponse> {
|
|
214
|
+
try {
|
|
215
|
+
const queryParams = new URLSearchParams();
|
|
216
|
+
|
|
217
|
+
// Add required params
|
|
218
|
+
queryParams.append("stacksAddress", params.stacksAddress);
|
|
219
|
+
queryParams.append("actionAmount", params.actionAmount);
|
|
220
|
+
queryParams.append("keeperType", params.keeperType);
|
|
221
|
+
|
|
222
|
+
// Add optional params
|
|
223
|
+
if (params.actionType) {
|
|
224
|
+
queryParams.append("actionType", params.actionType);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (params.tokenXId && params.tokenYId) {
|
|
228
|
+
queryParams.append("tokenXId", params.tokenXId);
|
|
229
|
+
queryParams.append("tokenYId", params.tokenYId);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (params.minReceived) {
|
|
233
|
+
queryParams.append("minReceived[amount]", params.minReceived.amount);
|
|
234
|
+
queryParams.append(
|
|
235
|
+
"minReceived[autoAdjust]",
|
|
236
|
+
params.minReceived.autoAdjust.toString()
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (params.feeRecipient) {
|
|
241
|
+
queryParams.append("feeRecipient", params.feeRecipient);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (params.bitcoinAddress) {
|
|
245
|
+
queryParams.append("bitcoinAddress", params.bitcoinAddress);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const url = `${KEEPER_API_BASE_URL}/getQuote?${queryParams.toString()}`;
|
|
249
|
+
const response = await fetch(url);
|
|
250
|
+
const responseText = await response.text();
|
|
251
|
+
|
|
252
|
+
if (!response.ok) {
|
|
253
|
+
throw new Error(`Unable to get quote: ${responseText}`);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
return JSON.parse(responseText) as GetQuoteResponse;
|
|
257
|
+
} catch (error) {
|
|
258
|
+
console.error("Error in getQuote:", error);
|
|
259
|
+
throw error;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export async function createGroupOrderAPI(
|
|
264
|
+
params: CreateGroupOrderParams
|
|
265
|
+
): Promise<CreateGroupOrderResponse> {
|
|
266
|
+
try {
|
|
267
|
+
const url = `${KEEPER_API_BASE_URL}/createGroupOrder`;
|
|
268
|
+
|
|
269
|
+
const requestBody: any = {
|
|
270
|
+
stacksAddress: params.stacksAddress,
|
|
271
|
+
amountPerOrder: params.amountPerOrder,
|
|
272
|
+
minReceived: params.minReceived,
|
|
273
|
+
numberOfOrders: params.numberOfOrders,
|
|
274
|
+
executionFrequency: params.executionFrequency,
|
|
275
|
+
feeRecipient: params.feeRecipient,
|
|
276
|
+
fundingTokens: params.fundingTokens,
|
|
277
|
+
bitcoinTxId: params.bitcoinTxId,
|
|
278
|
+
stacksTxId: params.stacksTxId,
|
|
279
|
+
keeperType: params.keeperType,
|
|
280
|
+
actionType: params.actionType,
|
|
281
|
+
actionFunctionArgs: params.actionFunctionArgs,
|
|
282
|
+
actionPostConditions: params.actionPostConditions,
|
|
283
|
+
actionAggregatorTokens: params.actionAggregatorTokens,
|
|
284
|
+
bitcoinAddress: params.bitcoinAddress || "",
|
|
285
|
+
nextExecutionAfter: params.nextExecutionAfter?.toISOString(),
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
if (params.priceRange) {
|
|
289
|
+
requestBody.priceRange = params.priceRange;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const response = await fetch(url, {
|
|
293
|
+
method: "POST",
|
|
294
|
+
headers: {
|
|
295
|
+
Accept: "application/json",
|
|
296
|
+
"Content-Type": "application/json",
|
|
297
|
+
},
|
|
298
|
+
body: JSON.stringify(requestBody),
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
if (!response.ok) {
|
|
302
|
+
const errorData = await response.json();
|
|
303
|
+
throw new Error(
|
|
304
|
+
errorData.error || `HTTP error! status: ${response.status}`
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
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
|
+
return data as CreateGroupOrderResponse;
|
|
322
|
+
} catch (error) {
|
|
323
|
+
console.error("Error in createGroupOrder:", error);
|
|
324
|
+
throw error;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
export async function getGroupOrderAPI(
|
|
329
|
+
groupId: string,
|
|
330
|
+
includeOrders: boolean = false
|
|
331
|
+
): Promise<GetGroupOrderResponse> {
|
|
332
|
+
try {
|
|
333
|
+
const queryParams = new URLSearchParams({
|
|
334
|
+
groupId: groupId,
|
|
335
|
+
includeOrders: includeOrders.toString(),
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
const url = `${KEEPER_API_BASE_URL}/getGroupOrder?${queryParams.toString()}`;
|
|
339
|
+
|
|
340
|
+
const response = await fetch(url, {
|
|
341
|
+
method: "GET",
|
|
342
|
+
headers: {
|
|
343
|
+
Accept: "application/json",
|
|
344
|
+
},
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
if (!response.ok) {
|
|
348
|
+
const errorData = await response.json();
|
|
349
|
+
throw new Error(
|
|
350
|
+
errorData.error || `HTTP error! status: ${response.status}`
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const data = await response.json();
|
|
355
|
+
|
|
356
|
+
// Convert date strings to Date objects
|
|
357
|
+
if (data.groupOrder) {
|
|
358
|
+
data.groupOrder.creationDate = new Date(data.groupOrder.creationDate);
|
|
359
|
+
data.groupOrder.lastUpdated = new Date(data.groupOrder.lastUpdated);
|
|
360
|
+
data.groupOrder.nextExecutionAfter = new Date(
|
|
361
|
+
data.groupOrder.nextExecutionAfter
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
if (data.groupOrders && Array.isArray(data.groupOrders)) {
|
|
366
|
+
data.groupOrders.forEach((order: KeeperOrder) => {
|
|
367
|
+
order.creationDate = new Date(order.creationDate);
|
|
368
|
+
order.lastUpdated = new Date(order.lastUpdated);
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
return data as GetGroupOrderResponse;
|
|
373
|
+
} catch (error) {
|
|
374
|
+
console.error("Error in getGroupOrder:", error);
|
|
375
|
+
throw error;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
export async function cancelOrderAPI(
|
|
380
|
+
orderId: string
|
|
381
|
+
): Promise<CancelOrderResponse> {
|
|
382
|
+
try {
|
|
383
|
+
const url = `${KEEPER_API_BASE_URL}/cancelOrder`;
|
|
384
|
+
|
|
385
|
+
const response = await fetch(url, {
|
|
386
|
+
method: "POST",
|
|
387
|
+
headers: {
|
|
388
|
+
Accept: "application/json",
|
|
389
|
+
"Content-Type": "application/json",
|
|
390
|
+
},
|
|
391
|
+
body: JSON.stringify({ orderId }),
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
if (!response.ok) {
|
|
395
|
+
const errorData = await response.json();
|
|
396
|
+
throw new Error(
|
|
397
|
+
errorData.error || `HTTP error! status: ${response.status}`
|
|
398
|
+
);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
return (await response.json()) as CancelOrderResponse;
|
|
402
|
+
} catch (error) {
|
|
403
|
+
console.error("Error in cancelOrder:", error);
|
|
404
|
+
throw error;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
export async function cancelGroupOrderAPI(
|
|
409
|
+
groupId: string
|
|
410
|
+
): Promise<CancelGroupOrderResponse> {
|
|
411
|
+
try {
|
|
412
|
+
const url = `${KEEPER_API_BASE_URL}/cancelGroupOrder`;
|
|
413
|
+
|
|
414
|
+
const response = await fetch(url, {
|
|
415
|
+
method: "POST",
|
|
416
|
+
headers: {
|
|
417
|
+
Accept: "application/json",
|
|
418
|
+
"Content-Type": "application/json",
|
|
419
|
+
},
|
|
420
|
+
body: JSON.stringify({ groupId }),
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
if (!response.ok) {
|
|
424
|
+
const errorData = await response.json();
|
|
425
|
+
throw new Error(
|
|
426
|
+
errorData.error || `HTTP error! status: ${response.status}`
|
|
427
|
+
);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
return (await response.json()) as CancelGroupOrderResponse;
|
|
431
|
+
} catch (error) {
|
|
432
|
+
console.error("Error in cancelGroupOrder:", error);
|
|
433
|
+
throw error;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
export const ALLOWED_CONTRACTS = new Set([
|
|
2
|
+
"SM1793C4R5PZ4NS4VQ4WMP7SKKYVH8JZEWSZ9HCCR.xyk-core-v-1-1",
|
|
3
|
+
"SM1793C4R5PZ4NS4VQ4WMP7SKKYVH8JZEWSZ9HCCR.xyk-core-v-1-2",
|
|
4
|
+
"SM1793C4R5PZ4NS4VQ4WMP7SKKYVH8JZEWSZ9HCCR.xyk-swap-helper-v-1-2",
|
|
5
|
+
"SM1793C4R5PZ4NS4VQ4WMP7SKKYVH8JZEWSZ9HCCR.stableswap-core-v-1-1",
|
|
6
|
+
"SM1793C4R5PZ4NS4VQ4WMP7SKKYVH8JZEWSZ9HCCR.stableswap-core-v-1-2",
|
|
7
|
+
"SM1793C4R5PZ4NS4VQ4WMP7SKKYVH8JZEWSZ9HCCR.stableswap-swap-helper-v-1-2",
|
|
8
|
+
"SM1793C4R5PZ4NS4VQ4WMP7SKKYVH8JZEWSZ9HCCR.router-xyk-stableswap-v-1-1",
|
|
9
|
+
]);
|
|
10
|
+
|
|
11
|
+
export enum ActionType {
|
|
12
|
+
SWAP_XYK_SWAP_HELPER = "SWAP_XYK_SWAP_HELPER",
|
|
13
|
+
SWAP_XYK_STABLESWAP_SWAP_HELPER = "SWAP_XYK_STABLESWAP_SWAP_HELPER",
|
|
14
|
+
SWAP_STABLESWAP_SWAP_HELPER = "SWAP_STABLESWAP_SWAP_HELPER",
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export enum KeeperType {
|
|
18
|
+
SWAP_BTC_TO_STX = "SWAP_BTC_TO_STX",
|
|
19
|
+
SWAP_RUNES_TO_RUNES_BRIDGE_OUT = "SWAP_RUNES_TO_RUNES_BRIDGE_OUT",
|
|
20
|
+
SWAP_BTC_TO_RUNES_BRIDGE_OUT = "SWAP_BTC_TO_RUNES_BRIDGE_OUT",
|
|
21
|
+
SWAP_RUNES_TO_BTC_BRIDGE_OUT = "SWAP_RUNES_TO_BTC_BRIDGE_OUT",
|
|
22
|
+
MULTI_ACTION_V1 = "MULTI_ACTION_V1",
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export enum KeeperTransactionType {
|
|
26
|
+
BITCOIN = "bitcoinTx",
|
|
27
|
+
STACKS = "stacksTx",
|
|
28
|
+
DEPLOY = "deployTx",
|
|
29
|
+
ACTION = "actionTx",
|
|
30
|
+
PONTIS = "pontisTx",
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export enum KeeperContractStatus {
|
|
34
|
+
ContractDeploymentNotStarted = "contractDeploymentNotStarted",
|
|
35
|
+
ContractDeploymentPending = "contractDeploymentPending",
|
|
36
|
+
ContractDeploymentSuccess = "contractDeploymentSuccess",
|
|
37
|
+
ContractDeploymentFailed = "contractDeploymentFailed",
|
|
38
|
+
ContractDeploymentRetry = "contractDeploymentRetry",
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export enum KeeperOrderStatus {
|
|
42
|
+
OrderCreated = "orderCreated",
|
|
43
|
+
OrderComplete = "orderComplete",
|
|
44
|
+
OrderFailed = "orderFailed",
|
|
45
|
+
ContractDeploymentPending = "contractDeploymentPending",
|
|
46
|
+
ContractDeploymentFailed = "contractDeploymentFailed",
|
|
47
|
+
ContractDeploymentRetry = "contractDeploymentRetry",
|
|
48
|
+
FundingPending = "fundingPending",
|
|
49
|
+
FundingFailed = "fundingFailed",
|
|
50
|
+
ActionPending = "actionPending",
|
|
51
|
+
ActionFailed = "actionFailed",
|
|
52
|
+
ActionRetry = "actionRetry",
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface KeeperContract {
|
|
56
|
+
contractIdentifier: string;
|
|
57
|
+
contractStatus: KeeperContractStatus;
|
|
58
|
+
deploymentDate?: Date;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface GetKeeperContractResponse {
|
|
62
|
+
keeperContract: KeeperContract;
|
|
63
|
+
error?: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface GetKeeperContractParams {
|
|
67
|
+
stacksAddress: string;
|
|
68
|
+
keeperType: KeeperType;
|
|
69
|
+
bitcoinAddress?: string;
|
|
70
|
+
deployContract?: boolean;
|
|
71
|
+
allActionsApproved?: boolean;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface MinReceived {
|
|
75
|
+
amount: string;
|
|
76
|
+
autoAdjust: boolean;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface TxRetries {
|
|
80
|
+
deploys: number;
|
|
81
|
+
actions: number;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface KeeperOrder {
|
|
85
|
+
orderId: string;
|
|
86
|
+
userStacksAddress: string;
|
|
87
|
+
userBitcoinAddress: string;
|
|
88
|
+
contractIdentifier: string;
|
|
89
|
+
actionAmount: string;
|
|
90
|
+
minReceived: MinReceived;
|
|
91
|
+
feeRecipient: string;
|
|
92
|
+
tokenOrder: string[];
|
|
93
|
+
txIds: Record<string, string>;
|
|
94
|
+
keeperType: KeeperType;
|
|
95
|
+
requiresPontisTx: boolean;
|
|
96
|
+
status: KeeperOrderStatus;
|
|
97
|
+
txRetries: TxRetries;
|
|
98
|
+
creationDate: Date;
|
|
99
|
+
lastUpdated: Date;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface GetOrderResponse {
|
|
103
|
+
order: KeeperOrder;
|
|
104
|
+
error?: string;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface User {
|
|
108
|
+
stacksAddress: string;
|
|
109
|
+
bitcoinAddress: string;
|
|
110
|
+
keeperContracts: Record<string, KeeperContract>;
|
|
111
|
+
keeperOrders: Record<string, KeeperOrder>;
|
|
112
|
+
creationDate: Date;
|
|
113
|
+
lastUpdated: Date;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface GetUserResponse {
|
|
117
|
+
user: User;
|
|
118
|
+
error?: string;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export interface CreateOrderParams {
|
|
122
|
+
stacksAddress: string;
|
|
123
|
+
keeperType: KeeperType;
|
|
124
|
+
contractIdentifier: string;
|
|
125
|
+
bitcoinAddress?: string;
|
|
126
|
+
actionAmount?: string;
|
|
127
|
+
minReceived?: {
|
|
128
|
+
amount: string;
|
|
129
|
+
autoAdjust: boolean;
|
|
130
|
+
};
|
|
131
|
+
feeRecipient?: string;
|
|
132
|
+
tokenOrder?: string[];
|
|
133
|
+
actionType: string;
|
|
134
|
+
bitcoinTxId: string;
|
|
135
|
+
actionFunctionArgs?: {
|
|
136
|
+
tokenList?: Record<string, string>;
|
|
137
|
+
xykPoolList?: Record<string, string>;
|
|
138
|
+
stableswapPoolList?: Record<string, string>;
|
|
139
|
+
boolList?: Record<string, string>;
|
|
140
|
+
[key: string]: any;
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export interface CreateOrderResponse {
|
|
145
|
+
order: KeeperOrder;
|
|
146
|
+
error?: string;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export interface ActionFunctionArgs {
|
|
150
|
+
actionTrait?: string;
|
|
151
|
+
tokenList?: Record<string, string>;
|
|
152
|
+
xykPoolList?: Record<string, string>;
|
|
153
|
+
stableswapPoolList?: Record<string, string>;
|
|
154
|
+
boolList?: Record<string, string>;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export interface GetQuoteParams {
|
|
158
|
+
stacksAddress: string;
|
|
159
|
+
actionAmount: string;
|
|
160
|
+
keeperType: KeeperType;
|
|
161
|
+
actionType?: string;
|
|
162
|
+
tokenXId?: string;
|
|
163
|
+
tokenYId?: string;
|
|
164
|
+
minReceived?: {
|
|
165
|
+
amount: string;
|
|
166
|
+
autoAdjust: boolean;
|
|
167
|
+
};
|
|
168
|
+
feeRecipient?: string;
|
|
169
|
+
bitcoinAddress?: string;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export interface GetQuoteResponse {
|
|
173
|
+
quote: string;
|
|
174
|
+
quoteWithSlippage: string;
|
|
175
|
+
keeperType: KeeperType;
|
|
176
|
+
actionType?: string;
|
|
177
|
+
tokenOrder: string[];
|
|
178
|
+
error?: string;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export interface AggregatorRouteData {
|
|
182
|
+
tokenX: string;
|
|
183
|
+
tokenY: string;
|
|
184
|
+
amountX: number;
|
|
185
|
+
routes: SwapRoute[];
|
|
186
|
+
dexPath: string[];
|
|
187
|
+
tokenPath: string[];
|
|
188
|
+
bestRoute?: SwapRoute;
|
|
189
|
+
keeperOrderData?: KeeperOrderRouteData;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export interface SwapRoute {
|
|
193
|
+
poolRoute: string[];
|
|
194
|
+
expectedOutput: number;
|
|
195
|
+
tokenRoute: string[];
|
|
196
|
+
dexRoute: string[];
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export interface KeeperOrderRouteData {
|
|
200
|
+
tokenList: Record<string, string>;
|
|
201
|
+
xykPoolList: Record<string, string>;
|
|
202
|
+
stableswapPoolList: Record<string, string>;
|
|
203
|
+
boolList: Record<string, string>;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export interface GroupOrder {
|
|
207
|
+
groupId: string;
|
|
208
|
+
userStacksAddress: string;
|
|
209
|
+
orders: KeeperOrder[];
|
|
210
|
+
status: GroupOrderStatus;
|
|
211
|
+
creationDate: Date;
|
|
212
|
+
lastUpdated: Date;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export enum GroupOrderStatus {
|
|
216
|
+
Active = "active",
|
|
217
|
+
Completed = "completed",
|
|
218
|
+
Cancelled = "cancelled",
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export interface CreateGroupOrderParams {
|
|
222
|
+
stacksAddress: string;
|
|
223
|
+
amountPerOrder: number;
|
|
224
|
+
numberOfOrders: number;
|
|
225
|
+
executionFrequency: number;
|
|
226
|
+
feeRecipient: string;
|
|
227
|
+
fundingTokens: {
|
|
228
|
+
[key: string]: string;
|
|
229
|
+
};
|
|
230
|
+
bitcoinTxId?: string;
|
|
231
|
+
stacksTxId?: string;
|
|
232
|
+
keeperType: KeeperType;
|
|
233
|
+
actionType?: string;
|
|
234
|
+
actionFunctionArgs?: ActionFunctionArgs;
|
|
235
|
+
actionPostConditions?: any[];
|
|
236
|
+
actionAggregatorTokens?: {
|
|
237
|
+
tokenXId: string;
|
|
238
|
+
tokenYId: string;
|
|
239
|
+
};
|
|
240
|
+
bitcoinAddress?: string;
|
|
241
|
+
nextExecutionAfter?: Date;
|
|
242
|
+
executeActionAfter?: Date;
|
|
243
|
+
minReceived: {
|
|
244
|
+
amount: string;
|
|
245
|
+
autoAdjust: boolean;
|
|
246
|
+
};
|
|
247
|
+
priceRange?: {
|
|
248
|
+
amount: string;
|
|
249
|
+
minPrice: string;
|
|
250
|
+
maxPrice: string;
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export interface CreateGroupOrderResponse {
|
|
255
|
+
keeperGroupOrder: {
|
|
256
|
+
groupId: string;
|
|
257
|
+
orderIds: string[];
|
|
258
|
+
userStacksAddress: string;
|
|
259
|
+
userBitcoinAddress: string;
|
|
260
|
+
contractIdentifier: string;
|
|
261
|
+
amountPerOrder: string;
|
|
262
|
+
numberOfOrders: string;
|
|
263
|
+
remainingOrders: string;
|
|
264
|
+
executionFrequency: string;
|
|
265
|
+
txIds: {
|
|
266
|
+
bitcoinTxId?: string;
|
|
267
|
+
stacksTxId?: string;
|
|
268
|
+
};
|
|
269
|
+
nextExecutionAfter: Date;
|
|
270
|
+
creationDate: Date;
|
|
271
|
+
lastUpdated: Date;
|
|
272
|
+
};
|
|
273
|
+
error?: string;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export interface GetGroupOrderResponse {
|
|
277
|
+
groupOrder: GroupOrder;
|
|
278
|
+
error?: string;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export interface CancelOrderResponse {
|
|
282
|
+
success: boolean;
|
|
283
|
+
error?: string;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export interface CancelGroupOrderResponse {
|
|
287
|
+
success: boolean;
|
|
288
|
+
error?: string;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
export const KEEPER_API_BASE_URL =
|
|
292
|
+
"https://bitflow-keeper-7owjsmt8.uc.gateway.dev";
|
|
293
|
+
// "http://localhost:8080";
|