@orb-labs/orby-core 0.0.2 → 0.0.4
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/README.md +42 -1
- package/dist/actions/account_cluster.d.ts +1 -1
- package/dist/actions/account_cluster.js +64 -27
- package/dist/actions/admin.js +25 -7
- package/dist/actions/application.js +7 -1
- package/dist/actions/instance.js +54 -13
- package/dist/actions/operation.d.ts +19 -13
- package/dist/actions/operation.js +42 -22
- package/dist/actions/token.js +18 -8
- package/dist/constants.d.ts +10 -0
- package/dist/constants.js +104 -1
- package/dist/entities/financial/currency_amount.d.ts +4 -1
- package/dist/entities/financial/currency_amount.js +18 -0
- package/dist/entities/financial/fungible_token_amount.d.ts +4 -1
- package/dist/entities/financial/fungible_token_amount.js +18 -0
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -4
- package/dist/interfaces/account_cluster.d.ts +1 -1
- package/dist/interfaces/operation.d.ts +13 -13
- package/dist/types.d.ts +6 -2
- package/dist/utils/action_helpers.d.ts +22 -0
- package/dist/utils/action_helpers.js +280 -0
- package/dist/utils/utils.d.ts +5 -22
- package/dist/utils/utils.js +13 -258
- package/package.json +6 -1
@@ -0,0 +1,280 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.extractGasSponsorshipData = exports.extractGasSponsorshipInformation = exports.extractGasSpendForInstance = exports.extractGasSpendForInstances = exports.extractGasSponsorshipPolicy = exports.extractAllowlistWithOpenFallback = exports.extractMaxAmountPerInterval = exports.extractBlockchainInformation = exports.extractBlockchainInformations = exports.extractStandardizedToken = exports.extractStandardizedTokens = exports.extractStandardizedBalance = exports.extractStandardizedBalances = exports.extractFungibleTokenOverview = exports.extractActivities = exports.extractOperationStatus = exports.extractOperationStatuses = exports.extractIntent = exports.extractOnchainOperation = exports.extractOperationSet = exports.extractAccountCluster = void 0;
|
4
|
+
const enums_1 = require("../enums");
|
5
|
+
const currency_amount_1 = require("../entities/financial/currency_amount");
|
6
|
+
const state_1 = require("../entities/state");
|
7
|
+
const currency_1 = require("../entities/financial/currency");
|
8
|
+
const fungible_token_amount_1 = require("../entities/financial/fungible_token_amount");
|
9
|
+
const fungible_token_1 = require("../entities/financial/fungible_token");
|
10
|
+
const account_1 = require("../entities/account");
|
11
|
+
const utils_1 = require("./utils");
|
12
|
+
const extractAccountCluster = (accountCluster) => {
|
13
|
+
var _a;
|
14
|
+
if (!accountCluster) {
|
15
|
+
return undefined;
|
16
|
+
}
|
17
|
+
else if ((0, utils_1.hasError)(accountCluster)) {
|
18
|
+
console.error("[extractAccountCluster]", accountCluster.code, accountCluster.message);
|
19
|
+
return undefined;
|
20
|
+
}
|
21
|
+
return {
|
22
|
+
accountClusterId: accountCluster.accountClusterId,
|
23
|
+
accounts: (_a = accountCluster === null || accountCluster === void 0 ? void 0 : accountCluster.accounts) === null || _a === void 0 ? void 0 : _a.map((account) => account_1.Account.toAccount(account)),
|
24
|
+
};
|
25
|
+
};
|
26
|
+
exports.extractAccountCluster = extractAccountCluster;
|
27
|
+
const extractOperationSet = (operationSet) => {
|
28
|
+
var _a;
|
29
|
+
if (!operationSet) {
|
30
|
+
return undefined;
|
31
|
+
}
|
32
|
+
else if ((0, utils_1.hasError)(operationSet)) {
|
33
|
+
console.error("[extractOperationSet]", operationSet);
|
34
|
+
return {
|
35
|
+
status: enums_1.CreateOperationsStatus.INTERNAL,
|
36
|
+
};
|
37
|
+
}
|
38
|
+
return {
|
39
|
+
status: operationSet.status,
|
40
|
+
primaryOperation: (0, exports.extractOnchainOperation)(operationSet.primaryOperation),
|
41
|
+
primaryOperationPreconditions: state_1.State.toState(operationSet.primaryOperationPreconditions),
|
42
|
+
inputState: state_1.State.toState(operationSet.inputState),
|
43
|
+
outputState: state_1.State.toState(operationSet.outputState),
|
44
|
+
intents: (_a = operationSet.intents) === null || _a === void 0 ? void 0 : _a.map((intent) => (0, exports.extractIntent)(intent)),
|
45
|
+
aggregateNetworkFeeInFiatCurrency: currency_amount_1.CurrencyAmount.toCurrencyAmount(operationSet.aggregateNetworkFeeInFiatCurrency),
|
46
|
+
aggregateOperationFeeInFiatCurrency: currency_amount_1.CurrencyAmount.toCurrencyAmount(operationSet.aggregateOperationFeeInFiatCurrency),
|
47
|
+
aggregateEstimatedTimeInMs: operationSet.aggregateEstimatedTimeInMs,
|
48
|
+
};
|
49
|
+
};
|
50
|
+
exports.extractOperationSet = extractOperationSet;
|
51
|
+
const extractOnchainOperation = (onchainOperation) => {
|
52
|
+
if (!onchainOperation) {
|
53
|
+
return undefined;
|
54
|
+
}
|
55
|
+
return {
|
56
|
+
chainId: (0, utils_1.getChainIdFromOrbyChainId)(onchainOperation.chainId),
|
57
|
+
data: onchainOperation.data,
|
58
|
+
estimatedNetworkFees: currency_amount_1.CurrencyAmount.toCurrencyAmount(onchainOperation.estimatedNetworkFees),
|
59
|
+
estimatedNetworkFeesInFiatCurrency: currency_amount_1.CurrencyAmount.toCurrencyAmount(onchainOperation.estimatedNetworkFeesInFiatCurrency),
|
60
|
+
estimatedTimeInMs: onchainOperation.estimatedTimeInMs,
|
61
|
+
format: onchainOperation.format,
|
62
|
+
from: onchainOperation.from,
|
63
|
+
gasLimit: onchainOperation.gasLimit
|
64
|
+
? BigInt(onchainOperation.gasLimit)
|
65
|
+
: undefined,
|
66
|
+
gasPrice: onchainOperation.gasPrice
|
67
|
+
? BigInt(onchainOperation.gasPrice)
|
68
|
+
: undefined,
|
69
|
+
inputState: state_1.State.toState(onchainOperation.inputState),
|
70
|
+
maxFeePerGas: onchainOperation.maxFeePerGas
|
71
|
+
? BigInt(onchainOperation.maxFeePerGas)
|
72
|
+
: undefined,
|
73
|
+
maxPriorityFeePerGas: onchainOperation.maxPriorityFeePerGas
|
74
|
+
? BigInt(onchainOperation.maxPriorityFeePerGas)
|
75
|
+
: undefined,
|
76
|
+
nativeCurrency: currency_1.Currency.toCurrency(onchainOperation.nativeCurrency),
|
77
|
+
nonce: onchainOperation.nonce ? BigInt(onchainOperation.nonce) : undefined,
|
78
|
+
outputState: state_1.State.toState(onchainOperation.outputState),
|
79
|
+
to: onchainOperation.to,
|
80
|
+
txRpcUrl: onchainOperation.txRpcUrl,
|
81
|
+
type: onchainOperation.type,
|
82
|
+
value: onchainOperation.value ? BigInt(onchainOperation.value) : undefined,
|
83
|
+
};
|
84
|
+
};
|
85
|
+
exports.extractOnchainOperation = extractOnchainOperation;
|
86
|
+
const extractIntent = (intent) => {
|
87
|
+
if (!intent) {
|
88
|
+
return undefined;
|
89
|
+
}
|
90
|
+
return {
|
91
|
+
estimatedProtocolFees: fungible_token_amount_1.FungibleTokenAmount.toFungibleTokenAmount(intent.estimatedProtocolFees),
|
92
|
+
estimatedProtocolFeesInFiatCurrency: currency_amount_1.CurrencyAmount.toCurrencyAmount(intent.estimatedProtocolFeesInFiatCurrency),
|
93
|
+
inputState: state_1.State.toState(intent.inputState),
|
94
|
+
intentOperations: intent.intentOperations.map((operation) => (0, exports.extractOnchainOperation)(operation)),
|
95
|
+
outputState: state_1.State.toState(intent.outputState),
|
96
|
+
};
|
97
|
+
};
|
98
|
+
exports.extractIntent = extractIntent;
|
99
|
+
const extractOperationStatuses = (operationStatus) => {
|
100
|
+
if ((0, utils_1.hasError)(operationStatus)) {
|
101
|
+
console.error("Error ", operationStatus);
|
102
|
+
return undefined;
|
103
|
+
}
|
104
|
+
return operationStatus === null || operationStatus === void 0 ? void 0 : operationStatus.map((status) => (0, exports.extractOperationStatus)(status));
|
105
|
+
};
|
106
|
+
exports.extractOperationStatuses = extractOperationStatuses;
|
107
|
+
const extractOperationStatus = (status) => {
|
108
|
+
if (!status) {
|
109
|
+
return undefined;
|
110
|
+
}
|
111
|
+
return {
|
112
|
+
blockHash: status.blockHash,
|
113
|
+
blockNumber: status.blockNumber ? BigInt(status.blockNumber) : undefined,
|
114
|
+
chainId: status.chainId
|
115
|
+
? (0, utils_1.getChainIdFromOrbyChainId)(status.chainId)
|
116
|
+
: undefined,
|
117
|
+
errorReason: status.errorReason,
|
118
|
+
hash: status.hash,
|
119
|
+
id: status.id,
|
120
|
+
status: status.status,
|
121
|
+
type: status.type,
|
122
|
+
};
|
123
|
+
};
|
124
|
+
exports.extractOperationStatus = extractOperationStatus;
|
125
|
+
const extractActivities = (activities) => {
|
126
|
+
if (!activities) {
|
127
|
+
return undefined;
|
128
|
+
}
|
129
|
+
else if ((0, utils_1.hasError)(activities)) {
|
130
|
+
console.error("Error ", activities);
|
131
|
+
return undefined;
|
132
|
+
}
|
133
|
+
return activities.map((activity) => {
|
134
|
+
return {
|
135
|
+
aggregateFiatValueOfInputState: currency_amount_1.CurrencyAmount.toCurrencyAmount(activity.aggregateFiatValueOfInputState),
|
136
|
+
aggregateFiatValueOfOutputState: currency_amount_1.CurrencyAmount.toCurrencyAmount(activity.aggregateFiatValueOfOutputState),
|
137
|
+
aggregateNetworkFeesInFiatCurrency: currency_amount_1.CurrencyAmount.toCurrencyAmount(activity.aggregateNetworkFeesInFiatCurrency),
|
138
|
+
aggregateProtocolFeesInFiatCurrency: currency_amount_1.CurrencyAmount.toCurrencyAmount(activity.aggregateProtocolFeesInFiatCurrency),
|
139
|
+
category: activity.category,
|
140
|
+
initiateAt: activity.initiateAt,
|
141
|
+
inputState: state_1.State.toState(activity.inputState),
|
142
|
+
operationStatuses: (0, exports.extractOperationStatus)(activity.operationStatuses),
|
143
|
+
outputState: state_1.State.toState(activity.outputState),
|
144
|
+
overallStatus: activity.overallStatus,
|
145
|
+
};
|
146
|
+
});
|
147
|
+
};
|
148
|
+
exports.extractActivities = extractActivities;
|
149
|
+
const extractFungibleTokenOverview = (overview) => {
|
150
|
+
if (!overview) {
|
151
|
+
return undefined;
|
152
|
+
}
|
153
|
+
else if ((0, utils_1.hasError)(overview)) {
|
154
|
+
console.error("[extractFungibleTokenOverview]", overview.code, overview.message);
|
155
|
+
return undefined;
|
156
|
+
}
|
157
|
+
return {
|
158
|
+
tokenCount: overview.tokenCount,
|
159
|
+
hiddenTokenCount: overview.hiddenTokenCount,
|
160
|
+
totalValueInFiat: currency_amount_1.CurrencyAmount.toCurrencyAmount(overview.totalValueInFiat),
|
161
|
+
};
|
162
|
+
};
|
163
|
+
exports.extractFungibleTokenOverview = extractFungibleTokenOverview;
|
164
|
+
const extractStandardizedBalances = (balances) => {
|
165
|
+
return balances === null || balances === void 0 ? void 0 : balances.map((balance) => (0, exports.extractStandardizedBalance)(balance));
|
166
|
+
};
|
167
|
+
exports.extractStandardizedBalances = extractStandardizedBalances;
|
168
|
+
const extractStandardizedBalance = (balance) => {
|
169
|
+
if (!balance) {
|
170
|
+
return undefined;
|
171
|
+
}
|
172
|
+
return {
|
173
|
+
standardizedTokenId: balance.standardizedTokenId,
|
174
|
+
tokenBalances: balance.tokenBalances.map((ft) => fungible_token_amount_1.FungibleTokenAmount.toFungibleTokenAmount(ft)),
|
175
|
+
tokenBalancesOnChains: balance.tokenBalancesOnChains.map((ft) => fungible_token_amount_1.FungibleTokenAmount.toFungibleTokenAmount(ft)),
|
176
|
+
total: currency_amount_1.CurrencyAmount.toCurrencyAmount(balance.total),
|
177
|
+
totalValueInFiat: currency_amount_1.CurrencyAmount.toCurrencyAmount(balance.totalValueInFiat),
|
178
|
+
};
|
179
|
+
};
|
180
|
+
exports.extractStandardizedBalance = extractStandardizedBalance;
|
181
|
+
const extractStandardizedTokens = (tokens) => {
|
182
|
+
return tokens === null || tokens === void 0 ? void 0 : tokens.map((token) => (0, exports.extractStandardizedToken)(token));
|
183
|
+
};
|
184
|
+
exports.extractStandardizedTokens = extractStandardizedTokens;
|
185
|
+
const extractStandardizedToken = (token) => {
|
186
|
+
if (!token) {
|
187
|
+
return undefined;
|
188
|
+
}
|
189
|
+
return {
|
190
|
+
stardardizedTokenId: token.stardardizedTokenId,
|
191
|
+
currency: currency_1.Currency.toCurrency(token.currency),
|
192
|
+
priceInFiat: currency_amount_1.CurrencyAmount.toCurrencyAmount(token.priceInFiat),
|
193
|
+
tokens: token.tokens.map((ft) => fungible_token_1.FungibleToken.toFungibleToken(ft)),
|
194
|
+
};
|
195
|
+
};
|
196
|
+
exports.extractStandardizedToken = extractStandardizedToken;
|
197
|
+
const extractBlockchainInformations = (blockchainInformation) => {
|
198
|
+
return blockchainInformation === null || blockchainInformation === void 0 ? void 0 : blockchainInformation.map((info) => (0, exports.extractBlockchainInformation)(info));
|
199
|
+
};
|
200
|
+
exports.extractBlockchainInformations = extractBlockchainInformations;
|
201
|
+
const extractBlockchainInformation = (blockchainInformation) => {
|
202
|
+
if (!blockchainInformation) {
|
203
|
+
return undefined;
|
204
|
+
}
|
205
|
+
return {
|
206
|
+
chainId: (0, utils_1.getChainIdFromOrbyChainId)(blockchainInformation.chainId),
|
207
|
+
environment: blockchainInformation.environment,
|
208
|
+
logoUrl: blockchainInformation.logoUrl,
|
209
|
+
name: blockchainInformation.name,
|
210
|
+
};
|
211
|
+
};
|
212
|
+
exports.extractBlockchainInformation = extractBlockchainInformation;
|
213
|
+
const extractMaxAmountPerInterval = (maxAmountPerInterval) => {
|
214
|
+
if (!maxAmountPerInterval) {
|
215
|
+
return undefined;
|
216
|
+
}
|
217
|
+
return {
|
218
|
+
amount: maxAmountPerInterval.amount,
|
219
|
+
interval: {
|
220
|
+
amount: maxAmountPerInterval.interval.amount,
|
221
|
+
unit: maxAmountPerInterval.interval.unit,
|
222
|
+
},
|
223
|
+
};
|
224
|
+
};
|
225
|
+
exports.extractMaxAmountPerInterval = extractMaxAmountPerInterval;
|
226
|
+
const extractAllowlistWithOpenFallback = (allowlist) => {
|
227
|
+
if (!allowlist) {
|
228
|
+
return undefined;
|
229
|
+
}
|
230
|
+
return {
|
231
|
+
tokenAllowlist: {
|
232
|
+
tokenAllowlistType: allowlist.tokenAllowlist.tokenAllowlistType,
|
233
|
+
sponsoredFunctions: allowlist.tokenAllowlist.sponsoredFunctions,
|
234
|
+
},
|
235
|
+
arbitraryContractAllowlist: allowlist.arbitraryContractAllowlist,
|
236
|
+
};
|
237
|
+
};
|
238
|
+
exports.extractAllowlistWithOpenFallback = extractAllowlistWithOpenFallback;
|
239
|
+
const extractGasSponsorshipPolicy = (gasSponsorshipPolicy) => {
|
240
|
+
if (!gasSponsorshipPolicy) {
|
241
|
+
return undefined;
|
242
|
+
}
|
243
|
+
return {
|
244
|
+
maxTotalGasSpendForInstance: (0, exports.extractMaxAmountPerInterval)(gasSponsorshipPolicy.maxTotalGasSpendForInstance),
|
245
|
+
maxGasSpendPerTransaction: gasSponsorshipPolicy.maxGasSpendPerTransaction,
|
246
|
+
allowlistWithOpenFallback: (0, exports.extractAllowlistWithOpenFallback)(gasSponsorshipPolicy.allowlistWithOpenFallback),
|
247
|
+
maxTotalTransactionCountForInstance: (0, exports.extractMaxAmountPerInterval)(gasSponsorshipPolicy.maxTotalTransactionCountForInstance),
|
248
|
+
maxTotalGasSpendPerUser: (0, exports.extractMaxAmountPerInterval)(gasSponsorshipPolicy.maxTotalGasSpendPerUser),
|
249
|
+
maxTotalTransactionCountPerUser: (0, exports.extractMaxAmountPerInterval)(gasSponsorshipPolicy.maxTotalTransactionCountPerUser),
|
250
|
+
};
|
251
|
+
};
|
252
|
+
exports.extractGasSponsorshipPolicy = extractGasSponsorshipPolicy;
|
253
|
+
const extractGasSpendForInstances = (gasSpendForInstances) => {
|
254
|
+
return gasSpendForInstances === null || gasSpendForInstances === void 0 ? void 0 : gasSpendForInstances.map((data) => (0, exports.extractGasSpendForInstance)(data));
|
255
|
+
};
|
256
|
+
exports.extractGasSpendForInstances = extractGasSpendForInstances;
|
257
|
+
const extractGasSpendForInstance = (gasSpendForInstance) => {
|
258
|
+
if (!gasSpendForInstance) {
|
259
|
+
return;
|
260
|
+
}
|
261
|
+
return {
|
262
|
+
instanceName: gasSpendForInstance.instanceName,
|
263
|
+
gasSpentForInstance: (0, exports.extractGasSponsorshipData)(gasSpendForInstance.gasSpentForInstance),
|
264
|
+
};
|
265
|
+
};
|
266
|
+
exports.extractGasSpendForInstance = extractGasSpendForInstance;
|
267
|
+
const extractGasSponsorshipInformation = (gasSponsorshipData) => {
|
268
|
+
return gasSponsorshipData === null || gasSponsorshipData === void 0 ? void 0 : gasSponsorshipData.map((data) => (0, exports.extractGasSponsorshipData)(data));
|
269
|
+
};
|
270
|
+
exports.extractGasSponsorshipInformation = extractGasSponsorshipInformation;
|
271
|
+
const extractGasSponsorshipData = (gasSponsorshipData) => {
|
272
|
+
if (!gasSponsorshipData) {
|
273
|
+
return undefined;
|
274
|
+
}
|
275
|
+
return {
|
276
|
+
totalGasSpent: currency_amount_1.CurrencyAmount.toCurrencyAmount(gasSponsorshipData.totalGasSpent),
|
277
|
+
totalTransactionCount: gasSponsorshipData.totalTransactionCount,
|
278
|
+
};
|
279
|
+
};
|
280
|
+
exports.extractGasSponsorshipData = extractGasSponsorshipData;
|
package/dist/utils/utils.d.ts
CHANGED
@@ -1,26 +1,9 @@
|
|
1
1
|
import { Blockchain } from "../enums";
|
2
|
-
import { AccountCluster, Activity, AllowlistWithOpenFallback, BlockchainInformation, FungibleTokenOverview, GasSpendForInstance, GasSponsorshipData, GasSponsorshipPolicy, Intent, MaxAmountPerInterval, OnchainOperation, Operation, OperationStatus, StandardizedBalance, StandardizedToken } from "../types";
|
3
|
-
export declare const extractAccountCluster: (accountCluster?: any) => AccountCluster;
|
4
|
-
export declare const extractOperationSet: (operations?: any) => Operation[];
|
5
|
-
export declare const extractOnchainOperation: (onchainOperation?: any) => OnchainOperation;
|
6
|
-
export declare const extractIntent: (intent?: any) => Intent;
|
7
|
-
export declare const extractOperationStatuses: (operationStatus?: any[]) => OperationStatus[];
|
8
|
-
export declare const extractOperationStatus: (status?: any) => OperationStatus;
|
9
|
-
export declare const extractActivities: (activities?: any[]) => Activity[];
|
10
|
-
export declare const extractFungibleTokenOverview: (overview?: any) => FungibleTokenOverview;
|
11
|
-
export declare const extractStandardizedBalances: (balances?: any) => StandardizedBalance[];
|
12
|
-
export declare const extractStandardizedBalance: (balance?: any) => StandardizedBalance;
|
13
|
-
export declare const extractStandardizedTokens: (tokens?: any) => StandardizedToken[];
|
14
|
-
export declare const extractStandardizedToken: (token?: any) => StandardizedToken;
|
15
|
-
export declare const extractBlockchainInformations: (blockchainInformation?: any[]) => BlockchainInformation[];
|
16
|
-
export declare const extractBlockchainInformation: (blockchainInformation?: any) => BlockchainInformation;
|
17
|
-
export declare const extractMaxAmountPerInterval: (maxAmountPerInterval?: any) => MaxAmountPerInterval;
|
18
|
-
export declare const extractAllowlistWithOpenFallback: (allowlist?: any) => AllowlistWithOpenFallback;
|
19
|
-
export declare const extractGasSponsorshipPolicy: (gasSponsorshipPolicy?: any) => GasSponsorshipPolicy;
|
20
|
-
export declare const extractGasSpendForInstances: (gasSpendForInstances?: any[]) => GasSpendForInstance[];
|
21
|
-
export declare const extractGasSpendForInstance: (gasSpendForInstance?: any) => GasSpendForInstance;
|
22
|
-
export declare const extractGasSponsorshipInformation: (gasSponsorshipData?: any[]) => GasSponsorshipData[];
|
23
|
-
export declare const extractGasSponsorshipData: (gasSponsorshipData?: any) => GasSponsorshipData;
|
24
2
|
export declare const getChainIdFromOrbyChainId: (value: string) => bigint | undefined;
|
25
3
|
export declare const getBlockchainIdFromBlockchain: (blockchain: Blockchain) => number;
|
4
|
+
export declare const hasError: (data: any) => {
|
5
|
+
code: number;
|
6
|
+
message: string;
|
7
|
+
};
|
26
8
|
export declare const getBlockchainFromName: (chainName: string) => Blockchain;
|
9
|
+
export declare const isMainnet: (chainId: bigint) => boolean;
|
package/dist/utils/utils.js
CHANGED
@@ -1,265 +1,8 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.isMainnet = exports.getBlockchainFromName = exports.hasError = exports.getBlockchainIdFromBlockchain = exports.getChainIdFromOrbyChainId = void 0;
|
4
4
|
const enums_1 = require("../enums");
|
5
5
|
const constants_1 = require("../constants");
|
6
|
-
const currency_amount_1 = require("../entities/financial/currency_amount");
|
7
|
-
const state_1 = require("../entities/state");
|
8
|
-
const currency_1 = require("../entities/financial/currency");
|
9
|
-
const fungible_token_amount_1 = require("../entities/financial/fungible_token_amount");
|
10
|
-
const fungible_token_1 = require("../entities/financial/fungible_token");
|
11
|
-
const account_1 = require("../entities/account");
|
12
|
-
const extractAccountCluster = (accountCluster) => {
|
13
|
-
var _a;
|
14
|
-
if (!accountCluster) {
|
15
|
-
return undefined;
|
16
|
-
}
|
17
|
-
return {
|
18
|
-
accountClusterId: accountCluster.accountClusterId,
|
19
|
-
accounts: (_a = accountCluster === null || accountCluster === void 0 ? void 0 : accountCluster.accounts) === null || _a === void 0 ? void 0 : _a.map((account) => account_1.Account.toAccount(account)),
|
20
|
-
};
|
21
|
-
};
|
22
|
-
exports.extractAccountCluster = extractAccountCluster;
|
23
|
-
const extractOperationSet = (operations) => {
|
24
|
-
if (!operations) {
|
25
|
-
return undefined;
|
26
|
-
}
|
27
|
-
return operations.map((operation) => {
|
28
|
-
var _a;
|
29
|
-
return {
|
30
|
-
status: operation.status,
|
31
|
-
primaryOperation: (0, exports.extractOnchainOperation)(operation.primaryOperation),
|
32
|
-
primaryOperationPreconditions: state_1.State.toState(operation.primaryOperationPreconditions),
|
33
|
-
inputState: state_1.State.toState(operation.inputState),
|
34
|
-
outputState: state_1.State.toState(operation.outputState),
|
35
|
-
intents: (_a = operation.intents) === null || _a === void 0 ? void 0 : _a.map((intent) => (0, exports.extractIntent)(intent)),
|
36
|
-
aggregateNetworkFeeInFiatCurrency: currency_amount_1.CurrencyAmount.toCurrencyAmount(operation.aggregateNetworkFeeInFiatCurrency),
|
37
|
-
aggregateOperationFeeInFiatCurrency: currency_amount_1.CurrencyAmount.toCurrencyAmount(operation.aggregateOperationFeeInFiatCurrency),
|
38
|
-
aggregateEstimatedTimeInMs: operation.aggregateEstimatedTimeInMs,
|
39
|
-
};
|
40
|
-
});
|
41
|
-
};
|
42
|
-
exports.extractOperationSet = extractOperationSet;
|
43
|
-
const extractOnchainOperation = (onchainOperation) => {
|
44
|
-
if (!onchainOperation) {
|
45
|
-
return undefined;
|
46
|
-
}
|
47
|
-
return {
|
48
|
-
chainId: (0, exports.getChainIdFromOrbyChainId)(onchainOperation.chainId),
|
49
|
-
data: onchainOperation.data,
|
50
|
-
estimatedNetworkFees: currency_amount_1.CurrencyAmount.toCurrencyAmount(onchainOperation.estimatedNetworkFees),
|
51
|
-
estimatedNetworkFeesInFiatCurrency: currency_amount_1.CurrencyAmount.toCurrencyAmount(onchainOperation.estimatedNetworkFeesInFiatCurrency),
|
52
|
-
estimatedTimeInMs: onchainOperation.estimatedTimeInMs
|
53
|
-
? BigInt(onchainOperation.estimatedTimeInMs)
|
54
|
-
: undefined,
|
55
|
-
format: onchainOperation.format,
|
56
|
-
from: onchainOperation.from,
|
57
|
-
gasLimit: onchainOperation.gasLimit
|
58
|
-
? BigInt(onchainOperation.gasLimit)
|
59
|
-
: undefined,
|
60
|
-
gasPrice: onchainOperation.gasPrice
|
61
|
-
? BigInt(onchainOperation.gasPrice)
|
62
|
-
: undefined,
|
63
|
-
inputState: state_1.State.toState(onchainOperation.inputState),
|
64
|
-
maxFeePerGas: onchainOperation.maxFeePerGas
|
65
|
-
? BigInt(onchainOperation.maxFeePerGas)
|
66
|
-
: undefined,
|
67
|
-
maxPriorityFeePerGas: onchainOperation.maxPriorityFeePerGas
|
68
|
-
? BigInt(onchainOperation.maxPriorityFeePerGas)
|
69
|
-
: undefined,
|
70
|
-
nativeCurrency: currency_1.Currency.toCurrency(onchainOperation.nativeCurrency),
|
71
|
-
nonce: onchainOperation.nonce ? BigInt(onchainOperation.nonce) : undefined,
|
72
|
-
outputState: state_1.State.toState(onchainOperation.outputState),
|
73
|
-
to: onchainOperation.to,
|
74
|
-
txRpcUrl: onchainOperation.txRpcUrl,
|
75
|
-
type: onchainOperation.type,
|
76
|
-
value: onchainOperation.value ? BigInt(onchainOperation.value) : undefined,
|
77
|
-
};
|
78
|
-
};
|
79
|
-
exports.extractOnchainOperation = extractOnchainOperation;
|
80
|
-
const extractIntent = (intent) => {
|
81
|
-
if (!intent) {
|
82
|
-
return undefined;
|
83
|
-
}
|
84
|
-
return {
|
85
|
-
estimatedProtocolFees: fungible_token_amount_1.FungibleTokenAmount.toFungibleTokenAmount(intent.estimatedProtocolFees),
|
86
|
-
estimatedProtocolFeesInFiatCurrency: currency_amount_1.CurrencyAmount.toCurrencyAmount(intent.estimatedProtocolFeesInFiatCurrency),
|
87
|
-
inputState: state_1.State.toState(intent.inputState),
|
88
|
-
intentOperations: intent.intentOperations.map((operation) => (0, exports.extractOnchainOperation)(operation)),
|
89
|
-
outputState: state_1.State.toState(intent.outputState),
|
90
|
-
};
|
91
|
-
};
|
92
|
-
exports.extractIntent = extractIntent;
|
93
|
-
const extractOperationStatuses = (operationStatus) => {
|
94
|
-
return operationStatus === null || operationStatus === void 0 ? void 0 : operationStatus.map((status) => (0, exports.extractOperationStatus)(status));
|
95
|
-
};
|
96
|
-
exports.extractOperationStatuses = extractOperationStatuses;
|
97
|
-
const extractOperationStatus = (status) => {
|
98
|
-
if (!status) {
|
99
|
-
return undefined;
|
100
|
-
}
|
101
|
-
return {
|
102
|
-
blockHash: status.blockHash,
|
103
|
-
blockNumber: status.blockNumber ? BigInt(status.blockNumber) : undefined,
|
104
|
-
chainId: status.chainId
|
105
|
-
? (0, exports.getChainIdFromOrbyChainId)(status.chainId)
|
106
|
-
: undefined,
|
107
|
-
errorReason: status.errorReason,
|
108
|
-
hash: status.hash,
|
109
|
-
id: status.id,
|
110
|
-
status: status.status,
|
111
|
-
type: status.type,
|
112
|
-
};
|
113
|
-
};
|
114
|
-
exports.extractOperationStatus = extractOperationStatus;
|
115
|
-
const extractActivities = (activities) => {
|
116
|
-
if (!activities) {
|
117
|
-
return undefined;
|
118
|
-
}
|
119
|
-
return activities.map((activity) => {
|
120
|
-
return {
|
121
|
-
aggregateFiatValueOfInputState: currency_amount_1.CurrencyAmount.toCurrencyAmount(activity.aggregateFiatValueOfInputState),
|
122
|
-
aggregateFiatValueOfOutputState: currency_amount_1.CurrencyAmount.toCurrencyAmount(activity.aggregateFiatValueOfOutputState),
|
123
|
-
aggregateNetworkFeesInFiatCurrency: currency_amount_1.CurrencyAmount.toCurrencyAmount(activity.aggregateNetworkFeesInFiatCurrency),
|
124
|
-
aggregateProtocolFeesInFiatCurrency: currency_amount_1.CurrencyAmount.toCurrencyAmount(activity.aggregateProtocolFeesInFiatCurrency),
|
125
|
-
category: activity.category,
|
126
|
-
initiateAt: activity.initiateAt,
|
127
|
-
inputState: state_1.State.toState(activity.inputState),
|
128
|
-
operationStatuses: (0, exports.extractOperationStatus)(activity.operationStatuses),
|
129
|
-
outputState: state_1.State.toState(activity.outputState),
|
130
|
-
overallStatus: activity.overallStatus,
|
131
|
-
};
|
132
|
-
});
|
133
|
-
};
|
134
|
-
exports.extractActivities = extractActivities;
|
135
|
-
const extractFungibleTokenOverview = (overview) => {
|
136
|
-
if (!overview) {
|
137
|
-
return undefined;
|
138
|
-
}
|
139
|
-
return {
|
140
|
-
tokenCount: overview.tokenCount,
|
141
|
-
hiddenTokenCount: overview.hiddenTokenCount,
|
142
|
-
totalValueInFiat: currency_amount_1.CurrencyAmount.toCurrencyAmount(overview.totalValueInFiat),
|
143
|
-
};
|
144
|
-
};
|
145
|
-
exports.extractFungibleTokenOverview = extractFungibleTokenOverview;
|
146
|
-
const extractStandardizedBalances = (balances) => {
|
147
|
-
return balances === null || balances === void 0 ? void 0 : balances.map((balance) => (0, exports.extractStandardizedBalance)(balance));
|
148
|
-
};
|
149
|
-
exports.extractStandardizedBalances = extractStandardizedBalances;
|
150
|
-
const extractStandardizedBalance = (balance) => {
|
151
|
-
if (!balance) {
|
152
|
-
return undefined;
|
153
|
-
}
|
154
|
-
return {
|
155
|
-
standardizedTokenId: balance.standardizedTokenId,
|
156
|
-
tokenBalances: balance.tokenBalances.map((ft) => fungible_token_amount_1.FungibleTokenAmount.toFungibleTokenAmount(ft)),
|
157
|
-
tokenBalancesOnChains: balance.tokenBalancesOnChains.map((ft) => fungible_token_amount_1.FungibleTokenAmount.toFungibleTokenAmount(ft)),
|
158
|
-
total: currency_amount_1.CurrencyAmount.toCurrencyAmount(balance.total),
|
159
|
-
totalValueInFiat: currency_amount_1.CurrencyAmount.toCurrencyAmount(balance.totalValueInFiat),
|
160
|
-
};
|
161
|
-
};
|
162
|
-
exports.extractStandardizedBalance = extractStandardizedBalance;
|
163
|
-
const extractStandardizedTokens = (tokens) => {
|
164
|
-
return tokens === null || tokens === void 0 ? void 0 : tokens.map((token) => (0, exports.extractStandardizedToken)(token));
|
165
|
-
};
|
166
|
-
exports.extractStandardizedTokens = extractStandardizedTokens;
|
167
|
-
const extractStandardizedToken = (token) => {
|
168
|
-
if (!token) {
|
169
|
-
return undefined;
|
170
|
-
}
|
171
|
-
return {
|
172
|
-
stardardizedTokenId: token.stardardizedTokenId,
|
173
|
-
currency: currency_1.Currency.toCurrency(token.currency),
|
174
|
-
priceInFiat: currency_amount_1.CurrencyAmount.toCurrencyAmount(token.priceInFiat),
|
175
|
-
tokens: token.tokens.map((ft) => fungible_token_1.FungibleToken.toFungibleToken(ft)),
|
176
|
-
};
|
177
|
-
};
|
178
|
-
exports.extractStandardizedToken = extractStandardizedToken;
|
179
|
-
const extractBlockchainInformations = (blockchainInformation) => {
|
180
|
-
return blockchainInformation === null || blockchainInformation === void 0 ? void 0 : blockchainInformation.map((info) => (0, exports.extractBlockchainInformation)(info));
|
181
|
-
};
|
182
|
-
exports.extractBlockchainInformations = extractBlockchainInformations;
|
183
|
-
const extractBlockchainInformation = (blockchainInformation) => {
|
184
|
-
if (!blockchainInformation) {
|
185
|
-
return undefined;
|
186
|
-
}
|
187
|
-
return {
|
188
|
-
chainId: (0, exports.getChainIdFromOrbyChainId)(blockchainInformation.chainId),
|
189
|
-
environment: blockchainInformation.environment,
|
190
|
-
logoUrl: blockchainInformation.logoUrl,
|
191
|
-
name: blockchainInformation.name,
|
192
|
-
};
|
193
|
-
};
|
194
|
-
exports.extractBlockchainInformation = extractBlockchainInformation;
|
195
|
-
const extractMaxAmountPerInterval = (maxAmountPerInterval) => {
|
196
|
-
if (!maxAmountPerInterval) {
|
197
|
-
return undefined;
|
198
|
-
}
|
199
|
-
return {
|
200
|
-
amount: maxAmountPerInterval.amount,
|
201
|
-
interval: {
|
202
|
-
amount: maxAmountPerInterval.interval.amount,
|
203
|
-
unit: maxAmountPerInterval.interval.unit,
|
204
|
-
},
|
205
|
-
};
|
206
|
-
};
|
207
|
-
exports.extractMaxAmountPerInterval = extractMaxAmountPerInterval;
|
208
|
-
const extractAllowlistWithOpenFallback = (allowlist) => {
|
209
|
-
if (!allowlist) {
|
210
|
-
return undefined;
|
211
|
-
}
|
212
|
-
return {
|
213
|
-
tokenAllowlist: {
|
214
|
-
tokenAllowlistType: allowlist.tokenAllowlist.tokenAllowlistType,
|
215
|
-
sponsoredFunctions: allowlist.tokenAllowlist.sponsoredFunctions,
|
216
|
-
},
|
217
|
-
arbitraryContractAllowlist: allowlist.arbitraryContractAllowlist,
|
218
|
-
};
|
219
|
-
};
|
220
|
-
exports.extractAllowlistWithOpenFallback = extractAllowlistWithOpenFallback;
|
221
|
-
const extractGasSponsorshipPolicy = (gasSponsorshipPolicy) => {
|
222
|
-
if (!gasSponsorshipPolicy) {
|
223
|
-
return undefined;
|
224
|
-
}
|
225
|
-
return {
|
226
|
-
maxTotalGasSpendForInstance: (0, exports.extractMaxAmountPerInterval)(gasSponsorshipPolicy.maxTotalGasSpendForInstance),
|
227
|
-
maxGasSpendPerTransaction: gasSponsorshipPolicy.maxGasSpendPerTransaction,
|
228
|
-
allowlistWithOpenFallback: (0, exports.extractAllowlistWithOpenFallback)(gasSponsorshipPolicy.allowlistWithOpenFallback),
|
229
|
-
maxTotalTransactionCountForInstance: (0, exports.extractMaxAmountPerInterval)(gasSponsorshipPolicy.maxTotalTransactionCountForInstance),
|
230
|
-
maxTotalGasSpendPerUser: (0, exports.extractMaxAmountPerInterval)(gasSponsorshipPolicy.maxTotalGasSpendPerUser),
|
231
|
-
maxTotalTransactionCountPerUser: (0, exports.extractMaxAmountPerInterval)(gasSponsorshipPolicy.maxTotalTransactionCountPerUser),
|
232
|
-
};
|
233
|
-
};
|
234
|
-
exports.extractGasSponsorshipPolicy = extractGasSponsorshipPolicy;
|
235
|
-
const extractGasSpendForInstances = (gasSpendForInstances) => {
|
236
|
-
return gasSpendForInstances === null || gasSpendForInstances === void 0 ? void 0 : gasSpendForInstances.map((data) => (0, exports.extractGasSpendForInstance)(data));
|
237
|
-
};
|
238
|
-
exports.extractGasSpendForInstances = extractGasSpendForInstances;
|
239
|
-
const extractGasSpendForInstance = (gasSpendForInstance) => {
|
240
|
-
if (!gasSpendForInstance) {
|
241
|
-
return;
|
242
|
-
}
|
243
|
-
return {
|
244
|
-
instanceName: gasSpendForInstance.instanceName,
|
245
|
-
gasSpentForInstance: (0, exports.extractGasSponsorshipData)(gasSpendForInstance.gasSpentForInstance),
|
246
|
-
};
|
247
|
-
};
|
248
|
-
exports.extractGasSpendForInstance = extractGasSpendForInstance;
|
249
|
-
const extractGasSponsorshipInformation = (gasSponsorshipData) => {
|
250
|
-
return gasSponsorshipData === null || gasSponsorshipData === void 0 ? void 0 : gasSponsorshipData.map((data) => (0, exports.extractGasSponsorshipData)(data));
|
251
|
-
};
|
252
|
-
exports.extractGasSponsorshipInformation = extractGasSponsorshipInformation;
|
253
|
-
const extractGasSponsorshipData = (gasSponsorshipData) => {
|
254
|
-
if (!gasSponsorshipData) {
|
255
|
-
return undefined;
|
256
|
-
}
|
257
|
-
return {
|
258
|
-
totalGasSpent: currency_amount_1.CurrencyAmount.toCurrencyAmount(gasSponsorshipData.totalGasSpent),
|
259
|
-
totalTransactionCount: gasSponsorshipData.totalTransactionCount,
|
260
|
-
};
|
261
|
-
};
|
262
|
-
exports.extractGasSponsorshipData = extractGasSponsorshipData;
|
263
6
|
const getChainIdFromOrbyChainId = (value) => {
|
264
7
|
var _a;
|
265
8
|
let chainId = undefined;
|
@@ -285,6 +28,13 @@ const getBlockchainIdFromBlockchain = (blockchain) => {
|
|
285
28
|
return constants_1.BLOCKCHAIN_ID[blockchain];
|
286
29
|
};
|
287
30
|
exports.getBlockchainIdFromBlockchain = getBlockchainIdFromBlockchain;
|
31
|
+
const hasError = (data) => {
|
32
|
+
if ((data === null || data === void 0 ? void 0 : data.code) && (data === null || data === void 0 ? void 0 : data.message)) {
|
33
|
+
return { code: data.code, message: data.message };
|
34
|
+
}
|
35
|
+
return undefined;
|
36
|
+
};
|
37
|
+
exports.hasError = hasError;
|
288
38
|
const getBlockchainFromName = (chainName) => {
|
289
39
|
var _a;
|
290
40
|
const formattedChainName = (_a = chainName === null || chainName === void 0 ? void 0 : chainName.toLowerCase()) === null || _a === void 0 ? void 0 : _a.replace("-", "_");
|
@@ -317,3 +67,8 @@ const getBlockchainFromName = (chainName) => {
|
|
317
67
|
}
|
318
68
|
};
|
319
69
|
exports.getBlockchainFromName = getBlockchainFromName;
|
70
|
+
const isMainnet = (chainId) => {
|
71
|
+
const blockchain = constants_1.BLOCKCHAIN_ID_TO_BLOCKCHAIN[Number(chainId)];
|
72
|
+
return constants_1.CHAIN_CONFIGS[blockchain].environment == enums_1.BlockchainEnvironment.MAINNET;
|
73
|
+
};
|
74
|
+
exports.isMainnet = isMainnet;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@orb-labs/orby-core",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.4",
|
4
4
|
"exports": {
|
5
5
|
".": "./dist/index.js"
|
6
6
|
},
|
@@ -15,11 +15,16 @@
|
|
15
15
|
"watch:alias": "nodemon --watch dist --exec \"tsc-alias -p tsconfig.json\""
|
16
16
|
},
|
17
17
|
"devDependencies": {
|
18
|
+
"@types/big.js": "^6.2.2",
|
18
19
|
"@types/lodash": "^4.17.13",
|
20
|
+
"concurrently": "^9.1.0",
|
19
21
|
"eslint": "^8",
|
20
22
|
"javascript-obfuscator": "^4.1.1",
|
21
23
|
"nodemon": "^3.0.3",
|
22
24
|
"tsc-alias": "^1.8.10",
|
23
25
|
"typescript": "^5.6.3"
|
26
|
+
},
|
27
|
+
"dependencies": {
|
28
|
+
"@uniswap/sdk-core": "^5.9.0"
|
24
29
|
}
|
25
30
|
}
|