@orb-labs/orby-core 0.0.22 → 0.0.23

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
@@ -2,7 +2,11 @@
2
2
 
3
3
  ### Unreleased
4
4
 
5
- ### 0.0.21
5
+ ### 0.0.23
6
+
7
+ - refactoring how we get the blockchain list
8
+
9
+ ### 0.0.22
6
10
 
7
11
  - refactor constants to fetch directly from backend
8
12
  - fix request method for getOperationsToSignTypeData
@@ -72,7 +72,7 @@ class AccountClusterActions extends library_request_js_1.LibraryRequest {
72
72
  async setCustomChainEndpointsForAccountCluster(accountClusterId, chainEndpoints) {
73
73
  const promises = chainEndpoints.map(async (endpoint) => {
74
74
  return {
75
- chainId: await (0, utils_js_1.getOrbyChainId)(endpoint.chainId),
75
+ chainId: await this.getOrbyChainId(endpoint.chainId),
76
76
  customRpcUrls: endpoint.customRpcUrls,
77
77
  customIndexerUrls: endpoint.customIndexerUrls,
78
78
  };
@@ -91,7 +91,7 @@ class AccountClusterActions extends library_request_js_1.LibraryRequest {
91
91
  return success;
92
92
  }
93
93
  async removeCustomChainEndpointsForAccountCluster(accountClusterId, chainIds) {
94
- const promises = chainIds.map(async (chainId) => await (0, utils_js_1.getOrbyChainId)(chainId));
94
+ const promises = chainIds.map(async (chainId) => await this.getOrbyChainId(chainId));
95
95
  const formattedChainIds = Promise.all(promises);
96
96
  const { success, message, code } = await this.sendRequest("orby_removeCustomChainEndpointsForAccountCluster", [
97
97
  {
@@ -125,7 +125,7 @@ class AccountClusterActions extends library_request_js_1.LibraryRequest {
125
125
  });
126
126
  }
127
127
  async isChainSupportedOnAccountCluster(accountClusterId, chainId) {
128
- const orbyChainId = await (0, utils_js_1.getOrbyChainId)(chainId);
128
+ const orbyChainId = await this.getOrbyChainId(chainId);
129
129
  const { supportStatus, message, code } = await this.sendRequest("orby_isChainSupportedOnAccountCluster", [
130
130
  {
131
131
  accountClusterId,
@@ -139,7 +139,7 @@ class AccountClusterActions extends library_request_js_1.LibraryRequest {
139
139
  return supportStatus;
140
140
  }
141
141
  async getNodeRpcUrl(accountClusterId, chainId) {
142
- const orbyChainId = await (0, utils_js_1.getOrbyChainId)(chainId);
142
+ const orbyChainId = await this.getOrbyChainId(chainId);
143
143
  const { nodeRpcUrl, code, message } = await this.sendRequest("orby_getNodeRpcUrl", [
144
144
  {
145
145
  accountClusterId,
@@ -153,7 +153,7 @@ class AccountClusterActions extends library_request_js_1.LibraryRequest {
153
153
  return nodeRpcUrl;
154
154
  }
155
155
  async getVirtualNodeRpcUrl(accountClusterId, chainId, entrypointAccountAddress) {
156
- const orbyChainId = await (0, utils_js_1.getOrbyChainId)(chainId);
156
+ const orbyChainId = await this.getOrbyChainId(chainId);
157
157
  const { virtualNodeRpcUrl, message, code } = await this.sendRequest("orby_getVirtualNodeRpcUrl", [
158
158
  {
159
159
  accountClusterId,
@@ -198,7 +198,7 @@ class AccountClusterActions extends library_request_js_1.LibraryRequest {
198
198
  return (0, action_helpers_js_1.extractStandardizedBalances)(fungibleTokenBalances);
199
199
  }
200
200
  async getFungibleTokenBalances(accountClusterId, offset, limit, chainId, tokensToOmit) {
201
- const orbyChainId = await (0, utils_js_1.getOrbyChainId)(chainId);
201
+ const orbyChainId = await this.getOrbyChainId(chainId);
202
202
  const { fungibleTokenBalances, code, message } = await this.sendRequest("orby_getFungibleTokenBalances", [
203
203
  {
204
204
  accountClusterId,
@@ -3,13 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BlockchainActions = void 0;
4
4
  const action_helpers_js_1 = require("../utils/action_helpers.js");
5
5
  const library_request_js_1 = require("../entities/library_request.js");
6
- const utils_js_1 = require("../utils/utils.js");
7
6
  class BlockchainActions extends library_request_js_1.LibraryRequest {
8
7
  constructor(library, client, provider) {
9
8
  super(library, client, provider);
10
9
  }
11
10
  async getBlockchainInformation(chainId) {
12
- const orbyChainId = await (0, utils_js_1.getOrbyChainId)(chainId);
11
+ const orbyChainId = await this.getOrbyChainId(chainId);
13
12
  const { blockchain, code, message } = await this.sendRequest("orby_getBlockchainInformation", [{ chainId: orbyChainId }]);
14
13
  if (code && message) {
15
14
  console.error("[getBlockchainInformation]", code, message);
@@ -11,7 +11,7 @@ class InstanceActions extends library_request_js_1.LibraryRequest {
11
11
  async setCustomChainEndpointsForInstance(chainEndpoints) {
12
12
  const promises = chainEndpoints.map(async (endpoint) => {
13
13
  return {
14
- chainId: await (0, utils_js_1.getOrbyChainId)(endpoint.chainId),
14
+ chainId: await this.getOrbyChainId(endpoint.chainId),
15
15
  customRpcUrls: endpoint.customRpcUrls,
16
16
  customIndexerUrls: endpoint.customIndexerUrls,
17
17
  };
@@ -25,7 +25,7 @@ class InstanceActions extends library_request_js_1.LibraryRequest {
25
25
  return success;
26
26
  }
27
27
  async removeCustomChainEndpointForInstance(chainIds) {
28
- const promises = chainIds.map(async (chainId) => await (0, utils_js_1.getOrbyChainId)(chainId));
28
+ const promises = chainIds.map(async (chainId) => await this.getOrbyChainId(chainId));
29
29
  const formattedChainIds = await Promise.all(promises);
30
30
  const { success, code, message } = await this.sendRequest("orby_removeCustomChainEndpointForInstance", [{ chainIds: formattedChainIds }]);
31
31
  if (code && message) {
@@ -5,7 +5,6 @@ const action_helpers_js_1 = require("../utils/action_helpers.js");
5
5
  const currency_amount_js_1 = require("../entities/financial/currency_amount.js");
6
6
  const enums_js_1 = require("../enums.js");
7
7
  const library_request_js_1 = require("../entities/library_request.js");
8
- const utils_js_1 = require("../utils/utils.js");
9
8
  const account_js_1 = require("../entities/account.js");
10
9
  // from here: https://stackoverflow.com/questions/65152373/typescript-serialize-bigint-in-json
11
10
  BigInt.prototype.toJSON = function () {
@@ -20,7 +19,7 @@ class OperationActions extends library_request_js_1.LibraryRequest {
20
19
  ? {
21
20
  ...gasToken,
22
21
  tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
23
- chainId: await (0, utils_js_1.getOrbyChainId)(chainId),
22
+ chainId: await this.getOrbyChainId(chainId),
24
23
  address,
25
24
  })) ?? []),
26
25
  }
@@ -41,7 +40,7 @@ class OperationActions extends library_request_js_1.LibraryRequest {
41
40
  ? {
42
41
  ...gasToken,
43
42
  tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
44
- chainId: await (0, utils_js_1.getOrbyChainId)(chainId),
43
+ chainId: await this.getOrbyChainId(chainId),
45
44
  address,
46
45
  })) ?? []),
47
46
  }
@@ -60,7 +59,7 @@ class OperationActions extends library_request_js_1.LibraryRequest {
60
59
  ? {
61
60
  ...gasToken,
62
61
  tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
63
- chainId: await (0, utils_js_1.getOrbyChainId)(chainId),
62
+ chainId: await this.getOrbyChainId(chainId),
64
63
  address,
65
64
  })) ?? []),
66
65
  }
@@ -156,13 +155,13 @@ class OperationActions extends library_request_js_1.LibraryRequest {
156
155
  ? {
157
156
  ...gasToken,
158
157
  tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
159
- chainId: await (0, utils_js_1.getOrbyChainId)(chainId),
158
+ chainId: await this.getOrbyChainId(chainId),
160
159
  address,
161
160
  })) ?? []),
162
161
  }
163
162
  : undefined;
164
163
  const formattedRecepient = {
165
- chainId: await (0, utils_js_1.getOrbyChainId)(recipient.chainId),
164
+ chainId: await this.getOrbyChainId(recipient.chainId),
166
165
  recipientAddress: recipient.recipientAddress,
167
166
  };
168
167
  const operationSet = await this.sendRequest("orby_getOperationsToTransferToken", [
@@ -181,7 +180,7 @@ class OperationActions extends library_request_js_1.LibraryRequest {
181
180
  ? {
182
181
  ...input,
183
182
  tokenSources: await Promise.all(input.tokenSources?.map(async ({ chainId, address }) => ({
184
- chainId: await (0, utils_js_1.getOrbyChainId)(chainId),
183
+ chainId: await this.getOrbyChainId(chainId),
185
184
  address,
186
185
  })) ?? []),
187
186
  }
@@ -191,7 +190,7 @@ class OperationActions extends library_request_js_1.LibraryRequest {
191
190
  ...output,
192
191
  tokenDestination: output.tokenDestination
193
192
  ? {
194
- chainId: await (0, utils_js_1.getOrbyChainId)(output.tokenDestination.chainId),
193
+ chainId: await this.getOrbyChainId(output.tokenDestination.chainId),
195
194
  address: output.tokenDestination.address,
196
195
  }
197
196
  : undefined,
@@ -201,7 +200,7 @@ class OperationActions extends library_request_js_1.LibraryRequest {
201
200
  ? {
202
201
  ...gasToken,
203
202
  tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
204
- chainId: await (0, utils_js_1.getOrbyChainId)(chainId),
203
+ chainId: await this.getOrbyChainId(chainId),
205
204
  address,
206
205
  })) ?? []),
207
206
  }
@@ -222,7 +221,7 @@ class OperationActions extends library_request_js_1.LibraryRequest {
222
221
  ? {
223
222
  ...input,
224
223
  tokenSources: await Promise.all(input.tokenSources?.map(async ({ chainId, address }) => ({
225
- chainId: await (0, utils_js_1.getOrbyChainId)(chainId),
224
+ chainId: await this.getOrbyChainId(chainId),
226
225
  address,
227
226
  })) ?? []),
228
227
  }
@@ -232,7 +231,7 @@ class OperationActions extends library_request_js_1.LibraryRequest {
232
231
  ...output,
233
232
  tokenDestination: output.tokenDestination
234
233
  ? {
235
- chainId: await (0, utils_js_1.getOrbyChainId)(output.tokenDestination.chainId),
234
+ chainId: await this.getOrbyChainId(output.tokenDestination.chainId),
236
235
  address: output.tokenDestination.address,
237
236
  }
238
237
  : undefined,
@@ -250,12 +249,12 @@ class OperationActions extends library_request_js_1.LibraryRequest {
250
249
  }
251
250
  async getOperationsToBridge(accountClusterId, standardizedTokenId, amount, tokenSources, tokenDestination, gasToken) {
252
251
  const formattedTokenSources = await Promise.all(tokenSources.map(async ({ chainId, address }) => ({
253
- chainId: await (0, utils_js_1.getOrbyChainId)(chainId),
252
+ chainId: await this.getOrbyChainId(chainId),
254
253
  address,
255
254
  })));
256
255
  const formattedDestination = tokenDestination
257
256
  ? {
258
- chainId: await (0, utils_js_1.getOrbyChainId)(tokenDestination.chainId),
257
+ chainId: await this.getOrbyChainId(tokenDestination.chainId),
259
258
  address: tokenDestination.address,
260
259
  }
261
260
  : undefined;
@@ -263,7 +262,7 @@ class OperationActions extends library_request_js_1.LibraryRequest {
263
262
  ? {
264
263
  ...gasToken,
265
264
  tokenSources: await Promise.all(gasToken.tokenSources?.map(async ({ chainId, address }) => ({
266
- chainId: await (0, utils_js_1.getOrbyChainId)(chainId),
265
+ chainId: await this.getOrbyChainId(chainId),
267
266
  address,
268
267
  })) ?? []),
269
268
  }
@@ -394,7 +393,7 @@ class OperationActions extends library_request_js_1.LibraryRequest {
394
393
  signature: signature,
395
394
  data: operation.data,
396
395
  from: operation.from,
397
- chainId: await (0, utils_js_1.getOrbyChainId)(operation.chainId),
396
+ chainId: await this.getOrbyChainId(operation.chainId),
398
397
  });
399
398
  }
400
399
  // batch sign all the smart contract transactions
@@ -424,7 +423,7 @@ class OperationActions extends library_request_js_1.LibraryRequest {
424
423
  signature: userOperation.signature,
425
424
  data: JSON.stringify(userOperation),
426
425
  from: transactions[0].from,
427
- chainId: await (0, utils_js_1.getOrbyChainId)(transactions[0].chainId),
426
+ chainId: await this.getOrbyChainId(transactions[0].chainId),
428
427
  });
429
428
  }
430
429
  const { operationSetId, operationResponses } = await this.sendSignedOperations(accountCluster.accountClusterId, signedOperations);
@@ -3,14 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TokenActions = void 0;
4
4
  const action_helpers_js_1 = require("../utils/action_helpers.js");
5
5
  const library_request_js_1 = require("../entities/library_request.js");
6
- const utils_js_1 = require("../utils/utils.js");
7
6
  class TokenActions extends library_request_js_1.LibraryRequest {
8
7
  constructor(library, client, provider) {
9
8
  super(library, client, provider);
10
9
  }
11
10
  async getStandardizedTokenIds(tokens) {
12
11
  const promises = tokens.map(async ({ tokenAddress, chainId }) => {
13
- return { chainId: await (0, utils_js_1.getOrbyChainId)(chainId), tokenAddress };
12
+ return { chainId: await this.getOrbyChainId(chainId), tokenAddress };
14
13
  });
15
14
  const formattedTokensInfo = await Promise.all(promises);
16
15
  const { standardizedTokenIds, message, code } = await this.sendRequest("orby_getStandardizedTokenIds", [
@@ -26,7 +25,7 @@ class TokenActions extends library_request_js_1.LibraryRequest {
26
25
  }
27
26
  async getStandardizedTokens(tokens) {
28
27
  const promises = tokens.map(async ({ tokenAddress, chainId }) => {
29
- return { chainId: await (0, utils_js_1.getOrbyChainId)(chainId), tokenAddress };
28
+ return { chainId: await this.getOrbyChainId(chainId), tokenAddress };
30
29
  });
31
30
  const formattedTokensInfo = await Promise.all(promises);
32
31
  const { standardizedTokens, message, code } = await this.sendRequest("orby_getStandardizedTokens", [
@@ -2,7 +2,6 @@ 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 ORBY_URL = "https://api-rpc-dev.orblabs.xyz/f1c1d996-8df4-4d23-b926-ca702173021d/mainnet";
6
5
  export declare const BLOCKCHAIN_ID: Record<Blockchain, number>;
7
6
  export declare const CHAIN_CONFIGS: Record<Blockchain, ChainConfigs>;
8
7
  export declare const BLOCKCHAIN_ID_TO_BLOCKCHAIN: Record<number, Blockchain>;
@@ -3,13 +3,11 @@ 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.ORBY_URL = exports.Big = void 0;
6
+ exports.FIAT_CURRENCY = exports.BLOCKCHAIN_ID_TO_BLOCKCHAIN = exports.CHAIN_CONFIGS = exports.BLOCKCHAIN_ID = exports.Big = void 0;
7
7
  const toformat_1 = __importDefault(require("toformat"));
8
8
  const big_js_1 = __importDefault(require("big.js"));
9
9
  const currency_js_1 = require("./entities/financial/currency.js");
10
10
  exports.Big = (0, toformat_1.default)(big_js_1.default);
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
11
  exports.BLOCKCHAIN_ID = {};
14
12
  exports.CHAIN_CONFIGS = {};
15
13
  exports.BLOCKCHAIN_ID_TO_BLOCKCHAIN = {};
@@ -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
  }
@@ -6,8 +6,37 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.LibraryRequest = void 0;
7
7
  const enums_js_1 = require("../enums.js");
8
8
  const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
9
+ const constants_js_1 = require("../constants.js");
10
+ const utils_js_1 = require("../utils/utils.js");
9
11
  class LibraryRequest {
10
12
  constructor(library, client, provider) {
13
+ this.getOrbyChainId = async (chainId) => {
14
+ if (!chainId) {
15
+ return undefined;
16
+ }
17
+ const environment = await this.getVirtualEnvironment(chainId);
18
+ console.log("ENVIRONMENT", environment);
19
+ switch (environment) {
20
+ case enums_js_1.VMType.SVM:
21
+ return `SVM-${chainId.toString()}`;
22
+ case enums_js_1.VMType.EVM:
23
+ return `EIP155-${chainId.toString()}`;
24
+ default:
25
+ return undefined;
26
+ }
27
+ };
28
+ this.getVirtualEnvironment = async (id) => {
29
+ if (Object.keys(constants_js_1.BLOCKCHAIN_ID_TO_BLOCKCHAIN).length == 0) {
30
+ await (0, utils_js_1.initializeBlockchainInformation)(this.providerUrl());
31
+ }
32
+ console.log("CHAIN_CONFIGS", constants_js_1.CHAIN_CONFIGS);
33
+ const blockchain = id ? constants_js_1.BLOCKCHAIN_ID_TO_BLOCKCHAIN[Number(id)] : undefined;
34
+ if (!blockchain) {
35
+ console.error("No blockchain found for chainId", id);
36
+ return undefined;
37
+ }
38
+ return constants_js_1.CHAIN_CONFIGS[blockchain]?.vmType;
39
+ };
11
40
  if (library == enums_js_1.LIBRARY_TYPE.VIEM) {
12
41
  (0, tiny_invariant_1.default)(client, "CLIENT");
13
42
  (0, tiny_invariant_1.default)(!provider, "PROVIDER");
@@ -33,5 +62,13 @@ class LibraryRequest {
33
62
  return this.provider.send(method, params);
34
63
  }
35
64
  }
65
+ providerUrl() {
66
+ if (this.library == enums_js_1.LIBRARY_TYPE.VIEM) {
67
+ return this.client?.transport?.url;
68
+ }
69
+ else if (this.library == enums_js_1.LIBRARY_TYPE.ETHERS) {
70
+ return this.provider._getConnection().url;
71
+ }
72
+ }
36
73
  }
37
74
  exports.LibraryRequest = LibraryRequest;
@@ -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,7 @@ export type GasSponsorshipData = {
164
164
  export type ChainConfigs = {
165
165
  environment: BlockchainEnvironment;
166
166
  chainId: bigint;
167
+ vmType: VMType;
167
168
  };
168
169
  export type VirtualNodeRpcUrlForSupportedChain = {
169
170
  chainId: string;
@@ -1,10 +1,8 @@
1
- import { Blockchain, VMType } from "../enums.js";
2
- export declare const initializeBlockchainInfo: () => Promise<void>;
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;
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getBlockchainFromName = exports.hasError = exports.getOrbyChainId = exports.getVirtualEnvironment = exports.getChainIdFromOrbyChainId = exports.initializeBlockchainInfo = void 0;
4
- const enums_js_1 = require("../enums.js");
3
+ exports.hasError = exports.getVirtualEnvironment = exports.getChainIdFromOrbyChainId = exports.initializeBlockchainInformation = void 0;
5
4
  const constants_js_1 = require("../constants.js");
6
5
  const validateAndParseAddress_js_1 = require("./validateAndParseAddress.js");
7
- const initializeBlockchainInfo = async () => {
8
- const response = await fetch(constants_js_1.ORBY_URL, {
6
+ const initializeBlockchainInformation = async (orbyUrl) => {
7
+ const response = await fetch(orbyUrl, {
9
8
  method: "POST",
10
9
  headers: {
11
10
  "Content-Type": "application/json",
@@ -30,12 +29,13 @@ const initializeBlockchainInfo = async () => {
30
29
  constants_js_1.BLOCKCHAIN_ID_TO_BLOCKCHAIN[Number(chainId)] = blockchainName;
31
30
  constants_js_1.CHAIN_CONFIGS[blockchainName] = {
32
31
  environment: blockchainInfo.environment,
33
- chainId: chainId
32
+ chainId: chainId,
33
+ vmType: blockchainInfo.vmType,
34
34
  };
35
35
  }
36
36
  });
37
37
  };
38
- exports.initializeBlockchainInfo = initializeBlockchainInfo;
38
+ exports.initializeBlockchainInformation = initializeBlockchainInformation;
39
39
  const getChainIdFromOrbyChainId = (value) => {
40
40
  let chainId = undefined;
41
41
  const formattedValue = (0, validateAndParseAddress_js_1.validateAndLowerCase)(value);
@@ -53,46 +53,17 @@ const getChainIdFromOrbyChainId = (value) => {
53
53
  ? BigInt(potentialId)
54
54
  : undefined;
55
55
  }
56
- else {
57
- const blockchain = (0, exports.getBlockchainFromName)(formattedValue);
58
- const potentialId = blockchain
59
- ? constants_js_1.BLOCKCHAIN_ID[blockchain]
60
- : undefined;
61
- chainId = potentialId ? BigInt(potentialId) : undefined;
62
- }
63
56
  return chainId;
64
57
  };
65
58
  exports.getChainIdFromOrbyChainId = getChainIdFromOrbyChainId;
66
59
  const getVirtualEnvironment = async (id) => {
67
- if (Object.keys(constants_js_1.BLOCKCHAIN_ID_TO_BLOCKCHAIN).length === 0) {
68
- await (0, exports.initializeBlockchainInfo)();
69
- }
70
60
  const blockchain = id ? constants_js_1.BLOCKCHAIN_ID_TO_BLOCKCHAIN[Number(id)] : undefined;
71
- switch (blockchain) {
72
- case undefined:
73
- return undefined;
74
- case enums_js_1.Blockchain.SOLANA:
75
- return enums_js_1.VMType.SVM;
76
- default:
77
- return enums_js_1.VMType.EVM;
78
- }
79
- };
80
- exports.getVirtualEnvironment = getVirtualEnvironment;
81
- const getOrbyChainId = async (chainId) => {
82
- if (!chainId) {
61
+ if (!blockchain) {
83
62
  return undefined;
84
63
  }
85
- const environment = await (0, exports.getVirtualEnvironment)(chainId);
86
- switch (environment) {
87
- case enums_js_1.VMType.SVM:
88
- return `SVM-${chainId.toString()}`;
89
- case enums_js_1.VMType.EVM:
90
- return `EIP155-${chainId.toString()}`;
91
- default:
92
- return undefined;
93
- }
64
+ return constants_js_1.CHAIN_CONFIGS[blockchain]?.vmType;
94
65
  };
95
- exports.getOrbyChainId = getOrbyChainId;
66
+ exports.getVirtualEnvironment = getVirtualEnvironment;
96
67
  const hasError = (data) => {
97
68
  if (data?.code && data?.message) {
98
69
  return { code: data.code, message: data.message };
@@ -100,34 +71,3 @@ const hasError = (data) => {
100
71
  return undefined;
101
72
  };
102
73
  exports.hasError = hasError;
103
- const getBlockchainFromName = (chainName) => {
104
- const formattedChainName = (0, validateAndParseAddress_js_1.validateAndLowerCase)(chainName)?.replace("-", "_");
105
- switch (formattedChainName) {
106
- case "bnbt": {
107
- return enums_js_1.Blockchain.BINANCE_TESTNET;
108
- }
109
- case "matic_amoy": {
110
- return enums_js_1.Blockchain.POLYGON_AMOY;
111
- }
112
- case "matic": {
113
- return enums_js_1.Blockchain.POLYGON;
114
- }
115
- case "mainnet": {
116
- return enums_js_1.Blockchain.ETHEREUM;
117
- }
118
- case "holesky": {
119
- return enums_js_1.Blockchain.ETHEREUM_HOLESKY;
120
- }
121
- case "sepolia": {
122
- return enums_js_1.Blockchain.ETHEREUM_SEPOLIA;
123
- }
124
- case "unknown": {
125
- return undefined;
126
- }
127
- default: {
128
- //statements;
129
- return formattedChainName;
130
- }
131
- }
132
- };
133
- exports.getBlockchainFromName = getBlockchainFromName;
@@ -1,6 +1,6 @@
1
1
  import { extractAccountCluster, extractActivities, extractFungibleTokenOverview, extractStandardizedBalances, } from "../utils/action_helpers.js";
2
2
  import { LibraryRequest } from "../entities/library_request.js";
3
- import { getChainIdFromOrbyChainId, getOrbyChainId } from "../utils/utils.js";
3
+ import { getChainIdFromOrbyChainId } from "../utils/utils.js";
4
4
  import { validateAndFormatAddress } from "../utils/validateAndParseAddress.js";
5
5
  export class AccountClusterActions extends LibraryRequest {
6
6
  constructor(library, client, provider) {
@@ -69,7 +69,7 @@ export class AccountClusterActions extends LibraryRequest {
69
69
  async setCustomChainEndpointsForAccountCluster(accountClusterId, chainEndpoints) {
70
70
  const promises = chainEndpoints.map(async (endpoint) => {
71
71
  return {
72
- chainId: await getOrbyChainId(endpoint.chainId),
72
+ chainId: await this.getOrbyChainId(endpoint.chainId),
73
73
  customRpcUrls: endpoint.customRpcUrls,
74
74
  customIndexerUrls: endpoint.customIndexerUrls,
75
75
  };
@@ -88,7 +88,7 @@ export class AccountClusterActions extends LibraryRequest {
88
88
  return success;
89
89
  }
90
90
  async removeCustomChainEndpointsForAccountCluster(accountClusterId, chainIds) {
91
- const promises = chainIds.map(async (chainId) => await getOrbyChainId(chainId));
91
+ const promises = chainIds.map(async (chainId) => await this.getOrbyChainId(chainId));
92
92
  const formattedChainIds = Promise.all(promises);
93
93
  const { success, message, code } = await this.sendRequest("orby_removeCustomChainEndpointsForAccountCluster", [
94
94
  {
@@ -122,7 +122,7 @@ export class AccountClusterActions extends LibraryRequest {
122
122
  });
123
123
  }
124
124
  async isChainSupportedOnAccountCluster(accountClusterId, chainId) {
125
- const orbyChainId = await getOrbyChainId(chainId);
125
+ const orbyChainId = await this.getOrbyChainId(chainId);
126
126
  const { supportStatus, message, code } = await this.sendRequest("orby_isChainSupportedOnAccountCluster", [
127
127
  {
128
128
  accountClusterId,
@@ -136,7 +136,7 @@ export class AccountClusterActions extends LibraryRequest {
136
136
  return supportStatus;
137
137
  }
138
138
  async getNodeRpcUrl(accountClusterId, chainId) {
139
- const orbyChainId = await getOrbyChainId(chainId);
139
+ const orbyChainId = await this.getOrbyChainId(chainId);
140
140
  const { nodeRpcUrl, code, message } = await this.sendRequest("orby_getNodeRpcUrl", [
141
141
  {
142
142
  accountClusterId,
@@ -150,7 +150,7 @@ export class AccountClusterActions extends LibraryRequest {
150
150
  return nodeRpcUrl;
151
151
  }
152
152
  async getVirtualNodeRpcUrl(accountClusterId, chainId, entrypointAccountAddress) {
153
- const orbyChainId = await getOrbyChainId(chainId);
153
+ const orbyChainId = await this.getOrbyChainId(chainId);
154
154
  const { virtualNodeRpcUrl, message, code } = await this.sendRequest("orby_getVirtualNodeRpcUrl", [
155
155
  {
156
156
  accountClusterId,
@@ -195,7 +195,7 @@ export class AccountClusterActions extends LibraryRequest {
195
195
  return extractStandardizedBalances(fungibleTokenBalances);
196
196
  }
197
197
  async getFungibleTokenBalances(accountClusterId, offset, limit, chainId, tokensToOmit) {
198
- const orbyChainId = await getOrbyChainId(chainId);
198
+ const orbyChainId = await this.getOrbyChainId(chainId);
199
199
  const { fungibleTokenBalances, code, message } = await this.sendRequest("orby_getFungibleTokenBalances", [
200
200
  {
201
201
  accountClusterId,
@@ -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, getOrbyChainId } from "../utils/utils.js";
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) {