@orb-labs/orby-core 0.0.14 → 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 +9 -0
- package/dist/cjs/actions/account_cluster.js +211 -0
- package/dist/cjs/actions/admin.js +43 -0
- package/dist/cjs/actions/application.js +20 -0
- package/dist/cjs/actions/blockchain.js +39 -0
- package/dist/cjs/actions/instance.js +98 -0
- package/dist/{actions → cjs/actions}/operation.d.ts +2 -2
- package/dist/cjs/actions/operation.js +415 -0
- package/dist/cjs/actions/token.js +50 -0
- package/dist/cjs/constants.js +139 -0
- package/dist/cjs/entities/account.js +49 -0
- package/dist/cjs/entities/financial/account_balance.js +35 -0
- package/dist/cjs/entities/financial/asset.js +42 -0
- package/dist/cjs/entities/financial/currency.js +56 -0
- package/dist/cjs/entities/financial/currency_amount.js +99 -0
- package/dist/cjs/entities/financial/fungible_token.js +68 -0
- package/dist/cjs/entities/financial/fungible_token_amount.js +102 -0
- package/dist/cjs/entities/financial/non_fungible_token.js +65 -0
- package/dist/cjs/entities/financial/semi_fungible_token.js +67 -0
- package/dist/cjs/entities/library_request.js +37 -0
- package/dist/cjs/entities/state.js +106 -0
- package/dist/cjs/enums.js +138 -0
- package/dist/cjs/index.js +49 -0
- package/dist/cjs/interfaces/account_cluster.js +2 -0
- package/dist/cjs/interfaces/admin.js +2 -0
- package/dist/cjs/interfaces/application.js +2 -0
- package/dist/cjs/interfaces/blockchain.js +2 -0
- package/dist/cjs/interfaces/instance.js +2 -0
- package/dist/{interfaces → cjs/interfaces}/operation.d.ts +2 -2
- package/dist/cjs/interfaces/operation.js +2 -0
- package/dist/cjs/interfaces/orby.js +2 -0
- package/dist/cjs/interfaces/token.js +2 -0
- package/dist/{types.d.ts → cjs/types.d.ts} +20 -0
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/utils/action_helpers.js +274 -0
- package/dist/cjs/utils/utils.js +79 -0
- package/dist/cjs/utils/validateAndParseAddress.js +29 -0
- package/dist/esm/actions/account_cluster.d.ts +32 -0
- package/dist/esm/actions/admin.d.ts +17 -0
- package/dist/esm/actions/application.d.ts +6 -0
- package/dist/esm/actions/blockchain.d.ts +16 -0
- package/dist/esm/actions/instance.d.ts +15 -0
- package/dist/esm/actions/operation.d.ts +99 -0
- package/dist/{actions → esm/actions}/operation.js +75 -5
- package/dist/esm/actions/token.d.ts +15 -0
- package/dist/{actions → esm/actions}/token.js +1 -1
- package/dist/esm/constants.d.ts +14 -0
- package/dist/esm/entities/account.d.ts +14 -0
- package/dist/{entities → esm/entities}/account.js +1 -1
- package/dist/esm/entities/financial/account_balance.d.ts +12 -0
- package/dist/esm/entities/financial/asset.d.ts +31 -0
- package/dist/esm/entities/financial/currency.d.ts +41 -0
- package/dist/esm/entities/financial/currency_amount.d.ts +34 -0
- package/dist/esm/entities/financial/fungible_token.d.ts +41 -0
- package/dist/esm/entities/financial/fungible_token_amount.d.ts +36 -0
- package/dist/esm/entities/financial/non_fungible_token.d.ts +39 -0
- package/dist/esm/entities/financial/semi_fungible_token.d.ts +41 -0
- package/dist/esm/entities/library_request.d.ts +8 -0
- package/dist/esm/entities/state.d.ts +22 -0
- package/dist/esm/enums.d.ts +116 -0
- package/dist/esm/index.d.ts +29 -0
- package/dist/esm/interfaces/account_cluster.d.ts +30 -0
- package/dist/esm/interfaces/admin.d.ts +14 -0
- package/dist/esm/interfaces/application.d.ts +3 -0
- package/dist/esm/interfaces/blockchain.d.ts +13 -0
- package/dist/esm/interfaces/instance.d.ts +12 -0
- package/dist/esm/interfaces/operation.d.ts +97 -0
- package/dist/esm/interfaces/orby.d.ts +9 -0
- package/dist/esm/interfaces/token.d.ts +12 -0
- package/dist/esm/types.d.ts +172 -0
- package/dist/esm/utils/action_helpers.d.ts +22 -0
- package/dist/esm/utils/utils.d.ts +10 -0
- package/dist/esm/utils/validateAndParseAddress.d.ts +10 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/package.json +16 -7
- package/dist/tsconfig.tsbuildinfo +0 -1
- /package/dist/{actions → cjs/actions}/account_cluster.d.ts +0 -0
- /package/dist/{actions → cjs/actions}/admin.d.ts +0 -0
- /package/dist/{actions → cjs/actions}/application.d.ts +0 -0
- /package/dist/{actions → cjs/actions}/blockchain.d.ts +0 -0
- /package/dist/{actions → cjs/actions}/instance.d.ts +0 -0
- /package/dist/{actions → cjs/actions}/token.d.ts +0 -0
- /package/dist/{constants.d.ts → cjs/constants.d.ts} +0 -0
- /package/dist/{entities → cjs/entities}/account.d.ts +0 -0
- /package/dist/{entities → cjs/entities}/financial/account_balance.d.ts +0 -0
- /package/dist/{entities → cjs/entities}/financial/asset.d.ts +0 -0
- /package/dist/{entities → cjs/entities}/financial/currency.d.ts +0 -0
- /package/dist/{entities → cjs/entities}/financial/currency_amount.d.ts +0 -0
- /package/dist/{entities → cjs/entities}/financial/fungible_token.d.ts +0 -0
- /package/dist/{entities → cjs/entities}/financial/fungible_token_amount.d.ts +0 -0
- /package/dist/{entities → cjs/entities}/financial/non_fungible_token.d.ts +0 -0
- /package/dist/{entities → cjs/entities}/financial/semi_fungible_token.d.ts +0 -0
- /package/dist/{entities → cjs/entities}/library_request.d.ts +0 -0
- /package/dist/{entities → cjs/entities}/state.d.ts +0 -0
- /package/dist/{enums.d.ts → cjs/enums.d.ts} +0 -0
- /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/dist/{interfaces → cjs/interfaces}/account_cluster.d.ts +0 -0
- /package/dist/{interfaces → cjs/interfaces}/admin.d.ts +0 -0
- /package/dist/{interfaces → cjs/interfaces}/application.d.ts +0 -0
- /package/dist/{interfaces → cjs/interfaces}/blockchain.d.ts +0 -0
- /package/dist/{interfaces → cjs/interfaces}/instance.d.ts +0 -0
- /package/dist/{interfaces → cjs/interfaces}/orby.d.ts +0 -0
- /package/dist/{interfaces → cjs/interfaces}/token.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/action_helpers.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/utils.d.ts +0 -0
- /package/dist/{utils → cjs/utils}/validateAndParseAddress.d.ts +0 -0
- /package/dist/{actions → esm/actions}/account_cluster.js +0 -0
- /package/dist/{actions → esm/actions}/admin.js +0 -0
- /package/dist/{actions → esm/actions}/application.js +0 -0
- /package/dist/{actions → esm/actions}/blockchain.js +0 -0
- /package/dist/{actions → esm/actions}/instance.js +0 -0
- /package/dist/{constants.js → esm/constants.js} +0 -0
- /package/dist/{entities → esm/entities}/financial/account_balance.js +0 -0
- /package/dist/{entities → esm/entities}/financial/asset.js +0 -0
- /package/dist/{entities → esm/entities}/financial/currency.js +0 -0
- /package/dist/{entities → esm/entities}/financial/currency_amount.js +0 -0
- /package/dist/{entities → esm/entities}/financial/fungible_token.js +0 -0
- /package/dist/{entities → esm/entities}/financial/fungible_token_amount.js +0 -0
- /package/dist/{entities → esm/entities}/financial/non_fungible_token.js +0 -0
- /package/dist/{entities → esm/entities}/financial/semi_fungible_token.js +0 -0
- /package/dist/{entities → esm/entities}/library_request.js +0 -0
- /package/dist/{entities → esm/entities}/state.js +0 -0
- /package/dist/{enums.js → esm/enums.js} +0 -0
- /package/dist/{index.js → esm/index.js} +0 -0
- /package/dist/{interfaces → esm/interfaces}/account_cluster.js +0 -0
- /package/dist/{interfaces → esm/interfaces}/admin.js +0 -0
- /package/dist/{interfaces → esm/interfaces}/application.js +0 -0
- /package/dist/{interfaces → esm/interfaces}/blockchain.js +0 -0
- /package/dist/{interfaces → esm/interfaces}/instance.js +0 -0
- /package/dist/{interfaces → esm/interfaces}/operation.js +0 -0
- /package/dist/{interfaces → esm/interfaces}/orby.js +0 -0
- /package/dist/{interfaces → esm/interfaces}/token.js +0 -0
- /package/dist/{types.js → esm/types.js} +0 -0
- /package/dist/{utils → esm/utils}/action_helpers.js +0 -0
- /package/dist/{utils → esm/utils}/utils.js +0 -0
- /package/dist/{utils → esm/utils}/validateAndParseAddress.js +0 -0
@@ -0,0 +1,415 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.OperationActions = void 0;
|
4
|
+
const action_helpers_js_1 = require("../utils/action_helpers.js");
|
5
|
+
const currency_amount_js_1 = require("../entities/financial/currency_amount.js");
|
6
|
+
const enums_js_1 = require("../enums.js");
|
7
|
+
const library_request_js_1 = require("../entities/library_request.js");
|
8
|
+
const utils_js_1 = require("../utils/utils.js");
|
9
|
+
const account_js_1 = require("../entities/account.js");
|
10
|
+
// from here: https://stackoverflow.com/questions/65152373/typescript-serialize-bigint-in-json
|
11
|
+
BigInt.prototype.toJSON = function () {
|
12
|
+
return this.toString();
|
13
|
+
};
|
14
|
+
class OperationActions extends library_request_js_1.LibraryRequest {
|
15
|
+
constructor(library, client, provider) {
|
16
|
+
super(library, client, provider);
|
17
|
+
}
|
18
|
+
async getOperationsToExecuteTransaction(accountClusterId, to, data, value, gasToken) {
|
19
|
+
const formattedGasToken = gasToken
|
20
|
+
? {
|
21
|
+
...gasToken,
|
22
|
+
tokenSources: gasToken.tokenSources?.map(({ chainId, address }) => ({
|
23
|
+
chainId: (0, utils_js_1.getOrbyChainId)(chainId),
|
24
|
+
address,
|
25
|
+
})),
|
26
|
+
}
|
27
|
+
: undefined;
|
28
|
+
const operationSet = await this.sendRequest("orby_getOperationsToExecuteTransaction", [
|
29
|
+
{
|
30
|
+
accountClusterId,
|
31
|
+
to,
|
32
|
+
data,
|
33
|
+
value,
|
34
|
+
gasToken: formattedGasToken,
|
35
|
+
},
|
36
|
+
]);
|
37
|
+
return (0, action_helpers_js_1.extractOperationSet)(operationSet);
|
38
|
+
}
|
39
|
+
async getOperationsToSignTypedData(accountClusterId, data, gasToken) {
|
40
|
+
const formattedGasToken = gasToken
|
41
|
+
? {
|
42
|
+
...gasToken,
|
43
|
+
tokenSources: gasToken.tokenSources?.map(({ chainId, address }) => ({
|
44
|
+
chainId: (0, utils_js_1.getOrbyChainId)(chainId),
|
45
|
+
address,
|
46
|
+
})),
|
47
|
+
}
|
48
|
+
: undefined;
|
49
|
+
const operationSet = await this.sendRequest("orby_getOperationsToSignTypedData", [
|
50
|
+
{
|
51
|
+
accountClusterId,
|
52
|
+
data,
|
53
|
+
gasToken: formattedGasToken,
|
54
|
+
},
|
55
|
+
]);
|
56
|
+
return (0, action_helpers_js_1.extractOperationSet)(operationSet);
|
57
|
+
}
|
58
|
+
async getOperationsToCancelTransaction(accountClusterId, operationSetId) {
|
59
|
+
const operationSet = await this.sendRequest("orby_getOperationsToCancelTransaction", [
|
60
|
+
{
|
61
|
+
accountClusterId,
|
62
|
+
operationSetId,
|
63
|
+
},
|
64
|
+
]);
|
65
|
+
return (0, action_helpers_js_1.extractOperationSet)(operationSet);
|
66
|
+
}
|
67
|
+
async isTransactionPreconditionSatisfied(accountClusterId, to, data, value) {
|
68
|
+
const { satisfied } = await this.sendRequest("orby_isTransactionPreconditionSatisfied", [
|
69
|
+
{
|
70
|
+
accountClusterId,
|
71
|
+
to,
|
72
|
+
data,
|
73
|
+
value,
|
74
|
+
},
|
75
|
+
]);
|
76
|
+
return satisfied;
|
77
|
+
}
|
78
|
+
async isTypedDataPreconditionSatisfied(accountClusterId, data) {
|
79
|
+
const { satisfied, code, message } = await this.sendRequest("orby_isTypedDataPreconditionSatisfied", [
|
80
|
+
{
|
81
|
+
accountClusterId,
|
82
|
+
data,
|
83
|
+
},
|
84
|
+
]);
|
85
|
+
if (code && message) {
|
86
|
+
console.error("[isTypedDataPreconditionSatisfied]", code, message);
|
87
|
+
return undefined;
|
88
|
+
}
|
89
|
+
return satisfied;
|
90
|
+
}
|
91
|
+
async sendSignedOperations(accountClusterId, signedOperations) {
|
92
|
+
const { operationSetId, operationResponses, code, message } = await this.sendRequest("orby_sendSignedOperations", [
|
93
|
+
{
|
94
|
+
accountClusterId,
|
95
|
+
signedOperations,
|
96
|
+
},
|
97
|
+
]);
|
98
|
+
if (code && message) {
|
99
|
+
console.error("[sendSignedOperations]", code, message);
|
100
|
+
return undefined;
|
101
|
+
}
|
102
|
+
return {
|
103
|
+
operationSetId,
|
104
|
+
operationResponses: (0, action_helpers_js_1.extractOperationStatuses)(operationResponses),
|
105
|
+
};
|
106
|
+
}
|
107
|
+
async getOperationStatuses(operationIds) {
|
108
|
+
const { operationStatuses } = await this.sendRequest("orby_getOperationStatuses", [{ operationIds }]);
|
109
|
+
return (0, action_helpers_js_1.extractOperationStatuses)(operationStatuses);
|
110
|
+
}
|
111
|
+
async estimateFiatCostToExecuteTransaction(to, data, value) {
|
112
|
+
const { estimatedCost, code, message } = await this.sendRequest("orby_estimateFiatCostToExecuteTransaction", [
|
113
|
+
{
|
114
|
+
to,
|
115
|
+
data,
|
116
|
+
value,
|
117
|
+
},
|
118
|
+
]);
|
119
|
+
if (code && message) {
|
120
|
+
console.error("[estimateFiatCostToExecuteTransaction]", code, message);
|
121
|
+
return undefined;
|
122
|
+
}
|
123
|
+
return currency_amount_js_1.CurrencyAmount.toCurrencyAmount(estimatedCost);
|
124
|
+
}
|
125
|
+
async estimateFiatCostToSignTypedData(data) {
|
126
|
+
const { estimatedCost, code, message } = await this.sendRequest("orby_estimateFiatCostToSignTypedData", [{ data }]);
|
127
|
+
if (code && message) {
|
128
|
+
console.error("[estimateFiatCostToSignTypedData]", code, message);
|
129
|
+
return undefined;
|
130
|
+
}
|
131
|
+
return currency_amount_js_1.CurrencyAmount.toCurrencyAmount(estimatedCost);
|
132
|
+
}
|
133
|
+
async getOperationsToTransferToken(accountClusterId, standardizedTokenId, amount, recipient, gasToken) {
|
134
|
+
const formattedGasToken = gasToken
|
135
|
+
? {
|
136
|
+
...gasToken,
|
137
|
+
tokenSources: gasToken.tokenSources?.map(({ chainId, address }) => ({
|
138
|
+
chainId: (0, utils_js_1.getOrbyChainId)(chainId),
|
139
|
+
address,
|
140
|
+
})),
|
141
|
+
}
|
142
|
+
: undefined;
|
143
|
+
const formattedRecepient = {
|
144
|
+
chainId: (0, utils_js_1.getOrbyChainId)(recipient.chainId),
|
145
|
+
recipientAddress: recipient.recipientAddress,
|
146
|
+
};
|
147
|
+
const operationSet = await this.sendRequest("orby_getOperationsToTransferToken", [
|
148
|
+
{
|
149
|
+
accountClusterId,
|
150
|
+
standardizedTokenId,
|
151
|
+
amount,
|
152
|
+
recipient: formattedRecepient,
|
153
|
+
gasToken: formattedGasToken,
|
154
|
+
},
|
155
|
+
]);
|
156
|
+
return (0, action_helpers_js_1.extractOperationSet)(operationSet);
|
157
|
+
}
|
158
|
+
async getOperationsToSwap(accountClusterId, swapType, input, output, gasToken) {
|
159
|
+
const formattedInput = input
|
160
|
+
? {
|
161
|
+
...input,
|
162
|
+
tokenSources: input?.tokenSources.map(({ chainId, address }) => ({
|
163
|
+
chainId: (0, utils_js_1.getOrbyChainId)(chainId),
|
164
|
+
address,
|
165
|
+
})),
|
166
|
+
}
|
167
|
+
: undefined;
|
168
|
+
const formattedOutput = output
|
169
|
+
? {
|
170
|
+
...output,
|
171
|
+
tokenDestination: output?.tokenDestination
|
172
|
+
? {
|
173
|
+
chainId: (0, utils_js_1.getOrbyChainId)(output.tokenDestination.chainId),
|
174
|
+
address: output.tokenDestination.address,
|
175
|
+
}
|
176
|
+
: undefined,
|
177
|
+
}
|
178
|
+
: undefined;
|
179
|
+
const formattedGasToken = gasToken
|
180
|
+
? {
|
181
|
+
...gasToken,
|
182
|
+
tokenSources: gasToken.tokenSources?.map(({ chainId, address }) => ({
|
183
|
+
chainId: (0, utils_js_1.getOrbyChainId)(chainId),
|
184
|
+
address,
|
185
|
+
})),
|
186
|
+
}
|
187
|
+
: undefined;
|
188
|
+
const operationSet = await this.sendRequest("orby_getOperationsToSwap", [
|
189
|
+
{
|
190
|
+
accountClusterId,
|
191
|
+
swapType,
|
192
|
+
input: formattedInput,
|
193
|
+
output: formattedOutput,
|
194
|
+
gasToken: formattedGasToken,
|
195
|
+
},
|
196
|
+
]);
|
197
|
+
return (0, action_helpers_js_1.extractOperationSet)(operationSet);
|
198
|
+
}
|
199
|
+
async getQuote(accountClusterId, swapType, input, output) {
|
200
|
+
const formattedInput = input
|
201
|
+
? {
|
202
|
+
...input,
|
203
|
+
tokenSources: input?.tokenSources.map(({ chainId, address }) => ({
|
204
|
+
chainId: (0, utils_js_1.getOrbyChainId)(chainId),
|
205
|
+
address,
|
206
|
+
})),
|
207
|
+
}
|
208
|
+
: undefined;
|
209
|
+
const formattedOutput = output
|
210
|
+
? {
|
211
|
+
...output,
|
212
|
+
tokenDestination: output?.tokenDestination
|
213
|
+
? {
|
214
|
+
chainId: (0, utils_js_1.getOrbyChainId)(output.tokenDestination.chainId),
|
215
|
+
address: output.tokenDestination.address,
|
216
|
+
}
|
217
|
+
: undefined,
|
218
|
+
}
|
219
|
+
: undefined;
|
220
|
+
const operationSet = await this.sendRequest("orby_getQuote", [
|
221
|
+
{
|
222
|
+
accountClusterId,
|
223
|
+
swapType,
|
224
|
+
input: formattedInput,
|
225
|
+
output: formattedOutput,
|
226
|
+
},
|
227
|
+
]);
|
228
|
+
return (0, action_helpers_js_1.extractOperationSet)(operationSet);
|
229
|
+
}
|
230
|
+
async getOperationsToBridge(accountClusterId, standardizedTokenId, amount, tokenSources, tokenDestination, gasToken) {
|
231
|
+
const formattedTokenSources = tokenSources.map(({ chainId, address }) => ({
|
232
|
+
chainId: (0, utils_js_1.getOrbyChainId)(chainId),
|
233
|
+
address,
|
234
|
+
}));
|
235
|
+
const formattedDestination = tokenDestination
|
236
|
+
? {
|
237
|
+
chainId: (0, utils_js_1.getOrbyChainId)(tokenDestination.chainId),
|
238
|
+
address: tokenDestination.address,
|
239
|
+
}
|
240
|
+
: undefined;
|
241
|
+
const formattedGasToken = gasToken
|
242
|
+
? {
|
243
|
+
...gasToken,
|
244
|
+
tokenSources: gasToken.tokenSources?.map(({ chainId, address }) => ({
|
245
|
+
chainId: (0, utils_js_1.getOrbyChainId)(chainId),
|
246
|
+
address,
|
247
|
+
})),
|
248
|
+
}
|
249
|
+
: undefined;
|
250
|
+
const operationSet = await this.sendRequest("orby_getOperationsToBridge", [
|
251
|
+
{
|
252
|
+
accountClusterId,
|
253
|
+
standardizedTokenId,
|
254
|
+
amount,
|
255
|
+
tokenSources: formattedTokenSources,
|
256
|
+
tokenDestination: formattedDestination,
|
257
|
+
gasToken: formattedGasToken,
|
258
|
+
},
|
259
|
+
]);
|
260
|
+
return (0, action_helpers_js_1.extractOperationSet)(operationSet);
|
261
|
+
}
|
262
|
+
subscribeToOperationStatuses(ids, onOperationStatusesUpdateCallback, timout) {
|
263
|
+
let intervalId = null;
|
264
|
+
let totalWaitTime = 0;
|
265
|
+
const timeoutOrDefault = timout ?? 300_000;
|
266
|
+
if (ids && ids?.length > 0) {
|
267
|
+
const waitTime = 500;
|
268
|
+
intervalId = setInterval(async () => {
|
269
|
+
let statusSummary = enums_js_1.OperationStatusType.WAITING_PRECONDITION;
|
270
|
+
let primaryOperation;
|
271
|
+
try {
|
272
|
+
const statuses = ids && ids?.length > 0
|
273
|
+
? await this?.getOperationStatuses(ids)
|
274
|
+
: undefined;
|
275
|
+
if (!ids || ids?.length == 0) {
|
276
|
+
statusSummary = enums_js_1.OperationStatusType.NOT_FOUND;
|
277
|
+
}
|
278
|
+
else if (!statuses) {
|
279
|
+
statusSummary = enums_js_1.OperationStatusType.NOT_FOUND;
|
280
|
+
}
|
281
|
+
else if (statuses.some((status) => status.status == enums_js_1.OperationStatusType.FAILED)) {
|
282
|
+
statusSummary = enums_js_1.OperationStatusType.FAILED;
|
283
|
+
}
|
284
|
+
else if (statuses.every((status) => status.status == enums_js_1.OperationStatusType.SUCCESSFUL)) {
|
285
|
+
statusSummary = enums_js_1.OperationStatusType.SUCCESSFUL;
|
286
|
+
}
|
287
|
+
primaryOperation = statuses?.find((status) => status.type == enums_js_1.OperationType.FINAL_TRANSACTION);
|
288
|
+
if (primaryOperation?.status == enums_js_1.OperationStatusType.PENDING) {
|
289
|
+
statusSummary = enums_js_1.OperationStatusType.PENDING;
|
290
|
+
}
|
291
|
+
onOperationStatusesUpdateCallback?.(statusSummary, primaryOperation, statuses);
|
292
|
+
}
|
293
|
+
catch (error) {
|
294
|
+
console.error("[useWaitForStatusCompletion]", error);
|
295
|
+
}
|
296
|
+
finally {
|
297
|
+
totalWaitTime += waitTime;
|
298
|
+
if (intervalId &&
|
299
|
+
enums_js_1.OperationStatusType.WAITING_PRECONDITION != statusSummary) {
|
300
|
+
clearInterval(intervalId);
|
301
|
+
intervalId = null;
|
302
|
+
}
|
303
|
+
else if (intervalId && totalWaitTime >= timeoutOrDefault) {
|
304
|
+
// we cant wait for more than 2 ETH blocks
|
305
|
+
clearInterval(intervalId);
|
306
|
+
intervalId = null;
|
307
|
+
}
|
308
|
+
}
|
309
|
+
}, waitTime);
|
310
|
+
}
|
311
|
+
return { intervalId };
|
312
|
+
}
|
313
|
+
async sendOperationSet(accountCluster, operationSet, signTransaction, signUserOperation, signTypedData) {
|
314
|
+
const signedOperations = [];
|
315
|
+
const operations = operationSet.intents
|
316
|
+
?.map((intent) => intent.intentOperations)
|
317
|
+
.flat()
|
318
|
+
?.concat(operationSet.primaryOperation)
|
319
|
+
.filter((value) => value != undefined && value != null);
|
320
|
+
if (operations?.length == 0) {
|
321
|
+
return { success: true, operationResponses: [] };
|
322
|
+
}
|
323
|
+
else if (!operations) {
|
324
|
+
return { success: false };
|
325
|
+
}
|
326
|
+
const hasPrimaryOperation = operations.find((operation) => operation.type == enums_js_1.OperationType.FINAL_TRANSACTION);
|
327
|
+
if (!hasPrimaryOperation) {
|
328
|
+
return { success: false };
|
329
|
+
}
|
330
|
+
const accountsMap = accountCluster.accounts.reduce((acc, account) => {
|
331
|
+
acc.set(account.key, account);
|
332
|
+
return acc;
|
333
|
+
}, new Map());
|
334
|
+
const smartAccountTransactions = operations.reduce((acc, operation) => {
|
335
|
+
const accountKey = account_js_1.Account.key(operation.from, operation.chainId);
|
336
|
+
const account = accountsMap.get(accountKey);
|
337
|
+
if (account?.accountType == enums_js_1.AccountType.SCA &&
|
338
|
+
operation.format == enums_js_1.OperationDataFormat.TRANSACTION) {
|
339
|
+
if (!acc.has(accountKey)) {
|
340
|
+
acc.set(accountKey, []);
|
341
|
+
}
|
342
|
+
acc.get(accountKey).push(operation);
|
343
|
+
}
|
344
|
+
return acc;
|
345
|
+
}, new Map());
|
346
|
+
// Loop through all the operations and sign them
|
347
|
+
for (let i = 0; i < operations.length; i++) {
|
348
|
+
const operation = operations[i];
|
349
|
+
let signature;
|
350
|
+
if (operation.format == enums_js_1.OperationDataFormat.TRANSACTION) {
|
351
|
+
const accountKey = account_js_1.Account.key(operation.from, operation.chainId);
|
352
|
+
const account = accountsMap.get(accountKey);
|
353
|
+
// skip signing the transaction if the account is an SCA
|
354
|
+
if (account?.accountType == enums_js_1.AccountType.SCA) {
|
355
|
+
continue;
|
356
|
+
}
|
357
|
+
signature = await signTransaction(operation);
|
358
|
+
}
|
359
|
+
else if (operation.format == enums_js_1.OperationDataFormat.TYPED_DATA) {
|
360
|
+
signature = await signTypedData(operation);
|
361
|
+
}
|
362
|
+
if (!signature) {
|
363
|
+
return { success: false };
|
364
|
+
}
|
365
|
+
signedOperations.push({
|
366
|
+
type: operation.type,
|
367
|
+
signature: signature,
|
368
|
+
data: operation.data,
|
369
|
+
from: operation.from,
|
370
|
+
chainId: (0, utils_js_1.getOrbyChainId)(operation.chainId),
|
371
|
+
});
|
372
|
+
}
|
373
|
+
// batch sign all the smart contract transactions
|
374
|
+
const accountKeys = Array.from(smartAccountTransactions.keys());
|
375
|
+
for (const accountKey of accountKeys) {
|
376
|
+
const transactions = smartAccountTransactions.get(accountKey);
|
377
|
+
transactions.sort((operationA, _) => {
|
378
|
+
if (operationA.type == enums_js_1.OperationType.APPROVE_ERC20_TOKEN) {
|
379
|
+
return -1;
|
380
|
+
}
|
381
|
+
return 0;
|
382
|
+
});
|
383
|
+
const userOperation = await signUserOperation(transactions, transactions[0].from, transactions[0].chainId, transactions[0].txRpcUrl);
|
384
|
+
if (!userOperation) {
|
385
|
+
return { success: false };
|
386
|
+
}
|
387
|
+
const types = transactions.map((operation) => operation.type);
|
388
|
+
let type = types[0];
|
389
|
+
if (types.includes(enums_js_1.OperationType.FINAL_TRANSACTION)) {
|
390
|
+
type = enums_js_1.OperationType.FINAL_TRANSACTION;
|
391
|
+
}
|
392
|
+
else if (types.includes(enums_js_1.OperationType.SUBMIT_INTENT)) {
|
393
|
+
type = enums_js_1.OperationType.SUBMIT_INTENT;
|
394
|
+
}
|
395
|
+
signedOperations.push({
|
396
|
+
type,
|
397
|
+
signature: userOperation.signature,
|
398
|
+
data: JSON.stringify(userOperation),
|
399
|
+
from: transactions[0].from,
|
400
|
+
chainId: (0, utils_js_1.getOrbyChainId)(transactions[0].chainId),
|
401
|
+
});
|
402
|
+
}
|
403
|
+
const { operationSetId, operationResponses } = await this.sendSignedOperations(accountCluster.accountClusterId, signedOperations);
|
404
|
+
return {
|
405
|
+
operationSetId,
|
406
|
+
operationResponses,
|
407
|
+
success: true,
|
408
|
+
primaryOperationStatus: {
|
409
|
+
type: enums_js_1.OperationType.FINAL_TRANSACTION,
|
410
|
+
status: enums_js_1.OperationStatusType.WAITING_PRECONDITION,
|
411
|
+
},
|
412
|
+
};
|
413
|
+
}
|
414
|
+
}
|
415
|
+
exports.OperationActions = OperationActions;
|
@@ -0,0 +1,50 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.TokenActions = void 0;
|
4
|
+
const action_helpers_js_1 = require("../utils/action_helpers.js");
|
5
|
+
const library_request_js_1 = require("../entities/library_request.js");
|
6
|
+
const utils_js_1 = require("../utils/utils.js");
|
7
|
+
class TokenActions extends library_request_js_1.LibraryRequest {
|
8
|
+
constructor(library, client, provider) {
|
9
|
+
super(library, client, provider);
|
10
|
+
}
|
11
|
+
async getStandardizedTokenIds(tokens) {
|
12
|
+
const formattedTokensInfo = tokens.map(({ tokenAddress, chainId }) => {
|
13
|
+
return { chainId: (0, utils_js_1.getOrbyChainId)(chainId), tokenAddress };
|
14
|
+
});
|
15
|
+
const { standardizedTokenIds, message, code } = await this.sendRequest("orby_getStandardizedTokenIds", [
|
16
|
+
{
|
17
|
+
tokens: formattedTokensInfo,
|
18
|
+
},
|
19
|
+
]);
|
20
|
+
if (code && message) {
|
21
|
+
console.error("[getStandardizedTokenIds]", code, message);
|
22
|
+
return undefined;
|
23
|
+
}
|
24
|
+
return standardizedTokenIds;
|
25
|
+
}
|
26
|
+
async getStandardizedTokens(tokens) {
|
27
|
+
const formattedTokensInfo = tokens.map(({ tokenAddress, chainId }) => {
|
28
|
+
return { chainId: (0, utils_js_1.getOrbyChainId)(chainId), tokenAddress };
|
29
|
+
});
|
30
|
+
const { standardizedTokens, message, code } = await this.sendRequest("orby_getStandardizedTokens", [
|
31
|
+
{
|
32
|
+
tokens: formattedTokensInfo,
|
33
|
+
},
|
34
|
+
]);
|
35
|
+
if (code && message) {
|
36
|
+
console.error("[getStandardizedTokens]", code, message);
|
37
|
+
return undefined;
|
38
|
+
}
|
39
|
+
return (0, action_helpers_js_1.extractStandardizedTokens)(standardizedTokens);
|
40
|
+
}
|
41
|
+
async getFungibleTokenData(standardizedTokenIds) {
|
42
|
+
const { data, message, code } = await this.sendRequest("orby_getFungibleTokenData", [{ standardizedTokenIds }]);
|
43
|
+
if (code && message) {
|
44
|
+
console.error("[getFungibleTokenData]", code, message);
|
45
|
+
return undefined;
|
46
|
+
}
|
47
|
+
return (0, action_helpers_js_1.extractStandardizedTokens)(data);
|
48
|
+
}
|
49
|
+
}
|
50
|
+
exports.TokenActions = TokenActions;
|
@@ -0,0 +1,139 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.FIAT_CURRENCY = exports.BLOCKCHAIN_ID_TO_BLOCKCHAIN = exports.CHAIN_CONFIGS = exports.BLOCKCHAIN_ID = exports.Big = void 0;
|
7
|
+
const toformat_1 = __importDefault(require("toformat"));
|
8
|
+
const big_js_1 = __importDefault(require("big.js"));
|
9
|
+
const enums_js_1 = require("./enums.js");
|
10
|
+
const currency_js_1 = require("./entities/financial/currency.js");
|
11
|
+
exports.Big = (0, toformat_1.default)(big_js_1.default);
|
12
|
+
exports.BLOCKCHAIN_ID = {
|
13
|
+
[enums_js_1.Blockchain.ETHEREUM]: 1,
|
14
|
+
[enums_js_1.Blockchain.POLYGON]: 137,
|
15
|
+
[enums_js_1.Blockchain.BINANCE]: 56,
|
16
|
+
[enums_js_1.Blockchain.ARBITRUM]: 42161,
|
17
|
+
[enums_js_1.Blockchain.ARBITRUM_NOVA]: 42170,
|
18
|
+
[enums_js_1.Blockchain.OPTIMISM]: 10,
|
19
|
+
[enums_js_1.Blockchain.EVMOS]: 9001,
|
20
|
+
[enums_js_1.Blockchain.MOONBEAM]: 1284,
|
21
|
+
[enums_js_1.Blockchain.BASE]: 8453,
|
22
|
+
[enums_js_1.Blockchain.AVALANCHE]: 43114,
|
23
|
+
// testnets
|
24
|
+
[enums_js_1.Blockchain.ETHEREUM_SEPOLIA]: 11155111,
|
25
|
+
[enums_js_1.Blockchain.ETHEREUM_HOLESKY]: 17000,
|
26
|
+
[enums_js_1.Blockchain.ARBITRUM_SEPOLIA]: 421614,
|
27
|
+
[enums_js_1.Blockchain.OPTIMISM_SEPOLIA]: 11155420,
|
28
|
+
[enums_js_1.Blockchain.POLYGON_AMOY]: 80002,
|
29
|
+
[enums_js_1.Blockchain.BINANCE_TESTNET]: 97,
|
30
|
+
[enums_js_1.Blockchain.OPBNB_TESTNET]: 5611,
|
31
|
+
[enums_js_1.Blockchain.MOONBEAM_ALPHA]: 1287,
|
32
|
+
[enums_js_1.Blockchain.BASE_SEPOLIA]: 84532,
|
33
|
+
// local testing
|
34
|
+
[enums_js_1.Blockchain.HARDHAT]: 31337,
|
35
|
+
[enums_js_1.Blockchain.LOCAL_CHAIN_0]: 1_000_000_000_001,
|
36
|
+
[enums_js_1.Blockchain.LOCAL_CHAIN_1]: 1_000_000_000_002,
|
37
|
+
};
|
38
|
+
exports.CHAIN_CONFIGS = {
|
39
|
+
[enums_js_1.Blockchain.ETHEREUM]: {
|
40
|
+
environment: enums_js_1.BlockchainEnvironment.MAINNET,
|
41
|
+
chainId: BigInt(1),
|
42
|
+
},
|
43
|
+
[enums_js_1.Blockchain.POLYGON]: {
|
44
|
+
environment: enums_js_1.BlockchainEnvironment.MAINNET,
|
45
|
+
chainId: BigInt(137),
|
46
|
+
},
|
47
|
+
[enums_js_1.Blockchain.BINANCE]: {
|
48
|
+
environment: enums_js_1.BlockchainEnvironment.MAINNET,
|
49
|
+
chainId: BigInt(56),
|
50
|
+
},
|
51
|
+
[enums_js_1.Blockchain.ARBITRUM]: {
|
52
|
+
environment: enums_js_1.BlockchainEnvironment.MAINNET,
|
53
|
+
chainId: BigInt(42161),
|
54
|
+
},
|
55
|
+
[enums_js_1.Blockchain.ARBITRUM_NOVA]: {
|
56
|
+
environment: enums_js_1.BlockchainEnvironment.MAINNET,
|
57
|
+
chainId: BigInt(42170),
|
58
|
+
},
|
59
|
+
[enums_js_1.Blockchain.OPTIMISM]: {
|
60
|
+
environment: enums_js_1.BlockchainEnvironment.MAINNET,
|
61
|
+
chainId: BigInt(10),
|
62
|
+
},
|
63
|
+
[enums_js_1.Blockchain.EVMOS]: {
|
64
|
+
environment: enums_js_1.BlockchainEnvironment.MAINNET,
|
65
|
+
chainId: BigInt(9001),
|
66
|
+
},
|
67
|
+
[enums_js_1.Blockchain.MOONBEAM]: {
|
68
|
+
environment: enums_js_1.BlockchainEnvironment.MAINNET,
|
69
|
+
chainId: BigInt(1284),
|
70
|
+
},
|
71
|
+
[enums_js_1.Blockchain.BASE]: {
|
72
|
+
environment: enums_js_1.BlockchainEnvironment.MAINNET,
|
73
|
+
chainId: BigInt(8453),
|
74
|
+
},
|
75
|
+
[enums_js_1.Blockchain.AVALANCHE]: {
|
76
|
+
environment: enums_js_1.BlockchainEnvironment.MAINNET,
|
77
|
+
chainId: BigInt(43114),
|
78
|
+
},
|
79
|
+
// testnets
|
80
|
+
[enums_js_1.Blockchain.ETHEREUM_SEPOLIA]: {
|
81
|
+
environment: enums_js_1.BlockchainEnvironment.TESTNET,
|
82
|
+
chainId: BigInt(11155111),
|
83
|
+
},
|
84
|
+
[enums_js_1.Blockchain.ETHEREUM_HOLESKY]: {
|
85
|
+
environment: enums_js_1.BlockchainEnvironment.TESTNET,
|
86
|
+
chainId: BigInt(17000),
|
87
|
+
},
|
88
|
+
[enums_js_1.Blockchain.ARBITRUM_SEPOLIA]: {
|
89
|
+
environment: enums_js_1.BlockchainEnvironment.TESTNET,
|
90
|
+
chainId: BigInt(421614),
|
91
|
+
},
|
92
|
+
[enums_js_1.Blockchain.BASE_SEPOLIA]: {
|
93
|
+
environment: enums_js_1.BlockchainEnvironment.TESTNET,
|
94
|
+
chainId: BigInt(84532),
|
95
|
+
},
|
96
|
+
[enums_js_1.Blockchain.OPTIMISM_SEPOLIA]: {
|
97
|
+
environment: enums_js_1.BlockchainEnvironment.TESTNET,
|
98
|
+
chainId: BigInt(11155420),
|
99
|
+
},
|
100
|
+
[enums_js_1.Blockchain.BINANCE_TESTNET]: {
|
101
|
+
environment: enums_js_1.BlockchainEnvironment.TESTNET,
|
102
|
+
chainId: BigInt(97),
|
103
|
+
},
|
104
|
+
[enums_js_1.Blockchain.OPBNB_TESTNET]: {
|
105
|
+
environment: enums_js_1.BlockchainEnvironment.TESTNET,
|
106
|
+
chainId: BigInt(5611),
|
107
|
+
},
|
108
|
+
[enums_js_1.Blockchain.MOONBEAM_ALPHA]: {
|
109
|
+
environment: enums_js_1.BlockchainEnvironment.TESTNET,
|
110
|
+
chainId: BigInt(1287),
|
111
|
+
},
|
112
|
+
[enums_js_1.Blockchain.POLYGON_AMOY]: {
|
113
|
+
environment: enums_js_1.BlockchainEnvironment.TESTNET,
|
114
|
+
chainId: BigInt(80002),
|
115
|
+
},
|
116
|
+
};
|
117
|
+
exports.BLOCKCHAIN_ID_TO_BLOCKCHAIN = {
|
118
|
+
[1]: enums_js_1.Blockchain.ETHEREUM,
|
119
|
+
[137]: enums_js_1.Blockchain.POLYGON,
|
120
|
+
[56]: enums_js_1.Blockchain.BINANCE,
|
121
|
+
[42161]: enums_js_1.Blockchain.ARBITRUM,
|
122
|
+
[42170]: enums_js_1.Blockchain.ARBITRUM_NOVA,
|
123
|
+
[10]: enums_js_1.Blockchain.OPTIMISM,
|
124
|
+
[9001]: enums_js_1.Blockchain.EVMOS,
|
125
|
+
[1284]: enums_js_1.Blockchain.MOONBEAM,
|
126
|
+
[8453]: enums_js_1.Blockchain.BASE,
|
127
|
+
[43114]: enums_js_1.Blockchain.AVALANCHE,
|
128
|
+
// testnets
|
129
|
+
[11155111]: enums_js_1.Blockchain.ETHEREUM_SEPOLIA,
|
130
|
+
[84532]: enums_js_1.Blockchain.BASE_SEPOLIA,
|
131
|
+
[17000]: enums_js_1.Blockchain.ETHEREUM_HOLESKY,
|
132
|
+
[421614]: enums_js_1.Blockchain.ARBITRUM_SEPOLIA,
|
133
|
+
[11155420]: enums_js_1.Blockchain.OPTIMISM_SEPOLIA,
|
134
|
+
[80002]: enums_js_1.Blockchain.POLYGON_AMOY,
|
135
|
+
[97]: enums_js_1.Blockchain.BINANCE_TESTNET,
|
136
|
+
[5611]: enums_js_1.Blockchain.OPBNB_TESTNET,
|
137
|
+
[1287]: enums_js_1.Blockchain.MOONBEAM_ALPHA,
|
138
|
+
};
|
139
|
+
exports.FIAT_CURRENCY = new currency_js_1.Currency(6, "USD", "US Dollar", undefined, false, false);
|
@@ -0,0 +1,49 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.Account = void 0;
|
4
|
+
const enums_js_1 = require("../enums.js");
|
5
|
+
const utils_js_1 = require("../utils/utils.js");
|
6
|
+
class Account {
|
7
|
+
static toAccount(account) {
|
8
|
+
const chainId = account?.chainId
|
9
|
+
? (0, utils_js_1.getChainIdFromOrbyChainId)(account.chainId)
|
10
|
+
: undefined;
|
11
|
+
const formattedAccountType = account?.accountType;
|
12
|
+
if (!chainId && formattedAccountType == enums_js_1.AccountType.SCA) {
|
13
|
+
return undefined;
|
14
|
+
}
|
15
|
+
return new Account(account.address, formattedAccountType, account.vmType, chainId);
|
16
|
+
}
|
17
|
+
constructor(address, accountType, vmType, chainId) {
|
18
|
+
// TODO(felix): add this back
|
19
|
+
// invariant(!_.isUndefined(getBlockchainFromBlockchainId(chainId)), "CHAIN_ID");
|
20
|
+
this.address = address?.toLowerCase(); // validateAndParseAddress(address)?.toLowerCase();
|
21
|
+
this.chainId = chainId ? BigInt(chainId) : undefined;
|
22
|
+
this.accountType = accountType;
|
23
|
+
this.vmType = vmType;
|
24
|
+
this.key = Account.key(address, chainId);
|
25
|
+
if (this.accountType == enums_js_1.AccountType.SCA) {
|
26
|
+
this.hasSufficientBalanceForGas = true;
|
27
|
+
}
|
28
|
+
else {
|
29
|
+
this.hasSufficientBalanceForGas = false;
|
30
|
+
}
|
31
|
+
}
|
32
|
+
static key(address, chainId) {
|
33
|
+
return chainId
|
34
|
+
? `${chainId?.toString()?.toLowerCase()}-${address}`
|
35
|
+
: address;
|
36
|
+
}
|
37
|
+
toAccountModel() {
|
38
|
+
return {
|
39
|
+
address: this.address,
|
40
|
+
accountType: this.accountType?.toUpperCase(),
|
41
|
+
vmType: this.vmType?.toUpperCase(),
|
42
|
+
chainId: this.chainId ? "EIP155-" + this.chainId : undefined,
|
43
|
+
};
|
44
|
+
}
|
45
|
+
equals(other) {
|
46
|
+
return this.key == other?.key && this.accountType == other?.accountType;
|
47
|
+
}
|
48
|
+
}
|
49
|
+
exports.Account = Account;
|
@@ -0,0 +1,35 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.AccountBalance = void 0;
|
4
|
+
const account_js_1 = require("../account.js");
|
5
|
+
const fungible_token_amount_js_1 = require("./fungible_token_amount.js");
|
6
|
+
class AccountBalance {
|
7
|
+
static toAccountBalance(balance) {
|
8
|
+
if (!balance) {
|
9
|
+
return undefined;
|
10
|
+
}
|
11
|
+
const amount = fungible_token_amount_js_1.FungibleTokenAmount.toFungibleTokenAmount(balance.amount);
|
12
|
+
const account = account_js_1.Account.toAccount(balance.account);
|
13
|
+
return new AccountBalance(amount, account);
|
14
|
+
}
|
15
|
+
constructor(amount, account) {
|
16
|
+
this.amount = amount;
|
17
|
+
this.account = account;
|
18
|
+
}
|
19
|
+
equals(other) {
|
20
|
+
return (this.account.equals(other.account) && this.amount.equals(other.amount));
|
21
|
+
}
|
22
|
+
lessThan(other) {
|
23
|
+
return (this.account.equals(other.account) && this.amount.lessThan(other.amount));
|
24
|
+
}
|
25
|
+
greaterThan(other) {
|
26
|
+
return (this.account.equals(other.account) &&
|
27
|
+
this.amount.greaterThan(other.amount));
|
28
|
+
}
|
29
|
+
greaterThanOrEqual(other) {
|
30
|
+
return (this.account.equals(other.account) &&
|
31
|
+
(this.amount.greaterThan(other.amount) ||
|
32
|
+
this.amount.equals(other.amount)));
|
33
|
+
}
|
34
|
+
}
|
35
|
+
exports.AccountBalance = AccountBalance;
|