@rango-dev/queue-manager-rango-preset 0.1.10-next.101
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 +8 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/helpers.d.ts +197 -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 +7 -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 +2799 -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 +2781 -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/services/httpService.d.ts +3 -0
- package/dist/services/httpService.d.ts.map +1 -0
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/shared-errors.d.ts +25 -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 +148 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/types.d.ts +48 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +62 -0
- package/readme.md +8 -0
- package/src/actions/checkStatus.ts +269 -0
- package/src/actions/createTransaction.ts +122 -0
- package/src/actions/executeTransaction.ts +121 -0
- package/src/actions/scheduleNextStep.ts +61 -0
- package/src/actions/start.ts +10 -0
- package/src/constants.ts +22 -0
- package/src/helpers.ts +1774 -0
- package/src/hooks.ts +76 -0
- package/src/index.ts +27 -0
- package/src/migration.ts +124 -0
- package/src/queueDef.ts +39 -0
- package/src/services/httpService.ts +7 -0
- package/src/services/index.ts +1 -0
- package/src/shared-errors.ts +160 -0
- package/src/shared-sentry.ts +24 -0
- package/src/shared.ts +342 -0
- package/src/types.ts +76 -0
package/dist/shared.d.ts
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
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';
|
|
3
|
+
export interface PendingSwapWithQueueID {
|
|
4
|
+
id: string;
|
|
5
|
+
swap: PendingSwap;
|
|
6
|
+
}
|
|
7
|
+
export declare type SwapProgressNotification = {
|
|
8
|
+
eventType: EventType;
|
|
9
|
+
swap: PendingSwap | null;
|
|
10
|
+
step: PendingSwapStep | null;
|
|
11
|
+
};
|
|
12
|
+
export declare type WalletBalance = {
|
|
13
|
+
chain: Network;
|
|
14
|
+
symbol: string;
|
|
15
|
+
ticker: string;
|
|
16
|
+
address: string | null;
|
|
17
|
+
rawAmount: string;
|
|
18
|
+
decimal: number | null;
|
|
19
|
+
amount: string;
|
|
20
|
+
logo: string | null;
|
|
21
|
+
usdPrice: number | null;
|
|
22
|
+
};
|
|
23
|
+
export declare type Account = {
|
|
24
|
+
balances: WalletBalance[] | null;
|
|
25
|
+
address: string;
|
|
26
|
+
loading: boolean;
|
|
27
|
+
walletType: WalletType;
|
|
28
|
+
error: boolean;
|
|
29
|
+
explorerUrl: string | null;
|
|
30
|
+
isConnected?: boolean;
|
|
31
|
+
};
|
|
32
|
+
export declare type Blockchain = {
|
|
33
|
+
name: string;
|
|
34
|
+
accounts: Account[];
|
|
35
|
+
};
|
|
36
|
+
export declare type Wallet = {
|
|
37
|
+
blockchains: Blockchain[];
|
|
38
|
+
};
|
|
39
|
+
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
|
+
export declare type SwapSavedSettings = {
|
|
41
|
+
slippage: string;
|
|
42
|
+
disabledSwappersIds: string[];
|
|
43
|
+
disabledSwappersGroups: string[];
|
|
44
|
+
infiniteApprove: boolean;
|
|
45
|
+
};
|
|
46
|
+
declare type InternalStepState = 'PENDING' | 'CREATED' | 'WAITING' | 'SIGNED' | 'SUCCESSED' | 'FAILED';
|
|
47
|
+
export declare type SwapperStatusStep = {
|
|
48
|
+
name: string;
|
|
49
|
+
state: InternalStepState;
|
|
50
|
+
current: boolean;
|
|
51
|
+
};
|
|
52
|
+
export declare enum PendingSwapNetworkStatus {
|
|
53
|
+
WaitingForConnectingWallet = "waitingForConnectingWallet",
|
|
54
|
+
WaitingForQueue = "waitingForQueue",
|
|
55
|
+
WaitingForNetworkChange = "waitingForNetworkChange",
|
|
56
|
+
NetworkChanged = "networkChanged"
|
|
57
|
+
}
|
|
58
|
+
export declare type SwapExplorerUrl = {
|
|
59
|
+
url: string;
|
|
60
|
+
description: string | null;
|
|
61
|
+
};
|
|
62
|
+
export declare type StepStatus = 'created' | 'running' | 'failed' | 'success' | 'waitingForApproval' | 'approved';
|
|
63
|
+
export declare type PendingSwapStep = {
|
|
64
|
+
id: number;
|
|
65
|
+
fromBlockchain: Network;
|
|
66
|
+
fromSymbol: string;
|
|
67
|
+
fromSymbolAddress: string | null;
|
|
68
|
+
fromDecimals: number;
|
|
69
|
+
fromAmountPrecision: string | null;
|
|
70
|
+
fromAmountMinValue: string | null;
|
|
71
|
+
fromAmountMaxValue: string | null;
|
|
72
|
+
fromAmountRestrictionType: AmountRestrictionType | null;
|
|
73
|
+
fromLogo: string;
|
|
74
|
+
toBlockchain: string;
|
|
75
|
+
toSymbol: string;
|
|
76
|
+
toSymbolAddress: string | null;
|
|
77
|
+
toDecimals: number;
|
|
78
|
+
toLogo: string;
|
|
79
|
+
swapperId: string;
|
|
80
|
+
expectedOutputAmountHumanReadable: string | null;
|
|
81
|
+
startTransactionTime: number;
|
|
82
|
+
internalSteps: SwapperStatusStep[] | null;
|
|
83
|
+
estimatedTimeInSeconds: number | null;
|
|
84
|
+
status: StepStatus;
|
|
85
|
+
networkStatus: PendingSwapNetworkStatus | null;
|
|
86
|
+
executedTransactionId: string | null;
|
|
87
|
+
executedTransactionTime: string | null;
|
|
88
|
+
explorerUrl: SwapExplorerUrl[] | null;
|
|
89
|
+
diagnosisUrl: string | null;
|
|
90
|
+
outputAmount: string | null;
|
|
91
|
+
cosmosTransaction: CosmosTransaction | null;
|
|
92
|
+
transferTransaction: TransferTransaction | null;
|
|
93
|
+
solanaTransaction: SolanaTransaction | null;
|
|
94
|
+
evmApprovalTransaction: EvmTransaction | null;
|
|
95
|
+
evmTransaction: EvmTransaction | null;
|
|
96
|
+
tronApprovalTransaction: TronTransaction | null;
|
|
97
|
+
tronTransaction: TronTransaction | null;
|
|
98
|
+
starknetApprovalTransaction: StarknetTransaction | null;
|
|
99
|
+
starknetTransaction: StarknetTransaction | null;
|
|
100
|
+
};
|
|
101
|
+
export declare type WalletTypeAndAddress = {
|
|
102
|
+
walletType: WalletType;
|
|
103
|
+
address: string;
|
|
104
|
+
};
|
|
105
|
+
export declare enum MessageSeverity {
|
|
106
|
+
error = "error",
|
|
107
|
+
warning = "warning",
|
|
108
|
+
info = "info",
|
|
109
|
+
success = "success"
|
|
110
|
+
}
|
|
111
|
+
export declare type SwapStatus = 'running' | 'failed' | 'success';
|
|
112
|
+
export declare type PendingSwap = {
|
|
113
|
+
creationTime: string;
|
|
114
|
+
finishTime: string | null;
|
|
115
|
+
requestId: string;
|
|
116
|
+
inputAmount: string;
|
|
117
|
+
status: SwapStatus;
|
|
118
|
+
isPaused: boolean;
|
|
119
|
+
extraMessage: string | null;
|
|
120
|
+
extraMessageSeverity: MessageSeverity | null;
|
|
121
|
+
extraMessageErrorCode: string | null;
|
|
122
|
+
extraMessageDetail: string | null | undefined;
|
|
123
|
+
networkStatusExtraMessage: string | null;
|
|
124
|
+
networkStatusExtraMessageDetail: string | null;
|
|
125
|
+
lastNotificationTime: string | null;
|
|
126
|
+
wallets: {
|
|
127
|
+
[p: string]: WalletTypeAndAddress;
|
|
128
|
+
};
|
|
129
|
+
settings: SwapSavedSettings;
|
|
130
|
+
steps: PendingSwapStep[];
|
|
131
|
+
simulationResult: SimulationResult;
|
|
132
|
+
validateBalanceOrFee: boolean;
|
|
133
|
+
hasAlreadyProceededToSign?: boolean | null;
|
|
134
|
+
};
|
|
135
|
+
export declare const getCurrentBlockchainOfOrNull: (swap: PendingSwap, step: PendingSwapStep) => Network | null;
|
|
136
|
+
export declare const getCurrentBlockchainOf: (swap: PendingSwap, step: PendingSwapStep) => Network;
|
|
137
|
+
export declare const getEvmApproveUrl: (tx: string, network: Network, evmBasedBlockchains: EvmBlockchainMeta[]) => string;
|
|
138
|
+
export declare const getStarknetApproveUrl: (tx: string) => string;
|
|
139
|
+
export declare const getTronApproveUrl: (tx: string) => string;
|
|
140
|
+
export declare function getNextStep(swap: PendingSwap, currentStep: PendingSwapStep): PendingSwapStep | null;
|
|
141
|
+
/**
|
|
142
|
+
* Returns the wallet address, based on the current step of `PendingSwap`.
|
|
143
|
+
*/
|
|
144
|
+
export declare const getCurrentAddressOf: (swap: PendingSwap, step: PendingSwapStep) => string;
|
|
145
|
+
export declare function getRelatedWallet(swap: PendingSwap, currentStep: PendingSwapStep): WalletTypeAndAddress;
|
|
146
|
+
export declare function getRelatedWalletOrNull(swap: PendingSwap, currentStep: PendingSwapStep): WalletTypeAndAddress | null;
|
|
147
|
+
export {};
|
|
148
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +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,EACtB,MAAM,WAAW,CAAC;AAInB,MAAM,WAAW,sBAAsB;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,WAAW,CAAC;CACnB;AAED,oBAAY,wBAAwB,GAAG;IACrC,SAAS,EAAE,SAAS,CAAC;IACrB,IAAI,EAAE,WAAW,GAAG,IAAI,CAAC;IACzB,IAAI,EAAE,eAAe,GAAG,IAAI,CAAC;CAC9B,CAAC;AAEF,oBAAY,aAAa,GAAG;IAC1B,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,GA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W,EAAE,eAAe,GAC3B,oBAAoB,GAAG,IAAI,CAM7B"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
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 { Meta, Network, WalletState, WalletType } from '@rango-dev/wallets-shared';
|
|
5
|
+
import { PendingSwap, SwapProgressNotification, Wallet } from './shared';
|
|
6
|
+
import { EvmBlockchainMeta, SignerFactory } from 'rango-types';
|
|
7
|
+
export declare type SwapQueueDef = QueueDef<SwapStorage, SwapActionTypes, SwapQueueContext>;
|
|
8
|
+
export interface SwapStorage extends QueueStorage {
|
|
9
|
+
swapDetails: PendingSwap;
|
|
10
|
+
}
|
|
11
|
+
export declare enum SwapActionTypes {
|
|
12
|
+
START = "START",
|
|
13
|
+
SCHEDULE_NEXT_STEP = "SCHEDULE_NEXT_STEP",
|
|
14
|
+
CREATE_TRANSACTION = "CREATE_TRANSACTION",
|
|
15
|
+
EXECUTE_TRANSACTION = "EXECUTE_TRANSACTION",
|
|
16
|
+
CHECK_TRANSACTION_STATUS = "CHECK_TRANSACTION_STATUS"
|
|
17
|
+
}
|
|
18
|
+
export declare type GetCurrentAddress = (type: WalletType, network: Network) => string | undefined;
|
|
19
|
+
export declare enum BlockReason {
|
|
20
|
+
WAIT_FOR_CONNECT_WALLET = "waiting_for_connecting_wallet",
|
|
21
|
+
WAIT_FOR_NETWORK_CHANGE = "waiting_for_network_change",
|
|
22
|
+
DEPENDS_ON_OTHER_QUEUES = "depends_on_other_queues"
|
|
23
|
+
}
|
|
24
|
+
export interface Block<T = any> {
|
|
25
|
+
reason: BlockReason;
|
|
26
|
+
description: string;
|
|
27
|
+
details?: T;
|
|
28
|
+
}
|
|
29
|
+
export interface SwapQueueContext extends QueueContext {
|
|
30
|
+
meta: Meta;
|
|
31
|
+
wallets: Wallet | null;
|
|
32
|
+
providers: Providers;
|
|
33
|
+
getSigners: (type: WalletType) => SignerFactory;
|
|
34
|
+
switchNetwork: (wallet: WalletType, network: Network) => Promise<ConnectResult> | undefined;
|
|
35
|
+
connect: (wallet: WalletType, network: Network) => Promise<ConnectResult> | undefined;
|
|
36
|
+
state: (type: WalletType) => WalletState;
|
|
37
|
+
notifier: (data: SwapProgressNotification) => void;
|
|
38
|
+
claimedBy?: string;
|
|
39
|
+
resetClaimedBy?: () => void;
|
|
40
|
+
}
|
|
41
|
+
export interface UseQueueManagerParams {
|
|
42
|
+
lastConnectedWallet: string;
|
|
43
|
+
disconnectedWallet: WalletType | undefined;
|
|
44
|
+
clearDisconnectedWallet: () => void;
|
|
45
|
+
evmChains: EvmBlockchainMeta[];
|
|
46
|
+
notifier: SwapQueueContext['notifier'];
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EACL,IAAI,EACJ,OAAO,EACP,WAAW,EACX,UAAU,EACX,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE/D,oBAAY,YAAY,GAAG,QAAQ,CACjC,WAAW,EACX,eAAe,EACf,gBAAgB,CACjB,CAAC;AAEF,MAAM,WAAW,WAAY,SAAQ,YAAY;IAC/C,WAAW,EAAE,WAAW,CAAC;CAC1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AAuB,EAAE,MAAM,IAAI,CAAC;IACpC,SAAS,EAAE,iBAAiB,EAAE,CAAC;IAC/B,QAAQ,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAC;CACxC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rango-dev/queue-manager-rango-preset",
|
|
3
|
+
"version": "0.1.10-next.101",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"module": "dist/queue-manager-rango-preset.esm.js",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"typings": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"src"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"dev": "tsdx watch",
|
|
14
|
+
"build": "tsdx build --tsconfig ./tsconfig.json",
|
|
15
|
+
"test": "tsdx test",
|
|
16
|
+
"lint": "tsdx lint",
|
|
17
|
+
"size": "size-limit",
|
|
18
|
+
"analyze": "size-limit --why"
|
|
19
|
+
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"@rango-dev/queue-manager-core": "*",
|
|
22
|
+
"@rango-dev/queue-manager-react": "*",
|
|
23
|
+
"@rango-dev/wallets-core": "*",
|
|
24
|
+
"@rango-dev/wallets-shared": "*",
|
|
25
|
+
"@sentry/browser": "*",
|
|
26
|
+
"bignumber.js": "*",
|
|
27
|
+
"rango-types": "*",
|
|
28
|
+
"uuid": "*"
|
|
29
|
+
},
|
|
30
|
+
"husky": {
|
|
31
|
+
"hooks": {
|
|
32
|
+
"pre-commit": "tsdx lint"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"prettier": {
|
|
36
|
+
"printWidth": 80,
|
|
37
|
+
"semi": true,
|
|
38
|
+
"singleQuote": true,
|
|
39
|
+
"trailingComma": "es5"
|
|
40
|
+
},
|
|
41
|
+
"size-limit": [
|
|
42
|
+
{
|
|
43
|
+
"path": "dist/queue-manager-rango-preset.cjs.production.min.js",
|
|
44
|
+
"limit": "10 KB"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"path": "dist/queue-manager-rango-preset.esm.js",
|
|
48
|
+
"limit": "10 KB"
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@types/uuid": "^8.3.4"
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"@sentry/browser": "^6.12.0",
|
|
56
|
+
"rango-sdk": "^0.1.20",
|
|
57
|
+
"uuid": "^9.0.0"
|
|
58
|
+
},
|
|
59
|
+
"publishConfig": {
|
|
60
|
+
"access": "public"
|
|
61
|
+
}
|
|
62
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { ExecuterActions } from '@rango-dev/queue-manager-core';
|
|
2
|
+
import {
|
|
3
|
+
delay,
|
|
4
|
+
getCurrentStep,
|
|
5
|
+
isCosmosTransaction,
|
|
6
|
+
isEvmTransaction,
|
|
7
|
+
isSolanaTransaction,
|
|
8
|
+
isStarknetTransaction,
|
|
9
|
+
isTrasnferTransaction,
|
|
10
|
+
isTronTransaction,
|
|
11
|
+
resetNetworkStatus,
|
|
12
|
+
updateSwapStatus,
|
|
13
|
+
} from '../helpers';
|
|
14
|
+
import { SwapActionTypes, SwapQueueContext, SwapStorage } from '../types';
|
|
15
|
+
import { getNextStep, MessageSeverity } from '../shared';
|
|
16
|
+
import { TransactionStatusResponse } from 'rango-sdk';
|
|
17
|
+
import { httpService } from '../services';
|
|
18
|
+
|
|
19
|
+
const INTERVAL_FOR_CHECK = 3_000;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Subscribe to status of swap transaction by checking from server periodically.
|
|
23
|
+
* After getting the status, notify the user and schedule `SCHEDULE_NEXT_STEP`.
|
|
24
|
+
*/
|
|
25
|
+
async function checkTransactionStatus({
|
|
26
|
+
getStorage,
|
|
27
|
+
setStorage,
|
|
28
|
+
next,
|
|
29
|
+
schedule,
|
|
30
|
+
retry,
|
|
31
|
+
context,
|
|
32
|
+
}: ExecuterActions<
|
|
33
|
+
SwapStorage,
|
|
34
|
+
SwapActionTypes,
|
|
35
|
+
SwapQueueContext
|
|
36
|
+
>): Promise<void> {
|
|
37
|
+
const swap = getStorage().swapDetails;
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
39
|
+
const currentStep = getCurrentStep(swap)!;
|
|
40
|
+
const txId = currentStep.executedTransactionId;
|
|
41
|
+
|
|
42
|
+
let status: TransactionStatusResponse | null = null;
|
|
43
|
+
try {
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
45
|
+
status = await httpService.checkStatus({
|
|
46
|
+
requestId: swap.requestId,
|
|
47
|
+
txId: txId!,
|
|
48
|
+
step: currentStep.id,
|
|
49
|
+
});
|
|
50
|
+
} catch (e) {
|
|
51
|
+
await delay(INTERVAL_FOR_CHECK);
|
|
52
|
+
retry();
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const outputAmount: string | null =
|
|
57
|
+
status?.outputAmount ||
|
|
58
|
+
(!!currentStep.outputAmount ? currentStep.outputAmount : null);
|
|
59
|
+
const prevOutputAmount = currentStep.outputAmount;
|
|
60
|
+
swap.extraMessage = status?.extraMessage || swap.extraMessage;
|
|
61
|
+
swap.extraMessageSeverity = MessageSeverity.info;
|
|
62
|
+
swap.extraMessageDetail = '';
|
|
63
|
+
|
|
64
|
+
currentStep.status = status?.status || currentStep.status;
|
|
65
|
+
currentStep.diagnosisUrl =
|
|
66
|
+
status?.diagnosisUrl || currentStep.diagnosisUrl || null;
|
|
67
|
+
currentStep.outputAmount = outputAmount || currentStep.outputAmount;
|
|
68
|
+
currentStep.explorerUrl = status?.explorerUrl || currentStep.explorerUrl;
|
|
69
|
+
currentStep.internalSteps = status?.steps || null;
|
|
70
|
+
|
|
71
|
+
const newTransaction = status?.newTx;
|
|
72
|
+
|
|
73
|
+
if (!!newTransaction) {
|
|
74
|
+
currentStep.status = 'created';
|
|
75
|
+
currentStep.executedTransactionId = null;
|
|
76
|
+
currentStep.executedTransactionTime = null;
|
|
77
|
+
currentStep.transferTransaction = null;
|
|
78
|
+
currentStep.cosmosTransaction = null;
|
|
79
|
+
currentStep.evmTransaction = null;
|
|
80
|
+
currentStep.solanaTransaction = null;
|
|
81
|
+
currentStep.evmApprovalTransaction = null;
|
|
82
|
+
currentStep.starknetApprovalTransaction = null;
|
|
83
|
+
currentStep.starknetTransaction = null;
|
|
84
|
+
currentStep.tronApprovalTransaction = null;
|
|
85
|
+
currentStep.tronTransaction = null;
|
|
86
|
+
|
|
87
|
+
if (isEvmTransaction(newTransaction)) {
|
|
88
|
+
if (newTransaction.isApprovalTx)
|
|
89
|
+
currentStep.evmApprovalTransaction = newTransaction;
|
|
90
|
+
else currentStep.evmTransaction = newTransaction;
|
|
91
|
+
} else if (isCosmosTransaction(newTransaction)) {
|
|
92
|
+
currentStep.cosmosTransaction = newTransaction;
|
|
93
|
+
} else if (isSolanaTransaction(newTransaction)) {
|
|
94
|
+
currentStep.solanaTransaction = newTransaction;
|
|
95
|
+
} else if (isTrasnferTransaction(newTransaction)) {
|
|
96
|
+
currentStep.transferTransaction = newTransaction;
|
|
97
|
+
} else if (isStarknetTransaction(newTransaction)) {
|
|
98
|
+
if (newTransaction.isApprovalTx)
|
|
99
|
+
currentStep.starknetApprovalTransaction = newTransaction;
|
|
100
|
+
else currentStep.starknetTransaction = newTransaction;
|
|
101
|
+
} else if (isTronTransaction(newTransaction)) {
|
|
102
|
+
if (newTransaction.isApprovalTx)
|
|
103
|
+
currentStep.tronApprovalTransaction = newTransaction;
|
|
104
|
+
else currentStep.tronTransaction = newTransaction;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (prevOutputAmount === null && outputAmount !== null)
|
|
109
|
+
context.notifier({
|
|
110
|
+
eventType: 'step_completed_with_output',
|
|
111
|
+
swap: swap,
|
|
112
|
+
step: currentStep,
|
|
113
|
+
});
|
|
114
|
+
else if (prevOutputAmount === null && outputAmount === null) {
|
|
115
|
+
// it is needed to set notification after reloading the page
|
|
116
|
+
context.notifier({
|
|
117
|
+
eventType: 'check_tx_status',
|
|
118
|
+
swap: swap,
|
|
119
|
+
step: currentStep,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (currentStep.status === 'success') {
|
|
124
|
+
const nextStep = getNextStep(swap, currentStep);
|
|
125
|
+
swap.extraMessageDetail = '';
|
|
126
|
+
swap.extraMessage = !!nextStep
|
|
127
|
+
? `starting next step: ${nextStep.swapperId}: ${nextStep.fromBlockchain} -> ${nextStep.toBlockchain}`
|
|
128
|
+
: '';
|
|
129
|
+
} else if (currentStep.status === 'failed') {
|
|
130
|
+
swap.extraMessage = 'Transaction failed in blockchain';
|
|
131
|
+
swap.extraMessageSeverity = MessageSeverity.error;
|
|
132
|
+
swap.extraMessageDetail = '';
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Sync data with storage
|
|
136
|
+
setStorage({ ...getStorage(), swapDetails: swap });
|
|
137
|
+
|
|
138
|
+
if (
|
|
139
|
+
status?.status === 'failed' ||
|
|
140
|
+
status?.status === 'success' ||
|
|
141
|
+
(status?.status === 'running' && !!status.newTx)
|
|
142
|
+
) {
|
|
143
|
+
schedule(SwapActionTypes.SCHEDULE_NEXT_STEP);
|
|
144
|
+
next();
|
|
145
|
+
} else {
|
|
146
|
+
await delay(INTERVAL_FOR_CHECK);
|
|
147
|
+
retry();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Subscribe to status of approval transaction by checking from server periodically.
|
|
153
|
+
* After getting the status, notify the user and schedule `SCHEDULE_NEXT_STEP`.
|
|
154
|
+
*/
|
|
155
|
+
async function checkApprovalStatus({
|
|
156
|
+
getStorage,
|
|
157
|
+
setStorage,
|
|
158
|
+
next,
|
|
159
|
+
schedule,
|
|
160
|
+
retry,
|
|
161
|
+
failed,
|
|
162
|
+
context,
|
|
163
|
+
}: ExecuterActions<
|
|
164
|
+
SwapStorage,
|
|
165
|
+
SwapActionTypes,
|
|
166
|
+
SwapQueueContext
|
|
167
|
+
>): Promise<void> {
|
|
168
|
+
const swap = getStorage().swapDetails as SwapStorage['swapDetails'];
|
|
169
|
+
// double check it after fixing parallel
|
|
170
|
+
// const onFinish = () => {
|
|
171
|
+
// // TODO resetClaimedBy is undefined here
|
|
172
|
+
// if (context.resetClaimedBy) {
|
|
173
|
+
// context.resetClaimedBy();
|
|
174
|
+
// }
|
|
175
|
+
// };
|
|
176
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
177
|
+
const currentStep = getCurrentStep(swap)!;
|
|
178
|
+
let isApproved = false;
|
|
179
|
+
try {
|
|
180
|
+
const response = await httpService.checkApproval(
|
|
181
|
+
swap.requestId,
|
|
182
|
+
currentStep.executedTransactionId || ''
|
|
183
|
+
);
|
|
184
|
+
isApproved = response.isApproved;
|
|
185
|
+
if (!isApproved && response.txStatus === 'failed') {
|
|
186
|
+
// approve transaction failed on
|
|
187
|
+
// we should fail the whole swap
|
|
188
|
+
const updateResult = updateSwapStatus({
|
|
189
|
+
getStorage,
|
|
190
|
+
setStorage,
|
|
191
|
+
nextStatus: 'failed',
|
|
192
|
+
nextStepStatus: 'failed',
|
|
193
|
+
errorCode: 'SEND_TX_FAILED',
|
|
194
|
+
message: 'Approve transaction failed',
|
|
195
|
+
details: 'Smart contract approval failed in blockchain.',
|
|
196
|
+
});
|
|
197
|
+
context.notifier({
|
|
198
|
+
eventType: 'smart_contract_call_failed',
|
|
199
|
+
...updateResult,
|
|
200
|
+
});
|
|
201
|
+
failed();
|
|
202
|
+
// onFinish();
|
|
203
|
+
} else if (!isApproved) {
|
|
204
|
+
// it is needed to set notification after reloading the page
|
|
205
|
+
context.notifier({
|
|
206
|
+
eventType: 'check_approve_tx_status',
|
|
207
|
+
swap: swap,
|
|
208
|
+
step: currentStep,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
} catch (e) {
|
|
212
|
+
console.error('Failed to check getApprovedAmount', e);
|
|
213
|
+
isApproved = false;
|
|
214
|
+
}
|
|
215
|
+
if (isApproved) {
|
|
216
|
+
currentStep.status = 'approved';
|
|
217
|
+
swap.extraMessage = `Spending ${currentStep.fromSymbol} approved successfully.`;
|
|
218
|
+
swap.extraMessageDetail = null;
|
|
219
|
+
swap.extraMessageSeverity = MessageSeverity.success;
|
|
220
|
+
currentStep.evmApprovalTransaction = null;
|
|
221
|
+
currentStep.executedTransactionId = null;
|
|
222
|
+
currentStep.executedTransactionTime = null;
|
|
223
|
+
currentStep.starknetApprovalTransaction = null;
|
|
224
|
+
currentStep.tronApprovalTransaction = null;
|
|
225
|
+
|
|
226
|
+
setStorage({
|
|
227
|
+
...getStorage(),
|
|
228
|
+
swapDetails: swap,
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
context.notifier({
|
|
232
|
+
eventType: 'contract_confirmed',
|
|
233
|
+
swap: swap,
|
|
234
|
+
step: currentStep,
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
schedule(SwapActionTypes.SCHEDULE_NEXT_STEP);
|
|
238
|
+
next();
|
|
239
|
+
} else {
|
|
240
|
+
await delay(2000);
|
|
241
|
+
retry();
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
*
|
|
247
|
+
* For doing a swap the user needs to accept a `contract` so it can use the user balance.
|
|
248
|
+
* There is two types of check status:
|
|
249
|
+
* 1. Checking approval transaction (Give permission to a contract)
|
|
250
|
+
* 2. Checking swap transaction.
|
|
251
|
+
*
|
|
252
|
+
*/
|
|
253
|
+
export async function checkStatus(
|
|
254
|
+
actions: ExecuterActions<SwapStorage, SwapActionTypes, SwapQueueContext>
|
|
255
|
+
): Promise<void> {
|
|
256
|
+
const swap = actions.getStorage().swapDetails;
|
|
257
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
258
|
+
const currentStep = getCurrentStep(swap)!;
|
|
259
|
+
|
|
260
|
+
// Reset network status
|
|
261
|
+
// Because when check status is on `loading` or `failed` status, it shows previous message that isn't related to current state.
|
|
262
|
+
resetNetworkStatus(actions);
|
|
263
|
+
|
|
264
|
+
if (currentStep.status === 'running') {
|
|
265
|
+
await checkTransactionStatus(actions);
|
|
266
|
+
} else if (currentStep.status === 'waitingForApproval') {
|
|
267
|
+
await checkApprovalStatus(actions);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { ExecuterActions } from '@rango-dev/queue-manager-core';
|
|
2
|
+
import { SwapActionTypes, SwapQueueContext, SwapStorage } from '../types';
|
|
3
|
+
import {
|
|
4
|
+
getCurrentStep,
|
|
5
|
+
isCosmosTransaction,
|
|
6
|
+
isEvmTransaction,
|
|
7
|
+
isSolanaTransaction,
|
|
8
|
+
isTrasnferTransaction,
|
|
9
|
+
isStarknetTransaction,
|
|
10
|
+
isTronTransaction,
|
|
11
|
+
updateSwapStatus,
|
|
12
|
+
throwOnOK,
|
|
13
|
+
} from '../helpers';
|
|
14
|
+
import { prettifyErrorMessage } from '../shared-errors';
|
|
15
|
+
import { CreateTransactionRequest } from 'rango-sdk';
|
|
16
|
+
import { httpService } from '../services';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* When a user asks for a swap, We first create the transaction by sending a request to server
|
|
21
|
+
* Server will return the transaction that need to be sent to wallet.
|
|
22
|
+
* It can be failed if server goes through an error, If not, we will schedule the `EXECTUTE_TRANSACTION`.
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
export async function createTransaction(
|
|
26
|
+
actions: ExecuterActions<SwapStorage, SwapActionTypes, SwapQueueContext>
|
|
27
|
+
): Promise<void> {
|
|
28
|
+
const { setStorage, getStorage, next, schedule, context } = actions;
|
|
29
|
+
const swap = getStorage().swapDetails;
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
31
|
+
const currentStep = getCurrentStep(swap)!;
|
|
32
|
+
|
|
33
|
+
const {
|
|
34
|
+
evmTransaction,
|
|
35
|
+
cosmosTransaction,
|
|
36
|
+
transferTransaction,
|
|
37
|
+
evmApprovalTransaction,
|
|
38
|
+
solanaTransaction,
|
|
39
|
+
tronTransaction,
|
|
40
|
+
tronApprovalTransaction,
|
|
41
|
+
starknetTransaction,
|
|
42
|
+
starknetApprovalTransaction,
|
|
43
|
+
} = currentStep;
|
|
44
|
+
|
|
45
|
+
if (
|
|
46
|
+
!evmTransaction &&
|
|
47
|
+
!evmApprovalTransaction &&
|
|
48
|
+
!tronTransaction &&
|
|
49
|
+
!tronApprovalTransaction &&
|
|
50
|
+
!starknetTransaction &&
|
|
51
|
+
!starknetApprovalTransaction &&
|
|
52
|
+
!cosmosTransaction &&
|
|
53
|
+
!transferTransaction &&
|
|
54
|
+
!solanaTransaction
|
|
55
|
+
) {
|
|
56
|
+
const request: CreateTransactionRequest = {
|
|
57
|
+
requestId: swap.requestId,
|
|
58
|
+
step: currentStep.id,
|
|
59
|
+
userSettings: {
|
|
60
|
+
slippage: swap.settings.slippage,
|
|
61
|
+
infiniteApprove: swap.settings.infiniteApprove,
|
|
62
|
+
},
|
|
63
|
+
validations: {
|
|
64
|
+
balance: swap.validateBalanceOrFee,
|
|
65
|
+
fee: swap.validateBalanceOrFee,
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
try {
|
|
69
|
+
// Getting transcation from server.
|
|
70
|
+
|
|
71
|
+
const { transaction } = await throwOnOK(
|
|
72
|
+
httpService.createTransaction(request)
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
if (transaction) {
|
|
76
|
+
if (isEvmTransaction(transaction)) {
|
|
77
|
+
if (transaction.isApprovalTx)
|
|
78
|
+
currentStep.evmApprovalTransaction = transaction;
|
|
79
|
+
else currentStep.evmTransaction = transaction;
|
|
80
|
+
} else if (isCosmosTransaction(transaction)) {
|
|
81
|
+
currentStep.cosmosTransaction = transaction;
|
|
82
|
+
} else if (isSolanaTransaction(transaction)) {
|
|
83
|
+
currentStep.solanaTransaction = transaction;
|
|
84
|
+
} else if (isTrasnferTransaction(transaction)) {
|
|
85
|
+
currentStep.transferTransaction = transaction;
|
|
86
|
+
} else if (isStarknetTransaction(transaction)) {
|
|
87
|
+
if (transaction.isApprovalTx)
|
|
88
|
+
currentStep.starknetApprovalTransaction = transaction;
|
|
89
|
+
else currentStep.starknetTransaction = transaction;
|
|
90
|
+
} else if (isTronTransaction(transaction)) {
|
|
91
|
+
if (transaction.isApprovalTx)
|
|
92
|
+
currentStep.tronApprovalTransaction = transaction;
|
|
93
|
+
else currentStep.tronTransaction = transaction;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
setStorage({ ...getStorage(), swapDetails: swap });
|
|
98
|
+
schedule(SwapActionTypes.EXECUTE_TRANSACTION);
|
|
99
|
+
next();
|
|
100
|
+
} catch (error) {
|
|
101
|
+
swap.status = 'failed';
|
|
102
|
+
swap.finishTime = new Date().getTime().toString();
|
|
103
|
+
const { extraMessage, extraMessageDetail } = prettifyErrorMessage(error);
|
|
104
|
+
|
|
105
|
+
const updateResult = updateSwapStatus({
|
|
106
|
+
getStorage,
|
|
107
|
+
setStorage,
|
|
108
|
+
nextStatus: 'failed',
|
|
109
|
+
nextStepStatus: 'failed',
|
|
110
|
+
message: extraMessage,
|
|
111
|
+
details: extraMessageDetail,
|
|
112
|
+
errorCode: 'FETCH_TX_FAILED',
|
|
113
|
+
});
|
|
114
|
+
context.notifier({
|
|
115
|
+
eventType: 'task_failed',
|
|
116
|
+
...updateResult,
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
actions.failed();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|