Skip to content

fix: adds ibc types to default registry#2132

Merged
stalniy merged 1 commit intomainfrom
fix/adds-ibc-types
Oct 29, 2025
Merged

fix: adds ibc types to default registry#2132
stalniy merged 1 commit intomainfrom
fix/adds-ibc-types

Conversation

@stalniy
Copy link
Contributor

@stalniy stalniy commented Oct 29, 2025

Why

Because we have ibc types inside indexer and would like to show stats. Fixes #2131

Summary by CodeRabbit

  • New Features

    • Public API to access the type registry via dependency injection.
  • Refactor

    • Registry now includes default Cosmos types plus IBC types and consolidates multiple type sources for broader blockchain type support.
    • Type imports standardized across frontend utilities.
  • Tests

    • Tests updated to use deployment owners as signers where applicable.

@stalniy stalniy requested a review from a team as a code owner October 29, 2025 05:28
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 29, 2025

Walkthrough

Refactors type registry construction to combine Cosmos default and IBC GeneratedTypes with Akash types, exposes the registry via a DI provider, switches several Coin type imports to the chain-sdk private types, and updates tests to use deployment owners as top-up signers.

Changes

Cohort / File(s) Summary
API type registry provider
apps/api/src/billing/providers/type-registry.provider.ts
Combine Cosmos default/IBC types with Akash GeneratedTypes for registry initialization; add DefaultRegistryType alias and ibcTypes extraction; register TYPE_REGISTRY in DI and export InjectTypeRegistry() helper.
Protobuf / registry utilities
apps/api/src/utils/protobuf.ts, apps/indexer/src/shared/utils/protobuf.ts, apps/deploy-web/src/utils/customRegistry.ts
Add DefaultRegistryType, pull stargate default registry, filter IBC entries into ibcTypes, normalize "$type" values (prefix with "/"), build defaultRegistryTypes from multiple Cosmos versions and concatenate ibcTypes; combine with Akash types when creating Registry.
Coin type import updates
apps/deploy-web/src/types/balances.ts, apps/deploy-web/src/utils/priceUtils.ts
Change type-only import of Coin from @cosmjs/stargate to @akashnetwork/chain-sdk/private-types/cosmos.v1beta1.
Top-up tests signer fix
apps/api/src/deployment/services/top-up-managed-deployments/top-up-managed-deployments.service.spec.ts
Replace hardcoded MANAGED_MASTER_WALLET_ADDRESS with deployment owner address as signer in top-up message constructions and related expectations.

Sequence Diagram(s)

sequenceDiagram
  participant App as Application
  participant DI as DI Container
  participant RegistryBuilder as TypeRegistry Builder
  participant Consumer as Service/Module

  rect rgba(60,160,120,0.06)
    Note over RegistryBuilder: Build defaultRegistryTypes\n(from Cosmos v1/v1beta1/v1alpha1/v2alpha1)\n+ ibcTypes (from stargate defaults)
    RegistryBuilder->>RegistryBuilder: normalize "$type" -> "/<type>"
    RegistryBuilder->>RegistryBuilder: collect akashTypes
    RegistryBuilder->>RegistryBuilder: combined = [...defaultRegistryTypes, ...akashTypes]
  end

  RegistryBuilder->>DI: register TYPE_REGISTRY (combined)
  App->>DI: InjectTypeRegistry()
  DI->>Consumer: provide TYPE_REGISTRY
  Consumer->>TYPE_REGISTRY: use GeneratedTypes for protobuf encoding/decoding
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Mixed changes across provider, shared utils, and frontend utils — similar pattern repeated but requires verification.
  • Areas needing extra attention:
    • Correctness of IBC filtering (entries starting with "/ibc") and any assumptions about leading "/" presence.
    • Consistent normalization of "$type" to include leading "/" and ensuring no duplicate/incorrect keys.
    • DI registration and InjectTypeRegistry() signature/usage match existing DI conventions.
    • Type import swaps for Coin — confirm the new private-types export shape and compatibility with existing code.
    • Test updates: verify expectations and signer behavior correctly reflect intended owner semantics.

Possibly related PRs

  • Main sdk next #2114 — Very similar changes to protobuf/type registry construction, IBC extraction, normalization of "$type", and exposure of TYPE_REGISTRY/InjectTypeRegistry.

Suggested reviewers

  • ygrishajev

Poem

🐰 I hopped through types and stitched the seam,
IBC and Cosmos join Akash's dream,
The registry now springs from many seeds,
A DI carrot gives consumers what they need,
Hop, encode, decode — a tidy stream! 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "fix: adds ibc types to default registry" accurately and directly reflects the primary changes throughout the codebase. The modifications across multiple files (type-registry.provider.ts, protobuf.ts, customRegistry.ts, and others) consistently implement the same core feature: extracting IBC types from stargateDefaultRegistryTypes and integrating them into the default registry. The title is concise, clear, and specific enough to convey the main intent without unnecessary details. The secondary test updates are supporting changes that don't detract from this primary objective.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/adds-ibc-types

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

@codecov
Copy link

codecov bot commented Oct 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 46.10%. Comparing base (2fba35d) to head (d6442b5).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2132      +/-   ##
==========================================
- Coverage   46.45%   46.10%   -0.35%     
==========================================
  Files        1016     1006      -10     
  Lines       28709    28370     -339     
  Branches     7463     7425      -38     
==========================================
- Hits        13336    13081     -255     
+ Misses      14969    14894      -75     
+ Partials      404      395       -9     
Flag Coverage Δ *Carryforward flag
api 81.95% <100.00%> (-0.01%) ⬇️
deploy-web 24.64% <100.00%> (+0.01%) ⬆️
log-collector ?
notifications 88.11% <ø> (ø) Carriedforward from 2fba35d
provider-console 81.48% <ø> (ø) Carriedforward from 2fba35d
provider-proxy 84.61% <ø> (ø) Carriedforward from 2fba35d

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
...pi/src/billing/providers/type-registry.provider.ts 100.00% <100.00%> (ø)
apps/api/src/utils/protobuf.ts 77.50% <100.00%> (+1.18%) ⬆️
apps/deploy-web/src/utils/customRegistry.ts 100.00% <100.00%> (ø)
apps/deploy-web/src/utils/priceUtils.ts 34.21% <ø> (ø)

... and 11 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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: 2

♻️ Duplicate comments (1)
apps/deploy-web/src/types/balances.ts (1)

1-1: Same private-types import path concern.

This file has the same private-types import path usage as apps/deploy-web/src/utils/priceUtils.ts. Please ensure this is the intended and stable import path across the codebase.

🧹 Nitpick comments (1)
apps/indexer/src/shared/utils/protobuf.ts (1)

15-20: Consider extracting duplicated registry construction logic.

The logic for defining DefaultRegistryType, extracting ibcTypes, and constructing defaultRegistryTypes is duplicated across multiple files:

  • apps/api/src/utils/protobuf.ts
  • apps/api/src/billing/providers/type-registry.provider.ts
  • apps/deploy-web/src/utils/customRegistry.ts

Consider extracting this shared logic into a common utility module to reduce duplication and ensure consistency.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2fba35d and afdaf8f.

📒 Files selected for processing (6)
  • apps/api/src/billing/providers/type-registry.provider.ts (1 hunks)
  • apps/api/src/utils/protobuf.ts (1 hunks)
  • apps/deploy-web/src/types/balances.ts (1 hunks)
  • apps/deploy-web/src/utils/customRegistry.ts (1 hunks)
  • apps/deploy-web/src/utils/priceUtils.ts (1 hunks)
  • apps/indexer/src/shared/utils/protobuf.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Never use type any or cast to type any. Always define the proper TypeScript types.

Files:

  • apps/deploy-web/src/types/balances.ts
  • apps/api/src/billing/providers/type-registry.provider.ts
  • apps/api/src/utils/protobuf.ts
  • apps/deploy-web/src/utils/priceUtils.ts
  • apps/deploy-web/src/utils/customRegistry.ts
  • apps/indexer/src/shared/utils/protobuf.ts
**/*.{js,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

**/*.{js,ts,tsx}: Never use deprecated methods from libraries.
Don't add unnecessary comments to the code

Files:

  • apps/deploy-web/src/types/balances.ts
  • apps/api/src/billing/providers/type-registry.provider.ts
  • apps/api/src/utils/protobuf.ts
  • apps/deploy-web/src/utils/priceUtils.ts
  • apps/deploy-web/src/utils/customRegistry.ts
  • apps/indexer/src/shared/utils/protobuf.ts
🧬 Code graph analysis (1)
apps/api/src/billing/providers/type-registry.provider.ts (1)
apps/deploy-web/src/utils/customRegistry.ts (1)
  • registry (28-28)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: test-build
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
🔇 Additional comments (4)
apps/deploy-web/src/utils/customRegistry.ts (1)

12-28: Registry construction looks correct.

The implementation properly:

  • Extracts IBC types from stargate defaults
  • Includes null checks in the filter (.filter(x => x && "$type" in x))
  • Includes cosmosv2alpha1 types
  • Combines default registry types with Akash-specific types

This is consistent with the intended changes.

apps/api/src/billing/providers/type-registry.provider.ts (1)

34-37: Good addition of dependency injection support.

Exposing the type registry through a DI provider (TYPE_REGISTRY token and InjectTypeRegistry()) is a good practice that improves testability and allows for easier mocking in unit tests.

apps/api/src/utils/protobuf.ts (1)

34-46: LGTM - proper error handling for type lookup.

The decodeMsg function correctly:

  • Creates a registry with all required types
  • Validates that the type exists before decoding
  • Ensures the type is ts-proto generated
  • Returns the decoded message
apps/deploy-web/src/utils/priceUtils.ts (1)

1-1: No changes needed — this is the correct import path.

The private-types import from @akashnetwork/chain-sdk is the intended and supported way to access types from the SDK. Analysis shows 74+ files across the codebase use this same import pattern, confirming it's the standard approach. The package is currently in alpha (1.0.0-alpha.12) under active development, which means breaking changes are possible in any release—but this is a project-wide infrastructure constraint, not specific to this file. No code modifications are required.

@stalniy stalniy force-pushed the fix/adds-ibc-types branch from afdaf8f to d6442b5 Compare October 29, 2025 06:04
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

♻️ Duplicate comments (1)
apps/api/src/utils/protobuf.ts (1)

16-21: Missing cosmosv2alpha1 types - critical inconsistency with other registries.

The defaultRegistryTypes construction is missing cosmosv2alpha1 types, while other registries in this PR include them (see apps/deploy-web/src/utils/customRegistry.ts line 18 and apps/api/src/billing/providers/type-registry.provider.ts line 22). This inconsistency will cause cosmosv2alpha1 messages to fail decoding in this context.

Add the missing import and include the types:

+import * as cosmosv2alpha1 from "@akashnetwork/chain-sdk/private-types/cosmos.v2alpha1";

 type DefaultRegistryType = [string, GeneratedType];
 const ibcTypes: DefaultRegistryType[] = stargateDefaultRegistryTypes.filter(([type]) => type.startsWith("/ibc"));
-const defaultRegistryTypes: DefaultRegistryType[] = [...Object.values(cosmosv1), ...Object.values(cosmosv1beta1), ...Object.values(cosmosv1alpha1)]
+const defaultRegistryTypes: DefaultRegistryType[] = [
+  ...Object.values(cosmosv1),
+  ...Object.values(cosmosv1beta1),
+  ...Object.values(cosmosv1alpha1),
+  ...Object.values(cosmosv2alpha1)
+]
   .filter(x => x && "$type" in x)
   .map(x => ["/" + x.$type, x as unknown as GeneratedType])
   .concat(ibcTypes) as DefaultRegistryType[];
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between afdaf8f and d6442b5.

📒 Files selected for processing (7)
  • apps/api/src/billing/providers/type-registry.provider.ts (1 hunks)
  • apps/api/src/deployment/services/top-up-managed-deployments/top-up-managed-deployments.service.spec.ts (4 hunks)
  • apps/api/src/utils/protobuf.ts (1 hunks)
  • apps/deploy-web/src/types/balances.ts (1 hunks)
  • apps/deploy-web/src/utils/customRegistry.ts (1 hunks)
  • apps/deploy-web/src/utils/priceUtils.ts (1 hunks)
  • apps/indexer/src/shared/utils/protobuf.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/deploy-web/src/utils/priceUtils.ts
  • apps/indexer/src/shared/utils/protobuf.ts
🧰 Additional context used
📓 Path-based instructions (3)
**/*.spec.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/no-jest-mock.mdc)

Don't use jest.mock() to mock dependencies in test files. Instead, use jest-mock-extended to create mocks and pass mocks as dependencies to the service under test.

**/*.spec.{ts,tsx}: Use setup function instead of beforeEach in test files
setup function must be at the bottom of the root describe block in test files
setup function creates an object under test and returns it
setup function should accept a single parameter with inline type definition
Don't use shared state in setup function
Don't specify return type of setup function

Files:

  • apps/api/src/deployment/services/top-up-managed-deployments/top-up-managed-deployments.service.spec.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Never use type any or cast to type any. Always define the proper TypeScript types.

Files:

  • apps/api/src/deployment/services/top-up-managed-deployments/top-up-managed-deployments.service.spec.ts
  • apps/api/src/billing/providers/type-registry.provider.ts
  • apps/deploy-web/src/utils/customRegistry.ts
  • apps/deploy-web/src/types/balances.ts
  • apps/api/src/utils/protobuf.ts
**/*.{js,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

**/*.{js,ts,tsx}: Never use deprecated methods from libraries.
Don't add unnecessary comments to the code

Files:

  • apps/api/src/deployment/services/top-up-managed-deployments/top-up-managed-deployments.service.spec.ts
  • apps/api/src/billing/providers/type-registry.provider.ts
  • apps/deploy-web/src/utils/customRegistry.ts
  • apps/deploy-web/src/types/balances.ts
  • apps/api/src/utils/protobuf.ts
🧬 Code graph analysis (2)
apps/api/src/deployment/services/top-up-managed-deployments/top-up-managed-deployments.service.spec.ts (1)
apps/indexer/drizzle/schema.ts (1)
  • deployment (185-208)
apps/api/src/billing/providers/type-registry.provider.ts (1)
apps/deploy-web/src/utils/customRegistry.ts (1)
  • registry (28-28)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
  • GitHub Check: test-build
🔇 Additional comments (5)
apps/deploy-web/src/types/balances.ts (1)

1-1: LGTM! Import path updated correctly.

The import path change to use the chain-sdk private types is appropriate and maintains the type-only import.

apps/deploy-web/src/utils/customRegistry.ts (1)

10-28: LGTM! Registry construction correctly includes IBC and Cosmos types.

The implementation properly:

  • Extracts IBC types from stargate default registry
  • Includes all Cosmos type versions (v1, v1beta1, v1alpha1, v2alpha1)
  • Combines default registry types with Akash types
  • Maintains correct type transformations with $type prefixing
apps/api/src/billing/providers/type-registry.provider.ts (1)

12-37: Registry construction looks good with IBC types integration.

The implementation correctly:

  • Filters IBC types from stargate defaults
  • Includes all required Cosmos versions (v1, v1beta1, v1alpha1, v2alpha1)
  • Combines default and Akash types in the registry
  • Exposes the registry via DI with InjectTypeRegistry
apps/api/src/deployment/services/top-up-managed-deployments/top-up-managed-deployments.service.spec.ts (2)

119-119: LGTM! Tests correctly updated to use deployment owner as signer.

The test changes reflect the proper ownership model where deployment owners sign their own top-up transactions instead of using a constant master wallet address.

Also applies to: 154-154


287-287: LGTM! Same-owner deployments correctly use owner as signer.

The test properly validates that multiple deployments with the same owner are batched in a single transaction with the owner as the signer.

Also applies to: 304-304

Comment on lines +28 to 30
const newAkashTypes: ReadonlyArray<[string, GeneratedType]> = [...Object.values(v1), ...Object.values(v1beta4), ...Object.values(v1beta5)]
.filter(x => "$type" in x)
.map(x => ["/" + x.$type, x as unknown as GeneratedType]);
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

Verify null safety in newAkashTypes filter.

Line 29 filters with .filter(x => "$type" in x) without checking if x is truthy first, unlike the defaultRegistryTypes filter on line 24 which includes x &&. If any of the imported values are null or undefined, the "$type" in x check could fail.


🏁 Script executed:

#!/bin/bash
# Check if v1, v1beta4, or v1beta5 exports contain null/undefined values
ast-grep --pattern $'export const $_ = null'
ast-grep --pattern $'export const $_ = undefined'

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Locate and examine the file
find . -type f -name "type-registry.provider.ts" -exec cat {} \;

Length of output: 1897


🏁 Script executed:

#!/bin/bash
# Search for imports of v1, v1beta4, v1beta5 in the file
rg -n "import.*\bv1\b" apps/api/src/billing/providers/type-registry.provider.ts -A 2 -B 2

Length of output: 529


🏁 Script executed:

#!/bin/bash
# Check the structure: find what v1beta4 and v1beta5 modules export (look for their files)
find . -type f \( -name "*v1beta4*" -o -name "*v1beta5*" \) | head -20

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Search for other usages of Object.values on these imported modules to see if null checks are needed elsewhere
rg -n "Object.values\(" apps/api/src/billing/providers/type-registry.provider.ts -B 2 -A 2

Length of output: 657


🏁 Script executed:

#!/bin/bash
# Check if there are other files that import from the same chain-sdk modules
rg -n "@akashnetwork/chain-sdk/private-types" --type=ts --type=tsx -g '!node_modules' | head -20

Length of output: 27


🏁 Script executed:

#!/bin/bash
# Look for patterns where Object.values is used on these modules elsewhere in the codebase
rg -n "Object\.values\(\s*(v1|v1beta4|v1beta5|cosmos)" --type=ts --type=tsx -g '!node_modules' -A 2 -B 2

Length of output: 27


Add null safety check to newAkashTypes filter to match defaultRegistryTypes pattern.

Line 29 should include x && before checking "$type" in x, matching the defensive check on line 24. Currently, if Object.values() returns null or undefined, the in operator will throw a TypeError. Both filters process values from external SDK modules using the same pattern and should apply the same safety checks.

const newAkashTypes: ReadonlyArray<[string, GeneratedType]> = [...Object.values(v1), ...Object.values(v1beta4), ...Object.values(v1beta5)]
  .filter(x => x && "$type" in x)
  .map(x => ["/" + x.$type, x as unknown as GeneratedType]);
🤖 Prompt for AI Agents
In apps/api/src/billing/providers/type-registry.provider.ts around lines 28 to
30, the filter on newAkashTypes uses `"${'$'}type" in x` without guarding for
null/undefined which can throw if Object.values yields nullish entries; update
the filter to check x truthiness first (e.g., `x && "$type" in x`) before
accessing $type so it matches the defensive pattern used by
defaultRegistryTypes, then leave the subsequent map unchanged.

@stalniy stalniy merged commit 9e3c6b0 into main Oct 29, 2025
62 checks passed
@stalniy stalniy deleted the fix/adds-ibc-types branch October 29, 2025 06:21
stalniy added a commit that referenced this pull request Nov 20, 2025
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.

Bug: missing proto types when fetching some transactions from stats app

1 participant

Comments