@orb-labs/orby-core 0.0.27 → 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 +6 -0
- package/dist/cjs/actions/blockchain.js +2 -1
- package/dist/cjs/actions/operation.d.ts +5 -1
- package/dist/cjs/actions/operation.js +60 -4
- package/dist/cjs/constants.d.ts +2 -2
- 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 +62 -6
- package/dist/esm/constants.d.ts +2 -2
- 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
package/CHANGELOG.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
### Unreleased
|
4
4
|
|
5
|
+
### 0.0.28
|
6
|
+
|
7
|
+
- returning the correct status
|
8
|
+
- using the same extractBlockchainInformation for all the places we need to parse blockchain information from Orby
|
9
|
+
- adding the getOperationSet function
|
10
|
+
|
5
11
|
### 0.0.27
|
6
12
|
|
7
13
|
- fix gasToken input
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BlockchainActions = void 0;
|
4
4
|
const action_helpers_js_1 = require("../utils/action_helpers.js");
|
5
5
|
const library_request_js_1 = require("../entities/library_request.js");
|
6
|
+
const index_js_1 = require("../index.js");
|
6
7
|
class BlockchainActions extends library_request_js_1.LibraryRequest {
|
7
8
|
constructor(library, client, provider) {
|
8
9
|
super(library, client, provider);
|
@@ -14,7 +15,7 @@ class BlockchainActions extends library_request_js_1.LibraryRequest {
|
|
14
15
|
console.error("[getBlockchainInformation]", code, message);
|
15
16
|
return undefined;
|
16
17
|
}
|
17
|
-
return (0,
|
18
|
+
return (0, index_js_1.extractBlockchainInformation)(blockchain);
|
18
19
|
}
|
19
20
|
async listBlockchainsInformation(offset, limit) {
|
20
21
|
const { pageInfo, edges, code, message } = await this.sendRequest("orby_listBlockchainsInformation", [{ offset, limit }]);
|
@@ -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
|
};
|
@@ -97,6 +97,14 @@ class OperationActions extends library_request_js_1.LibraryRequest {
|
|
97
97
|
operationResponses: (0, action_helpers_js_1.extractOperationStatuses)(operationResponses),
|
98
98
|
};
|
99
99
|
}
|
100
|
+
async getOperationSet(operationSetId) {
|
101
|
+
const { activity, code, message } = await this.sendRequest("orby_getOperationSet", [{ operationSetId }]);
|
102
|
+
if (code && message) {
|
103
|
+
console.error("[getOperationSet]", code, message);
|
104
|
+
return undefined;
|
105
|
+
}
|
106
|
+
return (0, action_helpers_js_1.extractActivity)(activity);
|
107
|
+
}
|
100
108
|
async getOperationStatuses(operationIds) {
|
101
109
|
const { operationStatuses } = await this.sendRequest("orby_getOperationStatuses", [{ operationIds }]);
|
102
110
|
return (0, action_helpers_js_1.extractOperationStatuses)(operationStatuses);
|
@@ -225,6 +233,47 @@ class OperationActions extends library_request_js_1.LibraryRequest {
|
|
225
233
|
]);
|
226
234
|
return (0, action_helpers_js_1.extractOperationSet)(operationSet);
|
227
235
|
}
|
236
|
+
subscribeToOperationSetStatus(operationSetId, onOperationSetStatusUpdateCallback, timeout) {
|
237
|
+
let intervalId = null;
|
238
|
+
let totalWaitTime = 0;
|
239
|
+
const timeoutOrDefault = timeout ?? 300_000;
|
240
|
+
if (operationSetId) {
|
241
|
+
const waitTime = 500;
|
242
|
+
intervalId = setInterval(async () => {
|
243
|
+
let statusSummary = enums_js_1.ActivityStatus.WAITING_PRECONDITION;
|
244
|
+
try {
|
245
|
+
const activity = operationSetId
|
246
|
+
? await this?.getOperationSet(operationSetId)
|
247
|
+
: undefined;
|
248
|
+
if (activity) {
|
249
|
+
statusSummary = activity?.overallStatus;
|
250
|
+
}
|
251
|
+
onOperationSetStatusUpdateCallback?.(activity);
|
252
|
+
}
|
253
|
+
catch (error) {
|
254
|
+
console.error("[subscribeToOperationSetStatus]", error);
|
255
|
+
}
|
256
|
+
finally {
|
257
|
+
totalWaitTime += waitTime;
|
258
|
+
if (intervalId &&
|
259
|
+
![
|
260
|
+
enums_js_1.ActivityStatus.WAITING_TOKEN_APPROVAL_TRANSACTIONS,
|
261
|
+
enums_js_1.ActivityStatus.WAITING_GAS_ABSTRACTION,
|
262
|
+
enums_js_1.ActivityStatus.WAITING_PRECONDITION,
|
263
|
+
].includes(statusSummary)) {
|
264
|
+
clearInterval(intervalId);
|
265
|
+
intervalId = null;
|
266
|
+
}
|
267
|
+
else if (intervalId && totalWaitTime >= timeoutOrDefault) {
|
268
|
+
// we cant wait for more than 2 ETH blocks
|
269
|
+
clearInterval(intervalId);
|
270
|
+
intervalId = null;
|
271
|
+
}
|
272
|
+
}
|
273
|
+
}, waitTime);
|
274
|
+
}
|
275
|
+
return { intervalId };
|
276
|
+
}
|
228
277
|
subscribeToOperationStatuses(ids, onOperationStatusesUpdateCallback, timout) {
|
229
278
|
let intervalId = null;
|
230
279
|
let totalWaitTime = 0;
|
@@ -251,18 +300,25 @@ class OperationActions extends library_request_js_1.LibraryRequest {
|
|
251
300
|
statusSummary = enums_js_1.OperationStatusType.SUCCESSFUL;
|
252
301
|
}
|
253
302
|
primaryOperation = statuses?.find((status) => status.type == enums_js_1.OperationType.FINAL_TRANSACTION);
|
254
|
-
if (
|
255
|
-
|
303
|
+
if ([
|
304
|
+
enums_js_1.OperationStatusType.PENDING,
|
305
|
+
enums_js_1.OperationStatusType.SUCCESSFUL,
|
306
|
+
].includes(primaryOperation?.status)) {
|
307
|
+
statusSummary = primaryOperation?.status;
|
256
308
|
}
|
257
309
|
onOperationStatusesUpdateCallback?.(statusSummary, primaryOperation, statuses);
|
258
310
|
}
|
259
311
|
catch (error) {
|
260
|
-
console.error("[
|
312
|
+
console.error("[subscribeToOperationStatuses]", error);
|
261
313
|
}
|
262
314
|
finally {
|
263
315
|
totalWaitTime += waitTime;
|
264
316
|
if (intervalId &&
|
265
|
-
|
317
|
+
![
|
318
|
+
enums_js_1.OperationStatusType.WAITING_TOKEN_APPROVAL_TRANSACTIONS,
|
319
|
+
enums_js_1.OperationStatusType.WAITING_GAS_ABSTRACTION,
|
320
|
+
enums_js_1.OperationStatusType.WAITING_PRECONDITION,
|
321
|
+
].includes(statusSummary)) {
|
266
322
|
clearInterval(intervalId);
|
267
323
|
intervalId = null;
|
268
324
|
}
|
package/dist/cjs/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;
|
package/dist/cjs/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/cjs/enums.js
CHANGED
@@ -60,11 +60,15 @@ var Category;
|
|
60
60
|
})(Category || (exports.Category = Category = {}));
|
61
61
|
var OperationStatusType;
|
62
62
|
(function (OperationStatusType) {
|
63
|
+
OperationStatusType["CANCELLED"] = "CANCELLED";
|
63
64
|
OperationStatusType["FAILED"] = "FAILED";
|
64
65
|
OperationStatusType["NOT_FOUND"] = "NOT_FOUND";
|
65
66
|
OperationStatusType["PENDING"] = "PENDING";
|
66
67
|
OperationStatusType["SUCCESSFUL"] = "SUCCESSFUL";
|
68
|
+
OperationStatusType["WAITING_GAS_ABSTRACTION"] = "WAITING_GAS_ABSTRACTION";
|
69
|
+
OperationStatusType["WAITING_TOKEN_APPROVAL_TRANSACTIONS"] = "WAITING_TOKEN_APPROVAL_TRANSACTIONS";
|
67
70
|
OperationStatusType["WAITING_PRECONDITION"] = "WAITING_PRECONDITION";
|
71
|
+
OperationStatusType["WAITING_TIMEOUT"] = "WAITING_TIMEOUT";
|
68
72
|
})(OperationStatusType || (exports.OperationStatusType = OperationStatusType = {}));
|
69
73
|
var QuoteType;
|
70
74
|
(function (QuoteType) {
|
@@ -80,8 +84,13 @@ var ActivityStatus;
|
|
80
84
|
(function (ActivityStatus) {
|
81
85
|
ActivityStatus["CANCELLED"] = "CANCELLED";
|
82
86
|
ActivityStatus["FAILED"] = "FAILED";
|
87
|
+
ActivityStatus["NOT_FOUND"] = "NOT_FOUND";
|
83
88
|
ActivityStatus["PENDING"] = "PENDING";
|
84
|
-
ActivityStatus["
|
89
|
+
ActivityStatus["SUCCESSFUL"] = "SUCCESSFUL";
|
90
|
+
ActivityStatus["WAITING_GAS_ABSTRACTION"] = "WAITING_GAS_ABSTRACTION";
|
91
|
+
ActivityStatus["WAITING_TOKEN_APPROVAL_TRANSACTIONS"] = "WAITING_TOKEN_APPROVAL_TRANSACTIONS";
|
92
|
+
ActivityStatus["WAITING_PRECONDITION"] = "WAITING_PRECONDITION";
|
93
|
+
ActivityStatus["WAITING_TIMEOUT"] = "WAITING_TIMEOUT";
|
85
94
|
})(ActivityStatus || (exports.ActivityStatus = ActivityStatus = {}));
|
86
95
|
var BlockchainEnvironment;
|
87
96
|
(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/cjs/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;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.extractGasSponsorshipData = exports.extractGasSponsorshipInformation = exports.extractGasSpendForInstance = exports.extractGasSpendForInstances = exports.extractGasSponsorshipPolicy = exports.extractAllowlistWithOpenFallback = exports.extractMaxAmountPerInterval = exports.
|
3
|
+
exports.extractGasSponsorshipData = exports.extractGasSponsorshipInformation = exports.extractGasSpendForInstance = exports.extractGasSpendForInstances = exports.extractGasSponsorshipPolicy = exports.extractAllowlistWithOpenFallback = exports.extractMaxAmountPerInterval = exports.extractBlockchainInformations = exports.extractStandardizedToken = exports.extractStandardizedTokens = exports.extractStandardizedBalance = exports.extractStandardizedBalances = exports.extractFungibleTokenOverview = exports.extractActivity = exports.extractActivities = exports.extractOperationStatus = exports.extractOperationStatuses = exports.extractIntent = exports.extractOnchainOperation = exports.extractOperationSet = exports.extractAccountCluster = void 0;
|
4
4
|
const enums_js_1 = require("../enums.js");
|
5
5
|
const currency_amount_js_1 = require("../entities/financial/currency_amount.js");
|
6
6
|
const state_js_1 = require("../entities/state.js");
|
@@ -124,22 +124,29 @@ const extractActivities = (activities) => {
|
|
124
124
|
if (!activities) {
|
125
125
|
return undefined;
|
126
126
|
}
|
127
|
-
return activities
|
128
|
-
|
129
|
-
|
130
|
-
aggregateFiatValueOfOutputState: currency_amount_js_1.CurrencyAmount.toCurrencyAmount(activity.aggregateFiatValueOfOutputState),
|
131
|
-
aggregateNetworkFeesInFiatCurrency: currency_amount_js_1.CurrencyAmount.toCurrencyAmount(activity.aggregateNetworkFeesInFiatCurrency),
|
132
|
-
aggregateProtocolFeesInFiatCurrency: currency_amount_js_1.CurrencyAmount.toCurrencyAmount(activity.aggregateProtocolFeesInFiatCurrency),
|
133
|
-
category: activity.category,
|
134
|
-
initiateAt: activity.initiateAt,
|
135
|
-
inputState: state_js_1.State.toState(activity.inputState),
|
136
|
-
operationStatuses: (0, exports.extractOperationStatuses)(activity.operationStatuses),
|
137
|
-
outputState: state_js_1.State.toState(activity.outputState),
|
138
|
-
overallStatus: activity.overallStatus,
|
139
|
-
};
|
140
|
-
});
|
127
|
+
return activities
|
128
|
+
.map((activity) => (0, exports.extractActivity)(activity))
|
129
|
+
.filter(utils_js_1.notEmpty);
|
141
130
|
};
|
142
131
|
exports.extractActivities = extractActivities;
|
132
|
+
const extractActivity = (activity) => {
|
133
|
+
if (!activity) {
|
134
|
+
return undefined;
|
135
|
+
}
|
136
|
+
return {
|
137
|
+
aggregateFiatValueOfInputState: currency_amount_js_1.CurrencyAmount.toCurrencyAmount(activity.aggregateFiatValueOfInputState),
|
138
|
+
aggregateFiatValueOfOutputState: currency_amount_js_1.CurrencyAmount.toCurrencyAmount(activity.aggregateFiatValueOfOutputState),
|
139
|
+
aggregateNetworkFeesInFiatCurrency: currency_amount_js_1.CurrencyAmount.toCurrencyAmount(activity.aggregateNetworkFeesInFiatCurrency),
|
140
|
+
aggregateProtocolFeesInFiatCurrency: currency_amount_js_1.CurrencyAmount.toCurrencyAmount(activity.aggregateProtocolFeesInFiatCurrency),
|
141
|
+
category: activity.category,
|
142
|
+
initiateAt: activity.initiateAt,
|
143
|
+
inputState: state_js_1.State.toState(activity.inputState),
|
144
|
+
operationStatuses: (0, exports.extractOperationStatuses)(activity.operationStatuses),
|
145
|
+
outputState: state_js_1.State.toState(activity.outputState),
|
146
|
+
overallStatus: activity.overallStatus,
|
147
|
+
};
|
148
|
+
};
|
149
|
+
exports.extractActivity = extractActivity;
|
143
150
|
const extractFungibleTokenOverview = (overview) => {
|
144
151
|
if (!overview) {
|
145
152
|
return undefined;
|
@@ -189,21 +196,9 @@ const extractStandardizedToken = (token) => {
|
|
189
196
|
};
|
190
197
|
exports.extractStandardizedToken = extractStandardizedToken;
|
191
198
|
const extractBlockchainInformations = (blockchainInformation) => {
|
192
|
-
return blockchainInformation?.map((info) => (0,
|
199
|
+
return blockchainInformation?.map((info) => (0, utils_js_1.extractBlockchainInformation)(info));
|
193
200
|
};
|
194
201
|
exports.extractBlockchainInformations = extractBlockchainInformations;
|
195
|
-
const extractBlockchainInformation = (blockchainInformation) => {
|
196
|
-
if (!blockchainInformation) {
|
197
|
-
return undefined;
|
198
|
-
}
|
199
|
-
return {
|
200
|
-
chainId: (0, utils_js_1.getChainIdFromOrbyChainId)(blockchainInformation.chainId),
|
201
|
-
environment: blockchainInformation.environment,
|
202
|
-
logoUrl: blockchainInformation.logoUrl,
|
203
|
-
name: blockchainInformation.name,
|
204
|
-
};
|
205
|
-
};
|
206
|
-
exports.extractBlockchainInformation = extractBlockchainInformation;
|
207
202
|
const extractMaxAmountPerInterval = (maxAmountPerInterval) => {
|
208
203
|
if (!maxAmountPerInterval) {
|
209
204
|
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/cjs/utils/utils.js
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.createNativeCurrencyAmount = exports.createNativeFungibleTokenAmount = exports.getNativeFungibleToken = exports.getNativeCurrency = exports.hasError = exports.getVirtualEnvironment = exports.getChainIdFromOrbyChainId = exports.initializeBlockchainInformation = void 0;
|
3
|
+
exports.createNativeCurrencyAmount = exports.createNativeFungibleTokenAmount = exports.getNativeFungibleToken = exports.getNativeCurrency = exports.hasError = exports.getVirtualEnvironment = exports.getChainIdFromOrbyChainId = exports.extractBlockchainInformation = exports.initializeBlockchainInformation = exports.notEmpty = void 0;
|
4
4
|
const constants_js_1 = require("../constants.js");
|
5
5
|
const validateAndParseAddress_js_1 = require("./validateAndParseAddress.js");
|
6
6
|
const currency_js_1 = require("../entities/financial/currency.js");
|
7
7
|
const fungible_token_js_1 = require("../entities/financial/fungible_token.js");
|
8
8
|
const fungible_token_amount_js_1 = require("../entities/financial/fungible_token_amount.js");
|
9
9
|
const currency_amount_js_1 = require("../entities/financial/currency_amount.js");
|
10
|
+
// used to filter out null and undefined values: https://stackoverflow.com/questions/43118692/typescript-filter-out-nulls-from-an-array
|
11
|
+
const notEmpty = (value) => value != undefined && value != null;
|
12
|
+
exports.notEmpty = notEmpty;
|
10
13
|
const initializeBlockchainInformation = async (orbyUrl) => {
|
11
14
|
const response = await fetch(orbyUrl, {
|
12
15
|
method: "POST",
|
@@ -28,15 +31,26 @@ const initializeBlockchainInformation = async (orbyUrl) => {
|
|
28
31
|
result.edges?.map((blockchainInfo) => {
|
29
32
|
const chainId = (0, exports.getChainIdFromOrbyChainId)(blockchainInfo.chainId);
|
30
33
|
if (chainId && blockchainInfo?.name) {
|
31
|
-
constants_js_1.CHAIN_CONFIGS[Number(chainId)] =
|
32
|
-
|
33
|
-
chainId: chainId,
|
34
|
-
nativeCurrency: currency_js_1.Currency.toCurrency(blockchainInfo?.nativeCurrency),
|
35
|
-
};
|
34
|
+
constants_js_1.CHAIN_CONFIGS[Number(chainId)] =
|
35
|
+
(0, exports.extractBlockchainInformation)(blockchainInfo);
|
36
36
|
}
|
37
37
|
});
|
38
38
|
};
|
39
39
|
exports.initializeBlockchainInformation = initializeBlockchainInformation;
|
40
|
+
const extractBlockchainInformation = (blockchainInformation) => {
|
41
|
+
if (!blockchainInformation) {
|
42
|
+
return undefined;
|
43
|
+
}
|
44
|
+
return {
|
45
|
+
chainId: (0, exports.getChainIdFromOrbyChainId)(blockchainInformation.chainId),
|
46
|
+
environment: blockchainInformation.environment,
|
47
|
+
logoUrl: blockchainInformation.logoUrl,
|
48
|
+
name: blockchainInformation.name,
|
49
|
+
vmType: blockchainInformation.vmType,
|
50
|
+
nativeCurrency: currency_js_1.Currency.toCurrency(blockchainInformation.nativeCurrency),
|
51
|
+
};
|
52
|
+
};
|
53
|
+
exports.extractBlockchainInformation = extractBlockchainInformation;
|
40
54
|
const getChainIdFromOrbyChainId = (value) => {
|
41
55
|
let chainId = undefined;
|
42
56
|
const formattedValue = (0, validateAndParseAddress_js_1.validateAndLowerCase)(value);
|
@@ -1,5 +1,6 @@
|
|
1
|
-
import {
|
1
|
+
import { extractBlockchainInformations } from "../utils/action_helpers.js";
|
2
2
|
import { LibraryRequest } from "../entities/library_request.js";
|
3
|
+
import { extractBlockchainInformation } from "../index.js";
|
3
4
|
export class BlockchainActions extends LibraryRequest {
|
4
5
|
constructor(library, client, provider) {
|
5
6
|
super(library, client, provider);
|
@@ -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
|
@@ -94,6 +94,14 @@ export class OperationActions extends LibraryRequest {
|
|
94
94
|
operationResponses: extractOperationStatuses(operationResponses),
|
95
95
|
};
|
96
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
|
+
}
|
97
105
|
async getOperationStatuses(operationIds) {
|
98
106
|
const { operationStatuses } = await this.sendRequest("orby_getOperationStatuses", [{ operationIds }]);
|
99
107
|
return extractOperationStatuses(operationStatuses);
|
@@ -222,6 +230,47 @@ export class OperationActions extends LibraryRequest {
|
|
222
230
|
]);
|
223
231
|
return extractOperationSet(operationSet);
|
224
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
|
+
}
|
225
274
|
subscribeToOperationStatuses(ids, onOperationStatusesUpdateCallback, timout) {
|
226
275
|
let intervalId = null;
|
227
276
|
let totalWaitTime = 0;
|
@@ -248,18 +297,25 @@ export class OperationActions extends LibraryRequest {
|
|
248
297
|
statusSummary = OperationStatusType.SUCCESSFUL;
|
249
298
|
}
|
250
299
|
primaryOperation = statuses?.find((status) => status.type == OperationType.FINAL_TRANSACTION);
|
251
|
-
if (
|
252
|
-
|
300
|
+
if ([
|
301
|
+
OperationStatusType.PENDING,
|
302
|
+
OperationStatusType.SUCCESSFUL,
|
303
|
+
].includes(primaryOperation?.status)) {
|
304
|
+
statusSummary = primaryOperation?.status;
|
253
305
|
}
|
254
306
|
onOperationStatusesUpdateCallback?.(statusSummary, primaryOperation, statuses);
|
255
307
|
}
|
256
308
|
catch (error) {
|
257
|
-
console.error("[
|
309
|
+
console.error("[subscribeToOperationStatuses]", error);
|
258
310
|
}
|
259
311
|
finally {
|
260
312
|
totalWaitTime += waitTime;
|
261
313
|
if (intervalId &&
|
262
|
-
|
314
|
+
![
|
315
|
+
OperationStatusType.WAITING_TOKEN_APPROVAL_TRANSACTIONS,
|
316
|
+
OperationStatusType.WAITING_GAS_ABSTRACTION,
|
317
|
+
OperationStatusType.WAITING_PRECONDITION,
|
318
|
+
].includes(statusSummary)) {
|
263
319
|
clearInterval(intervalId);
|
264
320
|
intervalId = null;
|
265
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;
|
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",
|