@orb-labs/orby-core 0.0.21 → 0.0.22

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.
@@ -67,13 +67,14 @@ export class AccountClusterActions extends LibraryRequest {
67
67
  return success;
68
68
  }
69
69
  async setCustomChainEndpointsForAccountCluster(accountClusterId, chainEndpoints) {
70
- const formattedEndpoints = chainEndpoints.map((endpoint) => {
70
+ const promises = chainEndpoints.map(async (endpoint) => {
71
71
  return {
72
- chainId: getOrbyChainId(endpoint.chainId),
72
+ chainId: await getOrbyChainId(endpoint.chainId),
73
73
  customRpcUrls: endpoint.customRpcUrls,
74
74
  customIndexerUrls: endpoint.customIndexerUrls,
75
75
  };
76
76
  });
77
+ const formattedEndpoints = await Promise.all(promises);
77
78
  const { success, message, code } = await this.sendRequest("orby_setCustomChainEndpointsForAccountCluster", [
78
79
  {
79
80
  accountClusterId,
@@ -87,7 +88,8 @@ export class AccountClusterActions extends LibraryRequest {
87
88
  return success;
88
89
  }
89
90
  async removeCustomChainEndpointsForAccountCluster(accountClusterId, chainIds) {
90
- const formattedChainIds = chainIds.map((chainId) => getOrbyChainId(chainId));
91
+ const promises = chainIds.map(async (chainId) => await getOrbyChainId(chainId));
92
+ const formattedChainIds = Promise.all(promises);
91
93
  const { success, message, code } = await this.sendRequest("orby_removeCustomChainEndpointsForAccountCluster", [
92
94
  {
93
95
  accountClusterId,
@@ -120,10 +122,11 @@ export class AccountClusterActions extends LibraryRequest {
120
122
  });
121
123
  }
122
124
  async isChainSupportedOnAccountCluster(accountClusterId, chainId) {
125
+ const orbyChainId = await getOrbyChainId(chainId);
123
126
  const { supportStatus, message, code } = await this.sendRequest("orby_isChainSupportedOnAccountCluster", [
124
127
  {
125
128
  accountClusterId,
126
- chainId: getOrbyChainId(chainId),
129
+ chainId: orbyChainId,
127
130
  },
128
131
  ]);
129
132
  if (code && message) {
@@ -133,10 +136,11 @@ export class AccountClusterActions extends LibraryRequest {
133
136
  return supportStatus;
134
137
  }
135
138
  async getNodeRpcUrl(accountClusterId, chainId) {
139
+ const orbyChainId = await getOrbyChainId(chainId);
136
140
  const { nodeRpcUrl, code, message } = await this.sendRequest("orby_getNodeRpcUrl", [
137
141
  {
138
142
  accountClusterId,
139
- chainId: getOrbyChainId(chainId),
143
+ chainId: orbyChainId,
140
144
  },
141
145
  ]);
142
146
  if (code && message) {
@@ -146,10 +150,11 @@ export class AccountClusterActions extends LibraryRequest {
146
150
  return nodeRpcUrl;
147
151
  }
148
152
  async getVirtualNodeRpcUrl(accountClusterId, chainId, entrypointAccountAddress) {
153
+ const orbyChainId = await getOrbyChainId(chainId);
149
154
  const { virtualNodeRpcUrl, message, code } = await this.sendRequest("orby_getVirtualNodeRpcUrl", [
150
155
  {
151
156
  accountClusterId,
152
- chainId: getOrbyChainId(chainId),
157
+ chainId: orbyChainId,
153
158
  entrypointAccountAddress,
154
159
  },
155
160
  ]);
@@ -190,12 +195,13 @@ export class AccountClusterActions extends LibraryRequest {
190
195
  return extractStandardizedBalances(fungibleTokenBalances);
191
196
  }
192
197
  async getFungibleTokenBalances(accountClusterId, offset, limit, chainId, tokensToOmit) {
198
+ const orbyChainId = await getOrbyChainId(chainId);
193
199
  const { fungibleTokenBalances, code, message } = await this.sendRequest("orby_getFungibleTokenBalances", [
194
200
  {
195
201
  accountClusterId,
196
202
  offset,
197
203
  limit,
198
- chainId: chainId ? getOrbyChainId(chainId) : undefined,
204
+ chainId: orbyChainId,
199
205
  tokensToOmit,
200
206
  },
201
207
  ]);
@@ -6,7 +6,8 @@ export class BlockchainActions extends LibraryRequest {
6
6
  super(library, client, provider);
7
7
  }
8
8
  async getBlockchainInformation(chainId) {
9
- const { blockchain, code, message } = await this.sendRequest("orby_getBlockchainInformation", [{ chainId: getOrbyChainId(chainId) }]);
9
+ const orbyChainId = await getOrbyChainId(chainId);
10
+ const { blockchain, code, message } = await this.sendRequest("orby_getBlockchainInformation", [{ chainId: orbyChainId }]);
10
11
  if (code && message) {
11
12
  console.error("[getBlockchainInformation]", code, message);
12
13
  return undefined;
@@ -6,13 +6,14 @@ export class InstanceActions extends LibraryRequest {
6
6
  super(library, client, provider);
7
7
  }
8
8
  async setCustomChainEndpointsForInstance(chainEndpoints) {
9
- const formattedEndpoints = chainEndpoints.map((endpoint) => {
9
+ const promises = chainEndpoints.map(async (endpoint) => {
10
10
  return {
11
- chainId: getOrbyChainId(endpoint.chainId),
11
+ chainId: await getOrbyChainId(endpoint.chainId),
12
12
  customRpcUrls: endpoint.customRpcUrls,
13
13
  customIndexerUrls: endpoint.customIndexerUrls,
14
14
  };
15
15
  });
16
+ const formattedEndpoints = await Promise.all(promises);
16
17
  const { success, code, message } = await this.sendRequest("orby_setCustomChainEndpointsForInstance", [{ chainEndpoints: formattedEndpoints }]);
17
18
  if (code && message) {
18
19
  console.error("[setCustomChainEndpointsForInstance]", code, message);
@@ -21,7 +22,8 @@ export class InstanceActions extends LibraryRequest {
21
22
  return success;
22
23
  }
23
24
  async removeCustomChainEndpointForInstance(chainIds) {
24
- const formattedChainIds = chainIds.map((chainId) => getOrbyChainId(chainId));
25
+ const promises = chainIds.map(async (chainId) => await getOrbyChainId(chainId));
26
+ const formattedChainIds = await Promise.all(promises);
25
27
  const { success, code, message } = await this.sendRequest("orby_removeCustomChainEndpointForInstance", [{ chainIds: formattedChainIds }]);
26
28
  if (code && message) {
27
29
  console.error("[removeCustomChainEndpointForInstance]", code, message);
@@ -16,10 +16,10 @@ export class OperationActions extends LibraryRequest {
16
16
  const formattedGasToken = gasToken
17
17
  ? {
18
18
  ...gasToken,
19
- tokenSources: gasToken.tokenSources?.map(({ chainId, address }) => ({
20
- chainId: getOrbyChainId(chainId),
19
+ tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
20
+ chainId: await getOrbyChainId(chainId),
21
21
  address,
22
- })),
22
+ })) ?? []),
23
23
  }
24
24
  : undefined;
25
25
  const operationSet = await this.sendRequest("orby_getOperationsToExecuteTransaction", [
@@ -37,13 +37,13 @@ export class OperationActions extends LibraryRequest {
37
37
  const formattedGasToken = gasToken
38
38
  ? {
39
39
  ...gasToken,
40
- tokenSources: gasToken.tokenSources?.map(({ chainId, address }) => ({
41
- chainId: getOrbyChainId(chainId),
40
+ tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
41
+ chainId: await getOrbyChainId(chainId),
42
42
  address,
43
- })),
43
+ })) ?? []),
44
44
  }
45
45
  : undefined;
46
- const operationSet = await this.sendRequest("orby_getOperationsForSignTransactionOrSignTypedData", [
46
+ const operationSet = await this.sendRequest("orby_getOperationsToSignTypedData", [
47
47
  {
48
48
  accountClusterId,
49
49
  data,
@@ -56,10 +56,10 @@ export class OperationActions extends LibraryRequest {
56
56
  const formattedGasToken = gasToken
57
57
  ? {
58
58
  ...gasToken,
59
- tokenSources: gasToken.tokenSources?.map(({ chainId, address }) => ({
60
- chainId: getOrbyChainId(chainId),
59
+ tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
60
+ chainId: await getOrbyChainId(chainId),
61
61
  address,
62
- })),
62
+ })) ?? []),
63
63
  }
64
64
  : undefined;
65
65
  const operationSet = await this.sendRequest("orby_getOperationsToSignTransactionOrSignTypedData", [
@@ -152,14 +152,14 @@ export class OperationActions extends LibraryRequest {
152
152
  const formattedGasToken = gasToken
153
153
  ? {
154
154
  ...gasToken,
155
- tokenSources: gasToken.tokenSources?.map(({ chainId, address }) => ({
156
- chainId: getOrbyChainId(chainId),
155
+ tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
156
+ chainId: await getOrbyChainId(chainId),
157
157
  address,
158
- })),
158
+ })) ?? []),
159
159
  }
160
160
  : undefined;
161
161
  const formattedRecepient = {
162
- chainId: getOrbyChainId(recipient.chainId),
162
+ chainId: await getOrbyChainId(recipient.chainId),
163
163
  recipientAddress: recipient.recipientAddress,
164
164
  };
165
165
  const operationSet = await this.sendRequest("orby_getOperationsToTransferToken", [
@@ -177,18 +177,18 @@ export class OperationActions extends LibraryRequest {
177
177
  const formattedInput = input
178
178
  ? {
179
179
  ...input,
180
- tokenSources: input?.tokenSources.map(({ chainId, address }) => ({
181
- chainId: getOrbyChainId(chainId),
180
+ tokenSources: await Promise.all(input.tokenSources?.map(async ({ chainId, address }) => ({
181
+ chainId: await getOrbyChainId(chainId),
182
182
  address,
183
- })),
183
+ })) ?? []),
184
184
  }
185
185
  : undefined;
186
186
  const formattedOutput = output
187
187
  ? {
188
188
  ...output,
189
- tokenDestination: output?.tokenDestination
189
+ tokenDestination: output.tokenDestination
190
190
  ? {
191
- chainId: getOrbyChainId(output.tokenDestination.chainId),
191
+ chainId: await getOrbyChainId(output.tokenDestination.chainId),
192
192
  address: output.tokenDestination.address,
193
193
  }
194
194
  : undefined,
@@ -197,10 +197,10 @@ export class OperationActions extends LibraryRequest {
197
197
  const formattedGasToken = gasToken
198
198
  ? {
199
199
  ...gasToken,
200
- tokenSources: gasToken.tokenSources?.map(({ chainId, address }) => ({
201
- chainId: getOrbyChainId(chainId),
200
+ tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
201
+ chainId: await getOrbyChainId(chainId),
202
202
  address,
203
- })),
203
+ })) ?? []),
204
204
  }
205
205
  : undefined;
206
206
  const operationSet = await this.sendRequest("orby_getOperationsToSwap", [
@@ -218,18 +218,18 @@ export class OperationActions extends LibraryRequest {
218
218
  const formattedInput = input
219
219
  ? {
220
220
  ...input,
221
- tokenSources: input?.tokenSources.map(({ chainId, address }) => ({
222
- chainId: getOrbyChainId(chainId),
221
+ tokenSources: await Promise.all(input.tokenSources?.map(async ({ chainId, address }) => ({
222
+ chainId: await getOrbyChainId(chainId),
223
223
  address,
224
- })),
224
+ })) ?? []),
225
225
  }
226
226
  : undefined;
227
227
  const formattedOutput = output
228
228
  ? {
229
229
  ...output,
230
- tokenDestination: output?.tokenDestination
230
+ tokenDestination: output.tokenDestination
231
231
  ? {
232
- chainId: getOrbyChainId(output.tokenDestination.chainId),
232
+ chainId: await getOrbyChainId(output.tokenDestination.chainId),
233
233
  address: output.tokenDestination.address,
234
234
  }
235
235
  : undefined,
@@ -246,23 +246,23 @@ export class OperationActions extends LibraryRequest {
246
246
  return extractOperationSet(operationSet);
247
247
  }
248
248
  async getOperationsToBridge(accountClusterId, standardizedTokenId, amount, tokenSources, tokenDestination, gasToken) {
249
- const formattedTokenSources = tokenSources.map(({ chainId, address }) => ({
250
- chainId: getOrbyChainId(chainId),
249
+ const formattedTokenSources = await Promise.all(tokenSources.map(async ({ chainId, address }) => ({
250
+ chainId: await getOrbyChainId(chainId),
251
251
  address,
252
- }));
252
+ })));
253
253
  const formattedDestination = tokenDestination
254
254
  ? {
255
- chainId: getOrbyChainId(tokenDestination.chainId),
255
+ chainId: await getOrbyChainId(tokenDestination.chainId),
256
256
  address: tokenDestination.address,
257
257
  }
258
258
  : undefined;
259
259
  const formattedGasToken = gasToken
260
260
  ? {
261
261
  ...gasToken,
262
- tokenSources: gasToken.tokenSources?.map(({ chainId, address }) => ({
263
- chainId: getOrbyChainId(chainId),
262
+ tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
263
+ chainId: await getOrbyChainId(chainId),
264
264
  address,
265
- })),
265
+ })) ?? []),
266
266
  }
267
267
  : undefined;
268
268
  const operationSet = await this.sendRequest("orby_getOperationsToBridge", [
@@ -391,7 +391,7 @@ export class OperationActions extends LibraryRequest {
391
391
  signature: signature,
392
392
  data: operation.data,
393
393
  from: operation.from,
394
- chainId: getOrbyChainId(operation.chainId),
394
+ chainId: await getOrbyChainId(operation.chainId),
395
395
  });
396
396
  }
397
397
  // batch sign all the smart contract transactions
@@ -421,7 +421,7 @@ export class OperationActions extends LibraryRequest {
421
421
  signature: userOperation.signature,
422
422
  data: JSON.stringify(userOperation),
423
423
  from: transactions[0].from,
424
- chainId: getOrbyChainId(transactions[0].chainId),
424
+ chainId: await getOrbyChainId(transactions[0].chainId),
425
425
  });
426
426
  }
427
427
  const { operationSetId, operationResponses } = await this.sendSignedOperations(accountCluster.accountClusterId, signedOperations);
@@ -6,9 +6,10 @@ export class TokenActions extends LibraryRequest {
6
6
  super(library, client, provider);
7
7
  }
8
8
  async getStandardizedTokenIds(tokens) {
9
- const formattedTokensInfo = tokens.map(({ tokenAddress, chainId }) => {
10
- return { chainId: getOrbyChainId(chainId), tokenAddress };
9
+ const promises = tokens.map(async ({ tokenAddress, chainId }) => {
10
+ return { chainId: await getOrbyChainId(chainId), tokenAddress };
11
11
  });
12
+ const formattedTokensInfo = await Promise.all(promises);
12
13
  const { standardizedTokenIds, message, code } = await this.sendRequest("orby_getStandardizedTokenIds", [
13
14
  {
14
15
  tokens: formattedTokensInfo,
@@ -21,9 +22,10 @@ export class TokenActions extends LibraryRequest {
21
22
  return standardizedTokenIds;
22
23
  }
23
24
  async getStandardizedTokens(tokens) {
24
- const formattedTokensInfo = tokens.map(({ tokenAddress, chainId }) => {
25
- return { chainId: getOrbyChainId(chainId), tokenAddress };
25
+ const promises = tokens.map(async ({ tokenAddress, chainId }) => {
26
+ return { chainId: await getOrbyChainId(chainId), tokenAddress };
26
27
  });
28
+ const formattedTokensInfo = await Promise.all(promises);
27
29
  const { standardizedTokens, message, code } = await this.sendRequest("orby_getStandardizedTokens", [
28
30
  {
29
31
  tokens: formattedTokensInfo,
@@ -2,13 +2,8 @@ import { Blockchain } from "./enums.js";
2
2
  import { Currency } from "./entities/financial/currency.js";
3
3
  import { ChainConfigs } from "./types.js";
4
4
  export declare const Big: any;
5
- export declare const BLOCKCHAIN_ID: {
6
- [s: string]: number;
7
- };
8
- export declare const CHAIN_CONFIGS: {
9
- [s: string]: ChainConfigs;
10
- };
11
- export declare const BLOCKCHAIN_ID_TO_BLOCKCHAIN: {
12
- [s: number]: Blockchain;
13
- };
5
+ export declare const ORBY_URL = "https://api-rpc-dev.orblabs.xyz/f1c1d996-8df4-4d23-b926-ca702173021d/mainnet";
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>;
14
9
  export declare const FIAT_CURRENCY: Currency;
@@ -1,139 +1,10 @@
1
1
  import toFormat from "toformat";
2
2
  import _Big from "big.js";
3
- import { Blockchain, BlockchainEnvironment } from "./enums.js";
4
3
  import { Currency } from "./entities/financial/currency.js";
5
4
  export const Big = toFormat(_Big);
6
- export const BLOCKCHAIN_ID = {
7
- [Blockchain.ETHEREUM]: 1,
8
- [Blockchain.POLYGON]: 137,
9
- [Blockchain.BINANCE]: 56,
10
- [Blockchain.ARBITRUM]: 42161,
11
- [Blockchain.ARBITRUM_NOVA]: 42170,
12
- [Blockchain.OPTIMISM]: 10,
13
- [Blockchain.EVMOS]: 9001,
14
- [Blockchain.MOONBEAM]: 1284,
15
- [Blockchain.BASE]: 8453,
16
- [Blockchain.AVALANCHE]: 43114,
17
- [Blockchain.SOLANA]: 101,
18
- // testnets
19
- [Blockchain.ETHEREUM_SEPOLIA]: 11155111,
20
- [Blockchain.ETHEREUM_HOLESKY]: 17000,
21
- [Blockchain.ARBITRUM_SEPOLIA]: 421614,
22
- [Blockchain.OPTIMISM_SEPOLIA]: 11155420,
23
- [Blockchain.POLYGON_AMOY]: 80002,
24
- [Blockchain.BINANCE_TESTNET]: 97,
25
- [Blockchain.OPBNB_TESTNET]: 5611,
26
- [Blockchain.MOONBEAM_ALPHA]: 1287,
27
- [Blockchain.BASE_SEPOLIA]: 84532,
28
- // local testing
29
- [Blockchain.HARDHAT]: 31337,
30
- [Blockchain.LOCAL_CHAIN_0]: 1_000_000_000_001,
31
- [Blockchain.LOCAL_CHAIN_1]: 1_000_000_000_002,
32
- };
33
- export const CHAIN_CONFIGS = {
34
- [Blockchain.ETHEREUM]: {
35
- environment: BlockchainEnvironment.MAINNET,
36
- chainId: BigInt(1),
37
- },
38
- [Blockchain.POLYGON]: {
39
- environment: BlockchainEnvironment.MAINNET,
40
- chainId: BigInt(137),
41
- },
42
- [Blockchain.BINANCE]: {
43
- environment: BlockchainEnvironment.MAINNET,
44
- chainId: BigInt(56),
45
- },
46
- [Blockchain.ARBITRUM]: {
47
- environment: BlockchainEnvironment.MAINNET,
48
- chainId: BigInt(42161),
49
- },
50
- [Blockchain.ARBITRUM_NOVA]: {
51
- environment: BlockchainEnvironment.MAINNET,
52
- chainId: BigInt(42170),
53
- },
54
- [Blockchain.OPTIMISM]: {
55
- environment: BlockchainEnvironment.MAINNET,
56
- chainId: BigInt(10),
57
- },
58
- [Blockchain.EVMOS]: {
59
- environment: BlockchainEnvironment.MAINNET,
60
- chainId: BigInt(9001),
61
- },
62
- [Blockchain.MOONBEAM]: {
63
- environment: BlockchainEnvironment.MAINNET,
64
- chainId: BigInt(1284),
65
- },
66
- [Blockchain.BASE]: {
67
- environment: BlockchainEnvironment.MAINNET,
68
- chainId: BigInt(8453),
69
- },
70
- [Blockchain.AVALANCHE]: {
71
- environment: BlockchainEnvironment.MAINNET,
72
- chainId: BigInt(43114),
73
- },
74
- [Blockchain.SOLANA]: {
75
- environment: BlockchainEnvironment.MAINNET,
76
- chainId: BigInt(101),
77
- },
78
- // testnets
79
- [Blockchain.ETHEREUM_SEPOLIA]: {
80
- environment: BlockchainEnvironment.TESTNET,
81
- chainId: BigInt(11155111),
82
- },
83
- [Blockchain.ETHEREUM_HOLESKY]: {
84
- environment: BlockchainEnvironment.TESTNET,
85
- chainId: BigInt(17000),
86
- },
87
- [Blockchain.ARBITRUM_SEPOLIA]: {
88
- environment: BlockchainEnvironment.TESTNET,
89
- chainId: BigInt(421614),
90
- },
91
- [Blockchain.BASE_SEPOLIA]: {
92
- environment: BlockchainEnvironment.TESTNET,
93
- chainId: BigInt(84532),
94
- },
95
- [Blockchain.OPTIMISM_SEPOLIA]: {
96
- environment: BlockchainEnvironment.TESTNET,
97
- chainId: BigInt(11155420),
98
- },
99
- [Blockchain.BINANCE_TESTNET]: {
100
- environment: BlockchainEnvironment.TESTNET,
101
- chainId: BigInt(97),
102
- },
103
- [Blockchain.OPBNB_TESTNET]: {
104
- environment: BlockchainEnvironment.TESTNET,
105
- chainId: BigInt(5611),
106
- },
107
- [Blockchain.MOONBEAM_ALPHA]: {
108
- environment: BlockchainEnvironment.TESTNET,
109
- chainId: BigInt(1287),
110
- },
111
- [Blockchain.POLYGON_AMOY]: {
112
- environment: BlockchainEnvironment.TESTNET,
113
- chainId: BigInt(80002),
114
- },
115
- };
116
- export const BLOCKCHAIN_ID_TO_BLOCKCHAIN = {
117
- [1]: Blockchain.ETHEREUM,
118
- [137]: Blockchain.POLYGON,
119
- [56]: Blockchain.BINANCE,
120
- [42161]: Blockchain.ARBITRUM,
121
- [42170]: Blockchain.ARBITRUM_NOVA,
122
- [10]: Blockchain.OPTIMISM,
123
- [9001]: Blockchain.EVMOS,
124
- [1284]: Blockchain.MOONBEAM,
125
- [8453]: Blockchain.BASE,
126
- [43114]: Blockchain.AVALANCHE,
127
- [101]: Blockchain.SOLANA,
128
- // testnets
129
- [11155111]: Blockchain.ETHEREUM_SEPOLIA,
130
- [84532]: Blockchain.BASE_SEPOLIA,
131
- [17000]: Blockchain.ETHEREUM_HOLESKY,
132
- [421614]: Blockchain.ARBITRUM_SEPOLIA,
133
- [11155420]: Blockchain.OPTIMISM_SEPOLIA,
134
- [80002]: Blockchain.POLYGON_AMOY,
135
- [97]: Blockchain.BINANCE_TESTNET,
136
- [5611]: Blockchain.OPBNB_TESTNET,
137
- [1287]: Blockchain.MOONBEAM_ALPHA,
138
- };
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
+ export const CHAIN_CONFIGS = {};
9
+ export const BLOCKCHAIN_ID_TO_BLOCKCHAIN = {};
139
10
  export const FIAT_CURRENCY = new Currency(6, "USD", "US Dollar", undefined, false, false);
@@ -1,11 +1,10 @@
1
1
  import { Blockchain, VMType } from "../enums.js";
2
+ export declare const initializeBlockchainInfo: () => Promise<void>;
2
3
  export declare const getChainIdFromOrbyChainId: (value: string) => bigint | undefined;
3
- export declare const getVirtualEnvironment: (id: bigint) => VMType;
4
- export declare const getOrbyChainId: (chainId: bigint) => string;
5
- export declare const getBlockchainIdFromBlockchain: (blockchain: Blockchain) => number;
4
+ export declare const getVirtualEnvironment: (id: bigint) => Promise<VMType>;
5
+ export declare const getOrbyChainId: (chainId: bigint) => Promise<string>;
6
6
  export declare const hasError: (data: any) => {
7
7
  code: number;
8
8
  message: string;
9
9
  };
10
10
  export declare const getBlockchainFromName: (chainName: string) => Blockchain;
11
- export declare const isMainnet: (chainId: bigint) => boolean;
@@ -1,6 +1,37 @@
1
- import { Blockchain, BlockchainEnvironment, VMType } from "../enums.js";
2
- import { BLOCKCHAIN_ID, BLOCKCHAIN_ID_TO_BLOCKCHAIN, CHAIN_CONFIGS, } from "../constants.js";
1
+ import { Blockchain, VMType } from "../enums.js";
2
+ import { BLOCKCHAIN_ID, BLOCKCHAIN_ID_TO_BLOCKCHAIN, CHAIN_CONFIGS, ORBY_URL, } from "../constants.js";
3
3
  import { validateAndLowerCase } from "./validateAndParseAddress.js";
4
+ export const initializeBlockchainInfo = async () => {
5
+ const response = await fetch(ORBY_URL, {
6
+ method: "POST",
7
+ headers: {
8
+ "Content-Type": "application/json",
9
+ },
10
+ body: JSON.stringify({
11
+ jsonrpc: "2.0",
12
+ method: "orby_listBlockchainsInformation",
13
+ params: [],
14
+ id: 1,
15
+ }),
16
+ });
17
+ const { result, error } = await response.json();
18
+ if (error?.code && error?.message) {
19
+ console.error("[initializeBlockchainInfo]", error.code, error.message);
20
+ return;
21
+ }
22
+ result.edges?.map((blockchainInfo) => {
23
+ const chainId = getChainIdFromOrbyChainId(blockchainInfo.chainId);
24
+ const blockchainName = blockchainInfo.name;
25
+ if (chainId && blockchainName) {
26
+ BLOCKCHAIN_ID[blockchainName] = Number(chainId);
27
+ BLOCKCHAIN_ID_TO_BLOCKCHAIN[Number(chainId)] = blockchainName;
28
+ CHAIN_CONFIGS[blockchainName] = {
29
+ environment: blockchainInfo.environment,
30
+ chainId: chainId
31
+ };
32
+ }
33
+ });
34
+ };
4
35
  export const getChainIdFromOrbyChainId = (value) => {
5
36
  let chainId = undefined;
6
37
  const formattedValue = validateAndLowerCase(value);
@@ -21,13 +52,16 @@ export const getChainIdFromOrbyChainId = (value) => {
21
52
  else {
22
53
  const blockchain = getBlockchainFromName(formattedValue);
23
54
  const potentialId = blockchain
24
- ? getBlockchainIdFromBlockchain(blockchain)
55
+ ? BLOCKCHAIN_ID[blockchain]
25
56
  : undefined;
26
57
  chainId = potentialId ? BigInt(potentialId) : undefined;
27
58
  }
28
59
  return chainId;
29
60
  };
30
- export const getVirtualEnvironment = (id) => {
61
+ export const getVirtualEnvironment = async (id) => {
62
+ if (Object.keys(BLOCKCHAIN_ID_TO_BLOCKCHAIN).length === 0) {
63
+ await initializeBlockchainInfo();
64
+ }
31
65
  const blockchain = id ? BLOCKCHAIN_ID_TO_BLOCKCHAIN[Number(id)] : undefined;
32
66
  switch (blockchain) {
33
67
  case undefined:
@@ -38,8 +72,12 @@ export const getVirtualEnvironment = (id) => {
38
72
  return VMType.EVM;
39
73
  }
40
74
  };
41
- export const getOrbyChainId = (chainId) => {
42
- switch (getVirtualEnvironment(chainId)) {
75
+ export const getOrbyChainId = async (chainId) => {
76
+ if (!chainId) {
77
+ return undefined;
78
+ }
79
+ const environment = await getVirtualEnvironment(chainId);
80
+ switch (environment) {
43
81
  case VMType.SVM:
44
82
  return `SVM-${chainId.toString()}`;
45
83
  case VMType.EVM:
@@ -48,9 +86,6 @@ export const getOrbyChainId = (chainId) => {
48
86
  return undefined;
49
87
  }
50
88
  };
51
- export const getBlockchainIdFromBlockchain = (blockchain) => {
52
- return BLOCKCHAIN_ID[blockchain];
53
- };
54
89
  export const hasError = (data) => {
55
90
  if (data?.code && data?.message) {
56
91
  return { code: data.code, message: data.message };
@@ -87,7 +122,3 @@ export const getBlockchainFromName = (chainName) => {
87
122
  }
88
123
  }
89
124
  };
90
- export const isMainnet = (chainId) => {
91
- const blockchain = BLOCKCHAIN_ID_TO_BLOCKCHAIN[Number(chainId)];
92
- return CHAIN_CONFIGS[blockchain].environment == BlockchainEnvironment.MAINNET;
93
- };