Cookbook

Screen a withdrawal

A decision before the money moves, a step-up to KYC L3, and the release when the session is approved.

1. A rule for large withdrawals

await dc.lens.rules.create({
  name: 'Over $10,000 in 30 days: KYC L3',
  priority: 100,
  rails: ['wire', 'ach', 'crypto'],
  directions: ['outbound'],
  condition: { metric: 'volume_30d', op: 'gt', value: 10000, currency: 'USD' },
  action: 'verification_required',
  reason_code: 'KYC_L3_REQUIRED',
  verify_kind: 'kyc',
  verify_level: 'l3',
  verify_flow_id: process.env.L3_FLOW_ID!,
});

2. Decide before the transfer

const decision = await dc.lens.decide({
  external_id: withdrawal.id,
  rail: 'crypto',
  operation: 'withdrawal',
  direction: 'outbound',
  amount: 12400,
  currency: 'USDC',
  subject: { reference: 'cus_10442' },
  counterparty: { address: withdrawal.address, chain: 'base' },
}, { timeoutMs: 800 });

switch (decision.effective_verdict) {
  case 'allow': return send(withdrawal);
  case 'verification_required': return askToVerify(decision.verification.url);
  default: return hold(withdrawal, decision.reason_codes);
}

3. Release on approval

on('lens.decision.updated', async (event) => {
  if (event.data.effective_verdict === 'allow') await send(await db.withdrawals.get(event.data.external_id));
});

The session approved at L3 resolves the decision to allow; rejected or expired, to deny.

On this page