Skip to content

feat(analytics): build protocol-wide analytics dashboard - #241

Closed
mijinummi wants to merge 1 commit into
JointSave-org:mainfrom
mijinummi:feat/protocol-analytics-dashboard-204
Closed

mijinummi wants to merge 1 commit into
JointSave-org:mainfrom
mijinummi:feat/protocol-analytics-dashboard-204

Conversation

@mijinummi

Copy link
Copy Markdown
Contributor

[Feature] Build a Protocol-Wide Analytics Dashboard #204

Summary

Closes #204

Implemented a protocol-wide analytics dashboard that provides a centralized view of key protocol metrics, including Total Value Locked (TVL), active pools, member growth, and transaction volume.

The dashboard is designed to give users and protocol stakeholders a clear overview of protocol activity and growth through concise metrics and visual analytics.

What Was Implemented

📊 Protocol Metrics

  • Added Total Value Locked (TVL) tracking to provide visibility into the total value secured across the protocol.
  • Added Active Pools metrics to show the number of currently active liquidity/pool instances.
  • Added Member Growth analytics to track protocol membership and growth over time.
  • Added Transaction Volume metrics to provide visibility into protocol transaction activity.

📈 Analytics Dashboard

  • Built a dedicated protocol-wide analytics dashboard.
  • Added summary/statistic cards for key protocol KPIs.
  • Added visual representations of historical and/or aggregated protocol activity where applicable.
  • Structured the dashboard to make protocol performance and growth easy to understand at a glance.
  • Ensured the dashboard is responsive across different screen sizes.

Technical Implementation

  • Integrated the dashboard with the existing application data flow and analytics infrastructure.
  • Added the required data aggregation and transformation logic for the supported protocol metrics.
  • Ensured analytics values are presented consistently across the dashboard.
  • Reused existing application components and patterns where appropriate to maintain consistency and reduce duplication.

Testing & Validation

The implementation has been:

  • ✅ Fully implemented
  • ✅ Successfully built/run
  • ✅ Manually tested
  • ✅ Verified against the expected dashboard behavior
  • ✅ Checked for responsive layout behavior
  • ✅ Validated that the required protocol metrics are displayed correctly

Expected Outcome

This feature provides a single, protocol-wide view of important growth and activity indicators, making it easier to:

  • Monitor protocol health and adoption.
  • Understand TVL and pool activity.
  • Track member growth.
  • Analyze transaction activity and volume.
  • Identify trends and changes in protocol usage.

Related Issue

Closes/Addresses #204 — [Feature] Build a protocol-wide analytics dashboard showing TVL, active pools, member growth, and transaction volume.

Status

Complete and ready for review.

@Sendi0011

Copy link
Copy Markdown
Contributor

Hey @mijinummi, two CI checks are failing:

  1. Component tests — __tests__/pool.test.ts:1 imports matchstick-as/assembly/index which is a Subgraph/AssemblyScript testing library. This doesn't work in a Vitest/React environment. You'll need to rewrite those tests using Vitest + React Testing Library.
  2. Lint (ESLint) — app/api/v1/protocol/summary/route.ts:40 has a no-explicit-any error. Replace the any type with a proper type.

Please fix both and push an update.

@mijinummi

Copy link
Copy Markdown
Contributor Author

Alright sir @Sendi0011 , on it

@Sendi0011

Copy link
Copy Markdown
Contributor

Superseded by #270 — adopted into org repo, test moved to subgraph/tests/, lint and test placement failures fixed. Thanks @mijinummi for the original implementation!

@Sendi0011 Sendi0011 closed this Sep 15, 2026
Sendi0011 added a commit that referenced this pull request Sep 15, 2026
 #241) (#270)

* feat(analytics): build protocol-wide analytics dashboard

* feat(analytics): adopt protocol analytics dashboard (#241) and fix lint + test placement

Adopts mijinummi's protocol analytics dashboard (API route + Dashboard component)
and the subgraph scaffolding (The Graph protocol indexer). Fixes two CI failures:

1. frontend/__tests__/pool.test.ts imported matchstick-as (a subgraph test
   framework not in frontend's deps) — moved to subgraph/tests/pool.test.ts
   where Graph projects expect matchstick tests to live. This also removes
   it from vitest's test roots (__tests__/).
2. prefer-const (5) and no-explicit-any (1) lint errors in pool.test.ts and
   route.ts fixed; route.ts error: any replaced with instanceof Error check.
3. Prettier run on route.ts and Dashboard.tsx.

---------

Co-authored-by: mijinummi <tech.md.auwal@gmail.com>
Co-authored-by: Sendi0011 <sendi0011@users.noreply.github.com>
Sendi0011 added a commit that referenced this pull request Oct 16, 2026
* feat(analytics): build protocol-wide analytics dashboard

* feat(analytics): adopt protocol analytics dashboard (#241) and fix lint + test placement

Adopts mijinummi's protocol analytics dashboard (API route + Dashboard component)
and the subgraph scaffolding (The Graph protocol indexer). Fixes two CI failures:

1. frontend/__tests__/pool.test.ts imported matchstick-as (a subgraph test
   framework not in frontend's deps) — moved to subgraph/tests/pool.test.ts
   where Graph projects expect matchstick tests to live. This also removes
   it from vitest's test roots (__tests__/).
2. prefer-const (5) and no-explicit-any (1) lint errors in pool.test.ts and
   route.ts fixed; route.ts error: any replaced with instanceof Error check.
3. Prettier run on route.ts and Dashboard.tsx.

* docs: add yield allocation design spec

Specifies a vault-agnostic adapter interface, a test mock vault, pool-side
shared accounting with a liquidity buffer, and a governance flow that reuses
the existing Custom proposal type so no enum or stored-proposal schema changes.
Documents custody, share-value, and illiquidity risks.

* feat(contract): add vault adapter interface for yield allocation

Introduces the jointsave-yield-vault crate with the VaultAdapter trait
(deposit, withdraw, share_price, max_redeemable, total_shares,
total_assets), a shared VaultError enum, yield-allocation events, and the
SHARE_SCALE / liquidity-buffer constants. The pool will depend only on this
interface, so any vault implementation can be plugged in.

* feat(contract): add mock yield vault for tests

Implements MockVault as a self-contained VaultAdapter: 1:1 first deposit,
live share price from its token balance, floor-rounded withdrawals, and a
set_locked_assets admin control to simulate illiquidity deterministically.
Includes unit tests and a CI wasm build step.

* feat(contract): route yield allocation proposals through governance

Extends the Custom proposal dispatcher: a Custom proposal carrying an
'action' parameter (alloc/dealloc) is forwarded via CPI to the pool's
apply_yield_allocation / apply_yield_deallocation entrypoints, using the
existing i128 param encoding and a strkey vault parameter. Proposals without
an 'action' parameter keep the previous behaviour, so the closed ProposalType
enum and stored proposal schema are unchanged. Adds mock-pool tests.

* feat(contract): allocate idle pot capital into a yield vault

Adds apply_yield_allocation (admin or governance only) which moves idle
capital into a vault implementing the adapter, tracks the pool's shares and
cost basis, and enforces a configurable liquidity buffer (default 20%) so the
pot always keeps enough liquid for withdrawals. Adds set_yield_buffer and
read-only views. The yield-vault mock is feature-gated so it is not linked
into the pool's wasm.

* feat(contract): add vault de-allocation and buffer-safe withdrawals

Adds apply_yield_deallocation (admin, governance, or any member) which
redeems shares and degrades gracefully to a partial recovery when the vault
is illiquid, removing proportional cost basis. Withdrawals now pull the
shortfall back from the vault automatically and only revert with a clear
'vault illiquid' error when the pot is genuinely short, so member funds are
never trapped. Adds set_yield_locked emergency mode.

* feat(contract): realise and distribute vault yield pro-rata

Adds sync_yield (admin, governance, or any member) which values the pool's
vault position at the live share price, credits any gain to members pro-rata
by principal balance using floor division, and advances the cost basis by
exactly what was credited so the rounding remainder stays in the pot as
still-unrealised yield. Adds yield_position and unrealised_yield views.

* test(contract): add yield allocation edge-case tests

Covers illiquidity (partial de-allocation, locked vaults, withdraw panic path),
buffer enforcement (zero buffer), rounding and zero-amount rejections, paused
pool behavior, and the governance Custom dispatch paths (double-vote/unauthorized
already covered). All existing and new tests pass.

* feat(frontend): add yield allocation bindings and hooks

Extends useJointSaveContracts with fetchYieldAllocationState and hooks to
apply allocation, deallocate, sync yield, set buffer, and set lock on the
flexible pool. Mirrors existing contract interaction patterns with loading
state and proper argument encoding.

* feat(frontend): add yield allocation service layer and data hook

Adds framework-free helpers (buffer/max-allocatable/share-price/unrealised
gain) mirroring the contract invariants with unit tests, plus useYieldAllocation
which loads the on-chain position and exposes apply/deallocate/sync/buffer/lock
actions that refetch after each mutation.

* feat(frontend): create yield allocation proposals

Extends the create-proposal dialog with an Allocate/De-allocate option for
flexible pools that encodes a Custom governance proposal carrying action,
vault and amount parameters (16-byte BE i128), matching the contract's
dispatch_custom routing. Adds pure param-encoding helpers with unit tests
and en/es copy.

* feat(frontend): show yield allocation details in voting UI

Parses proposal parameters out of the on-chain map and renders the decoded
action, amount and vault on each yield proposal card so members know what
they are voting on. Unifies the duplicate GovernanceProposal types onto
lib/governance as a single source of truth and adds decode/format helpers
with unit tests.

* feat(frontend): extend yield dashboard with vault allocation

Adds a vault-allocation section to the flexible-pool yield dashboard showing
the position value, unrealised yield, share price, liquidity buffer and
available-to-allocate, plus controls to allocate, de-allocate, sync yield and
toggle the vault lock. Reuses the useYieldAllocation hook with loading/error/
empty states and adds en/es copy.

* feat(frontend): surface illiquidity states in withdraw flow

Adds an in-UI banner for flexible pools when the yield vault is locked with
allocated shares, warns about withdrawal limits, and updates the withdraw
hint to reflect automatic on-chain de-allocation from vaults. Fetches yield
state to detect illiquidity.

* test(frontend): add yield dashboard and vote card tests

Add manual-mock exports for the yield allocation hooks so the
group-actions component test can render the extended withdraw flow,
and cover the vault allocation dashboard section plus the yield
proposal details in the voting UI.

* docs: document vault-backed yield allocation

Add a threat model for the vault-backed yield feature, document the
mock vault and its deployment in the smart-contract README, extend
deploy.sh to build/upload/deploy/initialize the mock vault and record
its wasm hash and contract id, and reference the feature from the
root README.

* test(contract): silence clippy unused-variable warnings

The CI clippy job runs with --all-targets, which lints test code too and
rejected two bindings that are only used for their side effects in the
yield allocation edge-case tests.

---------

Co-authored-by: mijinummi <tech.md.auwal@gmail.com>
Co-authored-by: Sendi0011 <sendi0011@users.noreply.github.com>
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.

[Feature] Build a protocol-wide analytics dashboard showing TVL, active pools, member growth, and transaction volume

2 participants