@orb-labs/orby-core 0.0.6 → 0.0.8

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.
Files changed (56) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/actions/account_cluster.d.ts +12 -5
  3. package/dist/actions/account_cluster.js +185 -338
  4. package/dist/actions/admin.d.ts +3 -3
  5. package/dist/actions/admin.js +37 -127
  6. package/dist/actions/application.d.ts +2 -2
  7. package/dist/actions/application.js +14 -77
  8. package/dist/actions/blockchain.d.ts +16 -0
  9. package/dist/actions/blockchain.js +35 -0
  10. package/dist/actions/instance.d.ts +3 -4
  11. package/dist/actions/instance.js +90 -255
  12. package/dist/actions/operation.d.ts +19 -10
  13. package/dist/actions/operation.js +323 -259
  14. package/dist/actions/token.d.ts +3 -3
  15. package/dist/actions/token.js +43 -119
  16. package/dist/constants.d.ts +3 -3
  17. package/dist/constants.js +70 -71
  18. package/dist/entities/account.d.ts +1 -1
  19. package/dist/entities/account.js +25 -30
  20. package/dist/entities/financial/account_balance.d.ts +2 -2
  21. package/dist/entities/financial/account_balance.js +20 -22
  22. package/dist/entities/financial/asset.js +13 -15
  23. package/dist/entities/financial/currency.d.ts +1 -1
  24. package/dist/entities/financial/currency.js +16 -35
  25. package/dist/entities/financial/currency_amount.d.ts +1 -1
  26. package/dist/entities/financial/currency_amount.js +49 -71
  27. package/dist/entities/financial/fungible_token.d.ts +3 -3
  28. package/dist/entities/financial/fungible_token.js +31 -52
  29. package/dist/entities/financial/fungible_token_amount.d.ts +2 -2
  30. package/dist/entities/financial/fungible_token_amount.js +53 -75
  31. package/dist/entities/financial/non_fungible_token.d.ts +2 -2
  32. package/dist/entities/financial/non_fungible_token.js +25 -45
  33. package/dist/entities/financial/semi_fungible_token.d.ts +2 -2
  34. package/dist/entities/financial/semi_fungible_token.js +25 -45
  35. package/dist/entities/library_request.d.ts +1 -1
  36. package/dist/entities/library_request.js +7 -9
  37. package/dist/entities/state.d.ts +4 -4
  38. package/dist/entities/state.js +57 -67
  39. package/dist/index.d.ts +29 -27
  40. package/dist/index.js +29 -27
  41. package/dist/interfaces/account_cluster.d.ts +11 -4
  42. package/dist/interfaces/admin.d.ts +1 -1
  43. package/dist/interfaces/blockchain.d.ts +13 -0
  44. package/dist/interfaces/blockchain.js +1 -0
  45. package/dist/interfaces/instance.d.ts +1 -2
  46. package/dist/interfaces/operation.d.ts +25 -10
  47. package/dist/interfaces/orby.d.ts +8 -7
  48. package/dist/interfaces/token.d.ts +1 -1
  49. package/dist/tsconfig.tsbuildinfo +1 -1
  50. package/dist/types.d.ts +9 -9
  51. package/dist/utils/action_helpers.d.ts +1 -1
  52. package/dist/utils/action_helpers.js +43 -63
  53. package/dist/utils/utils.d.ts +2 -1
  54. package/dist/utils/utils.js +23 -19
  55. package/dist/utils/validateAndParseAddress.js +3 -3
  56. package/package.json +4 -2
@@ -1,265 +1,329 @@
1
- var __extends = (this && this.__extends) || (function () {
2
- var extendStatics = function (d, b) {
3
- extendStatics = Object.setPrototypeOf ||
4
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
- return extendStatics(d, b);
7
- };
8
- return function (d, b) {
9
- if (typeof b !== "function" && b !== null)
10
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
- extendStatics(d, b);
12
- function __() { this.constructor = d; }
13
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
- };
15
- })();
16
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
- return new (P || (P = Promise))(function (resolve, reject) {
19
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
- step((generator = generator.apply(thisArg, _arguments || [])).next());
23
- });
24
- };
25
- var __generator = (this && this.__generator) || function (thisArg, body) {
26
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
27
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
28
- function verb(n) { return function (v) { return step([n, v]); }; }
29
- function step(op) {
30
- if (f) throw new TypeError("Generator is already executing.");
31
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
32
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
33
- if (y = 0, t) op = [op[0] & 2, t.value];
34
- switch (op[0]) {
35
- case 0: case 1: t = op; break;
36
- case 4: _.label++; return { value: op[1], done: false };
37
- case 5: _.label++; y = op[1]; op = [0]; continue;
38
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
39
- default:
40
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
41
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
42
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
43
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
44
- if (t[2]) _.ops.pop();
45
- _.trys.pop(); continue;
1
+ import { extractOperationSet, extractOperationStatuses, } from "../utils/action_helpers.js";
2
+ import { CurrencyAmount } from "../entities/financial/currency_amount.js";
3
+ import { OperationStatusType, OperationType, } from "../enums.js";
4
+ import { LibraryRequest } from "../entities/library_request.js";
5
+ import { getOrbyChainId } from "../utils/utils.js";
6
+ export class OperationActions extends LibraryRequest {
7
+ constructor(library, client, provider) {
8
+ super(library, client, provider);
9
+ }
10
+ async getOperationsToExecuteTransaction(accountClusterId, to, data, value, gasToken) {
11
+ const formattedGasToken = gasToken
12
+ ? {
13
+ ...gasToken,
14
+ tokenSources: gasToken.tokenSources?.map(({ chainId, address }) => ({
15
+ chainId: getOrbyChainId(chainId),
16
+ address,
17
+ })),
46
18
  }
47
- op = body.call(thisArg, _);
48
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
49
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
19
+ : undefined;
20
+ const operationSet = await this.sendRequest("orby_getOperationsToExecuteTransaction", [
21
+ {
22
+ accountClusterId,
23
+ to,
24
+ data,
25
+ value,
26
+ gasToken: formattedGasToken,
27
+ },
28
+ ]);
29
+ return extractOperationSet(operationSet);
50
30
  }
51
- };
52
- import { extractOperationSet, extractOperationStatuses, } from "../utils/action_helpers";
53
- import { CurrencyAmount } from "../entities/financial/currency_amount";
54
- import { LibraryRequest } from "../entities/library_request";
55
- var OperationActions = /** @class */ (function (_super) {
56
- __extends(OperationActions, _super);
57
- function OperationActions(library, client, provider) {
58
- return _super.call(this, library, client, provider) || this;
31
+ async getOperationsToSignTypedData(accountClusterId, data) {
32
+ const operationSet = await this.sendRequest("orby_getOperationsToSignTypedData", [
33
+ {
34
+ accountClusterId,
35
+ data,
36
+ },
37
+ ]);
38
+ return extractOperationSet(operationSet);
59
39
  }
60
- OperationActions.prototype.getOperationsToExecuteTransaction = function (accountClusterId, to, data, value, gasToken) {
61
- return __awaiter(this, void 0, void 0, function () {
62
- var operationSet;
63
- return __generator(this, function (_a) {
64
- switch (_a.label) {
65
- case 0: return [4 /*yield*/, this.sendRequest("orby_getOperationsToExecuteTransaction", [{ accountClusterId: accountClusterId, to: to, data: data, value: value, gasToken: gasToken }])];
66
- case 1:
67
- operationSet = _a.sent();
68
- return [2 /*return*/, extractOperationSet(operationSet)];
69
- }
70
- });
71
- });
72
- };
73
- OperationActions.prototype.getOperationsToSignTypedData = function (accountClusterId, data) {
74
- return __awaiter(this, void 0, void 0, function () {
75
- var operationSet;
76
- return __generator(this, function (_a) {
77
- switch (_a.label) {
78
- case 0: return [4 /*yield*/, this.sendRequest("orby_getOperationsToSignTypedData", [{ accountClusterId: accountClusterId, data: data }])];
79
- case 1:
80
- operationSet = _a.sent();
81
- return [2 /*return*/, extractOperationSet(operationSet)];
82
- }
83
- });
84
- });
85
- };
86
- OperationActions.prototype.getOperationsToCancelTransaction = function (accountClusterId, operationSetId) {
87
- return __awaiter(this, void 0, void 0, function () {
88
- var operationSet;
89
- return __generator(this, function (_a) {
90
- switch (_a.label) {
91
- case 0: return [4 /*yield*/, this.sendRequest("orby_getOperationsToCancelTransaction", [{ accountClusterId: accountClusterId, operationSetId: operationSetId }])];
92
- case 1:
93
- operationSet = _a.sent();
94
- return [2 /*return*/, extractOperationSet(operationSet)];
95
- }
96
- });
97
- });
98
- };
99
- OperationActions.prototype.isTransactionPreconditionSatisfied = function (accountClusterId, to, data, value) {
100
- return __awaiter(this, void 0, void 0, function () {
101
- var satisfied;
102
- return __generator(this, function (_a) {
103
- switch (_a.label) {
104
- case 0: return [4 /*yield*/, this.sendRequest("orby_isTransactionPreconditionSatisfied", [{ accountClusterId: accountClusterId, to: to, data: data, value: value }])];
105
- case 1:
106
- satisfied = (_a.sent()).satisfied;
107
- return [2 /*return*/, satisfied];
108
- }
109
- });
110
- });
111
- };
112
- OperationActions.prototype.isTypedDataPreconditionSatisfied = function (accountClusterId, data) {
113
- return __awaiter(this, void 0, void 0, function () {
114
- var _a, satisfied, code, message;
115
- return __generator(this, function (_b) {
116
- switch (_b.label) {
117
- case 0: return [4 /*yield*/, this.sendRequest("orby_isTypedDataPreconditionSatisfied", [{ accountClusterId: accountClusterId, data: data }])];
118
- case 1:
119
- _a = _b.sent(), satisfied = _a.satisfied, code = _a.code, message = _a.message;
120
- if (code && message) {
121
- console.error("[isTypedDataPreconditionSatisfied]", code, message);
122
- return [2 /*return*/, undefined];
123
- }
124
- return [2 /*return*/, satisfied];
125
- }
126
- });
127
- });
128
- };
129
- OperationActions.prototype.sendSignedOperations = function (accountClusterId, signedOperations) {
130
- return __awaiter(this, void 0, void 0, function () {
131
- var _a, operationSetId, operationResponses, code, message;
132
- return __generator(this, function (_b) {
133
- switch (_b.label) {
134
- case 0: return [4 /*yield*/, this.sendRequest("orby_sendSignedOperations", [
135
- { accountClusterId: accountClusterId, signedOperations: signedOperations },
136
- ])];
137
- case 1:
138
- _a = _b.sent(), operationSetId = _a.operationSetId, operationResponses = _a.operationResponses, code = _a.code, message = _a.message;
139
- if (code && message) {
140
- console.error("[sendSignedOperations]", code, message);
141
- return [2 /*return*/, undefined];
142
- }
143
- return [2 /*return*/, {
144
- operationSetId: operationSetId,
145
- operationResponses: extractOperationStatuses(operationResponses),
146
- }];
147
- }
148
- });
149
- });
150
- };
151
- OperationActions.prototype.getOperationStatuses = function (operationIds) {
152
- return __awaiter(this, void 0, void 0, function () {
153
- var operationStatuses;
154
- return __generator(this, function (_a) {
155
- switch (_a.label) {
156
- case 0: return [4 /*yield*/, this.sendRequest("orby_getOperationStatuses", [{ operationIds: operationIds }])];
157
- case 1:
158
- operationStatuses = (_a.sent()).operationStatuses;
159
- return [2 /*return*/, extractOperationStatuses(operationStatuses)];
160
- }
161
- });
162
- });
163
- };
164
- OperationActions.prototype.estimateFiatCostToExecuteTransaction = function (to, data, value) {
165
- return __awaiter(this, void 0, void 0, function () {
166
- var _a, estimatedCost, code, message;
167
- return __generator(this, function (_b) {
168
- switch (_b.label) {
169
- case 0: return [4 /*yield*/, this.sendRequest("orby_estimateFiatCostToExecuteTransaction", [{ to: to, data: data, value: value }])];
170
- case 1:
171
- _a = _b.sent(), estimatedCost = _a.estimatedCost, code = _a.code, message = _a.message;
172
- if (code && message) {
173
- console.error("[estimateFiatCostToExecuteTransaction]", code, message);
174
- return [2 /*return*/, undefined];
175
- }
176
- return [2 /*return*/, CurrencyAmount.toCurrencyAmount(estimatedCost)];
177
- }
178
- });
179
- });
180
- };
181
- OperationActions.prototype.estimateFiatCostToSignTypedData = function (data) {
182
- return __awaiter(this, void 0, void 0, function () {
183
- var _a, estimatedCost, code, message;
184
- return __generator(this, function (_b) {
185
- switch (_b.label) {
186
- case 0: return [4 /*yield*/, this.sendRequest("orby_estimateFiatCostToSignTypedData", [{ data: data }])];
187
- case 1:
188
- _a = _b.sent(), estimatedCost = _a.estimatedCost, code = _a.code, message = _a.message;
189
- if (code && message) {
190
- console.error("[estimateFiatCostToSignTypedData]", code, message);
191
- return [2 /*return*/, undefined];
192
- }
193
- return [2 /*return*/, CurrencyAmount.toCurrencyAmount(estimatedCost)];
194
- }
195
- });
196
- });
197
- };
198
- OperationActions.prototype.getOperationsToTransferToken = function (accountClusterId, standardizedTokenId, amount, recipient, gasToken) {
199
- return __awaiter(this, void 0, void 0, function () {
200
- var operationSet;
201
- return __generator(this, function (_a) {
202
- switch (_a.label) {
203
- case 0: return [4 /*yield*/, this.sendRequest("orby_getOperationsToTransferToken", [{ accountClusterId: accountClusterId, standardizedTokenId: standardizedTokenId, amount: amount, recipient: recipient, gasToken: gasToken }])];
204
- case 1:
205
- operationSet = _a.sent();
206
- return [2 /*return*/, extractOperationSet(operationSet)];
207
- }
208
- });
209
- });
210
- };
211
- OperationActions.prototype.getOperationsToSwap = function (accountClusterId, swapType, input, output, gasToken) {
212
- return __awaiter(this, void 0, void 0, function () {
213
- var operationSet;
214
- return __generator(this, function (_a) {
215
- switch (_a.label) {
216
- case 0: return [4 /*yield*/, this.sendRequest("orby_getOperationsToSwap", [
217
- { accountClusterId: accountClusterId, swapType: swapType, input: input, output: output, gasToken: gasToken },
218
- ])];
219
- case 1:
220
- operationSet = _a.sent();
221
- return [2 /*return*/, extractOperationSet(operationSet)];
40
+ async getOperationsToCancelTransaction(accountClusterId, operationSetId) {
41
+ const operationSet = await this.sendRequest("orby_getOperationsToCancelTransaction", [
42
+ {
43
+ accountClusterId,
44
+ operationSetId,
45
+ },
46
+ ]);
47
+ return extractOperationSet(operationSet);
48
+ }
49
+ async isTransactionPreconditionSatisfied(accountClusterId, to, data, value) {
50
+ const { satisfied } = await this.sendRequest("orby_isTransactionPreconditionSatisfied", [
51
+ {
52
+ accountClusterId,
53
+ to,
54
+ data,
55
+ value,
56
+ },
57
+ ]);
58
+ return satisfied;
59
+ }
60
+ async isTypedDataPreconditionSatisfied(accountClusterId, data) {
61
+ const { satisfied, code, message } = await this.sendRequest("orby_isTypedDataPreconditionSatisfied", [
62
+ {
63
+ accountClusterId,
64
+ data,
65
+ },
66
+ ]);
67
+ if (code && message) {
68
+ console.error("[isTypedDataPreconditionSatisfied]", code, message);
69
+ return undefined;
70
+ }
71
+ return satisfied;
72
+ }
73
+ async sendSignedOperations(accountClusterId, signedOperations) {
74
+ const { operationSetId, operationResponses, code, message } = await this.sendRequest("orby_sendSignedOperations", [
75
+ {
76
+ accountClusterId,
77
+ signedOperations,
78
+ },
79
+ ]);
80
+ if (code && message) {
81
+ console.error("[sendSignedOperations]", code, message);
82
+ return undefined;
83
+ }
84
+ return {
85
+ operationSetId,
86
+ operationResponses: extractOperationStatuses(operationResponses),
87
+ };
88
+ }
89
+ async getOperationStatuses(operationIds) {
90
+ const { operationStatuses } = await this.sendRequest("orby_getOperationStatuses", [{ operationIds }]);
91
+ return extractOperationStatuses(operationStatuses);
92
+ }
93
+ async estimateFiatCostToExecuteTransaction(to, data, value) {
94
+ const { estimatedCost, code, message } = await this.sendRequest("orby_estimateFiatCostToExecuteTransaction", [
95
+ {
96
+ to,
97
+ data,
98
+ value,
99
+ },
100
+ ]);
101
+ if (code && message) {
102
+ console.error("[estimateFiatCostToExecuteTransaction]", code, message);
103
+ return undefined;
104
+ }
105
+ return CurrencyAmount.toCurrencyAmount(estimatedCost);
106
+ }
107
+ async estimateFiatCostToSignTypedData(data) {
108
+ const { estimatedCost, code, message } = await this.sendRequest("orby_estimateFiatCostToSignTypedData", [{ data }]);
109
+ if (code && message) {
110
+ console.error("[estimateFiatCostToSignTypedData]", code, message);
111
+ return undefined;
112
+ }
113
+ return CurrencyAmount.toCurrencyAmount(estimatedCost);
114
+ }
115
+ async getOperationsToTransferToken(accountClusterId, standardizedTokenId, amount, recipient, gasToken) {
116
+ const formattedGasToken = gasToken
117
+ ? {
118
+ ...gasToken,
119
+ tokenSources: gasToken.tokenSources?.map(({ chainId, address }) => ({
120
+ chainId: getOrbyChainId(chainId),
121
+ address,
122
+ })),
123
+ }
124
+ : undefined;
125
+ const formattedRecepient = {
126
+ chainId: getOrbyChainId(recipient.chainId),
127
+ recipientAddress: recipient.recipientAddress,
128
+ };
129
+ const operationSet = await this.sendRequest("orby_getOperationsToTransferToken", [
130
+ {
131
+ accountClusterId,
132
+ standardizedTokenId,
133
+ amount,
134
+ recipient: formattedRecepient,
135
+ gasToken: formattedGasToken,
136
+ },
137
+ ]);
138
+ return extractOperationSet(operationSet);
139
+ }
140
+ async getOperationsToSwap(accountClusterId, swapType, input, output, gasToken) {
141
+ const formattedInput = input
142
+ ? {
143
+ ...input,
144
+ tokenSources: input?.tokenSources.map(({ chainId, address }) => ({
145
+ chainId: getOrbyChainId(chainId),
146
+ address,
147
+ })),
148
+ }
149
+ : undefined;
150
+ const formattedOutput = output
151
+ ? {
152
+ ...output,
153
+ tokenDestination: output?.tokenDestination
154
+ ? {
155
+ chainId: getOrbyChainId(output.tokenDestination.chainId),
156
+ address: output.tokenDestination.address,
157
+ }
158
+ : undefined,
159
+ }
160
+ : undefined;
161
+ const formattedGasToken = gasToken
162
+ ? {
163
+ ...gasToken,
164
+ tokenSources: gasToken.tokenSources?.map(({ chainId, address }) => ({
165
+ chainId: getOrbyChainId(chainId),
166
+ address,
167
+ })),
168
+ }
169
+ : undefined;
170
+ const operationSet = await this.sendRequest("orby_getOperationsToSwap", [
171
+ {
172
+ accountClusterId,
173
+ swapType,
174
+ input: formattedInput,
175
+ output: formattedOutput,
176
+ gasToken: formattedGasToken,
177
+ },
178
+ ]);
179
+ return extractOperationSet(operationSet);
180
+ }
181
+ async getQuote(accountClusterId, swapType, input, output) {
182
+ const formattedInput = input
183
+ ? {
184
+ ...input,
185
+ tokenSources: input?.tokenSources.map(({ chainId, address }) => ({
186
+ chainId: getOrbyChainId(chainId),
187
+ address,
188
+ })),
189
+ }
190
+ : undefined;
191
+ const formattedOutput = output
192
+ ? {
193
+ ...output,
194
+ tokenDestination: output?.tokenDestination
195
+ ? {
196
+ chainId: getOrbyChainId(output.tokenDestination.chainId),
197
+ address: output.tokenDestination.address,
198
+ }
199
+ : undefined,
200
+ }
201
+ : undefined;
202
+ const operationSet = await this.sendRequest("orby_getQuote", [
203
+ {
204
+ accountClusterId,
205
+ swapType,
206
+ input: formattedInput,
207
+ output: formattedOutput,
208
+ },
209
+ ]);
210
+ return extractOperationSet(operationSet);
211
+ }
212
+ async getOperationsToBridge(accountClusterId, standardizedTokenId, amount, tokenSources, tokenDestination, gasToken) {
213
+ const formattedTokenSources = tokenSources.map(({ chainId, address }) => ({
214
+ chainId: getOrbyChainId(chainId),
215
+ address,
216
+ }));
217
+ const formattedDestination = tokenDestination
218
+ ? {
219
+ chainId: getOrbyChainId(tokenDestination.chainId),
220
+ address: tokenDestination.address,
221
+ }
222
+ : undefined;
223
+ const formattedGasToken = gasToken
224
+ ? {
225
+ ...gasToken,
226
+ tokenSources: gasToken.tokenSources?.map(({ chainId, address }) => ({
227
+ chainId: getOrbyChainId(chainId),
228
+ address,
229
+ })),
230
+ }
231
+ : undefined;
232
+ const operationSet = await this.sendRequest("orby_getOperationsToBridge", [
233
+ {
234
+ accountClusterId,
235
+ standardizedTokenId,
236
+ amount,
237
+ tokenSources: formattedTokenSources,
238
+ tokenDestination: formattedDestination,
239
+ gasToken: formattedGasToken,
240
+ },
241
+ ]);
242
+ return extractOperationSet(operationSet);
243
+ }
244
+ subscribeToOperationStatuses(ids, onOperationStatusesUpdateCallback) {
245
+ let intervalId = null;
246
+ let totalWaitTime = 0;
247
+ if (ids && ids?.length > 0) {
248
+ const waitTime = 500;
249
+ intervalId = setInterval(async () => {
250
+ let statusSummary = OperationStatusType.WAITING_PRECONDITION;
251
+ try {
252
+ const statuses = ids && ids?.length > 0
253
+ ? await this?.getOperationStatuses(ids)
254
+ : undefined;
255
+ if (!ids || ids?.length == 0) {
256
+ statusSummary = OperationStatusType.NOT_FOUND;
257
+ }
258
+ else if (!statuses) {
259
+ statusSummary = OperationStatusType.NOT_FOUND;
260
+ }
261
+ else if (statuses.some((status) => status.status == OperationStatusType.FAILED)) {
262
+ statusSummary = OperationStatusType.FAILED;
263
+ }
264
+ else if (statuses.every((status) => status.status == OperationStatusType.SUCCESSFUL)) {
265
+ statusSummary = OperationStatusType.SUCCESSFUL;
266
+ }
267
+ const primaryOperation = statuses?.find((status) => status.type == OperationType.FINAL_TRANSACTION);
268
+ if (primaryOperation?.status == OperationStatusType.PENDING) {
269
+ statusSummary = OperationStatusType.PENDING;
270
+ }
271
+ onOperationStatusesUpdateCallback?.(statusSummary, primaryOperation, statuses);
222
272
  }
223
- });
224
- });
225
- };
226
- OperationActions.prototype.getQuote = function (accountClusterId, swapType, input, output) {
227
- return __awaiter(this, void 0, void 0, function () {
228
- var operationSet;
229
- return __generator(this, function (_a) {
230
- switch (_a.label) {
231
- case 0: return [4 /*yield*/, this.sendRequest("orby_getQuote", [
232
- { accountClusterId: accountClusterId, swapType: swapType, input: input, output: output },
233
- ])];
234
- case 1:
235
- operationSet = _a.sent();
236
- return [2 /*return*/, extractOperationSet(operationSet)];
273
+ catch (error) {
274
+ console.error("[useWaitForStatusCompletion]", error);
237
275
  }
238
- });
239
- });
240
- };
241
- OperationActions.prototype.getOperationsToBridge = function (accountClusterId, standardizedTokenId, amount, tokenSources, tokenDestination, gasToken) {
242
- return __awaiter(this, void 0, void 0, function () {
243
- var operationSet;
244
- return __generator(this, function (_a) {
245
- switch (_a.label) {
246
- case 0: return [4 /*yield*/, this.sendRequest("orby_getOperationsToBridge", [
247
- {
248
- accountClusterId: accountClusterId,
249
- standardizedTokenId: standardizedTokenId,
250
- amount: amount,
251
- tokenSources: tokenSources,
252
- tokenDestination: tokenDestination,
253
- gasToken: gasToken,
254
- },
255
- ])];
256
- case 1:
257
- operationSet = _a.sent();
258
- return [2 /*return*/, extractOperationSet(operationSet)];
276
+ finally {
277
+ totalWaitTime += waitTime;
278
+ if (intervalId &&
279
+ OperationStatusType.WAITING_PRECONDITION != statusSummary) {
280
+ clearInterval(intervalId);
281
+ intervalId = null;
282
+ }
283
+ else if (intervalId && totalWaitTime >= 60_000) {
284
+ // we cant wait for more than 2 ETH blocks
285
+ clearInterval(intervalId);
286
+ intervalId = null;
287
+ }
259
288
  }
260
- });
261
- });
262
- };
263
- return OperationActions;
264
- }(LibraryRequest));
265
- export { OperationActions };
289
+ }, waitTime);
290
+ }
291
+ return { intervalId };
292
+ }
293
+ async sendOperationSet(accountClusterId, operationSet, signOperation) {
294
+ const signedOperations = [];
295
+ const operations = operationSet.intents
296
+ ?.map((intent) => intent.intentOperations)
297
+ .flat()
298
+ ?.concat(operationSet.primaryOperation)
299
+ .filter((value) => value != undefined && value != null);
300
+ if (operations?.length == 0) {
301
+ return { success: true, operationResponses: [] };
302
+ }
303
+ else if (!operations) {
304
+ return { success: false };
305
+ }
306
+ const hasPrimaryOperation = operations.find((operation) => operation.type == OperationType.FINAL_TRANSACTION);
307
+ if (!hasPrimaryOperation) {
308
+ return { success: false };
309
+ }
310
+ // Loop through all the operations and sign them
311
+ for (let i = 0; i < operations.length; i++) {
312
+ const signature = await signOperation(operations[i]);
313
+ if (!signature) {
314
+ return { success: false };
315
+ }
316
+ signedOperations.push(signature);
317
+ }
318
+ const { operationSetId, operationResponses } = await this.sendSignedOperations(accountClusterId, signedOperations);
319
+ return {
320
+ operationSetId,
321
+ operationResponses,
322
+ success: true,
323
+ primaryOperationStatus: {
324
+ type: OperationType.FINAL_TRANSACTION,
325
+ status: OperationStatusType.WAITING_PRECONDITION,
326
+ },
327
+ };
328
+ }
329
+ }
@@ -1,6 +1,6 @@
1
- import { StandardizedToken } from "../types";
2
- import { LibraryRequest } from "../entities/library_request";
3
- import { LIBRARY_TYPE } from "../enums";
1
+ import { StandardizedToken } from "../types.js";
2
+ import { LibraryRequest } from "../entities/library_request.js";
3
+ import { LIBRARY_TYPE } from "../enums.js";
4
4
  export declare class TokenActions extends LibraryRequest {
5
5
  constructor(library: LIBRARY_TYPE, client?: any, provider?: any);
6
6
  getStandardizedTokenIds(tokens: {