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