Skip to content

Commit

Permalink
refactor: clean up process types (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov authored Jun 18, 2024
1 parent bab34fc commit de35a77
Show file tree
Hide file tree
Showing 8 changed files with 586 additions and 615 deletions.
610 changes: 305 additions & 305 deletions .yarn/releases/yarn-4.2.2.cjs → .yarn/releases/yarn-4.3.0.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ enableGlobalCache: false

nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.2.2.cjs
yarnPath: .yarn/releases/yarn-4.3.0.cjs
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,32 +94,32 @@
]
},
"dependencies": {
"@lifi/types": "^13.12.0",
"@lifi/types": "^13.15.0",
"@solana/wallet-adapter-base": "^0.9.23",
"@solana/web3.js": "^1.92.2",
"@solana/web3.js": "^1.93.0",
"eth-rpc-errors": "^4.0.3",
"viem": "^2.13.7"
"viem": "^2.14.2"
},
"devDependencies": {
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"@types/fs-extra": "^11.0.4",
"@types/ws": "^8.5.10",
"@typescript-eslint/eslint-plugin": "^7.12.0",
"@typescript-eslint/parser": "^7.12.0",
"@typescript-eslint/eslint-plugin": "^7.13.0",
"@typescript-eslint/parser": "^7.13.0",
"@vitest/coverage-v8": "^1.6.0",
"bs58": "^5.0.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jsdoc": "^48.2.8",
"eslint-plugin-jsdoc": "^48.2.12",
"eslint-plugin-prettier": "^5.1.3",
"fs-extra": "^11.2.0",
"husky": "^9.0.11",
"lint-staged": "^15.2.5",
"lint-staged": "^15.2.7",
"madge": "^7.0.0",
"msw": "^2.3.1",
"pinst": "^3.0.0",
"prettier": "^3.3.1",
"prettier": "^3.3.2",
"standard-version": "^9.5.0",
"ts-node": "^10.9.2",
"typescript": "^5.4.5",
Expand All @@ -130,7 +130,7 @@
"@solana/web3.js": "^1.91.0",
"viem": "^2.10.0"
},
"packageManager": "yarn@4.2.2",
"packageManager": "yarn@4.3.0",
"publishConfig": {
"access": "public"
},
Expand Down
16 changes: 9 additions & 7 deletions src/core/StatusManager.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type {
Execution,
ExecutionStatus,
LiFiStep,
Process,
ProcessStatus,
ProcessType,
Status,
} from '@lifi/types'
import { emptyExecution } from '@lifi/types'
import { executionState } from './executionState.js'
import type { LiFiStepExtended } from './types.js'
import { getProcessMessage } from './utils.js'
Expand Down Expand Up @@ -44,8 +44,10 @@ export class StatusManager {
*/
initExecutionObject = (step: LiFiStepExtended): Execution => {
if (!step.execution) {
step.execution = structuredClone<Execution>(emptyExecution)
step.execution.status = 'PENDING'
step.execution = {
status: 'PENDING',
process: [],
}
this.updateStepInRoute(step)
}

Expand All @@ -67,7 +69,7 @@ export class StatusManager {
*/
updateExecution(
step: LiFiStepExtended,
status: Status,
status: ExecutionStatus,
execution?: Partial<Execution>
): LiFiStep {
if (!step.execution) {
Expand All @@ -94,7 +96,7 @@ export class StatusManager {
findOrCreateProcess = (
step: LiFiStepExtended,
type: ProcessType,
status?: Status
status?: ProcessStatus
): Process => {
if (!step.execution?.process) {
throw new Error("Execution hasn't been initialized.")
Expand Down Expand Up @@ -133,7 +135,7 @@ export class StatusManager {
updateProcess = (
step: LiFiStepExtended,
type: ProcessType,
status: Status,
status: ProcessStatus,
params?: OptionalParameters
): Process => {
if (!step.execution) {
Expand Down
6 changes: 3 additions & 3 deletions src/core/StatusManager.unit.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Route, Status } from '@lifi/types'
import type { ExecutionStatus, ProcessStatus, Route } from '@lifi/types'
import type { Mock } from 'vitest'
import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
import { buildRouteObject, buildStepObject } from '../../tests/fixtures.js'
Expand Down Expand Up @@ -211,7 +211,7 @@ describe('StatusManager', () => {
const process = statusManager.updateProcess(
structuredClone(step),
'SWAP',
status as Status
status as ProcessStatus
)

expect(process.type).toEqual('SWAP')
Expand All @@ -229,7 +229,7 @@ describe('StatusManager', () => {
process: [step.execution!.process[0], process],
status: notUpdateableStatus
? step.execution!.status
: (status as Status),
: (status as ExecutionStatus),
})

const updatedStep = { ...step, execution: updatedExecution }
Expand Down
56 changes: 0 additions & 56 deletions src/core/prepareRestart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,68 +7,12 @@ export const prepareRestart = async (route: RouteExtended) => {
const stepHasFailed = step.execution?.status === 'FAILED'

if (stepHasFailed) {
// await handleErrorType(walletClient, step)
deleteFailedProcesses(step)
deleteTransactionData(step)
}
}
}

// const handleErrorType = async (walletClient: WalletClient, step: LiFiStep) => {
// const client = walletClient.extend(publicActions)

// const isGasLimitError = step.execution?.process.some(
// (p) => p.error?.code === LiFiErrorCode.GasLimitError
// )
// const isGasPriceError = step.execution?.process.some(
// (p) => p.error?.code === LiFiErrorCode.TransactionUnderpriced
// )

// const { transactionRequest } = step

// if (isGasLimitError) {
// if (transactionRequest) {
// let gasLimit = transactionRequest.gasLimit

// try {
// gasLimit = await client.estimateGas(transactionRequest)
// } catch (error) {}

// if (gasLimit) {
// transactionRequest.gasLimit = BigNumber.from(
// `${(BigInt(gasLimit.toString()) * 125n) / 100n}`
// )
// }
// }

// step.estimate.gasCosts?.forEach(
// (gasCost) =>
// (gasCost.limit = `${Math.round(Number(gasCost.limit) * 1.25)}`)
// )
// }

// if (isGasPriceError) {
// if (transactionRequest) {
// let gasPrice = transactionRequest.gasPrice

// try {
// gasPrice = await client.getGasPrice()
// } catch (error) {}

// if (gasPrice) {
// transactionRequest.gasPrice = BigNumber.from(
// `${(BigInt(gasPrice.toString()) * 125n) / 100n}`
// )
// }
// }

// step.estimate.gasCosts?.forEach(
// (gasCost) =>
// (gasCost.price = `${Math.round(Number(gasCost.price) * 1.25)}`)
// )
// }
// }

const deleteFailedProcesses = (step: LiFiStepExtended) => {
if (step.execution) {
step.execution.process = step.execution.process.filter(
Expand Down
9 changes: 6 additions & 3 deletions src/core/utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import {
type LiFiStep,
type ProcessStatus,
type ProcessType,
type Status,
type StatusMessage,
type Substatus,
} from '@lifi/types'

const processMessages: Record<ProcessType, Partial<Record<Status, string>>> = {
const processMessages: Record<
ProcessType,
Partial<Record<ProcessStatus, string>>
> = {
TOKEN_ALLOWANCE: {
STARTED: 'Setting token allowance.',
PENDING: 'Waiting for token allowance.',
Expand Down Expand Up @@ -61,7 +64,7 @@ const substatusMessages: Record<

export function getProcessMessage(
type: ProcessType,
status: Status
status: ProcessStatus
): string | undefined {
const processMessage = processMessages[type][status]
return processMessage
Expand Down
Loading

0 comments on commit de35a77

Please sign in to comment.