Skip to content

Conversation

@alfetopito
Copy link
Contributor

@alfetopito alfetopito commented Oct 16, 2025

Summary

AppData hook field dappId property is currently too strict, specially since we moved to a human readable format.

Partially addressed already on #591

This PR:

  • Removed the hex limitation of the dappId field to accommodate for current usage covered on fix(app-data): remove dappId validation #591
  • Marked dappId field as deprecated in favor of the new field type
  • Added type field to be more inline with the current usage

Testing

Unit tests

Summary by CodeRabbit

  • New Features

    • Added support for app data v1.9.0.
    • Enhanced order interaction hooks: pre/post hook execution, new hook type, and dApp ID marked deprecated.
    • New order metadata: flashloan, bridging, widget settings, partner-fee structures, and replaced-order tracking.
  • Tests

    • Expanded test coverage for v1.9.0 and hooks; tests updated to reference the latest app-data version.

@alfetopito alfetopito self-assigned this Oct 16, 2025
@alfetopito alfetopito requested a review from a team October 16, 2025 16:39
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 16, 2025

Walkthrough

Adds AppData v1.9.0 and bumps hooks metadata to v0.3.0: new generated TypeScript types, new JSON schemas for hooks and root schema, updated generatedTypes exports, and corresponding test updates and constant bumps.

Changes

Cohort / File(s) Summary
Type Definitions Index
packages/app-data/src/generatedTypes/index.ts
Bumped LATEST_APP_DATA_VERSION '1.8.0' → '1.9.0' and LATEST_HOOKS_METADATA_VERSION '0.2.0' → '0.3.0'; LatestAppDataDocVersion now references v1_9_0.AppDataRootSchema; expanded AnyAppDataDocVersion union; exported v1_9_0.
Type Definitions Export
packages/app-data/src/generatedTypes/latest.ts
Re-export cowAppDataLatestScheme from ./v1.9.0 instead of ./v1.8.0.
v1.9.0 Generated Types
packages/app-data/src/generatedTypes/v1.9.0.ts
New auto-generated TypeScript file: many type aliases, unions, and interfaces for AppDataRootSchema v1.9.0 (Metadata, CoWHook, PartnerFee, Bridging, Flashloan, UTMs, Quote, etc.).
Schema Definitions
packages/app-data/src/schemas/definitions.json
Removed pattern constraint from dappId; added new hookType definition (string, minLength:1).
Hook Schema v0.3.0
packages/app-data/src/schemas/hook/v0.3.0.json
New JSON Schema for Hook v0.3.0: required target, callData, gasLimit; dappId marked deprecated; type uses new hookType definition; strict additionalProperties: false.
Hooks Schema v0.3.0
packages/app-data/src/schemas/hooks/v0.3.0.json
New JSON Schema for OrderInteractionHooks v0.3.0: version (default "0.3.0"), pre and post arrays referencing hook/v0.3.0.json.
App Data Root Schema v1.9.0
packages/app-data/src/schemas/v1.9.0.json
New AppData root schema v1.9.0: required version and metadata, optional appCode/environment; metadata references multiple versioned sub-schemas (signer, referrer, utm, quote, orderClass, hooks, widget, partnerFee, replacedOrder, bridging, flashloan).
Schema Tests
packages/app-data/test/schema.spec.ts
Added test suite "Schema v1.9.0: hooks metadata update to 0.3.0" validating minimal schema, empty hooks, and pre/post hook shapes (including target, callData, gasLimit, type, dappId).
Flashloan Tests
packages/app-data/test/flashloan-metadata.spec.ts
Tests updated to import LATEST_APP_DATA_VERSION; replaced hard-coded '1.8.0' with the latest constant and updated descriptions to reference "latest".

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

v7

Poem

🐰 I stitched a new schema, neat and spry,
v1.9.0 hops in, hooks reach the sky.
Types lined up, tests give a cheer,
Metadata tuned — a carrot-sized gear.
Hooray for small paws making code clear! 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The PR title "fix(app-data): add hook type, ease validation on dappId" accurately reflects the core objectives documented in the PR summary. The title captures the two main improvements: adding a new type field to the hook system and removing the hexadecimal-only pattern constraint from dappId to support human-readable values. While the changeset is comprehensive (including v1.9.0 schema migration and multiple supporting files), the title appropriately focuses on the primary API improvements that drive these changes. The title is clear, concise, and specific—it conveys the meaningful intent without unnecessary details like version numbers or file lists.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ 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/hook-type

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.

},
"dappId": {
"$id": "#/definitions/dappId",
"pattern": "^[a-fA-F0-9]{64}$",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is no longer true since we moved to human readable URL format.

"$ref": "../definitions.json#/definitions/dappId",
"title": "Id of the dApp which has built the hook",
"description": "Deprecated, will be removed in future versions. Use `type` field instead.",
"deprecated": true
Copy link
Contributor Author

Choose a reason for hiding this comment

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

dappId marked as deprecated

"deprecated": true
},
"type": {
"$ref": "../definitions.json#/definitions/hookType"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added type field as the name is more explicit

@github-actions
Copy link
Contributor

github-actions bot commented Oct 16, 2025

📦 GitHub Packages Published

Last updated: Oct 17, 2025, 11:02:03 AM UTC

The following packages have been published to GitHub Packages with pre-release version pr-589-05e65625:


Installation

These packages require authentication to install from GitHub Packages. First, create a .npmrc file:

# Create .npmrc file in your project root
echo "@cowprotocol:registry=https://npm.pkg.github.com" > .npmrc
echo "//npm.pkg.github.com/:_authToken=YOUR_GITHUB_TOKEN" >> .npmrc

To get your GitHub token:

  1. Go to https://github.com/settings/tokens
  2. Click "Generate new token (classic)"
  3. Check only the "read:packages" scope
  4. Copy the token and replace YOUR_GITHUB_TOKEN in the .npmrc file

Then install any of the packages above, either by exact version (i.e. @cowprotocol/[email protected]) or more conveniently by using the tag (@cowprotocol/cow-sdk@pr-589):

# Yarn
yarn add npm:@cowprotocol/cow-sdk@pr-589

# pnpm
pnpm install npm:@cowprotocol/cow-sdk@pr-589

# NPM
npm install npm:@cowprotocol/cow-sdk@pr-589

Update to the latest version (only if you used the tag)

Every commit will publish a new package. To upgrade to the latest version, run:

# Yarn
yarn upgrade @cowprotocol/cow-sdk

# pnpm
pnpm update @cowprotocol/cow-sdk

# NPM
npm update @cowprotocol/cow-sdk

View Packages

You can view the published packages at: https://github.com/cowprotocol/cow-sdk/packages

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

🧹 Nitpick comments (5)
packages/app-data/src/schemas/definitions.json (2)

51-56: dappId docs are now misleading; update title/description to reflect relaxed validation and deprecation

Since the hex pattern was removed, "A hex string..." is inaccurate. Suggest clarifying and marking deprecated at the definition level.

 "dappId": {
   "$id": "#/definitions/dappId",
-  "title": "A hex string representing a dApp ID",
-  "examples": ["75716a3cb48fdbb43ebdff58ce6c541f6a2c269be690513131355800367f2da2"],
+  "title": "dApp identifier",
+  "description": "Deprecated; replaced by `type` in hooks. Accepts arbitrary string for backward compatibility.",
+  "deprecated": true,
+  "examples": ["cow-swap", "legacy-hex-id-75716a3c..."],
   "type": "string"
 }

57-63: Prevent empty hookType values

Consider enforcing a minimal length to avoid accidental empty strings while keeping it otherwise free-form.

 "hookType": {
   "$id": "#/definitions/hookType",
   "title": "Hook Type",
   "description": "Non-typed identifier of a hook, usually in the form of a URL.",
   "examples": ["cow-swap://libs/hook-dapp-lib/permit", "cow-sdk://bridging/providers/socket"],
-  "type": "string"
+  "type": "string",
+  "minLength": 1
 },
packages/app-data/src/schemas/hooks/v0.3.0.json (1)

16-33: Quality-of-life: default empty arrays for pre/post

Defaulting to [] reduces boilerplate and matches “empty hooks” semantics.

 "pre": {
   "$id": "#/properties/hooks/pre",
   "title": "Pre-Hooks",
   "description": "CoW Hooks to call before an order executes",
   "type": "array",
+  "default": [],
   "items": {
     "$ref": "../hook/v0.3.0.json#"
   }
 },
 "post": {
   "$id": "#/properties/hooks/post",
   "title": "Post-Hooks",
   "description": "CoW Hooks to call after an order executes",
   "type": "array",
+  "default": [],
   "items": {
     "$ref": "../hook/v0.3.0.json#"
   }
 }
packages/app-data/test/schema.spec.ts (1)

1165-1237: Add a negative test to enforce additionalProperties: false on hook items

Ensure unknown fields in hook objects are rejected.

Add:

test('Reject unknown fields in hook item', () => {
  const invalidDoc = {
    version: '1.9.0',
    metadata: {
      hooks: {
        pre: [
          {
            target: '0x0102030405060708091011121314151617181920',
            callData: '0x01020304',
            gasLimit: '10000',
            type: 'cow-swap://libs/hook',
            unexpected: 'nope',
          },
        ],
      },
    },
  }
  expect(validator(invalidDoc)).toBe(false)
})
packages/app-data/src/generatedTypes/v1.9.0.ts (1)

233-239: Surface deprecation in typings for better DX

Consider configuring json-schema-to-typescript (or updating schema annotations) so CoWHook.dappId is emitted with a JSDoc @deprecated tag. This makes IDEs warn at call sites while keeping the field available.

If you want, I can check the generator version and options used to see if it supports emitting @deprecated from deprecated: true in the schema.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0f09262 and 794600f.

📒 Files selected for processing (8)
  • packages/app-data/src/generatedTypes/index.ts (2 hunks)
  • packages/app-data/src/generatedTypes/latest.ts (1 hunks)
  • packages/app-data/src/generatedTypes/v1.9.0.ts (1 hunks)
  • packages/app-data/src/schemas/definitions.json (1 hunks)
  • packages/app-data/src/schemas/hook/v0.3.0.json (1 hunks)
  • packages/app-data/src/schemas/hooks/v0.3.0.json (1 hunks)
  • packages/app-data/src/schemas/v1.9.0.json (1 hunks)
  • packages/app-data/test/schema.spec.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-06-10T03:06:46.146Z
Learnt from: jeffersonBastos
PR: cowprotocol/cow-sdk#327
File: packages/app-data/src/schemas/v0.3.0.json:1-10
Timestamp: 2025-06-10T03:06:46.146Z
Learning: Schema versions v0.1.0 through v0.7.0 in the app-data package are intentionally designed to allow additional properties (no "additionalProperties": false constraint), while versions v0.8.0 and later enforce strict validation. This represents a deliberate design evolution and historical schema versions should not be modified to add stricter validation.

Applied to files:

  • packages/app-data/src/schemas/v1.9.0.json
  • packages/app-data/src/generatedTypes/index.ts
🧬 Code graph analysis (2)
packages/app-data/test/schema.spec.ts (1)
packages/app-data/test/test-utils.ts (1)
  • buildAssertValidFn (3-11)
packages/app-data/src/generatedTypes/index.ts (2)
packages/app-data/src/generatedTypes/v1.9.0.ts (1)
  • AppDataRootSchema (186-191)
packages/trading/src/types.ts (1)
  • AppDataRootSchema (229-229)
⏰ 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). (2)
  • GitHub Check: Publish to GitHub Packages
  • GitHub Check: eslint
🔇 Additional comments (4)
packages/app-data/src/generatedTypes/latest.ts (1)

3-3: LGTM: latest export now targets v1.9.0

Aligns the alias with the new schema version.

packages/app-data/src/schemas/v1.9.0.json (1)

1-84: v1.9.0 schema wiring looks correct

Root/metadata strictness and hooks->v0.3.0 reference align with the change.

packages/app-data/src/schemas/hook/v0.3.0.json (1)

1-44: Hook v0.3.0 matches the migration plan

Required fields + optional deprecated dappId and new type are correct. With hookType minLength enforcement in definitions.json, this stays flexible without allowing empty strings.

packages/app-data/src/generatedTypes/index.ts (1)

27-41: LGTM: latest constants/types upgraded to 1.9.0 and hooks 0.3.0

Public API aligns with new schema; union updated appropriately.

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

🧹 Nitpick comments (1)
packages/app-data/test/flashloan-v1.7.0.spec.ts (1)

5-5: Consider renaming the describe block to reflect mixed version coverage.

The describe block name "Flashloan metadata v1.7.0" and the file name flashloan-v1.7.0.spec.ts suggest all tests validate v1.7.0 specifically. However, tests at lines 14-25 and 156-172 now validate the latest version (1.9.0). While the behavior is correct—newly generated documents should use the latest schema—the naming is misleading.

Consider either:

  1. Renaming the describe block to "Flashloan metadata" (removing version reference)
  2. Splitting tests into separate describe blocks for v1.7.0 and latest version
  3. Renaming the file to flashloan.spec.ts

Also applies to: 14-14, 156-156

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 794600f and 7677d8c.

📒 Files selected for processing (1)
  • packages/app-data/test/flashloan-v1.7.0.spec.ts (5 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/app-data/test/flashloan-v1.7.0.spec.ts (1)
packages/app-data/src/generatedTypes/index.ts (1)
  • LATEST_APP_DATA_VERSION (27-27)
⏰ 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). (3)
  • GitHub Check: test
  • GitHub Check: Publish to GitHub Packages
  • GitHub Check: eslint
🔇 Additional comments (2)
packages/app-data/test/flashloan-v1.7.0.spec.ts (2)

3-3: LGTM: Import of LATEST_APP_DATA_VERSION is correct.

The import statement correctly brings in the latest version constant for use in the tests.


14-14: LGTM: Correct usage of LATEST_APP_DATA_VERSION constant.

The test names were appropriately updated to "latest" and the assertions correctly use the LATEST_APP_DATA_VERSION constant instead of hard-coded version strings. This ensures tests automatically validate against the current latest version.

Also applies to: 24-24, 156-156, 171-171

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

🧹 Nitpick comments (1)
packages/app-data/test/flashloan-metadata.spec.ts (1)

27-154: Consider adding v1.9.0 compatibility tests.

The existing tests validate flashloan metadata for v1.7.0, which is good for regression testing. However, consider adding similar validation tests using v1.9.0 to ensure flashloan metadata remains compatible with the latest schema version.

Example test to add:

test('Validates valid flashloan metadata v1.9.0', async () => {
  // given
  const appDataDocV190 = {
    version: '1.9.0',
    appCode: 'aave-v3-flashloan',
    metadata: {
      flashloan: validFlashloanMetadata,
    },
  }

  // when
  const validation = await validateAppDataDoc(appDataDocV190)

  // then
  expect(validation.success).toBeTruthy()
  expect(validation.errors).toBeUndefined()
})
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7677d8c and 82737d4.

📒 Files selected for processing (2)
  • packages/app-data/src/schemas/definitions.json (2 hunks)
  • packages/app-data/test/flashloan-metadata.spec.ts (5 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/app-data/test/flashloan-metadata.spec.ts (1)
packages/app-data/src/generatedTypes/index.ts (1)
  • LATEST_APP_DATA_VERSION (27-27)
⏰ 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). (3)
  • GitHub Check: Publish to GitHub Packages
  • GitHub Check: test
  • GitHub Check: eslint
🔇 Additional comments (2)
packages/app-data/test/flashloan-metadata.spec.ts (2)

3-3: LGTM! Good use of version constant for maintainability.

Using LATEST_APP_DATA_VERSION instead of hardcoded version strings improves maintainability and ensures tests stay in sync with the latest schema version.

Also applies to: 24-24, 171-171


5-5: LGTM! Test naming now version-agnostic.

The updated test names appropriately reference "latest" instead of specific versions, making them easier to maintain as new versions are introduced.

Also applies to: 14-14, 156-156

Copy link
Contributor

@anxolin anxolin left a comment

Choose a reason for hiding this comment

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

Nice, please if we change this check our alerts don't depend on this. I believe they do (hook trace debug queries from Matias)

@alfetopito alfetopito marked this pull request as draft October 17, 2025 13:30
@alfetopito
Copy link
Contributor Author

Nice, please if we change this check our alerts don't depend on this. I believe they do (hook trace debug queries from Matias)

I moved it back to draft, as we need to update usages of dappId with type everywhere in the SDK, and later on CoW Swap.
For now, just released the fix only removing the bad validation #591 to unblock lifi.

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.

3 participants