@rango-dev/queue-manager-rango-preset 0.1.10-next.77
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/dist/actions/checkStatus.d.ts +12 -0
- package/dist/actions/checkStatus.d.ts.map +1 -0
- package/dist/actions/createTransaction.d.ts +11 -0
- package/dist/actions/createTransaction.d.ts.map +1 -0
- package/dist/actions/executeTransaction.d.ts +13 -0
- package/dist/actions/executeTransaction.d.ts.map +1 -0
- package/dist/actions/scheduleNextStep.d.ts +13 -0
- package/dist/actions/scheduleNextStep.d.ts.map +1 -0
- package/dist/actions/start.d.ts +4 -0
- package/dist/actions/start.d.ts.map +1 -0
- package/dist/constants.d.ts +9 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/helpers.d.ts +159 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/hooks.d.ts +19 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/migration.d.ts +15 -0
- package/dist/migration.d.ts.map +1 -0
- package/dist/queue-manager-rango-preset.cjs.development.js +2249 -0
- package/dist/queue-manager-rango-preset.cjs.development.js.map +1 -0
- package/dist/queue-manager-rango-preset.cjs.production.min.js +2 -0
- package/dist/queue-manager-rango-preset.cjs.production.min.js.map +1 -0
- package/dist/queue-manager-rango-preset.esm.js +2242 -0
- package/dist/queue-manager-rango-preset.esm.js.map +1 -0
- package/dist/queueDef.d.ts +10 -0
- package/dist/queueDef.d.ts.map +1 -0
- package/dist/shared-api.d.ts +10 -0
- package/dist/shared-api.d.ts.map +1 -0
- package/dist/shared-errors.d.ts +56 -0
- package/dist/shared-errors.d.ts.map +1 -0
- package/dist/shared-sentry.d.ts +4 -0
- package/dist/shared-sentry.d.ts.map +1 -0
- package/dist/shared.d.ts +149 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/types.d.ts +46 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +59 -0
- package/readme.md +9 -0
- package/src/actions/checkStatus.ts +213 -0
- package/src/actions/createTransaction.ts +101 -0
- package/src/actions/executeTransaction.ts +117 -0
- package/src/actions/scheduleNextStep.ts +60 -0
- package/src/actions/start.ts +10 -0
- package/src/constants.ts +23 -0
- package/src/helpers.ts +1252 -0
- package/src/hooks.ts +75 -0
- package/src/index.ts +39 -0
- package/src/migration.ts +112 -0
- package/src/queueDef.ts +39 -0
- package/src/shared-api.ts +175 -0
- package/src/shared-errors.ts +156 -0
- package/src/shared-sentry.ts +24 -0
- package/src/shared.ts +333 -0
- package/src/types.ts +76 -0
package/src/shared.ts
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Network,
|
|
3
|
+
Transaction,
|
|
4
|
+
TransferTransaction,
|
|
5
|
+
WalletError,
|
|
6
|
+
WalletType,
|
|
7
|
+
} from '@rango-dev/wallets-shared';
|
|
8
|
+
import {
|
|
9
|
+
CosmosTransaction,
|
|
10
|
+
EvmBlockchainMeta,
|
|
11
|
+
EvmTransaction,
|
|
12
|
+
SimulationResult,
|
|
13
|
+
SolanaTransaction,
|
|
14
|
+
StarknetTransaction,
|
|
15
|
+
TronTransaction,
|
|
16
|
+
} from 'rango-sdk';
|
|
17
|
+
import { BigNumber } from 'bignumber.js';
|
|
18
|
+
|
|
19
|
+
import { ErrorDetail, PrettyError } from './shared-errors';
|
|
20
|
+
import { getRelatedWallet } from './helpers';
|
|
21
|
+
|
|
22
|
+
export type SwapperStatusResponse = {
|
|
23
|
+
status: 'running' | 'failed' | 'success' | null;
|
|
24
|
+
extraMessage: string | null;
|
|
25
|
+
timestamp: number;
|
|
26
|
+
outputAmount: BigNumber | null;
|
|
27
|
+
explorerUrl: SwapExplorerUrl[] | null;
|
|
28
|
+
trackingCode: string;
|
|
29
|
+
newTx: Transaction | null;
|
|
30
|
+
diagnosisUrl: string | null;
|
|
31
|
+
steps: SwapperStatusStep[] | null;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type SwapProgressNotification = {
|
|
35
|
+
eventType: EventType;
|
|
36
|
+
swap: PendingSwap | null;
|
|
37
|
+
step: PendingSwapStep | null;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type WalletBalance = {
|
|
41
|
+
chain: Network;
|
|
42
|
+
symbol: string;
|
|
43
|
+
ticker: string;
|
|
44
|
+
address: string | null;
|
|
45
|
+
rawAmount: string;
|
|
46
|
+
decimal: number | null;
|
|
47
|
+
amount: string;
|
|
48
|
+
logo: string | null;
|
|
49
|
+
usdPrice: number | null;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export type Account = {
|
|
53
|
+
balances: WalletBalance[] | null;
|
|
54
|
+
address: string;
|
|
55
|
+
loading: boolean;
|
|
56
|
+
walletType: WalletType;
|
|
57
|
+
error: boolean;
|
|
58
|
+
explorerUrl: string | null;
|
|
59
|
+
isConnected: boolean;
|
|
60
|
+
};
|
|
61
|
+
export type Blockchain = { name: string; accounts: Account[] };
|
|
62
|
+
export type Wallet = { blockchains: Blockchain[] };
|
|
63
|
+
|
|
64
|
+
export type EventType =
|
|
65
|
+
| 'swap_started'
|
|
66
|
+
| 'confirm_contract'
|
|
67
|
+
| 'confirm_transfer'
|
|
68
|
+
| 'task_failed'
|
|
69
|
+
| 'task_completed'
|
|
70
|
+
| 'task_canceled'
|
|
71
|
+
| 'task_paused'
|
|
72
|
+
| 'contract_confirmed'
|
|
73
|
+
| 'contract_rejected'
|
|
74
|
+
| 'transfer_confirmed'
|
|
75
|
+
| 'transfer_rejected'
|
|
76
|
+
| 'calling_smart_contract'
|
|
77
|
+
| 'smart_contract_called'
|
|
78
|
+
| 'smart_contract_call_failed'
|
|
79
|
+
| 'step_completed_with_output'
|
|
80
|
+
| 'waiting_for_network_change'
|
|
81
|
+
| 'waiting_for_connecting_wallet'
|
|
82
|
+
| 'network_changed'
|
|
83
|
+
| 'not_enough_balance'
|
|
84
|
+
| 'check_fee_failed'
|
|
85
|
+
| 'route_failed_to_find';
|
|
86
|
+
|
|
87
|
+
export type SwapSavedSettings = {
|
|
88
|
+
slippage: string;
|
|
89
|
+
disabledSwappersIds: string[];
|
|
90
|
+
disabledSwappersGroups: string[];
|
|
91
|
+
infiniteApprove: boolean;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
type InternalStepState =
|
|
95
|
+
| 'PENDING'
|
|
96
|
+
| 'CREATED'
|
|
97
|
+
| 'WAITING'
|
|
98
|
+
| 'SIGNED'
|
|
99
|
+
| 'SUCCESSED'
|
|
100
|
+
| 'FAILED';
|
|
101
|
+
|
|
102
|
+
export type SwapperStatusStep = {
|
|
103
|
+
name: string;
|
|
104
|
+
state: InternalStepState;
|
|
105
|
+
current: boolean;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export enum PendingSwapNetworkStatus {
|
|
109
|
+
WaitingForConnectingWallet = 'waitingForConnectingWallet',
|
|
110
|
+
WaitingForQueue = 'waitingForQueue',
|
|
111
|
+
WaitingForNetworkChange = 'waitingForNetworkChange',
|
|
112
|
+
NetworkChanged = 'networkChanged',
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export type SwapExplorerUrl = {
|
|
116
|
+
url: string;
|
|
117
|
+
description: string | null;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export type SwapperId =
|
|
121
|
+
| 'ThorChain'
|
|
122
|
+
| 'OneInchEth'
|
|
123
|
+
| 'Binance Bridge'
|
|
124
|
+
| 'OneInchBsc'
|
|
125
|
+
| 'OneInchPolygon'
|
|
126
|
+
| 'Terra Bridge'
|
|
127
|
+
| 'TerraSwap'
|
|
128
|
+
| 'Osmosis'
|
|
129
|
+
| 'Lido'
|
|
130
|
+
| 'PoS Bridge'
|
|
131
|
+
| 'Wormhole';
|
|
132
|
+
|
|
133
|
+
export type StepStatus =
|
|
134
|
+
| 'created'
|
|
135
|
+
| 'running'
|
|
136
|
+
| 'failed'
|
|
137
|
+
| 'success'
|
|
138
|
+
| 'waitingForApproval'
|
|
139
|
+
| 'approved';
|
|
140
|
+
|
|
141
|
+
export type PendingSwapStep = {
|
|
142
|
+
id: number;
|
|
143
|
+
fromBlockchain: Network;
|
|
144
|
+
fromSymbol: string;
|
|
145
|
+
fromSymbolAddress: string | null;
|
|
146
|
+
fromDecimals: number;
|
|
147
|
+
fromAmountPrecision: number | null;
|
|
148
|
+
fromAmountMinValue: number | null;
|
|
149
|
+
fromAmountMaxValue: number | null;
|
|
150
|
+
fromLogo: string;
|
|
151
|
+
toBlockchain: string;
|
|
152
|
+
toSymbol: string;
|
|
153
|
+
toSymbolAddress: string | null;
|
|
154
|
+
toDecimals: number;
|
|
155
|
+
toLogo: string;
|
|
156
|
+
swapperId: SwapperId;
|
|
157
|
+
expectedOutputAmountHumanReadable: string | null;
|
|
158
|
+
startTransactionTime: number;
|
|
159
|
+
outputAmount: string | null;
|
|
160
|
+
status: StepStatus;
|
|
161
|
+
networkStatus: PendingSwapNetworkStatus | null;
|
|
162
|
+
executedTransactionId: string | null;
|
|
163
|
+
explorerUrl: SwapExplorerUrl[] | null;
|
|
164
|
+
evmApprovalTransaction: EvmTransaction | null;
|
|
165
|
+
evmTransaction: EvmTransaction | null;
|
|
166
|
+
cosmosTransaction: CosmosTransaction | null;
|
|
167
|
+
transferTransaction: TransferTransaction | null;
|
|
168
|
+
solanaTransaction: SolanaTransaction | null;
|
|
169
|
+
starknetTransaction: StarknetTransaction | null;
|
|
170
|
+
starknetApprovalTransaction: StarknetTransaction | null;
|
|
171
|
+
tronTransaction: TronTransaction | null;
|
|
172
|
+
tronApprovalTransaction: TronTransaction | null;
|
|
173
|
+
diagnosisUrl: string | null;
|
|
174
|
+
internalSteps: SwapperStatusStep[] | null;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
export type WalletTypeAndAddress = {
|
|
178
|
+
walletType: WalletType;
|
|
179
|
+
address: string;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
export enum MessageSeverity {
|
|
183
|
+
error = 'error',
|
|
184
|
+
warning = 'warning',
|
|
185
|
+
info = 'info',
|
|
186
|
+
success = 'success',
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export type SwapStatus = 'running' | 'failed' | 'success';
|
|
190
|
+
|
|
191
|
+
export type PendingSwap = {
|
|
192
|
+
creationTime: string;
|
|
193
|
+
finishTime: string | null;
|
|
194
|
+
requestId: string;
|
|
195
|
+
inputAmount: string;
|
|
196
|
+
status: SwapStatus;
|
|
197
|
+
isPaused: boolean;
|
|
198
|
+
extraMessage: string | null;
|
|
199
|
+
extraMessageSeverity: MessageSeverity | null;
|
|
200
|
+
extraMessageErrorCode: string | null;
|
|
201
|
+
extraMessageDetail: string | null | undefined;
|
|
202
|
+
networkStatusExtraMessage: string | null;
|
|
203
|
+
networkStatusExtraMessageDetail: string | null;
|
|
204
|
+
lastNotificationTime: string | null;
|
|
205
|
+
wallets: { [p: string]: WalletTypeAndAddress };
|
|
206
|
+
settings: SwapSavedSettings;
|
|
207
|
+
steps: PendingSwapStep[];
|
|
208
|
+
simulationResult: SimulationResult;
|
|
209
|
+
validateBalanceOrFee: boolean;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
export const getCurrentBlockchainOfOrNull = (
|
|
213
|
+
swap: PendingSwap,
|
|
214
|
+
step: PendingSwapStep
|
|
215
|
+
): Network | null => {
|
|
216
|
+
try {
|
|
217
|
+
return getCurrentBlockchainOf(swap, step);
|
|
218
|
+
} catch (e) {
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
export const getCurrentBlockchainOf = (
|
|
224
|
+
swap: PendingSwap,
|
|
225
|
+
step: PendingSwapStep
|
|
226
|
+
): Network => {
|
|
227
|
+
const b1 =
|
|
228
|
+
step.evmTransaction?.blockChain ||
|
|
229
|
+
step.evmApprovalTransaction?.blockChain ||
|
|
230
|
+
step.starknetTransaction?.blockChain ||
|
|
231
|
+
step.starknetApprovalTransaction?.blockChain ||
|
|
232
|
+
step.tronTransaction?.blockChain ||
|
|
233
|
+
step.tronApprovalTransaction?.blockChain ||
|
|
234
|
+
step.cosmosTransaction?.blockChain ||
|
|
235
|
+
step.solanaTransaction?.blockChain;
|
|
236
|
+
if (!!b1) return b1 as Network;
|
|
237
|
+
|
|
238
|
+
const transferAddress = step.transferTransaction?.fromWalletAddress;
|
|
239
|
+
if (!transferAddress) throw PrettyError.BlockchainMissing();
|
|
240
|
+
|
|
241
|
+
const blockchain =
|
|
242
|
+
Object.keys(swap.wallets).find(
|
|
243
|
+
(b) => swap.wallets[b]?.address === transferAddress
|
|
244
|
+
) || null;
|
|
245
|
+
if (blockchain == null) throw PrettyError.BlockchainMissing();
|
|
246
|
+
|
|
247
|
+
// TODO: check why it returns string
|
|
248
|
+
return blockchain as Network;
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
export const getEvmApproveUrl = (
|
|
252
|
+
tx: string,
|
|
253
|
+
network: Network,
|
|
254
|
+
evmBasedBlockchains: EvmBlockchainMeta[]
|
|
255
|
+
): string => {
|
|
256
|
+
const evmBlochain = evmBasedBlockchains.find(
|
|
257
|
+
(blockchain) => blockchain.name === network
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
if (!evmBlochain) {
|
|
261
|
+
throw Error(`unsupported network: ${network} for getting approve url.`);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (evmBlochain.info.transactionUrl)
|
|
265
|
+
return evmBlochain.info.transactionUrl.replace(
|
|
266
|
+
'{txHash}',
|
|
267
|
+
tx.toLowerCase()
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
throw Error(`Explorer url for ${network} is not implemented`);
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
export const prettifyErrorMessage = (obj: unknown): ErrorDetail => {
|
|
274
|
+
if (!obj) return { extraMessage: '', extraMessageErrorCode: null };
|
|
275
|
+
if (obj instanceof PrettyError) return obj.getErrorDetail();
|
|
276
|
+
if (obj instanceof WalletError) {
|
|
277
|
+
const t = obj.getErrorDetail();
|
|
278
|
+
return {
|
|
279
|
+
extraMessage: t.message,
|
|
280
|
+
extraMessageDetail: t.detail,
|
|
281
|
+
extraMessageErrorCode: t.code,
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
if (obj instanceof Error)
|
|
285
|
+
return {
|
|
286
|
+
extraMessage: obj.toString(),
|
|
287
|
+
extraMessageErrorCode: null,
|
|
288
|
+
};
|
|
289
|
+
if (typeof obj !== 'string')
|
|
290
|
+
return {
|
|
291
|
+
extraMessage: JSON.stringify(obj),
|
|
292
|
+
extraMessageErrorCode: null,
|
|
293
|
+
};
|
|
294
|
+
return { extraMessage: obj, extraMessageErrorCode: null };
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
export function getCookieId(): string {
|
|
298
|
+
const key = 'X-Rango-Id';
|
|
299
|
+
const cookieId = window.localStorage.getItem(key);
|
|
300
|
+
if (cookieId) {
|
|
301
|
+
return cookieId;
|
|
302
|
+
}
|
|
303
|
+
const value =
|
|
304
|
+
Math.random().toString(36).substring(2, 15) +
|
|
305
|
+
Math.random().toString(36).substring(2, 15);
|
|
306
|
+
window.localStorage.setItem(key, value);
|
|
307
|
+
return value;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export function getNextStep(
|
|
311
|
+
swap: PendingSwap,
|
|
312
|
+
currentStep: PendingSwapStep
|
|
313
|
+
): PendingSwapStep | null {
|
|
314
|
+
return (
|
|
315
|
+
swap.steps.find(
|
|
316
|
+
(step) =>
|
|
317
|
+
step.status !== 'failed' &&
|
|
318
|
+
step.status !== 'success' &&
|
|
319
|
+
step.id !== currentStep.id
|
|
320
|
+
) || null
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
export function getRelatedWalletOrNull(
|
|
325
|
+
swap: PendingSwap,
|
|
326
|
+
currentStep: PendingSwapStep
|
|
327
|
+
): WalletTypeAndAddress | null {
|
|
328
|
+
try {
|
|
329
|
+
return getRelatedWallet(swap, currentStep);
|
|
330
|
+
} catch (e) {
|
|
331
|
+
return null;
|
|
332
|
+
}
|
|
333
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { QueueStorage, QueueDef } from '@rango-dev/queue-manager-core';
|
|
2
|
+
import { QueueContext } from '@rango-dev/queue-manager-core/dist/queue';
|
|
3
|
+
import { ConnectResult, Providers } from '@rango-dev/wallets-core';
|
|
4
|
+
import {
|
|
5
|
+
EvmBlockchainMeta,
|
|
6
|
+
Meta,
|
|
7
|
+
Network,
|
|
8
|
+
WalletSigners,
|
|
9
|
+
WalletState,
|
|
10
|
+
WalletType,
|
|
11
|
+
} from '@rango-dev/wallets-shared';
|
|
12
|
+
import { PendingSwap, SwapProgressNotification, Wallet } from './shared';
|
|
13
|
+
|
|
14
|
+
export type SwapQueueDef = QueueDef<
|
|
15
|
+
SwapStorage,
|
|
16
|
+
SwapActionTypes,
|
|
17
|
+
SwapQueueContext
|
|
18
|
+
>;
|
|
19
|
+
|
|
20
|
+
export interface SwapStorage extends QueueStorage {
|
|
21
|
+
swapDetails: PendingSwap;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export enum SwapActionTypes {
|
|
25
|
+
START = 'START',
|
|
26
|
+
SCHEDULE_NEXT_STEP = 'SCHEDULE_NEXT_STEP',
|
|
27
|
+
CREATE_TRANSACTION = 'CREATE_TRANSACTION',
|
|
28
|
+
EXECUTE_TRANSACTION = 'EXECUTE_TRANSACTION',
|
|
29
|
+
CHECK_TRANSACTION_STATUS = 'CHECK_TRANSACTION_STATUS',
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type GetCurrentAddress = (
|
|
33
|
+
type: WalletType,
|
|
34
|
+
network: Network
|
|
35
|
+
) => string | undefined;
|
|
36
|
+
|
|
37
|
+
export enum BlockReason {
|
|
38
|
+
WAIT_FOR_CONNECT_WALLET = 'waiting_for_connecting_wallet',
|
|
39
|
+
WAIT_FOR_NETWORK_CHANGE = 'waiting_for_network_change',
|
|
40
|
+
DEPENDS_ON_OTHER_QUEUES = 'depends_on_other_queues',
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
|
+
export interface Block<T = any> {
|
|
45
|
+
reason: BlockReason;
|
|
46
|
+
description: string;
|
|
47
|
+
details?: T;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface SwapQueueContext extends QueueContext {
|
|
51
|
+
meta: Meta;
|
|
52
|
+
wallets: Wallet | null;
|
|
53
|
+
providers: Providers;
|
|
54
|
+
getSigners: (type: WalletType) => WalletSigners;
|
|
55
|
+
switchNetwork: (
|
|
56
|
+
wallet: WalletType,
|
|
57
|
+
network: Network
|
|
58
|
+
) => Promise<ConnectResult> | undefined;
|
|
59
|
+
connect: (
|
|
60
|
+
wallet: WalletType,
|
|
61
|
+
network: Network
|
|
62
|
+
) => Promise<ConnectResult> | undefined;
|
|
63
|
+
state: (type: WalletType) => WalletState;
|
|
64
|
+
notifier: (data: SwapProgressNotification) => void;
|
|
65
|
+
|
|
66
|
+
// Dynamically will be added to context.
|
|
67
|
+
claimedBy?: string;
|
|
68
|
+
resetClaimedBy?: () => void;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface UseQueueManagerParams {
|
|
72
|
+
lastConnectedWallet: string;
|
|
73
|
+
disconnectedWallet: WalletType | undefined;
|
|
74
|
+
clearDisconnectedWallet: () => void;
|
|
75
|
+
evmChains: EvmBlockchainMeta[];
|
|
76
|
+
}
|