Skip to content

Conversation

@g1nt0ki
Copy link
Member

@g1nt0ki g1nt0ki commented Jan 27, 2026

Summary by CodeRabbit

  • New Features

    • Added a new CLI migration command for managing deprecated adapters with automatic dependency resolution and relocation
    • Integrated support for deprecated adapters into the core module loading system
  • Chores

    • Added npm script for running the adapter migration utility

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 27, 2026

📝 Walkthrough

Walkthrough

This change introduces a system for managing "dead" adapters—modules marked with a deadFrom marker. A new migration CLI script scans adapter modules, identifies dead adapters, and relocates them to a dead/ directory with a registry. Integration points in the factory registry and module builder incorporate dead adapters into the runtime module map during adapter lookup and module generation.

Changes

Cohort / File(s) Summary
Dead Adapter Registry
factory/deadAdapters.json, factory/registry.ts
New deadAdapters.json placeholder file added. Registry imports and re-exports deadAdapters; extends getAdapterFromHelpers() to pre-check deadAdapters before factory loading, returning dead adapters if found.
Module Builder Integration
cli/buildModules.ts
Imports deadAdapters and calls new addDeadAdapters() function after addFactoryAdapters(), merging static dead adapters into dimensionsImports module map.
Migration Script
cli/migrateDeadProjects.ts
New comprehensive CLI script that scans adapter modules to detect dead adapters (via deadFrom marker), resolves import dependencies, relocates modules to dead/ directory in dependency order, and persists updated deadAdapters.json registry with mocked module structures.
NPM Scripts
package.json
Adds "migrate-dead" script invoking ts-node on migrateDeadProjects.ts.

Sequence Diagrams

sequenceDiagram
    participant CLI as Migration CLI
    participant FS as File System
    participant Registry as deadAdapters.json
    participant ModuleMap as Module Builder

    CLI->>FS: Scan adapter modules for deadFrom markers
    CLI->>CLI: Identify dead adapters & resolve dependencies
    CLI->>CLI: Sort by dependency order
    CLI->>FS: Create dead/ directories
    CLI->>FS: Move dead adapter files
    CLI->>Registry: Write deadAdapters.json with module paths
    ModuleMap->>Registry: Load deadAdapters on startup
    ModuleMap->>ModuleMap: Merge into dimensionsImports
Loading
sequenceDiagram
    participant Client as Client Code
    participant Registry as factory/registry.ts
    participant DeadReg as deadAdapters.json
    participant Factory as Adapter Factory

    Client->>Registry: getAdapterFromHelpers(adapterType, protocolName)
    Registry->>DeadReg: Check deadAdapters[adapterType][protocolName]
    alt Dead Adapter Found
        DeadReg-->>Registry: Return dead adapter entry
        Registry-->>Client: Return {factoryName: 'deadAdapter', adapter}
    else Not Found
        Registry->>Factory: Load via dynamic factory
        Factory-->>Registry: Return adapter
        Registry-->>Client: Return adapter
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Possibly related PRs

Poem

🐰 Hoppy trails for adapters past,
Dead ones marked with timestamps cast,
Bundled up and moved with care,
In the dead/ folder, they rest there!

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.38% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The pull request has no description provided, but the changes do not relate to adding a new protocol listing, so the template is not applicable to this PR. Add a brief description explaining the purpose of moving dead adapters, the changes made, and any testing performed to validate the migration infrastructure.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Move out dead adapters' is concise and clearly describes the main purpose of the changeset, which introduces infrastructure to handle dead adapters.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@factory/registry.ts`:
- Around line 51-57: The returned object is supplying metadata
(deadAdapters[adapterType][protocolName]) where the signature expects a
functional SimpleAdapter (AdapterBase & { adapter?: BaseAdapter }), and the
stored metadata's module field is corrupted by mockFunctions; fix by changing
the registry return to provide either a real adapter loader or a properly-typed
adapter: locate the deadAdapters map and instead of returning the raw metadata
object, use its modulePath/codePath to import/require and reconstruct a valid
SimpleAdapter instance (or return a wrapper that lazily imports and instantiates
the adapter) so callers like importAdapter.ts receive an AdapterBase-compatible
object; also update the types for deadAdapters and the return type of the
registry function to reflect metadata vs adapter (or convert metadata to a
proper SimpleAdapter before returning), and ensure migrateDeadProjects.ts does
not leave the module field with mockFunctions='_f' or provide a deserialization
step to restore real functions.
🧹 Nitpick comments (3)
cli/migrateDeadProjects.ts (3)

63-97: Inconsistent fs module usage.

Line 67 uses require('fs').statSync while existsSync and readFileSync are already imported from fs at line 2. Consider using the already-imported statSync for consistency.

Suggested fix
-import { existsSync, readFileSync } from "fs";
+import { existsSync, readFileSync, statSync } from "fs";
-    const fileStat = existsSync(filePath) ? require('fs').statSync(filePath) : null
+    const fileStat = existsSync(filePath) ? statSync(filePath) : null

99-151: Silent error swallowing may hide legitimate issues.

Lines 147-149 silently catch and ignore all errors during adapter move operations. While some failures are expected (e.g., import errors for incompatible modules), completely silent failure could mask real problems like permission errors, disk space issues, or partially moved files.

Consider logging at least a debug message when errors occur.

Suggested improvement
   } catch (error: any) {
-    // Skip modules that fail to import
+    // Log non-import errors for debugging
+    if (error.code && error.code !== 'MODULE_NOT_FOUND') {
+      console.log(`  Warning: Failed to move ${moduleKey}: ${error.message}`)
+    }
   }

214-217: Minor: Unused loop variable.

The _ variable is unused in the for-of loop. This is a common convention for ignored values, but you could destructure directly.

Suggested fix
-  for (const [_, info] of deadAdapterInfos) {
+  for (const info of deadAdapterInfos.values()) {

Comment on lines +51 to +57

if ((deadAdapters as any)[adapterType]?.[protocolName]) {
return {
factoryName: 'deadAdapter',
adapter: (deadAdapters as any)[adapterType][protocolName]
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

rg -n -C3 'getAdapterFromHelpers'

Repository: DefiLlama/dimension-adapters

Length of output: 1282


🏁 Script executed:

cat -n factory/registry.ts | sed -n '40,70p'

Repository: DefiLlama/dimension-adapters

Length of output: 1269


🏁 Script executed:

rg -n -B5 -A10 'deadAdapters' factory/registry.ts | head -40

Repository: DefiLlama/dimension-adapters

Length of output: 1047


🏁 Script executed:

fd migrateDeadProjects.ts

Repository: DefiLlama/dimension-adapters

Length of output: 98


🏁 Script executed:

cat factory/deadAdapters.json | head -100

Repository: DefiLlama/dimension-adapters

Length of output: 74


🏁 Script executed:

cat -n cli/migrateDeadProjects.ts | sed -n '120,145p'

Repository: DefiLlama/dimension-adapters

Length of output: 1132


🏁 Script executed:

rg -n -B5 -A10 'function mockFunctions' cli/migrateDeadProjects.ts

Repository: DefiLlama/dimension-adapters

Length of output: 483


🏁 Script executed:

# Check how the adapter field from getAdapterFromHelpers is used
rg -n -A5 'const result = getAdapterFromHelpers' adapters/utils/importAdapter.ts

Repository: DefiLlama/dimension-adapters

Length of output: 384


🏁 Script executed:

# Check what SimpleAdapter looks like to confirm the incompatibility
rg -n -A10 'interface SimpleAdapter' adapters/types

Repository: DefiLlama/dimension-adapters

Length of output: 126


🏁 Script executed:

# Check if there are any other usages of result.adapter in importAdapter.ts
cat -n adapters/utils/importAdapter.ts

Repository: DefiLlama/dimension-adapters

Length of output: 1881


🏁 Script executed:

fd types.ts | grep -v node_modules

Repository: DefiLlama/dimension-adapters

Length of output: 238


🏁 Script executed:

# Find SimpleAdapter definition
rg -n 'interface SimpleAdapter|type SimpleAdapter' --type ts

Repository: DefiLlama/dimension-adapters

Length of output: 402


🏁 Script executed:

cat -n adapters/types.ts | sed -n '115,160p'

Repository: DefiLlama/dimension-adapters

Length of output: 1847


Fix type mismatch: deadAdapters stores metadata objects, not SimpleAdapter instances.

The function returns deadAdapters[adapterType][protocolName] (a { modulePath, codePath, module } object created in migrateDeadProjects.ts lines 128-132) as the adapter field, but the return type signature declares adapter: SimpleAdapter. Callers like importAdapter.ts (line 41) expect a SimpleAdapter conforming to AdapterBase & { adapter?: BaseAdapter }, not metadata.

Additionally, the module field is corrupted by mockFunctions (lines 41-48 of migrateDeadProjects.ts), which replaces all functions with the string '_f'. When dead adapters are retrieved at runtime, the caller will receive an incompatible data structure instead of a functional adapter.

🤖 Prompt for AI Agents
In `@factory/registry.ts` around lines 51 - 57, The returned object is supplying
metadata (deadAdapters[adapterType][protocolName]) where the signature expects a
functional SimpleAdapter (AdapterBase & { adapter?: BaseAdapter }), and the
stored metadata's module field is corrupted by mockFunctions; fix by changing
the registry return to provide either a real adapter loader or a properly-typed
adapter: locate the deadAdapters map and instead of returning the raw metadata
object, use its modulePath/codePath to import/require and reconstruct a valid
SimpleAdapter instance (or return a wrapper that lazily imports and instantiates
the adapter) so callers like importAdapter.ts receive an AdapterBase-compatible
object; also update the types for deadAdapters and the return type of the
registry function to reflect metadata vs adapter (or convert metadata to a
proper SimpleAdapter before returning), and ensure migrateDeadProjects.ts does
not leave the module field with mockFunctions='_f' or provide a deserialization
step to restore real functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants