@rango-dev/queue-manager-rango-preset 0.22.1-next.9 → 0.23.0
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 +34 -0
- package/dist/actions/checkStatus.d.ts +3 -2
- package/dist/actions/checkStatus.d.ts.map +1 -1
- package/dist/actions/executeTransaction.d.ts.map +1 -1
- package/dist/actions/scheduleNextStep.d.ts +3 -2
- package/dist/actions/scheduleNextStep.d.ts.map +1 -1
- package/dist/helpers.d.ts +3 -3
- package/dist/helpers.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/migration.d.ts.map +1 -1
- package/dist/services/eventEmitter.d.ts +1 -1
- package/dist/services/eventEmitter.d.ts.map +1 -1
- package/dist/shared-sentry.d.ts +2 -2
- package/dist/shared-sentry.d.ts.map +1 -1
- package/dist/shared.d.ts +3 -98
- package/dist/shared.d.ts.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/actions/checkStatus.ts +71 -53
- package/src/actions/executeTransaction.ts +3 -1
- package/src/actions/scheduleNextStep.ts +13 -10
- package/src/helpers.ts +10 -10
- package/src/index.ts +1 -7
- package/src/migration.ts +11 -11
- package/src/services/eventEmitter.ts +1 -1
- package/src/shared-sentry.ts +3 -2
- package/src/shared.ts +66 -166
- package/src/types.ts +3 -1
package/src/index.ts
CHANGED
|
@@ -33,18 +33,12 @@ export {
|
|
|
33
33
|
StepExecutionEventStatus,
|
|
34
34
|
StepExecutionBlockedEventStatus,
|
|
35
35
|
} from './types';
|
|
36
|
-
export type {
|
|
37
|
-
PendingSwapWithQueueID,
|
|
38
|
-
PendingSwapStep,
|
|
39
|
-
PendingSwap,
|
|
40
|
-
EventType,
|
|
41
|
-
} from './shared';
|
|
36
|
+
export type { PendingSwapWithQueueID, EventType } from './shared';
|
|
42
37
|
export {
|
|
43
38
|
getCurrentBlockchainOfOrNull,
|
|
44
39
|
getRelatedWalletOrNull,
|
|
45
40
|
getRelatedWallet,
|
|
46
41
|
MessageSeverity,
|
|
47
|
-
PendingSwapNetworkStatus,
|
|
48
42
|
calculatePendingSwap,
|
|
49
43
|
} from './shared';
|
|
50
44
|
export {
|
package/src/migration.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
DB_NAME,
|
|
6
|
-
} from '@rango-dev/queue-manager-core';
|
|
1
|
+
import type { PersistedQueue } from '@rango-dev/queue-manager-core';
|
|
2
|
+
import type { PendingSwap } from 'rango-types';
|
|
3
|
+
|
|
4
|
+
import { DB_NAME, Persistor, Status } from '@rango-dev/queue-manager-core';
|
|
7
5
|
import { v4 as uuid } from 'uuid';
|
|
8
|
-
|
|
6
|
+
|
|
9
7
|
import { SwapActionTypes } from './types';
|
|
10
8
|
|
|
11
9
|
const MIGRATED_KEY = 'migratedToQueueManager';
|
|
@@ -49,9 +47,9 @@ async function migration(): Promise<boolean> {
|
|
|
49
47
|
const convertedSwaps: PersistedQueue[] = [];
|
|
50
48
|
|
|
51
49
|
swaps.forEach((swap) => {
|
|
52
|
-
/*
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
/*
|
|
51
|
+
*For running task we need to add some more work
|
|
52
|
+
*We need to create a queue task to be run and resume the running task from queue manager.
|
|
55
53
|
*/
|
|
56
54
|
if (swap.status === 'running') {
|
|
57
55
|
const taskId = uuid();
|
|
@@ -112,7 +110,9 @@ async function migration(): Promise<boolean> {
|
|
|
112
110
|
// Getting an instance from persistor, so we can directly put our data inside it.
|
|
113
111
|
const persistor = new Persistor();
|
|
114
112
|
|
|
115
|
-
const promises = convertedSwaps.map((queue) =>
|
|
113
|
+
const promises = convertedSwaps.map(async (queue) =>
|
|
114
|
+
persistor.insertQueue(queue)
|
|
115
|
+
);
|
|
116
116
|
await Promise.all(promises);
|
|
117
117
|
|
|
118
118
|
// Mark as the data has been successfully migrated.
|
package/src/shared-sentry.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { WalletType } from '@rango-dev/wallets-shared';
|
|
2
|
+
import type { PendingSwap, PendingSwapStep } from 'rango-types';
|
|
3
|
+
|
|
1
4
|
import * as Sentry from '@sentry/browser';
|
|
2
|
-
import { PendingSwap, PendingSwapStep } from './shared';
|
|
3
|
-
import { WalletType } from '@rango-dev/wallets-shared';
|
|
4
5
|
|
|
5
6
|
export function logRPCError(
|
|
6
7
|
error: unknown,
|
package/src/shared.ts
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
import type { Network, WalletType } from '@rango-dev/wallets-shared';
|
|
2
2
|
import type {
|
|
3
|
-
AmountRestrictionType,
|
|
4
3
|
BestRouteResponse,
|
|
5
4
|
BlockchainMeta,
|
|
6
|
-
CosmosTransaction,
|
|
7
|
-
EvmTransaction,
|
|
8
5
|
MetaResponse,
|
|
9
|
-
SimulationResult,
|
|
10
|
-
SolanaTransaction,
|
|
11
|
-
StarknetTransaction,
|
|
12
6
|
SwapResult,
|
|
13
7
|
Token,
|
|
14
|
-
Transfer as TransferTransaction,
|
|
15
|
-
TronTransaction,
|
|
16
8
|
} from 'rango-sdk';
|
|
17
|
-
import type {
|
|
9
|
+
import type {
|
|
10
|
+
PendingSwap,
|
|
11
|
+
PendingSwapStep,
|
|
12
|
+
SwapSavedSettings,
|
|
13
|
+
SwapStepRoute,
|
|
14
|
+
WalletTypeAndAddress,
|
|
15
|
+
} from 'rango-types';
|
|
18
16
|
|
|
19
17
|
import BigNumber from 'bignumber.js';
|
|
20
18
|
import {
|
|
@@ -86,107 +84,6 @@ export type EventType =
|
|
|
86
84
|
| 'route_failed_to_find'
|
|
87
85
|
| 'transaction_expired';
|
|
88
86
|
|
|
89
|
-
export type SwapSavedSettings = {
|
|
90
|
-
slippage: string;
|
|
91
|
-
disabledSwappersIds?: string[];
|
|
92
|
-
disabledSwappersGroups?: string[];
|
|
93
|
-
infiniteApprove?: boolean;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
type InternalStepState =
|
|
97
|
-
| 'PENDING'
|
|
98
|
-
| 'CREATED'
|
|
99
|
-
| 'WAITING'
|
|
100
|
-
| 'SIGNED'
|
|
101
|
-
| 'SUCCESSED'
|
|
102
|
-
| 'FAILED';
|
|
103
|
-
|
|
104
|
-
export type SwapperStatusStep = {
|
|
105
|
-
name: string;
|
|
106
|
-
state: InternalStepState;
|
|
107
|
-
current: boolean;
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
export enum PendingSwapNetworkStatus {
|
|
111
|
-
WaitingForConnectingWallet = 'waitingForConnectingWallet',
|
|
112
|
-
WaitingForQueue = 'waitingForQueue',
|
|
113
|
-
WaitingForNetworkChange = 'waitingForNetworkChange',
|
|
114
|
-
NetworkChanged = 'networkChanged',
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export type SwapExplorerUrl = {
|
|
118
|
-
url: string;
|
|
119
|
-
description: string | null;
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
export type StepStatus =
|
|
123
|
-
| 'created'
|
|
124
|
-
| 'running'
|
|
125
|
-
| 'failed'
|
|
126
|
-
| 'success'
|
|
127
|
-
| 'waitingForApproval'
|
|
128
|
-
| 'approved';
|
|
129
|
-
|
|
130
|
-
export type PendingSwapStep = {
|
|
131
|
-
// routing data
|
|
132
|
-
id: number;
|
|
133
|
-
fromBlockchain: string;
|
|
134
|
-
fromSymbol: string;
|
|
135
|
-
fromSymbolAddress: string | null;
|
|
136
|
-
fromDecimals: number;
|
|
137
|
-
fromAmountPrecision: string | null;
|
|
138
|
-
fromAmountMinValue: string | null;
|
|
139
|
-
fromAmountMaxValue: string | null;
|
|
140
|
-
fromAmountRestrictionType: AmountRestrictionType | null;
|
|
141
|
-
fromLogo: string;
|
|
142
|
-
toBlockchain: string;
|
|
143
|
-
toSymbol: string;
|
|
144
|
-
toSymbolAddress: string | null;
|
|
145
|
-
toDecimals: number;
|
|
146
|
-
toLogo: string;
|
|
147
|
-
swapperId: string;
|
|
148
|
-
expectedOutputAmountHumanReadable: string | null;
|
|
149
|
-
startTransactionTime: number;
|
|
150
|
-
internalSteps: SwapperStatusStep[] | null;
|
|
151
|
-
estimatedTimeInSeconds: number | null;
|
|
152
|
-
|
|
153
|
-
// status data
|
|
154
|
-
status: StepStatus;
|
|
155
|
-
networkStatus: PendingSwapNetworkStatus | null;
|
|
156
|
-
executedTransactionId: string | null;
|
|
157
|
-
executedTransactionTime: string | null;
|
|
158
|
-
explorerUrl: SwapExplorerUrl[] | null;
|
|
159
|
-
diagnosisUrl: string | null;
|
|
160
|
-
outputAmount: string | null;
|
|
161
|
-
|
|
162
|
-
// txs data
|
|
163
|
-
cosmosTransaction: CosmosTransaction | null;
|
|
164
|
-
transferTransaction: TransferTransaction | null;
|
|
165
|
-
solanaTransaction: SolanaTransaction | null;
|
|
166
|
-
evmApprovalTransaction: EvmTransaction | null;
|
|
167
|
-
evmTransaction: EvmTransaction | null;
|
|
168
|
-
tronApprovalTransaction: TronTransaction | null;
|
|
169
|
-
tronTransaction: TronTransaction | null;
|
|
170
|
-
starknetApprovalTransaction: StarknetTransaction | null;
|
|
171
|
-
starknetTransaction: StarknetTransaction | null;
|
|
172
|
-
tonTransaction: TonTransaction | null;
|
|
173
|
-
|
|
174
|
-
/*
|
|
175
|
-
* missing fields in older versions
|
|
176
|
-
* keeping null for backward compatability
|
|
177
|
-
*/
|
|
178
|
-
swapperLogo: string | null;
|
|
179
|
-
swapperType: string | null;
|
|
180
|
-
fromBlockchainLogo: string | null;
|
|
181
|
-
toBlockchainLogo: string | null;
|
|
182
|
-
feeInUsd: string | null;
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
export type WalletTypeAndAddress = {
|
|
186
|
-
walletType: WalletType;
|
|
187
|
-
address: string;
|
|
188
|
-
};
|
|
189
|
-
|
|
190
87
|
export enum MessageSeverity {
|
|
191
88
|
error = 'error',
|
|
192
89
|
warning = 'warning',
|
|
@@ -196,28 +93,6 @@ export enum MessageSeverity {
|
|
|
196
93
|
|
|
197
94
|
export type SwapStatus = 'running' | 'failed' | 'success';
|
|
198
95
|
|
|
199
|
-
export type PendingSwap = {
|
|
200
|
-
creationTime: string;
|
|
201
|
-
finishTime: string | null;
|
|
202
|
-
requestId: string;
|
|
203
|
-
inputAmount: string;
|
|
204
|
-
status: SwapStatus;
|
|
205
|
-
isPaused: boolean;
|
|
206
|
-
extraMessage: string | null;
|
|
207
|
-
extraMessageSeverity: MessageSeverity | null;
|
|
208
|
-
extraMessageErrorCode: string | null;
|
|
209
|
-
extraMessageDetail: string | null | undefined;
|
|
210
|
-
networkStatusExtraMessage: string | null;
|
|
211
|
-
networkStatusExtraMessageDetail: string | null;
|
|
212
|
-
lastNotificationTime: string | null;
|
|
213
|
-
wallets: { [p: string]: WalletTypeAndAddress };
|
|
214
|
-
settings: SwapSavedSettings;
|
|
215
|
-
steps: PendingSwapStep[];
|
|
216
|
-
simulationResult: SimulationResult;
|
|
217
|
-
validateBalanceOrFee: boolean;
|
|
218
|
-
hasAlreadyProceededToSign?: boolean | null;
|
|
219
|
-
};
|
|
220
|
-
|
|
221
96
|
export const getCurrentBlockchainOfOrNull = (
|
|
222
97
|
swap: PendingSwap,
|
|
223
98
|
step: PendingSwapStep
|
|
@@ -358,8 +233,11 @@ export function getRelatedWallet(
|
|
|
358
233
|
|
|
359
234
|
export function getRelatedWalletOrNull(
|
|
360
235
|
swap: PendingSwap,
|
|
361
|
-
currentStep: PendingSwapStep
|
|
236
|
+
currentStep: PendingSwapStep | null
|
|
362
237
|
): WalletTypeAndAddress | null {
|
|
238
|
+
if (!currentStep) {
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
363
241
|
try {
|
|
364
242
|
return getRelatedWallet(swap, currentStep);
|
|
365
243
|
} catch (e) {
|
|
@@ -407,6 +285,49 @@ export function getUsdFeeOfStep(
|
|
|
407
285
|
return totalFeeInUsd;
|
|
408
286
|
}
|
|
409
287
|
|
|
288
|
+
function mapSwapStepToPendingSwapStep(
|
|
289
|
+
swap: SwapResult,
|
|
290
|
+
meta: Pick<MetaResponse, 'blockchains' | 'tokens'> | null
|
|
291
|
+
): SwapStepRoute {
|
|
292
|
+
return {
|
|
293
|
+
// from
|
|
294
|
+
fromBlockchain: swap.from.blockchain,
|
|
295
|
+
fromBlockchainLogo: swap.from.blockchainLogo,
|
|
296
|
+
fromLogo: swap.from.logo,
|
|
297
|
+
fromSymbol: swap.from.symbol,
|
|
298
|
+
fromSymbolAddress: swap.from.address,
|
|
299
|
+
fromDecimals: swap.from.decimals,
|
|
300
|
+
fromAmountPrecision: swap.fromAmountPrecision,
|
|
301
|
+
fromAmountMinValue: swap.fromAmountMinValue,
|
|
302
|
+
fromAmountMaxValue: swap.fromAmountMaxValue,
|
|
303
|
+
fromAmountRestrictionType: swap.fromAmountRestrictionType,
|
|
304
|
+
fromUsdPrice: swap.from.usdPrice,
|
|
305
|
+
|
|
306
|
+
// to
|
|
307
|
+
toBlockchain: swap.to.blockchain,
|
|
308
|
+
toBlockchainLogo: swap.to.blockchainLogo,
|
|
309
|
+
toSymbol: swap.to.symbol,
|
|
310
|
+
toSymbolAddress: swap.to.address,
|
|
311
|
+
toDecimals: swap.to.decimals,
|
|
312
|
+
toLogo: swap.to.logo,
|
|
313
|
+
toUsdPrice: swap.to.usdPrice,
|
|
314
|
+
|
|
315
|
+
// swapper
|
|
316
|
+
swapperId: swap.swapperId,
|
|
317
|
+
swapperLogo: swap.swapperLogo,
|
|
318
|
+
swapperType: swap.swapperType,
|
|
319
|
+
|
|
320
|
+
// route
|
|
321
|
+
expectedOutputAmountHumanReadable: swap.toAmount,
|
|
322
|
+
feeInUsd: meta
|
|
323
|
+
? // eslint-disable-next-line @typescript-eslint/no-magic-numbers
|
|
324
|
+
numberToString(getUsdFeeOfStep(swap, meta?.tokens), null, 8)
|
|
325
|
+
: null,
|
|
326
|
+
estimatedTimeInSeconds: swap.estimatedTimeInSeconds || null,
|
|
327
|
+
internalSteps: null,
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
|
|
410
331
|
export function calculatePendingSwap(
|
|
411
332
|
inputAmount: string,
|
|
412
333
|
bestRoute: BestRouteResponse,
|
|
@@ -440,44 +361,23 @@ export function calculatePendingSwap(
|
|
|
440
361
|
validateBalanceOrFee,
|
|
441
362
|
steps:
|
|
442
363
|
bestRoute.result?.swaps?.map((swap, index) => {
|
|
364
|
+
const stepRoute = mapSwapStepToPendingSwapStep(swap, meta);
|
|
443
365
|
return {
|
|
444
366
|
id: index + 1,
|
|
445
367
|
|
|
446
|
-
//
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
fromAmountRestrictionType: swap.fromAmountRestrictionType,
|
|
457
|
-
|
|
458
|
-
// to
|
|
459
|
-
toBlockchain: swap.to.blockchain,
|
|
460
|
-
toBlockchainLogo: swap.to.blockchainLogo,
|
|
461
|
-
toSymbol: swap.to.symbol,
|
|
462
|
-
toSymbolAddress: swap.to.address,
|
|
463
|
-
toDecimals: swap.to.decimals,
|
|
464
|
-
toLogo: swap.to.logo,
|
|
465
|
-
|
|
466
|
-
// swapper
|
|
467
|
-
swapperId: swap.swapperId,
|
|
468
|
-
swapperLogo: swap.swapperLogo,
|
|
469
|
-
swapperType: swap.swapperType,
|
|
470
|
-
|
|
471
|
-
// output, fee, timing
|
|
472
|
-
expectedOutputAmountHumanReadable: swap.toAmount,
|
|
473
|
-
outputAmount: '',
|
|
474
|
-
feeInUsd: meta
|
|
475
|
-
? // eslint-disable-next-line @typescript-eslint/no-magic-numbers
|
|
476
|
-
numberToString(getUsdFeeOfStep(swap, meta?.tokens), null, 8)
|
|
477
|
-
: null,
|
|
478
|
-
estimatedTimeInSeconds: swap.estimatedTimeInSeconds || null,
|
|
368
|
+
// route
|
|
369
|
+
...stepRoute,
|
|
370
|
+
internalSwaps:
|
|
371
|
+
swap?.internalSwaps?.map((internalSwap) => {
|
|
372
|
+
const stepRoute = mapSwapStepToPendingSwapStep(
|
|
373
|
+
internalSwap,
|
|
374
|
+
meta
|
|
375
|
+
);
|
|
376
|
+
return stepRoute;
|
|
377
|
+
}) || null,
|
|
479
378
|
|
|
480
379
|
// status, tracking
|
|
380
|
+
outputAmount: '',
|
|
481
381
|
status: 'created',
|
|
482
382
|
networkStatus: null,
|
|
483
383
|
startTransactionTime: new Date().getTime(),
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Wallet } from './shared';
|
|
2
2
|
import type {
|
|
3
3
|
QueueContext,
|
|
4
4
|
QueueDef,
|
|
@@ -16,6 +16,8 @@ import type { Transaction } from 'rango-sdk';
|
|
|
16
16
|
import type {
|
|
17
17
|
APIErrorCode,
|
|
18
18
|
EvmBlockchainMeta,
|
|
19
|
+
PendingSwap,
|
|
20
|
+
PendingSwapStep,
|
|
19
21
|
SignerFactory,
|
|
20
22
|
} from 'rango-types';
|
|
21
23
|
|