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 the loan creation process:| Stage | Description |
|---|---|
INITIALIZING | Workflow starting |
DEPOSIT_ADDRESS_READY | Deposit address generated |
AWAITING_DEPOSIT | Waiting for BTC deposit |
DEPOSIT_CONFIRMED | Deposit received |
COLLATERAL_DEPOSITED | Collateral processed |
PREPARING_LOAN | Loan being prepared |
LOAN_CONFIRMED | Loan executed |
COMPLETED | Workflow complete |
FAILED | Workflow failed |
Repay Workflow
Tracks the repayment process:| Stage | Description |
|---|---|
INITIALIZING | Starting repayment |
TRANSFERRING_TO_KERNEL | Moving funds |
REPAYING_LOAN | Executing repayment |
WITHDRAWING_COLLATERAL | Withdrawing BTC |
TRANSFERRING_TO_PLATFORM_WALLET | Preparing bridge |
BRIDGE_INITIALIZING | Bridge starting |
BRIDGE_QUOTE_READY | Bridge quote received |
BRIDGE_SWAP_CREATED | Swap created |
BRIDGE_EXECUTING_APPROVAL | Approving tokens |
BRIDGE_APPROVAL_CONFIRMED | Approval confirmed |
BRIDGE_EXECUTING_INITIATE | Initiating bridge |
BRIDGE_INITIATE_CONFIRMED | Bridge initiated |
BRIDGE_AWAITING_BRIDGE_COMPLETION | Waiting for bridge |
BRIDGE_COMPLETED | Bridge complete |
COMPLETED | Workflow complete |
FAILED | Workflow failed |
Workflow Status Object
Tracking Workflows
Automatic Tracking
By default, workflows are tracked automatically:Manual Tracking
Disable auto-tracking and track manually: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):
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:| Interval | Use Case |
|---|---|
| 1000ms | Responsive UI, more API calls |
| 2000ms | Default, good balance |
| 5000ms | Less frequent updates, fewer API calls |