@orb-labs/orby-core 0.0.18 → 0.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/dist/cjs/actions/account_cluster.js +2 -1
- package/dist/cjs/actions/operation.d.ts +10 -3
- package/dist/cjs/actions/operation.js +25 -4
- package/dist/cjs/constants.js +6 -0
- package/dist/cjs/entities/account.js +7 -5
- package/dist/cjs/entities/financial/fungible_token.js +5 -4
- package/dist/cjs/entities/financial/non_fungible_token.js +4 -4
- package/dist/cjs/entities/financial/semi_fungible_token.js +4 -4
- package/dist/cjs/enums.d.ts +3 -1
- package/dist/cjs/enums.js +2 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/interfaces/operation.d.ts +10 -3
- package/dist/cjs/utils/utils.d.ts +2 -1
- package/dist/cjs/utils/utils.js +30 -6
- package/dist/cjs/utils/validateAndParseAddress.d.ts +8 -0
- package/dist/cjs/utils/validateAndParseAddress.js +52 -0
- package/dist/esm/actions/account_cluster.js +2 -1
- package/dist/esm/actions/operation.d.ts +10 -3
- package/dist/esm/actions/operation.js +25 -4
- package/dist/esm/constants.js +6 -0
- package/dist/esm/entities/account.js +7 -5
- package/dist/esm/entities/financial/fungible_token.js +6 -5
- package/dist/esm/entities/financial/non_fungible_token.js +5 -5
- package/dist/esm/entities/financial/semi_fungible_token.js +5 -5
- package/dist/esm/enums.d.ts +3 -1
- package/dist/esm/enums.js +2 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/interfaces/operation.d.ts +10 -3
- package/dist/esm/utils/utils.d.ts +2 -1
- package/dist/esm/utils/utils.js +29 -6
- package/dist/esm/utils/validateAndParseAddress.d.ts +8 -0
- package/dist/esm/utils/validateAndParseAddress.js +48 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/esm/constants.js
CHANGED
@@ -14,6 +14,7 @@ export const BLOCKCHAIN_ID = {
|
|
14
14
|
[Blockchain.MOONBEAM]: 1284,
|
15
15
|
[Blockchain.BASE]: 8453,
|
16
16
|
[Blockchain.AVALANCHE]: 43114,
|
17
|
+
[Blockchain.SOLANA]: 101,
|
17
18
|
// testnets
|
18
19
|
[Blockchain.ETHEREUM_SEPOLIA]: 11155111,
|
19
20
|
[Blockchain.ETHEREUM_HOLESKY]: 17000,
|
@@ -70,6 +71,10 @@ export const CHAIN_CONFIGS = {
|
|
70
71
|
environment: BlockchainEnvironment.MAINNET,
|
71
72
|
chainId: BigInt(43114),
|
72
73
|
},
|
74
|
+
[Blockchain.SOLANA]: {
|
75
|
+
environment: BlockchainEnvironment.MAINNET,
|
76
|
+
chainId: BigInt(101),
|
77
|
+
},
|
73
78
|
// testnets
|
74
79
|
[Blockchain.ETHEREUM_SEPOLIA]: {
|
75
80
|
environment: BlockchainEnvironment.TESTNET,
|
@@ -119,6 +124,7 @@ export const BLOCKCHAIN_ID_TO_BLOCKCHAIN = {
|
|
119
124
|
[1284]: Blockchain.MOONBEAM,
|
120
125
|
[8453]: Blockchain.BASE,
|
121
126
|
[43114]: Blockchain.AVALANCHE,
|
127
|
+
[101]: Blockchain.SOLANA,
|
122
128
|
// testnets
|
123
129
|
[11155111]: Blockchain.ETHEREUM_SEPOLIA,
|
124
130
|
[84532]: Blockchain.BASE_SEPOLIA,
|
@@ -1,19 +1,21 @@
|
|
1
1
|
import { AccountType } from "../enums.js";
|
2
2
|
import { getChainIdFromOrbyChainId } from "../utils/utils.js";
|
3
|
+
import { validateAndFormatAddress } from "../utils/validateAndParseAddress.js";
|
3
4
|
export class Account {
|
4
5
|
static toAccount(account) {
|
5
6
|
const chainId = account?.chainId
|
6
7
|
? getChainIdFromOrbyChainId(account.chainId)
|
7
8
|
: undefined;
|
8
|
-
if (!chainId && account?.
|
9
|
+
if (!chainId && account?.accountType == AccountType.SCA) {
|
9
10
|
return undefined;
|
10
11
|
}
|
11
|
-
return new Account(account.address, account?.
|
12
|
+
return new Account(account.address, account?.accountType, // backend uses accountType, frontend uses type
|
13
|
+
account.vmType, chainId);
|
12
14
|
}
|
13
15
|
constructor(address, type, vmType, chainId) {
|
14
16
|
// TODO(felix): add this back
|
15
17
|
// invariant(!_.isUndefined(getBlockchainFromBlockchainId(chainId)), "CHAIN_ID");
|
16
|
-
this.address =
|
18
|
+
this.address = validateAndFormatAddress(address);
|
17
19
|
this.chainId = chainId ? BigInt(chainId) : undefined;
|
18
20
|
this.type = type;
|
19
21
|
this.vmType = vmType;
|
@@ -27,13 +29,13 @@ export class Account {
|
|
27
29
|
}
|
28
30
|
static key(address, chainId) {
|
29
31
|
return chainId
|
30
|
-
? `${chainId?.toString()
|
32
|
+
? `${chainId?.toString()}-${validateAndFormatAddress(address)}`
|
31
33
|
: address;
|
32
34
|
}
|
33
35
|
toAccountModel() {
|
34
36
|
return {
|
35
37
|
address: this.address,
|
36
|
-
|
38
|
+
accountType: this.type?.toUpperCase(), // backend uses accountType, frontend uses type
|
37
39
|
vmType: this.vmType?.toUpperCase(),
|
38
40
|
chainId: this.chainId ? "EIP155-" + this.chainId : undefined,
|
39
41
|
};
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { Currency } from "./currency.js";
|
2
|
-
import {
|
2
|
+
import { validateAndFormatAddress, } from "../../utils/validateAndParseAddress.js";
|
3
3
|
import { TokenType } from "../../enums.js";
|
4
4
|
/**
|
5
5
|
* Represents an ERC20 token with a unique address and some metadata.
|
@@ -28,10 +28,10 @@ export class FungibleToken extends Currency {
|
|
28
28
|
// TODO(felix): bypassChecksum is a little confusing since when bypassChecksum is true, we still validate the address
|
29
29
|
// bypassChecksum is derived from the isNative parameter, so we should remove it and just check if isNative here
|
30
30
|
if (bypassChecksum) {
|
31
|
-
this.address =
|
31
|
+
this.address = validateAndFormatAddress(address);
|
32
32
|
}
|
33
33
|
else if (!isNative) {
|
34
|
-
this.address =
|
34
|
+
this.address = validateAndFormatAddress(address);
|
35
35
|
}
|
36
36
|
else {
|
37
37
|
this.address = address;
|
@@ -47,7 +47,8 @@ export class FungibleToken extends Currency {
|
|
47
47
|
if (this === other)
|
48
48
|
return true;
|
49
49
|
return (this.chainId == other?.chainId &&
|
50
|
-
this.address
|
50
|
+
validateAndFormatAddress(this.address) ==
|
51
|
+
validateAndFormatAddress(other?.address));
|
51
52
|
}
|
52
53
|
/**
|
53
54
|
* Returns the currency object that this token represents
|
@@ -59,6 +60,6 @@ export class FungibleToken extends Currency {
|
|
59
60
|
return TokenType.FUNGIBLE_TOKEN;
|
60
61
|
}
|
61
62
|
identifier() {
|
62
|
-
return `${this.chainId}+${this.address
|
63
|
+
return `${this.chainId}+${validateAndFormatAddress(this.address)}`;
|
63
64
|
}
|
64
65
|
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { Asset } from "./asset.js";
|
2
|
-
import {
|
2
|
+
import { validateAndFormatAddress, } from "../../utils/validateAndParseAddress.js";
|
3
3
|
import { TokenType } from "../../enums.js";
|
4
4
|
/**
|
5
5
|
* Represents an ERC721 token with a unique address and some metadata.
|
@@ -20,10 +20,10 @@ export class NonFungibleToken extends Asset {
|
|
20
20
|
this.isNative = false;
|
21
21
|
this.isToken = true;
|
22
22
|
if (bypassChecksum) {
|
23
|
-
this.address =
|
23
|
+
this.address = validateAndFormatAddress(address);
|
24
24
|
}
|
25
25
|
else {
|
26
|
-
this.address =
|
26
|
+
this.address = validateAndFormatAddress(address);
|
27
27
|
}
|
28
28
|
this.chainId = chainId;
|
29
29
|
this.url = url;
|
@@ -44,7 +44,7 @@ export class NonFungibleToken extends Asset {
|
|
44
44
|
if (this === other)
|
45
45
|
return true;
|
46
46
|
return (this.chainId === other.chainId &&
|
47
|
-
this.address === other.address
|
47
|
+
this.address === validateAndFormatAddress(other.address));
|
48
48
|
}
|
49
49
|
/**
|
50
50
|
* Returns the asset representation of this currency
|
@@ -56,6 +56,6 @@ export class NonFungibleToken extends Asset {
|
|
56
56
|
return TokenType.NON_FUNGIBLE_TOKEN;
|
57
57
|
}
|
58
58
|
identifier() {
|
59
|
-
return `${this.chainId}+${this.address
|
59
|
+
return `${this.chainId}+${validateAndFormatAddress(this.address)}`;
|
60
60
|
}
|
61
61
|
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { Currency } from "./currency.js";
|
2
|
-
import {
|
2
|
+
import { validateAndFormatAddress, } from "../../utils/validateAndParseAddress.js";
|
3
3
|
import { TokenType } from "../../enums.js";
|
4
4
|
/**
|
5
5
|
* Represents an ERC1155 token with a unique address and some metadata.
|
@@ -22,10 +22,10 @@ export class SemiFungibleToken extends Currency {
|
|
22
22
|
this.isNative = false;
|
23
23
|
this.isToken = true;
|
24
24
|
if (bypassChecksum) {
|
25
|
-
this.address =
|
25
|
+
this.address = validateAndFormatAddress(address);
|
26
26
|
}
|
27
27
|
else {
|
28
|
-
this.address =
|
28
|
+
this.address = validateAndFormatAddress(address);
|
29
29
|
}
|
30
30
|
this.chainId = chainId;
|
31
31
|
this.url = url;
|
@@ -46,7 +46,7 @@ export class SemiFungibleToken extends Currency {
|
|
46
46
|
if (this === other)
|
47
47
|
return true;
|
48
48
|
return (this.chainId === other.chainId &&
|
49
|
-
this.address === other.address
|
49
|
+
this.address === validateAndFormatAddress(other.address));
|
50
50
|
}
|
51
51
|
/**
|
52
52
|
* Returns the currency object that this token represents
|
@@ -58,6 +58,6 @@ export class SemiFungibleToken extends Currency {
|
|
58
58
|
return TokenType.SEMI_FUNGIBLE_TOKEN;
|
59
59
|
}
|
60
60
|
identifier() {
|
61
|
-
return `${this.chainId}+${this.address
|
61
|
+
return `${this.chainId}+${validateAndFormatAddress(this.address)}`;
|
62
62
|
}
|
63
63
|
}
|
package/dist/esm/enums.d.ts
CHANGED
@@ -9,6 +9,7 @@ export declare enum Blockchain {
|
|
9
9
|
OPTIMISM = "optimism",
|
10
10
|
EVMOS = "evmos",
|
11
11
|
MOONBEAM = "moonbeam",
|
12
|
+
SOLANA = "solana",
|
12
13
|
ETHEREUM_SEPOLIA = "ethereum_sepolia",
|
13
14
|
ETHEREUM_HOLESKY = "ethereum_holesky",
|
14
15
|
BASE_SEPOLIA = "base_sepolia",
|
@@ -33,7 +34,8 @@ export declare enum AccountType {
|
|
33
34
|
SCA = "SCA"
|
34
35
|
}
|
35
36
|
export declare enum VMType {
|
36
|
-
EVM = "EVM"
|
37
|
+
EVM = "EVM",
|
38
|
+
SVM = "SVM"
|
37
39
|
}
|
38
40
|
export declare enum ChainSupportStatus {
|
39
41
|
CHAIN_SUPPORTED = "CHAIN_SUPPORTED",
|
package/dist/esm/enums.js
CHANGED
@@ -10,6 +10,7 @@ export var Blockchain;
|
|
10
10
|
Blockchain["OPTIMISM"] = "optimism";
|
11
11
|
Blockchain["EVMOS"] = "evmos";
|
12
12
|
Blockchain["MOONBEAM"] = "moonbeam";
|
13
|
+
Blockchain["SOLANA"] = "solana";
|
13
14
|
// testnets
|
14
15
|
Blockchain["ETHEREUM_SEPOLIA"] = "ethereum_sepolia";
|
15
16
|
Blockchain["ETHEREUM_HOLESKY"] = "ethereum_holesky";
|
@@ -40,6 +41,7 @@ export var AccountType;
|
|
40
41
|
export var VMType;
|
41
42
|
(function (VMType) {
|
42
43
|
VMType["EVM"] = "EVM";
|
44
|
+
VMType["SVM"] = "SVM";
|
43
45
|
})(VMType || (VMType = {}));
|
44
46
|
export var ChainSupportStatus;
|
45
47
|
(function (ChainSupportStatus) {
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.js
CHANGED
@@ -2,7 +2,7 @@ import { AccountCluster, OnchainOperation, OperationSet, OperationStatus, Signed
|
|
2
2
|
import { CurrencyAmount } from "../entities/financial/currency_amount.js";
|
3
3
|
import { OperationStatusType, QuoteType } from "../enums.js";
|
4
4
|
export interface IOperationActions {
|
5
|
-
getOperationsToExecuteTransaction(accountClusterId: string,
|
5
|
+
getOperationsToExecuteTransaction(accountClusterId: string, data: string, to?: string, value?: bigint, gasToken?: {
|
6
6
|
standardizedTokenId: string;
|
7
7
|
tokenSources?: {
|
8
8
|
chainId: bigint;
|
@@ -16,15 +16,22 @@ export interface IOperationActions {
|
|
16
16
|
address?: string;
|
17
17
|
}[];
|
18
18
|
}): Promise<OperationSet>;
|
19
|
+
getOperationsToSignTransactionOrSignTypedData(accountClusterId: string, data: string, to?: string, value?: bigint, gasToken?: {
|
20
|
+
standardizedTokenId: string;
|
21
|
+
tokenSources?: {
|
22
|
+
chainId: bigint;
|
23
|
+
address?: string;
|
24
|
+
}[];
|
25
|
+
}): Promise<OperationSet>;
|
19
26
|
getOperationsToCancelTransaction(accountClusterId: string, operationSetId: string): Promise<OperationSet>;
|
20
|
-
isTransactionPreconditionSatisfied(accountClusterId: string,
|
27
|
+
isTransactionPreconditionSatisfied(accountClusterId: string, data: string, to?: string, value?: bigint): Promise<boolean>;
|
21
28
|
isTypedDataPreconditionSatisfied(accountClusterId: string, data: string): Promise<boolean>;
|
22
29
|
sendSignedOperations(accountClusterId: string, signedOperations: SignedOperation[]): Promise<{
|
23
30
|
operationSetId: string;
|
24
31
|
operationResponses: OperationStatus[];
|
25
32
|
}>;
|
26
33
|
getOperationStatuses(operationIds: string[]): Promise<OperationStatus[]>;
|
27
|
-
estimateFiatCostToExecuteTransaction(
|
34
|
+
estimateFiatCostToExecuteTransaction(data: string, to?: string, value?: bigint): Promise<CurrencyAmount>;
|
28
35
|
estimateFiatCostToSignTypedData(data: string): Promise<CurrencyAmount>;
|
29
36
|
getOperationsToTransferToken(accountClusterId: string, standardizedTokenId: string, amount: bigint, recipient: {
|
30
37
|
chainId: bigint;
|
@@ -1,5 +1,6 @@
|
|
1
|
-
import { Blockchain } from "../enums.js";
|
1
|
+
import { Blockchain, VMType } from "../enums.js";
|
2
2
|
export declare const getChainIdFromOrbyChainId: (value: string) => bigint | undefined;
|
3
|
+
export declare const getVirtualEnvironment: (id: bigint) => VMType;
|
3
4
|
export declare const getOrbyChainId: (chainId: bigint) => string;
|
4
5
|
export declare const getBlockchainIdFromBlockchain: (blockchain: Blockchain) => number;
|
5
6
|
export declare const hasError: (data: any) => {
|
package/dist/esm/utils/utils.js
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
import { Blockchain, BlockchainEnvironment } from "../enums.js";
|
1
|
+
import { Blockchain, BlockchainEnvironment, VMType } from "../enums.js";
|
2
2
|
import { BLOCKCHAIN_ID, BLOCKCHAIN_ID_TO_BLOCKCHAIN, CHAIN_CONFIGS, } from "../constants.js";
|
3
|
+
import { validateAndLowerCase } from "./validateAndParseAddress.js";
|
3
4
|
export const getChainIdFromOrbyChainId = (value) => {
|
4
5
|
let chainId = undefined;
|
5
|
-
const formattedValue = value
|
6
|
+
const formattedValue = validateAndLowerCase(value);
|
6
7
|
if (formattedValue?.includes("eip155")) {
|
7
8
|
const publicIdElements = formattedValue.split("eip155-");
|
8
9
|
const potentialId = publicIdElements?.length > 1 ? publicIdElements[1] : undefined;
|
@@ -10,6 +11,13 @@ export const getChainIdFromOrbyChainId = (value) => {
|
|
10
11
|
? BigInt(potentialId)
|
11
12
|
: undefined;
|
12
13
|
}
|
14
|
+
else if (formattedValue?.includes("svm")) {
|
15
|
+
const publicIdElements = formattedValue.split("svm-");
|
16
|
+
const potentialId = publicIdElements?.length > 1 ? publicIdElements[1] : undefined;
|
17
|
+
chainId = !Number.isNaN(Number(potentialId))
|
18
|
+
? BigInt(potentialId)
|
19
|
+
: undefined;
|
20
|
+
}
|
13
21
|
else {
|
14
22
|
const blockchain = getBlockchainFromName(formattedValue);
|
15
23
|
const potentialId = blockchain
|
@@ -19,11 +27,26 @@ export const getChainIdFromOrbyChainId = (value) => {
|
|
19
27
|
}
|
20
28
|
return chainId;
|
21
29
|
};
|
30
|
+
export const getVirtualEnvironment = (id) => {
|
31
|
+
const blockchain = id ? BLOCKCHAIN_ID_TO_BLOCKCHAIN[Number(id)] : undefined;
|
32
|
+
switch (blockchain) {
|
33
|
+
case undefined:
|
34
|
+
return undefined;
|
35
|
+
case Blockchain.SOLANA:
|
36
|
+
return VMType.SVM;
|
37
|
+
default:
|
38
|
+
return VMType.EVM;
|
39
|
+
}
|
40
|
+
};
|
22
41
|
export const getOrbyChainId = (chainId) => {
|
23
|
-
|
24
|
-
|
42
|
+
switch (getVirtualEnvironment(chainId)) {
|
43
|
+
case VMType.SVM:
|
44
|
+
return `SVM-${chainId.toString()}`;
|
45
|
+
case VMType.EVM:
|
46
|
+
return `EIP155-${chainId.toString()}`;
|
47
|
+
default:
|
48
|
+
return undefined;
|
25
49
|
}
|
26
|
-
return `EIP155-${chainId.toString()}`;
|
27
50
|
};
|
28
51
|
export const getBlockchainIdFromBlockchain = (blockchain) => {
|
29
52
|
return BLOCKCHAIN_ID[blockchain];
|
@@ -35,7 +58,7 @@ export const hasError = (data) => {
|
|
35
58
|
return undefined;
|
36
59
|
};
|
37
60
|
export const getBlockchainFromName = (chainName) => {
|
38
|
-
const formattedChainName = chainName
|
61
|
+
const formattedChainName = validateAndLowerCase(chainName)?.replace("-", "_");
|
39
62
|
switch (formattedChainName) {
|
40
63
|
case "bnbt": {
|
41
64
|
return Blockchain.BINANCE_TESTNET;
|
@@ -8,3 +8,11 @@ export declare function validateAndParseAddress(address: string): string;
|
|
8
8
|
* @param address the unchecksummed hex address
|
9
9
|
*/
|
10
10
|
export declare function checkValidAddress(address: string): string;
|
11
|
+
/**
|
12
|
+
* Checks if an address is valid by checking 0x prefix, length === 42 and hex encoding.
|
13
|
+
* @param address the unchecksummed hex address
|
14
|
+
*/
|
15
|
+
export declare function checkValidEVMAddress(address: string): string;
|
16
|
+
export declare function checkValidSVMAddress(address: string): string;
|
17
|
+
export declare function validateAndFormatAddress(address?: string): string;
|
18
|
+
export declare function validateAndLowerCase(value?: string): string;
|
@@ -23,3 +23,51 @@ export function checkValidAddress(address) {
|
|
23
23
|
}
|
24
24
|
throw new Error(`${address} is not a valid address.`);
|
25
25
|
}
|
26
|
+
/**
|
27
|
+
* Checks if an address is valid by checking 0x prefix, length === 42 and hex encoding.
|
28
|
+
* @param address the unchecksummed hex address
|
29
|
+
*/
|
30
|
+
export function checkValidEVMAddress(address) {
|
31
|
+
if (startsWith0xLen42HexRegex.test(address)) {
|
32
|
+
return address.toLowerCase();
|
33
|
+
}
|
34
|
+
throw new Error(`${address} is not a valid address.`);
|
35
|
+
}
|
36
|
+
// Solana address validation
|
37
|
+
// Base58 character set: [1-9A-HJ-NP-Za-km-z]
|
38
|
+
// Standard Solana addresses are 32-44 characters long
|
39
|
+
const solanaRegex = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
|
40
|
+
export function checkValidSVMAddress(address) {
|
41
|
+
if (solanaRegex.test(address)) {
|
42
|
+
return address;
|
43
|
+
}
|
44
|
+
throw new Error(`${address} is not a valid address.`);
|
45
|
+
}
|
46
|
+
// for ETH and SOL addresses.
|
47
|
+
// ETH addresses are 42 characters long, starting with 0x
|
48
|
+
// SOL addresses are 32-44 characters long, containing only alphanumeric characters
|
49
|
+
export function validateAndFormatAddress(address) {
|
50
|
+
if (!address) {
|
51
|
+
return undefined;
|
52
|
+
}
|
53
|
+
// Remove any whitespace
|
54
|
+
address = address?.trim();
|
55
|
+
if (startsWith0xLen42HexRegex.test(address)) {
|
56
|
+
return address.toLowerCase();
|
57
|
+
}
|
58
|
+
else if (solanaRegex.test(address)) {
|
59
|
+
return address;
|
60
|
+
}
|
61
|
+
return undefined;
|
62
|
+
}
|
63
|
+
export function validateAndLowerCase(value) {
|
64
|
+
if (!value) {
|
65
|
+
return undefined;
|
66
|
+
}
|
67
|
+
// Remove any whitespace
|
68
|
+
value = value?.trim();
|
69
|
+
if (solanaRegex.test(value)) {
|
70
|
+
throw new Error(`should not lowwercase solana address: ${value}`);
|
71
|
+
}
|
72
|
+
return value?.toLowerCase();
|
73
|
+
}
|