@rango-dev/queue-manager-rango-preset 0.1.10 → 0.1.11-next.3
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/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/numbers.d.ts +3 -0
- package/dist/numbers.d.ts.map +1 -0
- package/dist/queue-manager-rango-preset.cjs.development.js +132 -1
- package/dist/queue-manager-rango-preset.cjs.development.js.map +1 -1
- package/dist/queue-manager-rango-preset.cjs.production.min.js +1 -1
- package/dist/queue-manager-rango-preset.cjs.production.min.js.map +1 -1
- package/dist/queue-manager-rango-preset.esm.js +130 -2
- package/dist/queue-manager-rango-preset.esm.js.map +1 -1
- package/dist/services/httpService.d.ts.map +1 -1
- package/dist/shared-sentry.d.ts +1 -1
- package/dist/shared-sentry.d.ts.map +1 -1
- package/dist/shared.d.ts +16 -5
- package/dist/shared.d.ts.map +1 -1
- package/package.json +1 -1
- package/readme.md +1 -1
- package/src/index.ts +1 -0
- package/src/numbers.ts +68 -0
- package/src/services/httpService.ts +5 -1
- package/src/shared-sentry.ts +1 -1
- package/src/shared.ts +153 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpService.d.ts","sourceRoot":"","sources":["../src/services/httpService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"httpService.d.ts","sourceRoot":"","sources":["../src/services/httpService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAOxC,eAAO,MAAM,WAAW,aAGvB,CAAC"}
|
package/dist/shared-sentry.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WalletType } from '@rango-dev/wallets-shared';
|
|
2
1
|
import { PendingSwap, PendingSwapStep } from './shared';
|
|
2
|
+
import { WalletType } from '@rango-dev/wallets-shared';
|
|
3
3
|
export declare function logRPCError(error: unknown, swap: PendingSwap, currentStep: PendingSwapStep | undefined, walletType: WalletType | undefined): void;
|
|
4
4
|
//# sourceMappingURL=shared-sentry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared-sentry.d.ts","sourceRoot":"","sources":["src/shared-sentry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"shared-sentry.d.ts","sourceRoot":"","sources":["src/shared-sentry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAEvD,wBAAgB,WAAW,CACzB,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,WAAW,EACjB,WAAW,EAAE,eAAe,GAAG,SAAS,EACxC,UAAU,EAAE,UAAU,GAAG,SAAS,GACjC,IAAI,CAcN"}
|
package/dist/shared.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Network, WalletType } from '@rango-dev/wallets-shared';
|
|
2
|
-
import { CosmosTransaction, EvmBlockchainMeta, EvmTransaction, SimulationResult, SolanaTransaction, StarknetTransaction, TronTransaction, Transfer as TransferTransaction, AmountRestrictionType } from 'rango-sdk';
|
|
2
|
+
import { CosmosTransaction, EvmBlockchainMeta, EvmTransaction, SimulationResult, SolanaTransaction, StarknetTransaction, TronTransaction, Transfer as TransferTransaction, AmountRestrictionType, BestRouteResponse, MetaResponse, Token, SwapResult } from 'rango-sdk';
|
|
3
|
+
import BigNumber from 'bignumber.js';
|
|
3
4
|
export interface PendingSwapWithQueueID {
|
|
4
5
|
id: string;
|
|
5
6
|
swap: PendingSwap;
|
|
@@ -39,9 +40,9 @@ export declare type Wallet = {
|
|
|
39
40
|
export declare type EventType = 'swap_started' | 'confirm_contract' | 'confirm_transfer' | 'task_failed' | 'task_completed' | 'task_canceled' | 'task_paused' | 'contract_confirmed' | 'confirm_approve_contract' | 'contract_rejected' | 'check_tx_status' | 'check_approve_tx_status' | 'transfer_rejected' | 'calling_smart_contract' | 'smart_contract_called' | 'smart_contract_call_failed' | 'step_completed_with_output' | 'waiting_for_network_change' | 'waiting_for_connecting_wallet' | 'waiting_for_change_wallet_account' | 'network_changed' | 'not_enough_balance' | 'waiting_for_queue' | 'check_fee_failed' | 'route_failed_to_find' | 'transaction_expired';
|
|
40
41
|
export declare type SwapSavedSettings = {
|
|
41
42
|
slippage: string;
|
|
42
|
-
disabledSwappersIds
|
|
43
|
-
disabledSwappersGroups
|
|
44
|
-
infiniteApprove
|
|
43
|
+
disabledSwappersIds?: string[];
|
|
44
|
+
disabledSwappersGroups?: string[];
|
|
45
|
+
infiniteApprove?: boolean;
|
|
45
46
|
};
|
|
46
47
|
declare type InternalStepState = 'PENDING' | 'CREATED' | 'WAITING' | 'SIGNED' | 'SUCCESSED' | 'FAILED';
|
|
47
48
|
export declare type SwapperStatusStep = {
|
|
@@ -62,7 +63,7 @@ export declare type SwapExplorerUrl = {
|
|
|
62
63
|
export declare type StepStatus = 'created' | 'running' | 'failed' | 'success' | 'waitingForApproval' | 'approved';
|
|
63
64
|
export declare type PendingSwapStep = {
|
|
64
65
|
id: number;
|
|
65
|
-
fromBlockchain:
|
|
66
|
+
fromBlockchain: string;
|
|
66
67
|
fromSymbol: string;
|
|
67
68
|
fromSymbolAddress: string | null;
|
|
68
69
|
fromDecimals: number;
|
|
@@ -97,6 +98,11 @@ export declare type PendingSwapStep = {
|
|
|
97
98
|
tronTransaction: TronTransaction | null;
|
|
98
99
|
starknetApprovalTransaction: StarknetTransaction | null;
|
|
99
100
|
starknetTransaction: StarknetTransaction | null;
|
|
101
|
+
swapperLogo: string | null;
|
|
102
|
+
swapperType: string | null;
|
|
103
|
+
fromBlockchainLogo: string | null;
|
|
104
|
+
toBlockchainLogo: string | null;
|
|
105
|
+
feeInUsd: string | null;
|
|
100
106
|
};
|
|
101
107
|
export declare type WalletTypeAndAddress = {
|
|
102
108
|
walletType: WalletType;
|
|
@@ -144,5 +150,10 @@ export declare function getNextStep(swap: PendingSwap, currentStep: PendingSwapS
|
|
|
144
150
|
export declare const getCurrentAddressOf: (swap: PendingSwap, step: PendingSwapStep) => string;
|
|
145
151
|
export declare function getRelatedWallet(swap: PendingSwap, currentStep: PendingSwapStep): WalletTypeAndAddress;
|
|
146
152
|
export declare function getRelatedWalletOrNull(swap: PendingSwap, currentStep: PendingSwapStep): WalletTypeAndAddress | null;
|
|
153
|
+
export declare const getUsdPrice: (blockchain: string, symbol: string, address: string | null, allTokens: Token[]) => number | null;
|
|
154
|
+
export declare function getUsdFeeOfStep(step: SwapResult, allTokens: Token[]): BigNumber;
|
|
155
|
+
export declare function calculatePendingSwap(inputAmount: string, bestRoute: BestRouteResponse, wallets: {
|
|
156
|
+
[p: string]: WalletTypeAndAddress;
|
|
157
|
+
}, settings: SwapSavedSettings, validateBalanceOrFee: boolean, meta: MetaResponse | null): PendingSwap;
|
|
147
158
|
export {};
|
|
148
159
|
//# sourceMappingURL=shared.d.ts.map
|
package/dist/shared.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["src/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,QAAQ,IAAI,mBAAmB,EAC/B,qBAAqB,
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["src/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,QAAQ,IAAI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,EAC5B,OAAO,EAAE;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,oBAAoB,CAAA;CAAE,EAC9C,QAAQ,EAAE,iBAAiB,EAC3B,oBAAoB,EAAE,OAAO,EAC7B,IAAI,EAAE,YAAY,GAAG,IAAI,GACxB,WAAW,CAwFb"}
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
# @rango-dev/queue-manager-rango-preset
|
|
1
|
+
# @rango-dev/queue-manager-rango-preset
|
package/src/index.ts
CHANGED
package/src/numbers.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import BigNumber from 'bignumber.js';
|
|
2
|
+
|
|
3
|
+
export const numberToString = (
|
|
4
|
+
number: BigNumber | string | null,
|
|
5
|
+
minDecimals: number | null = null,
|
|
6
|
+
maxDecimals: number | null = null
|
|
7
|
+
): string => {
|
|
8
|
+
if (number === null) return '';
|
|
9
|
+
if (number === '') return '';
|
|
10
|
+
const n = new BigNumber(number);
|
|
11
|
+
const roundingMode = 1;
|
|
12
|
+
let maxI = 1000;
|
|
13
|
+
for (let i = 0; i < 60; i++) {
|
|
14
|
+
if (new BigNumber(n.toFixed(i, roundingMode)).eq(n)) {
|
|
15
|
+
maxI = i;
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (n.gte(10000)) return n.toFormat(0, roundingMode);
|
|
21
|
+
if (n.gte(1000))
|
|
22
|
+
return n.toFormat(
|
|
23
|
+
Math.min(
|
|
24
|
+
maxI,
|
|
25
|
+
Math.min(maxDecimals || 100, Math.max(minDecimals || 0, 1))
|
|
26
|
+
),
|
|
27
|
+
roundingMode
|
|
28
|
+
);
|
|
29
|
+
if (n.gte(100))
|
|
30
|
+
return n.toFormat(
|
|
31
|
+
Math.min(
|
|
32
|
+
maxI,
|
|
33
|
+
Math.min(maxDecimals || 100, Math.max(minDecimals || 0, 1))
|
|
34
|
+
),
|
|
35
|
+
roundingMode
|
|
36
|
+
);
|
|
37
|
+
if (n.gte(1))
|
|
38
|
+
return n.toFormat(
|
|
39
|
+
Math.min(
|
|
40
|
+
maxI,
|
|
41
|
+
Math.min(maxDecimals || 100, Math.max(minDecimals || 0, 2))
|
|
42
|
+
),
|
|
43
|
+
roundingMode
|
|
44
|
+
);
|
|
45
|
+
if (n.gte(0.01))
|
|
46
|
+
return n.toFormat(
|
|
47
|
+
Math.min(
|
|
48
|
+
maxI,
|
|
49
|
+
Math.min(maxDecimals || 100, Math.max(minDecimals || 0, 4))
|
|
50
|
+
),
|
|
51
|
+
roundingMode
|
|
52
|
+
);
|
|
53
|
+
for (let i = minDecimals || 4; i < 17; i++)
|
|
54
|
+
if (n.gte(Math.pow(10, -i)))
|
|
55
|
+
return n.toFormat(
|
|
56
|
+
Math.min(
|
|
57
|
+
maxI,
|
|
58
|
+
Math.min(maxDecimals || 100, Math.max(minDecimals || 0, i))
|
|
59
|
+
),
|
|
60
|
+
roundingMode
|
|
61
|
+
);
|
|
62
|
+
if (n.isEqualTo(0)) return '0';
|
|
63
|
+
|
|
64
|
+
return n.toFormat(
|
|
65
|
+
Math.min(maxI, Math.min(maxDecimals || 100, Math.max(minDecimals || 0, 8))),
|
|
66
|
+
roundingMode
|
|
67
|
+
);
|
|
68
|
+
};
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { RangoClient } from 'rango-sdk';
|
|
2
2
|
import { RANGO_DAPP_API_KEY, RANGO_DAPP_API_BASE_URL } from '../constants';
|
|
3
3
|
|
|
4
|
+
// this API key is limited and
|
|
5
|
+
// it is only for test purpose
|
|
6
|
+
const RANGO_PUBLIC_API_KEY = 'c6381a79-2817-4602-83bf-6a641a409e32';
|
|
7
|
+
|
|
4
8
|
export const httpService = new RangoClient(
|
|
5
|
-
RANGO_DAPP_API_KEY ||
|
|
9
|
+
RANGO_DAPP_API_KEY || RANGO_PUBLIC_API_KEY,
|
|
6
10
|
RANGO_DAPP_API_BASE_URL
|
|
7
11
|
);
|
package/src/shared-sentry.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { WalletType } from '@rango-dev/wallets-shared';
|
|
2
1
|
import * as Sentry from '@sentry/browser';
|
|
3
2
|
import { PendingSwap, PendingSwapStep } from './shared';
|
|
3
|
+
import { WalletType } from '@rango-dev/wallets-shared';
|
|
4
4
|
|
|
5
5
|
export function logRPCError(
|
|
6
6
|
error: unknown,
|
package/src/shared.ts
CHANGED
|
@@ -9,9 +9,15 @@ import {
|
|
|
9
9
|
TronTransaction,
|
|
10
10
|
Transfer as TransferTransaction,
|
|
11
11
|
AmountRestrictionType,
|
|
12
|
+
BestRouteResponse,
|
|
13
|
+
MetaResponse,
|
|
14
|
+
Token,
|
|
15
|
+
SwapResult,
|
|
12
16
|
} from 'rango-sdk';
|
|
13
17
|
|
|
14
18
|
import { PrettyError } from './shared-errors';
|
|
19
|
+
import BigNumber from 'bignumber.js';
|
|
20
|
+
import { numberToString } from './numbers';
|
|
15
21
|
|
|
16
22
|
export interface PendingSwapWithQueueID {
|
|
17
23
|
id: string;
|
|
@@ -78,9 +84,9 @@ export type EventType =
|
|
|
78
84
|
|
|
79
85
|
export type SwapSavedSettings = {
|
|
80
86
|
slippage: string;
|
|
81
|
-
disabledSwappersIds
|
|
82
|
-
disabledSwappersGroups
|
|
83
|
-
infiniteApprove
|
|
87
|
+
disabledSwappersIds?: string[];
|
|
88
|
+
disabledSwappersGroups?: string[];
|
|
89
|
+
infiniteApprove?: boolean;
|
|
84
90
|
};
|
|
85
91
|
|
|
86
92
|
type InternalStepState =
|
|
@@ -120,7 +126,7 @@ export type StepStatus =
|
|
|
120
126
|
export type PendingSwapStep = {
|
|
121
127
|
// routing data
|
|
122
128
|
id: number;
|
|
123
|
-
fromBlockchain:
|
|
129
|
+
fromBlockchain: string;
|
|
124
130
|
fromSymbol: string;
|
|
125
131
|
fromSymbolAddress: string | null;
|
|
126
132
|
fromDecimals: number;
|
|
@@ -159,6 +165,14 @@ export type PendingSwapStep = {
|
|
|
159
165
|
tronTransaction: TronTransaction | null;
|
|
160
166
|
starknetApprovalTransaction: StarknetTransaction | null;
|
|
161
167
|
starknetTransaction: StarknetTransaction | null;
|
|
168
|
+
|
|
169
|
+
// missing fields in older versions
|
|
170
|
+
// keeping null for backward compatability
|
|
171
|
+
swapperLogo: string | null;
|
|
172
|
+
swapperType: string | null;
|
|
173
|
+
fromBlockchainLogo: string | null;
|
|
174
|
+
toBlockchainLogo: string | null;
|
|
175
|
+
feeInUsd: string | null;
|
|
162
176
|
};
|
|
163
177
|
|
|
164
178
|
export type WalletTypeAndAddress = {
|
|
@@ -340,3 +354,138 @@ export function getRelatedWalletOrNull(
|
|
|
340
354
|
return null;
|
|
341
355
|
}
|
|
342
356
|
}
|
|
357
|
+
|
|
358
|
+
export const getUsdPrice = (
|
|
359
|
+
blockchain: string,
|
|
360
|
+
symbol: string,
|
|
361
|
+
address: string | null,
|
|
362
|
+
allTokens: Token[]
|
|
363
|
+
): number | null => {
|
|
364
|
+
const token = allTokens?.find(
|
|
365
|
+
(t) =>
|
|
366
|
+
t.blockchain === blockchain &&
|
|
367
|
+
t.symbol?.toUpperCase() === symbol?.toUpperCase() &&
|
|
368
|
+
t.address === address
|
|
369
|
+
);
|
|
370
|
+
return token?.usdPrice || null;
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
export function getUsdFeeOfStep(
|
|
374
|
+
step: SwapResult,
|
|
375
|
+
allTokens: Token[]
|
|
376
|
+
): BigNumber {
|
|
377
|
+
let totalFeeInUsd = new BigNumber(0);
|
|
378
|
+
for (let i = 0; i < step.fee.length; i++) {
|
|
379
|
+
const fee = step.fee[i];
|
|
380
|
+
if (fee.expenseType === 'DECREASE_FROM_OUTPUT') continue;
|
|
381
|
+
|
|
382
|
+
const unitPrice = getUsdPrice(
|
|
383
|
+
fee.asset.blockchain,
|
|
384
|
+
fee.asset.symbol,
|
|
385
|
+
fee.asset.address,
|
|
386
|
+
allTokens
|
|
387
|
+
);
|
|
388
|
+
totalFeeInUsd = totalFeeInUsd.plus(
|
|
389
|
+
new BigNumber(fee.amount).multipliedBy(unitPrice || 0)
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
return totalFeeInUsd;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
export function calculatePendingSwap(
|
|
397
|
+
inputAmount: string,
|
|
398
|
+
bestRoute: BestRouteResponse,
|
|
399
|
+
wallets: { [p: string]: WalletTypeAndAddress },
|
|
400
|
+
settings: SwapSavedSettings,
|
|
401
|
+
validateBalanceOrFee: boolean,
|
|
402
|
+
meta: MetaResponse | null
|
|
403
|
+
): PendingSwap {
|
|
404
|
+
const simulationResult = bestRoute.result;
|
|
405
|
+
if (!simulationResult) throw Error('Simulation result should not be null');
|
|
406
|
+
|
|
407
|
+
return {
|
|
408
|
+
creationTime: new Date().getTime().toString(),
|
|
409
|
+
finishTime: null,
|
|
410
|
+
requestId: bestRoute.requestId || '',
|
|
411
|
+
inputAmount: inputAmount,
|
|
412
|
+
wallets,
|
|
413
|
+
status: 'running',
|
|
414
|
+
isPaused: false,
|
|
415
|
+
extraMessage: null,
|
|
416
|
+
extraMessageSeverity: null,
|
|
417
|
+
extraMessageDetail: null,
|
|
418
|
+
extraMessageErrorCode: null,
|
|
419
|
+
networkStatusExtraMessage: null,
|
|
420
|
+
networkStatusExtraMessageDetail: null,
|
|
421
|
+
lastNotificationTime: null,
|
|
422
|
+
settings: settings,
|
|
423
|
+
simulationResult: simulationResult,
|
|
424
|
+
validateBalanceOrFee,
|
|
425
|
+
steps:
|
|
426
|
+
bestRoute.result?.swaps?.map((swap, index) => {
|
|
427
|
+
return {
|
|
428
|
+
id: index + 1,
|
|
429
|
+
|
|
430
|
+
// from
|
|
431
|
+
fromBlockchain: swap.from.blockchain,
|
|
432
|
+
fromBlockchainLogo: swap.from.blockchainLogo,
|
|
433
|
+
fromLogo: swap.from.logo,
|
|
434
|
+
fromSymbol: swap.from.symbol,
|
|
435
|
+
fromSymbolAddress: swap.from.address,
|
|
436
|
+
fromDecimals: swap.from.decimals,
|
|
437
|
+
fromAmountPrecision: swap.fromAmountPrecision,
|
|
438
|
+
fromAmountMinValue: swap.fromAmountMinValue,
|
|
439
|
+
fromAmountMaxValue: swap.fromAmountMaxValue,
|
|
440
|
+
fromAmountRestrictionType: swap.fromAmountRestrictionType,
|
|
441
|
+
|
|
442
|
+
// to
|
|
443
|
+
toBlockchain: swap.to.blockchain,
|
|
444
|
+
toBlockchainLogo: swap.to.blockchainLogo,
|
|
445
|
+
toSymbol: swap.to.symbol,
|
|
446
|
+
toSymbolAddress: swap.to.address,
|
|
447
|
+
toDecimals: swap.to.decimals,
|
|
448
|
+
toLogo: swap.to.logo,
|
|
449
|
+
|
|
450
|
+
// swapper
|
|
451
|
+
swapperId: swap.swapperId,
|
|
452
|
+
swapperLogo: swap.swapperLogo,
|
|
453
|
+
swapperType: swap.swapperType,
|
|
454
|
+
|
|
455
|
+
// output, fee, timing
|
|
456
|
+
expectedOutputAmountHumanReadable: swap.toAmount,
|
|
457
|
+
outputAmount: '',
|
|
458
|
+
feeInUsd: meta
|
|
459
|
+
? numberToString(getUsdFeeOfStep(swap, meta?.tokens), null, 8)
|
|
460
|
+
: null,
|
|
461
|
+
estimatedTimeInSeconds: swap.estimatedTimeInSeconds || null,
|
|
462
|
+
|
|
463
|
+
// status, tracking
|
|
464
|
+
status: 'created',
|
|
465
|
+
networkStatus: null,
|
|
466
|
+
startTransactionTime: new Date().getTime(),
|
|
467
|
+
externalTransactionId: null,
|
|
468
|
+
executedTransactionId: null,
|
|
469
|
+
executedTransactionTime: null,
|
|
470
|
+
explorerUrl: null,
|
|
471
|
+
diagnosisUrl: null,
|
|
472
|
+
trackingCode: null,
|
|
473
|
+
internalSteps: null,
|
|
474
|
+
|
|
475
|
+
// transactions
|
|
476
|
+
evmTransaction: null,
|
|
477
|
+
evmApprovalTransaction: null,
|
|
478
|
+
starknetTransaction: null,
|
|
479
|
+
starknetApprovalTransaction: null,
|
|
480
|
+
tronTransaction: null,
|
|
481
|
+
tronApprovalTransaction: null,
|
|
482
|
+
cosmosTransaction: null,
|
|
483
|
+
solanaTransaction: null,
|
|
484
|
+
transferTransaction: null,
|
|
485
|
+
|
|
486
|
+
// front fields
|
|
487
|
+
hasAlreadyProceededToSign: false,
|
|
488
|
+
};
|
|
489
|
+
}) || [],
|
|
490
|
+
};
|
|
491
|
+
}
|