Skip to main content

Workflows

Workflows are asynchronous, multi-step processes that track the progress of loan operations.

What is a Workflow?

A workflow represents a complex operation (like borrowing or repaying) that involves multiple steps and external events (like Bitcoin deposits).

Workflow Types

Borrow Workflow

Tracks loan creation. These are the stages currently exposed by the SDK flow: BorrowWorkflowStage also contains compatibility stages used by other lending paths: PREPARING_DEPOSIT, AUTO_TRANSFERRING_BTC, AWAITING_REDEEM, REDEEM_CONFIRMED, PREPARING_BORROW, PREPARING_REPAY, AWAITING_REPAY_CONFIRMATION, PREPARING_WITHDRAW, and AWAITING_WITHDRAW_CONFIRMATION. A particular operation does not visit every stage.

Borrow More Workflow

Borrow More reuses existing collateral and therefore skips the Bitcoin bridge and collateral transaction. It still emits the shared position-preparation stage: INITIALIZING → PREPARING_BORROW_DEPOSIT → PREPARING_LOAN → LOAN_CONFIRMED → PREPARING_DISBURSEMENT → DISBURSEMENT_SUBMITTED → DISBURSEMENT_COMPLETED → COMPLETED

Deposit More Workflow

Deposit More bridges new Bitcoin collateral but does not borrow or disburse: INITIALIZING → QUOTE_READY → DEPOSIT_ADDRESS_READY → AWAITING_DEPOSIT → AWAITING_DEPOSIT_CONFIRMATION → DEPOSIT_CONFIRMED → PREPARING_BORROW_DEPOSIT → COLLATERAL_DEPOSITED → COMPLETED

Repay Workflow

Tracks the repayment process:

Withdrawal Workflows

Bitcoin withdrawals use the bridge stages: INITIALIZING → QUOTE_READY → SWAP_CREATED → EXECUTING_APPROVAL → APPROVAL_CONFIRMED → EXECUTING_INITIATE → INITIATE_CONFIRMED → AWAITING_BRIDGE_COMPLETION → BRIDGE_COMPLETED → COMPLETED Direct EVM withdrawals use: INITIALIZING → VALIDATING → CHECKING_BALANCE → EXECUTING_TRANSFER → COMPLETED Both withdrawal flows can terminate at FAILED or CANCELLED.

Status fields

SDK status endpoints expose several related fields: Do not depend on raw bridge quotes, database fields, or provider payloads. Those are intentionally not part of the public SDK response.
Stage enums can grow as workflows become more detailed. Handle unknown stages gracefully and use isComplete and isFailed from WorkflowStatus for terminal UI behavior.

Workflow Status Object

Tracking Workflows

Tracking a Borrow Workflow

After executeBorrow() returns a workflow ID, pass it to trackWorkflow():

Resuming Tracking

Resume tracking a workflow that was interrupted:

Workflow Callbacks

onStatusUpdate

Called when the workflow stage changes:

onDepositReady

Called when a deposit address is ready (borrow workflows): Treat this callback as time-sensitive in the UI: the deposit address is single-use and the quote stays locked for up to 6 hours.

onComplete

Called when the workflow completes successfully:

onError

Called when the workflow fails:

Polling Configuration

The SDK polls for workflow status at a configurable interval:
Minimum interval is 100ms.

Stopping Tracking

Stop All Tracking

Workflow State Diagram

Borrow Workflow

Getting Workflow Status Manually

Handling Pending Workflows

Check for and resume pending workflows on app load:

Best Practices

1. Always Handle Errors

2. Persist Workflow IDs

3. Show Progress Indicator

4. Handle Page Refresh