Skip to content

CIP-104 rewards-accounting walkthrough script - #70

Open
pepebndc wants to merge 4 commits into
mainfrom
feat/cip0104-rewards-walkthrough
Open

CIP-104 rewards-accounting walkthrough script#70
pepebndc wants to merge 4 commits into
mainfrom
feat/cip0104-rewards-walkthrough

Conversation

@pepebndc

@pepebndc pepebndc commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

What

Two artifacts telling the same CIP-0104 rewards-accounting story, one on each side of the ledger boundary:

1. A narrated on-ledger walkthrough (Cip0104RewardsWalkthrough.daml) adds test_cip0104_rewardsAccountingWalkthrough, a step-by-step script showing:

  • which functions an integrator calls: mint (ToyHolding create), SettlementFactory_CreateAllocationInstruction + AllocationInstruction_Accept per side, SettlementFactory_SettleBatch by the app-provider executor;
  • balances and accumulated rewards before/after each action: every step logs issuer-view balances, the app-provider's attributed activity (settlements, settled volume, holdings-change events) derived purely from SettlementReceipt + SettlementEventLogEntry queries, and an illustrative accrued reward;
  • that only confirmed executor activity accrues: a non-executor's settle attempt fails and the counters do not move (and alice's spendable balance visibly dips while her holding is locked in the pending allocation);
  • round-close distribution: the accrued reward is split across declared beneficiaries (venue 0.7 / instrument registrar 0.2 / validator operator 0.1), shares conserve the total.

Registered in the LocalNet gate (scripts/localnet-cip-interop-validation.sh, now 12 scripts) with the CIP-0104 row updated in LOCALNET.md.

2. A fully off-chain client (app-rewards/harness.mjs + README) that consumes the settlement surface the way real CIP-0104 reward infrastructure would: a Node harness driving mint, allocation, and settlement over the JSON Ledger API v2 (factory handed to the executor as a disclosed contract), deriving attribution and the accrued reward purely from Ledger API reads. It replays the same six steps and asserts the same numbers as the Daml walkthrough, so the on-ledger executable spec and the off-chain consumer stay in lockstep. Launched by scripts/localnet-cip0104-rewards-walkthrough.sh (wallclock sandbox, no deadline, mirrors the wallet-gateway gate's structure).

In both artifacts the reward math is clearly-labeled illustrative stand-ins for CIP-0104's off-ledger traffic-proportional CC calculation (deferred to M2, per the DEX reference architecture section 6.2), and no reward-marker templates are introduced, preserving the exemplar's core CIP-0104 property.

Why

The existing Cip0104AppRewards scripts prove the structural properties but do not narrate how rewards are distributed and accounted for. The walkthrough pair gives integrators both the ledger-side spec and a concrete off-chain consumer of it (coordinated with Ionut).

Validation

dpm build --all                                    # compiles
scripts/check-lint.sh                              # no hints
scripts/check-docs.sh                              # 308 local links OK
cd experiments/interoperability/cip-exemplar && dpm test   # 15/15 scripts pass
scripts/localnet-cip-interop-validation.sh         # 12/12 on a static-time Canton sandbox (2026-08-07, SDK 3.4.11)
scripts/localnet-cip0104-rewards-walkthrough.sh    # off-chain harness passes, numbers match the Daml walkthrough

Sample narrative (identical from both artifacts):

== step 1: app settled alice -> bob 30 USD ==
balances (issuer view): alice=70 USD, bob=30 USD, totalSupply=100 USD
attribution (app view): settlements=1, settledVolume=30 USD, holdingsChangeEvents=2
accrued reward (illustrative): 0.3 CC
...
== step 5: round closes, reward distributed (illustrative) ==
venue (app-provider): 0.42 CC
instrument registrar: 0.12 CC
validator operator: 0.06 CC

🤖 Generated with Claude Code

pepebndc and others added 4 commits August 7, 2026 11:46
Adds Cip0104RewardsWalkthrough.daml to the interop exemplar: a step-by-step
script showing which settlement functions an integrator calls, balances and
accumulated attributable activity before/after each action, that failed
non-executor settles accrue nothing, and an illustrative round-close reward
distribution across beneficiaries. All reward math is off-ledger Daml Script
computation over SettlementReceipt and SettlementEventLogEntry queries; no
reward-marker templates are introduced.

Registers the script in the LocalNet gate (now 12 scripts) and updates the
LOCALNET.md scenario row.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…SON Ledger API

Adds experiments/interoperability/app-rewards/harness.mjs, a Node client that
consumes the CIP-0112 settlement surface the way real CIP-0104 reward
infrastructure would: mint, allocation, and settlement driven over the JSON
Ledger API v2 (factory passed as a disclosed contract), with attribution and
the illustrative accrued reward derived purely from Ledger API reads of
SettlementReceipt and SettlementEventLogEntry. It replays the same six steps
and asserts the same numbers as Cip0104RewardsWalkthrough.daml so the two
artifacts stay in lockstep.

scripts/localnet-cip0104-rewards-walkthrough.sh boots a wallclock sandbox with
the JSON API enabled, runs the harness, and tears down.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…d Technical English

Rewrites all prose in the PR's files to follow ASD-STE100 style: short
sentences, one idea per sentence, active voice, present tense, no idioms.
Code and log output stay unchanged.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sends the dpm build output to a log file, removes the job-control
Terminated message at teardown, and shows only the error code for the
expected step-3 rejection.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@pepebndc
pepebndc marked this pull request as ready for review August 7, 2026 10:36
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