Skip to content

refactor(wallet-registry): update withdrawRewards#3945

Open
lionakhnazarov wants to merge 4 commits intothreshold-network:mainfrom
lionakhnazarov:feat/walletRegistry-withdraw
Open

refactor(wallet-registry): update withdrawRewards#3945
lionakhnazarov wants to merge 4 commits intothreshold-network:mainfrom
lionakhnazarov:feat/walletRegistry-withdraw

Conversation

@lionakhnazarov
Copy link
Copy Markdown
Collaborator

@lionakhnazarov lionakhnazarov commented Apr 17, 2026

Summary

Documents and tests WalletRegistry.withdrawRewards beneficiary resolution via _currentAuthorizationSource().rolesOf(stakingProvider) (Allowlist when allowlist != address(0), otherwise TokenStaking), addressing review feedback that this path differs from always using TokenStaking.rolesOf after upgrade.

Changes

Contract

  • WalletRegistry.withdrawRewards: NatSpec updated to match implementation and to explain Allowlist vs TokenStaking rolesOf semantics (TIP-092 Allowlist uses staking-provider-as-beneficiary; TokenStaking can use a delegated beneficiary). Removed outdated wording that implied lookup stayed on TokenStaking only.
  • Changed the beneficiary retrieval logic in the withdrawRewards function to use the current authorization source, improving accuracy in reward distribution. This change ensures that the correct beneficiary is identified based on the latest authorization context.

Tests

  • WalletRegistry.Rewards.test.ts: New case using walletRegistryFixture({ useAllowlist: true }) — asserts non-zero allowlist, reads Allowlist.rolesOf, funds the sortition pool, calls withdrawRewards, and checks rewards land on the expected beneficiary. (Hardhat + TypeScript; this package does not use Foundry .t.sol.)

Auditor / reviewer notes

On networks where the proxy allowlist is set (e.g. mainnet), withdrawRewards pays the address returned by the Allowlist contract, which may differ from a legacy TokenStaking delegated beneficiary when owner ≠ beneficiary delegation applied only under staking.

Merge / scope

Intended as a small, isolated PR (separate from unrelated testnet or infra work) so beneficiary routing and documentation get focused review.

…dd tests for allowlist integration

- Enhanced documentation for the  function to clarify the beneficiary retrieval process based on the current authorization source.
- Removed historical migration rationale as it is no longer relevant.
- Added new tests to verify reward distribution when the allowlist is active, ensuring correct beneficiary handling and reward payouts.
- Updated import statements to include 'ethers' alongside 'helpers' for clarity.
- Refactored test code for better readability by adjusting line breaks and formatting.
- Ensured consistent handling of the 'stakingProvider' variable for improved code maintainability.
… function

- Changed the beneficiary retrieval logic in the withdrawRewards function to use the current authorization source, improving accuracy in reward distribution.
- This change ensures that the correct beneficiary is identified based on the latest authorization context.
…test

The "NOT MIGRATED Touchpoints" describe block in
WalletRegistry.Authorization.test.ts asserted that withdrawRewards
retained TokenStaking beneficiary lookup post-initializeV2. With
withdrawRewards now routed through _currentAuthorizationSource(),
that invariant no longer holds. The test still passed because it
never invoked withdrawRewards -- it only read staking.rolesOf and
walletRegistry.allowlist() -- but its name, rationale comment, and
block-level documentation advertised behavior the code no longer
exhibits and would mislead future maintainers.

Positive coverage for post-upgrade Allowlist routing lives in
WalletRegistry.Rewards.test.ts ("withdrawRewards when allowlist !=
address(0)"). The top-of-file coverage summary is updated so the
remaining "NOT MIGRATED touchpoints" line continues to reflect the
still-valid slashing path (challengeDkgResult) without the removed
beneficiary claim.
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