Skip to content

Dynamic dispatch example#31

Open
mohammadfawaz wants to merge 1 commit into
mainfrom
mohammadfawaz/dynamic_dispatch
Open

Dynamic dispatch example#31
mohammadfawaz wants to merge 1 commit into
mainfrom
mohammadfawaz/dynamic_dispatch

Conversation

@mohammadfawaz

@mohammadfawaz mohammadfawaz commented Mar 30, 2026

Copy link
Copy Markdown
Collaborator

Adds a dynamic dispatch example demonstrating two related Leo 4 features: interfaces and runtime program routing.

What's in the example

Three programs that together implement a pluggable governance voting system:

  • voting_power.aleo — Declares the VotingStrategy interface and provides the linear implementation (1 token = 1 vote)
  • quadratic_power.aleo — Implements the same interface with floor(√balance) voting power, reducing whale influence
  • governance.aleo — Dispatch hub that accepts a strategy identifier at runtime and routes calls to whichever program the caller names, with no redeployment needed

Features showcased

  • Interfaces as compile-time contracts — each program re-declares VotingStrategy and Leo verifies the signatures match
  • Dynamic dispatch via VotingStrategy@(strategy)::compute_power(balance) — the identifier type resolves the target program at runtime
  • Identifier literals ('voting_power', 'quadratic_power') for compile-time-known dispatch targets

How to run

run.sh handles the full flow: local execution of each strategy individually (no devnode needed), then deployment of all three programs and dynamic dispatch calls showing diverging outcomes under linear vs quadratic voting. Requires leo devnode running in a separate terminal.

🤖 Generated with Claude Code

@mohammadfawaz mohammadfawaz force-pushed the mohammadfawaz/dynamic_dispatch branch from d4b3df1 to 0e1f71c Compare March 30, 2026 16:11
@mohammadfawaz mohammadfawaz force-pushed the mohammadfawaz/dynamic_dispatch branch from 0e1f71c to 0dce7ca Compare April 16, 2026 14:58
@mohammadfawaz mohammadfawaz marked this pull request as ready for review April 16, 2026 14:58
@mohammadfawaz mohammadfawaz self-assigned this Apr 16, 2026
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