@orb-labs/orby-core 0.0.31 → 0.0.34
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 +20 -0
- package/dist/cjs/actions/account_cluster.d.ts +2 -1
- package/dist/cjs/actions/account_cluster.js +8 -0
- package/dist/cjs/actions/operation.d.ts +22 -2
- package/dist/cjs/actions/operation.js +193 -7
- package/dist/cjs/actions/token.d.ts +1 -0
- package/dist/cjs/actions/token.js +11 -0
- package/dist/cjs/enums.d.ts +4 -0
- package/dist/cjs/enums.js +6 -1
- package/dist/cjs/interfaces/account_cluster.d.ts +2 -1
- package/dist/cjs/interfaces/operation.d.ts +22 -2
- package/dist/cjs/interfaces/token.d.ts +1 -0
- package/dist/cjs/types.d.ts +22 -2
- package/dist/cjs/utils/action_helpers.d.ts +7 -1
- package/dist/cjs/utils/action_helpers.js +62 -1
- package/dist/esm/actions/account_cluster.d.ts +2 -1
- package/dist/esm/actions/account_cluster.js +9 -1
- package/dist/esm/actions/operation.d.ts +22 -2
- package/dist/esm/actions/operation.js +194 -8
- package/dist/esm/actions/token.d.ts +1 -0
- package/dist/esm/actions/token.js +11 -0
- package/dist/esm/enums.d.ts +4 -0
- package/dist/esm/enums.js +5 -0
- package/dist/esm/interfaces/account_cluster.d.ts +2 -1
- package/dist/esm/interfaces/operation.d.ts +22 -2
- package/dist/esm/interfaces/token.d.ts +1 -0
- package/dist/esm/types.d.ts +22 -2
- package/dist/esm/utils/action_helpers.d.ts +7 -1
- package/dist/esm/utils/action_helpers.js +55 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Account } from "../entities/account.js";
|
|
2
|
-
import { AccountCluster, Activity, ChainEndpoint, FungibleTokenOverview, StandardizedBalance, VirtualNodeRpcUrlForSupportedChain } from "../types.js";
|
|
2
|
+
import { AccountCluster, Activity, ChainEndpoint, FungibleTokenOverview, StablecoinAutoDepositSettingsForAccount, StandardizedBalance, VirtualNodeRpcUrlForSupportedChain } from "../types.js";
|
|
3
3
|
import { ChainSupportStatus, LIBRARY_TYPE, Order } from "../enums.js";
|
|
4
4
|
import { LibraryRequest } from "../entities/library_request.js";
|
|
5
5
|
export declare class AccountClusterActions extends LibraryRequest {
|
|
@@ -29,4 +29,5 @@ export declare class AccountClusterActions extends LibraryRequest {
|
|
|
29
29
|
getPortfolioOverview(accountClusterId: string): Promise<FungibleTokenOverview>;
|
|
30
30
|
getFungibleTokenPortfolio(accountClusterId: string): Promise<StandardizedBalance[]>;
|
|
31
31
|
getFungibleTokenBalances(accountClusterId: string, offset?: number, limit?: number, chainId?: bigint, tokensToOmit?: string[], standardizedTokenIds?: string[]): Promise<StandardizedBalance[]>;
|
|
32
|
+
getStablecoinAutoDepositSettingsForAccount(accountClusterId: string, account?: Account): Promise<StablecoinAutoDepositSettingsForAccount[]>;
|
|
32
33
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { extractAccountCluster, extractActivities, extractFungibleTokenOverview, extractStandardizedBalances, } from "../utils/action_helpers.js";
|
|
1
|
+
import { extractAccountCluster, extractActivities, extractFungibleTokenOverview, extractStablecoinAutoDepositSettingsForAccount, extractStandardizedBalances, } from "../utils/action_helpers.js";
|
|
2
2
|
import { LibraryRequest } from "../entities/library_request.js";
|
|
3
3
|
import { getChainIdFromOrbyChainId } from "../utils/utils.js";
|
|
4
4
|
import { validateAndFormatAddress } from "../utils/validateAndParseAddress.js";
|
|
@@ -212,4 +212,12 @@ export class AccountClusterActions extends LibraryRequest {
|
|
|
212
212
|
}
|
|
213
213
|
return extractStandardizedBalances(fungibleTokenBalances);
|
|
214
214
|
}
|
|
215
|
+
async getStablecoinAutoDepositSettingsForAccount(accountClusterId, account) {
|
|
216
|
+
const { settings, message, code } = await this.sendRequest("orby_getStablecoinAutoDepositSettingsForAccount", [{ accountClusterId, account: account?.toAccountModel() }]);
|
|
217
|
+
if (code && message) {
|
|
218
|
+
console.error("[getStablecoinAutoDepositSettingsForAccountCluster]", code, message);
|
|
219
|
+
return undefined;
|
|
220
|
+
}
|
|
221
|
+
return extractStablecoinAutoDepositSettingsForAccount(settings);
|
|
222
|
+
}
|
|
215
223
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AccountCluster, Activity, OnchainOperation, OperationSet, OperationStatus, SignedOperation, UserOperation } from "../types.js";
|
|
1
|
+
import { AccountCluster, Activity, MiniProgram, OnchainOperation, OperationSet, OperationStatus, SignedOperation, UserOperation } from "../types.js";
|
|
2
2
|
import { CurrencyAmount } from "../entities/financial/currency_amount.js";
|
|
3
3
|
import { LIBRARY_TYPE, OperationStatusType, QuoteType } from "../enums.js";
|
|
4
4
|
import { LibraryRequest } from "../entities/library_request.js";
|
|
@@ -24,9 +24,24 @@ export declare class OperationActions extends LibraryRequest {
|
|
|
24
24
|
chainId: bigint;
|
|
25
25
|
address?: string;
|
|
26
26
|
}[];
|
|
27
|
+
}, options?: Map<string, any>): Promise<OperationSet>;
|
|
28
|
+
getOperationsForStablecoinAutoDepositSettings(accountClusterId: string, settings: {
|
|
29
|
+
userStablecoins: {
|
|
30
|
+
stablecoinAddress: string;
|
|
31
|
+
targetPercentage: number;
|
|
32
|
+
}[];
|
|
33
|
+
chainId: bigint;
|
|
34
|
+
miniProgramHash: string;
|
|
35
|
+
miniProgram: MiniProgram;
|
|
36
|
+
}[], gasToken?: {
|
|
37
|
+
standardizedTokenId: string;
|
|
38
|
+
tokenSources?: {
|
|
39
|
+
chainId: bigint;
|
|
40
|
+
address?: string;
|
|
41
|
+
}[];
|
|
27
42
|
}): Promise<OperationSet>;
|
|
28
43
|
getOperationsToCancelTransaction(accountClusterId: string, operationSetId: string): Promise<OperationSet>;
|
|
29
|
-
isTransactionPreconditionSatisfied(accountClusterId: string, data: string, to?: string, value?: bigint): Promise<boolean>;
|
|
44
|
+
isTransactionPreconditionSatisfied(accountClusterId: string, data: string, to?: string, value?: bigint, gasLimit?: bigint, maxFeePerGas?: bigint, maxPriorityFeePerGas?: bigint, gasPrice?: bigint): Promise<boolean>;
|
|
30
45
|
isTypedDataPreconditionSatisfied(accountClusterId: string, data: string): Promise<boolean>;
|
|
31
46
|
sendSignedOperations(accountClusterId: string, signedOperations: SignedOperation[]): Promise<{
|
|
32
47
|
operationSetId: string;
|
|
@@ -107,4 +122,9 @@ export declare class OperationActions extends LibraryRequest {
|
|
|
107
122
|
primaryOperationStatus?: OperationStatus;
|
|
108
123
|
operationResponses?: OperationStatus[];
|
|
109
124
|
}>;
|
|
125
|
+
sendOperationSetWithLocalOrchestration(accountCluster: AccountCluster, operationSet: OperationSet, sendTransaction?: (operation: OnchainOperation) => Promise<string | undefined>, sendUserOperation?: (operations: OnchainOperation[], accountAddress: string, chainId: bigint, txRpcUrl: string) => Promise<string | undefined>, signTypedData?: (operation: OnchainOperation) => Promise<string | undefined>, onCompletionCallback?: (operationStatuses?: {
|
|
126
|
+
operationId: string;
|
|
127
|
+
status: OperationStatusType;
|
|
128
|
+
operations: OnchainOperation[];
|
|
129
|
+
}[], statusSummary?: OperationStatusType) => void, onOperationSubmissionCallback?: (operationId: string, status: OperationStatusType, operations: OnchainOperation[]) => void, timeout?: number): Promise<void>;
|
|
110
130
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { extractActivity, extractOperationSet, extractOperationStatuses, } from "../utils/action_helpers.js";
|
|
2
2
|
import { CurrencyAmount } from "../entities/financial/currency_amount.js";
|
|
3
|
-
import { AccountType, ActivityStatus, OperationDataFormat, OperationStatusType, OperationType, } from "../enums.js";
|
|
3
|
+
import { AccountType, ActivityStatus, LIBRARY_TYPE, OperationDataFormat, OperationOrigin, OperationStatusType, OperationType, } from "../enums.js";
|
|
4
4
|
import { LibraryRequest } from "../entities/library_request.js";
|
|
5
5
|
import { Account } from "../entities/account.js";
|
|
6
|
+
import { createClient, http } from "viem";
|
|
7
|
+
import { ethers } from "ethers";
|
|
6
8
|
// from here: https://stackoverflow.com/questions/65152373/typescript-serialize-bigint-in-json
|
|
7
9
|
BigInt.prototype.toJSON = function () {
|
|
8
10
|
return this.toString();
|
|
@@ -33,7 +35,7 @@ export class OperationActions extends LibraryRequest {
|
|
|
33
35
|
]);
|
|
34
36
|
return extractOperationSet(operationSet);
|
|
35
37
|
}
|
|
36
|
-
async getOperationsToSignTransactionOrSignTypedData(accountClusterId, data, to, value, gasToken) {
|
|
38
|
+
async getOperationsToSignTransactionOrSignTypedData(accountClusterId, data, to, value, gasToken, options) {
|
|
37
39
|
const operationSet = await this.sendRequest("orby_getOperationsToSignTransactionOrSignTypedData", [
|
|
38
40
|
{
|
|
39
41
|
accountClusterId,
|
|
@@ -41,6 +43,21 @@ export class OperationActions extends LibraryRequest {
|
|
|
41
43
|
data,
|
|
42
44
|
value,
|
|
43
45
|
gasToken: await this.formatGasToken(gasToken),
|
|
46
|
+
options: options ? Object.fromEntries(options) : undefined,
|
|
47
|
+
},
|
|
48
|
+
]);
|
|
49
|
+
return extractOperationSet(operationSet);
|
|
50
|
+
}
|
|
51
|
+
async getOperationsForStablecoinAutoDepositSettings(accountClusterId, settings, gasToken) {
|
|
52
|
+
const formattedSettings = await Promise.all(settings.map(async (setting) => ({
|
|
53
|
+
...setting,
|
|
54
|
+
chainId: await this.getOrbyChainId(setting.chainId),
|
|
55
|
+
})));
|
|
56
|
+
const operationSet = await this.sendRequest("orby_getOperationsForStablecoinAutoDepositSettings", [
|
|
57
|
+
{
|
|
58
|
+
accountClusterId,
|
|
59
|
+
settings: formattedSettings,
|
|
60
|
+
gasToken: await this.formatGasToken(gasToken),
|
|
44
61
|
},
|
|
45
62
|
]);
|
|
46
63
|
return extractOperationSet(operationSet);
|
|
@@ -54,13 +71,17 @@ export class OperationActions extends LibraryRequest {
|
|
|
54
71
|
]);
|
|
55
72
|
return extractOperationSet(operationSet);
|
|
56
73
|
}
|
|
57
|
-
async isTransactionPreconditionSatisfied(accountClusterId, data, to, value) {
|
|
74
|
+
async isTransactionPreconditionSatisfied(accountClusterId, data, to, value, gasLimit, maxFeePerGas, maxPriorityFeePerGas, gasPrice) {
|
|
58
75
|
const { satisfied } = await this.sendRequest("orby_isTransactionPreconditionSatisfied", [
|
|
59
76
|
{
|
|
60
77
|
accountClusterId,
|
|
61
78
|
to,
|
|
62
79
|
data,
|
|
63
80
|
value,
|
|
81
|
+
gasLimit,
|
|
82
|
+
maxFeePerGas,
|
|
83
|
+
maxPriorityFeePerGas,
|
|
84
|
+
gasPrice,
|
|
64
85
|
},
|
|
65
86
|
]);
|
|
66
87
|
return satisfied;
|
|
@@ -82,7 +103,10 @@ export class OperationActions extends LibraryRequest {
|
|
|
82
103
|
const { operationSetId, operationResponses, code, message } = await this.sendRequest("orby_sendSignedOperations", [
|
|
83
104
|
{
|
|
84
105
|
accountClusterId,
|
|
85
|
-
signedOperations
|
|
106
|
+
signedOperations: await Promise.all(signedOperations.map(async (signedOperation) => ({
|
|
107
|
+
...signedOperation,
|
|
108
|
+
chainId: await this.getOrbyChainId(signedOperation.chainId),
|
|
109
|
+
}))),
|
|
86
110
|
},
|
|
87
111
|
]);
|
|
88
112
|
if (code && message) {
|
|
@@ -275,7 +299,10 @@ export class OperationActions extends LibraryRequest {
|
|
|
275
299
|
let intervalId = null;
|
|
276
300
|
let totalWaitTime = 0;
|
|
277
301
|
const timeoutOrDefault = timout ?? 300_000;
|
|
278
|
-
if (ids
|
|
302
|
+
if (!ids || ids?.length == 0) {
|
|
303
|
+
onOperationStatusesUpdateCallback?.(OperationStatusType.SUCCESSFUL, undefined, []);
|
|
304
|
+
}
|
|
305
|
+
else if (ids && ids?.length > 0) {
|
|
279
306
|
const waitTime = 500;
|
|
280
307
|
intervalId = setInterval(async () => {
|
|
281
308
|
let statusSummary = OperationStatusType.WAITING_PRECONDITION;
|
|
@@ -335,7 +362,8 @@ export class OperationActions extends LibraryRequest {
|
|
|
335
362
|
?.map((intent) => intent.intentOperations)
|
|
336
363
|
.flat()
|
|
337
364
|
?.concat(operationSet.primaryOperation)
|
|
338
|
-
.filter((value) => value != undefined && value != null)
|
|
365
|
+
.filter((value) => (value != undefined && value != null) ||
|
|
366
|
+
value?.origin == OperationOrigin.EXTERNAL);
|
|
339
367
|
if (operations?.length == 0) {
|
|
340
368
|
return { success: true, operationResponses: [] };
|
|
341
369
|
}
|
|
@@ -392,7 +420,7 @@ export class OperationActions extends LibraryRequest {
|
|
|
392
420
|
signature: signature,
|
|
393
421
|
data: operation.data,
|
|
394
422
|
from: operation.from,
|
|
395
|
-
chainId:
|
|
423
|
+
chainId: operation.chainId,
|
|
396
424
|
});
|
|
397
425
|
}
|
|
398
426
|
// batch sign all the smart contract transactions
|
|
@@ -422,7 +450,7 @@ export class OperationActions extends LibraryRequest {
|
|
|
422
450
|
signature: userOperation.signature,
|
|
423
451
|
data: JSON.stringify(userOperation),
|
|
424
452
|
from: transactions[0].from,
|
|
425
|
-
chainId:
|
|
453
|
+
chainId: transactions[0].chainId,
|
|
426
454
|
});
|
|
427
455
|
}
|
|
428
456
|
const { operationSetId, operationResponses } = await this.sendSignedOperations(accountCluster.accountClusterId, signedOperations);
|
|
@@ -436,4 +464,162 @@ export class OperationActions extends LibraryRequest {
|
|
|
436
464
|
},
|
|
437
465
|
};
|
|
438
466
|
}
|
|
467
|
+
async sendOperationSetWithLocalOrchestration(accountCluster, operationSet, sendTransaction, sendUserOperation, signTypedData, onCompletionCallback, onOperationSubmissionCallback, timeout) {
|
|
468
|
+
// 1. filter out all the operations that are not orby operations
|
|
469
|
+
const orbyOperations = operationSet.intents
|
|
470
|
+
?.map((intent) => intent.intentOperations)
|
|
471
|
+
.flat()
|
|
472
|
+
?.concat(operationSet.primaryOperation)
|
|
473
|
+
.filter((value) => (value != undefined && value != null) ||
|
|
474
|
+
value?.origin == OperationOrigin.EXTERNAL);
|
|
475
|
+
if (orbyOperations?.length == 0) {
|
|
476
|
+
onCompletionCallback?.([], OperationStatusType.SUCCESSFUL);
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
else if (!orbyOperations) {
|
|
480
|
+
onCompletionCallback?.([], OperationStatusType.FAILED);
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
// 2. group operations that can be sent in a single transaction together
|
|
484
|
+
const accountsMap = accountCluster.accounts.reduce((acc, account) => {
|
|
485
|
+
acc.set(account.key, account);
|
|
486
|
+
return acc;
|
|
487
|
+
}, new Map());
|
|
488
|
+
const smartAccountTransactions = orbyOperations.reduce((acc, operation) => {
|
|
489
|
+
const accountKey = Account.key(operation.from, operation.chainId);
|
|
490
|
+
const account = accountsMap.get(accountKey);
|
|
491
|
+
if (account?.type == AccountType.SCA &&
|
|
492
|
+
operation.format == OperationDataFormat.TRANSACTION) {
|
|
493
|
+
if (!acc.has(accountKey)) {
|
|
494
|
+
acc.set(accountKey, []);
|
|
495
|
+
}
|
|
496
|
+
acc.get(accountKey).push(operation);
|
|
497
|
+
}
|
|
498
|
+
return acc;
|
|
499
|
+
}, new Map());
|
|
500
|
+
const groupedOperations = [];
|
|
501
|
+
for (let i = 0; i < orbyOperations.length; i++) {
|
|
502
|
+
const operation = orbyOperations[i];
|
|
503
|
+
if (operation.format == OperationDataFormat.TRANSACTION) {
|
|
504
|
+
const accountKey = Account.key(operation.from, operation.chainId);
|
|
505
|
+
const account = accountsMap.get(accountKey);
|
|
506
|
+
if (account?.type == AccountType.SCA) {
|
|
507
|
+
continue;
|
|
508
|
+
}
|
|
509
|
+
else {
|
|
510
|
+
groupedOperations.push([operation]);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
else if (operation.format == OperationDataFormat.TYPED_DATA) {
|
|
514
|
+
groupedOperations.push([operation]);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
// 3. group the operations that can be sent in a single transaction together
|
|
518
|
+
for (const accountKey of smartAccountTransactions.keys()) {
|
|
519
|
+
const transactions = smartAccountTransactions.get(accountKey);
|
|
520
|
+
transactions.sort((operationA, _) => {
|
|
521
|
+
if (operationA.type == OperationType.APPROVE_ERC20_TOKEN) {
|
|
522
|
+
return -1;
|
|
523
|
+
}
|
|
524
|
+
return 0;
|
|
525
|
+
});
|
|
526
|
+
groupedOperations.push(transactions);
|
|
527
|
+
}
|
|
528
|
+
const timeoutOrDefault = timeout ?? 300_000;
|
|
529
|
+
const waitTime = 2000;
|
|
530
|
+
let intervalId = null;
|
|
531
|
+
let totalWaitTime = 0;
|
|
532
|
+
let isProcessing = false;
|
|
533
|
+
const hashedOperations = new Array(groupedOperations.length).fill(undefined);
|
|
534
|
+
// 3. send the operations in batches
|
|
535
|
+
intervalId = setInterval(async () => {
|
|
536
|
+
if (isProcessing) {
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
try {
|
|
540
|
+
isProcessing = true;
|
|
541
|
+
const promises = groupedOperations.map(async (operations, index) => {
|
|
542
|
+
if (hashedOperations[index]) {
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
const operation = operations[0];
|
|
546
|
+
// create a new operation actions client for each operation
|
|
547
|
+
let opsActions;
|
|
548
|
+
if (this.library == LIBRARY_TYPE.VIEM) {
|
|
549
|
+
opsActions = new OperationActions(LIBRARY_TYPE.VIEM, createClient({
|
|
550
|
+
transport: http(operation.txRpcUrl),
|
|
551
|
+
}), undefined);
|
|
552
|
+
}
|
|
553
|
+
else if (this.library == LIBRARY_TYPE.ETHERS) {
|
|
554
|
+
opsActions = new OperationActions(LIBRARY_TYPE.ETHERS, undefined, new ethers.providers.JsonRpcProvider(operation.txRpcUrl));
|
|
555
|
+
}
|
|
556
|
+
if (operation.format === OperationDataFormat.TRANSACTION) {
|
|
557
|
+
const isPreconditionSatisfied = await opsActions.isTransactionPreconditionSatisfied(accountCluster.accountClusterId, operation.data, operation.to, operation.value, operation.gasLimit, operation.maxFeePerGas, operation.maxPriorityFeePerGas, operation.gasPrice);
|
|
558
|
+
if (isPreconditionSatisfied) {
|
|
559
|
+
const accountKey = Account.key(operation.from, operation.chainId);
|
|
560
|
+
const account = accountsMap.get(accountKey);
|
|
561
|
+
if (account?.type == AccountType.SCA) {
|
|
562
|
+
const hash = await sendUserOperation?.(operations, operation.from, operation.chainId, operation.txRpcUrl);
|
|
563
|
+
onOperationSubmissionCallback?.(hash, OperationStatusType.PENDING, operations);
|
|
564
|
+
hashedOperations[index] = {
|
|
565
|
+
operationId: hash,
|
|
566
|
+
status: OperationStatusType.SUCCESSFUL,
|
|
567
|
+
operations,
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
else {
|
|
571
|
+
const hash = await sendTransaction?.(operation);
|
|
572
|
+
onOperationSubmissionCallback?.(hash, OperationStatusType.PENDING, operations);
|
|
573
|
+
hashedOperations[index] = {
|
|
574
|
+
operationId: hash,
|
|
575
|
+
status: OperationStatusType.SUCCESSFUL,
|
|
576
|
+
operations,
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
else if (operation.format === OperationDataFormat.TYPED_DATA) {
|
|
582
|
+
const isPreconditionSatisfied = await opsActions.isTypedDataPreconditionSatisfied(accountCluster.accountClusterId, operation.data);
|
|
583
|
+
if (isPreconditionSatisfied) {
|
|
584
|
+
const signature = await signTypedData?.(operation);
|
|
585
|
+
const sendOperation = await opsActions.sendSignedOperations(accountCluster.accountClusterId, [
|
|
586
|
+
{
|
|
587
|
+
type: operation.type,
|
|
588
|
+
signature,
|
|
589
|
+
data: operation.data,
|
|
590
|
+
from: operation.from,
|
|
591
|
+
chainId: operation.chainId,
|
|
592
|
+
},
|
|
593
|
+
]);
|
|
594
|
+
onOperationSubmissionCallback?.(sendOperation.operationResponses[0].hash, OperationStatusType.SUCCESSFUL, operations);
|
|
595
|
+
hashedOperations[index] = {
|
|
596
|
+
operationId: sendOperation.operationResponses[0].hash,
|
|
597
|
+
status: OperationStatusType.SUCCESSFUL,
|
|
598
|
+
operations,
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
await Promise.all(promises);
|
|
604
|
+
if (hashedOperations.every((result) => result)) {
|
|
605
|
+
onCompletionCallback?.(hashedOperations, OperationStatusType.SUCCESSFUL);
|
|
606
|
+
clearInterval(intervalId);
|
|
607
|
+
intervalId = null;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
catch (error) {
|
|
611
|
+
console.error("[sendOperationSetWithLocalOrchestration]", error);
|
|
612
|
+
}
|
|
613
|
+
finally {
|
|
614
|
+
isProcessing = false; // Reset processing flag
|
|
615
|
+
totalWaitTime += waitTime;
|
|
616
|
+
if (intervalId && totalWaitTime >= timeoutOrDefault) {
|
|
617
|
+
onCompletionCallback?.(hashedOperations, OperationStatusType.WAITING_PRECONDITION);
|
|
618
|
+
// we cant wait for more than 2 ETH blocks
|
|
619
|
+
clearInterval(intervalId);
|
|
620
|
+
intervalId = null;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
}, waitTime);
|
|
624
|
+
}
|
|
439
625
|
}
|
|
@@ -12,4 +12,5 @@ export declare class TokenActions extends LibraryRequest {
|
|
|
12
12
|
chainId: bigint;
|
|
13
13
|
}[]): Promise<StandardizedToken[]>;
|
|
14
14
|
getFungibleTokenData(standardizedTokenIds: string[]): Promise<StandardizedToken[]>;
|
|
15
|
+
listAbstractableStablecoins(chainId?: bigint): Promise<StandardizedToken[]>;
|
|
15
16
|
}
|
|
@@ -44,4 +44,15 @@ export class TokenActions extends LibraryRequest {
|
|
|
44
44
|
}
|
|
45
45
|
return extractStandardizedTokens(data);
|
|
46
46
|
}
|
|
47
|
+
async listAbstractableStablecoins(chainId) {
|
|
48
|
+
const orbyChainId = chainId
|
|
49
|
+
? await this.getOrbyChainId(chainId)
|
|
50
|
+
: undefined;
|
|
51
|
+
const { stablecoins, message, code } = await this.sendRequest("orby_listAbstractableStablecoins", [{ chainId: orbyChainId }]);
|
|
52
|
+
if (code && message) {
|
|
53
|
+
console.error("[listAbstractableStablecoins]", code, message);
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
return extractStandardizedTokens(stablecoins);
|
|
57
|
+
}
|
|
47
58
|
}
|
package/dist/esm/enums.d.ts
CHANGED
|
@@ -29,6 +29,10 @@ export declare enum OperationDataFormat {
|
|
|
29
29
|
TRANSACTION = "TRANSACTION",
|
|
30
30
|
TYPED_DATA = "TYPED_DATA"
|
|
31
31
|
}
|
|
32
|
+
export declare enum OperationOrigin {
|
|
33
|
+
EXTERNAL = "external",
|
|
34
|
+
ORBY = "orby"
|
|
35
|
+
}
|
|
32
36
|
export declare enum OperationType {
|
|
33
37
|
APPROVE_ERC20_TOKEN = "APPROVE_ERC20_TOKEN",
|
|
34
38
|
CANCEL_OPERATION = "CANCEL_OPERATION",
|
package/dist/esm/enums.js
CHANGED
|
@@ -35,6 +35,11 @@ export var OperationDataFormat;
|
|
|
35
35
|
OperationDataFormat["TRANSACTION"] = "TRANSACTION";
|
|
36
36
|
OperationDataFormat["TYPED_DATA"] = "TYPED_DATA";
|
|
37
37
|
})(OperationDataFormat || (OperationDataFormat = {}));
|
|
38
|
+
export var OperationOrigin;
|
|
39
|
+
(function (OperationOrigin) {
|
|
40
|
+
OperationOrigin["EXTERNAL"] = "external";
|
|
41
|
+
OperationOrigin["ORBY"] = "orby";
|
|
42
|
+
})(OperationOrigin || (OperationOrigin = {}));
|
|
38
43
|
export var OperationType;
|
|
39
44
|
(function (OperationType) {
|
|
40
45
|
OperationType["APPROVE_ERC20_TOKEN"] = "APPROVE_ERC20_TOKEN";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Account } from "../entities/account.js";
|
|
2
|
-
import { AccountCluster, Activity, ChainEndpoint, FungibleTokenOverview, StandardizedBalance, VirtualNodeRpcUrlForSupportedChain } from "../types.js";
|
|
2
|
+
import { AccountCluster, Activity, ChainEndpoint, FungibleTokenOverview, StablecoinAutoDepositSettingsForAccount, StandardizedBalance, VirtualNodeRpcUrlForSupportedChain } from "../types.js";
|
|
3
3
|
import { ChainSupportStatus, Order } from "../enums.js";
|
|
4
4
|
export interface IAccountClusterActions {
|
|
5
5
|
createAccountCluster(accounts: Account[]): Promise<AccountCluster>;
|
|
@@ -27,4 +27,5 @@ export interface IAccountClusterActions {
|
|
|
27
27
|
getPortfolioOverview(accountClusterId: string): Promise<FungibleTokenOverview>;
|
|
28
28
|
getFungibleTokenPortfolio(accountClusterId: string): Promise<StandardizedBalance[]>;
|
|
29
29
|
getFungibleTokenBalances(accountClusterId: string, offset?: number, limit?: number, chainId?: bigint, tokensToOmit?: string[], standardizedTokenIds?: string[]): Promise<StandardizedBalance[]>;
|
|
30
|
+
getStablecoinAutoDepositSettingsForAccount(accountClusterId: string, account?: Account): Promise<StablecoinAutoDepositSettingsForAccount[]>;
|
|
30
31
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AccountCluster, Activity, OnchainOperation, OperationSet, OperationStatus, SignedOperation, UserOperation } from "../types.js";
|
|
1
|
+
import { AccountCluster, Activity, MiniProgram, OnchainOperation, OperationSet, OperationStatus, SignedOperation, UserOperation } from "../types.js";
|
|
2
2
|
import { CurrencyAmount } from "../entities/financial/currency_amount.js";
|
|
3
3
|
import { OperationStatusType, QuoteType } from "../enums.js";
|
|
4
4
|
export interface IOperationActions {
|
|
@@ -22,9 +22,24 @@ export interface IOperationActions {
|
|
|
22
22
|
chainId: bigint;
|
|
23
23
|
address?: string;
|
|
24
24
|
}[];
|
|
25
|
+
}, options?: Map<string, any>): Promise<OperationSet>;
|
|
26
|
+
getOperationsForStablecoinAutoDepositSettings(accountClusterId: string, settings: {
|
|
27
|
+
userStablecoins: {
|
|
28
|
+
stablecoinAddress: string;
|
|
29
|
+
targetPercentage: number;
|
|
30
|
+
}[];
|
|
31
|
+
chainId: bigint;
|
|
32
|
+
miniProgramHash: string;
|
|
33
|
+
miniProgram: MiniProgram;
|
|
34
|
+
}[], gasToken?: {
|
|
35
|
+
standardizedTokenId: string;
|
|
36
|
+
tokenSources?: {
|
|
37
|
+
chainId: bigint;
|
|
38
|
+
address?: string;
|
|
39
|
+
}[];
|
|
25
40
|
}): Promise<OperationSet>;
|
|
26
41
|
getOperationsToCancelTransaction(accountClusterId: string, operationSetId: string): Promise<OperationSet>;
|
|
27
|
-
isTransactionPreconditionSatisfied(accountClusterId: string, data: string, to?: string, value?: bigint): Promise<boolean>;
|
|
42
|
+
isTransactionPreconditionSatisfied(accountClusterId: string, data: string, to?: string, value?: bigint, gasLimit?: bigint, maxFeePerGas?: bigint, maxPriorityFeePerGas?: bigint, gasPrice?: bigint): Promise<boolean>;
|
|
28
43
|
isTypedDataPreconditionSatisfied(accountClusterId: string, data: string): Promise<boolean>;
|
|
29
44
|
sendSignedOperations(accountClusterId: string, signedOperations: SignedOperation[]): Promise<{
|
|
30
45
|
operationSetId: string;
|
|
@@ -105,4 +120,9 @@ export interface IOperationActions {
|
|
|
105
120
|
primaryOperationStatus?: OperationStatus;
|
|
106
121
|
operationResponses?: OperationStatus[];
|
|
107
122
|
}>;
|
|
123
|
+
sendOperationSetWithLocalOrchestration(accountCluster: AccountCluster, operationSet: OperationSet, sendTransaction?: (operation: OnchainOperation) => Promise<string | undefined>, sendUserOperation?: (operations: OnchainOperation[], accountAddress: string, chainId: bigint, txRpcUrl: string) => Promise<string | undefined>, signTypedData?: (operation: OnchainOperation) => Promise<string | undefined>, onCompletionCallback?: (operationStatuses?: {
|
|
124
|
+
operationId: string;
|
|
125
|
+
status: OperationStatusType;
|
|
126
|
+
operations: OnchainOperation[];
|
|
127
|
+
}[], statusSummary?: OperationStatusType) => void, onOperationSubmissionCallback?: (operationId: string, status: OperationStatusType, operations: OnchainOperation[]) => void, timeout?: number): Promise<void>;
|
|
108
128
|
}
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -4,10 +4,11 @@ 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, VMType } from "./enums.js";
|
|
7
|
+
import { ActivityStatus, BlockchainEnvironment, Category, CreateOperationsStatus, OperationDataFormat, OperationOrigin, OperationStatusType, OperationType, TimeIntervalUnits, TokenAllowlistType, VMType } from "./enums.js";
|
|
8
8
|
export type AccountCluster = {
|
|
9
9
|
accountClusterId: string;
|
|
10
10
|
accounts: Account[];
|
|
11
|
+
isChainAbstractionEnabled: boolean;
|
|
11
12
|
};
|
|
12
13
|
export type ChainEndpoint = {
|
|
13
14
|
chainId: bigint;
|
|
@@ -70,6 +71,7 @@ export interface OnchainOperation {
|
|
|
70
71
|
txRpcUrl: string;
|
|
71
72
|
type: OperationType;
|
|
72
73
|
value?: bigint;
|
|
74
|
+
origin: OperationOrigin;
|
|
73
75
|
}
|
|
74
76
|
export type SignedOperation = {
|
|
75
77
|
type: OperationType;
|
|
@@ -77,7 +79,7 @@ export type SignedOperation = {
|
|
|
77
79
|
category?: Category;
|
|
78
80
|
data?: string;
|
|
79
81
|
from?: string;
|
|
80
|
-
chainId?:
|
|
82
|
+
chainId?: bigint;
|
|
81
83
|
};
|
|
82
84
|
export type OperationStatus = {
|
|
83
85
|
blockHash?: string;
|
|
@@ -171,3 +173,21 @@ export type VirtualNodeRpcUrlForSupportedChain = {
|
|
|
171
173
|
entrypointAccountAddress: string;
|
|
172
174
|
virtualNodeRpcUrl: string;
|
|
173
175
|
};
|
|
176
|
+
export type MiniProgram = {
|
|
177
|
+
verificationContract: string;
|
|
178
|
+
miniProgram: string;
|
|
179
|
+
};
|
|
180
|
+
export type StablecoinAutoDepositProportion = {
|
|
181
|
+
token: FungibleToken;
|
|
182
|
+
targetPercentage: number;
|
|
183
|
+
};
|
|
184
|
+
export type StablecoinAutoDepositPerChainUserStablecoinsSettings = {
|
|
185
|
+
userStablecoins: StablecoinAutoDepositProportion[];
|
|
186
|
+
chainId: bigint;
|
|
187
|
+
miniProgram: MiniProgram;
|
|
188
|
+
miniProgramHash: string;
|
|
189
|
+
};
|
|
190
|
+
export type StablecoinAutoDepositSettingsForAccount = {
|
|
191
|
+
account: Account;
|
|
192
|
+
settings: StablecoinAutoDepositPerChainUserStablecoinsSettings[];
|
|
193
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AccountCluster, Activity, AllowlistWithOpenFallback, BlockchainInformation, FungibleTokenOverview, GasSpendForInstance, GasSponsorshipData, GasSponsorshipPolicy, Intent, MaxAmountPerInterval, OnchainOperation, OperationSet, OperationStatus, StandardizedBalance, StandardizedToken } from "../types.js";
|
|
1
|
+
import { AccountCluster, Activity, AllowlistWithOpenFallback, BlockchainInformation, FungibleTokenOverview, GasSpendForInstance, GasSponsorshipData, GasSponsorshipPolicy, Intent, MaxAmountPerInterval, OnchainOperation, OperationSet, OperationStatus, StablecoinAutoDepositPerChainUserStablecoinsSettings, StablecoinAutoDepositProportion, StablecoinAutoDepositSettingsForAccount, StandardizedBalance, StandardizedToken } from "../types.js";
|
|
2
2
|
export declare const extractAccountCluster: (accountCluster?: any) => AccountCluster;
|
|
3
3
|
export declare const extractOperationSet: (operationSet?: any) => OperationSet;
|
|
4
4
|
export declare const extractOnchainOperation: (onchainOperation?: any) => OnchainOperation;
|
|
@@ -20,3 +20,9 @@ export declare const extractGasSpendForInstances: (gasSpendForInstances?: any[])
|
|
|
20
20
|
export declare const extractGasSpendForInstance: (gasSpendForInstance?: any) => GasSpendForInstance;
|
|
21
21
|
export declare const extractGasSponsorshipInformation: (gasSponsorshipData?: any[]) => GasSponsorshipData[];
|
|
22
22
|
export declare const extractGasSponsorshipData: (gasSponsorshipData?: any) => GasSponsorshipData;
|
|
23
|
+
export declare const extractStablecoinAutoDepositSettingsForAccount: (settings?: any[]) => StablecoinAutoDepositSettingsForAccount[];
|
|
24
|
+
export declare const extractStablecoinAutoDepositSettingsForAccountItem: (setting?: any) => StablecoinAutoDepositSettingsForAccount;
|
|
25
|
+
export declare const extractStablecoinAutoDepositPerChainUserStablecoinsSettings: (settings?: any[]) => StablecoinAutoDepositPerChainUserStablecoinsSettings[];
|
|
26
|
+
export declare const extractStablecoinAutoDepositPerChainUserStablecoinsSettingsItem: (setting?: any) => StablecoinAutoDepositPerChainUserStablecoinsSettings;
|
|
27
|
+
export declare const extractStablecoinAutoDepositProportions: (proportions?: any[]) => StablecoinAutoDepositProportion[];
|
|
28
|
+
export declare const extractStablecoinAutoDepositProportion: (proportion?: any) => StablecoinAutoDepositProportion;
|
|
@@ -16,6 +16,7 @@ export const extractAccountCluster = (accountCluster) => {
|
|
|
16
16
|
}
|
|
17
17
|
return {
|
|
18
18
|
accountClusterId: accountCluster?.accountClusterId,
|
|
19
|
+
isChainAbstractionEnabled: accountCluster?.isChainAbstractionEnabled,
|
|
19
20
|
accounts: accountCluster?.accounts?.map((account) => Account.toAccount(account)),
|
|
20
21
|
};
|
|
21
22
|
};
|
|
@@ -73,6 +74,7 @@ export const extractOnchainOperation = (onchainOperation) => {
|
|
|
73
74
|
txRpcUrl: onchainOperation.txRpcUrl,
|
|
74
75
|
type: onchainOperation.type,
|
|
75
76
|
value: onchainOperation.value ? BigInt(onchainOperation.value) : undefined,
|
|
77
|
+
origin: onchainOperation.origin,
|
|
76
78
|
};
|
|
77
79
|
};
|
|
78
80
|
export const extractIntent = (intent) => {
|
|
@@ -245,3 +247,56 @@ export const extractGasSponsorshipData = (gasSponsorshipData) => {
|
|
|
245
247
|
totalTransactionCount: gasSponsorshipData.totalTransactionCount,
|
|
246
248
|
};
|
|
247
249
|
};
|
|
250
|
+
export const extractStablecoinAutoDepositSettingsForAccount = (settings) => {
|
|
251
|
+
if (!settings) {
|
|
252
|
+
return undefined;
|
|
253
|
+
}
|
|
254
|
+
return settings
|
|
255
|
+
.map((setting) => extractStablecoinAutoDepositSettingsForAccountItem(setting))
|
|
256
|
+
.filter(notEmpty);
|
|
257
|
+
};
|
|
258
|
+
export const extractStablecoinAutoDepositSettingsForAccountItem = (setting) => {
|
|
259
|
+
if (!setting) {
|
|
260
|
+
return undefined;
|
|
261
|
+
}
|
|
262
|
+
return {
|
|
263
|
+
account: Account.toAccount(setting.account),
|
|
264
|
+
settings: extractStablecoinAutoDepositPerChainUserStablecoinsSettings(setting.settings),
|
|
265
|
+
};
|
|
266
|
+
};
|
|
267
|
+
export const extractStablecoinAutoDepositPerChainUserStablecoinsSettings = (settings) => {
|
|
268
|
+
if (!settings) {
|
|
269
|
+
return undefined;
|
|
270
|
+
}
|
|
271
|
+
return settings
|
|
272
|
+
.map((setting) => extractStablecoinAutoDepositPerChainUserStablecoinsSettingsItem(setting))
|
|
273
|
+
.filter(notEmpty);
|
|
274
|
+
};
|
|
275
|
+
export const extractStablecoinAutoDepositPerChainUserStablecoinsSettingsItem = (setting) => {
|
|
276
|
+
if (!setting) {
|
|
277
|
+
return undefined;
|
|
278
|
+
}
|
|
279
|
+
return {
|
|
280
|
+
userStablecoins: extractStablecoinAutoDepositProportions(setting.userStablecoins),
|
|
281
|
+
chainId: getChainIdFromOrbyChainId(setting.chainId),
|
|
282
|
+
miniProgram: setting.miniProgram,
|
|
283
|
+
miniProgramHash: setting.miniProgramHash,
|
|
284
|
+
};
|
|
285
|
+
};
|
|
286
|
+
export const extractStablecoinAutoDepositProportions = (proportions) => {
|
|
287
|
+
if (!proportions) {
|
|
288
|
+
return undefined;
|
|
289
|
+
}
|
|
290
|
+
return proportions
|
|
291
|
+
.map((proportion) => extractStablecoinAutoDepositProportion(proportion))
|
|
292
|
+
.filter(notEmpty);
|
|
293
|
+
};
|
|
294
|
+
export const extractStablecoinAutoDepositProportion = (proportion) => {
|
|
295
|
+
if (!proportion) {
|
|
296
|
+
return undefined;
|
|
297
|
+
}
|
|
298
|
+
return {
|
|
299
|
+
token: FungibleToken.toFungibleToken(proportion.token),
|
|
300
|
+
targetPercentage: proportion.targetPercentage,
|
|
301
|
+
};
|
|
302
|
+
};
|