|
| 1 | +# Architecture |
| 2 | + |
| 3 | +HoudiniSkill is an installable Agent Skill package for HoudiniSwap, not a |
| 4 | +long-running service. The runtime surface is a set of small Node.js CLI scripts |
| 5 | +that an agent can call after reading `SKILL.md`. |
| 6 | + |
| 7 | +## System Overview |
| 8 | + |
| 9 | +```mermaid |
| 10 | +flowchart TB |
| 11 | + U[User natural-language request] --> A[Agent / Codex / Claude / Cursor] |
| 12 | + A --> S[SKILL.md instructions and routing rules] |
| 13 | +
|
| 14 | + S --> C[Node CLI scripts] |
| 15 | + C --> CL[_client.mjs shared runtime] |
| 16 | +
|
| 17 | + CL --> H[HoudiniSwap Partner API v2] |
| 18 | + C --> V[Verification CLIs] |
| 19 | + V --> AD[Chain adapter layer] |
| 20 | + AD --> RPC[Chain RPC / REST / Explorer] |
| 21 | +
|
| 22 | + I[install.sh / install.ps1] --> D[Agent skills directories] |
| 23 | + T[Node test runner] --> M[Mock API server] |
| 24 | + T --> C |
| 25 | +``` |
| 26 | + |
| 27 | +The important boundary is between the agent and the CLI scripts. The agent |
| 28 | +decides which script to run, confirms quote and recipient details with the |
| 29 | +user, and reports results. The scripts handle deterministic API calls, |
| 30 | +validation, JSON output, and exit codes. |
| 31 | + |
| 32 | +## Code Layers |
| 33 | + |
| 34 | +```mermaid |
| 35 | +flowchart LR |
| 36 | + subgraph Docs["Docs and agent entrypoint"] |
| 37 | + R[README.md] |
| 38 | + S[skills/houdiniswap/SKILL.md] |
| 39 | + Ref[references/*.md] |
| 40 | + end |
| 41 | +
|
| 42 | + subgraph CLI["Swap CLIs"] |
| 43 | + Search[search-tokens] |
| 44 | + Chains[list-chains] |
| 45 | + Quote[get-quote] |
| 46 | + Create[create-exchange] |
| 47 | + Order[get-order / wait-for-order] |
| 48 | + Multi[multi-swap] |
| 49 | + end |
| 50 | +
|
| 51 | + subgraph Runtime["Shared runtime"] |
| 52 | + Client[_client.mjs] |
| 53 | + Env[.env auto-loading] |
| 54 | + Auth[Auth header selection] |
| 55 | + Errors[Exit codes and JSON output] |
| 56 | + end |
| 57 | +
|
| 58 | + subgraph Verify["Verification subsystem"] |
| 59 | + Addr[verify-address] |
| 60 | + Hash[verify-tx-hash] |
| 61 | + Tx[verify-tx-onchain] |
| 62 | + ListRpc[list-rpc] |
| 63 | + Adapters[EVM / Solana / UTXO / Tron / Explorer-only] |
| 64 | + end |
| 65 | +
|
| 66 | + Docs --> CLI |
| 67 | + CLI --> Runtime |
| 68 | + Verify --> Runtime |
| 69 | + Tx --> Adapters |
| 70 | +``` |
| 71 | + |
| 72 | +### Docs and agent entrypoint |
| 73 | + |
| 74 | +- `SKILL.md` is the contract an agent reads to decide when and how to use the |
| 75 | + skill. |
| 76 | +- `README.md` is the human-facing install, configuration, and repository guide. |
| 77 | +- `references/*.md` holds deeper operational notes: auth, private-swap |
| 78 | + behavior, status codes, examples, verification, testing, and this |
| 79 | + architecture note. |
| 80 | + |
| 81 | +### Swap CLI layer |
| 82 | + |
| 83 | +The swap scripts are intentionally thin: |
| 84 | + |
| 85 | +- `search-tokens.mjs` maps user-friendly symbols/chains to HoudiniSwap token |
| 86 | + ObjectIds. |
| 87 | +- `list-chains.mjs` discovers supported chain short names and metadata. |
| 88 | +- `get-quote.mjs` calls `/quotes` and returns quote data that must be shown to |
| 89 | + the user before an order is created. |
| 90 | +- `create-exchange.mjs` turns a confirmed quote and recipient address into a |
| 91 | + HoudiniSwap order and deposit address. |
| 92 | +- `get-order.mjs` and `wait-for-order.mjs` inspect order status. |
| 93 | +- `multi-swap.mjs` submits a JSON array of orders to `/exchanges/multi`. |
| 94 | + |
| 95 | +### Shared runtime layer |
| 96 | + |
| 97 | +`scripts/_client.mjs` centralizes behavior that every CLI needs: |
| 98 | + |
| 99 | +- `.env` discovery from the skill directory, ancestor directories, and the |
| 100 | + fallback Claude skills path. |
| 101 | +- Auth precedence: full API key headers first, public partner-id second. |
| 102 | +- URL building, JSON request/response handling, timeout and abort behavior. |
| 103 | +- Uniform error classes and stable exit codes. |
| 104 | +- `runCli`, the wrapper that gives every script consistent `--help`, JSON |
| 105 | + stdout, human-readable stderr, and exit behavior. |
| 106 | + |
| 107 | +### Verification subsystem |
| 108 | + |
| 109 | +Verification scripts protect the user before and after an order: |
| 110 | + |
| 111 | +- `verify-address.mjs` checks recipient address format using the regex returned |
| 112 | + by `/v2/chains`. |
| 113 | +- `verify-tx-hash.mjs` checks transaction hash format based on `chain.kind`. |
| 114 | +- `verify-tx-onchain.mjs` routes chain verification to an adapter. |
| 115 | +- `list-rpc.mjs` reports built-in RPC coverage and current environment |
| 116 | + overrides without making network calls. |
| 117 | + |
| 118 | +The adapter layer implements the chain-specific mechanics: |
| 119 | + |
| 120 | +- EVM: JSON-RPC receipt/transaction/block queries and ERC-20 `Transfer` log |
| 121 | + decoding. |
| 122 | +- Solana: `getTransaction` plus native and SPL token balance deltas. |
| 123 | +- UTXO: Esplora/mempool.space-compatible REST transaction inspection. |
| 124 | +- Tron: trongrid REST and TRC20 transfer events. |
| 125 | +- Explorer-only: explicit `MANUAL` or `UNVERIFIABLE` verdicts when automatic |
| 126 | + verification would be misleading. |
| 127 | + |
| 128 | +## Swap Flow |
| 129 | + |
| 130 | +```mermaid |
| 131 | +sequenceDiagram |
| 132 | + participant User |
| 133 | + participant Agent |
| 134 | + participant CLI as HoudiniSkill CLI |
| 135 | + participant API as HoudiniSwap API |
| 136 | + participant Chain as Chain RPC/REST |
| 137 | +
|
| 138 | + User->>Agent: Swap token A to token B with privacy |
| 139 | + Agent->>CLI: search-tokens |
| 140 | + CLI->>API: GET /tokens |
| 141 | + API-->>CLI: Token ObjectIds |
| 142 | +
|
| 143 | + Agent->>CLI: get-quote --from --to --amount |
| 144 | + CLI->>API: GET /quotes |
| 145 | + API-->>CLI: quoteId / amountOut / expiresAt |
| 146 | +
|
| 147 | + Agent->>User: Show quote and request confirmation |
| 148 | + User-->>Agent: Confirm recipient address |
| 149 | +
|
| 150 | + Agent->>CLI: verify-address |
| 151 | + CLI->>API: GET /chains |
| 152 | + API-->>CLI: Chain addressValidation regex |
| 153 | + CLI-->>Agent: valid / invalid |
| 154 | +
|
| 155 | + Agent->>CLI: create-exchange --quote-id --address-to |
| 156 | + CLI->>API: POST /exchanges |
| 157 | + API-->>CLI: houdiniId / depositAddress |
| 158 | +
|
| 159 | + Agent->>User: Show depositAddress for source-chain funding |
| 160 | + Agent->>CLI: wait-for-order houdiniId |
| 161 | + CLI->>API: Poll GET /orders/{id} |
| 162 | + API-->>CLI: done / failed / pending |
| 163 | +
|
| 164 | + Agent->>CLI: verify-tx-onchain optional |
| 165 | + CLI->>Chain: RPC/REST transaction lookup |
| 166 | + Chain-->>CLI: PASS / FAIL / MANUAL / UNVERIFIABLE |
| 167 | +``` |
| 168 | + |
| 169 | +## Design Principles |
| 170 | + |
| 171 | +- **Zero runtime dependencies.** The skill runs on Node.js v22+ built-ins so it |
| 172 | + is easy to install in agent environments. |
| 173 | +- **CLI-first.** Every capability is scriptable by an agent or a human. |
| 174 | +- **Consistent machine interface.** Successful commands write JSON to stdout; |
| 175 | + failures write concise diagnostics to stderr and exit with documented codes. |
| 176 | +- **Privacy-first routing.** Natural-language privacy intent maps to |
| 177 | + HoudiniSwap Private Swap behavior, not ordinary traceable swap defaults. |
| 178 | +- **No false verification.** The skill does not sign, broadcast, or pretend to |
| 179 | + verify opaque chains. It returns `MANUAL` or `UNVERIFIABLE` when automatic |
| 180 | + verification is not supported. |
| 181 | +- **Offline-testable.** Most tests run against a local mock server; live API |
| 182 | + smoke tests are opt-in. |
0 commit comments