Skip to content

Commit 1bc1324

Browse files
committed
Implement dry run on review modal
1 parent e7e88af commit 1bc1324

18 files changed

Lines changed: 92 additions & 159 deletions

File tree

apps/main/.env.development

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ VITE_TRSRY_ADDR=7L53bUTBopuwFt3mKUfmkzgGLayYa1Yvn1hAg9v5UMrQzTfh
99
VITE_EVM_CHAIN_ID=222222
1010
VITE_DISPLAY_ASSET_ID="10"
1111
VITE_HSM_ENABLED=false
12-
VITE_DRY_RUN_ENABLED=false
12+
VITE_DRY_RUN_ENABLED=true

apps/main/.env.production

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ VITE_TRSRY_ADDR=7L53bUTBopuwFt3mKUfmkzgGLayYa1Yvn1hAg9v5UMrQzTfh
99
VITE_EVM_CHAIN_ID=222222
1010
VITE_DISPLAY_ASSET_ID="10"
1111
VITE_HSM_ENABLED=false
12-
VITE_DRY_RUN_ENABLED=false
12+
VITE_DRY_RUN_ENABLED=true

apps/main/src/api/dryRun.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
1-
import { QUERY_KEY_BLOCK_PREFIX } from "@galacticcouncil/utils"
21
import { queryOptions } from "@tanstack/react-query"
2+
import { Enum } from "polkadot-api"
33

44
import { decodeTx } from "@/modules/transactions/review/ReviewTransactionJsonView/ReviewTransactionJsonView.utils"
5-
import { AnyPapiTx } from "@/modules/transactions/types"
5+
import { AnyTransaction } from "@/modules/transactions/types"
6+
import { isPapiTransaction } from "@/modules/transactions/utils/polkadot"
67
import { getPapiTransactionCallData } from "@/modules/transactions/utils/tx"
78
import { TProviderContext } from "@/providers/rpcProvider"
89

910
export const papiDryRunErrorQuery = (
1011
{ papi, dryRunErrorDecoder, papiCompatibilityToken }: TProviderContext,
1112
address: string,
12-
tx: AnyPapiTx,
13+
tx: AnyTransaction,
1314
debug?: boolean,
1415
) =>
1516
queryOptions({
1617
queryKey: [
17-
QUERY_KEY_BLOCK_PREFIX,
1818
"dryRun",
1919
"papi",
2020
address,
2121
getPapiTransactionCallData(tx, papiCompatibilityToken),
2222
],
2323
queryFn: async () => {
2424
try {
25-
const json = decodeTx(tx)
25+
if (!isPapiTransaction(tx)) {
26+
return null
27+
}
28+
29+
const rawOrigin = Enum("Signed", address)
30+
const origin = Enum("system", rawOrigin)
31+
2632
const result = await papi.apis.DryRunApi.dry_run_call(
27-
{
28-
type: "system",
29-
value: {
30-
type: "Signed",
31-
value: address,
32-
},
33-
},
33+
origin,
3434
// @ts-expect-error contains structured call data
35-
json,
35+
tx.decodedCall,
3636
1,
3737
)
38-
38+
console.log(result)
3939
if (!result.success || result.value.execution_result.success) {
4040
return null
4141
}
@@ -44,6 +44,8 @@ export const papiDryRunErrorQuery = (
4444
result.value.execution_result.value.error,
4545
)
4646

47+
const json = decodeTx(tx)
48+
4749
if (debug && error) {
4850
console.log(new Date().toLocaleTimeString(), error.name, json)
4951
}

apps/main/src/api/trade.ts

Lines changed: 10 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import { QUERY_KEY_BLOCK_PREFIX } from "@galacticcouncil/utils"
33
import { QueryKey, queryOptions } from "@tanstack/react-query"
44
import Big from "big.js"
55

6-
import { papiDryRunErrorQuery } from "@/api/dryRun"
76
import { getTimeFrameMillis } from "@/components/TimeFrame/TimeFrame.utils"
8-
import { ENV } from "@/config/env"
97
import {
108
DcaFormValues,
119
DcaOrdersMode,
@@ -84,24 +82,17 @@ export const bestSellTxQuery = (
8482
type BestSellWithTxArgs = BestSellArgs & {
8583
readonly slippage: number
8684
readonly address: string
87-
readonly dryRun?: boolean
8885
}
8986

9087
export const bestSellWithTxQuery = (
9188
rpc: TProviderContext,
92-
{ slippage, address, dryRun, ...bestSellArgs }: BestSellWithTxArgs,
89+
{ slippage, address, ...bestSellArgs }: BestSellWithTxArgs,
9390
) => {
9491
const { queryClient } = rpc
9592
const bestSell = bestSellQuery(rpc, bestSellArgs)
9693

9794
return queryOptions({
98-
queryKey: [
99-
QUERY_KEY_BLOCK_PREFIX,
100-
bestSell.queryKey,
101-
slippage,
102-
address,
103-
dryRun,
104-
],
95+
queryKey: [QUERY_KEY_BLOCK_PREFIX, bestSell.queryKey, slippage, address],
10596
queryFn: async () => {
10697
const swap = await queryClient.ensureQueryData(bestSell)
10798

@@ -117,17 +108,9 @@ export const bestSellWithTxQuery = (
117108
? await queryClient.ensureQueryData(txQuery)
118109
: null
119110

120-
const dryRunError =
121-
tx && dryRun && ENV.VITE_DRY_RUN_ENABLED
122-
? await queryClient.ensureQueryData(
123-
papiDryRunErrorQuery(rpc, address, tx, bestSellArgs.debug),
124-
)
125-
: null
126-
127111
return {
128112
swap,
129113
tx,
130-
dryRunError,
131114
}
132115
},
133116
enabled: bestSell.enabled as boolean,
@@ -189,7 +172,6 @@ type BestSellTwapWithTxArgs = BestSellTwapArgs & {
189172
readonly slippage: number
190173
readonly address: string
191174
readonly maxRetries: number
192-
readonly dryRun?: boolean
193175
}
194176

195177
export const bestSellTwapWithTxQuery = (
@@ -198,7 +180,6 @@ export const bestSellTwapWithTxQuery = (
198180
slippage,
199181
maxRetries,
200182
address,
201-
dryRun,
202183
...bestSellTwapArgs
203184
}: BestSellTwapWithTxArgs,
204185
enabled = true,
@@ -213,7 +194,6 @@ export const bestSellTwapWithTxQuery = (
213194
slippage,
214195
maxRetries,
215196
address,
216-
dryRun,
217197
],
218198
queryFn: async () => {
219199
const twap = await queryClient.ensureQueryData(bestSellTwap)
@@ -231,14 +211,7 @@ export const bestSellTwapWithTxQuery = (
231211
? await queryClient.ensureQueryData(txQuery)
232212
: null
233213

234-
const dryRunError =
235-
tx && dryRun && ENV.VITE_DRY_RUN_ENABLED
236-
? await queryClient.ensureQueryData(
237-
papiDryRunErrorQuery(rpc, address, tx),
238-
)
239-
: null
240-
241-
return { twap, tx, dryRunError }
214+
return { twap, tx }
242215
},
243216
enabled: enabled && (bestSellTwap.enabled as boolean),
244217
})
@@ -303,24 +276,17 @@ export const bestBuyTxQuery = (
303276
type BestBuyWithTxArgs = BestBuyArgs & {
304277
readonly slippage: number
305278
readonly address: string
306-
readonly dryRun?: boolean
307279
}
308280

309281
export const bestBuyWithTxQuery = (
310282
rpc: TProviderContext,
311-
{ slippage, address, dryRun, ...bestBuyArgs }: BestBuyWithTxArgs,
283+
{ slippage, address, ...bestBuyArgs }: BestBuyWithTxArgs,
312284
) => {
313285
const { queryClient } = rpc
314286
const bestBuy = bestBuyQuery(rpc, bestBuyArgs)
315287

316288
return queryOptions({
317-
queryKey: [
318-
QUERY_KEY_BLOCK_PREFIX,
319-
bestBuy.queryKey,
320-
slippage,
321-
address,
322-
dryRun,
323-
],
289+
queryKey: [QUERY_KEY_BLOCK_PREFIX, bestBuy.queryKey, slippage, address],
324290
queryFn: async () => {
325291
const swap = await queryClient.ensureQueryData(bestBuy)
326292

@@ -336,17 +302,9 @@ export const bestBuyWithTxQuery = (
336302
? await queryClient.ensureQueryData(txQuery)
337303
: null
338304

339-
const dryRunError =
340-
tx && dryRun && ENV.VITE_DRY_RUN_ENABLED
341-
? await queryClient.ensureQueryData(
342-
papiDryRunErrorQuery(rpc, address, tx, bestBuyArgs.debug),
343-
)
344-
: null
345-
346305
return {
347306
swap,
348307
tx,
349-
dryRunError,
350308
}
351309
},
352310
enabled: bestBuy.enabled as boolean,
@@ -408,18 +366,11 @@ type BestBuyTwapWithTxArgs = BestBuyTwapArgs & {
408366
readonly slippage: number
409367
readonly address: string
410368
readonly maxRetries: number
411-
readonly dryRun?: boolean
412369
}
413370

414371
export const bestBuyTwapWithTxQuery = (
415372
rpc: TProviderContext,
416-
{
417-
slippage,
418-
maxRetries,
419-
address,
420-
dryRun,
421-
...bestBuyTwapArgs
422-
}: BestBuyTwapWithTxArgs,
373+
{ slippage, maxRetries, address, ...bestBuyTwapArgs }: BestBuyTwapWithTxArgs,
423374
enabled = true,
424375
) => {
425376
const { queryClient } = rpc
@@ -432,7 +383,6 @@ export const bestBuyTwapWithTxQuery = (
432383
slippage,
433384
maxRetries,
434385
address,
435-
dryRun,
436386
],
437387
queryFn: async () => {
438388
const twap = await queryClient.ensureQueryData(bestBuyTwap)
@@ -450,14 +400,7 @@ export const bestBuyTwapWithTxQuery = (
450400
? await queryClient.ensureQueryData(txQuery)
451401
: null
452402

453-
const dryRunError =
454-
tx && dryRun && ENV.VITE_DRY_RUN_ENABLED
455-
? await queryClient.ensureQueryData(
456-
papiDryRunErrorQuery(rpc, address, tx),
457-
)
458-
: null
459-
460-
return { twap, tx, dryRunError }
403+
return { twap, tx }
461404
},
462405
enabled: enabled && (bestBuyTwap.enabled as boolean),
463406
})
@@ -541,18 +484,17 @@ type DcaTradeOrderArgs = {
541484
readonly slippage: number
542485
readonly maxRetries: number
543486
readonly address: string
544-
readonly dryRun?: boolean
545487
}
546488

547489
export const dcaTradeOrderQuery = (
548490
rpc: TProviderContext,
549-
{ form, slippage, maxRetries, address, dryRun }: DcaTradeOrderArgs,
491+
{ form, slippage, maxRetries, address }: DcaTradeOrderArgs,
550492
) => {
551493
const { queryClient } = rpc
552494
const dcaOrder = dcaOrderQuery(rpc, form)
553495

554496
return queryOptions({
555-
queryKey: [...dcaOrder.queryKey, slippage, maxRetries, address, dryRun],
497+
queryKey: [...dcaOrder.queryKey, slippage, maxRetries, address],
556498
queryFn: async () => {
557499
const order = await queryClient.ensureQueryData(dcaOrder)
558500

@@ -571,14 +513,7 @@ export const dcaTradeOrderQuery = (
571513
? await queryClient.ensureQueryData(txQuery)
572514
: null
573515

574-
const dryRunError =
575-
orderTx && dryRun && ENV.VITE_DRY_RUN_ENABLED
576-
? await queryClient.ensureQueryData(
577-
papiDryRunErrorQuery(rpc, address, orderTx),
578-
)
579-
: null
580-
581-
return { order, orderTx, dryRunError }
516+
return { order, orderTx }
582517
},
583518
enabled: dcaOrder.enabled as boolean,
584519
})

apps/main/src/api/xcm.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
import { secondsToMilliseconds } from "date-fns"
1515
import { useEffect, useRef, useState } from "react"
1616

17-
import { TProviderContext, useRpcProvider } from "@/providers/rpcProvider"
17+
import { useRpcProvider } from "@/providers/rpcProvider"
1818

1919
export const useCrossChainConfig = () => {
2020
const { sdk } = useRpcProvider()
@@ -199,34 +199,18 @@ export const xcmTransferReportQuery = (
199199
})
200200

201201
export const xcmTransferCallQuery = (
202-
{ dryRunErrorDecoder }: TProviderContext,
203202
transfer: Transfer | null,
204203
amount: string,
205204
transferArgs: XcmTransferArgs,
206-
dryRun?: boolean,
207205
) =>
208206
queryOptions({
209207
enabled: !!transfer && !!amount,
210208
placeholderData: keepPreviousData,
211-
queryKey: ["xcm", "call", amount, transferArgs, dryRun],
209+
queryKey: ["xcm", "call", amount, transferArgs],
212210
queryFn: async () => {
213211
if (!transfer) throw new Error("Invalid transfer")
214212
const call = await transfer.buildCall(amount)
215213

216-
const dryRunError = await (async () => {
217-
if (!dryRun) {
218-
return null
219-
}
220-
221-
const result = await call?.dryRun()
222-
223-
if (result?.error) {
224-
return await dryRunErrorDecoder.parseError(result.error)
225-
}
226-
227-
return null
228-
})()
229-
230-
return { call, dryRunError }
214+
return { call }
231215
},
232216
})

apps/main/src/i18n/locales/en/common.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@
316316
"transaction.alert.pendingDispatchPermit": "Permit transaction is pending. Please wait.",
317317
"transaction.alert.sellAll": "You are selling your entire balance of {{ value, currency }}.",
318318
"transaction.alert.acceptRisk": "I accept the risk involved.",
319+
"transaction.alert.dryRunWarning": "Transaction might be failed. Reason: {{reason}}",
319320
"transaction.batch.warning": "Your transaction would exhaust block limit, we need to split it into multiple transactions",
320321
"transaction.batch.step.label": "Transaction {{ index }}",
321322
"transaction.error.unsupportedTransaction": "Unsupported transaction or signer type",

apps/main/src/modules/trade/swap/sections/DCA/Dca.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export const Dca: FC = () => {
3232
const {
3333
order,
3434
orderTx,
35-
dryRunError,
3635
healthFactor: initialHealthFactor,
3736
isLoading,
3837
} = useDcaTradeOrder(form)
@@ -150,11 +149,7 @@ export const Dca: FC = () => {
150149
}
151150
isLoading={isLoading}
152151
/>
153-
<DcaErrors
154-
priceImpact={order?.tradeImpactPct ?? 0}
155-
errors={errors}
156-
dryRunError={dryRunError}
157-
/>
152+
<DcaErrors priceImpact={order?.tradeImpactPct ?? 0} errors={errors} />
158153
<DcaWarnings
159154
isFormValid={isFormValid}
160155
order={order}

0 commit comments

Comments
 (0)