Skip to content

feat: add patch for the refund logic - #639

Merged
s2imonovic merged 5 commits into
mainfrom
refund-patch
Nov 3, 2026
Merged

s2imonovic merged 5 commits into
mainfrom
refund-patch

Conversation

@s2imonovic

@s2imonovic s2imonovic commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Mainnet patch for the refund logic


Note

High Risk
Introduces a new custody outflow path controlled by DEFAULT_ADMIN_ROLE on a mainnet-facing token vault; incorrect off-chain validation or compromised admin could misdirect user funds.

Overview
Adds refundStrandedFunds on ERC20Custody so default admins (not TSS/WITHDRAWER_ROLE) can send whitelisted ERC20 from custody to a recipient after off-chain validation—intended as a mainnet patch for stranded balances.

The call mirrors withdraw’s transfer mechanics (safeTransfer, whitelist check) but is gated by DEFAULT_ADMIN_ROLE, respects pause and reentrancy guards, rejects zero to, and emits StrandedFundsRefunded. The interface and upgrade test double are updated; Foundry tests cover success, ACL, pause, whitelist, and insufficient balance, plus post-UUPS upgrade behavior.

Reviewed by Cursor Bugbot for commit 858be59. Configure here.

Summary by CodeRabbit

  • New Features

    • Added a way for admins to refund stranded ERC20 tokens held in custody.
    • Refunds now emit an event so transfers can be tracked externally.
  • Bug Fixes

    • Added safeguards for invalid recipient addresses, unapproved tokens, paused contracts, and insufficient balances.
    • Included reentrancy protection and admin-only access checks for refunds.
  • Tests

    • Expanded test coverage for successful refunds, failure cases, and upgrade behavior.

@s2imonovic
s2imonovic requested review from a team as code owners June 30, 2026 15:11
@github-actions github-actions Bot added the feat label Jun 30, 2026
@coderabbitai

coderabbitai Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@s2imonovic, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 45 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 70a3fa59-66d0-4106-9553-7d1d709545c2

📥 Commits

Reviewing files that changed from the base of the PR and between 858be59 and b64c24f.

⛔ Files ignored due to path filters (1)
  • data/checksum/mainnet.json is excluded by !data/**
📒 Files selected for processing (6)
  • broadcast/DeployERC20CustodyImplementation.s.sol/1/run-latest.json
  • broadcast/DeployERC20CustodyImplementation.s.sol/137/run-latest.json
  • broadcast/DeployERC20CustodyImplementation.s.sol/42161/run-latest.json
  • broadcast/DeployERC20CustodyImplementation.s.sol/43114/run-latest.json
  • broadcast/DeployERC20CustodyImplementation.s.sol/56/run-latest.json
  • broadcast/DeployERC20CustodyImplementation.s.sol/8453/run-latest.json
📝 Walkthrough

Walkthrough

Adds a refundStrandedFunds function to ERC20Custody and its interface, allowing the contract admin to transfer whitelisted ERC20 tokens from custody to a recipient. The function emits StrandedFundsRefunded. Tests cover success, five failure cases, and a post-upgrade scenario.

Changes

Stranded Funds Refund

Layer / File(s) Summary
Interface: event and function
contracts/evm/interfaces/IERC20Custody.sol
Adds StrandedFundsRefunded event and refundStrandedFunds external function to IERC20CustodyEvents and IERC20Custody.
Implementation
contracts/evm/ERC20Custody.sol, test/utils/upgrades/ERC20CustodyUpgradeTest.sol
Implements refundStrandedFunds with DEFAULT_ADMIN_ROLE, whenNotPaused, nonReentrant, zero-address and whitelist validation, safeTransfer, and event emission. Upgrade test contract mirrors the same logic.
Tests
test/ERC20Custody.t.sol
Adds testRefundStrandedFunds (success), five revert cases (non-admin, zero address, non-whitelisted token, paused, insufficient balance), and testUpgradeAndRefundStrandedFunds.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is broadly aligned with the new refundStrandedFunds patch, though it is somewhat vague about the specific ERC20 custody change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refund-patch

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.

@skosito skosito mentioned this pull request Nov 3, 2026

@skosito skosito left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Checked on chain:

  • All 6 mainnet custodies (ETH, BSC, Polygon, Base, Arbitrum, Avalanche) point at 0x245a2e9a284F9C8c04ECdAf90908B54a05e34232, matching the checksum.
  • The broadcast files show it was deployed from 858be59, whose ERC20Custody.sol is the code in this PR.
  • On each chain the admin is a 5/7 Safe that holds DEFAULT_ADMIN_ROLE, and none of the custodies are paused.

Non-blocking, since it's already deployed:

  1. DEFAULT_ADMIN_ROLE as the gate.

    • Every refund batch needs 5/7 signatures on the protocol admin Safe.
    • Only that Safe can refund, short of granting DEFAULT_ADMIN_ROLE elsewhere, which also gives upgrade and role-grant power.
    • A dedicated REFUNDER_ROLE would let the admin hand refunds to a separate Safe or service and revoke it after the program.

    If the admin Safe signing every batch is the plan, no change is needed. Changing it later means another impl deploy and 6 upgrades, so it's better decided now.

  2. whenNotPaused. If shutdown pauses custody to stop TSS withdrawals, refunds stop too. Revoking WITHDRAWER_ROLE from TSS instead keeps refunds working while blocking withdrawals.

  3. Scope. The foundry.toml isolate = false and GatewayEVM.t.sol changes are test-only and unrelated to refunds. Worth a line in the description.

  4. generate failure. It's on the coreregistry bindings, and main has failed "Generated Files are Updated" since May (b184c3b), so it's not from this PR.

  5. develop. Once this merges, develop needs the same code. #638 carries it.

@s2imonovic
s2imonovic merged commit 68e25bf into main Nov 3, 2026
10 of 12 checks passed
@s2imonovic
s2imonovic deleted the refund-patch branch November 3, 2026 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants