Skip to content

Fix allocated giv value#2305

Merged
kkatusic merged 4 commits intomasterfrom
fix_allocated_giv_value
Mar 12, 2026
Merged

Fix allocated giv value#2305
kkatusic merged 4 commits intomasterfrom
fix_allocated_giv_value

Conversation

@kkatusic
Copy link
Collaborator

@kkatusic kkatusic commented Mar 12, 2026

Summary by CodeRabbit

  • New Features

    • Added RPC trace fallback for more reliable internal transaction retrieval.
  • Bug Fixes

    • Improved GivBack eligibility calculation with enhanced ranking-based factor logic.
    • Strengthened error handling for transaction data retrieval with fallback mechanisms.
  • Chores

    • Expanded CORS whitelist to include additional domain.
    • Refactored donation eligibility logic to use date-window-based calculations.

@kkatusic kkatusic self-assigned this Mar 12, 2026
@kkatusic kkatusic changed the base branch from staging to master March 12, 2026 12:46
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 12, 2026

Caution

Review failed

Failed to post review comments

Walkthrough

This PR removes the powerRound parameter dependency from donation eligibility calculations, replacing it with a date-window-based approach using a 16:00 UTC window for the current month. Tests are updated accordingly. Additionally, the transaction service gains RPC trace fallback logic, and givback factor calculation is refactored with enhanced input validation.

Changes

Cohort / File(s) Summary
Donation Eligibility Refactor
src/repositories/donationRepository.ts, src/repositories/donationRepository.test.ts
Replaced powerRound-based filtering with date-range logic using 16:00 UTC monthly window. Updated function signature (powerRound parameter now unused but preserved). Added tests for donations inside/outside operational window and purple list scenarios. Introduced helper functions for window-based timestamp generation.
Donation Resolver Tests
src/resolvers/donationResolver.test.ts
Updated test cases to use createdAt timestamps within current month window instead of powerRound. Added refreshCache: true to allocatedGivbacksGraphQL queries and validates usdValueSentAmountInPowerRound with computed expectedSum.
Givback Factor Calculation
src/services/givbackService.ts
Extracted ranking-based factor computation into new calculateGivbackFactorByRank() helper. Enhanced environment variable parsing with finitude checks and fallback defaults. Strengthened input validation for bottomRank and projectRank normalization.
Transaction Service Enhancement
src/services/chains/evm/transactionService.ts
Added RPC trace-based internal transaction collector with parseTraceValueToWei, collectValueTransfersFromCallTrace, and getInternalTransactionsByTxHashFromRpcTrace. Implemented fallback mechanism: attempts explorer fetch first, then falls back to RPC trace on failure with enhanced logging.
CORS Configuration
src/server/cors.ts
Added qf.giveth.io to static host whitelist, expanding valid CORS origins.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Service as transactionService
    participant Explorer as Block Explorer
    participant RPC as RPC Node
    
    Client->>Service: getInternalTransactionsByTxHash(txHash)
    Service->>Explorer: Fetch internal transactions
    alt Explorer Success
        Explorer-->>Service: Return transactions
        Service-->>Client: Return results
    else Explorer Failure
        Explorer-->>Service: Error/Timeout
        Service->>RPC: debug_traceTransaction (callTracer)
        RPC-->>Service: Trace data with value transfers
        Service->>Service: parseTraceValueToWei()<br/>collectValueTransfersFromCallTrace()
        Service-->>Client: Return RPC-derived transactions
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • mohammadranjbarz
  • RamRamez
  • ae2079

Poem

🐰 A temporal hop through the gift-giving fields,
Where windows of time now the power yield,
We trace the value when explorers fail,
And factors rank high through every tale! 🎁

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Fix allocated giv value' is vague and does not clearly summarize the main changes across multiple files and systems. Consider a more specific title that describes the key changes, such as 'Refactor giv allocation logic to use date-window based calculations instead of powerRound' or similar to better convey the scope of changes.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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 fix_allocated_giv_value

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.

@kkatusic kkatusic merged commit 4626a38 into master Mar 12, 2026
13 checks passed
@kkatusic kkatusic deleted the fix_allocated_giv_value branch March 12, 2026 13:18
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.

1 participant