Skip to content

feat: use address utils to compare addresses#827

Open
limitofzero wants to merge 6 commits intomainfrom
feat/use-address-utils-for-comparing
Open

feat: use address utils to compare addresses#827
limitofzero wants to merge 6 commits intomainfrom
feat/use-address-utils-for-comparing

Conversation

@limitofzero
Copy link
Contributor

@limitofzero limitofzero commented Mar 14, 2026

Summary by CodeRabbit

  • Refactor
    • Standardized address normalization and comparison across bridging providers, signing adapters, and token utilities for more consistent behavior.
  • Bug Fixes
    • Improved token lookup, deduplication and equality checks to reduce mismatches and ensure more reliable token identification and flow handling.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7bd8ce01-5b63-4699-92a6-9463cda41692

📥 Commits

Reviewing files that changed from the base of the PR and between 9984f7c and 2521c02.

⛔ Files ignored due to path filters (1)
  • packages/contracts-ts/src/generated/packageVersion.ts is excluded by !**/generated/**
📒 Files selected for processing (3)
  • packages/bridging/src/BridgingSdk/BridgingSdk.ts
  • packages/bridging/src/providers/across/AcrossBridgeProvider.ts
  • packages/bridging/src/providers/across/util.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/bridging/src/providers/across/util.ts

📝 Walkthrough

Walkthrough

Replaces ad-hoc lowercasing with centralized helpers getAddressKey and areAddressesEqual from @cowprotocol/sdk-common across bridging, provider, contracts, and adapter packages to standardize address normalization and comparisons.

Changes

Cohort / File(s) Summary
Bridging SDK Core
packages/bridging/src/BridgingSdk/BridgingSdk.ts, packages/bridging/src/BridgingSdk/determineIntermediateToken.ts, packages/bridging/src/BridgingSdk/helpers.ts, packages/bridging/src/BridgingSdk/tokenPriority.ts
Replaced .toLowerCase() normalization with getAddressKey() for token deduplication, cache keys, correlated-token resolution, and stablecoin priority checks; one token literal lowercased.
Across provider
packages/bridging/src/providers/across/AcrossBridgeProvider.ts, packages/bridging/src/providers/across/util.ts
Switched address normalization to getAddressKey() for buy-token lookups, supported-token maps, and event log comparisons.
Bungee provider
packages/bridging/src/providers/bungee/createBungeeDepositCall.ts
Replaced direct lowercased ETH address comparison with areAddressesEqual() when determining native/token value.
Near Intents provider
packages/bridging/src/providers/near-intents/NearIntentsBridgeProvider.ts, packages/bridging/src/providers/near-intents/util.ts
Now uses getAddressKey() for token maps/lookups and areAddressesEqual() for attestor/ETH and token equality checks.
Contracts TS API
packages/contracts-ts/src/api.ts
Replaced lowercase string equality with areAddressesEqual() for buyToken validation; updated mismatch message to show raw addresses.
Ethers signer adapters
packages/providers/ethers-v5-adapter/src/EthersV5SignerAdapter.ts, packages/providers/ethers-v6-adapter/src/EthersV6SignerAdapter.ts
Use getAddressKey() instead of .toLowerCase() when supplying addresses to eth_signTypedData requests.
Trading utilities
packages/trading/src/utils/misc.ts
Replaced .toLowerCase() equality with areAddressesEqual() for ETH-flow detection logic.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I hopped through code with a twitchy nose,
Swapped scattered lowercases for trusty prose,
getAddressKey and areAddressesEqual sing,
Addresses now march tidy in a ring,
A happy rabbit hop — neat code, ready to go!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective of the changeset: replacing manual string lowercasing with dedicated address utility functions for comparing and normalizing addresses across multiple files.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/use-address-utils-for-comparing
📝 Coding Plan
  • Generate coding plan for human review comments

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.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 14, 2026

📦 GitHub Packages Published

Last updated: Mar 16, 2026, 12:46:20 PM UTC

The following packages have been published to GitHub Packages with pre-release version pr-827-e1dae620:

  • @cowprotocol/cow-sdk@8.0.0-pr-827-e1dae620.0
  • @cowprotocol/sdk-app-data@4.6.8-pr-827-e1dae620.0
  • @cowprotocol/sdk-bridging@3.0.0-pr-827-e1dae620.0
  • @cowprotocol/sdk-common@0.7.1-pr-827-e1dae620.0
  • @cowprotocol/sdk-composable@0.1.38-pr-827-e1dae620.0
  • @cowprotocol/sdk-config@1.0.0-pr-827-e1dae620.0
  • @cowprotocol/sdk-contracts-ts@2.0.0-pr-827-e1dae620.0
  • @cowprotocol/sdk-cow-shed@0.2.22-pr-827-e1dae620.0
  • @cowprotocol/sdk-ethers-v5-adapter@0.3.11-pr-827-e1dae620.0
  • @cowprotocol/sdk-ethers-v6-adapter@0.3.11-pr-827-e1dae620.0
  • @cowprotocol/sdk-flash-loans@2.0.0-pr-827-e1dae620.0
  • @cowprotocol/sdk-order-book@2.0.0-pr-827-e1dae620.0
  • @cowprotocol/sdk-order-signing@0.1.38-pr-827-e1dae620.0
  • @cowprotocol/sdk-subgraph@1.0.0-pr-827-e1dae620.0
  • @cowprotocol/sdk-trading@1.0.4-pr-827-e1dae620.0
  • @cowprotocol/sdk-viem-adapter@0.3.11-pr-827-e1dae620.0
  • @cowprotocol/sdk-weiroll@0.1.22-pr-827-e1dae620.0

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/cow-sdk@8.0.0-pr-827-e1dae620.0) or more conveniently by using the tag (@cowprotocol/cow-sdk@pr-827):

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

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

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

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

@limitofzero limitofzero requested a review from a team March 14, 2026 18:41
@limitofzero limitofzero self-assigned this Mar 14, 2026
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/bridging/src/BridgingSdk/helpers.ts (1)

14-14: Consider preserving legacy cache-key shape (or versioning cache prefix).

This changes persisted key generation for non-EVM/default token values, so existing localStorage entries may become unreachable after rollout.

♻️ Compatibility-preserving option
 export const getCacheKey = ({
   id,
   buyChainId,
   sellChainId = 'noSellChainID',
   tokenAddress = 'noTokenAddress',
 }: {
   id: string
   buyChainId: string
   sellChainId?: string
   tokenAddress?: string
 }) => {
-  return `${id}-${buyChainId}-${sellChainId}-${getAddressKey(tokenAddress)}`
+  const tokenKey = tokenAddress === 'noTokenAddress' ? 'notokenaddress' : getAddressKey(tokenAddress)
+  return `${id}-${buyChainId}-${sellChainId}-${tokenKey}`
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bridging/src/BridgingSdk/helpers.ts` at line 14, The cache key
generation change in the return expression that builds
`${id}-${buyChainId}-${sellChainId}-${getAddressKey(tokenAddress)}` will break
access to existing persisted localStorage entries; either restore the legacy key
shape for non-EVM/default token cases or add an explicit versioned prefix to the
key so old keys remain reachable. Update the function that constructs this key
(the line returning the template string and the helper getAddressKey if it
altered behavior) to either (a) detect legacy token types and emit the previous
format, or (b) prepend a stable version prefix like `v1:` to new keys so you can
migrate/lookup old keys alongside new ones.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/bridging/src/BridgingSdk/tokenPriority.ts`:
- Line 54: The registry contains a mixed-case literal so lookups like return
chainTokens.has(getAddressKey(tokenAddress)) can miss matches; when constructing
or populating chainTokens (the registry/set) normalize each entry using the same
getAddressKey (or a consistent toLowerCase) function used in lookups so the keys
are canonical, or alternatively ensure getAddressKey normalizes both input and
stored registry values; update the code that builds chainTokens to call
getAddressKey on each registry literal so
chainTokens.has(getAddressKey(tokenAddress)) reliably matches.

---

Nitpick comments:
In `@packages/bridging/src/BridgingSdk/helpers.ts`:
- Line 14: The cache key generation change in the return expression that builds
`${id}-${buyChainId}-${sellChainId}-${getAddressKey(tokenAddress)}` will break
access to existing persisted localStorage entries; either restore the legacy key
shape for non-EVM/default token cases or add an explicit versioned prefix to the
key so old keys remain reachable. Update the function that constructs this key
(the line returning the template string and the helper getAddressKey if it
altered behavior) to either (a) detect legacy token types and emit the previous
format, or (b) prepend a stable version prefix like `v1:` to new keys so you can
migrate/lookup old keys alongside new ones.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1ba14ad2-3d17-4b3e-a60c-c7b9ae515d42

📥 Commits

Reviewing files that changed from the base of the PR and between 9cb9513 and 44d4b68.

⛔ Files ignored due to path filters (1)
  • packages/contracts-ts/src/generated/packageVersion.ts is excluded by !**/generated/**
📒 Files selected for processing (13)
  • packages/bridging/src/BridgingSdk/BridgingSdk.ts
  • packages/bridging/src/BridgingSdk/determineIntermediateToken.ts
  • packages/bridging/src/BridgingSdk/helpers.ts
  • packages/bridging/src/BridgingSdk/tokenPriority.ts
  • packages/bridging/src/providers/across/AcrossBridgeProvider.ts
  • packages/bridging/src/providers/across/util.ts
  • packages/bridging/src/providers/bungee/createBungeeDepositCall.ts
  • packages/bridging/src/providers/near-intents/NearIntentsBridgeProvider.ts
  • packages/bridging/src/providers/near-intents/util.ts
  • packages/contracts-ts/src/api.ts
  • packages/providers/ethers-v5-adapter/src/EthersV5SignerAdapter.ts
  • packages/providers/ethers-v6-adapter/src/EthersV6SignerAdapter.ts
  • packages/trading/src/utils/misc.ts

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