@rango-dev/queue-manager-rango-preset 0.22.1-next.9 → 0.24.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 +4 -0
- package/dist/actions/executeTransaction.d.ts +2 -2
- package/dist/actions/executeTransaction.d.ts.map +1 -1
- package/dist/helpers.d.ts +25 -10
- package/dist/helpers.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/services/eventEmitter.d.ts +2 -2
- package/dist/services/eventEmitter.d.ts.map +1 -1
- package/dist/shared.d.ts +4 -4
- package/dist/shared.d.ts.map +1 -1
- package/dist/types.d.ts +8 -7
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/actions/executeTransaction.ts +25 -20
- package/src/helpers.ts +121 -147
- package/src/index.ts +2 -0
- package/src/services/eventEmitter.ts +22 -39
- package/src/shared.ts +28 -49
- package/src/types.ts +8 -16
package/src/shared.ts
CHANGED
|
@@ -1,32 +1,31 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
AmountRestrictionType,
|
|
4
|
-
BestRouteResponse,
|
|
5
|
-
BlockchainMeta,
|
|
1
|
+
import { Network, WalletType } from '@rango-dev/wallets-shared';
|
|
2
|
+
import {
|
|
6
3
|
CosmosTransaction,
|
|
7
4
|
EvmTransaction,
|
|
8
|
-
MetaResponse,
|
|
9
5
|
SimulationResult,
|
|
10
6
|
SolanaTransaction,
|
|
11
7
|
StarknetTransaction,
|
|
12
|
-
SwapResult,
|
|
13
|
-
Token,
|
|
14
|
-
Transfer as TransferTransaction,
|
|
15
8
|
TronTransaction,
|
|
9
|
+
Transfer as TransferTransaction,
|
|
10
|
+
AmountRestrictionType,
|
|
11
|
+
BestRouteResponse,
|
|
12
|
+
MetaResponse,
|
|
13
|
+
Token,
|
|
14
|
+
SwapResult,
|
|
15
|
+
BlockchainMeta,
|
|
16
16
|
} from 'rango-sdk';
|
|
17
|
-
import type { TonTransaction } from 'rango-types';
|
|
18
17
|
|
|
18
|
+
import { PrettyError } from './shared-errors';
|
|
19
19
|
import BigNumber from 'bignumber.js';
|
|
20
|
+
import { numberToString } from './numbers';
|
|
20
21
|
import {
|
|
22
|
+
TonTransaction,
|
|
21
23
|
isCosmosBlockchain,
|
|
22
24
|
isEvmBlockchain,
|
|
23
25
|
isStarknetBlockchain,
|
|
24
26
|
isTronBlockchain,
|
|
25
27
|
} from 'rango-types';
|
|
26
28
|
|
|
27
|
-
import { numberToString } from './numbers';
|
|
28
|
-
import { PrettyError } from './shared-errors';
|
|
29
|
-
|
|
30
29
|
export interface PendingSwapWithQueueID {
|
|
31
30
|
id: string;
|
|
32
31
|
swap: PendingSwap;
|
|
@@ -171,10 +170,8 @@ export type PendingSwapStep = {
|
|
|
171
170
|
starknetTransaction: StarknetTransaction | null;
|
|
172
171
|
tonTransaction: TonTransaction | null;
|
|
173
172
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
* keeping null for backward compatability
|
|
177
|
-
*/
|
|
173
|
+
// missing fields in older versions
|
|
174
|
+
// keeping null for backward compatability
|
|
178
175
|
swapperLogo: string | null;
|
|
179
176
|
swapperType: string | null;
|
|
180
177
|
fromBlockchainLogo: string | null;
|
|
@@ -243,22 +240,16 @@ export const getCurrentBlockchainOf = (
|
|
|
243
240
|
step.cosmosTransaction?.blockChain ||
|
|
244
241
|
step.solanaTransaction?.blockChain ||
|
|
245
242
|
step.tonTransaction?.blockChain;
|
|
246
|
-
if (b1)
|
|
247
|
-
return b1;
|
|
248
|
-
}
|
|
243
|
+
if (b1) return b1;
|
|
249
244
|
|
|
250
245
|
const transferAddress = step.transferTransaction?.fromWalletAddress;
|
|
251
|
-
if (!transferAddress)
|
|
252
|
-
throw PrettyError.BlockchainMissing();
|
|
253
|
-
}
|
|
246
|
+
if (!transferAddress) throw PrettyError.BlockchainMissing();
|
|
254
247
|
|
|
255
248
|
const blockchain =
|
|
256
249
|
Object.keys(swap.wallets).find(
|
|
257
250
|
(b) => swap.wallets[b]?.address === transferAddress
|
|
258
251
|
) || null;
|
|
259
|
-
if (blockchain == null)
|
|
260
|
-
throw PrettyError.BlockchainMissing();
|
|
261
|
-
}
|
|
252
|
+
if (blockchain == null) throw PrettyError.BlockchainMissing();
|
|
262
253
|
|
|
263
254
|
return blockchain;
|
|
264
255
|
};
|
|
@@ -266,15 +257,14 @@ export const getCurrentBlockchainOf = (
|
|
|
266
257
|
const getBlockchainMetaExplorerBaseUrl = (
|
|
267
258
|
blockchainMeta: BlockchainMeta
|
|
268
259
|
): string | undefined => {
|
|
269
|
-
if (isCosmosBlockchain(blockchainMeta))
|
|
260
|
+
if (isCosmosBlockchain(blockchainMeta))
|
|
270
261
|
return blockchainMeta.info?.explorerUrlToTx;
|
|
271
|
-
|
|
262
|
+
else if (
|
|
272
263
|
isEvmBlockchain(blockchainMeta) ||
|
|
273
264
|
isStarknetBlockchain(blockchainMeta) ||
|
|
274
265
|
isTronBlockchain(blockchainMeta)
|
|
275
|
-
)
|
|
266
|
+
)
|
|
276
267
|
return blockchainMeta.info.transactionUrl;
|
|
277
|
-
}
|
|
278
268
|
return;
|
|
279
269
|
};
|
|
280
270
|
|
|
@@ -285,12 +275,9 @@ export const getScannerUrl = (
|
|
|
285
275
|
): string | undefined => {
|
|
286
276
|
const blockchainMeta = blockchainMetaMap[network];
|
|
287
277
|
const baseUrl = getBlockchainMetaExplorerBaseUrl(blockchainMeta);
|
|
288
|
-
if (!baseUrl)
|
|
289
|
-
|
|
290
|
-
}
|
|
291
|
-
if (baseUrl.indexOf('/{txHash}') !== -1) {
|
|
278
|
+
if (!baseUrl) return;
|
|
279
|
+
if (baseUrl.indexOf('/{txHash}') !== -1)
|
|
292
280
|
return baseUrl.replace('{txHash}', txHash?.toLowerCase());
|
|
293
|
-
}
|
|
294
281
|
return `${baseUrl}/${txHash?.toLowerCase()}`;
|
|
295
282
|
};
|
|
296
283
|
|
|
@@ -329,9 +316,7 @@ export const getCurrentAddressOf = (
|
|
|
329
316
|
? { address: step.transferTransaction?.fromWalletAddress }
|
|
330
317
|
: null) ||
|
|
331
318
|
null;
|
|
332
|
-
if (result == null)
|
|
333
|
-
throw PrettyError.WalletMissing();
|
|
334
|
-
}
|
|
319
|
+
if (result == null) throw PrettyError.WalletMissing();
|
|
335
320
|
return result.address;
|
|
336
321
|
};
|
|
337
322
|
|
|
@@ -348,11 +333,10 @@ export function getRelatedWallet(
|
|
|
348
333
|
const wallet = walletKV?.v || null;
|
|
349
334
|
|
|
350
335
|
const walletType = wallet?.walletType;
|
|
351
|
-
if (wallet === null)
|
|
336
|
+
if (wallet === null)
|
|
352
337
|
throw PrettyError.AssertionFailed(
|
|
353
338
|
`Wallet for source ${blockchain} not passed: walletType: ${walletType}`
|
|
354
339
|
);
|
|
355
|
-
}
|
|
356
340
|
return wallet;
|
|
357
341
|
}
|
|
358
342
|
|
|
@@ -389,9 +373,7 @@ export function getUsdFeeOfStep(
|
|
|
389
373
|
let totalFeeInUsd = new BigNumber(0);
|
|
390
374
|
for (let i = 0; i < step.fee.length; i++) {
|
|
391
375
|
const fee = step.fee[i];
|
|
392
|
-
if (fee.expenseType === 'DECREASE_FROM_OUTPUT')
|
|
393
|
-
continue;
|
|
394
|
-
}
|
|
376
|
+
if (fee.expenseType === 'DECREASE_FROM_OUTPUT') continue;
|
|
395
377
|
|
|
396
378
|
const unitPrice = getUsdPrice(
|
|
397
379
|
fee.asset.blockchain,
|
|
@@ -413,12 +395,10 @@ export function calculatePendingSwap(
|
|
|
413
395
|
wallets: { [p: string]: WalletTypeAndAddress },
|
|
414
396
|
settings: SwapSavedSettings,
|
|
415
397
|
validateBalanceOrFee: boolean,
|
|
416
|
-
meta:
|
|
398
|
+
meta: MetaResponse | null
|
|
417
399
|
): PendingSwap {
|
|
418
400
|
const simulationResult = bestRoute.result;
|
|
419
|
-
if (!simulationResult)
|
|
420
|
-
throw Error('Simulation result should not be null');
|
|
421
|
-
}
|
|
401
|
+
if (!simulationResult) throw Error('Simulation result should not be null');
|
|
422
402
|
|
|
423
403
|
return {
|
|
424
404
|
creationTime: new Date().getTime().toString(),
|
|
@@ -472,8 +452,7 @@ export function calculatePendingSwap(
|
|
|
472
452
|
expectedOutputAmountHumanReadable: swap.toAmount,
|
|
473
453
|
outputAmount: '',
|
|
474
454
|
feeInUsd: meta
|
|
475
|
-
?
|
|
476
|
-
numberToString(getUsdFeeOfStep(swap, meta?.tokens), null, 8)
|
|
455
|
+
? numberToString(getUsdFeeOfStep(swap, meta?.tokens), null, 8)
|
|
477
456
|
: null,
|
|
478
457
|
estimatedTimeInSeconds: swap.estimatedTimeInSeconds || null,
|
|
479
458
|
|
package/src/types.ts
CHANGED
|
@@ -1,23 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
QueueStorage,
|
|
6
|
-
} from '@rango-dev/queue-manager-core';
|
|
7
|
-
import type { ConnectResult } from '@rango-dev/wallets-core';
|
|
8
|
-
import type {
|
|
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-react';
|
|
4
|
+
import {
|
|
9
5
|
Meta,
|
|
10
6
|
Network,
|
|
11
|
-
Providers,
|
|
12
7
|
WalletState,
|
|
13
8
|
WalletType,
|
|
14
9
|
} from '@rango-dev/wallets-shared';
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
|
|
18
|
-
EvmBlockchainMeta,
|
|
19
|
-
SignerFactory,
|
|
20
|
-
} from 'rango-types';
|
|
10
|
+
import { APIErrorCode, EvmBlockchainMeta, SignerFactory } from 'rango-types';
|
|
11
|
+
import { Transaction } from 'rango-sdk';
|
|
12
|
+
import { PendingSwap, PendingSwapStep, Wallet } from './shared';
|
|
21
13
|
|
|
22
14
|
export type RemoveNameField<T, U extends string> = {
|
|
23
15
|
[Property in keyof T as Exclude<Property, U>]: T[Property];
|
|
@@ -69,7 +61,7 @@ export interface SwapQueueContext extends QueueContext {
|
|
|
69
61
|
switchNetwork: (
|
|
70
62
|
wallet: WalletType,
|
|
71
63
|
network: Network
|
|
72
|
-
) => Promise<ConnectResult
|
|
64
|
+
) => Promise<ConnectResult> | undefined;
|
|
73
65
|
canSwitchNetworkTo: (type: WalletType, network: Network) => boolean;
|
|
74
66
|
connect: (
|
|
75
67
|
wallet: WalletType,
|