@orb-labs/orby-core 0.0.14 → 0.0.15

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 (137) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/cjs/actions/account_cluster.d.ts +32 -0
  3. package/dist/cjs/actions/account_cluster.js +211 -0
  4. package/dist/cjs/actions/admin.d.ts +17 -0
  5. package/dist/cjs/actions/admin.js +43 -0
  6. package/dist/cjs/actions/application.d.ts +6 -0
  7. package/dist/cjs/actions/application.js +20 -0
  8. package/dist/cjs/actions/blockchain.d.ts +16 -0
  9. package/dist/cjs/actions/blockchain.js +39 -0
  10. package/dist/cjs/actions/instance.d.ts +15 -0
  11. package/dist/cjs/actions/instance.js +98 -0
  12. package/dist/cjs/actions/operation.d.ts +99 -0
  13. package/dist/cjs/actions/operation.js +345 -0
  14. package/dist/cjs/actions/token.d.ts +15 -0
  15. package/dist/cjs/actions/token.js +50 -0
  16. package/dist/cjs/constants.d.ts +14 -0
  17. package/dist/cjs/constants.js +139 -0
  18. package/dist/cjs/entities/account.d.ts +14 -0
  19. package/dist/cjs/entities/account.js +49 -0
  20. package/dist/cjs/entities/financial/account_balance.d.ts +12 -0
  21. package/dist/cjs/entities/financial/account_balance.js +35 -0
  22. package/dist/cjs/entities/financial/asset.d.ts +31 -0
  23. package/dist/cjs/entities/financial/asset.js +42 -0
  24. package/dist/cjs/entities/financial/currency.d.ts +41 -0
  25. package/dist/cjs/entities/financial/currency.js +56 -0
  26. package/dist/cjs/entities/financial/currency_amount.d.ts +34 -0
  27. package/dist/cjs/entities/financial/currency_amount.js +99 -0
  28. package/dist/cjs/entities/financial/fungible_token.d.ts +41 -0
  29. package/dist/cjs/entities/financial/fungible_token.js +68 -0
  30. package/dist/cjs/entities/financial/fungible_token_amount.d.ts +36 -0
  31. package/dist/cjs/entities/financial/fungible_token_amount.js +102 -0
  32. package/dist/cjs/entities/financial/non_fungible_token.d.ts +39 -0
  33. package/dist/cjs/entities/financial/non_fungible_token.js +65 -0
  34. package/dist/cjs/entities/financial/semi_fungible_token.d.ts +41 -0
  35. package/dist/cjs/entities/financial/semi_fungible_token.js +67 -0
  36. package/dist/cjs/entities/library_request.d.ts +8 -0
  37. package/dist/cjs/entities/library_request.js +37 -0
  38. package/dist/cjs/entities/state.d.ts +22 -0
  39. package/dist/cjs/entities/state.js +106 -0
  40. package/dist/cjs/enums.d.ts +116 -0
  41. package/dist/cjs/enums.js +138 -0
  42. package/dist/cjs/index.d.ts +29 -0
  43. package/dist/cjs/index.js +49 -0
  44. package/dist/cjs/interfaces/account_cluster.d.ts +30 -0
  45. package/dist/cjs/interfaces/account_cluster.js +2 -0
  46. package/dist/cjs/interfaces/admin.d.ts +14 -0
  47. package/dist/cjs/interfaces/admin.js +2 -0
  48. package/dist/cjs/interfaces/application.d.ts +3 -0
  49. package/dist/cjs/interfaces/application.js +2 -0
  50. package/dist/cjs/interfaces/blockchain.d.ts +13 -0
  51. package/dist/cjs/interfaces/blockchain.js +2 -0
  52. package/dist/cjs/interfaces/instance.d.ts +12 -0
  53. package/dist/cjs/interfaces/instance.js +2 -0
  54. package/dist/cjs/interfaces/operation.d.ts +97 -0
  55. package/dist/cjs/interfaces/operation.js +2 -0
  56. package/dist/cjs/interfaces/orby.d.ts +9 -0
  57. package/dist/cjs/interfaces/orby.js +2 -0
  58. package/dist/cjs/interfaces/token.d.ts +12 -0
  59. package/dist/cjs/interfaces/token.js +2 -0
  60. package/dist/cjs/types.d.ts +152 -0
  61. package/dist/cjs/types.js +2 -0
  62. package/dist/cjs/utils/action_helpers.d.ts +22 -0
  63. package/dist/cjs/utils/action_helpers.js +274 -0
  64. package/dist/cjs/utils/utils.d.ts +10 -0
  65. package/dist/cjs/utils/utils.js +79 -0
  66. package/dist/cjs/utils/validateAndParseAddress.d.ts +10 -0
  67. package/dist/cjs/utils/validateAndParseAddress.js +29 -0
  68. package/dist/esm/actions/account_cluster.d.ts +32 -0
  69. package/dist/esm/actions/account_cluster.js +207 -0
  70. package/dist/esm/actions/admin.d.ts +17 -0
  71. package/dist/esm/actions/admin.js +39 -0
  72. package/dist/esm/actions/application.d.ts +6 -0
  73. package/dist/esm/actions/application.js +16 -0
  74. package/dist/esm/actions/blockchain.d.ts +16 -0
  75. package/dist/esm/actions/blockchain.js +35 -0
  76. package/dist/esm/actions/instance.d.ts +15 -0
  77. package/dist/esm/actions/instance.js +94 -0
  78. package/dist/esm/actions/operation.d.ts +99 -0
  79. package/dist/esm/actions/operation.js +341 -0
  80. package/dist/esm/actions/token.d.ts +15 -0
  81. package/dist/esm/actions/token.js +46 -0
  82. package/dist/esm/constants.d.ts +14 -0
  83. package/dist/esm/constants.js +133 -0
  84. package/dist/esm/entities/account.d.ts +14 -0
  85. package/dist/esm/entities/account.js +45 -0
  86. package/dist/esm/entities/financial/account_balance.d.ts +12 -0
  87. package/dist/esm/entities/financial/account_balance.js +31 -0
  88. package/dist/esm/entities/financial/asset.d.ts +31 -0
  89. package/dist/esm/entities/financial/asset.js +38 -0
  90. package/dist/esm/entities/financial/currency.d.ts +41 -0
  91. package/dist/esm/entities/financial/currency.js +49 -0
  92. package/dist/esm/entities/financial/currency_amount.d.ts +34 -0
  93. package/dist/esm/entities/financial/currency_amount.js +92 -0
  94. package/dist/esm/entities/financial/fungible_token.d.ts +41 -0
  95. package/dist/esm/entities/financial/fungible_token.js +64 -0
  96. package/dist/esm/entities/financial/fungible_token_amount.d.ts +36 -0
  97. package/dist/esm/entities/financial/fungible_token_amount.js +95 -0
  98. package/dist/esm/entities/financial/non_fungible_token.d.ts +39 -0
  99. package/dist/esm/entities/financial/non_fungible_token.js +61 -0
  100. package/dist/esm/entities/financial/semi_fungible_token.d.ts +41 -0
  101. package/dist/esm/entities/financial/semi_fungible_token.js +63 -0
  102. package/dist/esm/entities/library_request.d.ts +8 -0
  103. package/dist/esm/entities/library_request.js +30 -0
  104. package/dist/esm/entities/state.d.ts +22 -0
  105. package/dist/esm/entities/state.js +102 -0
  106. package/dist/esm/enums.d.ts +116 -0
  107. package/dist/esm/enums.js +135 -0
  108. package/dist/esm/index.d.ts +29 -0
  109. package/dist/esm/index.js +33 -0
  110. package/dist/esm/interfaces/account_cluster.d.ts +30 -0
  111. package/dist/esm/interfaces/account_cluster.js +1 -0
  112. package/dist/esm/interfaces/admin.d.ts +14 -0
  113. package/dist/esm/interfaces/admin.js +1 -0
  114. package/dist/esm/interfaces/application.d.ts +3 -0
  115. package/dist/esm/interfaces/application.js +1 -0
  116. package/dist/esm/interfaces/blockchain.d.ts +13 -0
  117. package/dist/esm/interfaces/blockchain.js +1 -0
  118. package/dist/esm/interfaces/instance.d.ts +12 -0
  119. package/dist/esm/interfaces/instance.js +1 -0
  120. package/dist/esm/interfaces/operation.d.ts +97 -0
  121. package/dist/esm/interfaces/operation.js +1 -0
  122. package/dist/esm/interfaces/orby.d.ts +9 -0
  123. package/dist/esm/interfaces/orby.js +1 -0
  124. package/dist/esm/interfaces/token.d.ts +12 -0
  125. package/dist/esm/interfaces/token.js +1 -0
  126. package/dist/esm/types.d.ts +152 -0
  127. package/dist/esm/types.js +1 -0
  128. package/dist/esm/utils/action_helpers.d.ts +22 -0
  129. package/dist/esm/utils/action_helpers.js +250 -0
  130. package/dist/esm/utils/utils.d.ts +10 -0
  131. package/dist/esm/utils/utils.js +70 -0
  132. package/dist/esm/utils/validateAndParseAddress.d.ts +10 -0
  133. package/dist/esm/utils/validateAndParseAddress.js +25 -0
  134. package/dist/tsconfig.cjs.tsbuildinfo +1 -0
  135. package/dist/tsconfig.esm.tsbuildinfo +1 -0
  136. package/dist/tsconfig.tsbuildinfo +1 -1
  137. package/package.json +16 -7
@@ -0,0 +1,99 @@
1
+ import { OnchainOperation, OperationSet, OperationStatus, SignedOperation } from "../types.js";
2
+ import { CurrencyAmount } from "../entities/financial/currency_amount.js";
3
+ import { LIBRARY_TYPE, OperationStatusType, QuoteType } from "../enums.js";
4
+ import { LibraryRequest } from "../entities/library_request.js";
5
+ export declare class OperationActions extends LibraryRequest {
6
+ constructor(library: LIBRARY_TYPE, client?: any, provider?: any);
7
+ getOperationsToExecuteTransaction(accountClusterId: string, to: string, data: string, value?: bigint, gasToken?: {
8
+ standardizedTokenId: string;
9
+ tokenSources?: {
10
+ chainId: bigint;
11
+ address?: string;
12
+ }[];
13
+ }): Promise<OperationSet>;
14
+ getOperationsToSignTypedData(accountClusterId: string, data: string, gasToken?: {
15
+ standardizedTokenId: string;
16
+ tokenSources?: {
17
+ chainId: bigint;
18
+ address?: string;
19
+ }[];
20
+ }): Promise<OperationSet>;
21
+ getOperationsToCancelTransaction(accountClusterId: string, operationSetId: string): Promise<OperationSet>;
22
+ isTransactionPreconditionSatisfied(accountClusterId: string, to: string, data: string, value?: bigint): Promise<boolean>;
23
+ isTypedDataPreconditionSatisfied(accountClusterId: string, data: string): Promise<boolean>;
24
+ sendSignedOperations(accountClusterId: string, signedOperations: SignedOperation[]): Promise<{
25
+ operationSetId: string;
26
+ operationResponses: OperationStatus[];
27
+ }>;
28
+ getOperationStatuses(operationIds: string[]): Promise<OperationStatus[]>;
29
+ estimateFiatCostToExecuteTransaction(to: string, data: string, value?: bigint): Promise<CurrencyAmount>;
30
+ estimateFiatCostToSignTypedData(data: string): Promise<CurrencyAmount>;
31
+ getOperationsToTransferToken(accountClusterId: string, standardizedTokenId: string, amount: bigint, recipient: {
32
+ chainId: bigint;
33
+ recipientAddress: string;
34
+ }, gasToken?: {
35
+ standardizedTokenId: string;
36
+ tokenSources?: {
37
+ chainId: bigint;
38
+ address?: string;
39
+ }[];
40
+ }): Promise<OperationSet>;
41
+ getOperationsToSwap(accountClusterId: string, swapType: QuoteType, input: {
42
+ standardizedTokenId: string;
43
+ amount?: bigint;
44
+ tokenSources?: {
45
+ chainId: bigint;
46
+ address?: string;
47
+ }[];
48
+ }, output: {
49
+ standardizedTokenId: string;
50
+ amount?: bigint;
51
+ tokenDestination?: {
52
+ chainId: bigint;
53
+ address?: string;
54
+ };
55
+ }, gasToken?: {
56
+ standardizedTokenId: string;
57
+ tokenSources?: {
58
+ chainId: bigint;
59
+ address?: string;
60
+ }[];
61
+ }): Promise<OperationSet>;
62
+ getQuote(accountClusterId: string, swapType: QuoteType, input: {
63
+ standardizedTokenId: string;
64
+ amount?: bigint;
65
+ tokenSources?: {
66
+ chainId: bigint;
67
+ address?: string;
68
+ }[];
69
+ }, output: {
70
+ standardizedTokenId: string;
71
+ amount?: bigint;
72
+ tokenDestination?: {
73
+ chainId: bigint;
74
+ address?: string;
75
+ };
76
+ }): Promise<OperationSet>;
77
+ getOperationsToBridge(accountClusterId: string, standardizedTokenId: string, amount: bigint, tokenSources?: {
78
+ chainId: bigint;
79
+ address?: string;
80
+ }[], tokenDestination?: {
81
+ chainId: bigint;
82
+ address?: string;
83
+ }, gasToken?: {
84
+ standardizedTokenId: string;
85
+ tokenSources?: {
86
+ chainId: bigint;
87
+ address?: string;
88
+ }[];
89
+ }): Promise<OperationSet>;
90
+ subscribeToOperationStatuses(ids?: string[], onOperationStatusesUpdateCallback?: (statusSummary: OperationStatusType, primaryOperationStatus?: OperationStatus, allOperationStatuses?: OperationStatus[]) => void, timout?: number): {
91
+ intervalId: NodeJS.Timeout | null;
92
+ };
93
+ sendOperationSet(accountClusterId: string, operationSet: OperationSet, signOperation: (operation: OnchainOperation) => Promise<SignedOperation | undefined>): Promise<{
94
+ success: boolean;
95
+ operationSetId?: string;
96
+ primaryOperationStatus?: OperationStatus;
97
+ operationResponses?: OperationStatus[];
98
+ }>;
99
+ }
@@ -0,0 +1,341 @@
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
+ })),
18
+ }
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);
30
+ }
31
+ async getOperationsToSignTypedData(accountClusterId, data, gasToken) {
32
+ const formattedGasToken = gasToken
33
+ ? {
34
+ ...gasToken,
35
+ tokenSources: gasToken.tokenSources?.map(({ chainId, address }) => ({
36
+ chainId: getOrbyChainId(chainId),
37
+ address,
38
+ })),
39
+ }
40
+ : undefined;
41
+ const operationSet = await this.sendRequest("orby_getOperationsToSignTypedData", [
42
+ {
43
+ accountClusterId,
44
+ data,
45
+ gasToken: formattedGasToken,
46
+ },
47
+ ]);
48
+ return extractOperationSet(operationSet);
49
+ }
50
+ async getOperationsToCancelTransaction(accountClusterId, operationSetId) {
51
+ const operationSet = await this.sendRequest("orby_getOperationsToCancelTransaction", [
52
+ {
53
+ accountClusterId,
54
+ operationSetId,
55
+ },
56
+ ]);
57
+ return extractOperationSet(operationSet);
58
+ }
59
+ async isTransactionPreconditionSatisfied(accountClusterId, to, data, value) {
60
+ const { satisfied } = await this.sendRequest("orby_isTransactionPreconditionSatisfied", [
61
+ {
62
+ accountClusterId,
63
+ to,
64
+ data,
65
+ value,
66
+ },
67
+ ]);
68
+ return satisfied;
69
+ }
70
+ async isTypedDataPreconditionSatisfied(accountClusterId, data) {
71
+ const { satisfied, code, message } = await this.sendRequest("orby_isTypedDataPreconditionSatisfied", [
72
+ {
73
+ accountClusterId,
74
+ data,
75
+ },
76
+ ]);
77
+ if (code && message) {
78
+ console.error("[isTypedDataPreconditionSatisfied]", code, message);
79
+ return undefined;
80
+ }
81
+ return satisfied;
82
+ }
83
+ async sendSignedOperations(accountClusterId, signedOperations) {
84
+ const { operationSetId, operationResponses, code, message } = await this.sendRequest("orby_sendSignedOperations", [
85
+ {
86
+ accountClusterId,
87
+ signedOperations,
88
+ },
89
+ ]);
90
+ if (code && message) {
91
+ console.error("[sendSignedOperations]", code, message);
92
+ return undefined;
93
+ }
94
+ return {
95
+ operationSetId,
96
+ operationResponses: extractOperationStatuses(operationResponses),
97
+ };
98
+ }
99
+ async getOperationStatuses(operationIds) {
100
+ const { operationStatuses } = await this.sendRequest("orby_getOperationStatuses", [{ operationIds }]);
101
+ return extractOperationStatuses(operationStatuses);
102
+ }
103
+ async estimateFiatCostToExecuteTransaction(to, data, value) {
104
+ const { estimatedCost, code, message } = await this.sendRequest("orby_estimateFiatCostToExecuteTransaction", [
105
+ {
106
+ to,
107
+ data,
108
+ value,
109
+ },
110
+ ]);
111
+ if (code && message) {
112
+ console.error("[estimateFiatCostToExecuteTransaction]", code, message);
113
+ return undefined;
114
+ }
115
+ return CurrencyAmount.toCurrencyAmount(estimatedCost);
116
+ }
117
+ async estimateFiatCostToSignTypedData(data) {
118
+ const { estimatedCost, code, message } = await this.sendRequest("orby_estimateFiatCostToSignTypedData", [{ data }]);
119
+ if (code && message) {
120
+ console.error("[estimateFiatCostToSignTypedData]", code, message);
121
+ return undefined;
122
+ }
123
+ return CurrencyAmount.toCurrencyAmount(estimatedCost);
124
+ }
125
+ async getOperationsToTransferToken(accountClusterId, standardizedTokenId, amount, recipient, gasToken) {
126
+ const formattedGasToken = gasToken
127
+ ? {
128
+ ...gasToken,
129
+ tokenSources: gasToken.tokenSources?.map(({ chainId, address }) => ({
130
+ chainId: getOrbyChainId(chainId),
131
+ address,
132
+ })),
133
+ }
134
+ : undefined;
135
+ const formattedRecepient = {
136
+ chainId: getOrbyChainId(recipient.chainId),
137
+ recipientAddress: recipient.recipientAddress,
138
+ };
139
+ const operationSet = await this.sendRequest("orby_getOperationsToTransferToken", [
140
+ {
141
+ accountClusterId,
142
+ standardizedTokenId,
143
+ amount,
144
+ recipient: formattedRecepient,
145
+ gasToken: formattedGasToken,
146
+ },
147
+ ]);
148
+ return extractOperationSet(operationSet);
149
+ }
150
+ async getOperationsToSwap(accountClusterId, swapType, input, output, gasToken) {
151
+ const formattedInput = input
152
+ ? {
153
+ ...input,
154
+ tokenSources: input?.tokenSources.map(({ chainId, address }) => ({
155
+ chainId: getOrbyChainId(chainId),
156
+ address,
157
+ })),
158
+ }
159
+ : undefined;
160
+ const formattedOutput = output
161
+ ? {
162
+ ...output,
163
+ tokenDestination: output?.tokenDestination
164
+ ? {
165
+ chainId: getOrbyChainId(output.tokenDestination.chainId),
166
+ address: output.tokenDestination.address,
167
+ }
168
+ : undefined,
169
+ }
170
+ : undefined;
171
+ const formattedGasToken = gasToken
172
+ ? {
173
+ ...gasToken,
174
+ tokenSources: gasToken.tokenSources?.map(({ chainId, address }) => ({
175
+ chainId: getOrbyChainId(chainId),
176
+ address,
177
+ })),
178
+ }
179
+ : undefined;
180
+ const operationSet = await this.sendRequest("orby_getOperationsToSwap", [
181
+ {
182
+ accountClusterId,
183
+ swapType,
184
+ input: formattedInput,
185
+ output: formattedOutput,
186
+ gasToken: formattedGasToken,
187
+ },
188
+ ]);
189
+ return extractOperationSet(operationSet);
190
+ }
191
+ async getQuote(accountClusterId, swapType, input, output) {
192
+ const formattedInput = input
193
+ ? {
194
+ ...input,
195
+ tokenSources: input?.tokenSources.map(({ chainId, address }) => ({
196
+ chainId: getOrbyChainId(chainId),
197
+ address,
198
+ })),
199
+ }
200
+ : undefined;
201
+ const formattedOutput = output
202
+ ? {
203
+ ...output,
204
+ tokenDestination: output?.tokenDestination
205
+ ? {
206
+ chainId: getOrbyChainId(output.tokenDestination.chainId),
207
+ address: output.tokenDestination.address,
208
+ }
209
+ : undefined,
210
+ }
211
+ : undefined;
212
+ const operationSet = await this.sendRequest("orby_getQuote", [
213
+ {
214
+ accountClusterId,
215
+ swapType,
216
+ input: formattedInput,
217
+ output: formattedOutput,
218
+ },
219
+ ]);
220
+ return extractOperationSet(operationSet);
221
+ }
222
+ async getOperationsToBridge(accountClusterId, standardizedTokenId, amount, tokenSources, tokenDestination, gasToken) {
223
+ const formattedTokenSources = tokenSources.map(({ chainId, address }) => ({
224
+ chainId: getOrbyChainId(chainId),
225
+ address,
226
+ }));
227
+ const formattedDestination = tokenDestination
228
+ ? {
229
+ chainId: getOrbyChainId(tokenDestination.chainId),
230
+ address: tokenDestination.address,
231
+ }
232
+ : undefined;
233
+ const formattedGasToken = gasToken
234
+ ? {
235
+ ...gasToken,
236
+ tokenSources: gasToken.tokenSources?.map(({ chainId, address }) => ({
237
+ chainId: getOrbyChainId(chainId),
238
+ address,
239
+ })),
240
+ }
241
+ : undefined;
242
+ const operationSet = await this.sendRequest("orby_getOperationsToBridge", [
243
+ {
244
+ accountClusterId,
245
+ standardizedTokenId,
246
+ amount,
247
+ tokenSources: formattedTokenSources,
248
+ tokenDestination: formattedDestination,
249
+ gasToken: formattedGasToken,
250
+ },
251
+ ]);
252
+ return extractOperationSet(operationSet);
253
+ }
254
+ subscribeToOperationStatuses(ids, onOperationStatusesUpdateCallback, timout) {
255
+ let intervalId = null;
256
+ let totalWaitTime = 0;
257
+ const timeoutOrDefault = timout ?? 300_000;
258
+ if (ids && ids?.length > 0) {
259
+ const waitTime = 500;
260
+ intervalId = setInterval(async () => {
261
+ let statusSummary = OperationStatusType.WAITING_PRECONDITION;
262
+ let primaryOperation;
263
+ try {
264
+ const statuses = ids && ids?.length > 0
265
+ ? await this?.getOperationStatuses(ids)
266
+ : undefined;
267
+ if (!ids || ids?.length == 0) {
268
+ statusSummary = OperationStatusType.NOT_FOUND;
269
+ }
270
+ else if (!statuses) {
271
+ statusSummary = OperationStatusType.NOT_FOUND;
272
+ }
273
+ else if (statuses.some((status) => status.status == OperationStatusType.FAILED)) {
274
+ statusSummary = OperationStatusType.FAILED;
275
+ }
276
+ else if (statuses.every((status) => status.status == OperationStatusType.SUCCESSFUL)) {
277
+ statusSummary = OperationStatusType.SUCCESSFUL;
278
+ }
279
+ primaryOperation = statuses?.find((status) => status.type == OperationType.FINAL_TRANSACTION);
280
+ if (primaryOperation?.status == OperationStatusType.PENDING) {
281
+ statusSummary = OperationStatusType.PENDING;
282
+ }
283
+ onOperationStatusesUpdateCallback?.(statusSummary, primaryOperation, statuses);
284
+ }
285
+ catch (error) {
286
+ console.error("[useWaitForStatusCompletion]", error);
287
+ }
288
+ finally {
289
+ totalWaitTime += waitTime;
290
+ if (intervalId &&
291
+ OperationStatusType.WAITING_PRECONDITION != statusSummary) {
292
+ clearInterval(intervalId);
293
+ intervalId = null;
294
+ }
295
+ else if (intervalId && totalWaitTime >= timeoutOrDefault) {
296
+ // we cant wait for more than 2 ETH blocks
297
+ clearInterval(intervalId);
298
+ intervalId = null;
299
+ }
300
+ }
301
+ }, waitTime);
302
+ }
303
+ return { intervalId };
304
+ }
305
+ async sendOperationSet(accountClusterId, operationSet, signOperation) {
306
+ const signedOperations = [];
307
+ const operations = operationSet.intents
308
+ ?.map((intent) => intent.intentOperations)
309
+ .flat()
310
+ ?.concat(operationSet.primaryOperation)
311
+ .filter((value) => value != undefined && value != null);
312
+ if (operations?.length == 0) {
313
+ return { success: true, operationResponses: [] };
314
+ }
315
+ else if (!operations) {
316
+ return { success: false };
317
+ }
318
+ const hasPrimaryOperation = operations.find((operation) => operation.type == OperationType.FINAL_TRANSACTION);
319
+ if (!hasPrimaryOperation) {
320
+ return { success: false };
321
+ }
322
+ // Loop through all the operations and sign them
323
+ for (let i = 0; i < operations.length; i++) {
324
+ const signature = await signOperation(operations[i]);
325
+ if (!signature) {
326
+ return { success: false };
327
+ }
328
+ signedOperations.push(signature);
329
+ }
330
+ const { operationSetId, operationResponses } = await this.sendSignedOperations(accountClusterId, signedOperations);
331
+ return {
332
+ operationSetId,
333
+ operationResponses,
334
+ success: true,
335
+ primaryOperationStatus: {
336
+ type: OperationType.FINAL_TRANSACTION,
337
+ status: OperationStatusType.WAITING_PRECONDITION,
338
+ },
339
+ };
340
+ }
341
+ }
@@ -0,0 +1,15 @@
1
+ import { StandardizedToken } from "../types.js";
2
+ import { LibraryRequest } from "../entities/library_request.js";
3
+ import { LIBRARY_TYPE } from "../enums.js";
4
+ export declare class TokenActions extends LibraryRequest {
5
+ constructor(library: LIBRARY_TYPE, client?: any, provider?: any);
6
+ getStandardizedTokenIds(tokens: {
7
+ tokenAddress: string;
8
+ chainId: bigint;
9
+ }[]): Promise<string[]>;
10
+ getStandardizedTokens(tokens: {
11
+ tokenAddress: string;
12
+ chainId: bigint;
13
+ }[]): Promise<StandardizedToken[]>;
14
+ getFungibleTokenData(standardizedTokenIds: string[]): Promise<StandardizedToken[]>;
15
+ }
@@ -0,0 +1,46 @@
1
+ import { extractStandardizedTokens, } from "../utils/action_helpers.js";
2
+ import { LibraryRequest } from "../entities/library_request.js";
3
+ import { getOrbyChainId } from "../utils/utils.js";
4
+ export class TokenActions extends LibraryRequest {
5
+ constructor(library, client, provider) {
6
+ super(library, client, provider);
7
+ }
8
+ async getStandardizedTokenIds(tokens) {
9
+ const formattedTokensInfo = tokens.map(({ tokenAddress, chainId }) => {
10
+ return { chainId: getOrbyChainId(chainId), tokenAddress };
11
+ });
12
+ const { standardizedTokenIds, message, code } = await this.sendRequest("orby_getStandardizedTokenIds", [
13
+ {
14
+ tokens: formattedTokensInfo,
15
+ },
16
+ ]);
17
+ if (code && message) {
18
+ console.error("[getStandardizedTokenIds]", code, message);
19
+ return undefined;
20
+ }
21
+ return standardizedTokenIds;
22
+ }
23
+ async getStandardizedTokens(tokens) {
24
+ const formattedTokensInfo = tokens.map(({ tokenAddress, chainId }) => {
25
+ return { chainId: getOrbyChainId(chainId), tokenAddress };
26
+ });
27
+ const { standardizedTokens, message, code } = await this.sendRequest("orby_getStandardizedTokens", [
28
+ {
29
+ tokens: formattedTokensInfo,
30
+ },
31
+ ]);
32
+ if (code && message) {
33
+ console.error("[getStandardizedTokens]", code, message);
34
+ return undefined;
35
+ }
36
+ return extractStandardizedTokens(standardizedTokens);
37
+ }
38
+ async getFungibleTokenData(standardizedTokenIds) {
39
+ const { data, message, code } = await this.sendRequest("orby_getFungibleTokenData", [{ standardizedTokenIds }]);
40
+ if (code && message) {
41
+ console.error("[getFungibleTokenData]", code, message);
42
+ return undefined;
43
+ }
44
+ return extractStandardizedTokens(data);
45
+ }
46
+ }
@@ -0,0 +1,14 @@
1
+ import { Blockchain } from "./enums.js";
2
+ import { Currency } from "./entities/financial/currency.js";
3
+ import { ChainConfigs } from "./types.js";
4
+ export declare const Big: any;
5
+ export declare const BLOCKCHAIN_ID: {
6
+ [s: string]: number;
7
+ };
8
+ export declare const CHAIN_CONFIGS: {
9
+ [s: string]: ChainConfigs;
10
+ };
11
+ export declare const BLOCKCHAIN_ID_TO_BLOCKCHAIN: {
12
+ [s: number]: Blockchain;
13
+ };
14
+ export declare const FIAT_CURRENCY: Currency;
@@ -0,0 +1,133 @@
1
+ import toFormat from "toformat";
2
+ import _Big from "big.js";
3
+ import { Blockchain, BlockchainEnvironment } from "./enums.js";
4
+ import { Currency } from "./entities/financial/currency.js";
5
+ export const Big = toFormat(_Big);
6
+ export const BLOCKCHAIN_ID = {
7
+ [Blockchain.ETHEREUM]: 1,
8
+ [Blockchain.POLYGON]: 137,
9
+ [Blockchain.BINANCE]: 56,
10
+ [Blockchain.ARBITRUM]: 42161,
11
+ [Blockchain.ARBITRUM_NOVA]: 42170,
12
+ [Blockchain.OPTIMISM]: 10,
13
+ [Blockchain.EVMOS]: 9001,
14
+ [Blockchain.MOONBEAM]: 1284,
15
+ [Blockchain.BASE]: 8453,
16
+ [Blockchain.AVALANCHE]: 43114,
17
+ // testnets
18
+ [Blockchain.ETHEREUM_SEPOLIA]: 11155111,
19
+ [Blockchain.ETHEREUM_HOLESKY]: 17000,
20
+ [Blockchain.ARBITRUM_SEPOLIA]: 421614,
21
+ [Blockchain.OPTIMISM_SEPOLIA]: 11155420,
22
+ [Blockchain.POLYGON_AMOY]: 80002,
23
+ [Blockchain.BINANCE_TESTNET]: 97,
24
+ [Blockchain.OPBNB_TESTNET]: 5611,
25
+ [Blockchain.MOONBEAM_ALPHA]: 1287,
26
+ [Blockchain.BASE_SEPOLIA]: 84532,
27
+ // local testing
28
+ [Blockchain.HARDHAT]: 31337,
29
+ [Blockchain.LOCAL_CHAIN_0]: 1_000_000_000_001,
30
+ [Blockchain.LOCAL_CHAIN_1]: 1_000_000_000_002,
31
+ };
32
+ export const CHAIN_CONFIGS = {
33
+ [Blockchain.ETHEREUM]: {
34
+ environment: BlockchainEnvironment.MAINNET,
35
+ chainId: BigInt(1),
36
+ },
37
+ [Blockchain.POLYGON]: {
38
+ environment: BlockchainEnvironment.MAINNET,
39
+ chainId: BigInt(137),
40
+ },
41
+ [Blockchain.BINANCE]: {
42
+ environment: BlockchainEnvironment.MAINNET,
43
+ chainId: BigInt(56),
44
+ },
45
+ [Blockchain.ARBITRUM]: {
46
+ environment: BlockchainEnvironment.MAINNET,
47
+ chainId: BigInt(42161),
48
+ },
49
+ [Blockchain.ARBITRUM_NOVA]: {
50
+ environment: BlockchainEnvironment.MAINNET,
51
+ chainId: BigInt(42170),
52
+ },
53
+ [Blockchain.OPTIMISM]: {
54
+ environment: BlockchainEnvironment.MAINNET,
55
+ chainId: BigInt(10),
56
+ },
57
+ [Blockchain.EVMOS]: {
58
+ environment: BlockchainEnvironment.MAINNET,
59
+ chainId: BigInt(9001),
60
+ },
61
+ [Blockchain.MOONBEAM]: {
62
+ environment: BlockchainEnvironment.MAINNET,
63
+ chainId: BigInt(1284),
64
+ },
65
+ [Blockchain.BASE]: {
66
+ environment: BlockchainEnvironment.MAINNET,
67
+ chainId: BigInt(8453),
68
+ },
69
+ [Blockchain.AVALANCHE]: {
70
+ environment: BlockchainEnvironment.MAINNET,
71
+ chainId: BigInt(43114),
72
+ },
73
+ // testnets
74
+ [Blockchain.ETHEREUM_SEPOLIA]: {
75
+ environment: BlockchainEnvironment.TESTNET,
76
+ chainId: BigInt(11155111),
77
+ },
78
+ [Blockchain.ETHEREUM_HOLESKY]: {
79
+ environment: BlockchainEnvironment.TESTNET,
80
+ chainId: BigInt(17000),
81
+ },
82
+ [Blockchain.ARBITRUM_SEPOLIA]: {
83
+ environment: BlockchainEnvironment.TESTNET,
84
+ chainId: BigInt(421614),
85
+ },
86
+ [Blockchain.BASE_SEPOLIA]: {
87
+ environment: BlockchainEnvironment.TESTNET,
88
+ chainId: BigInt(84532),
89
+ },
90
+ [Blockchain.OPTIMISM_SEPOLIA]: {
91
+ environment: BlockchainEnvironment.TESTNET,
92
+ chainId: BigInt(11155420),
93
+ },
94
+ [Blockchain.BINANCE_TESTNET]: {
95
+ environment: BlockchainEnvironment.TESTNET,
96
+ chainId: BigInt(97),
97
+ },
98
+ [Blockchain.OPBNB_TESTNET]: {
99
+ environment: BlockchainEnvironment.TESTNET,
100
+ chainId: BigInt(5611),
101
+ },
102
+ [Blockchain.MOONBEAM_ALPHA]: {
103
+ environment: BlockchainEnvironment.TESTNET,
104
+ chainId: BigInt(1287),
105
+ },
106
+ [Blockchain.POLYGON_AMOY]: {
107
+ environment: BlockchainEnvironment.TESTNET,
108
+ chainId: BigInt(80002),
109
+ },
110
+ };
111
+ export const BLOCKCHAIN_ID_TO_BLOCKCHAIN = {
112
+ [1]: Blockchain.ETHEREUM,
113
+ [137]: Blockchain.POLYGON,
114
+ [56]: Blockchain.BINANCE,
115
+ [42161]: Blockchain.ARBITRUM,
116
+ [42170]: Blockchain.ARBITRUM_NOVA,
117
+ [10]: Blockchain.OPTIMISM,
118
+ [9001]: Blockchain.EVMOS,
119
+ [1284]: Blockchain.MOONBEAM,
120
+ [8453]: Blockchain.BASE,
121
+ [43114]: Blockchain.AVALANCHE,
122
+ // testnets
123
+ [11155111]: Blockchain.ETHEREUM_SEPOLIA,
124
+ [84532]: Blockchain.BASE_SEPOLIA,
125
+ [17000]: Blockchain.ETHEREUM_HOLESKY,
126
+ [421614]: Blockchain.ARBITRUM_SEPOLIA,
127
+ [11155420]: Blockchain.OPTIMISM_SEPOLIA,
128
+ [80002]: Blockchain.POLYGON_AMOY,
129
+ [97]: Blockchain.BINANCE_TESTNET,
130
+ [5611]: Blockchain.OPBNB_TESTNET,
131
+ [1287]: Blockchain.MOONBEAM_ALPHA,
132
+ };
133
+ export const FIAT_CURRENCY = new Currency(6, "USD", "US Dollar", undefined, false, false);
@@ -0,0 +1,14 @@
1
+ import { AccountType, VMType } from "../enums.js";
2
+ export declare class Account {
3
+ readonly address: string;
4
+ readonly chainId?: bigint;
5
+ readonly accountType: AccountType;
6
+ readonly vmType: VMType;
7
+ readonly key: string;
8
+ hasSufficientBalanceForGas: boolean;
9
+ static toAccount(account: any): Account;
10
+ constructor(address: string, accountType: AccountType, vmType: VMType, chainId?: bigint);
11
+ static key(address: string, chainId?: bigint): string;
12
+ toAccountModel(): any;
13
+ equals(other: Account): boolean;
14
+ }