@orb-labs/orby-core 0.0.26 → 0.0.28
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/CHANGELOG.md +11 -1
- package/dist/cjs/actions/blockchain.js +2 -1
- package/dist/cjs/actions/operation.d.ts +5 -1
- package/dist/cjs/actions/operation.js +66 -64
- package/dist/cjs/constants.d.ts +2 -2
- package/dist/cjs/entities/library_request.d.ts +13 -0
- package/dist/cjs/entities/library_request.js +12 -0
- package/dist/cjs/enums.d.ts +11 -2
- package/dist/cjs/enums.js +10 -1
- package/dist/cjs/interfaces/operation.d.ts +5 -1
- package/dist/cjs/types.d.ts +8 -12
- package/dist/cjs/utils/action_helpers.d.ts +1 -1
- package/dist/cjs/utils/action_helpers.js +23 -28
- package/dist/cjs/utils/utils.d.ts +3 -0
- package/dist/cjs/utils/utils.js +20 -6
- package/dist/esm/actions/blockchain.js +2 -1
- package/dist/esm/actions/operation.d.ts +5 -1
- package/dist/esm/actions/operation.js +68 -66
- package/dist/esm/constants.d.ts +2 -2
- package/dist/esm/entities/library_request.d.ts +13 -0
- package/dist/esm/entities/library_request.js +12 -0
- package/dist/esm/enums.d.ts +11 -2
- package/dist/esm/enums.js +10 -1
- package/dist/esm/interfaces/operation.d.ts +5 -1
- package/dist/esm/types.d.ts +8 -12
- package/dist/esm/utils/action_helpers.d.ts +1 -1
- package/dist/esm/utils/action_helpers.js +21 -26
- package/dist/esm/utils/utils.d.ts +3 -0
- package/dist/esm/utils/utils.js +17 -5
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +1 -1
@@ -1,4 +1,4 @@
|
|
1
|
-
import { AccountCluster, OnchainOperation, OperationSet, OperationStatus, SignedOperation, UserOperation } from "../types.js";
|
1
|
+
import { AccountCluster, Activity, OnchainOperation, OperationSet, OperationStatus, SignedOperation, UserOperation } from "../types.js";
|
2
2
|
import { CurrencyAmount } from "../entities/financial/currency_amount.js";
|
3
3
|
import { LIBRARY_TYPE, OperationStatusType, QuoteType } from "../enums.js";
|
4
4
|
import { LibraryRequest } from "../entities/library_request.js";
|
@@ -32,6 +32,7 @@ export declare class OperationActions extends LibraryRequest {
|
|
32
32
|
operationSetId: string;
|
33
33
|
operationResponses: OperationStatus[];
|
34
34
|
}>;
|
35
|
+
getOperationSet(operationSetId: string): Promise<Activity>;
|
35
36
|
getOperationStatuses(operationIds: string[]): Promise<OperationStatus[]>;
|
36
37
|
estimateFiatCostToExecuteTransaction(data: string, to?: string, value?: bigint): Promise<CurrencyAmount>;
|
37
38
|
estimateFiatCostToSignTypedData(data: string): Promise<CurrencyAmount>;
|
@@ -94,6 +95,9 @@ export declare class OperationActions extends LibraryRequest {
|
|
94
95
|
address?: string;
|
95
96
|
}[];
|
96
97
|
}): Promise<OperationSet>;
|
98
|
+
subscribeToOperationSetStatus(operationSetId?: string, onOperationSetStatusUpdateCallback?: (activity?: Activity) => void, timeout?: number): {
|
99
|
+
intervalId: NodeJS.Timeout | null;
|
100
|
+
};
|
97
101
|
subscribeToOperationStatuses(ids?: string[], onOperationStatusesUpdateCallback?: (statusSummary: OperationStatusType, primaryOperationStatus?: OperationStatus, allOperationStatuses?: OperationStatus[]) => void, timout?: number): {
|
98
102
|
intervalId: NodeJS.Timeout | null;
|
99
103
|
};
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import { extractOperationSet, extractOperationStatuses, } from "../utils/action_helpers.js";
|
1
|
+
import { extractActivity, extractOperationSet, extractOperationStatuses, } from "../utils/action_helpers.js";
|
2
2
|
import { CurrencyAmount } from "../entities/financial/currency_amount.js";
|
3
|
-
import { AccountType, OperationDataFormat, OperationStatusType, OperationType, } from "../enums.js";
|
3
|
+
import { AccountType, ActivityStatus, OperationDataFormat, OperationStatusType, OperationType, } from "../enums.js";
|
4
4
|
import { LibraryRequest } from "../entities/library_request.js";
|
5
5
|
import { Account } from "../entities/account.js";
|
6
6
|
// from here: https://stackoverflow.com/questions/65152373/typescript-serialize-bigint-in-json
|
@@ -12,62 +12,35 @@ export class OperationActions extends LibraryRequest {
|
|
12
12
|
super(library, client, provider);
|
13
13
|
}
|
14
14
|
async getOperationsToExecuteTransaction(accountClusterId, data, to, value, gasToken) {
|
15
|
-
const formattedGasToken = gasToken
|
16
|
-
? {
|
17
|
-
...gasToken,
|
18
|
-
tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
|
19
|
-
chainId: await this.getOrbyChainId(chainId),
|
20
|
-
address,
|
21
|
-
}))),
|
22
|
-
}
|
23
|
-
: undefined;
|
24
15
|
const operationSet = await this.sendRequest("orby_getOperationsToExecuteTransaction", [
|
25
16
|
{
|
26
17
|
accountClusterId,
|
27
18
|
to,
|
28
19
|
data,
|
29
20
|
value,
|
30
|
-
gasToken:
|
21
|
+
gasToken: await this.formatGasToken(gasToken),
|
31
22
|
},
|
32
23
|
]);
|
33
24
|
return extractOperationSet(operationSet);
|
34
25
|
}
|
35
26
|
async getOperationsToSignTypedData(accountClusterId, data, gasToken) {
|
36
|
-
const formattedGasToken = gasToken
|
37
|
-
? {
|
38
|
-
...gasToken,
|
39
|
-
tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
|
40
|
-
chainId: await this.getOrbyChainId(chainId),
|
41
|
-
address,
|
42
|
-
}))),
|
43
|
-
}
|
44
|
-
: undefined;
|
45
27
|
const operationSet = await this.sendRequest("orby_getOperationsToSignTypedData", [
|
46
28
|
{
|
47
29
|
accountClusterId,
|
48
30
|
data,
|
49
|
-
gasToken:
|
31
|
+
gasToken: await this.formatGasToken(gasToken),
|
50
32
|
},
|
51
33
|
]);
|
52
34
|
return extractOperationSet(operationSet);
|
53
35
|
}
|
54
36
|
async getOperationsToSignTransactionOrSignTypedData(accountClusterId, data, to, value, gasToken) {
|
55
|
-
const formattedGasToken = gasToken
|
56
|
-
? {
|
57
|
-
...gasToken,
|
58
|
-
tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
|
59
|
-
chainId: await this.getOrbyChainId(chainId),
|
60
|
-
address,
|
61
|
-
}))),
|
62
|
-
}
|
63
|
-
: undefined;
|
64
37
|
const operationSet = await this.sendRequest("orby_getOperationsToSignTransactionOrSignTypedData", [
|
65
38
|
{
|
66
39
|
accountClusterId,
|
67
40
|
to,
|
68
41
|
data,
|
69
42
|
value,
|
70
|
-
gasToken:
|
43
|
+
gasToken: await this.formatGasToken(gasToken),
|
71
44
|
},
|
72
45
|
]);
|
73
46
|
return extractOperationSet(operationSet);
|
@@ -121,6 +94,14 @@ export class OperationActions extends LibraryRequest {
|
|
121
94
|
operationResponses: extractOperationStatuses(operationResponses),
|
122
95
|
};
|
123
96
|
}
|
97
|
+
async getOperationSet(operationSetId) {
|
98
|
+
const { activity, code, message } = await this.sendRequest("orby_getOperationSet", [{ operationSetId }]);
|
99
|
+
if (code && message) {
|
100
|
+
console.error("[getOperationSet]", code, message);
|
101
|
+
return undefined;
|
102
|
+
}
|
103
|
+
return extractActivity(activity);
|
104
|
+
}
|
124
105
|
async getOperationStatuses(operationIds) {
|
125
106
|
const { operationStatuses } = await this.sendRequest("orby_getOperationStatuses", [{ operationIds }]);
|
126
107
|
return extractOperationStatuses(operationStatuses);
|
@@ -148,15 +129,6 @@ export class OperationActions extends LibraryRequest {
|
|
148
129
|
return CurrencyAmount.toCurrencyAmount(estimatedCost);
|
149
130
|
}
|
150
131
|
async getOperationsToTransferToken(accountClusterId, standardizedTokenId, amount, recipient, gasToken) {
|
151
|
-
const formattedGasToken = gasToken
|
152
|
-
? {
|
153
|
-
...gasToken,
|
154
|
-
tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
|
155
|
-
chainId: await this.getOrbyChainId(chainId),
|
156
|
-
address,
|
157
|
-
}))),
|
158
|
-
}
|
159
|
-
: undefined;
|
160
132
|
const formattedRecepient = {
|
161
133
|
chainId: await this.getOrbyChainId(recipient.chainId),
|
162
134
|
address: recipient.address,
|
@@ -167,7 +139,7 @@ export class OperationActions extends LibraryRequest {
|
|
167
139
|
standardizedTokenId,
|
168
140
|
amount,
|
169
141
|
recipient: formattedRecepient,
|
170
|
-
gasToken:
|
142
|
+
gasToken: await this.formatGasToken(gasToken),
|
171
143
|
},
|
172
144
|
]);
|
173
145
|
return extractOperationSet(operationSet);
|
@@ -193,22 +165,13 @@ export class OperationActions extends LibraryRequest {
|
|
193
165
|
: undefined,
|
194
166
|
}
|
195
167
|
: undefined;
|
196
|
-
const formattedGasToken = gasToken
|
197
|
-
? {
|
198
|
-
...gasToken,
|
199
|
-
tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
|
200
|
-
chainId: await this.getOrbyChainId(chainId),
|
201
|
-
address,
|
202
|
-
}))),
|
203
|
-
}
|
204
|
-
: undefined;
|
205
168
|
const operationSet = await this.sendRequest("orby_getOperationsToSwap", [
|
206
169
|
{
|
207
170
|
accountClusterId,
|
208
171
|
swapType,
|
209
172
|
input: formattedInput,
|
210
173
|
output: formattedOutput,
|
211
|
-
gasToken:
|
174
|
+
gasToken: await this.formatGasToken(gasToken),
|
212
175
|
},
|
213
176
|
]);
|
214
177
|
return extractOperationSet(operationSet);
|
@@ -255,15 +218,6 @@ export class OperationActions extends LibraryRequest {
|
|
255
218
|
address: tokenDestination.address,
|
256
219
|
}
|
257
220
|
: undefined;
|
258
|
-
const formattedGasToken = gasToken
|
259
|
-
? {
|
260
|
-
...gasToken,
|
261
|
-
tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
|
262
|
-
chainId: await this.getOrbyChainId(chainId),
|
263
|
-
address,
|
264
|
-
}))),
|
265
|
-
}
|
266
|
-
: undefined;
|
267
221
|
const operationSet = await this.sendRequest("orby_getOperationsToBridge", [
|
268
222
|
{
|
269
223
|
accountClusterId,
|
@@ -271,11 +225,52 @@ export class OperationActions extends LibraryRequest {
|
|
271
225
|
amount,
|
272
226
|
tokenSources: formattedTokenSources,
|
273
227
|
tokenDestination: formattedDestination,
|
274
|
-
gasToken:
|
228
|
+
gasToken: await this.formatGasToken(gasToken),
|
275
229
|
},
|
276
230
|
]);
|
277
231
|
return extractOperationSet(operationSet);
|
278
232
|
}
|
233
|
+
subscribeToOperationSetStatus(operationSetId, onOperationSetStatusUpdateCallback, timeout) {
|
234
|
+
let intervalId = null;
|
235
|
+
let totalWaitTime = 0;
|
236
|
+
const timeoutOrDefault = timeout ?? 300_000;
|
237
|
+
if (operationSetId) {
|
238
|
+
const waitTime = 500;
|
239
|
+
intervalId = setInterval(async () => {
|
240
|
+
let statusSummary = ActivityStatus.WAITING_PRECONDITION;
|
241
|
+
try {
|
242
|
+
const activity = operationSetId
|
243
|
+
? await this?.getOperationSet(operationSetId)
|
244
|
+
: undefined;
|
245
|
+
if (activity) {
|
246
|
+
statusSummary = activity?.overallStatus;
|
247
|
+
}
|
248
|
+
onOperationSetStatusUpdateCallback?.(activity);
|
249
|
+
}
|
250
|
+
catch (error) {
|
251
|
+
console.error("[subscribeToOperationSetStatus]", error);
|
252
|
+
}
|
253
|
+
finally {
|
254
|
+
totalWaitTime += waitTime;
|
255
|
+
if (intervalId &&
|
256
|
+
![
|
257
|
+
ActivityStatus.WAITING_TOKEN_APPROVAL_TRANSACTIONS,
|
258
|
+
ActivityStatus.WAITING_GAS_ABSTRACTION,
|
259
|
+
ActivityStatus.WAITING_PRECONDITION,
|
260
|
+
].includes(statusSummary)) {
|
261
|
+
clearInterval(intervalId);
|
262
|
+
intervalId = null;
|
263
|
+
}
|
264
|
+
else if (intervalId && totalWaitTime >= timeoutOrDefault) {
|
265
|
+
// we cant wait for more than 2 ETH blocks
|
266
|
+
clearInterval(intervalId);
|
267
|
+
intervalId = null;
|
268
|
+
}
|
269
|
+
}
|
270
|
+
}, waitTime);
|
271
|
+
}
|
272
|
+
return { intervalId };
|
273
|
+
}
|
279
274
|
subscribeToOperationStatuses(ids, onOperationStatusesUpdateCallback, timout) {
|
280
275
|
let intervalId = null;
|
281
276
|
let totalWaitTime = 0;
|
@@ -302,18 +297,25 @@ export class OperationActions extends LibraryRequest {
|
|
302
297
|
statusSummary = OperationStatusType.SUCCESSFUL;
|
303
298
|
}
|
304
299
|
primaryOperation = statuses?.find((status) => status.type == OperationType.FINAL_TRANSACTION);
|
305
|
-
if (
|
306
|
-
|
300
|
+
if ([
|
301
|
+
OperationStatusType.PENDING,
|
302
|
+
OperationStatusType.SUCCESSFUL,
|
303
|
+
].includes(primaryOperation?.status)) {
|
304
|
+
statusSummary = primaryOperation?.status;
|
307
305
|
}
|
308
306
|
onOperationStatusesUpdateCallback?.(statusSummary, primaryOperation, statuses);
|
309
307
|
}
|
310
308
|
catch (error) {
|
311
|
-
console.error("[
|
309
|
+
console.error("[subscribeToOperationStatuses]", error);
|
312
310
|
}
|
313
311
|
finally {
|
314
312
|
totalWaitTime += waitTime;
|
315
313
|
if (intervalId &&
|
316
|
-
|
314
|
+
![
|
315
|
+
OperationStatusType.WAITING_TOKEN_APPROVAL_TRANSACTIONS,
|
316
|
+
OperationStatusType.WAITING_GAS_ABSTRACTION,
|
317
|
+
OperationStatusType.WAITING_PRECONDITION,
|
318
|
+
].includes(statusSummary)) {
|
317
319
|
clearInterval(intervalId);
|
318
320
|
intervalId = null;
|
319
321
|
}
|
package/dist/esm/constants.d.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
import { Currency } from "./entities/financial/currency.js";
|
2
|
-
import {
|
2
|
+
import { BlockchainInformation } from "./types.js";
|
3
3
|
export declare const Big: any;
|
4
4
|
export declare const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
5
5
|
export declare const ONE_ADDRESS = "0x0000000000000000000000000000000000000001";
|
6
6
|
export declare const TWO_ADDRESS = "0x0000000000000000000000000000000000000002";
|
7
7
|
export declare const NATIVE_TOKEN_ADDRESS = "0x0000000000000000000000000000000000000000";
|
8
|
-
export declare const CHAIN_CONFIGS: Record<number,
|
8
|
+
export declare const CHAIN_CONFIGS: Record<number, BlockchainInformation>;
|
9
9
|
export declare const FIAT_CURRENCY: Currency;
|
@@ -8,4 +8,17 @@ export declare class LibraryRequest {
|
|
8
8
|
protected getOrbyChainId: (chainId: bigint) => Promise<string>;
|
9
9
|
protected getVirtualEnvironment: (id: bigint) => Promise<VMType>;
|
10
10
|
protected providerUrl(): string;
|
11
|
+
formatGasToken(gasToken?: {
|
12
|
+
standardizedTokenId: string;
|
13
|
+
tokenSources?: {
|
14
|
+
chainId: bigint;
|
15
|
+
address?: string;
|
16
|
+
}[];
|
17
|
+
}): Promise<{
|
18
|
+
tokenSources: {
|
19
|
+
chainId: string;
|
20
|
+
address: string;
|
21
|
+
}[] | undefined;
|
22
|
+
standardizedTokenId: string;
|
23
|
+
} | undefined>;
|
11
24
|
}
|
@@ -67,4 +67,16 @@ export class LibraryRequest {
|
|
67
67
|
const endIndex = url.indexOf(match[1]) + match[1].length;
|
68
68
|
return url.slice(0, endIndex);
|
69
69
|
}
|
70
|
+
async formatGasToken(gasToken) {
|
71
|
+
if (!gasToken) {
|
72
|
+
return undefined;
|
73
|
+
}
|
74
|
+
const tokenSources = gasToken.tokenSources
|
75
|
+
? await Promise.all(gasToken.tokenSources.map(async ({ chainId, address }) => ({
|
76
|
+
chainId: await this.getOrbyChainId(chainId),
|
77
|
+
address,
|
78
|
+
})))
|
79
|
+
: undefined;
|
80
|
+
return { ...gasToken, tokenSources };
|
81
|
+
}
|
70
82
|
}
|
package/dist/esm/enums.d.ts
CHANGED
@@ -48,11 +48,15 @@ export declare enum Category {
|
|
48
48
|
TYPED_DATA_SIGNATURE = "TYPED_DATA_SIGNATURE"
|
49
49
|
}
|
50
50
|
export declare enum OperationStatusType {
|
51
|
+
CANCELLED = "CANCELLED",
|
51
52
|
FAILED = "FAILED",
|
52
53
|
NOT_FOUND = "NOT_FOUND",
|
53
54
|
PENDING = "PENDING",
|
54
55
|
SUCCESSFUL = "SUCCESSFUL",
|
55
|
-
|
56
|
+
WAITING_GAS_ABSTRACTION = "WAITING_GAS_ABSTRACTION",
|
57
|
+
WAITING_TOKEN_APPROVAL_TRANSACTIONS = "WAITING_TOKEN_APPROVAL_TRANSACTIONS",
|
58
|
+
WAITING_PRECONDITION = "WAITING_PRECONDITION",
|
59
|
+
WAITING_TIMEOUT = "WAITING_TIMEOUT"
|
56
60
|
}
|
57
61
|
export declare enum QuoteType {
|
58
62
|
EXACT_INPUT = "EXACT_INPUT",
|
@@ -65,8 +69,13 @@ export declare enum Order {
|
|
65
69
|
export declare enum ActivityStatus {
|
66
70
|
CANCELLED = "CANCELLED",
|
67
71
|
FAILED = "FAILED",
|
72
|
+
NOT_FOUND = "NOT_FOUND",
|
68
73
|
PENDING = "PENDING",
|
69
|
-
|
74
|
+
SUCCESSFUL = "SUCCESSFUL",
|
75
|
+
WAITING_GAS_ABSTRACTION = "WAITING_GAS_ABSTRACTION",
|
76
|
+
WAITING_TOKEN_APPROVAL_TRANSACTIONS = "WAITING_TOKEN_APPROVAL_TRANSACTIONS",
|
77
|
+
WAITING_PRECONDITION = "WAITING_PRECONDITION",
|
78
|
+
WAITING_TIMEOUT = "WAITING_TIMEOUT"
|
70
79
|
}
|
71
80
|
export declare enum BlockchainEnvironment {
|
72
81
|
MAINNET = "MAINNET",
|
package/dist/esm/enums.js
CHANGED
@@ -57,11 +57,15 @@ export var Category;
|
|
57
57
|
})(Category || (Category = {}));
|
58
58
|
export var OperationStatusType;
|
59
59
|
(function (OperationStatusType) {
|
60
|
+
OperationStatusType["CANCELLED"] = "CANCELLED";
|
60
61
|
OperationStatusType["FAILED"] = "FAILED";
|
61
62
|
OperationStatusType["NOT_FOUND"] = "NOT_FOUND";
|
62
63
|
OperationStatusType["PENDING"] = "PENDING";
|
63
64
|
OperationStatusType["SUCCESSFUL"] = "SUCCESSFUL";
|
65
|
+
OperationStatusType["WAITING_GAS_ABSTRACTION"] = "WAITING_GAS_ABSTRACTION";
|
66
|
+
OperationStatusType["WAITING_TOKEN_APPROVAL_TRANSACTIONS"] = "WAITING_TOKEN_APPROVAL_TRANSACTIONS";
|
64
67
|
OperationStatusType["WAITING_PRECONDITION"] = "WAITING_PRECONDITION";
|
68
|
+
OperationStatusType["WAITING_TIMEOUT"] = "WAITING_TIMEOUT";
|
65
69
|
})(OperationStatusType || (OperationStatusType = {}));
|
66
70
|
export var QuoteType;
|
67
71
|
(function (QuoteType) {
|
@@ -77,8 +81,13 @@ export var ActivityStatus;
|
|
77
81
|
(function (ActivityStatus) {
|
78
82
|
ActivityStatus["CANCELLED"] = "CANCELLED";
|
79
83
|
ActivityStatus["FAILED"] = "FAILED";
|
84
|
+
ActivityStatus["NOT_FOUND"] = "NOT_FOUND";
|
80
85
|
ActivityStatus["PENDING"] = "PENDING";
|
81
|
-
ActivityStatus["
|
86
|
+
ActivityStatus["SUCCESSFUL"] = "SUCCESSFUL";
|
87
|
+
ActivityStatus["WAITING_GAS_ABSTRACTION"] = "WAITING_GAS_ABSTRACTION";
|
88
|
+
ActivityStatus["WAITING_TOKEN_APPROVAL_TRANSACTIONS"] = "WAITING_TOKEN_APPROVAL_TRANSACTIONS";
|
89
|
+
ActivityStatus["WAITING_PRECONDITION"] = "WAITING_PRECONDITION";
|
90
|
+
ActivityStatus["WAITING_TIMEOUT"] = "WAITING_TIMEOUT";
|
82
91
|
})(ActivityStatus || (ActivityStatus = {}));
|
83
92
|
export var BlockchainEnvironment;
|
84
93
|
(function (BlockchainEnvironment) {
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { AccountCluster, OnchainOperation, OperationSet, OperationStatus, SignedOperation, UserOperation } from "../types.js";
|
1
|
+
import { AccountCluster, Activity, OnchainOperation, OperationSet, OperationStatus, SignedOperation, UserOperation } from "../types.js";
|
2
2
|
import { CurrencyAmount } from "../entities/financial/currency_amount.js";
|
3
3
|
import { OperationStatusType, QuoteType } from "../enums.js";
|
4
4
|
export interface IOperationActions {
|
@@ -31,6 +31,7 @@ export interface IOperationActions {
|
|
31
31
|
operationResponses: OperationStatus[];
|
32
32
|
}>;
|
33
33
|
getOperationStatuses(operationIds: string[]): Promise<OperationStatus[]>;
|
34
|
+
getOperationSet(operationSetId: string): Promise<Activity>;
|
34
35
|
estimateFiatCostToExecuteTransaction(data: string, to?: string, value?: bigint): Promise<CurrencyAmount>;
|
35
36
|
estimateFiatCostToSignTypedData(data: string): Promise<CurrencyAmount>;
|
36
37
|
getOperationsToTransferToken(accountClusterId: string, standardizedTokenId: string, amount: bigint, recipient: {
|
@@ -95,6 +96,9 @@ export interface IOperationActions {
|
|
95
96
|
subscribeToOperationStatuses(ids?: string[], onOperationStatusesUpdateCallback?: (statusSummary: OperationStatusType, primaryOperationStatus?: OperationStatus, allOperationStatuses?: OperationStatus[]) => void, timout?: number): {
|
96
97
|
intervalId: NodeJS.Timeout | null;
|
97
98
|
};
|
99
|
+
subscribeToOperationSetStatus(operationSetId?: string, onOperationSetStatusUpdateCallback?: (activity?: Activity) => void, timout?: number): {
|
100
|
+
intervalId: NodeJS.Timeout | null;
|
101
|
+
};
|
98
102
|
sendOperationSet(accountCluster: AccountCluster, operationSet: OperationSet, signTransaction?: (operation: OnchainOperation) => Promise<string | undefined>, signUserOperation?: (operations: OnchainOperation[], accountAddress: string, chainId: bigint, txRpcUrl: string) => Promise<UserOperation | undefined>, signTypedData?: (operation: OnchainOperation) => Promise<string | undefined>): Promise<{
|
99
103
|
success: boolean;
|
100
104
|
operationSetId?: string;
|
package/dist/esm/types.d.ts
CHANGED
@@ -95,6 +95,8 @@ export type Activity = {
|
|
95
95
|
aggregateNetworkFeesInFiatCurrency?: CurrencyAmount;
|
96
96
|
aggregateProtocolFeesInFiatCurrency?: CurrencyAmount;
|
97
97
|
category: Category;
|
98
|
+
gasTokenAmount?: FungibleTokenAmount;
|
99
|
+
gasTokenAmountInFiatCurrency?: CurrencyAmount;
|
98
100
|
initiateAt?: Date;
|
99
101
|
inputState?: State;
|
100
102
|
operationStatuses: OperationStatus[];
|
@@ -120,10 +122,13 @@ export type StandardizedToken = {
|
|
120
122
|
tokens: FungibleToken[];
|
121
123
|
};
|
122
124
|
export type BlockchainInformation = {
|
123
|
-
chainId: bigint;
|
124
125
|
environment: BlockchainEnvironment;
|
125
|
-
|
126
|
-
|
126
|
+
chainId: bigint;
|
127
|
+
vmType: VMType;
|
128
|
+
logoUrl: string;
|
129
|
+
name: string;
|
130
|
+
genesisBlockHash?: string;
|
131
|
+
nativeCurrency: Currency;
|
127
132
|
};
|
128
133
|
export type ContractAllowlistWithAllMethodFallback = {
|
129
134
|
contractAddress: string;
|
@@ -161,15 +166,6 @@ export type GasSponsorshipData = {
|
|
161
166
|
totalGasSpent: CurrencyAmount;
|
162
167
|
totalTransactionCount: bigint;
|
163
168
|
};
|
164
|
-
export type ChainConfigs = {
|
165
|
-
environment: BlockchainEnvironment;
|
166
|
-
chainId: bigint;
|
167
|
-
vmType: VMType;
|
168
|
-
logoUrl: string;
|
169
|
-
name: string;
|
170
|
-
genesisBlockHash?: string;
|
171
|
-
nativeCurrency: Currency;
|
172
|
-
};
|
173
169
|
export type VirtualNodeRpcUrlForSupportedChain = {
|
174
170
|
chainId: string;
|
175
171
|
entrypointAccountAddress: string;
|
@@ -6,13 +6,13 @@ export declare const extractIntent: (intent?: any) => Intent;
|
|
6
6
|
export declare const extractOperationStatuses: (operationStatus?: any[]) => OperationStatus[];
|
7
7
|
export declare const extractOperationStatus: (status?: any) => OperationStatus;
|
8
8
|
export declare const extractActivities: (activities?: any[]) => Activity[];
|
9
|
+
export declare const extractActivity: (activity?: any) => Activity;
|
9
10
|
export declare const extractFungibleTokenOverview: (overview?: any) => FungibleTokenOverview;
|
10
11
|
export declare const extractStandardizedBalances: (balances?: any) => StandardizedBalance[];
|
11
12
|
export declare const extractStandardizedBalance: (balance?: any) => StandardizedBalance;
|
12
13
|
export declare const extractStandardizedTokens: (tokens?: any) => StandardizedToken[];
|
13
14
|
export declare const extractStandardizedToken: (token?: any) => StandardizedToken;
|
14
15
|
export declare const extractBlockchainInformations: (blockchainInformation?: any[]) => BlockchainInformation[];
|
15
|
-
export declare const extractBlockchainInformation: (blockchainInformation?: any) => BlockchainInformation;
|
16
16
|
export declare const extractMaxAmountPerInterval: (maxAmountPerInterval?: any) => MaxAmountPerInterval;
|
17
17
|
export declare const extractAllowlistWithOpenFallback: (allowlist?: any) => AllowlistWithOpenFallback;
|
18
18
|
export declare const extractGasSponsorshipPolicy: (gasSponsorshipPolicy?: any) => GasSponsorshipPolicy;
|
@@ -5,7 +5,7 @@ import { Currency } from "../entities/financial/currency.js";
|
|
5
5
|
import { FungibleTokenAmount } from "../entities/financial/fungible_token_amount.js";
|
6
6
|
import { FungibleToken } from "../entities/financial/fungible_token.js";
|
7
7
|
import { Account } from "../entities/account.js";
|
8
|
-
import { getChainIdFromOrbyChainId, hasError } from "./utils.js";
|
8
|
+
import { extractBlockchainInformation, getChainIdFromOrbyChainId, hasError, notEmpty, } from "./utils.js";
|
9
9
|
export const extractAccountCluster = (accountCluster) => {
|
10
10
|
if (!accountCluster) {
|
11
11
|
return undefined;
|
@@ -115,20 +115,26 @@ export const extractActivities = (activities) => {
|
|
115
115
|
if (!activities) {
|
116
116
|
return undefined;
|
117
117
|
}
|
118
|
-
return activities
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
118
|
+
return activities
|
119
|
+
.map((activity) => extractActivity(activity))
|
120
|
+
.filter(notEmpty);
|
121
|
+
};
|
122
|
+
export const extractActivity = (activity) => {
|
123
|
+
if (!activity) {
|
124
|
+
return undefined;
|
125
|
+
}
|
126
|
+
return {
|
127
|
+
aggregateFiatValueOfInputState: CurrencyAmount.toCurrencyAmount(activity.aggregateFiatValueOfInputState),
|
128
|
+
aggregateFiatValueOfOutputState: CurrencyAmount.toCurrencyAmount(activity.aggregateFiatValueOfOutputState),
|
129
|
+
aggregateNetworkFeesInFiatCurrency: CurrencyAmount.toCurrencyAmount(activity.aggregateNetworkFeesInFiatCurrency),
|
130
|
+
aggregateProtocolFeesInFiatCurrency: CurrencyAmount.toCurrencyAmount(activity.aggregateProtocolFeesInFiatCurrency),
|
131
|
+
category: activity.category,
|
132
|
+
initiateAt: activity.initiateAt,
|
133
|
+
inputState: State.toState(activity.inputState),
|
134
|
+
operationStatuses: extractOperationStatuses(activity.operationStatuses),
|
135
|
+
outputState: State.toState(activity.outputState),
|
136
|
+
overallStatus: activity.overallStatus,
|
137
|
+
};
|
132
138
|
};
|
133
139
|
export const extractFungibleTokenOverview = (overview) => {
|
134
140
|
if (!overview) {
|
@@ -176,17 +182,6 @@ export const extractStandardizedToken = (token) => {
|
|
176
182
|
export const extractBlockchainInformations = (blockchainInformation) => {
|
177
183
|
return blockchainInformation?.map((info) => extractBlockchainInformation(info));
|
178
184
|
};
|
179
|
-
export const extractBlockchainInformation = (blockchainInformation) => {
|
180
|
-
if (!blockchainInformation) {
|
181
|
-
return undefined;
|
182
|
-
}
|
183
|
-
return {
|
184
|
-
chainId: getChainIdFromOrbyChainId(blockchainInformation.chainId),
|
185
|
-
environment: blockchainInformation.environment,
|
186
|
-
logoUrl: blockchainInformation.logoUrl,
|
187
|
-
name: blockchainInformation.name,
|
188
|
-
};
|
189
|
-
};
|
190
185
|
export const extractMaxAmountPerInterval = (maxAmountPerInterval) => {
|
191
186
|
if (!maxAmountPerInterval) {
|
192
187
|
return undefined;
|
@@ -3,7 +3,10 @@ import { Currency } from "../entities/financial/currency.js";
|
|
3
3
|
import { FungibleToken } from "../entities/financial/fungible_token.js";
|
4
4
|
import { FungibleTokenAmount } from "../entities/financial/fungible_token_amount.js";
|
5
5
|
import { CurrencyAmount } from "../entities/financial/currency_amount.js";
|
6
|
+
import { BlockchainInformation } from "../types.js";
|
7
|
+
export declare const notEmpty: <T>(value: T) => value is NonNullable<T>;
|
6
8
|
export declare const initializeBlockchainInformation: (orbyUrl: string) => Promise<void>;
|
9
|
+
export declare const extractBlockchainInformation: (blockchainInformation?: any) => BlockchainInformation;
|
7
10
|
export declare const getChainIdFromOrbyChainId: (value: string) => bigint | undefined;
|
8
11
|
export declare const getVirtualEnvironment: (id: bigint) => Promise<VMType>;
|
9
12
|
export declare const hasError: (data: any) => {
|
package/dist/esm/utils/utils.js
CHANGED
@@ -4,6 +4,8 @@ import { Currency } from "../entities/financial/currency.js";
|
|
4
4
|
import { FungibleToken } from "../entities/financial/fungible_token.js";
|
5
5
|
import { FungibleTokenAmount } from "../entities/financial/fungible_token_amount.js";
|
6
6
|
import { CurrencyAmount } from "../entities/financial/currency_amount.js";
|
7
|
+
// used to filter out null and undefined values: https://stackoverflow.com/questions/43118692/typescript-filter-out-nulls-from-an-array
|
8
|
+
export const notEmpty = (value) => value != undefined && value != null;
|
7
9
|
export const initializeBlockchainInformation = async (orbyUrl) => {
|
8
10
|
const response = await fetch(orbyUrl, {
|
9
11
|
method: "POST",
|
@@ -25,14 +27,24 @@ export const initializeBlockchainInformation = async (orbyUrl) => {
|
|
25
27
|
result.edges?.map((blockchainInfo) => {
|
26
28
|
const chainId = getChainIdFromOrbyChainId(blockchainInfo.chainId);
|
27
29
|
if (chainId && blockchainInfo?.name) {
|
28
|
-
CHAIN_CONFIGS[Number(chainId)] =
|
29
|
-
|
30
|
-
chainId: chainId,
|
31
|
-
nativeCurrency: Currency.toCurrency(blockchainInfo?.nativeCurrency),
|
32
|
-
};
|
30
|
+
CHAIN_CONFIGS[Number(chainId)] =
|
31
|
+
extractBlockchainInformation(blockchainInfo);
|
33
32
|
}
|
34
33
|
});
|
35
34
|
};
|
35
|
+
export const extractBlockchainInformation = (blockchainInformation) => {
|
36
|
+
if (!blockchainInformation) {
|
37
|
+
return undefined;
|
38
|
+
}
|
39
|
+
return {
|
40
|
+
chainId: getChainIdFromOrbyChainId(blockchainInformation.chainId),
|
41
|
+
environment: blockchainInformation.environment,
|
42
|
+
logoUrl: blockchainInformation.logoUrl,
|
43
|
+
name: blockchainInformation.name,
|
44
|
+
vmType: blockchainInformation.vmType,
|
45
|
+
nativeCurrency: Currency.toCurrency(blockchainInformation.nativeCurrency),
|
46
|
+
};
|
47
|
+
};
|
36
48
|
export const getChainIdFromOrbyChainId = (value) => {
|
37
49
|
let chainId = undefined;
|
38
50
|
const formattedValue = validateAndLowerCase(value);
|