Skip to main content

Metrics

Pre-built aggregation functions that combine multiple on-chain reads into meaningful reports. Import from @oaknetwork/contracts-sdk/metrics.

Entry point

Metrics helpers are exported from @oaknetwork/contracts-sdk/metrics only — they are not re-exported from the root @oaknetwork/contracts-sdk barrel.

Platform Stats

Protocol-level statistics from GlobalParams:

import { getPlatformStats } from '@oaknetwork/contracts-sdk/metrics';

const stats = await getPlatformStats({
globalParamsAddress: '0x...',
publicClient: oak.publicClient,
});

console.log(`${stats.platformCount} platforms enlisted`);
console.log(`Protocol fee: ${stats.protocolFeePercent} bps`);

Return shape

FieldTypeDescription
platformCountbigintNumber of platforms currently enlisted
protocolFeePercentbigintProtocol fee in basis points (100 = 1%)

Campaign Summary

Financial aggregation from a deployed CampaignInfo contract:

import { getCampaignSummary } from '@oaknetwork/contracts-sdk/metrics';

const summary = await getCampaignSummary({
campaignInfoAddress: '0x...',
publicClient: oak.publicClient,
});

console.log(`Total raised: ${summary.totalRaised}`);
console.log(`Goal: ${summary.goalAmount}`);
console.log(`Goal reached: ${summary.goalReached}`);
console.log(`Refunded: ${summary.totalRefunded}`);

Return shape

FieldTypeDescription
totalRaisedbigintTotal amount raised across all treasuries
goalAmountbigintCampaign funding goal
goalReachedbooleanWhether totalRaised >= goalAmount
totalRefundedbigintTotal amount refunded to backers

Treasury Report

Per-treasury financial report for any treasury type:

import { getTreasuryReport } from '@oaknetwork/contracts-sdk/metrics';

const report = await getTreasuryReport({
treasuryAddress: '0x...',
treasuryType: 'all-or-nothing', // or "keep-whats-raised" | "payment-treasury"
publicClient: oak.publicClient,
});

console.log(`Raised: ${report.raisedAmount}`);
console.log(`Refunded: ${report.refundedAmount}`);
console.log(`Fee: ${report.platformFeePercent} bps`);
console.log(`Cancelled: ${report.cancelled}`);

Return shape

FieldTypeDescription
raisedAmountbigintTotal raised by this treasury
refundedAmountbigintTotal refunded from this treasury
platformFeePercentbigintPlatform fee in basis points
cancelledbooleanWhether the treasury has been cancelled

Supported treasury types

treasuryType valueContract
"all-or-nothing"AllOrNothing treasury
"keep-whats-raised"KeepWhatsRaised treasury
"payment-treasury"PaymentTreasury / TimeConstrainedPaymentTreasury