Skip to main content

celo-pg

Divvi Protocol - KPI calculation functions


Divvi Protocol - KPI calculation functions / celo-pg

celo-pg

Functions

calculateKpi()

function calculateKpi(params): Promise<KpiResult<string>>

Defined in: celo-pg/index.ts:48

Calculates gas usage for Celo public goods infrastructure activity.

KPI Unit: Gas units (computational units consumed)

Business Purpose: Measures the computational resources (gas) consumed by a specific user's transactions on Celo network. This metric quantifies the infrastructure utilization generated by user interactions and supports gas usage analysis for public goods funding and network sustainability.

Protocol Context: Celo PG (Public Goods) tracks gas consumption to measure network utilization and infrastructure impact. Gas usage serves as a proxy for computational resource consumption and network contribution, supporting public goods funding decisions.

Network: Celo Mainnet

Data Sources:

  • HyperSync: Transaction and gas usage data from Celo network via HyperSync client
  • Block Data: Timestamps via getBlockRange utility for temporal filtering

Business Assumptions:

  • Gas usage accurately represents computational resource consumption
  • User's infrastructure impact is proportional to total gas consumed within time window
  • All transaction types contribute equally to network utilization regardless of purpose
  • Gas measurements include both successful and failed transaction attempts
  • Public goods funding allocation can be based on proportional gas contribution

Gas Types: Transaction execution gas, contract interaction gas, token transfer gas, and smart contract deployment gas

Calculation Method:

  1. Queries all transactions initiated by user wallet within the specified time window
  2. Retrieves transaction receipts to extract gas used for each transaction
  3. Filters transactions by block timestamp to ensure they fall within the time range
  4. Aggregates total gas consumed across all user transactions
  5. Returns total gas usage representing user's infrastructure utilization

Parameters

params

Calculation parameters

address

string

User wallet address to calculate gas usage for

endTimestampExclusive

Date

End of time window for gas calculation (exclusive)

redis?

RedisClientType

startTimestamp

Date

Start of time window for gas calculation (inclusive)

Returns

Promise<KpiResult<string>>

Promise resolving to total gas units consumed by user's transactions