Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

refactor: migrate publishIntent(s) function#552

Merged
cawabunga-bytes merged 5 commits intobetafrom
refactor/migrate-publish-intent
Jul 23, 2025
Merged

refactor: migrate publishIntent(s) function#552
cawabunga-bytes merged 5 commits intobetafrom
refactor/migrate-publish-intent

Conversation

@jobotics
Copy link
Collaborator

@jobotics jobotics commented Jul 22, 2025

Summary by CodeRabbit

  • Refactor
    • Updated internal mechanisms for publishing intents and handling their results, improving compatibility with newer backend systems.
    • Enhanced error handling by standardizing error formats and mapping error codes to legacy structures.
  • Chores
    • Removed outdated publishing and error parsing logic to streamline the codebase.
    • Replaced legacy publishing methods with new, more maintainable utility functions.

@jobotics jobotics requested a review from cawabunga-bytes July 22, 2025 09:54
@coderabbitai
Copy link

coderabbitai bot commented Jul 22, 2025

Warning

Rate limit exceeded

@cawabunga-bytes has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 29 minutes and 1 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 06c1f2b and 1a89c3f.

📒 Files selected for processing (1)
  • src/features/machines/swapIntentMachine.ts (2 hunks)

Walkthrough

The changes refactor the codebase to remove direct usage of legacy publishIntent and publishIntents functions, replacing them with calls to solverRelay.publishIntent(s) from an internal utility package. New adapter functions convert the new result types into the legacy formats expected by the rest of the system. Related error parsing, HTTP client wrappers, and retry logic are removed or replaced by these adapters.

Changes

File(s) Change Summary
src/features/gift/actors/giftMakerPublishingActor.ts
src/features/gift/actors/shared/giftClaimActor.ts
src/features/otcDesk/actors/otcMakerOrderCancellationActor.ts
src/features/otcDesk/hooks/useOtcTakerConfirmTrade.ts
Replaced direct usage of legacy publishIntents with solverRelay.publishIntents and conversion to legacy result format.
src/features/machines/swapIntentMachine.ts
src/features/tokenMigration/machines/tokenMigrationMachine.ts
Switched from legacy publishIntent to solverRelay.publishIntent with result conversion to legacy format.
src/sdk/solverRelay/publishIntent.ts Deleted legacy publishIntent function and its exported types.
src/sdk/solverRelay/publishIntents.ts Removed legacy publishIntents and added convertPublishIntentsToLegacyFormat for adapting new result types to legacy format.
src/sdk/solverRelay/solverRelayHttpClient/apis.ts Removed exported publishIntent and publishIntents HTTP client wrappers.
src/sdk/solverRelay/utils/parseFailedPublishError.ts Replaced legacy error parsing with convertPublishIntentToLegacyFormat for new result type adaptation.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Feature Module
    participant SolverRelay as solverRelay (internal-utils)
    participant Adapter as Legacy Adapter

    Caller->>SolverRelay: publishIntent(s)(...)
    SolverRelay-->>Caller: Result (new format)
    Caller->>Adapter: convertPublishIntent(s)ToLegacyFormat(Result)
    Adapter-->>Caller: Result (legacy format)
Loading

Estimated code review effort

4 (~90 minutes)

Poem

In the warren where code does relay,
Old paths to publish swept away.
New adapters hop in, swift and neat,
Mapping errors, never missing a beat.
Intentions now clearer, legacy in tow—
A bunny’s job well done, onward we go! 🐇✨

✨ 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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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: 3

🔭 Outside diff range comments (1)
src/sdk/solverRelay/utils/parseFailedPublishError.ts (1)

4-17: Add missing RELAY_PUBLISH_NETWORK_ERROR to ParsedPublishErrors type

The ParsedPublishErrors type is missing RELAY_PUBLISH_NETWORK_ERROR which exists in PublishIntentsErr in the other file. This creates an inconsistency.

 export type ParsedPublishErrors =
   | {
       reason:
         | "RELAY_PUBLISH_SIGNATURE_EXPIRED"
         | "RELAY_PUBLISH_INTERNAL_ERROR"
         | "RELAY_PUBLISH_SIGNATURE_INVALID"
         | "RELAY_PUBLISH_NONCE_USED"
         | "RELAY_PUBLISH_INSUFFICIENT_BALANCE"
         | "RELAY_PUBLISH_PUBLIC_NOT_EXIST"
+        | "RELAY_PUBLISH_NETWORK_ERROR"
     }
   | {
       reason: "RELAY_PUBLISH_UNKNOWN_ERROR"
       serverReason: string
     }
🧹 Nitpick comments (1)
src/sdk/solverRelay/publishIntents.ts (1)

10-54: Consider simplifying the return type

Since this function performs synchronous conversion, returning a Promise is unnecessary and adds complexity.

-export function convertPublishIntentsToLegacyFormat(
-  result: Result<
-    solverRelay.PublishIntentsReturnType,
-    solverRelay.PublishIntentsErrorType
-  >
-): Promise<Result<PublishIntentsOk, PublishIntentsErr>> {
+export function convertPublishIntentsToLegacyFormat(
+  result: Result<
+    solverRelay.PublishIntentsReturnType,
+    solverRelay.PublishIntentsErrorType
+  >
+): Result<PublishIntentsOk, PublishIntentsErr> {
   if (result.isOk()) {
-    return Promise.resolve(Ok(result.unwrap()))
+    return Ok(result.unwrap())
   }

   const error = result.unwrapErr()
   const errorCode = error.code

   // Map new PublishErrorCode to old ParsedPublishErrors format
   let reason: ParsedPublishErrors["reason"]
   switch (errorCode) {
     // ... cases ...
   }

-  return Promise.resolve(
-    Err({
-      reason,
-      serverReason: errorCode,
-    })
-  )
+  return Err({
+    reason,
+    serverReason: errorCode,
+  })

Note: This would require updating the usage in otcMakerOrderCancellationActor.ts to remove the .then() call.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 41e7079 and 06c1f2b.

📒 Files selected for processing (10)
  • src/features/gift/actors/giftMakerPublishingActor.ts (2 hunks)
  • src/features/gift/actors/shared/giftClaimActor.ts (2 hunks)
  • src/features/machines/swapIntentMachine.ts (2 hunks)
  • src/features/otcDesk/actors/otcMakerOrderCancellationActor.ts (2 hunks)
  • src/features/otcDesk/hooks/useOtcTakerConfirmTrade.ts (3 hunks)
  • src/features/tokenMigration/machines/tokenMigrationMachine.ts (2 hunks)
  • src/sdk/solverRelay/publishIntent.ts (0 hunks)
  • src/sdk/solverRelay/publishIntents.ts (1 hunks)
  • src/sdk/solverRelay/solverRelayHttpClient/apis.ts (0 hunks)
  • src/sdk/solverRelay/utils/parseFailedPublishError.ts (2 hunks)
💤 Files with no reviewable changes (2)
  • src/sdk/solverRelay/solverRelayHttpClient/apis.ts
  • src/sdk/solverRelay/publishIntent.ts
🔇 Additional comments (12)
src/features/machines/swapIntentMachine.ts (2)

2-2: LGTM: Clean import additions for the migration.

The imports properly bring in the new solverRelay client and the legacy format conversion utility.

Also applies to: 8-8


267-270: LGTM: Proper migration to new solverRelay client.

The change correctly replaces the direct publishIntent call with solverRelay.publishIntent followed by legacy format conversion. The parameter signature matches and the promise chaining ensures proper error propagation.

src/features/otcDesk/hooks/useOtcTakerConfirmTrade.ts (2)

1-1: LGTM: Consistent import changes for the migration.

The imports correctly add the new solverRelay client and replace the old publishIntents import with the legacy conversion function.

Also applies to: 12-12


99-104: LGTM: Proper publishIntents migration with legacy compatibility.

The migration correctly replaces the direct publishIntents call with solverRelay.publishIntents and applies legacy format conversion. The parameter structure is maintained properly.

src/features/gift/actors/shared/giftClaimActor.ts (2)

1-1: LGTM: Consistent import updates for migration.

The imports properly add the new solverRelay client and replace the legacy publishIntents import with the conversion utility.

Also applies to: 8-8


118-123: LGTM: Proper publishIntents migration in gift claim flow.

The migration correctly updates the publishGiftActor to use solverRelay.publishIntents with legacy format conversion. The empty quote_hashes array is appropriate for gift claiming scenarios.

src/features/gift/actors/giftMakerPublishingActor.ts (2)

1-1: LGTM: Consistent import changes for migration.

The imports properly add the new solverRelay client and the legacy conversion utility.

Also applies to: 6-6


45-58: LGTM: Well-structured publishIntents migration with inline error handling.

The migration correctly uses solverRelay.publishIntents with legacy format conversion. The inline error handling and result transformation logic maintains the expected tagged response format while properly handling both success and error cases.

src/features/tokenMigration/machines/tokenMigrationMachine.ts (2)

1-1: LGTM: Proper import updates for migration.

The imports correctly add the new solverRelay client and the legacy format conversion utility.

Also applies to: 7-7


59-63: LGTM: Excellent type-safe migration of publishIntent actor.

The migration uses proper TypeScript typing with Parameters<typeof solverRelay.publishIntent> and correctly applies the spread operator to pass parameters. The legacy format conversion maintains backward compatibility.

src/features/otcDesk/actors/otcMakerOrderCancellationActor.ts (2)

1-1: Import changes look good

The imports correctly reference the new solverRelay from @defuse-protocol/internal-utils and the new conversion function.

Also applies to: 9-9


69-83: Publisher actor migration implemented correctly

The migration properly:

  • Uses the new solverRelay.publishIntents API
  • Converts the result to legacy format for backward compatibility
  • Preserves the existing error handling flow

reason = "RELAY_PUBLISH_INSUFFICIENT_BALANCE"
break
case "PUBLIC_KEY_NOT_EXIST":
reason = "RELAY_PUBLISH_PUBLIC_NOT_EXIST"
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix typo in error reason

The reason should be RELAY_PUBLISH_PUBLIC_KEY_NOT_EXIST to match the pattern and be more descriptive.

-      reason = "RELAY_PUBLISH_PUBLIC_NOT_EXIST"
+      reason = "RELAY_PUBLISH_PUBLIC_KEY_NOT_EXIST"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
reason = "RELAY_PUBLISH_PUBLIC_NOT_EXIST"
reason = "RELAY_PUBLISH_PUBLIC_KEY_NOT_EXIST"
🤖 Prompt for AI Agents
In src/sdk/solverRelay/publishIntents.ts at line 42, the error reason string is
incorrectly set to "RELAY_PUBLISH_PUBLIC_NOT_EXIST". Update this string to
"RELAY_PUBLISH_PUBLIC_KEY_NOT_EXIST" to correct the typo and maintain
consistency with the naming pattern.

reason = "RELAY_PUBLISH_INSUFFICIENT_BALANCE"
break
case "PUBLIC_KEY_NOT_EXIST":
reason = "RELAY_PUBLISH_PUBLIC_NOT_EXIST"
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix typo in error reason (same as in publishIntents.ts)

-      reason = "RELAY_PUBLISH_PUBLIC_NOT_EXIST"
+      reason = "RELAY_PUBLISH_PUBLIC_KEY_NOT_EXIST"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
reason = "RELAY_PUBLISH_PUBLIC_NOT_EXIST"
reason = "RELAY_PUBLISH_PUBLIC_KEY_NOT_EXIST"
🤖 Prompt for AI Agents
In src/sdk/solverRelay/utils/parseFailedPublishError.ts at line 57, there is a
typo in the error reason string "RELAY_PUBLISH_PUBLIC_NOT_EXIST". Correct this
typo to match the exact error reason used in publishIntents.ts for consistency
and correctness.

Comment on lines +59 to 67
reason = "RELAY_PUBLISH_UNKNOWN_ERROR"
break
case "NETWORK_ERROR":
reason = "RELAY_PUBLISH_UNKNOWN_ERROR"
break
default:
reason = "RELAY_PUBLISH_UNKNOWN_ERROR"
}

Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve error mapping to preserve information

  1. NETWORK_ERROR should map to the existing RELAY_PUBLISH_NETWORK_ERROR reason instead of UNKNOWN_ERROR
  2. The default case should include serverReason to help with debugging unmapped error codes
     case "PUBLIC_KEY_NOT_EXIST":
       reason = "RELAY_PUBLISH_PUBLIC_NOT_EXIST"
       break
     case "UNKNOWN_ERROR":
       reason = "RELAY_PUBLISH_UNKNOWN_ERROR"
       break
     case "NETWORK_ERROR":
-      reason = "RELAY_PUBLISH_UNKNOWN_ERROR"
+      reason = "RELAY_PUBLISH_NETWORK_ERROR"
       break
     default:
       reason = "RELAY_PUBLISH_UNKNOWN_ERROR"
   }

   return {
     tag: "err",
     value:
-      reason === "RELAY_PUBLISH_UNKNOWN_ERROR"
+      reason === "RELAY_PUBLISH_UNKNOWN_ERROR" || errorCode === "UNKNOWN_ERROR" || !["SIGNATURE_EXPIRED", "INTERNAL_ERROR", "SIGNATURE_INVALID", "NONCE_USED", "INSUFFICIENT_BALANCE", "PUBLIC_KEY_NOT_EXIST", "NETWORK_ERROR"].includes(errorCode)
         ? { reason, serverReason: errorCode }
         : { reason },
   }

Note: You'll need to add RELAY_PUBLISH_NETWORK_ERROR to the ParsedPublishErrors type union if it doesn't already exist.

Also applies to: 72-74

🤖 Prompt for AI Agents
In src/sdk/solverRelay/utils/parseFailedPublishError.ts around lines 59 to 67,
update the error mapping so that the "NETWORK_ERROR" case assigns reason to
"RELAY_PUBLISH_NETWORK_ERROR" instead of "RELAY_PUBLISH_UNKNOWN_ERROR". Modify
the default case to include the serverReason value in the reason to aid
debugging of unmapped errors. Also ensure that RELAY_PUBLISH_NETWORK_ERROR is
added to the ParsedPublishErrors type union if it is not already present. Apply
the same changes to lines 72-74 as well.

@cawabunga-bytes cawabunga-bytes merged commit b13ac89 into beta Jul 23, 2025
0 of 2 checks passed
@cawabunga-bytes cawabunga-bytes deleted the refactor/migrate-publish-intent branch July 23, 2025 12:40
cawabunga-bytes added a commit that referenced this pull request Jul 23, 2025
* beta:
  refactor: migrate failover and request utils (#554)
  refactor: migrate publishIntent(s) function (#552)
  refactor: migrate logger from internal-utils (#551)
  refactor: migrate poaBridge utils (#550)
  refactor: use toError and NEP-141 storage utils from internal-utils (#548)
cawabunga-bytes added a commit that referenced this pull request Jul 23, 2025
* beta:
  refactor: migrate runtime and waitForIntentSettlement utils (#553)
  refactor: migrate failover and request utils (#554)
  refactor: migrate publishIntent(s) function (#552)
  refactor: migrate logger from internal-utils (#551)
  refactor: migrate poaBridge utils (#550)
  refactor: use toError and NEP-141 storage utils from internal-utils (#548)
@amdefuse
Copy link
Contributor

🎉 This PR is included in version 1.0.0-beta.204 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants