@rango-dev/queue-manager-rango-preset 0.41.1-next.0 → 0.42.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/dist/actions/checkStatus.d.ts.map +1 -1
- package/dist/actions/executeTransaction.d.ts.map +1 -1
- package/dist/actions/scheduleNextStep.d.ts.map +1 -1
- package/dist/helpers.d.ts +8 -2
- package/dist/helpers.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +3 -3
- package/dist/queue-manager-rango-preset.build.json +1 -1
- package/dist/services/eventEmitter.d.ts.map +1 -1
- package/dist/shared.d.ts +3 -7
- package/dist/shared.d.ts.map +1 -1
- package/dist/types.d.ts +9 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/actions/checkStatus.ts +11 -5
- package/src/actions/executeTransaction.ts +3 -5
- package/src/actions/scheduleNextStep.ts +6 -0
- package/src/helpers.ts +90 -37
- package/src/index.ts +2 -6
- package/src/services/eventEmitter.ts +18 -8
- package/src/shared.ts +29 -71
- package/src/types.ts +11 -4
|
@@ -12,9 +12,11 @@ import {
|
|
|
12
12
|
getCurrentStepTx,
|
|
13
13
|
getFailedStep,
|
|
14
14
|
getLastSuccessfulStep,
|
|
15
|
+
getSwapInputUsd,
|
|
16
|
+
getSwapOutputUsd,
|
|
15
17
|
isApprovalCurrentStepTx,
|
|
16
18
|
} from '../helpers';
|
|
17
|
-
import {
|
|
19
|
+
import { getCurrentBlockchainOfOrNull } from '../shared';
|
|
18
20
|
import {
|
|
19
21
|
EventSeverity,
|
|
20
22
|
RouteEventType,
|
|
@@ -140,7 +142,7 @@ function getEventPayload(
|
|
|
140
142
|
return result;
|
|
141
143
|
}
|
|
142
144
|
|
|
143
|
-
function emitRouteEvent(stepEvent: StepEvent, route: Route) {
|
|
145
|
+
function emitRouteEvent(stepEvent: StepEvent, route: Route, swap: PendingSwap) {
|
|
144
146
|
let routeEvent: RouteEvent | undefined;
|
|
145
147
|
const { type } = stepEvent;
|
|
146
148
|
switch (type) {
|
|
@@ -150,9 +152,17 @@ function emitRouteEvent(stepEvent: StepEvent, route: Route) {
|
|
|
150
152
|
case StepEventType.FAILED:
|
|
151
153
|
routeEvent = { ...stepEvent, type: RouteEventType.FAILED };
|
|
152
154
|
break;
|
|
153
|
-
case StepEventType.SUCCEEDED:
|
|
154
|
-
routeEvent = {
|
|
155
|
+
case StepEventType.SUCCEEDED: {
|
|
156
|
+
routeEvent = {
|
|
157
|
+
...stepEvent,
|
|
158
|
+
type: RouteEventType.SUCCEEDED,
|
|
159
|
+
inputAmount: swap.inputAmount,
|
|
160
|
+
inputAmountUsd: getSwapInputUsd(swap),
|
|
161
|
+
outputAmount: swap.steps[swap.steps.length - 1].outputAmount ?? '',
|
|
162
|
+
outputAmountUsd: getSwapOutputUsd(swap),
|
|
163
|
+
};
|
|
155
164
|
break;
|
|
165
|
+
}
|
|
156
166
|
default:
|
|
157
167
|
break;
|
|
158
168
|
}
|
|
@@ -178,8 +188,8 @@ export function notifier(params: NotifierParams) {
|
|
|
178
188
|
const fromAsset = `${step.fromBlockchain}.${step.fromSymbol}`;
|
|
179
189
|
const toAsset = `${step.toBlockchain}.${step.toSymbol}`;
|
|
180
190
|
const outputAmount = step.outputAmount ?? '';
|
|
181
|
-
const
|
|
182
|
-
?
|
|
191
|
+
const currentFromBlockchain = !!params.step
|
|
192
|
+
? getCurrentBlockchainOfOrNull(params.swap, params.step)
|
|
183
193
|
: null;
|
|
184
194
|
let message = '';
|
|
185
195
|
let messageSeverity: StepEvent['messageSeverity'] = EventSeverity.INFO;
|
|
@@ -254,7 +264,7 @@ export function notifier(params: NotifierParams) {
|
|
|
254
264
|
event.status ===
|
|
255
265
|
StepExecutionBlockedEventStatus.WAITING_FOR_NETWORK_CHANGE
|
|
256
266
|
) {
|
|
257
|
-
message = `Please change your wallet network to ${
|
|
267
|
+
message = `Please change your wallet network to ${currentFromBlockchain}.`;
|
|
258
268
|
messageSeverity = EventSeverity.WARNING;
|
|
259
269
|
}
|
|
260
270
|
break;
|
|
@@ -267,6 +277,6 @@ export function notifier(params: NotifierParams) {
|
|
|
267
277
|
emitStepEvent({ ...event, message, messageSeverity }, route, step);
|
|
268
278
|
}
|
|
269
279
|
if (params.event.type === StepEventType.FAILED || !params.step) {
|
|
270
|
-
emitRouteEvent({ ...event, message, messageSeverity }, route);
|
|
280
|
+
emitRouteEvent({ ...event, message, messageSeverity }, route, params.swap);
|
|
271
281
|
}
|
|
272
282
|
}
|
package/src/shared.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { NamespaceInputForConnect } from '@rango-dev/wallets-core/dist/legacy/types';
|
|
2
1
|
import type { Network, WalletType } from '@rango-dev/wallets-shared';
|
|
3
2
|
import type {
|
|
4
3
|
BlockchainMeta,
|
|
@@ -38,6 +37,7 @@ export type WalletBalance = {
|
|
|
38
37
|
};
|
|
39
38
|
|
|
40
39
|
export type Account = {
|
|
40
|
+
balances: WalletBalance[] | null;
|
|
41
41
|
address: string;
|
|
42
42
|
loading: boolean;
|
|
43
43
|
walletType: WalletType;
|
|
@@ -87,91 +87,49 @@ export enum MessageSeverity {
|
|
|
87
87
|
|
|
88
88
|
export type SwapStatus = 'running' | 'failed' | 'success';
|
|
89
89
|
|
|
90
|
-
export
|
|
91
|
-
namespace: NamespaceInputForConnect['namespace'];
|
|
92
|
-
network: string;
|
|
93
|
-
}
|
|
94
|
-
export const getCurrentNamespaceOfOrNull = (
|
|
90
|
+
export const getCurrentBlockchainOfOrNull = (
|
|
95
91
|
swap: PendingSwap,
|
|
96
92
|
step: PendingSwapStep
|
|
97
|
-
):
|
|
93
|
+
): Network | null => {
|
|
98
94
|
try {
|
|
99
|
-
return
|
|
95
|
+
return getCurrentBlockchainOf(swap, step);
|
|
100
96
|
} catch (e) {
|
|
101
97
|
return null;
|
|
102
98
|
}
|
|
103
99
|
};
|
|
104
100
|
|
|
105
|
-
export const
|
|
101
|
+
export const getCurrentBlockchainOf = (
|
|
106
102
|
swap: PendingSwap,
|
|
107
103
|
step: PendingSwapStep
|
|
108
|
-
):
|
|
109
|
-
const
|
|
110
|
-
step.evmTransaction?.blockChain ||
|
|
111
|
-
|
|
104
|
+
): Network => {
|
|
105
|
+
const b1 =
|
|
106
|
+
step.evmTransaction?.blockChain ||
|
|
107
|
+
step.evmApprovalTransaction?.blockChain ||
|
|
112
108
|
step.starknetTransaction?.blockChain ||
|
|
113
|
-
step.starknetApprovalTransaction?.blockChain
|
|
114
|
-
const tronNetwork =
|
|
109
|
+
step.starknetApprovalTransaction?.blockChain ||
|
|
115
110
|
step.tronTransaction?.blockChain ||
|
|
116
|
-
step.tronApprovalTransaction?.blockChain
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
namespace: 'EVM',
|
|
124
|
-
network: evmNetwork,
|
|
125
|
-
};
|
|
126
|
-
} else if (starknetNetwork) {
|
|
127
|
-
return {
|
|
128
|
-
namespace: 'Starknet',
|
|
129
|
-
network: starknetNetwork,
|
|
130
|
-
};
|
|
131
|
-
} else if (tronNetwork) {
|
|
132
|
-
return {
|
|
133
|
-
namespace: 'Tron',
|
|
134
|
-
network: tronNetwork,
|
|
135
|
-
};
|
|
136
|
-
} else if (cosmosNetwork) {
|
|
137
|
-
return {
|
|
138
|
-
namespace: 'Cosmos',
|
|
139
|
-
network: cosmosNetwork,
|
|
140
|
-
};
|
|
141
|
-
} else if (solanaNetwork) {
|
|
142
|
-
return {
|
|
143
|
-
namespace: 'Solana',
|
|
144
|
-
network: solanaNetwork,
|
|
145
|
-
};
|
|
146
|
-
} else if (tonNetwork) {
|
|
147
|
-
return {
|
|
148
|
-
namespace: 'Ton',
|
|
149
|
-
network: tonNetwork,
|
|
150
|
-
};
|
|
151
|
-
} else if (!!step.transferTransaction) {
|
|
152
|
-
const transferAddress = step.transferTransaction.fromWalletAddress;
|
|
153
|
-
if (!transferAddress) {
|
|
154
|
-
throw PrettyError.BlockchainMissing();
|
|
155
|
-
}
|
|
156
|
-
const utxoNetwork = Object.keys(swap.wallets).find(
|
|
157
|
-
(network) => swap.wallets[network]?.address === transferAddress
|
|
158
|
-
);
|
|
159
|
-
if (!utxoNetwork) {
|
|
160
|
-
throw PrettyError.BlockchainMissing();
|
|
161
|
-
}
|
|
111
|
+
step.tronApprovalTransaction?.blockChain ||
|
|
112
|
+
step.cosmosTransaction?.blockChain ||
|
|
113
|
+
step.solanaTransaction?.blockChain ||
|
|
114
|
+
step.tonTransaction?.blockChain;
|
|
115
|
+
if (b1) {
|
|
116
|
+
return b1;
|
|
117
|
+
}
|
|
162
118
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
};
|
|
119
|
+
const transferAddress = step.transferTransaction?.fromWalletAddress;
|
|
120
|
+
if (!transferAddress) {
|
|
121
|
+
throw PrettyError.BlockchainMissing();
|
|
167
122
|
}
|
|
168
123
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
124
|
+
const blockchain =
|
|
125
|
+
Object.keys(swap.wallets).find(
|
|
126
|
+
(b) => swap.wallets[b]?.address === transferAddress
|
|
127
|
+
) || null;
|
|
128
|
+
if (blockchain == null) {
|
|
129
|
+
throw PrettyError.BlockchainMissing();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return blockchain;
|
|
175
133
|
};
|
|
176
134
|
|
|
177
135
|
export const getScannerUrl = (
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Wallet } from './shared';
|
|
2
2
|
import type {
|
|
3
3
|
QueueContext,
|
|
4
4
|
QueueDef,
|
|
@@ -70,9 +70,13 @@ export interface SwapQueueContext extends QueueContext {
|
|
|
70
70
|
getSigners: (type: WalletType) => Promise<SignerFactory>;
|
|
71
71
|
switchNetwork: (
|
|
72
72
|
wallet: WalletType,
|
|
73
|
-
|
|
74
|
-
) => Promise<ConnectResult |
|
|
73
|
+
network: Network
|
|
74
|
+
) => Promise<ConnectResult | undefined> | undefined;
|
|
75
75
|
canSwitchNetworkTo: (type: WalletType, network: Network) => boolean;
|
|
76
|
+
connect: (
|
|
77
|
+
wallet: WalletType,
|
|
78
|
+
network: Network
|
|
79
|
+
) => Promise<ConnectResult> | undefined;
|
|
76
80
|
state: (type: WalletType) => WalletState;
|
|
77
81
|
isMobileWallet: (type: WalletType) => boolean;
|
|
78
82
|
|
|
@@ -185,12 +189,15 @@ export type FailedRouteEventPayload = {
|
|
|
185
189
|
export type FailedStepEventPayload = FailedRouteEventPayload;
|
|
186
190
|
|
|
187
191
|
export type SucceededRouteEventPayload = {
|
|
192
|
+
inputAmount: string;
|
|
193
|
+
inputAmountUsd: string;
|
|
188
194
|
outputAmount: string;
|
|
195
|
+
outputAmountUsd: string;
|
|
189
196
|
};
|
|
190
197
|
|
|
191
198
|
export type SucceededStepEventPayload = SucceededRouteEventPayload;
|
|
192
199
|
|
|
193
|
-
export type OutputRevealedEventPayload =
|
|
200
|
+
export type OutputRevealedEventPayload = { outputAmount: string };
|
|
194
201
|
|
|
195
202
|
export type StepExecutionEventPayload = {
|
|
196
203
|
status:
|