Skip to content
This repository was archived by the owner on Jan 14, 2026. It is now read-only.
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
82 changes: 82 additions & 0 deletions .claude/CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

Deflex SDK is a TypeScript/JavaScript SDK for the Deflex Order Router - smart order routing and DEX aggregation on Algorand. This is a pnpm workspace monorepo containing the SDK package and example implementations.

## Commands

```bash
# Install dependencies
pnpm install

# Build the SDK (runs tsdown and publint)
pnpm build

# Run tests
pnpm test
pnpm test:watch # Watch mode
pnpm test:coverage # With coverage

# Run a single test file
pnpm --filter @txnlab/deflex vitest run tests/client.test.ts

# Linting and formatting
pnpm lint # ESLint
pnpm format # Check formatting
pnpm format:fix # Fix formatting

# Type checking
pnpm typecheck

# Run all CI checks
pnpm run ci
```

## Architecture

### SDK Package (`packages/deflex/`)

The SDK exports from `src/index.ts`:

- **client.ts** - `DeflexClient` class: Main entry point for interacting with the Deflex API. Handles quote fetching, swap transaction creation, and automatic asset opt-in detection.

- **composer.ts** - `SwapComposer` class: Builder pattern for constructing atomic transaction groups. Manages transaction lifecycle (BUILDING → BUILT → SIGNED → SUBMITTED → COMMITTED). Supports adding custom transactions and ABI method calls before/after swaps.

- **middleware.ts** - `SwapMiddleware` interface: Plugin system for extending swap functionality. Middleware can modify quote parameters, add transactions before/after swaps. Includes built-in `AutoOptOutMiddleware`.

- **types.ts** - TypeScript types for API requests/responses, quotes, transactions.

- **constants.ts** - Default configuration values and protocol constants.

### Workspace Structure

```
packages/deflex/ # Main SDK package (@txnlab/deflex)
examples/
react/ # React + Vite example
react-query/ # React + TanStack Query example
node-cli/ # Node.js CLI example
```

Examples use `"@txnlab/deflex": "workspace:*"` to reference the local SDK.

## Key Patterns

### Transaction Signing

The SDK accepts both `algosdk.TransactionSigner` and ARC-1 compliant signer functions. The `SignerFunction` type in composer.ts handles both patterns.

### Middleware System

Middleware implements `SwapMiddleware` interface with optional hooks:
- `shouldApply(context)` - Determine if middleware applies to a swap
- `modifyQuoteParams(params)` - Adjust quote parameters (e.g., reduce maxGroupSize)
- `getPreSwapTransactions(context)` - Add transactions before swap
- `getPostSwapTransactions(context)` - Add transactions after swap

### Peer Dependencies

The SDK requires `algosdk ^3.0.0` as a peer dependency.
33 changes: 33 additions & 0 deletions .claude/skills/commit-messages.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Project Commit Conventions

This file extends the global commit-messages skill (`~/.claude/skills/commit-messages/SKILL.md`).

## Lowercase Rule

Commit messages MUST begin with a lowercase letter after the colon.

**Correct:**
```
feat(composer): add getSummary() method
fix(client): handle network timeout errors
chore(deps): update algosdk to v3.1.0
```

**Incorrect:**
```
feat(composer): Add getSummary() method
fix(client): Handle network timeout errors
chore(deps): Update algosdk to v3.1.0
```

Note: The commit history contains Renovate bot commits that use uppercase (e.g., "chore(deps): Update..."). These are automated and follow Renovate's default format. All commits written by Claude Code or developers should use lowercase.

## Common Scopes

- `client` - DeflexClient class changes
- `composer` - SwapComposer class changes
- `middleware` - Middleware system changes
- `types` - Type definitions
- `deps` - Dependency updates
- `examples` - Example application changes
- `docs` - Documentation updates