@orb-labs/orby-core 0.0.22 → 0.0.24
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 +10 -1
- package/dist/cjs/actions/account_cluster.js +6 -6
- package/dist/cjs/actions/blockchain.js +1 -2
- package/dist/cjs/actions/instance.js +2 -2
- package/dist/cjs/actions/operation.js +15 -16
- package/dist/cjs/actions/token.js +2 -3
- package/dist/cjs/constants.d.ts +1 -5
- package/dist/cjs/constants.js +1 -5
- package/dist/cjs/entities/library_request.d.ts +4 -1
- package/dist/cjs/entities/library_request.js +40 -0
- package/dist/cjs/enums.d.ts +0 -25
- package/dist/cjs/enums.js +1 -29
- package/dist/cjs/types.d.ts +5 -1
- package/dist/cjs/utils/utils.d.ts +2 -4
- package/dist/cjs/utils/utils.js +9 -77
- package/dist/esm/actions/account_cluster.js +7 -7
- package/dist/esm/actions/blockchain.js +1 -2
- package/dist/esm/actions/instance.js +3 -3
- package/dist/esm/actions/operation.js +15 -16
- package/dist/esm/actions/token.js +2 -3
- package/dist/esm/constants.d.ts +1 -5
- package/dist/esm/constants.js +0 -4
- package/dist/esm/entities/library_request.d.ts +4 -1
- package/dist/esm/entities/library_request.js +41 -1
- package/dist/esm/enums.d.ts +0 -25
- package/dist/esm/enums.js +0 -28
- package/dist/esm/types.d.ts +5 -1
- package/dist/esm/utils/utils.d.ts +2 -4
- package/dist/esm/utils/utils.js +8 -74
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +1 -1
@@ -1,12 +1,11 @@
|
|
1
1
|
import { extractBlockchainInformation, extractBlockchainInformations, } from "../utils/action_helpers.js";
|
2
2
|
import { LibraryRequest } from "../entities/library_request.js";
|
3
|
-
import { getOrbyChainId } from "../utils/utils.js";
|
4
3
|
export class BlockchainActions extends LibraryRequest {
|
5
4
|
constructor(library, client, provider) {
|
6
5
|
super(library, client, provider);
|
7
6
|
}
|
8
7
|
async getBlockchainInformation(chainId) {
|
9
|
-
const orbyChainId = await getOrbyChainId(chainId);
|
8
|
+
const orbyChainId = await this.getOrbyChainId(chainId);
|
10
9
|
const { blockchain, code, message } = await this.sendRequest("orby_getBlockchainInformation", [{ chainId: orbyChainId }]);
|
11
10
|
if (code && message) {
|
12
11
|
console.error("[getBlockchainInformation]", code, message);
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { extractGasSponsorshipPolicy } from "../utils/action_helpers.js";
|
2
2
|
import { LibraryRequest } from "../entities/library_request.js";
|
3
|
-
import { getChainIdFromOrbyChainId
|
3
|
+
import { getChainIdFromOrbyChainId } from "../utils/utils.js";
|
4
4
|
export class InstanceActions extends LibraryRequest {
|
5
5
|
constructor(library, client, provider) {
|
6
6
|
super(library, client, provider);
|
@@ -8,7 +8,7 @@ export class InstanceActions extends LibraryRequest {
|
|
8
8
|
async setCustomChainEndpointsForInstance(chainEndpoints) {
|
9
9
|
const promises = chainEndpoints.map(async (endpoint) => {
|
10
10
|
return {
|
11
|
-
chainId: await getOrbyChainId(endpoint.chainId),
|
11
|
+
chainId: await this.getOrbyChainId(endpoint.chainId),
|
12
12
|
customRpcUrls: endpoint.customRpcUrls,
|
13
13
|
customIndexerUrls: endpoint.customIndexerUrls,
|
14
14
|
};
|
@@ -22,7 +22,7 @@ export class InstanceActions extends LibraryRequest {
|
|
22
22
|
return success;
|
23
23
|
}
|
24
24
|
async removeCustomChainEndpointForInstance(chainIds) {
|
25
|
-
const promises = chainIds.map(async (chainId) => await getOrbyChainId(chainId));
|
25
|
+
const promises = chainIds.map(async (chainId) => await this.getOrbyChainId(chainId));
|
26
26
|
const formattedChainIds = await Promise.all(promises);
|
27
27
|
const { success, code, message } = await this.sendRequest("orby_removeCustomChainEndpointForInstance", [{ chainIds: formattedChainIds }]);
|
28
28
|
if (code && message) {
|
@@ -2,7 +2,6 @@ import { extractOperationSet, extractOperationStatuses, } from "../utils/action_
|
|
2
2
|
import { CurrencyAmount } from "../entities/financial/currency_amount.js";
|
3
3
|
import { AccountType, OperationDataFormat, OperationStatusType, OperationType, } from "../enums.js";
|
4
4
|
import { LibraryRequest } from "../entities/library_request.js";
|
5
|
-
import { getOrbyChainId } from "../utils/utils.js";
|
6
5
|
import { Account } from "../entities/account.js";
|
7
6
|
// from here: https://stackoverflow.com/questions/65152373/typescript-serialize-bigint-in-json
|
8
7
|
BigInt.prototype.toJSON = function () {
|
@@ -17,7 +16,7 @@ export class OperationActions extends LibraryRequest {
|
|
17
16
|
? {
|
18
17
|
...gasToken,
|
19
18
|
tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
|
20
|
-
chainId: await getOrbyChainId(chainId),
|
19
|
+
chainId: await this.getOrbyChainId(chainId),
|
21
20
|
address,
|
22
21
|
})) ?? []),
|
23
22
|
}
|
@@ -38,7 +37,7 @@ export class OperationActions extends LibraryRequest {
|
|
38
37
|
? {
|
39
38
|
...gasToken,
|
40
39
|
tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
|
41
|
-
chainId: await getOrbyChainId(chainId),
|
40
|
+
chainId: await this.getOrbyChainId(chainId),
|
42
41
|
address,
|
43
42
|
})) ?? []),
|
44
43
|
}
|
@@ -57,7 +56,7 @@ export class OperationActions extends LibraryRequest {
|
|
57
56
|
? {
|
58
57
|
...gasToken,
|
59
58
|
tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
|
60
|
-
chainId: await getOrbyChainId(chainId),
|
59
|
+
chainId: await this.getOrbyChainId(chainId),
|
61
60
|
address,
|
62
61
|
})) ?? []),
|
63
62
|
}
|
@@ -153,13 +152,13 @@ export class OperationActions extends LibraryRequest {
|
|
153
152
|
? {
|
154
153
|
...gasToken,
|
155
154
|
tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
|
156
|
-
chainId: await getOrbyChainId(chainId),
|
155
|
+
chainId: await this.getOrbyChainId(chainId),
|
157
156
|
address,
|
158
157
|
})) ?? []),
|
159
158
|
}
|
160
159
|
: undefined;
|
161
160
|
const formattedRecepient = {
|
162
|
-
chainId: await getOrbyChainId(recipient.chainId),
|
161
|
+
chainId: await this.getOrbyChainId(recipient.chainId),
|
163
162
|
recipientAddress: recipient.recipientAddress,
|
164
163
|
};
|
165
164
|
const operationSet = await this.sendRequest("orby_getOperationsToTransferToken", [
|
@@ -178,7 +177,7 @@ export class OperationActions extends LibraryRequest {
|
|
178
177
|
? {
|
179
178
|
...input,
|
180
179
|
tokenSources: await Promise.all(input.tokenSources?.map(async ({ chainId, address }) => ({
|
181
|
-
chainId: await getOrbyChainId(chainId),
|
180
|
+
chainId: await this.getOrbyChainId(chainId),
|
182
181
|
address,
|
183
182
|
})) ?? []),
|
184
183
|
}
|
@@ -188,7 +187,7 @@ export class OperationActions extends LibraryRequest {
|
|
188
187
|
...output,
|
189
188
|
tokenDestination: output.tokenDestination
|
190
189
|
? {
|
191
|
-
chainId: await getOrbyChainId(output.tokenDestination.chainId),
|
190
|
+
chainId: await this.getOrbyChainId(output.tokenDestination.chainId),
|
192
191
|
address: output.tokenDestination.address,
|
193
192
|
}
|
194
193
|
: undefined,
|
@@ -198,7 +197,7 @@ export class OperationActions extends LibraryRequest {
|
|
198
197
|
? {
|
199
198
|
...gasToken,
|
200
199
|
tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
|
201
|
-
chainId: await getOrbyChainId(chainId),
|
200
|
+
chainId: await this.getOrbyChainId(chainId),
|
202
201
|
address,
|
203
202
|
})) ?? []),
|
204
203
|
}
|
@@ -219,7 +218,7 @@ export class OperationActions extends LibraryRequest {
|
|
219
218
|
? {
|
220
219
|
...input,
|
221
220
|
tokenSources: await Promise.all(input.tokenSources?.map(async ({ chainId, address }) => ({
|
222
|
-
chainId: await getOrbyChainId(chainId),
|
221
|
+
chainId: await this.getOrbyChainId(chainId),
|
223
222
|
address,
|
224
223
|
})) ?? []),
|
225
224
|
}
|
@@ -229,7 +228,7 @@ export class OperationActions extends LibraryRequest {
|
|
229
228
|
...output,
|
230
229
|
tokenDestination: output.tokenDestination
|
231
230
|
? {
|
232
|
-
chainId: await getOrbyChainId(output.tokenDestination.chainId),
|
231
|
+
chainId: await this.getOrbyChainId(output.tokenDestination.chainId),
|
233
232
|
address: output.tokenDestination.address,
|
234
233
|
}
|
235
234
|
: undefined,
|
@@ -247,12 +246,12 @@ export class OperationActions extends LibraryRequest {
|
|
247
246
|
}
|
248
247
|
async getOperationsToBridge(accountClusterId, standardizedTokenId, amount, tokenSources, tokenDestination, gasToken) {
|
249
248
|
const formattedTokenSources = await Promise.all(tokenSources.map(async ({ chainId, address }) => ({
|
250
|
-
chainId: await getOrbyChainId(chainId),
|
249
|
+
chainId: await this.getOrbyChainId(chainId),
|
251
250
|
address,
|
252
251
|
})));
|
253
252
|
const formattedDestination = tokenDestination
|
254
253
|
? {
|
255
|
-
chainId: await getOrbyChainId(tokenDestination.chainId),
|
254
|
+
chainId: await this.getOrbyChainId(tokenDestination.chainId),
|
256
255
|
address: tokenDestination.address,
|
257
256
|
}
|
258
257
|
: undefined;
|
@@ -260,7 +259,7 @@ export class OperationActions extends LibraryRequest {
|
|
260
259
|
? {
|
261
260
|
...gasToken,
|
262
261
|
tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
|
263
|
-
chainId: await getOrbyChainId(chainId),
|
262
|
+
chainId: await this.getOrbyChainId(chainId),
|
264
263
|
address,
|
265
264
|
})) ?? []),
|
266
265
|
}
|
@@ -391,7 +390,7 @@ export class OperationActions extends LibraryRequest {
|
|
391
390
|
signature: signature,
|
392
391
|
data: operation.data,
|
393
392
|
from: operation.from,
|
394
|
-
chainId: await getOrbyChainId(operation.chainId),
|
393
|
+
chainId: await this.getOrbyChainId(operation.chainId),
|
395
394
|
});
|
396
395
|
}
|
397
396
|
// batch sign all the smart contract transactions
|
@@ -421,7 +420,7 @@ export class OperationActions extends LibraryRequest {
|
|
421
420
|
signature: userOperation.signature,
|
422
421
|
data: JSON.stringify(userOperation),
|
423
422
|
from: transactions[0].from,
|
424
|
-
chainId: await getOrbyChainId(transactions[0].chainId),
|
423
|
+
chainId: await this.getOrbyChainId(transactions[0].chainId),
|
425
424
|
});
|
426
425
|
}
|
427
426
|
const { operationSetId, operationResponses } = await this.sendSignedOperations(accountCluster.accountClusterId, signedOperations);
|
@@ -1,13 +1,12 @@
|
|
1
1
|
import { extractStandardizedTokens } from "../utils/action_helpers.js";
|
2
2
|
import { LibraryRequest } from "../entities/library_request.js";
|
3
|
-
import { getOrbyChainId } from "../utils/utils.js";
|
4
3
|
export class TokenActions extends LibraryRequest {
|
5
4
|
constructor(library, client, provider) {
|
6
5
|
super(library, client, provider);
|
7
6
|
}
|
8
7
|
async getStandardizedTokenIds(tokens) {
|
9
8
|
const promises = tokens.map(async ({ tokenAddress, chainId }) => {
|
10
|
-
return { chainId: await getOrbyChainId(chainId), tokenAddress };
|
9
|
+
return { chainId: await this.getOrbyChainId(chainId), tokenAddress };
|
11
10
|
});
|
12
11
|
const formattedTokensInfo = await Promise.all(promises);
|
13
12
|
const { standardizedTokenIds, message, code } = await this.sendRequest("orby_getStandardizedTokenIds", [
|
@@ -23,7 +22,7 @@ export class TokenActions extends LibraryRequest {
|
|
23
22
|
}
|
24
23
|
async getStandardizedTokens(tokens) {
|
25
24
|
const promises = tokens.map(async ({ tokenAddress, chainId }) => {
|
26
|
-
return { chainId: await getOrbyChainId(chainId), tokenAddress };
|
25
|
+
return { chainId: await this.getOrbyChainId(chainId), tokenAddress };
|
27
26
|
});
|
28
27
|
const formattedTokensInfo = await Promise.all(promises);
|
29
28
|
const { standardizedTokens, message, code } = await this.sendRequest("orby_getStandardizedTokens", [
|
package/dist/esm/constants.d.ts
CHANGED
@@ -1,9 +1,5 @@
|
|
1
|
-
import { Blockchain } from "./enums.js";
|
2
1
|
import { Currency } from "./entities/financial/currency.js";
|
3
2
|
import { ChainConfigs } from "./types.js";
|
4
3
|
export declare const Big: any;
|
5
|
-
export declare const
|
6
|
-
export declare const BLOCKCHAIN_ID: Record<Blockchain, number>;
|
7
|
-
export declare const CHAIN_CONFIGS: Record<Blockchain, ChainConfigs>;
|
8
|
-
export declare const BLOCKCHAIN_ID_TO_BLOCKCHAIN: Record<number, Blockchain>;
|
4
|
+
export declare const CHAIN_CONFIGS: Record<number, ChainConfigs>;
|
9
5
|
export declare const FIAT_CURRENCY: Currency;
|
package/dist/esm/constants.js
CHANGED
@@ -2,9 +2,5 @@ import toFormat from "toformat";
|
|
2
2
|
import _Big from "big.js";
|
3
3
|
import { Currency } from "./entities/financial/currency.js";
|
4
4
|
export const Big = toFormat(_Big);
|
5
|
-
// TO-DO (Sofia): fix API to return full list instead of just mainnet
|
6
|
-
export const ORBY_URL = "https://api-rpc-dev.orblabs.xyz/f1c1d996-8df4-4d23-b926-ca702173021d/mainnet";
|
7
|
-
export const BLOCKCHAIN_ID = {};
|
8
5
|
export const CHAIN_CONFIGS = {};
|
9
|
-
export const BLOCKCHAIN_ID_TO_BLOCKCHAIN = {};
|
10
6
|
export const FIAT_CURRENCY = new Currency(6, "USD", "US Dollar", undefined, false, false);
|
@@ -1,8 +1,11 @@
|
|
1
|
-
import { LIBRARY_TYPE } from "../enums.js";
|
1
|
+
import { LIBRARY_TYPE, VMType } from "../enums.js";
|
2
2
|
export declare class LibraryRequest {
|
3
3
|
readonly library: LIBRARY_TYPE;
|
4
4
|
readonly client?: any;
|
5
5
|
readonly provider?: any;
|
6
6
|
constructor(library: LIBRARY_TYPE, client?: any, provider?: any);
|
7
7
|
sendRequest(method: string, params: any[]): Promise<any>;
|
8
|
+
protected getOrbyChainId: (chainId: bigint) => Promise<string>;
|
9
|
+
protected getVirtualEnvironment: (id: bigint) => Promise<VMType>;
|
10
|
+
protected providerUrl(): string;
|
8
11
|
}
|
@@ -1,7 +1,29 @@
|
|
1
|
-
import { LIBRARY_TYPE } from "../enums.js";
|
1
|
+
import { LIBRARY_TYPE, VMType } from "../enums.js";
|
2
2
|
import invariant from "tiny-invariant";
|
3
|
+
import { CHAIN_CONFIGS } from "../constants.js";
|
4
|
+
import { initializeBlockchainInformation } from "../utils/utils.js";
|
3
5
|
export class LibraryRequest {
|
4
6
|
constructor(library, client, provider) {
|
7
|
+
this.getOrbyChainId = async (chainId) => {
|
8
|
+
if (!chainId) {
|
9
|
+
return undefined;
|
10
|
+
}
|
11
|
+
const environment = await this.getVirtualEnvironment(chainId);
|
12
|
+
switch (environment) {
|
13
|
+
case VMType.SVM:
|
14
|
+
return `SVM-${chainId.toString()}`;
|
15
|
+
case VMType.EVM:
|
16
|
+
return `EIP155-${chainId.toString()}`;
|
17
|
+
default:
|
18
|
+
return undefined;
|
19
|
+
}
|
20
|
+
};
|
21
|
+
this.getVirtualEnvironment = async (id) => {
|
22
|
+
if (Object.keys(CHAIN_CONFIGS).length == 0) {
|
23
|
+
await initializeBlockchainInformation(this.providerUrl());
|
24
|
+
}
|
25
|
+
return CHAIN_CONFIGS[Number(id)]?.vmType;
|
26
|
+
};
|
5
27
|
if (library == LIBRARY_TYPE.VIEM) {
|
6
28
|
invariant(client, "CLIENT");
|
7
29
|
invariant(!provider, "PROVIDER");
|
@@ -20,6 +42,9 @@ export class LibraryRequest {
|
|
20
42
|
this.provider = provider;
|
21
43
|
}
|
22
44
|
sendRequest(method, params) {
|
45
|
+
if (Object.keys(CHAIN_CONFIGS).length == 0) {
|
46
|
+
initializeBlockchainInformation(this.providerUrl());
|
47
|
+
}
|
23
48
|
if (this.library == LIBRARY_TYPE.VIEM) {
|
24
49
|
return this.client.request({ method, params });
|
25
50
|
}
|
@@ -27,4 +52,19 @@ export class LibraryRequest {
|
|
27
52
|
return this.provider.send(method, params);
|
28
53
|
}
|
29
54
|
}
|
55
|
+
providerUrl() {
|
56
|
+
let url = "";
|
57
|
+
if (this.library == LIBRARY_TYPE.VIEM) {
|
58
|
+
url = this.client?.transport?.url;
|
59
|
+
}
|
60
|
+
else if (this.library == LIBRARY_TYPE.ETHERS) {
|
61
|
+
url = this.provider._getConnection().url;
|
62
|
+
}
|
63
|
+
const uuidRegex = /([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/i;
|
64
|
+
const match = url.match(uuidRegex);
|
65
|
+
if (!match)
|
66
|
+
return url;
|
67
|
+
const endIndex = url.indexOf(match[1]) + match[1].length;
|
68
|
+
return url.slice(0, endIndex);
|
69
|
+
}
|
30
70
|
}
|
package/dist/esm/enums.d.ts
CHANGED
@@ -1,28 +1,3 @@
|
|
1
|
-
export declare enum Blockchain {
|
2
|
-
ETHEREUM = "ethereum",
|
3
|
-
POLYGON = "polygon",
|
4
|
-
BINANCE = "binance",
|
5
|
-
ARBITRUM = "arbitrum",
|
6
|
-
BASE = "base",
|
7
|
-
AVALANCHE = "avalanche",
|
8
|
-
ARBITRUM_NOVA = "arbitrum_nova",
|
9
|
-
OPTIMISM = "optimism",
|
10
|
-
EVMOS = "evmos",
|
11
|
-
MOONBEAM = "moonbeam",
|
12
|
-
SOLANA = "solana",
|
13
|
-
ETHEREUM_SEPOLIA = "ethereum_sepolia",
|
14
|
-
ETHEREUM_HOLESKY = "ethereum_holesky",
|
15
|
-
BASE_SEPOLIA = "base_sepolia",
|
16
|
-
ARBITRUM_SEPOLIA = "arbitrum_sepolia",
|
17
|
-
OPTIMISM_SEPOLIA = "optimism_sepolia",
|
18
|
-
POLYGON_AMOY = "polygon_amoy",
|
19
|
-
BINANCE_TESTNET = "binance_testnet",
|
20
|
-
OPBNB_TESTNET = "opbnb_testnet",
|
21
|
-
MOONBEAM_ALPHA = "moonbeam_alpha",
|
22
|
-
HARDHAT = "hardhat",
|
23
|
-
LOCAL_CHAIN_0 = "local_chain_0",
|
24
|
-
LOCAL_CHAIN_1 = "local_chain_1"
|
25
|
-
}
|
26
1
|
export declare enum TokenType {
|
27
2
|
FUNGIBLE_TOKEN = "FUNGIBLE_TOKEN",
|
28
3
|
NON_FUNGIBLE_TOKEN = "NON_FUNGIBLE_TOKEN",
|
package/dist/esm/enums.js
CHANGED
@@ -1,31 +1,3 @@
|
|
1
|
-
export var Blockchain;
|
2
|
-
(function (Blockchain) {
|
3
|
-
Blockchain["ETHEREUM"] = "ethereum";
|
4
|
-
Blockchain["POLYGON"] = "polygon";
|
5
|
-
Blockchain["BINANCE"] = "binance";
|
6
|
-
Blockchain["ARBITRUM"] = "arbitrum";
|
7
|
-
Blockchain["BASE"] = "base";
|
8
|
-
Blockchain["AVALANCHE"] = "avalanche";
|
9
|
-
Blockchain["ARBITRUM_NOVA"] = "arbitrum_nova";
|
10
|
-
Blockchain["OPTIMISM"] = "optimism";
|
11
|
-
Blockchain["EVMOS"] = "evmos";
|
12
|
-
Blockchain["MOONBEAM"] = "moonbeam";
|
13
|
-
Blockchain["SOLANA"] = "solana";
|
14
|
-
// testnets
|
15
|
-
Blockchain["ETHEREUM_SEPOLIA"] = "ethereum_sepolia";
|
16
|
-
Blockchain["ETHEREUM_HOLESKY"] = "ethereum_holesky";
|
17
|
-
Blockchain["BASE_SEPOLIA"] = "base_sepolia";
|
18
|
-
Blockchain["ARBITRUM_SEPOLIA"] = "arbitrum_sepolia";
|
19
|
-
Blockchain["OPTIMISM_SEPOLIA"] = "optimism_sepolia";
|
20
|
-
Blockchain["POLYGON_AMOY"] = "polygon_amoy";
|
21
|
-
Blockchain["BINANCE_TESTNET"] = "binance_testnet";
|
22
|
-
Blockchain["OPBNB_TESTNET"] = "opbnb_testnet";
|
23
|
-
Blockchain["MOONBEAM_ALPHA"] = "moonbeam_alpha";
|
24
|
-
// local testing
|
25
|
-
Blockchain["HARDHAT"] = "hardhat";
|
26
|
-
Blockchain["LOCAL_CHAIN_0"] = "local_chain_0";
|
27
|
-
Blockchain["LOCAL_CHAIN_1"] = "local_chain_1";
|
28
|
-
})(Blockchain || (Blockchain = {}));
|
29
1
|
export var TokenType;
|
30
2
|
(function (TokenType) {
|
31
3
|
TokenType["FUNGIBLE_TOKEN"] = "FUNGIBLE_TOKEN";
|
package/dist/esm/types.d.ts
CHANGED
@@ -4,7 +4,7 @@ import { CurrencyAmount } from "./entities/financial/currency_amount.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 { State } from "./entities/state.js";
|
7
|
-
import { ActivityStatus, BlockchainEnvironment, Category, CreateOperationsStatus, OperationDataFormat, OperationStatusType, OperationType, TimeIntervalUnits, TokenAllowlistType } from "./enums.js";
|
7
|
+
import { ActivityStatus, BlockchainEnvironment, Category, CreateOperationsStatus, OperationDataFormat, OperationStatusType, OperationType, TimeIntervalUnits, TokenAllowlistType, VMType } from "./enums.js";
|
8
8
|
export type AccountCluster = {
|
9
9
|
accountClusterId: string;
|
10
10
|
accounts: Account[];
|
@@ -164,6 +164,10 @@ export type GasSponsorshipData = {
|
|
164
164
|
export type ChainConfigs = {
|
165
165
|
environment: BlockchainEnvironment;
|
166
166
|
chainId: bigint;
|
167
|
+
vmType: VMType;
|
168
|
+
logoUrl: string;
|
169
|
+
name: string;
|
170
|
+
genesisBlockHash?: string;
|
167
171
|
};
|
168
172
|
export type VirtualNodeRpcUrlForSupportedChain = {
|
169
173
|
chainId: string;
|
@@ -1,10 +1,8 @@
|
|
1
|
-
import {
|
2
|
-
export declare const
|
1
|
+
import { VMType } from "../enums.js";
|
2
|
+
export declare const initializeBlockchainInformation: (orbyUrl: string) => Promise<void>;
|
3
3
|
export declare const getChainIdFromOrbyChainId: (value: string) => bigint | undefined;
|
4
4
|
export declare const getVirtualEnvironment: (id: bigint) => Promise<VMType>;
|
5
|
-
export declare const getOrbyChainId: (chainId: bigint) => Promise<string>;
|
6
5
|
export declare const hasError: (data: any) => {
|
7
6
|
code: number;
|
8
7
|
message: string;
|
9
8
|
};
|
10
|
-
export declare const getBlockchainFromName: (chainName: string) => Blockchain;
|
package/dist/esm/utils/utils.js
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
import {
|
2
|
-
import { BLOCKCHAIN_ID, BLOCKCHAIN_ID_TO_BLOCKCHAIN, CHAIN_CONFIGS, ORBY_URL, } from "../constants.js";
|
1
|
+
import { CHAIN_CONFIGS } from "../constants.js";
|
3
2
|
import { validateAndLowerCase } from "./validateAndParseAddress.js";
|
4
|
-
export const
|
5
|
-
const response = await fetch(
|
3
|
+
export const initializeBlockchainInformation = async (orbyUrl) => {
|
4
|
+
const response = await fetch(orbyUrl, {
|
6
5
|
method: "POST",
|
7
6
|
headers: {
|
8
7
|
"Content-Type": "application/json",
|
@@ -21,13 +20,10 @@ export const initializeBlockchainInfo = async () => {
|
|
21
20
|
}
|
22
21
|
result.edges?.map((blockchainInfo) => {
|
23
22
|
const chainId = getChainIdFromOrbyChainId(blockchainInfo.chainId);
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
CHAIN_CONFIGS[blockchainName] = {
|
29
|
-
environment: blockchainInfo.environment,
|
30
|
-
chainId: chainId
|
23
|
+
if (chainId && blockchainInfo?.name) {
|
24
|
+
CHAIN_CONFIGS[Number(chainId)] = {
|
25
|
+
...blockchainInfo,
|
26
|
+
chainId: chainId,
|
31
27
|
};
|
32
28
|
}
|
33
29
|
});
|
@@ -49,42 +45,10 @@ export const getChainIdFromOrbyChainId = (value) => {
|
|
49
45
|
? BigInt(potentialId)
|
50
46
|
: undefined;
|
51
47
|
}
|
52
|
-
else {
|
53
|
-
const blockchain = getBlockchainFromName(formattedValue);
|
54
|
-
const potentialId = blockchain
|
55
|
-
? BLOCKCHAIN_ID[blockchain]
|
56
|
-
: undefined;
|
57
|
-
chainId = potentialId ? BigInt(potentialId) : undefined;
|
58
|
-
}
|
59
48
|
return chainId;
|
60
49
|
};
|
61
50
|
export const getVirtualEnvironment = async (id) => {
|
62
|
-
|
63
|
-
await initializeBlockchainInfo();
|
64
|
-
}
|
65
|
-
const blockchain = id ? BLOCKCHAIN_ID_TO_BLOCKCHAIN[Number(id)] : undefined;
|
66
|
-
switch (blockchain) {
|
67
|
-
case undefined:
|
68
|
-
return undefined;
|
69
|
-
case Blockchain.SOLANA:
|
70
|
-
return VMType.SVM;
|
71
|
-
default:
|
72
|
-
return VMType.EVM;
|
73
|
-
}
|
74
|
-
};
|
75
|
-
export const getOrbyChainId = async (chainId) => {
|
76
|
-
if (!chainId) {
|
77
|
-
return undefined;
|
78
|
-
}
|
79
|
-
const environment = await getVirtualEnvironment(chainId);
|
80
|
-
switch (environment) {
|
81
|
-
case VMType.SVM:
|
82
|
-
return `SVM-${chainId.toString()}`;
|
83
|
-
case VMType.EVM:
|
84
|
-
return `EIP155-${chainId.toString()}`;
|
85
|
-
default:
|
86
|
-
return undefined;
|
87
|
-
}
|
51
|
+
return CHAIN_CONFIGS[Number(id)]?.vmType;
|
88
52
|
};
|
89
53
|
export const hasError = (data) => {
|
90
54
|
if (data?.code && data?.message) {
|
@@ -92,33 +56,3 @@ export const hasError = (data) => {
|
|
92
56
|
}
|
93
57
|
return undefined;
|
94
58
|
};
|
95
|
-
export const getBlockchainFromName = (chainName) => {
|
96
|
-
const formattedChainName = validateAndLowerCase(chainName)?.replace("-", "_");
|
97
|
-
switch (formattedChainName) {
|
98
|
-
case "bnbt": {
|
99
|
-
return Blockchain.BINANCE_TESTNET;
|
100
|
-
}
|
101
|
-
case "matic_amoy": {
|
102
|
-
return Blockchain.POLYGON_AMOY;
|
103
|
-
}
|
104
|
-
case "matic": {
|
105
|
-
return Blockchain.POLYGON;
|
106
|
-
}
|
107
|
-
case "mainnet": {
|
108
|
-
return Blockchain.ETHEREUM;
|
109
|
-
}
|
110
|
-
case "holesky": {
|
111
|
-
return Blockchain.ETHEREUM_HOLESKY;
|
112
|
-
}
|
113
|
-
case "sepolia": {
|
114
|
-
return Blockchain.ETHEREUM_SEPOLIA;
|
115
|
-
}
|
116
|
-
case "unknown": {
|
117
|
-
return undefined;
|
118
|
-
}
|
119
|
-
default: {
|
120
|
-
//statements;
|
121
|
-
return formattedChainName;
|
122
|
-
}
|
123
|
-
}
|
124
|
-
};
|