@orb-labs/orby-core 0.0.15 → 0.0.16
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 +5 -0
- package/dist/cjs/actions/operation.d.ts +2 -2
- package/dist/cjs/actions/operation.js +74 -4
- package/dist/cjs/entities/account.js +1 -1
- package/dist/cjs/interfaces/operation.d.ts +2 -2
- package/dist/cjs/types.d.ts +20 -0
- package/dist/esm/actions/operation.d.ts +2 -2
- package/dist/esm/actions/operation.js +75 -5
- package/dist/esm/actions/token.js +1 -1
- package/dist/esm/entities/account.js +1 -1
- package/dist/esm/interfaces/operation.d.ts +2 -2
- package/dist/esm/types.d.ts +20 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/actions/account_cluster.d.ts +0 -32
- package/dist/actions/account_cluster.js +0 -207
- package/dist/actions/admin.d.ts +0 -17
- package/dist/actions/admin.js +0 -39
- package/dist/actions/application.d.ts +0 -6
- package/dist/actions/application.js +0 -16
- package/dist/actions/blockchain.d.ts +0 -16
- package/dist/actions/blockchain.js +0 -35
- package/dist/actions/instance.d.ts +0 -15
- package/dist/actions/instance.js +0 -94
- package/dist/actions/operation.d.ts +0 -99
- package/dist/actions/operation.js +0 -341
- package/dist/actions/token.d.ts +0 -15
- package/dist/actions/token.js +0 -46
- package/dist/constants.d.ts +0 -14
- package/dist/constants.js +0 -133
- package/dist/entities/account.d.ts +0 -14
- package/dist/entities/account.js +0 -45
- package/dist/entities/financial/account_balance.d.ts +0 -12
- package/dist/entities/financial/account_balance.js +0 -31
- package/dist/entities/financial/asset.d.ts +0 -31
- package/dist/entities/financial/asset.js +0 -38
- package/dist/entities/financial/currency.d.ts +0 -41
- package/dist/entities/financial/currency.js +0 -49
- package/dist/entities/financial/currency_amount.d.ts +0 -34
- package/dist/entities/financial/currency_amount.js +0 -92
- package/dist/entities/financial/fungible_token.d.ts +0 -41
- package/dist/entities/financial/fungible_token.js +0 -64
- package/dist/entities/financial/fungible_token_amount.d.ts +0 -36
- package/dist/entities/financial/fungible_token_amount.js +0 -95
- package/dist/entities/financial/non_fungible_token.d.ts +0 -39
- package/dist/entities/financial/non_fungible_token.js +0 -61
- package/dist/entities/financial/semi_fungible_token.d.ts +0 -41
- package/dist/entities/financial/semi_fungible_token.js +0 -63
- package/dist/entities/library_request.d.ts +0 -8
- package/dist/entities/library_request.js +0 -30
- package/dist/entities/state.d.ts +0 -22
- package/dist/entities/state.js +0 -102
- package/dist/enums.d.ts +0 -116
- package/dist/enums.js +0 -135
- package/dist/index.d.ts +0 -29
- package/dist/index.js +0 -33
- package/dist/interfaces/account_cluster.d.ts +0 -30
- package/dist/interfaces/account_cluster.js +0 -1
- package/dist/interfaces/admin.d.ts +0 -14
- package/dist/interfaces/admin.js +0 -1
- package/dist/interfaces/application.d.ts +0 -3
- package/dist/interfaces/application.js +0 -1
- package/dist/interfaces/blockchain.d.ts +0 -13
- package/dist/interfaces/blockchain.js +0 -1
- package/dist/interfaces/instance.d.ts +0 -12
- package/dist/interfaces/instance.js +0 -1
- package/dist/interfaces/operation.d.ts +0 -97
- package/dist/interfaces/operation.js +0 -1
- package/dist/interfaces/orby.d.ts +0 -9
- package/dist/interfaces/orby.js +0 -1
- package/dist/interfaces/token.d.ts +0 -12
- package/dist/interfaces/token.js +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/types.d.ts +0 -152
- package/dist/types.js +0 -1
- package/dist/utils/action_helpers.d.ts +0 -22
- package/dist/utils/action_helpers.js +0 -250
- package/dist/utils/utils.d.ts +0 -10
- package/dist/utils/utils.js +0 -70
- package/dist/utils/validateAndParseAddress.d.ts +0 -10
- package/dist/utils/validateAndParseAddress.js +0 -25
package/dist/actions/admin.js
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
import { extractGasSpendForInstances, extractGasSponsorshipData, } from "../utils/action_helpers.js";
|
2
|
-
import { LibraryRequest } from "../entities/library_request.js";
|
3
|
-
export class AdminActions extends LibraryRequest {
|
4
|
-
constructor(library, client, provider) {
|
5
|
-
super(library, client, provider);
|
6
|
-
}
|
7
|
-
async createInstance(name) {
|
8
|
-
const result = await this.sendRequest("orby_createInstance", [{ name }]);
|
9
|
-
if (result.code && result.message) {
|
10
|
-
console.error("[createInstance]", result.code, result.message);
|
11
|
-
return undefined;
|
12
|
-
}
|
13
|
-
return result;
|
14
|
-
}
|
15
|
-
async getInstanceUrls(name) {
|
16
|
-
const result = await this.sendRequest("orby_getInstanceUrls", [{ name }]);
|
17
|
-
if (result.code && result.message) {
|
18
|
-
console.error("[getInstanceUrls]", result.code, result.message);
|
19
|
-
return undefined;
|
20
|
-
}
|
21
|
-
return result;
|
22
|
-
}
|
23
|
-
async getGasSpentForCustomer(month, year) {
|
24
|
-
const { totalGasSpentForCustomer, code, message } = await this.sendRequest("orby_getGasSpentForCustomer", [{ month, year }]);
|
25
|
-
if (code && message) {
|
26
|
-
console.error("[getGasSpentForCustomer]", code, message);
|
27
|
-
return undefined;
|
28
|
-
}
|
29
|
-
return extractGasSponsorshipData(totalGasSpentForCustomer);
|
30
|
-
}
|
31
|
-
async getGasSpentForInstances(month, year, instanceNames) {
|
32
|
-
const { totalGasSpendForInstances, code, message } = await this.sendRequest("orby_getGasSpentForInstances", [{ month, year, instanceNames }]);
|
33
|
-
if (code && message) {
|
34
|
-
console.error("[getGasSpentForInstances]", code, message);
|
35
|
-
return undefined;
|
36
|
-
}
|
37
|
-
return extractGasSpendForInstances(totalGasSpendForInstances);
|
38
|
-
}
|
39
|
-
}
|
@@ -1,6 +0,0 @@
|
|
1
|
-
import { LibraryRequest } from "../entities/library_request.js";
|
2
|
-
import { LIBRARY_TYPE } from "../enums.js";
|
3
|
-
export declare class ApplicationActions extends LibraryRequest {
|
4
|
-
constructor(library: LIBRARY_TYPE, client?: any, provider?: any);
|
5
|
-
isChainAbstractionCompatible(appDomainUrl: string): Promise<boolean>;
|
6
|
-
}
|
@@ -1,16 +0,0 @@
|
|
1
|
-
import { LibraryRequest } from "../entities/library_request.js";
|
2
|
-
export class ApplicationActions extends LibraryRequest {
|
3
|
-
constructor(library, client, provider) {
|
4
|
-
super(library, client, provider);
|
5
|
-
}
|
6
|
-
async isChainAbstractionCompatible(appDomainUrl) {
|
7
|
-
const { isChainAbstractionCompatible, code, message } = await this.sendRequest("orby_isChainAbstractionCompatible", [
|
8
|
-
{ appDomainUrl },
|
9
|
-
]);
|
10
|
-
if (code && message) {
|
11
|
-
console.error("[isChainAbstractionCompatible]", code, message);
|
12
|
-
return undefined;
|
13
|
-
}
|
14
|
-
return isChainAbstractionCompatible;
|
15
|
-
}
|
16
|
-
}
|
@@ -1,16 +0,0 @@
|
|
1
|
-
import { BlockchainInformation } from "../types.js";
|
2
|
-
import { LibraryRequest } from "../entities/library_request.js";
|
3
|
-
import { LIBRARY_TYPE } from "../enums.js";
|
4
|
-
export declare class BlockchainActions extends LibraryRequest {
|
5
|
-
constructor(library: LIBRARY_TYPE, client?: any, provider?: any);
|
6
|
-
getBlockchainInformation(chainId: bigint): Promise<BlockchainInformation>;
|
7
|
-
listBlockchainsInformation(offset?: number, limit?: number): Promise<{
|
8
|
-
blockchains: BlockchainInformation[];
|
9
|
-
pageInfo: {
|
10
|
-
hasNextPage: boolean;
|
11
|
-
hasPreviousPage: boolean;
|
12
|
-
totalCount: number;
|
13
|
-
};
|
14
|
-
}>;
|
15
|
-
getChainsSupportedByDefault(): Promise<BlockchainInformation[]>;
|
16
|
-
}
|
@@ -1,35 +0,0 @@
|
|
1
|
-
import { extractBlockchainInformation, extractBlockchainInformations, } from "../utils/action_helpers.js";
|
2
|
-
import { LibraryRequest } from "../entities/library_request.js";
|
3
|
-
import { getOrbyChainId } from "../utils/utils.js";
|
4
|
-
export class BlockchainActions extends LibraryRequest {
|
5
|
-
constructor(library, client, provider) {
|
6
|
-
super(library, client, provider);
|
7
|
-
}
|
8
|
-
async getBlockchainInformation(chainId) {
|
9
|
-
const { blockchain, code, message } = await this.sendRequest("orby_getBlockchainInformation", [{ chainId: getOrbyChainId(chainId) }]);
|
10
|
-
if (code && message) {
|
11
|
-
console.error("[getBlockchainInformation]", code, message);
|
12
|
-
return undefined;
|
13
|
-
}
|
14
|
-
return extractBlockchainInformation(blockchain);
|
15
|
-
}
|
16
|
-
async listBlockchainsInformation(offset, limit) {
|
17
|
-
const { pageInfo, edges, code, message } = await this.sendRequest("orby_listBlockchainsInformation", [{ offset, limit }]);
|
18
|
-
if (code && message) {
|
19
|
-
console.error("[listBlockchainsInformation]", code, message);
|
20
|
-
return undefined;
|
21
|
-
}
|
22
|
-
return {
|
23
|
-
blockchains: extractBlockchainInformations(edges),
|
24
|
-
pageInfo,
|
25
|
-
};
|
26
|
-
}
|
27
|
-
async getChainsSupportedByDefault() {
|
28
|
-
const { blockchains, code, message } = await this.sendRequest("orby_getChainsSupportedByDefault", []);
|
29
|
-
if (code && message) {
|
30
|
-
console.error("[getChainsSupportedByDefault]", code, message);
|
31
|
-
return undefined;
|
32
|
-
}
|
33
|
-
return extractBlockchainInformations(blockchains);
|
34
|
-
}
|
35
|
-
}
|
@@ -1,15 +0,0 @@
|
|
1
|
-
import { ChainEndpoint, GasSponsorshipPolicy } from "../types.js";
|
2
|
-
import { LIBRARY_TYPE } from "../enums.js";
|
3
|
-
import { LibraryRequest } from "../entities/library_request.js";
|
4
|
-
export declare class InstanceActions extends LibraryRequest {
|
5
|
-
constructor(library: LIBRARY_TYPE, client?: any, provider?: any);
|
6
|
-
setCustomChainEndpointsForInstance(chainEndpoints: ChainEndpoint[]): Promise<boolean>;
|
7
|
-
removeCustomChainEndpointForInstance(chainIds: bigint[]): Promise<boolean>;
|
8
|
-
getCustomChainEndpointsForInstance(returnChainIdsOnly: boolean): Promise<boolean>;
|
9
|
-
enableChainAbstractionForInstance(enable: boolean): Promise<boolean>;
|
10
|
-
enableGasSponsorshipForInstance(enable: boolean): Promise<boolean>;
|
11
|
-
getGasSponsorForInstance(): Promise<string>;
|
12
|
-
getOrbyGasSponsorPolicyForInstance(): Promise<GasSponsorshipPolicy>;
|
13
|
-
setOrbyGasSponsorPolicyForInstance(gasSponsorshipPolicy: GasSponsorshipPolicy): Promise<boolean>;
|
14
|
-
removeOrbyGasSponsorPolicyForInstance(): Promise<boolean>;
|
15
|
-
}
|
package/dist/actions/instance.js
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
import { extractGasSponsorshipPolicy } from "../utils/action_helpers.js";
|
2
|
-
import { LibraryRequest } from "../entities/library_request.js";
|
3
|
-
import { getChainIdFromOrbyChainId, getOrbyChainId } from "../utils/utils.js";
|
4
|
-
export class InstanceActions extends LibraryRequest {
|
5
|
-
constructor(library, client, provider) {
|
6
|
-
super(library, client, provider);
|
7
|
-
}
|
8
|
-
async setCustomChainEndpointsForInstance(chainEndpoints) {
|
9
|
-
const formattedEndpoints = chainEndpoints.map((endpoint) => {
|
10
|
-
return {
|
11
|
-
chainId: getOrbyChainId(endpoint.chainId),
|
12
|
-
customRpcUrls: endpoint.customRpcUrls,
|
13
|
-
customIndexerUrls: endpoint.customIndexerUrls,
|
14
|
-
};
|
15
|
-
});
|
16
|
-
const { success, code, message } = await this.sendRequest("orby_setCustomChainEndpointsForInstance", [{ chainEndpoints: formattedEndpoints }]);
|
17
|
-
if (code && message) {
|
18
|
-
console.error("[setCustomChainEndpointsForInstance]", code, message);
|
19
|
-
return undefined;
|
20
|
-
}
|
21
|
-
return success;
|
22
|
-
}
|
23
|
-
async removeCustomChainEndpointForInstance(chainIds) {
|
24
|
-
const formattedChainIds = chainIds.map((chainId) => getOrbyChainId(chainId));
|
25
|
-
const { success, code, message } = await this.sendRequest("orby_removeCustomChainEndpointForInstance", [{ chainIds: formattedChainIds }]);
|
26
|
-
if (code && message) {
|
27
|
-
console.error("[removeCustomChainEndpointForInstance]", code, message);
|
28
|
-
return undefined;
|
29
|
-
}
|
30
|
-
return success;
|
31
|
-
}
|
32
|
-
async getCustomChainEndpointsForInstance(returnChainIdsOnly) {
|
33
|
-
const { chainEndpoints, code, message } = await this.sendRequest("orby_getCustomChainEndpointsForInstance", [{ returnChainIdsOnly }]);
|
34
|
-
if (code && message) {
|
35
|
-
console.error("[getCustomChainEndpointsForInstance]", code, message);
|
36
|
-
return undefined;
|
37
|
-
}
|
38
|
-
return chainEndpoints.map((endpoint) => {
|
39
|
-
return {
|
40
|
-
chainId: getChainIdFromOrbyChainId(endpoint.chainId),
|
41
|
-
customRpcUrls: endpoint.customRpcUrls,
|
42
|
-
customIndexerUrls: endpoint.customIndexerUrls,
|
43
|
-
};
|
44
|
-
});
|
45
|
-
}
|
46
|
-
async enableChainAbstractionForInstance(enable) {
|
47
|
-
const { success, code, message } = await this.sendRequest("orby_enableChainAbstractionForInstance", [{ enable }]);
|
48
|
-
if (code && message) {
|
49
|
-
console.error("[enableChainAbstractionForInstance]", code, message);
|
50
|
-
return undefined;
|
51
|
-
}
|
52
|
-
return success;
|
53
|
-
}
|
54
|
-
async enableGasSponsorshipForInstance(enable) {
|
55
|
-
const { success, code, message } = await this.sendRequest("orby_enableGasSponsorshipForInstance", [{ enable }]);
|
56
|
-
if (code && message) {
|
57
|
-
console.error("[enableGasSponsorshipForInstance]", code, message);
|
58
|
-
return undefined;
|
59
|
-
}
|
60
|
-
return success;
|
61
|
-
}
|
62
|
-
async getGasSponsorForInstance() {
|
63
|
-
const { gasSponsor, code, message } = await this.sendRequest("orby_getGasSponsorForInstance", []);
|
64
|
-
if (code && message) {
|
65
|
-
console.error("[getGasSponsorForInstance]", code, message);
|
66
|
-
return undefined;
|
67
|
-
}
|
68
|
-
return gasSponsor;
|
69
|
-
}
|
70
|
-
async getOrbyGasSponsorPolicyForInstance() {
|
71
|
-
const { gasSponsorshipPolicy, message, code } = await this.sendRequest("orby_getOrbyGasSponsorPolicyForInstance", []);
|
72
|
-
if (code && message) {
|
73
|
-
console.error("[getOrbyGasSponsorPolicyForInstance]", code, message);
|
74
|
-
return undefined;
|
75
|
-
}
|
76
|
-
return extractGasSponsorshipPolicy(gasSponsorshipPolicy);
|
77
|
-
}
|
78
|
-
async setOrbyGasSponsorPolicyForInstance(gasSponsorshipPolicy) {
|
79
|
-
const { success, code, message } = await this.sendRequest("orby_setOrbyGasSponsorPolicyForInstance", [{ ...gasSponsorshipPolicy }]);
|
80
|
-
if (code && message) {
|
81
|
-
console.error("[setOrbyGasSponsorPolicyForInstance]", code, message);
|
82
|
-
return undefined;
|
83
|
-
}
|
84
|
-
return success;
|
85
|
-
}
|
86
|
-
async removeOrbyGasSponsorPolicyForInstance() {
|
87
|
-
const { success, code, message } = await this.sendRequest("orby_removeOrbyGasSponsorPolicyForInstance", []);
|
88
|
-
if (code && message) {
|
89
|
-
console.error("[removeOrbyGasSponsorPolicyForInstance]", code, message);
|
90
|
-
return undefined;
|
91
|
-
}
|
92
|
-
return success;
|
93
|
-
}
|
94
|
-
}
|
@@ -1,99 +0,0 @@
|
|
1
|
-
import { OnchainOperation, OperationSet, OperationStatus, SignedOperation } from "../types.js";
|
2
|
-
import { CurrencyAmount } from "../entities/financial/currency_amount.js";
|
3
|
-
import { LIBRARY_TYPE, OperationStatusType, QuoteType } from "../enums.js";
|
4
|
-
import { LibraryRequest } from "../entities/library_request.js";
|
5
|
-
export declare class OperationActions extends LibraryRequest {
|
6
|
-
constructor(library: LIBRARY_TYPE, client?: any, provider?: any);
|
7
|
-
getOperationsToExecuteTransaction(accountClusterId: string, to: string, data: string, value?: bigint, gasToken?: {
|
8
|
-
standardizedTokenId: string;
|
9
|
-
tokenSources?: {
|
10
|
-
chainId: bigint;
|
11
|
-
address?: string;
|
12
|
-
}[];
|
13
|
-
}): Promise<OperationSet>;
|
14
|
-
getOperationsToSignTypedData(accountClusterId: string, data: string, gasToken?: {
|
15
|
-
standardizedTokenId: string;
|
16
|
-
tokenSources?: {
|
17
|
-
chainId: bigint;
|
18
|
-
address?: string;
|
19
|
-
}[];
|
20
|
-
}): Promise<OperationSet>;
|
21
|
-
getOperationsToCancelTransaction(accountClusterId: string, operationSetId: string): Promise<OperationSet>;
|
22
|
-
isTransactionPreconditionSatisfied(accountClusterId: string, to: string, data: string, value?: bigint): Promise<boolean>;
|
23
|
-
isTypedDataPreconditionSatisfied(accountClusterId: string, data: string): Promise<boolean>;
|
24
|
-
sendSignedOperations(accountClusterId: string, signedOperations: SignedOperation[]): Promise<{
|
25
|
-
operationSetId: string;
|
26
|
-
operationResponses: OperationStatus[];
|
27
|
-
}>;
|
28
|
-
getOperationStatuses(operationIds: string[]): Promise<OperationStatus[]>;
|
29
|
-
estimateFiatCostToExecuteTransaction(to: string, data: string, value?: bigint): Promise<CurrencyAmount>;
|
30
|
-
estimateFiatCostToSignTypedData(data: string): Promise<CurrencyAmount>;
|
31
|
-
getOperationsToTransferToken(accountClusterId: string, standardizedTokenId: string, amount: bigint, recipient: {
|
32
|
-
chainId: bigint;
|
33
|
-
recipientAddress: string;
|
34
|
-
}, gasToken?: {
|
35
|
-
standardizedTokenId: string;
|
36
|
-
tokenSources?: {
|
37
|
-
chainId: bigint;
|
38
|
-
address?: string;
|
39
|
-
}[];
|
40
|
-
}): Promise<OperationSet>;
|
41
|
-
getOperationsToSwap(accountClusterId: string, swapType: QuoteType, input: {
|
42
|
-
standardizedTokenId: string;
|
43
|
-
amount?: bigint;
|
44
|
-
tokenSources?: {
|
45
|
-
chainId: bigint;
|
46
|
-
address?: string;
|
47
|
-
}[];
|
48
|
-
}, output: {
|
49
|
-
standardizedTokenId: string;
|
50
|
-
amount?: bigint;
|
51
|
-
tokenDestination?: {
|
52
|
-
chainId: bigint;
|
53
|
-
address?: string;
|
54
|
-
};
|
55
|
-
}, gasToken?: {
|
56
|
-
standardizedTokenId: string;
|
57
|
-
tokenSources?: {
|
58
|
-
chainId: bigint;
|
59
|
-
address?: string;
|
60
|
-
}[];
|
61
|
-
}): Promise<OperationSet>;
|
62
|
-
getQuote(accountClusterId: string, swapType: QuoteType, input: {
|
63
|
-
standardizedTokenId: string;
|
64
|
-
amount?: bigint;
|
65
|
-
tokenSources?: {
|
66
|
-
chainId: bigint;
|
67
|
-
address?: string;
|
68
|
-
}[];
|
69
|
-
}, output: {
|
70
|
-
standardizedTokenId: string;
|
71
|
-
amount?: bigint;
|
72
|
-
tokenDestination?: {
|
73
|
-
chainId: bigint;
|
74
|
-
address?: string;
|
75
|
-
};
|
76
|
-
}): Promise<OperationSet>;
|
77
|
-
getOperationsToBridge(accountClusterId: string, standardizedTokenId: string, amount: bigint, tokenSources?: {
|
78
|
-
chainId: bigint;
|
79
|
-
address?: string;
|
80
|
-
}[], tokenDestination?: {
|
81
|
-
chainId: bigint;
|
82
|
-
address?: string;
|
83
|
-
}, gasToken?: {
|
84
|
-
standardizedTokenId: string;
|
85
|
-
tokenSources?: {
|
86
|
-
chainId: bigint;
|
87
|
-
address?: string;
|
88
|
-
}[];
|
89
|
-
}): Promise<OperationSet>;
|
90
|
-
subscribeToOperationStatuses(ids?: string[], onOperationStatusesUpdateCallback?: (statusSummary: OperationStatusType, primaryOperationStatus?: OperationStatus, allOperationStatuses?: OperationStatus[]) => void, timout?: number): {
|
91
|
-
intervalId: NodeJS.Timeout | null;
|
92
|
-
};
|
93
|
-
sendOperationSet(accountClusterId: string, operationSet: OperationSet, signOperation: (operation: OnchainOperation) => Promise<SignedOperation | undefined>): Promise<{
|
94
|
-
success: boolean;
|
95
|
-
operationSetId?: string;
|
96
|
-
primaryOperationStatus?: OperationStatus;
|
97
|
-
operationResponses?: OperationStatus[];
|
98
|
-
}>;
|
99
|
-
}
|
@@ -1,341 +0,0 @@
|
|
1
|
-
import { extractOperationSet, extractOperationStatuses, } from "../utils/action_helpers.js";
|
2
|
-
import { CurrencyAmount } from "../entities/financial/currency_amount.js";
|
3
|
-
import { OperationStatusType, OperationType, } from "../enums.js";
|
4
|
-
import { LibraryRequest } from "../entities/library_request.js";
|
5
|
-
import { getOrbyChainId } from "../utils/utils.js";
|
6
|
-
export class OperationActions extends LibraryRequest {
|
7
|
-
constructor(library, client, provider) {
|
8
|
-
super(library, client, provider);
|
9
|
-
}
|
10
|
-
async getOperationsToExecuteTransaction(accountClusterId, to, data, value, gasToken) {
|
11
|
-
const formattedGasToken = gasToken
|
12
|
-
? {
|
13
|
-
...gasToken,
|
14
|
-
tokenSources: gasToken.tokenSources?.map(({ chainId, address }) => ({
|
15
|
-
chainId: getOrbyChainId(chainId),
|
16
|
-
address,
|
17
|
-
})),
|
18
|
-
}
|
19
|
-
: undefined;
|
20
|
-
const operationSet = await this.sendRequest("orby_getOperationsToExecuteTransaction", [
|
21
|
-
{
|
22
|
-
accountClusterId,
|
23
|
-
to,
|
24
|
-
data,
|
25
|
-
value,
|
26
|
-
gasToken: formattedGasToken,
|
27
|
-
},
|
28
|
-
]);
|
29
|
-
return extractOperationSet(operationSet);
|
30
|
-
}
|
31
|
-
async getOperationsToSignTypedData(accountClusterId, data, gasToken) {
|
32
|
-
const formattedGasToken = gasToken
|
33
|
-
? {
|
34
|
-
...gasToken,
|
35
|
-
tokenSources: gasToken.tokenSources?.map(({ chainId, address }) => ({
|
36
|
-
chainId: getOrbyChainId(chainId),
|
37
|
-
address,
|
38
|
-
})),
|
39
|
-
}
|
40
|
-
: undefined;
|
41
|
-
const operationSet = await this.sendRequest("orby_getOperationsToSignTypedData", [
|
42
|
-
{
|
43
|
-
accountClusterId,
|
44
|
-
data,
|
45
|
-
gasToken: formattedGasToken,
|
46
|
-
},
|
47
|
-
]);
|
48
|
-
return extractOperationSet(operationSet);
|
49
|
-
}
|
50
|
-
async getOperationsToCancelTransaction(accountClusterId, operationSetId) {
|
51
|
-
const operationSet = await this.sendRequest("orby_getOperationsToCancelTransaction", [
|
52
|
-
{
|
53
|
-
accountClusterId,
|
54
|
-
operationSetId,
|
55
|
-
},
|
56
|
-
]);
|
57
|
-
return extractOperationSet(operationSet);
|
58
|
-
}
|
59
|
-
async isTransactionPreconditionSatisfied(accountClusterId, to, data, value) {
|
60
|
-
const { satisfied } = await this.sendRequest("orby_isTransactionPreconditionSatisfied", [
|
61
|
-
{
|
62
|
-
accountClusterId,
|
63
|
-
to,
|
64
|
-
data,
|
65
|
-
value,
|
66
|
-
},
|
67
|
-
]);
|
68
|
-
return satisfied;
|
69
|
-
}
|
70
|
-
async isTypedDataPreconditionSatisfied(accountClusterId, data) {
|
71
|
-
const { satisfied, code, message } = await this.sendRequest("orby_isTypedDataPreconditionSatisfied", [
|
72
|
-
{
|
73
|
-
accountClusterId,
|
74
|
-
data,
|
75
|
-
},
|
76
|
-
]);
|
77
|
-
if (code && message) {
|
78
|
-
console.error("[isTypedDataPreconditionSatisfied]", code, message);
|
79
|
-
return undefined;
|
80
|
-
}
|
81
|
-
return satisfied;
|
82
|
-
}
|
83
|
-
async sendSignedOperations(accountClusterId, signedOperations) {
|
84
|
-
const { operationSetId, operationResponses, code, message } = await this.sendRequest("orby_sendSignedOperations", [
|
85
|
-
{
|
86
|
-
accountClusterId,
|
87
|
-
signedOperations,
|
88
|
-
},
|
89
|
-
]);
|
90
|
-
if (code && message) {
|
91
|
-
console.error("[sendSignedOperations]", code, message);
|
92
|
-
return undefined;
|
93
|
-
}
|
94
|
-
return {
|
95
|
-
operationSetId,
|
96
|
-
operationResponses: extractOperationStatuses(operationResponses),
|
97
|
-
};
|
98
|
-
}
|
99
|
-
async getOperationStatuses(operationIds) {
|
100
|
-
const { operationStatuses } = await this.sendRequest("orby_getOperationStatuses", [{ operationIds }]);
|
101
|
-
return extractOperationStatuses(operationStatuses);
|
102
|
-
}
|
103
|
-
async estimateFiatCostToExecuteTransaction(to, data, value) {
|
104
|
-
const { estimatedCost, code, message } = await this.sendRequest("orby_estimateFiatCostToExecuteTransaction", [
|
105
|
-
{
|
106
|
-
to,
|
107
|
-
data,
|
108
|
-
value,
|
109
|
-
},
|
110
|
-
]);
|
111
|
-
if (code && message) {
|
112
|
-
console.error("[estimateFiatCostToExecuteTransaction]", code, message);
|
113
|
-
return undefined;
|
114
|
-
}
|
115
|
-
return CurrencyAmount.toCurrencyAmount(estimatedCost);
|
116
|
-
}
|
117
|
-
async estimateFiatCostToSignTypedData(data) {
|
118
|
-
const { estimatedCost, code, message } = await this.sendRequest("orby_estimateFiatCostToSignTypedData", [{ data }]);
|
119
|
-
if (code && message) {
|
120
|
-
console.error("[estimateFiatCostToSignTypedData]", code, message);
|
121
|
-
return undefined;
|
122
|
-
}
|
123
|
-
return CurrencyAmount.toCurrencyAmount(estimatedCost);
|
124
|
-
}
|
125
|
-
async getOperationsToTransferToken(accountClusterId, standardizedTokenId, amount, recipient, gasToken) {
|
126
|
-
const formattedGasToken = gasToken
|
127
|
-
? {
|
128
|
-
...gasToken,
|
129
|
-
tokenSources: gasToken.tokenSources?.map(({ chainId, address }) => ({
|
130
|
-
chainId: getOrbyChainId(chainId),
|
131
|
-
address,
|
132
|
-
})),
|
133
|
-
}
|
134
|
-
: undefined;
|
135
|
-
const formattedRecepient = {
|
136
|
-
chainId: getOrbyChainId(recipient.chainId),
|
137
|
-
recipientAddress: recipient.recipientAddress,
|
138
|
-
};
|
139
|
-
const operationSet = await this.sendRequest("orby_getOperationsToTransferToken", [
|
140
|
-
{
|
141
|
-
accountClusterId,
|
142
|
-
standardizedTokenId,
|
143
|
-
amount,
|
144
|
-
recipient: formattedRecepient,
|
145
|
-
gasToken: formattedGasToken,
|
146
|
-
},
|
147
|
-
]);
|
148
|
-
return extractOperationSet(operationSet);
|
149
|
-
}
|
150
|
-
async getOperationsToSwap(accountClusterId, swapType, input, output, gasToken) {
|
151
|
-
const formattedInput = input
|
152
|
-
? {
|
153
|
-
...input,
|
154
|
-
tokenSources: input?.tokenSources.map(({ chainId, address }) => ({
|
155
|
-
chainId: getOrbyChainId(chainId),
|
156
|
-
address,
|
157
|
-
})),
|
158
|
-
}
|
159
|
-
: undefined;
|
160
|
-
const formattedOutput = output
|
161
|
-
? {
|
162
|
-
...output,
|
163
|
-
tokenDestination: output?.tokenDestination
|
164
|
-
? {
|
165
|
-
chainId: getOrbyChainId(output.tokenDestination.chainId),
|
166
|
-
address: output.tokenDestination.address,
|
167
|
-
}
|
168
|
-
: undefined,
|
169
|
-
}
|
170
|
-
: undefined;
|
171
|
-
const formattedGasToken = gasToken
|
172
|
-
? {
|
173
|
-
...gasToken,
|
174
|
-
tokenSources: gasToken.tokenSources?.map(({ chainId, address }) => ({
|
175
|
-
chainId: getOrbyChainId(chainId),
|
176
|
-
address,
|
177
|
-
})),
|
178
|
-
}
|
179
|
-
: undefined;
|
180
|
-
const operationSet = await this.sendRequest("orby_getOperationsToSwap", [
|
181
|
-
{
|
182
|
-
accountClusterId,
|
183
|
-
swapType,
|
184
|
-
input: formattedInput,
|
185
|
-
output: formattedOutput,
|
186
|
-
gasToken: formattedGasToken,
|
187
|
-
},
|
188
|
-
]);
|
189
|
-
return extractOperationSet(operationSet);
|
190
|
-
}
|
191
|
-
async getQuote(accountClusterId, swapType, input, output) {
|
192
|
-
const formattedInput = input
|
193
|
-
? {
|
194
|
-
...input,
|
195
|
-
tokenSources: input?.tokenSources.map(({ chainId, address }) => ({
|
196
|
-
chainId: getOrbyChainId(chainId),
|
197
|
-
address,
|
198
|
-
})),
|
199
|
-
}
|
200
|
-
: undefined;
|
201
|
-
const formattedOutput = output
|
202
|
-
? {
|
203
|
-
...output,
|
204
|
-
tokenDestination: output?.tokenDestination
|
205
|
-
? {
|
206
|
-
chainId: getOrbyChainId(output.tokenDestination.chainId),
|
207
|
-
address: output.tokenDestination.address,
|
208
|
-
}
|
209
|
-
: undefined,
|
210
|
-
}
|
211
|
-
: undefined;
|
212
|
-
const operationSet = await this.sendRequest("orby_getQuote", [
|
213
|
-
{
|
214
|
-
accountClusterId,
|
215
|
-
swapType,
|
216
|
-
input: formattedInput,
|
217
|
-
output: formattedOutput,
|
218
|
-
},
|
219
|
-
]);
|
220
|
-
return extractOperationSet(operationSet);
|
221
|
-
}
|
222
|
-
async getOperationsToBridge(accountClusterId, standardizedTokenId, amount, tokenSources, tokenDestination, gasToken) {
|
223
|
-
const formattedTokenSources = tokenSources.map(({ chainId, address }) => ({
|
224
|
-
chainId: getOrbyChainId(chainId),
|
225
|
-
address,
|
226
|
-
}));
|
227
|
-
const formattedDestination = tokenDestination
|
228
|
-
? {
|
229
|
-
chainId: getOrbyChainId(tokenDestination.chainId),
|
230
|
-
address: tokenDestination.address,
|
231
|
-
}
|
232
|
-
: undefined;
|
233
|
-
const formattedGasToken = gasToken
|
234
|
-
? {
|
235
|
-
...gasToken,
|
236
|
-
tokenSources: gasToken.tokenSources?.map(({ chainId, address }) => ({
|
237
|
-
chainId: getOrbyChainId(chainId),
|
238
|
-
address,
|
239
|
-
})),
|
240
|
-
}
|
241
|
-
: undefined;
|
242
|
-
const operationSet = await this.sendRequest("orby_getOperationsToBridge", [
|
243
|
-
{
|
244
|
-
accountClusterId,
|
245
|
-
standardizedTokenId,
|
246
|
-
amount,
|
247
|
-
tokenSources: formattedTokenSources,
|
248
|
-
tokenDestination: formattedDestination,
|
249
|
-
gasToken: formattedGasToken,
|
250
|
-
},
|
251
|
-
]);
|
252
|
-
return extractOperationSet(operationSet);
|
253
|
-
}
|
254
|
-
subscribeToOperationStatuses(ids, onOperationStatusesUpdateCallback, timout) {
|
255
|
-
let intervalId = null;
|
256
|
-
let totalWaitTime = 0;
|
257
|
-
const timeoutOrDefault = timout ?? 300_000;
|
258
|
-
if (ids && ids?.length > 0) {
|
259
|
-
const waitTime = 500;
|
260
|
-
intervalId = setInterval(async () => {
|
261
|
-
let statusSummary = OperationStatusType.WAITING_PRECONDITION;
|
262
|
-
let primaryOperation;
|
263
|
-
try {
|
264
|
-
const statuses = ids && ids?.length > 0
|
265
|
-
? await this?.getOperationStatuses(ids)
|
266
|
-
: undefined;
|
267
|
-
if (!ids || ids?.length == 0) {
|
268
|
-
statusSummary = OperationStatusType.NOT_FOUND;
|
269
|
-
}
|
270
|
-
else if (!statuses) {
|
271
|
-
statusSummary = OperationStatusType.NOT_FOUND;
|
272
|
-
}
|
273
|
-
else if (statuses.some((status) => status.status == OperationStatusType.FAILED)) {
|
274
|
-
statusSummary = OperationStatusType.FAILED;
|
275
|
-
}
|
276
|
-
else if (statuses.every((status) => status.status == OperationStatusType.SUCCESSFUL)) {
|
277
|
-
statusSummary = OperationStatusType.SUCCESSFUL;
|
278
|
-
}
|
279
|
-
primaryOperation = statuses?.find((status) => status.type == OperationType.FINAL_TRANSACTION);
|
280
|
-
if (primaryOperation?.status == OperationStatusType.PENDING) {
|
281
|
-
statusSummary = OperationStatusType.PENDING;
|
282
|
-
}
|
283
|
-
onOperationStatusesUpdateCallback?.(statusSummary, primaryOperation, statuses);
|
284
|
-
}
|
285
|
-
catch (error) {
|
286
|
-
console.error("[useWaitForStatusCompletion]", error);
|
287
|
-
}
|
288
|
-
finally {
|
289
|
-
totalWaitTime += waitTime;
|
290
|
-
if (intervalId &&
|
291
|
-
OperationStatusType.WAITING_PRECONDITION != statusSummary) {
|
292
|
-
clearInterval(intervalId);
|
293
|
-
intervalId = null;
|
294
|
-
}
|
295
|
-
else if (intervalId && totalWaitTime >= timeoutOrDefault) {
|
296
|
-
// we cant wait for more than 2 ETH blocks
|
297
|
-
clearInterval(intervalId);
|
298
|
-
intervalId = null;
|
299
|
-
}
|
300
|
-
}
|
301
|
-
}, waitTime);
|
302
|
-
}
|
303
|
-
return { intervalId };
|
304
|
-
}
|
305
|
-
async sendOperationSet(accountClusterId, operationSet, signOperation) {
|
306
|
-
const signedOperations = [];
|
307
|
-
const operations = operationSet.intents
|
308
|
-
?.map((intent) => intent.intentOperations)
|
309
|
-
.flat()
|
310
|
-
?.concat(operationSet.primaryOperation)
|
311
|
-
.filter((value) => value != undefined && value != null);
|
312
|
-
if (operations?.length == 0) {
|
313
|
-
return { success: true, operationResponses: [] };
|
314
|
-
}
|
315
|
-
else if (!operations) {
|
316
|
-
return { success: false };
|
317
|
-
}
|
318
|
-
const hasPrimaryOperation = operations.find((operation) => operation.type == OperationType.FINAL_TRANSACTION);
|
319
|
-
if (!hasPrimaryOperation) {
|
320
|
-
return { success: false };
|
321
|
-
}
|
322
|
-
// Loop through all the operations and sign them
|
323
|
-
for (let i = 0; i < operations.length; i++) {
|
324
|
-
const signature = await signOperation(operations[i]);
|
325
|
-
if (!signature) {
|
326
|
-
return { success: false };
|
327
|
-
}
|
328
|
-
signedOperations.push(signature);
|
329
|
-
}
|
330
|
-
const { operationSetId, operationResponses } = await this.sendSignedOperations(accountClusterId, signedOperations);
|
331
|
-
return {
|
332
|
-
operationSetId,
|
333
|
-
operationResponses,
|
334
|
-
success: true,
|
335
|
-
primaryOperationStatus: {
|
336
|
-
type: OperationType.FINAL_TRANSACTION,
|
337
|
-
status: OperationStatusType.WAITING_PRECONDITION,
|
338
|
-
},
|
339
|
-
};
|
340
|
-
}
|
341
|
-
}
|