@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.
@@ -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", [
@@ -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>;
@@ -2,8 +2,6 @@ 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
5
  export const BLOCKCHAIN_ID = {};
8
6
  export const CHAIN_CONFIGS = {};
9
7
  export const 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
  }
@@ -1,7 +1,36 @@
1
- import { LIBRARY_TYPE } from "../enums.js";
1
+ import { LIBRARY_TYPE, VMType } from "../enums.js";
2
2
  import invariant from "tiny-invariant";
3
+ import { BLOCKCHAIN_ID_TO_BLOCKCHAIN, 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
+ console.log("ENVIRONMENT", environment);
13
+ switch (environment) {
14
+ case VMType.SVM:
15
+ return `SVM-${chainId.toString()}`;
16
+ case VMType.EVM:
17
+ return `EIP155-${chainId.toString()}`;
18
+ default:
19
+ return undefined;
20
+ }
21
+ };
22
+ this.getVirtualEnvironment = async (id) => {
23
+ if (Object.keys(BLOCKCHAIN_ID_TO_BLOCKCHAIN).length == 0) {
24
+ await initializeBlockchainInformation(this.providerUrl());
25
+ }
26
+ console.log("CHAIN_CONFIGS", CHAIN_CONFIGS);
27
+ const blockchain = id ? BLOCKCHAIN_ID_TO_BLOCKCHAIN[Number(id)] : undefined;
28
+ if (!blockchain) {
29
+ console.error("No blockchain found for chainId", id);
30
+ return undefined;
31
+ }
32
+ return CHAIN_CONFIGS[blockchain]?.vmType;
33
+ };
5
34
  if (library == LIBRARY_TYPE.VIEM) {
6
35
  invariant(client, "CLIENT");
7
36
  invariant(!provider, "PROVIDER");
@@ -27,4 +56,12 @@ export class LibraryRequest {
27
56
  return this.provider.send(method, params);
28
57
  }
29
58
  }
59
+ providerUrl() {
60
+ if (this.library == LIBRARY_TYPE.VIEM) {
61
+ return this.client?.transport?.url;
62
+ }
63
+ else if (this.library == LIBRARY_TYPE.ETHERS) {
64
+ return this.provider._getConnection().url;
65
+ }
66
+ }
30
67
  }
@@ -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,8 +1,7 @@
1
- import { Blockchain, VMType } from "../enums.js";
2
- import { BLOCKCHAIN_ID, BLOCKCHAIN_ID_TO_BLOCKCHAIN, CHAIN_CONFIGS, ORBY_URL, } from "../constants.js";
1
+ import { BLOCKCHAIN_ID, BLOCKCHAIN_ID_TO_BLOCKCHAIN, CHAIN_CONFIGS, } from "../constants.js";
3
2
  import { validateAndLowerCase } from "./validateAndParseAddress.js";
4
- export const initializeBlockchainInfo = async () => {
5
- const response = await fetch(ORBY_URL, {
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",
@@ -27,7 +26,8 @@ export const initializeBlockchainInfo = async () => {
27
26
  BLOCKCHAIN_ID_TO_BLOCKCHAIN[Number(chainId)] = blockchainName;
28
27
  CHAIN_CONFIGS[blockchainName] = {
29
28
  environment: blockchainInfo.environment,
30
- chainId: chainId
29
+ chainId: chainId,
30
+ vmType: blockchainInfo.vmType,
31
31
  };
32
32
  }
33
33
  });
@@ -49,42 +49,14 @@ export const getChainIdFromOrbyChainId = (value) => {
49
49
  ? BigInt(potentialId)
50
50
  : undefined;
51
51
  }
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
52
  return chainId;
60
53
  };
61
54
  export const getVirtualEnvironment = async (id) => {
62
- if (Object.keys(BLOCKCHAIN_ID_TO_BLOCKCHAIN).length === 0) {
63
- await initializeBlockchainInfo();
64
- }
65
55
  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) {
56
+ if (!blockchain) {
77
57
  return undefined;
78
58
  }
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
- }
59
+ return CHAIN_CONFIGS[blockchain]?.vmType;
88
60
  };
89
61
  export const hasError = (data) => {
90
62
  if (data?.code && data?.message) {
@@ -92,33 +64,3 @@ export const hasError = (data) => {
92
64
  }
93
65
  return undefined;
94
66
  };
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
- };