@rango-dev/queue-manager-rango-preset 0.0.0-experimental-936229e8-20251208

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.
Files changed (75) hide show
  1. package/CHANGELOG.md +353 -0
  2. package/dist/actions/checkStatus.d.ts +13 -0
  3. package/dist/actions/checkStatus.d.ts.map +1 -0
  4. package/dist/actions/common/checkEnvironmentBeforeExecuteTransaction.d.ts +8 -0
  5. package/dist/actions/common/checkEnvironmentBeforeExecuteTransaction.d.ts.map +1 -0
  6. package/dist/actions/common/produceNextStateForTransaction.d.ts +17 -0
  7. package/dist/actions/common/produceNextStateForTransaction.d.ts.map +1 -0
  8. package/dist/actions/common/utils.d.ts +5 -0
  9. package/dist/actions/common/utils.d.ts.map +1 -0
  10. package/dist/actions/createTransaction.d.ts +12 -0
  11. package/dist/actions/createTransaction.d.ts.map +1 -0
  12. package/dist/actions/executeTransaction/executeTransaction.d.ts +14 -0
  13. package/dist/actions/executeTransaction/executeTransaction.d.ts.map +1 -0
  14. package/dist/actions/executeTransaction/index.d.ts +2 -0
  15. package/dist/actions/executeTransaction/index.d.ts.map +1 -0
  16. package/dist/actions/scheduleNextStep.d.ts +14 -0
  17. package/dist/actions/scheduleNextStep.d.ts.map +1 -0
  18. package/dist/actions/start.d.ts +4 -0
  19. package/dist/actions/start.d.ts.map +1 -0
  20. package/dist/configs.d.ts +14 -0
  21. package/dist/configs.d.ts.map +1 -0
  22. package/dist/constants.d.ts +7 -0
  23. package/dist/constants.d.ts.map +1 -0
  24. package/dist/helpers.d.ts +255 -0
  25. package/dist/helpers.d.ts.map +1 -0
  26. package/dist/hooks.d.ts +19 -0
  27. package/dist/hooks.d.ts.map +1 -0
  28. package/dist/index.d.ts +11 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +2 -0
  31. package/dist/index.js.map +7 -0
  32. package/dist/migration.d.ts +15 -0
  33. package/dist/migration.d.ts.map +1 -0
  34. package/dist/numbers.d.ts +3 -0
  35. package/dist/numbers.d.ts.map +1 -0
  36. package/dist/queue-manager-rango-preset.build.json +1 -0
  37. package/dist/queueDef.d.ts +10 -0
  38. package/dist/queueDef.d.ts.map +1 -0
  39. package/dist/services/eventEmitter.d.ts +10 -0
  40. package/dist/services/eventEmitter.d.ts.map +1 -0
  41. package/dist/services/httpService.d.ts +3 -0
  42. package/dist/services/httpService.d.ts.map +1 -0
  43. package/dist/services/index.d.ts +2 -0
  44. package/dist/services/index.d.ts.map +1 -0
  45. package/dist/shared-errors.d.ts +25 -0
  46. package/dist/shared-errors.d.ts.map +1 -0
  47. package/dist/shared.d.ts +81 -0
  48. package/dist/shared.d.ts.map +1 -0
  49. package/dist/types.d.ts +172 -0
  50. package/dist/types.d.ts.map +1 -0
  51. package/package.json +45 -0
  52. package/readme.md +2 -0
  53. package/src/actions/checkStatus.ts +564 -0
  54. package/src/actions/common/checkEnvironmentBeforeExecuteTransaction.ts +157 -0
  55. package/src/actions/common/produceNextStateForTransaction.ts +167 -0
  56. package/src/actions/common/utils.ts +25 -0
  57. package/src/actions/createTransaction.ts +117 -0
  58. package/src/actions/executeTransaction/executeTransaction.ts +107 -0
  59. package/src/actions/executeTransaction/index.ts +1 -0
  60. package/src/actions/scheduleNextStep.ts +104 -0
  61. package/src/actions/start.ts +16 -0
  62. package/src/configs.ts +38 -0
  63. package/src/constants.ts +18 -0
  64. package/src/helpers.ts +1598 -0
  65. package/src/hooks.ts +94 -0
  66. package/src/index.ts +68 -0
  67. package/src/migration.ts +124 -0
  68. package/src/numbers.ts +68 -0
  69. package/src/queueDef.ts +39 -0
  70. package/src/services/eventEmitter.ts +290 -0
  71. package/src/services/httpService.ts +10 -0
  72. package/src/services/index.ts +1 -0
  73. package/src/shared-errors.ts +165 -0
  74. package/src/shared.ts +473 -0
  75. package/src/types.ts +305 -0
package/src/types.ts ADDED
@@ -0,0 +1,305 @@
1
+ import type { TargetNamespace, Wallet } from './shared';
2
+ import type {
3
+ QueueContext,
4
+ QueueDef,
5
+ QueueStorage,
6
+ } from '@rango-dev/queue-manager-core';
7
+ import type { Provider } from '@rango-dev/wallets-core';
8
+ import type { LegacyConnectResult as ConnectResult } from '@rango-dev/wallets-core/legacy';
9
+ import type {
10
+ Meta,
11
+ Network,
12
+ Providers,
13
+ WalletState,
14
+ WalletType,
15
+ } from '@rango-dev/wallets-shared';
16
+ import type { Transaction } from 'rango-sdk';
17
+ import type {
18
+ APIErrorCode,
19
+ EvmBlockchainMeta,
20
+ PendingSwap,
21
+ PendingSwapStep,
22
+ SignerFactory,
23
+ } from 'rango-types';
24
+
25
+ export type RemoveNameField<T, U extends string> = {
26
+ [Property in keyof T as Exclude<Property, U>]: T[Property];
27
+ };
28
+
29
+ export type ArrayElement<A> = A extends readonly (infer T)[] ? T : never;
30
+
31
+ export type SwapQueueDef = QueueDef<
32
+ SwapStorage,
33
+ SwapActionTypes,
34
+ SwapQueueContext
35
+ >;
36
+
37
+ export interface SwapStorage extends QueueStorage {
38
+ swapDetails: PendingSwap;
39
+ }
40
+
41
+ export enum SwapActionTypes {
42
+ START = 'START',
43
+ SCHEDULE_NEXT_STEP = 'SCHEDULE_NEXT_STEP',
44
+ CREATE_TRANSACTION = 'CREATE_TRANSACTION',
45
+ EXECUTE_TRANSACTION = 'EXECUTE_TRANSACTION',
46
+ CHECK_TRANSACTION_STATUS = 'CHECK_TRANSACTION_STATUS',
47
+ }
48
+
49
+ export type GetCurrentAddress = (
50
+ type: WalletType,
51
+ network: Network
52
+ ) => string | undefined;
53
+
54
+ export enum BlockReason {
55
+ WAIT_FOR_CONNECT_WALLET = 'waiting_for_connecting_wallet',
56
+ WAIT_FOR_NETWORK_CHANGE = 'waiting_for_network_change',
57
+ DEPENDS_ON_OTHER_QUEUES = 'depends_on_other_queues',
58
+ }
59
+
60
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
61
+ export interface Block<T = any> {
62
+ reason: BlockReason;
63
+ description: string;
64
+ details?: T;
65
+ }
66
+
67
+ export interface SwapQueueContext extends QueueContext {
68
+ meta: Meta;
69
+ wallets: Wallet | null;
70
+ providers: Providers;
71
+ hubProvider: (type: WalletType) => Provider;
72
+ getSigners: (type: WalletType) => Promise<SignerFactory>;
73
+ switchNetwork: (
74
+ wallet: WalletType,
75
+ namespaces: TargetNamespace
76
+ ) => Promise<ConnectResult | ConnectResult[] | undefined> | undefined;
77
+ canSwitchNetworkTo: UseQueueManagerParams['canSwitchNetworkTo'];
78
+ state: (type: WalletType) => WalletState;
79
+ isMobileWallet: (type: WalletType) => boolean;
80
+
81
+ // Dynamically will be added to context.
82
+ claimedBy?: string;
83
+ resetClaimedBy?: () => void;
84
+ }
85
+
86
+ export type LastConnectedWallet = {
87
+ walletType: string;
88
+ network?: string;
89
+ accounts?: string[];
90
+ };
91
+
92
+ export interface UseQueueManagerParams {
93
+ lastConnectedWallet: LastConnectedWallet | null;
94
+ disconnectedWallet: WalletType | undefined;
95
+ clearDisconnectedWallet: () => void;
96
+ evmChains: EvmBlockchainMeta[];
97
+ canSwitchNetworkTo: (
98
+ type: WalletType,
99
+ network: Network,
100
+ namespace: TargetNamespace
101
+ ) => boolean;
102
+ }
103
+
104
+ export enum WidgetEvents {
105
+ RouteEvent = 'routeEvent',
106
+ StepEvent = 'stepEvent',
107
+ }
108
+
109
+ export type Step = Pick<
110
+ PendingSwapStep,
111
+ | 'diagnosisUrl'
112
+ | 'estimatedTimeInSeconds'
113
+ | 'explorerUrl'
114
+ | 'feeInUsd'
115
+ | 'executedTransactionId'
116
+ | 'executedTransactionTime'
117
+ | 'expectedOutputAmountHumanReadable'
118
+ | 'fromBlockchain'
119
+ | 'toBlockchain'
120
+ | 'fromSymbol'
121
+ | 'toSymbol'
122
+ | 'toSymbolAddress'
123
+ | 'fromSymbolAddress'
124
+ | 'swapperType'
125
+ | 'outputAmount'
126
+ | 'fromAmountMaxValue'
127
+ | 'fromAmountMinValue'
128
+ | 'fromAmountPrecision'
129
+ | 'fromAmountRestrictionType'
130
+ | 'fromDecimals'
131
+ | 'status'
132
+ > & { swapperName: string; transaction: Transaction | null };
133
+
134
+ export type Route = Pick<
135
+ PendingSwap,
136
+ | 'creationTime'
137
+ | 'finishTime'
138
+ | 'requestId'
139
+ | 'inputAmount'
140
+ | 'status'
141
+ | 'wallets'
142
+ > & { steps: Step[]; slippage: string; infiniteApproval?: boolean };
143
+
144
+ export type SwapEvent = RouteEvent | StepEvent;
145
+
146
+ export enum RouteEventType {
147
+ STARTED = 'started',
148
+ FAILED = 'failed',
149
+ SUCCEEDED = 'succeeded',
150
+ }
151
+
152
+ export enum StepExecutionEventStatus {
153
+ CREATE_TX = 'create_tx',
154
+ SEND_TX = 'send_tx',
155
+ TX_SENT = 'tx_sent',
156
+ }
157
+
158
+ export enum StepExecutionBlockedEventStatus {
159
+ WAITING_FOR_QUEUE = 'waiting_for_queue',
160
+ WAITING_FOR_WALLET_CONNECT = 'waiting_for_wallet_connect',
161
+ WAITING_FOR_NETWORK_CHANGE = 'waiting_for_network_change',
162
+ WAITING_FOR_CHANGE_WALLET_ACCOUNT = 'waiting_for_change_wallet_account',
163
+ }
164
+
165
+ export enum StepEventType {
166
+ STARTED = 'started',
167
+ FAILED = 'failed',
168
+ SUCCEEDED = 'succeeded',
169
+ TX_EXECUTION = 'tx_execution',
170
+ TX_EXECUTION_BLOCKED = 'tx_execution_blocked',
171
+ APPROVAL_TX_SUCCEEDED = 'approval_tx_succeeded',
172
+ CHECK_STATUS = 'check_status',
173
+ OUTPUT_REVEALED = 'output_revealed',
174
+ }
175
+
176
+ export enum EventSeverity {
177
+ ERROR = 'error',
178
+ SUCCESS = 'success',
179
+ WARNING = 'warning',
180
+ INFO = 'info',
181
+ }
182
+
183
+ export type Event<
184
+ T extends StepEventType | RouteEventType,
185
+ U extends Record<string, unknown> = Record<string, unknown>
186
+ > = {
187
+ type: T;
188
+ message: string;
189
+ messageSeverity: EventSeverity;
190
+ } & U;
191
+
192
+ export type FailedRouteEventPayload = {
193
+ inputAmount: string;
194
+ inputAmountUsd: string;
195
+ reason?: string;
196
+ reasonCode: APIErrorCode;
197
+ swapMode: 'swap' | 'refuel';
198
+ };
199
+
200
+ export type FailedStepEventPayload = Omit<FailedRouteEventPayload, 'swapMode'>;
201
+
202
+ export type SucceededRouteEventPayload = {
203
+ inputAmount: string;
204
+ inputAmountUsd: string;
205
+ outputAmount: string;
206
+ outputAmountUsd: string;
207
+ swapMode: 'swap' | 'refuel';
208
+ };
209
+
210
+ export type SucceededStepEventPayload = Omit<
211
+ SucceededRouteEventPayload,
212
+ 'swapMode'
213
+ >;
214
+
215
+ export type OutputRevealedEventPayload = { outputAmount: string };
216
+
217
+ export type StepExecutionEventPayload = {
218
+ status:
219
+ | StepExecutionEventStatus.CREATE_TX
220
+ | StepExecutionEventStatus.SEND_TX
221
+ | StepExecutionEventStatus.TX_SENT;
222
+ };
223
+
224
+ export type StepBlockedEventPayload =
225
+ | { status: StepExecutionBlockedEventStatus.WAITING_FOR_QUEUE }
226
+ | {
227
+ status: StepExecutionBlockedEventStatus.WAITING_FOR_WALLET_CONNECT;
228
+ requiredWallet?: string;
229
+ requiredAccount?: string;
230
+ }
231
+ | {
232
+ status: StepExecutionBlockedEventStatus.WAITING_FOR_CHANGE_WALLET_ACCOUNT;
233
+ requiredAccount?: string;
234
+ }
235
+ | {
236
+ status: StepExecutionBlockedEventStatus.WAITING_FOR_NETWORK_CHANGE;
237
+ currentNetwork?: string;
238
+ requiredNetwork?: string;
239
+ };
240
+
241
+ export type RouteStartedEvent = Event<RouteEventType.STARTED>;
242
+
243
+ export type RouteFailedEvent = Event<
244
+ RouteEventType.FAILED,
245
+ FailedRouteEventPayload
246
+ >;
247
+
248
+ export type RouteSucceededEvent = Event<
249
+ RouteEventType.SUCCEEDED,
250
+ SucceededRouteEventPayload
251
+ >;
252
+
253
+ export type StepStartedEvent = Event<StepEventType.STARTED>;
254
+
255
+ export type StepSucceededEvent = Event<
256
+ StepEventType.SUCCEEDED,
257
+ SucceededStepEventPayload
258
+ >;
259
+ export type StepFailedEvent = Event<
260
+ StepEventType.FAILED,
261
+ FailedStepEventPayload
262
+ >;
263
+
264
+ export type StepTxExecutionUpdatedEvent = Event<
265
+ StepEventType.TX_EXECUTION,
266
+ StepExecutionEventPayload
267
+ >;
268
+
269
+ export type StepTxExecutionBlockedEvent = Event<
270
+ StepEventType.TX_EXECUTION_BLOCKED,
271
+ StepBlockedEventPayload
272
+ >;
273
+
274
+ export type StepCheckStatusEvent = Event<StepEventType.CHECK_STATUS>;
275
+
276
+ export type StepApprovalTxSucceededEvent =
277
+ Event<StepEventType.APPROVAL_TX_SUCCEEDED>;
278
+
279
+ export type StepOutputRevealedEvent = Event<
280
+ StepEventType.OUTPUT_REVEALED,
281
+ OutputRevealedEventPayload
282
+ >;
283
+
284
+ export type StepEvent =
285
+ | StepStartedEvent
286
+ | StepSucceededEvent
287
+ | StepFailedEvent
288
+ | StepTxExecutionUpdatedEvent
289
+ | StepTxExecutionBlockedEvent
290
+ | StepCheckStatusEvent
291
+ | StepApprovalTxSucceededEvent
292
+ | StepOutputRevealedEvent;
293
+
294
+ export type RouteEvent =
295
+ | RouteStartedEvent
296
+ | RouteSucceededEvent
297
+ | RouteFailedEvent;
298
+
299
+ export type RouteEventData = { route: Route; event: RouteEvent };
300
+ export type StepEventData = { route: Route; step: Step; event: StepEvent };
301
+
302
+ export type RouteExecutionEvents = {
303
+ [WidgetEvents.RouteEvent]: RouteEventData;
304
+ [WidgetEvents.StepEvent]: StepEventData;
305
+ };