Skip to content

feat: add streaming dividends example (DividendTreasury + StreamingShare) - #59

Draft
tiero wants to merge 1 commit into
masterfrom
claude/streaming-dividends-6ftipe
Draft

feat: add streaming dividends example (DividendTreasury + StreamingShare)#59
tiero wants to merge 1 commit into
masterfrom
claude/streaming-dividends-6ftipe

Conversation

@tiero

@tiero tiero commented Jul 25, 2026

Copy link
Copy Markdown
Member

Summary

Adds a complete streaming-dividend program demonstrating continuous per-second accrual of fixed USD-cent dividends paid in sats at an oracle-attested BTC/USD price. The program consists of two covenants that co-spend in claim transactions: DividendTreasury (singleton reserve) and StreamingShare (per-holder position).

Key Changes

  • New contracts:

    • examples/dividend_stream/dividend_treasury.ark — issuer-funded reserve with topUp (permissionless), service (permissionless claim servicing), recall (issuer-gated withdrawal), and CSV unilateral exit
    • examples/dividend_stream/streaming_share.ark — per-holder position with claim (holder-signed dividend settlement), transfer (key swap), split (accrual-fair division), and CSV unilateral exit
    • examples/dividend_stream/dividend_stream.md — design documentation covering accrual mechanics, claim transaction layout, oracle model, trust model, and relation to other examples
  • New test suite (tests/examples/dividend_stream.rs):

    • Compilation and function count assertions
    • Oracle verification and cross-input introspection validation (OP_CHECKSIGFROMSTACK, OP_CAT, OP_SHA256, OP_PUSHCURRENTINPUTINDEX)
    • Accrual math verification (OP_DIV64, OP_MUL64, seconds-per-year constant)
    • Permission model checks (topUp permissionless, service oracle-only, recall issuer-gated, claim holder-signed)
    • Position basis advancement and payout routing
    • Dust floor enforcement (330 sats)
    • Unilateral exit structure (CSV tapscripts)
    • Cooperative leaf synthesis
    • Constructor schema alignment between treasury and share
  • Integration test updates (tests/examples/compilation_roundtrip.rs): roundtrip compilation tests for both contracts

  • Playground registration (playground/main.js): dividend_stream project with name and description

  • Test module registration (tests/examples.rs): dividend_stream module added to the suite

Implementation Details

The program demonstrates several Arkade patterns:

  • Two-contract co-spend: service and claim functions in separate contracts verify each other's scriptPubKey via witness-declared state
  • Oracle integration: Fuji-style signed price feed (sha256(ticker || price || time)) with freshness bounds (600 seconds)
  • Per-second accrual: Uses tx.offchainTime for one-second granularity; accrual formula: units × annualDividendCents × elapsed / 31536000
  • Record-date elimination: transfer and split preserve lastClaim, so accrued-but-unclaimed dividends travel with the position
  • Dust handling: 330-sat minimum enforced on all outputs; zero-payout claims blocked by accruedCents > 0 guard
  • Unilateral exits: Both contracts include CSV-gated tapscript leaves for operator offline recovery
  • Cooperative signing: Covenant functions synthesize default collaborative leaves with server and emulator keys

The test suite validates the complete specification: oracle attestation paths, accrual math bounds, permission gates, position state advancement, and output routing. Full cargo test green (357 tests), cargo fmt --check clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CmsjJ5rEDp6DE42kvauYD2


Generated by Claude Code

Add examples/dividend_stream/: a two-contract corporate dividend rail
where the dividend accrues continuously at one-second granularity
(tx.offchainTime), fixed in USD cents per unit-year, paid in sats at an
oracle-attested BTC/USD price. Motivated by a hypothetical pilot for a
listed Bitcoin treasury company: batch dividend rails cap ambition at
monthly payouts and need record dates, transfer agents and distribution
runs; continuous accrual removes the batch entirely (see
dividend_stream.md).

- DividendTreasury: singleton BTC reserve. Permissionless topUp
  (reserve only grows — public recurring-cash-flow time series),
  permissionless service of one claim per co-spend (recomputes accrual,
  pays the holder, and requires the position re-created with
  lastClaim = now so the same second is never paid twice),
  issuer-gated recall, CSV unilateral exit.
- StreamingShare: per-holder position (units, lastClaim). claim
  co-spends the treasury (cross-input scriptPubKey binding via
  this.activeInputIndex, bonds-style); transfer is a pure key swap that
  carries accrual with the position (no ex-dividend cliff, no record
  date); split keeps lastClaim so it is exactly accrual-fair; CSV
  unilateral exit.
- Accrual: units × annualDividendCents × elapsed / 31536000, int64-safe
  for realistic sizes; accruedCents > 0 guards basis-advance griefing;
  330-sat dust floor on claims.
- Tests: 13 behavioral tests (oracle message reconstruction, cross-input
  inspection, permissionless topUp/service, issuer-gated recall,
  key-swap purity, basis-advance recreation placeholders, CSV exits,
  synthesized cooperative leaves, shared constructor schema) + 2
  roundtrip entries. Full suite green, cargo fmt clean.
- Playground: Streaming Dividends project registered in main.js.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CmsjJ5rEDp6DE42kvauYD2
@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 666470f7-299a-47f7-ba94-9fbcf504540e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/streaming-dividends-6ftipe

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

Playground Preview

A live preview of this PR's playground is available at:
https://arkade-os.github.io/compiler/pr-previews/pr-59/

Built from commit ddd723486f5f4d14c008d517d95e0c97c33979c2 · Workflow run

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.

2 participants