Skip to content

Feature/0.1.33 events#78

Merged
jorgecuesta merged 5 commits into
mainfrom
feature/0.1.33-events
Apr 20, 2026
Merged

Feature/0.1.33 events#78
jorgecuesta merged 5 commits into
mainfrom
feature/0.1.33-events

Conversation

@Alann27

@Alann27 Alann27 commented Mar 25, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add settlement aggregation fields to EventClaimSettled (settled/minted/overservicing/deflation amounts, mint ratio, supplier owner)
  • Add optional fields to EventApplicationOverserviced (service, session end block height, spend limit exceeded)
  • Extend SettlementOpReason enum with new relay burn-equals-mint and global mint TLM distribution reasons
  • Fix burns/mints derivation for reward_distribution_detailed path by reading values directly from chain op_reason entries instead of broken math
  • Handle EventSettlementBatch to save batched validator/delegator rewards as ModToAcctTransfer records
  • Refactor _handleEventClaimSettled into smaller, focused functions

Detail

schema.graphql:

  • Add settlement aggregation fields to EventClaimSettled: settledAmount, settledDenom, mintRatio, supplierOwner, mintedAmount, mintedDenom, overservicingLossAmount, overservicingLossDenom, deflationLossAmount, deflationLossDenom
  • Add optional fields to EventApplicationOverserviced: service, sessionEndBlockHeight, spendLimitExceeded
  • Extend SettlementOpReason enum with relay burn-equals-mint and global mint TLM distribution reasons (DAO, source owner, application, validator, delegator, tokenomics mint)

proto/pocket/tokenomics/event.proto:

  • Add proto definitions for new settlement aggregation event attributes
  • Add RewardDistributionDetail message
  • Add EventSettlementBatch message

src/mappings/pocket/relays.ts:

  • Parse new event attributes: reward_distribution_detailed, settled_upokt, minted_upokt, mint_ratio, supplier_owner_address, overservicing_loss_upokt, deflation_loss_upokt, num_estimated_relays
  • Refactor _handleEventClaimSettled into smaller functions:
    • _resolveSettlementParts
    • _buildClaimSettledProps
    • _buildSettlementFromResult
    • _buildSettlementFromDetailedDistribution
    • _buildSettlementFromDistribution
    • _computeNumEstimatedRelays
    • _computeDeflationLoss
    • _computeOverservicingLoss
  • Build burns/mints from chain-provided values and reward_distribution_detailed op_reason entries instead of deriving them mathematically
  • Add handleEventSettlementBatch to save batched validator/delegator rewards as ModToAcctTransfer records

src/mappings/handlers.ts:

  • Wire handleEventSettlementBatch to pocket.tokenomics.EventSettlementBatch

src/mappings/indexer.manager.ts:

  • Subscribe to pocket.tokenomics.EventSettlementBatch event type

project.ts:

  • Register EventSettlementBatch event handler

Issue

The previous implementation derived inflation and reimbursement mint amounts by computing sum(reward_distribution) - (effectiveBurn × mintRatio). This broke at height 153753 (beta) because reward_distribution_detailed excludes proposer/validator rewards (they are batched separately via EventSettlementBatch), making the total less than minted_upokt and producing a negative value.

The fix:

  • Extracts inflation and reimbursement directly from reward_distribution_detailed entries by op_reason (TLM_GLOBAL_MINT_DAO_REWARD_DISTRIBUTION and TLM_GLOBAL_MINT_REIMBURSEMENT_REQUEST_ESCROW_DAO_TRANSFER)
  • Saves the batched validator/delegator rewards from EventSettlementBatch as ModToAcctTransfer records

Type of change

Select one or more:

  • New feature, functionality or library
  • Bug fix
  • Code health or cleanup
  • Documentation
  • Other (specify)

Sanity Checklist

  • I have tested my changes using the available tooling
  • I have commented my code
  • I have performed a self-review of my own code; both comments & source code
  • I create and reference any new tickets, if applicable
  • I have left TODOs throughout the codebase, if applicable

@Alann27 Alann27 requested a review from jorgecuesta March 25, 2026 20:24
@Alann27 Alann27 self-assigned this Mar 25, 2026
@Alann27 Alann27 added bug Something isn't working enhancement New feature or request labels Mar 25, 2026
oten91 and others added 3 commits March 25, 2026 17:05
…ttlementBatch)

Sync proto from poktroll to support new settlement aggregation fields on
EventClaimSettled (settled_upokt, mint_ratio, session_id, supplier_owner,
num_estimated_relays, minted_upokt, overservicing/deflation losses, and
reward_distribution_detailed), new fields on EventApplicationOverserviced
(service_id, session_end_block_height, spend_limit_exceeded), and new
EventSettlementBatch event type. All new schema fields are nullable for
backward compatibility with pre-upgrade blocks.
- Removed `EventSettlementBatch` handler and related schema definitions from codebase.
- Consolidated settlement processing by enhancing `_handleEventClaimSettled` with modular utility functions and optimized computation of settlement components.
- Updated schema to remove unused entities and fields (`rewardDistributionDetailed`, `EventSettlementBatch`).
- Readded `EventSettlementBatch` handler and its integration into the event processing pipeline.
- Improved settlement logic by refining record structure and adding modular components for handling mint, burn, and transfer operations.
- Updated schema and mappings to remove deprecated entities while aligning with new functionality.
- Added validation for essential settlement data (`inflationAmount` and `reimbursementAmount`) with informative failure handling.
@Alann27 Alann27 force-pushed the feature/0.1.33-events branch from a0fb129 to fd62e7d Compare March 25, 2026 21:05
Alann27 added 2 commits March 26, 2026 18:50
- Enhanced `modToAcctTransfers` handling by introducing `summarizeTransfers`.
- Updated logic to perform bulk insert of both raw and summarized transfers for improved data tracking.
…ked suppliers and Support new protocol opReason values for inflation and mint_burn in supply stats
@jorgecuesta jorgecuesta merged commit 78c3d96 into main Apr 20, 2026
3 checks passed
@jorgecuesta jorgecuesta deleted the feature/0.1.33-events branch April 20, 2026 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants