@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/CHANGELOG.md
CHANGED
@@ -2,6 +2,16 @@
|
|
2
2
|
|
3
3
|
### Unreleased
|
4
4
|
|
5
|
+
### 0.0.20
|
6
|
+
|
7
|
+
- adding getOperationsToSignTransactionOrSignTypedData function and interfaces
|
8
|
+
- making to value optional for the isTransactionPreconditionSatisfied, estimateFiatCostToExecuteTransaction and getOperationsToExecuteTransaction functions
|
9
|
+
|
10
|
+
### 0.0.19
|
11
|
+
|
12
|
+
- fix: use accountType when interacting with the backend
|
13
|
+
- changing address formating to handle Solana addresses
|
14
|
+
|
5
15
|
### 0.0.18
|
6
16
|
|
7
17
|
- chore: update type (using Account.type instead of Account.accountType)
|
@@ -4,6 +4,7 @@ exports.AccountClusterActions = 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
6
|
const utils_js_1 = require("../utils/utils.js");
|
7
|
+
const validateAndParseAddress_js_1 = require("../utils/validateAndParseAddress.js");
|
7
8
|
class AccountClusterActions extends library_request_js_1.LibraryRequest {
|
8
9
|
constructor(library, client, provider) {
|
9
10
|
super(library, client, provider);
|
@@ -51,7 +52,7 @@ class AccountClusterActions extends library_request_js_1.LibraryRequest {
|
|
51
52
|
return {
|
52
53
|
chainId: (0, utils_js_1.getChainIdFromOrbyChainId)(info.chainId),
|
53
54
|
virtualNodeRpcUrl: info.virtualNodeRpcUrl,
|
54
|
-
entrypointAccountAddress: info?.entrypointAccountAddress
|
55
|
+
entrypointAccountAddress: (0, validateAndParseAddress_js_1.validateAndFormatAddress)(info?.entrypointAccountAddress),
|
55
56
|
};
|
56
57
|
});
|
57
58
|
}
|
@@ -4,7 +4,7 @@ import { LIBRARY_TYPE, OperationStatusType, QuoteType } from "../enums.js";
|
|
4
4
|
import { LibraryRequest } from "../entities/library_request.js";
|
5
5
|
export declare class OperationActions extends LibraryRequest {
|
6
6
|
constructor(library: LIBRARY_TYPE, client?: any, provider?: any);
|
7
|
-
getOperationsToExecuteTransaction(accountClusterId: string,
|
7
|
+
getOperationsToExecuteTransaction(accountClusterId: string, data: string, to?: string, value?: bigint, gasToken?: {
|
8
8
|
standardizedTokenId: string;
|
9
9
|
tokenSources?: {
|
10
10
|
chainId: bigint;
|
@@ -18,15 +18,22 @@ export declare class OperationActions extends LibraryRequest {
|
|
18
18
|
address?: string;
|
19
19
|
}[];
|
20
20
|
}): Promise<OperationSet>;
|
21
|
+
getOperationsToSignTransactionOrSignTypedData(accountClusterId: string, data: string, to?: string, value?: bigint, gasToken?: {
|
22
|
+
standardizedTokenId: string;
|
23
|
+
tokenSources?: {
|
24
|
+
chainId: bigint;
|
25
|
+
address?: string;
|
26
|
+
}[];
|
27
|
+
}): Promise<OperationSet>;
|
21
28
|
getOperationsToCancelTransaction(accountClusterId: string, operationSetId: string): Promise<OperationSet>;
|
22
|
-
isTransactionPreconditionSatisfied(accountClusterId: string,
|
29
|
+
isTransactionPreconditionSatisfied(accountClusterId: string, data: string, to?: string, value?: bigint): Promise<boolean>;
|
23
30
|
isTypedDataPreconditionSatisfied(accountClusterId: string, data: string): Promise<boolean>;
|
24
31
|
sendSignedOperations(accountClusterId: string, signedOperations: SignedOperation[]): Promise<{
|
25
32
|
operationSetId: string;
|
26
33
|
operationResponses: OperationStatus[];
|
27
34
|
}>;
|
28
35
|
getOperationStatuses(operationIds: string[]): Promise<OperationStatus[]>;
|
29
|
-
estimateFiatCostToExecuteTransaction(
|
36
|
+
estimateFiatCostToExecuteTransaction(data: string, to?: string, value?: bigint): Promise<CurrencyAmount>;
|
30
37
|
estimateFiatCostToSignTypedData(data: string): Promise<CurrencyAmount>;
|
31
38
|
getOperationsToTransferToken(accountClusterId: string, standardizedTokenId: string, amount: bigint, recipient: {
|
32
39
|
chainId: bigint;
|
@@ -15,7 +15,7 @@ class OperationActions extends library_request_js_1.LibraryRequest {
|
|
15
15
|
constructor(library, client, provider) {
|
16
16
|
super(library, client, provider);
|
17
17
|
}
|
18
|
-
async getOperationsToExecuteTransaction(accountClusterId,
|
18
|
+
async getOperationsToExecuteTransaction(accountClusterId, data, to, value, gasToken) {
|
19
19
|
const formattedGasToken = gasToken
|
20
20
|
? {
|
21
21
|
...gasToken,
|
@@ -46,7 +46,7 @@ class OperationActions extends library_request_js_1.LibraryRequest {
|
|
46
46
|
})),
|
47
47
|
}
|
48
48
|
: undefined;
|
49
|
-
const operationSet = await this.sendRequest("
|
49
|
+
const operationSet = await this.sendRequest("orby_getOperationsForSignTransactionOrSignTypedData", [
|
50
50
|
{
|
51
51
|
accountClusterId,
|
52
52
|
data,
|
@@ -55,6 +55,27 @@ class OperationActions extends library_request_js_1.LibraryRequest {
|
|
55
55
|
]);
|
56
56
|
return (0, action_helpers_js_1.extractOperationSet)(operationSet);
|
57
57
|
}
|
58
|
+
async getOperationsToSignTransactionOrSignTypedData(accountClusterId, data, to, value, gasToken) {
|
59
|
+
const formattedGasToken = gasToken
|
60
|
+
? {
|
61
|
+
...gasToken,
|
62
|
+
tokenSources: gasToken.tokenSources?.map(({ chainId, address }) => ({
|
63
|
+
chainId: (0, utils_js_1.getOrbyChainId)(chainId),
|
64
|
+
address,
|
65
|
+
})),
|
66
|
+
}
|
67
|
+
: undefined;
|
68
|
+
const operationSet = await this.sendRequest("orby_getOperationsToSignTransactionOrSignTypedData", [
|
69
|
+
{
|
70
|
+
accountClusterId,
|
71
|
+
to,
|
72
|
+
data,
|
73
|
+
value,
|
74
|
+
gasToken: formattedGasToken,
|
75
|
+
},
|
76
|
+
]);
|
77
|
+
return (0, action_helpers_js_1.extractOperationSet)(operationSet);
|
78
|
+
}
|
58
79
|
async getOperationsToCancelTransaction(accountClusterId, operationSetId) {
|
59
80
|
const operationSet = await this.sendRequest("orby_getOperationsToCancelTransaction", [
|
60
81
|
{
|
@@ -64,7 +85,7 @@ class OperationActions extends library_request_js_1.LibraryRequest {
|
|
64
85
|
]);
|
65
86
|
return (0, action_helpers_js_1.extractOperationSet)(operationSet);
|
66
87
|
}
|
67
|
-
async isTransactionPreconditionSatisfied(accountClusterId,
|
88
|
+
async isTransactionPreconditionSatisfied(accountClusterId, data, to, value) {
|
68
89
|
const { satisfied } = await this.sendRequest("orby_isTransactionPreconditionSatisfied", [
|
69
90
|
{
|
70
91
|
accountClusterId,
|
@@ -108,7 +129,7 @@ class OperationActions extends library_request_js_1.LibraryRequest {
|
|
108
129
|
const { operationStatuses } = await this.sendRequest("orby_getOperationStatuses", [{ operationIds }]);
|
109
130
|
return (0, action_helpers_js_1.extractOperationStatuses)(operationStatuses);
|
110
131
|
}
|
111
|
-
async estimateFiatCostToExecuteTransaction(
|
132
|
+
async estimateFiatCostToExecuteTransaction(data, to, value) {
|
112
133
|
const { estimatedCost, code, message } = await this.sendRequest("orby_estimateFiatCostToExecuteTransaction", [
|
113
134
|
{
|
114
135
|
to,
|
package/dist/cjs/constants.js
CHANGED
@@ -20,6 +20,7 @@ exports.BLOCKCHAIN_ID = {
|
|
20
20
|
[enums_js_1.Blockchain.MOONBEAM]: 1284,
|
21
21
|
[enums_js_1.Blockchain.BASE]: 8453,
|
22
22
|
[enums_js_1.Blockchain.AVALANCHE]: 43114,
|
23
|
+
[enums_js_1.Blockchain.SOLANA]: 101,
|
23
24
|
// testnets
|
24
25
|
[enums_js_1.Blockchain.ETHEREUM_SEPOLIA]: 11155111,
|
25
26
|
[enums_js_1.Blockchain.ETHEREUM_HOLESKY]: 17000,
|
@@ -76,6 +77,10 @@ exports.CHAIN_CONFIGS = {
|
|
76
77
|
environment: enums_js_1.BlockchainEnvironment.MAINNET,
|
77
78
|
chainId: BigInt(43114),
|
78
79
|
},
|
80
|
+
[enums_js_1.Blockchain.SOLANA]: {
|
81
|
+
environment: enums_js_1.BlockchainEnvironment.MAINNET,
|
82
|
+
chainId: BigInt(101),
|
83
|
+
},
|
79
84
|
// testnets
|
80
85
|
[enums_js_1.Blockchain.ETHEREUM_SEPOLIA]: {
|
81
86
|
environment: enums_js_1.BlockchainEnvironment.TESTNET,
|
@@ -125,6 +130,7 @@ exports.BLOCKCHAIN_ID_TO_BLOCKCHAIN = {
|
|
125
130
|
[1284]: enums_js_1.Blockchain.MOONBEAM,
|
126
131
|
[8453]: enums_js_1.Blockchain.BASE,
|
127
132
|
[43114]: enums_js_1.Blockchain.AVALANCHE,
|
133
|
+
[101]: enums_js_1.Blockchain.SOLANA,
|
128
134
|
// testnets
|
129
135
|
[11155111]: enums_js_1.Blockchain.ETHEREUM_SEPOLIA,
|
130
136
|
[84532]: enums_js_1.Blockchain.BASE_SEPOLIA,
|
@@ -3,20 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Account = void 0;
|
4
4
|
const enums_js_1 = require("../enums.js");
|
5
5
|
const utils_js_1 = require("../utils/utils.js");
|
6
|
+
const validateAndParseAddress_js_1 = require("../utils/validateAndParseAddress.js");
|
6
7
|
class Account {
|
7
8
|
static toAccount(account) {
|
8
9
|
const chainId = account?.chainId
|
9
10
|
? (0, utils_js_1.getChainIdFromOrbyChainId)(account.chainId)
|
10
11
|
: undefined;
|
11
|
-
if (!chainId && account?.
|
12
|
+
if (!chainId && account?.accountType == enums_js_1.AccountType.SCA) {
|
12
13
|
return undefined;
|
13
14
|
}
|
14
|
-
return new Account(account.address, account?.
|
15
|
+
return new Account(account.address, account?.accountType, // backend uses accountType, frontend uses type
|
16
|
+
account.vmType, chainId);
|
15
17
|
}
|
16
18
|
constructor(address, type, vmType, chainId) {
|
17
19
|
// TODO(felix): add this back
|
18
20
|
// invariant(!_.isUndefined(getBlockchainFromBlockchainId(chainId)), "CHAIN_ID");
|
19
|
-
this.address =
|
21
|
+
this.address = (0, validateAndParseAddress_js_1.validateAndFormatAddress)(address);
|
20
22
|
this.chainId = chainId ? BigInt(chainId) : undefined;
|
21
23
|
this.type = type;
|
22
24
|
this.vmType = vmType;
|
@@ -30,13 +32,13 @@ class Account {
|
|
30
32
|
}
|
31
33
|
static key(address, chainId) {
|
32
34
|
return chainId
|
33
|
-
? `${chainId?.toString()
|
35
|
+
? `${chainId?.toString()}-${(0, validateAndParseAddress_js_1.validateAndFormatAddress)(address)}`
|
34
36
|
: address;
|
35
37
|
}
|
36
38
|
toAccountModel() {
|
37
39
|
return {
|
38
40
|
address: this.address,
|
39
|
-
|
41
|
+
accountType: this.type?.toUpperCase(), // backend uses accountType, frontend uses type
|
40
42
|
vmType: this.vmType?.toUpperCase(),
|
41
43
|
chainId: this.chainId ? "EIP155-" + this.chainId : undefined,
|
42
44
|
};
|
@@ -31,10 +31,10 @@ class FungibleToken extends currency_js_1.Currency {
|
|
31
31
|
// TODO(felix): bypassChecksum is a little confusing since when bypassChecksum is true, we still validate the address
|
32
32
|
// bypassChecksum is derived from the isNative parameter, so we should remove it and just check if isNative here
|
33
33
|
if (bypassChecksum) {
|
34
|
-
this.address = (0, validateAndParseAddress_js_1.
|
34
|
+
this.address = (0, validateAndParseAddress_js_1.validateAndFormatAddress)(address);
|
35
35
|
}
|
36
36
|
else if (!isNative) {
|
37
|
-
this.address = (0, validateAndParseAddress_js_1.
|
37
|
+
this.address = (0, validateAndParseAddress_js_1.validateAndFormatAddress)(address);
|
38
38
|
}
|
39
39
|
else {
|
40
40
|
this.address = address;
|
@@ -50,7 +50,8 @@ class FungibleToken extends currency_js_1.Currency {
|
|
50
50
|
if (this === other)
|
51
51
|
return true;
|
52
52
|
return (this.chainId == other?.chainId &&
|
53
|
-
this.address
|
53
|
+
(0, validateAndParseAddress_js_1.validateAndFormatAddress)(this.address) ==
|
54
|
+
(0, validateAndParseAddress_js_1.validateAndFormatAddress)(other?.address));
|
54
55
|
}
|
55
56
|
/**
|
56
57
|
* Returns the currency object that this token represents
|
@@ -62,7 +63,7 @@ class FungibleToken extends currency_js_1.Currency {
|
|
62
63
|
return enums_js_1.TokenType.FUNGIBLE_TOKEN;
|
63
64
|
}
|
64
65
|
identifier() {
|
65
|
-
return `${this.chainId}+${this.address
|
66
|
+
return `${this.chainId}+${(0, validateAndParseAddress_js_1.validateAndFormatAddress)(this.address)}`;
|
66
67
|
}
|
67
68
|
}
|
68
69
|
exports.FungibleToken = FungibleToken;
|
@@ -23,10 +23,10 @@ class NonFungibleToken extends asset_js_1.Asset {
|
|
23
23
|
this.isNative = false;
|
24
24
|
this.isToken = true;
|
25
25
|
if (bypassChecksum) {
|
26
|
-
this.address = (0, validateAndParseAddress_js_1.
|
26
|
+
this.address = (0, validateAndParseAddress_js_1.validateAndFormatAddress)(address);
|
27
27
|
}
|
28
28
|
else {
|
29
|
-
this.address = (0, validateAndParseAddress_js_1.
|
29
|
+
this.address = (0, validateAndParseAddress_js_1.validateAndFormatAddress)(address);
|
30
30
|
}
|
31
31
|
this.chainId = chainId;
|
32
32
|
this.url = url;
|
@@ -47,7 +47,7 @@ class NonFungibleToken extends asset_js_1.Asset {
|
|
47
47
|
if (this === other)
|
48
48
|
return true;
|
49
49
|
return (this.chainId === other.chainId &&
|
50
|
-
this.address === other.address
|
50
|
+
this.address === (0, validateAndParseAddress_js_1.validateAndFormatAddress)(other.address));
|
51
51
|
}
|
52
52
|
/**
|
53
53
|
* Returns the asset representation of this currency
|
@@ -59,7 +59,7 @@ class NonFungibleToken extends asset_js_1.Asset {
|
|
59
59
|
return enums_js_1.TokenType.NON_FUNGIBLE_TOKEN;
|
60
60
|
}
|
61
61
|
identifier() {
|
62
|
-
return `${this.chainId}+${this.address
|
62
|
+
return `${this.chainId}+${(0, validateAndParseAddress_js_1.validateAndFormatAddress)(this.address)}`;
|
63
63
|
}
|
64
64
|
}
|
65
65
|
exports.NonFungibleToken = NonFungibleToken;
|
@@ -25,10 +25,10 @@ class SemiFungibleToken extends currency_js_1.Currency {
|
|
25
25
|
this.isNative = false;
|
26
26
|
this.isToken = true;
|
27
27
|
if (bypassChecksum) {
|
28
|
-
this.address = (0, validateAndParseAddress_js_1.
|
28
|
+
this.address = (0, validateAndParseAddress_js_1.validateAndFormatAddress)(address);
|
29
29
|
}
|
30
30
|
else {
|
31
|
-
this.address = (0, validateAndParseAddress_js_1.
|
31
|
+
this.address = (0, validateAndParseAddress_js_1.validateAndFormatAddress)(address);
|
32
32
|
}
|
33
33
|
this.chainId = chainId;
|
34
34
|
this.url = url;
|
@@ -49,7 +49,7 @@ class SemiFungibleToken extends currency_js_1.Currency {
|
|
49
49
|
if (this === other)
|
50
50
|
return true;
|
51
51
|
return (this.chainId === other.chainId &&
|
52
|
-
this.address === other.address
|
52
|
+
this.address === (0, validateAndParseAddress_js_1.validateAndFormatAddress)(other.address));
|
53
53
|
}
|
54
54
|
/**
|
55
55
|
* Returns the currency object that this token represents
|
@@ -61,7 +61,7 @@ class SemiFungibleToken extends currency_js_1.Currency {
|
|
61
61
|
return enums_js_1.TokenType.SEMI_FUNGIBLE_TOKEN;
|
62
62
|
}
|
63
63
|
identifier() {
|
64
|
-
return `${this.chainId}+${this.address
|
64
|
+
return `${this.chainId}+${(0, validateAndParseAddress_js_1.validateAndFormatAddress)(this.address)}`;
|
65
65
|
}
|
66
66
|
}
|
67
67
|
exports.SemiFungibleToken = SemiFungibleToken;
|
package/dist/cjs/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/cjs/enums.js
CHANGED
@@ -13,6 +13,7 @@ var Blockchain;
|
|
13
13
|
Blockchain["OPTIMISM"] = "optimism";
|
14
14
|
Blockchain["EVMOS"] = "evmos";
|
15
15
|
Blockchain["MOONBEAM"] = "moonbeam";
|
16
|
+
Blockchain["SOLANA"] = "solana";
|
16
17
|
// testnets
|
17
18
|
Blockchain["ETHEREUM_SEPOLIA"] = "ethereum_sepolia";
|
18
19
|
Blockchain["ETHEREUM_HOLESKY"] = "ethereum_holesky";
|
@@ -43,6 +44,7 @@ var AccountType;
|
|
43
44
|
var VMType;
|
44
45
|
(function (VMType) {
|
45
46
|
VMType["EVM"] = "EVM";
|
47
|
+
VMType["SVM"] = "SVM";
|
46
48
|
})(VMType || (exports.VMType = VMType = {}));
|
47
49
|
var ChainSupportStatus;
|
48
50
|
(function (ChainSupportStatus) {
|
package/dist/cjs/index.d.ts
CHANGED
package/dist/cjs/index.js
CHANGED
@@ -47,3 +47,4 @@ __exportStar(require("./enums.js"), exports);
|
|
47
47
|
__exportStar(require("./types.js"), exports);
|
48
48
|
__exportStar(require("./constants.js"), exports);
|
49
49
|
__exportStar(require("./utils/utils.js"), exports);
|
50
|
+
__exportStar(require("./utils/validateAndParseAddress.js"), exports);
|
@@ -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/cjs/utils/utils.js
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.isMainnet = exports.getBlockchainFromName = exports.hasError = exports.getBlockchainIdFromBlockchain = exports.getOrbyChainId = exports.getChainIdFromOrbyChainId = void 0;
|
3
|
+
exports.isMainnet = exports.getBlockchainFromName = exports.hasError = exports.getBlockchainIdFromBlockchain = exports.getOrbyChainId = exports.getVirtualEnvironment = exports.getChainIdFromOrbyChainId = void 0;
|
4
4
|
const enums_js_1 = require("../enums.js");
|
5
5
|
const constants_js_1 = require("../constants.js");
|
6
|
+
const validateAndParseAddress_js_1 = require("./validateAndParseAddress.js");
|
6
7
|
const getChainIdFromOrbyChainId = (value) => {
|
7
8
|
let chainId = undefined;
|
8
|
-
const formattedValue =
|
9
|
+
const formattedValue = (0, validateAndParseAddress_js_1.validateAndLowerCase)(value);
|
9
10
|
if (formattedValue?.includes("eip155")) {
|
10
11
|
const publicIdElements = formattedValue.split("eip155-");
|
11
12
|
const potentialId = publicIdElements?.length > 1 ? publicIdElements[1] : undefined;
|
@@ -13,6 +14,13 @@ const getChainIdFromOrbyChainId = (value) => {
|
|
13
14
|
? BigInt(potentialId)
|
14
15
|
: undefined;
|
15
16
|
}
|
17
|
+
else if (formattedValue?.includes("svm")) {
|
18
|
+
const publicIdElements = formattedValue.split("svm-");
|
19
|
+
const potentialId = publicIdElements?.length > 1 ? publicIdElements[1] : undefined;
|
20
|
+
chainId = !Number.isNaN(Number(potentialId))
|
21
|
+
? BigInt(potentialId)
|
22
|
+
: undefined;
|
23
|
+
}
|
16
24
|
else {
|
17
25
|
const blockchain = (0, exports.getBlockchainFromName)(formattedValue);
|
18
26
|
const potentialId = blockchain
|
@@ -23,11 +31,27 @@ const getChainIdFromOrbyChainId = (value) => {
|
|
23
31
|
return chainId;
|
24
32
|
};
|
25
33
|
exports.getChainIdFromOrbyChainId = getChainIdFromOrbyChainId;
|
34
|
+
const getVirtualEnvironment = (id) => {
|
35
|
+
const blockchain = id ? constants_js_1.BLOCKCHAIN_ID_TO_BLOCKCHAIN[Number(id)] : undefined;
|
36
|
+
switch (blockchain) {
|
37
|
+
case undefined:
|
38
|
+
return undefined;
|
39
|
+
case enums_js_1.Blockchain.SOLANA:
|
40
|
+
return enums_js_1.VMType.SVM;
|
41
|
+
default:
|
42
|
+
return enums_js_1.VMType.EVM;
|
43
|
+
}
|
44
|
+
};
|
45
|
+
exports.getVirtualEnvironment = getVirtualEnvironment;
|
26
46
|
const getOrbyChainId = (chainId) => {
|
27
|
-
|
28
|
-
|
47
|
+
switch ((0, exports.getVirtualEnvironment)(chainId)) {
|
48
|
+
case enums_js_1.VMType.SVM:
|
49
|
+
return `SVM-${chainId.toString()}`;
|
50
|
+
case enums_js_1.VMType.EVM:
|
51
|
+
return `EIP155-${chainId.toString()}`;
|
52
|
+
default:
|
53
|
+
return undefined;
|
29
54
|
}
|
30
|
-
return `EIP155-${chainId.toString()}`;
|
31
55
|
};
|
32
56
|
exports.getOrbyChainId = getOrbyChainId;
|
33
57
|
const getBlockchainIdFromBlockchain = (blockchain) => {
|
@@ -42,7 +66,7 @@ const hasError = (data) => {
|
|
42
66
|
};
|
43
67
|
exports.hasError = hasError;
|
44
68
|
const getBlockchainFromName = (chainName) => {
|
45
|
-
const formattedChainName =
|
69
|
+
const formattedChainName = (0, validateAndParseAddress_js_1.validateAndLowerCase)(chainName)?.replace("-", "_");
|
46
70
|
switch (formattedChainName) {
|
47
71
|
case "bnbt": {
|
48
72
|
return enums_js_1.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;
|
@@ -2,6 +2,10 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.validateAndParseAddress = validateAndParseAddress;
|
4
4
|
exports.checkValidAddress = checkValidAddress;
|
5
|
+
exports.checkValidEVMAddress = checkValidEVMAddress;
|
6
|
+
exports.checkValidSVMAddress = checkValidSVMAddress;
|
7
|
+
exports.validateAndFormatAddress = validateAndFormatAddress;
|
8
|
+
exports.validateAndLowerCase = validateAndLowerCase;
|
5
9
|
const address_1 = require("@ethersproject/address");
|
6
10
|
/**
|
7
11
|
* Validates an address and returns the parsed (checksummed) version of that address
|
@@ -27,3 +31,51 @@ function checkValidAddress(address) {
|
|
27
31
|
}
|
28
32
|
throw new Error(`${address} is not a valid address.`);
|
29
33
|
}
|
34
|
+
/**
|
35
|
+
* Checks if an address is valid by checking 0x prefix, length === 42 and hex encoding.
|
36
|
+
* @param address the unchecksummed hex address
|
37
|
+
*/
|
38
|
+
function checkValidEVMAddress(address) {
|
39
|
+
if (startsWith0xLen42HexRegex.test(address)) {
|
40
|
+
return address.toLowerCase();
|
41
|
+
}
|
42
|
+
throw new Error(`${address} is not a valid address.`);
|
43
|
+
}
|
44
|
+
// Solana address validation
|
45
|
+
// Base58 character set: [1-9A-HJ-NP-Za-km-z]
|
46
|
+
// Standard Solana addresses are 32-44 characters long
|
47
|
+
const solanaRegex = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
|
48
|
+
function checkValidSVMAddress(address) {
|
49
|
+
if (solanaRegex.test(address)) {
|
50
|
+
return address;
|
51
|
+
}
|
52
|
+
throw new Error(`${address} is not a valid address.`);
|
53
|
+
}
|
54
|
+
// for ETH and SOL addresses.
|
55
|
+
// ETH addresses are 42 characters long, starting with 0x
|
56
|
+
// SOL addresses are 32-44 characters long, containing only alphanumeric characters
|
57
|
+
function validateAndFormatAddress(address) {
|
58
|
+
if (!address) {
|
59
|
+
return undefined;
|
60
|
+
}
|
61
|
+
// Remove any whitespace
|
62
|
+
address = address?.trim();
|
63
|
+
if (startsWith0xLen42HexRegex.test(address)) {
|
64
|
+
return address.toLowerCase();
|
65
|
+
}
|
66
|
+
else if (solanaRegex.test(address)) {
|
67
|
+
return address;
|
68
|
+
}
|
69
|
+
return undefined;
|
70
|
+
}
|
71
|
+
function validateAndLowerCase(value) {
|
72
|
+
if (!value) {
|
73
|
+
return undefined;
|
74
|
+
}
|
75
|
+
// Remove any whitespace
|
76
|
+
value = value?.trim();
|
77
|
+
if (solanaRegex.test(value)) {
|
78
|
+
throw new Error(`should not lowwercase solana address: ${value}`);
|
79
|
+
}
|
80
|
+
return value?.toLowerCase();
|
81
|
+
}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { extractAccountCluster, extractActivities, extractFungibleTokenOverview, extractStandardizedBalances, } from "../utils/action_helpers.js";
|
2
2
|
import { LibraryRequest } from "../entities/library_request.js";
|
3
3
|
import { getChainIdFromOrbyChainId, getOrbyChainId } from "../utils/utils.js";
|
4
|
+
import { validateAndFormatAddress } from "../utils/validateAndParseAddress.js";
|
4
5
|
export class AccountClusterActions extends LibraryRequest {
|
5
6
|
constructor(library, client, provider) {
|
6
7
|
super(library, client, provider);
|
@@ -48,7 +49,7 @@ export class AccountClusterActions extends LibraryRequest {
|
|
48
49
|
return {
|
49
50
|
chainId: getChainIdFromOrbyChainId(info.chainId),
|
50
51
|
virtualNodeRpcUrl: info.virtualNodeRpcUrl,
|
51
|
-
entrypointAccountAddress: info?.entrypointAccountAddress
|
52
|
+
entrypointAccountAddress: validateAndFormatAddress(info?.entrypointAccountAddress),
|
52
53
|
};
|
53
54
|
});
|
54
55
|
}
|
@@ -4,7 +4,7 @@ import { LIBRARY_TYPE, OperationStatusType, QuoteType } from "../enums.js";
|
|
4
4
|
import { LibraryRequest } from "../entities/library_request.js";
|
5
5
|
export declare class OperationActions extends LibraryRequest {
|
6
6
|
constructor(library: LIBRARY_TYPE, client?: any, provider?: any);
|
7
|
-
getOperationsToExecuteTransaction(accountClusterId: string,
|
7
|
+
getOperationsToExecuteTransaction(accountClusterId: string, data: string, to?: string, value?: bigint, gasToken?: {
|
8
8
|
standardizedTokenId: string;
|
9
9
|
tokenSources?: {
|
10
10
|
chainId: bigint;
|
@@ -18,15 +18,22 @@ export declare class OperationActions extends LibraryRequest {
|
|
18
18
|
address?: string;
|
19
19
|
}[];
|
20
20
|
}): Promise<OperationSet>;
|
21
|
+
getOperationsToSignTransactionOrSignTypedData(accountClusterId: string, data: string, to?: string, value?: bigint, gasToken?: {
|
22
|
+
standardizedTokenId: string;
|
23
|
+
tokenSources?: {
|
24
|
+
chainId: bigint;
|
25
|
+
address?: string;
|
26
|
+
}[];
|
27
|
+
}): Promise<OperationSet>;
|
21
28
|
getOperationsToCancelTransaction(accountClusterId: string, operationSetId: string): Promise<OperationSet>;
|
22
|
-
isTransactionPreconditionSatisfied(accountClusterId: string,
|
29
|
+
isTransactionPreconditionSatisfied(accountClusterId: string, data: string, to?: string, value?: bigint): Promise<boolean>;
|
23
30
|
isTypedDataPreconditionSatisfied(accountClusterId: string, data: string): Promise<boolean>;
|
24
31
|
sendSignedOperations(accountClusterId: string, signedOperations: SignedOperation[]): Promise<{
|
25
32
|
operationSetId: string;
|
26
33
|
operationResponses: OperationStatus[];
|
27
34
|
}>;
|
28
35
|
getOperationStatuses(operationIds: string[]): Promise<OperationStatus[]>;
|
29
|
-
estimateFiatCostToExecuteTransaction(
|
36
|
+
estimateFiatCostToExecuteTransaction(data: string, to?: string, value?: bigint): Promise<CurrencyAmount>;
|
30
37
|
estimateFiatCostToSignTypedData(data: string): Promise<CurrencyAmount>;
|
31
38
|
getOperationsToTransferToken(accountClusterId: string, standardizedTokenId: string, amount: bigint, recipient: {
|
32
39
|
chainId: bigint;
|
@@ -12,7 +12,7 @@ export class OperationActions extends LibraryRequest {
|
|
12
12
|
constructor(library, client, provider) {
|
13
13
|
super(library, client, provider);
|
14
14
|
}
|
15
|
-
async getOperationsToExecuteTransaction(accountClusterId,
|
15
|
+
async getOperationsToExecuteTransaction(accountClusterId, data, to, value, gasToken) {
|
16
16
|
const formattedGasToken = gasToken
|
17
17
|
? {
|
18
18
|
...gasToken,
|
@@ -43,7 +43,7 @@ export class OperationActions extends LibraryRequest {
|
|
43
43
|
})),
|
44
44
|
}
|
45
45
|
: undefined;
|
46
|
-
const operationSet = await this.sendRequest("
|
46
|
+
const operationSet = await this.sendRequest("orby_getOperationsForSignTransactionOrSignTypedData", [
|
47
47
|
{
|
48
48
|
accountClusterId,
|
49
49
|
data,
|
@@ -52,6 +52,27 @@ export class OperationActions extends LibraryRequest {
|
|
52
52
|
]);
|
53
53
|
return extractOperationSet(operationSet);
|
54
54
|
}
|
55
|
+
async getOperationsToSignTransactionOrSignTypedData(accountClusterId, data, to, value, gasToken) {
|
56
|
+
const formattedGasToken = gasToken
|
57
|
+
? {
|
58
|
+
...gasToken,
|
59
|
+
tokenSources: gasToken.tokenSources?.map(({ chainId, address }) => ({
|
60
|
+
chainId: getOrbyChainId(chainId),
|
61
|
+
address,
|
62
|
+
})),
|
63
|
+
}
|
64
|
+
: undefined;
|
65
|
+
const operationSet = await this.sendRequest("orby_getOperationsToSignTransactionOrSignTypedData", [
|
66
|
+
{
|
67
|
+
accountClusterId,
|
68
|
+
to,
|
69
|
+
data,
|
70
|
+
value,
|
71
|
+
gasToken: formattedGasToken,
|
72
|
+
},
|
73
|
+
]);
|
74
|
+
return extractOperationSet(operationSet);
|
75
|
+
}
|
55
76
|
async getOperationsToCancelTransaction(accountClusterId, operationSetId) {
|
56
77
|
const operationSet = await this.sendRequest("orby_getOperationsToCancelTransaction", [
|
57
78
|
{
|
@@ -61,7 +82,7 @@ export class OperationActions extends LibraryRequest {
|
|
61
82
|
]);
|
62
83
|
return extractOperationSet(operationSet);
|
63
84
|
}
|
64
|
-
async isTransactionPreconditionSatisfied(accountClusterId,
|
85
|
+
async isTransactionPreconditionSatisfied(accountClusterId, data, to, value) {
|
65
86
|
const { satisfied } = await this.sendRequest("orby_isTransactionPreconditionSatisfied", [
|
66
87
|
{
|
67
88
|
accountClusterId,
|
@@ -105,7 +126,7 @@ export class OperationActions extends LibraryRequest {
|
|
105
126
|
const { operationStatuses } = await this.sendRequest("orby_getOperationStatuses", [{ operationIds }]);
|
106
127
|
return extractOperationStatuses(operationStatuses);
|
107
128
|
}
|
108
|
-
async estimateFiatCostToExecuteTransaction(
|
129
|
+
async estimateFiatCostToExecuteTransaction(data, to, value) {
|
109
130
|
const { estimatedCost, code, message } = await this.sendRequest("orby_estimateFiatCostToExecuteTransaction", [
|
110
131
|
{
|
111
132
|
to,
|