Skip to content

Commit 280de4a

Browse files
authored
feat: skip step tx generation if tx data already provided (#100)
* feat: skip step tx generation if tx data already provided * fix: handle failed normal routes * fix(ConfigService): config rpc length check
1 parent b6c1b75 commit 280de4a

File tree

4 files changed

+36
-28
lines changed

4 files changed

+36
-28
lines changed

src/execution/bridges/bridge.execute.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,21 @@ export class BridgeExecutionManager {
7171
// check balance
7272
await balanceCheck(signer, step)
7373

74-
// create new transaction
75-
const personalizedStep = await personalizeStep(signer, step)
76-
const updatedStep = await ApiService.getStepTransaction(
77-
personalizedStep
78-
)
79-
step = {
80-
...(await stepComparison(
81-
statusManager,
82-
personalizedStep,
83-
updatedStep,
84-
settings.acceptSlippageUpdateHook,
85-
this.shouldContinue
86-
)),
87-
execution: step.execution,
74+
if (!step.transactionRequest) {
75+
const personalizedStep = await personalizeStep(signer, step)
76+
const updatedStep = await ApiService.getStepTransaction(
77+
personalizedStep
78+
)
79+
step = {
80+
...(await stepComparison(
81+
statusManager,
82+
personalizedStep,
83+
updatedStep,
84+
settings.acceptSlippageUpdateHook,
85+
this.shouldContinue
86+
)),
87+
execution: step.execution,
88+
}
8889
}
8990

9091
const { transactionRequest } = step

src/execution/exchanges/swap.execute.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,21 @@ export class SwapExecutionManager {
6868
await balanceCheck(signer, step)
6969

7070
// -> get tx from backend
71-
const personalizedStep = await personalizeStep(signer, step)
72-
const updatedStep = await ApiService.getStepTransaction(
73-
personalizedStep
74-
)
75-
step = {
76-
...(await stepComparison(
77-
statusManager,
78-
personalizedStep,
79-
updatedStep,
80-
settings.acceptSlippageUpdateHook,
81-
this.shouldContinue
82-
)),
83-
execution: step.execution,
71+
if (!step.transactionRequest) {
72+
const personalizedStep = await personalizeStep(signer, step)
73+
const updatedStep = await ApiService.getStepTransaction(
74+
personalizedStep
75+
)
76+
step = {
77+
...(await stepComparison(
78+
statusManager,
79+
personalizedStep,
80+
updatedStep,
81+
settings.acceptSlippageUpdateHook,
82+
this.shouldContinue
83+
)),
84+
execution: step.execution,
85+
}
8486
}
8587

8688
const { transactionRequest } = step

src/services/ConfigService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export default class ConfigService {
113113
const chainId = chain.id as ChainId
114114

115115
// set RPCs if they were not configured by the user before
116-
if (!this.config.rpcs[chainId].length) {
116+
if (!this.config.rpcs[chainId]?.length) {
117117
this.config.rpcs[chainId] = chain.metamask.rpcUrls
118118
}
119119

src/utils/preRestart.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const handlePreRestart = (route: Route) => {
99
if (stepHasFailed) {
1010
handleErrorType(route, index)
1111
deleteFailedProcesses(route, index)
12+
deleteTransactionData(route, index)
1213
}
1314
}
1415
}
@@ -43,3 +44,7 @@ const deleteFailedProcesses = (route: Route, index: number) => {
4344
].execution!.process.filter((process) => process.status !== 'FAILED')
4445
}
4546
}
47+
48+
const deleteTransactionData = (route: Route, index: number) => {
49+
route.steps[index].transactionRequest = undefined
50+
}

0 commit comments

Comments
 (0)