Skip to content

The ordered wallet steps that together complete one protocol action, and the execute function that runs them. Every build*Workflow method returns one. For instance, a deposit from VaultModule.buildDepositWorkflow can be two WalletOperations:

  1. an ERC-20 approve for the Collateral Vault
  2. the deposit into the Collateral Vault

Remarks

A workflow belongs to the account connected when it was built. If the connected account changes before or between steps, execution stops before the next wallet prompt: that step is marked Failed with validationErrorResponse { root: ['WalletNotConnected'] }, or, when revalidation notices the change first, execute() resolves failed with a WorkflowSignerChangedError. Build a new workflow for the new account. This keeps balance, allowance, signature, and transaction decisions tied to one signer.

Example

// Builders read chain state and prepend any ERC-20 approve the vault
// needs.
const workflow = await sdk.vault.buildDepositWorkflow({
tokenAmounts: [{ tokenAddress: USDC, amount: 1_000_000_000n }], // 1,000
});
// e.g. approve, deposit
console.log(workflow.operations.map(op => op.type));
let cancelled = false;
const execution = await workflow.execute(
update => {
for (const op of update)
console.log(op.type, op.status, op.transactionHash);
},
() => cancelled // checked between steps; flip to stop before next prompt
);
if (execution.status !== 'executed') {
if (execution.status === 'invalid') {
throw new Error(JSON.stringify(execution.issues));
}
if (execution.status === 'failed') throw execution.error;
return false;
}
const finalOps = execution.operations;
const failed = finalOps.find(
op => op.status === WalletOperationStatus.Failed
);
if (failed) {
throw new Error(JSON.stringify(failed.validationErrorResponse));
}
const parked = finalOps.find(isIndeterminateWithoutHash);
if (parked) {
// The send failed in transit: it may or may not have landed, and
// execute() will not resend it. Check wallet activity before rebuilding.
throw new Error(`${parked.type} may have been sent`);
}
return finalOps.every(op => isTerminalOperationStatus(op.status));

Properties

execute

execute: WorkflowExecuteFunction;

Runs the workflow: execute(h?, isCancelled?) resolves with a WorkflowExecutionResult.

Before the first new wallet prompt, execute() validates the workflow’s inputs again against current state. If they no longer hold, it resolves invalid (or failed when validation cannot finish) without prompting and without changing any step. Otherwise it runs the steps in order through the connected wallet and resolves executed with every step.

  • h, the update handler, receives a fresh copy of the whole operations list each time a step’s status changes. An error it throws is logged and ignored.
  • isCancelled is checked between steps. Return true to stop before the next prompt: before the first prompt the result is cancelled; after it, the remaining steps become Rejected.
  • A call made while a run is in progress joins that run. Each caller gets its own updates and the same result, and the run stops only when every caller’s isCancelled returns true.
  • A step that finished, including a Failed or Rejected one, never runs again. To retry after a failure, build a new workflow.

operations

operations: WalletOperation < AnvilWalletOperationType > [];

The steps in execution order, as they stood when the workflow was built. This array does not change while the workflow runs: follow progress through execute’s update handler and its result.