Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add process chain id #217

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@
]
},
"dependencies": {
"@lifi/types": "^15.11.0",
"@lifi/types": "^15.13.0",
"@solana/wallet-adapter-base": "^0.9.23",
"@solana/web3.js": "^1.95.3",
"viem": "^2.21.6"
"viem": "^2.21.8"
},
"devDependencies": {
"@commitlint/cli": "^19.5.0",
Expand All @@ -105,23 +105,23 @@
"@types/ws": "^8.5.12",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"@vitest/coverage-v8": "^2.0.5",
"@vitest/coverage-v8": "^2.1.1",
"bs58": "^6.0.0",
"eslint": "^8.57.0",
"eslint": "^8.57.1",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jsdoc": "^48.11.0",
"eslint-plugin-prettier": "^5.2.1",
"fs-extra": "^11.2.0",
"husky": "^9.1.6",
"lint-staged": "^15.2.10",
"madge": "^8.0.0",
"msw": "^2.4.5",
"msw": "^2.4.8",
"pinst": "^3.0.0",
"prettier": "^3.3.3",
"standard-version": "^9.5.0",
"ts-node": "^10.9.2",
"typescript": "^5.6.2",
"vitest": "^2.0.5"
"vitest": "^2.1.1"
},
"peerDependencies": {
"@solana/wallet-adapter-base": "^0.9.0",
Expand Down
22 changes: 12 additions & 10 deletions src/core/EVM/EVMStepExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ export class EVMStepExecutor extends BaseStepExecutor {
let processToUpdate = process
if (!processToUpdate) {
// We need to create some process if we don't have one so we can show the error
processToUpdate = this.statusManager.findOrCreateProcess(
processToUpdate = this.statusManager.findOrCreateProcess({
step,
'TRANSACTION'
)
type: 'TRANSACTION',
})
}
const errorMessage =
'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.'
Expand Down Expand Up @@ -164,10 +164,11 @@ export class EVMStepExecutor extends BaseStepExecutor {
}

// STEP 2: Get transaction
let process = this.statusManager.findOrCreateProcess(
let process = this.statusManager.findOrCreateProcess({
step,
currentProcessType
)
type: currentProcessType,
chainId: fromChain.id,
})

if (process.status !== 'DONE') {
const multisigProcess = step.execution.process.find(
Expand Down Expand Up @@ -413,11 +414,12 @@ export class EVMStepExecutor extends BaseStepExecutor {
// STEP 5: Wait for the receiving chain
const processTxHash = process.txHash
if (isBridgeExecution) {
process = this.statusManager.findOrCreateProcess(
process = this.statusManager.findOrCreateProcess({
step,
'RECEIVING_CHAIN',
'PENDING'
)
type: 'RECEIVING_CHAIN',
status: 'PENDING',
chainId: toChain.id,
})
}
let statusResponse: FullStatusData

Expand Down
7 changes: 4 additions & 3 deletions src/core/EVM/checkAllowance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ export const checkAllowance = async (
shouldBatchTransactions = false
): Promise<Hash | void> => {
// Ask the user to set an allowance
let allowanceProcess: Process = statusManager.findOrCreateProcess(
let allowanceProcess: Process = statusManager.findOrCreateProcess({
step,
'TOKEN_ALLOWANCE'
)
type: 'TOKEN_ALLOWANCE',
chainId: step.action.fromChainId,
})

// Check allowance
try {
Expand Down
8 changes: 4 additions & 4 deletions src/core/EVM/switchChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ export const switchChain = async (
step.execution = statusManager.initExecutionObject(step)
statusManager.updateExecution(step, 'ACTION_REQUIRED')

let switchProcess = statusManager.findOrCreateProcess(
let switchProcess = statusManager.findOrCreateProcess({
step,
'SWITCH_CHAIN',
'ACTION_REQUIRED'
)
type: 'SWITCH_CHAIN',
status: 'ACTION_REQUIRED',
})

if (!allowUserInteraction) {
return
Expand Down
15 changes: 8 additions & 7 deletions src/core/Solana/SolanaStepExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ export class SolanaStepExecutor extends BaseStepExecutor {
const currentProcessType = isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'

// STEP 2: Get transaction
let process = this.statusManager.findOrCreateProcess(
let process = this.statusManager.findOrCreateProcess({
step,
currentProcessType
)
type: currentProcessType,
})

if (process.status !== 'DONE') {
try {
Expand Down Expand Up @@ -297,11 +297,12 @@ export class SolanaStepExecutor extends BaseStepExecutor {
// STEP 5: Wait for the receiving chain
const processTxHash = process.txHash
if (isBridgeExecution) {
process = this.statusManager.findOrCreateProcess(
process = this.statusManager.findOrCreateProcess({
step,
'RECEIVING_CHAIN',
'PENDING'
)
type: 'RECEIVING_CHAIN',
status: 'PENDING',
chainId: toChain.id,
})
}
let statusResponse: FullStatusData
try {
Expand Down
46 changes: 24 additions & 22 deletions src/core/StatusManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
ChainId,
Execution,
ExecutionStatus,
LiFiStep,
Expand All @@ -10,19 +11,12 @@ import { executionState } from './executionState.js'
import { getProcessMessage } from './processMessages.js'
import type { LiFiStepExtended } from './types.js'

type OptionalParameters = Partial<
Pick<
Process,
| 'doneAt'
| 'failedAt'
| 'txHash'
| 'txLink'
| 'error'
| 'substatus'
| 'substatusMessage'
| 'multisigTxHash'
>
>
export type FindOrCreateProcessProps = {
step: LiFiStepExtended
type: ProcessType
chainId?: ChainId
status?: ProcessStatus
}

/**
* Manages status updates of a route and provides various functions for tracking processes
Expand Down Expand Up @@ -88,16 +82,23 @@ export class StatusManager {

/**
* Create and push a new process into the execution.
* @param step The step that should contain the new process.
* @param type Type of the process. Used to identify already existing processes.
* @param status By default created procces is set to the STARTED status. We can override new process with the needed status.
* @param step.step The step that should contain the new process.
* @param step.type Type of the process. Used to identify already existing processes.
* @param step.chainId Chain Id of the process.
* @param step.status By default created procces is set to the STARTED status. We can override new process with the needed status.
* @param root0
* @param root0.step
* @param root0.type
* @param root0.chainId
* @param root0.status
* @returns Returns process.
*/
findOrCreateProcess = (
step: LiFiStepExtended,
type: ProcessType,
status?: ProcessStatus
): Process => {
findOrCreateProcess = ({
step,
type,
chainId,
status,
}: FindOrCreateProcessProps): Process => {
if (!step.execution?.process) {
throw new Error("Execution hasn't been initialized.")
}
Expand All @@ -117,6 +118,7 @@ export class StatusManager {
startedAt: Date.now(),
message: getProcessMessage(type, status ?? 'STARTED'),
status: status ?? 'STARTED',
chainId: chainId,
}

step.execution.process.push(newProcess)
Expand All @@ -136,7 +138,7 @@ export class StatusManager {
step: LiFiStepExtended,
type: ProcessType,
status: ProcessStatus,
params?: OptionalParameters
params?: Partial<Process>
): Process => {
if (!step.execution) {
throw new Error("Can't update an empty step execution.")
Expand Down
21 changes: 12 additions & 9 deletions src/core/StatusManager.unit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ describe('StatusManager', () => {

it('should throw an error', () => {
expect(() =>
statusManager.findOrCreateProcess(structuredClone(step), 'SWAP')
statusManager.findOrCreateProcess({
step: structuredClone(step),
type: 'SWAP',
})
).toThrow("Execution hasn't been initialized.")
})
})
Expand All @@ -141,10 +144,10 @@ describe('StatusManager', () => {

describe('and the process already exists', () => {
it('should return the process and not call the callbacks', () => {
const process = statusManager.findOrCreateProcess(
structuredClone(step),
'TOKEN_ALLOWANCE'
)
const process = statusManager.findOrCreateProcess({
step: structuredClone(step),
type: 'TOKEN_ALLOWANCE',
})

expect(process).toEqual(step.execution?.process[0])

Expand All @@ -154,10 +157,10 @@ describe('StatusManager', () => {

describe("and the process doesn't exist", () => {
it('should create a process and call the callbacks with the updated route', () => {
const process = statusManager.findOrCreateProcess(
structuredClone(step),
'CROSS_CHAIN'
)
const process = statusManager.findOrCreateProcess({
step: structuredClone(step),
type: 'CROSS_CHAIN',
})

expect(process.type).toEqual('CROSS_CHAIN')
expect(process.status).toEqual('STARTED')
Expand Down
Loading
Loading