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