Skip to content

Add revenue pool yield deposit entrypoint - #521

Merged
greatest0fallt1me merged 1 commit into
CalloraOrg:mainfrom
newmattock:issue-484-yield-deposit
Jun 27, 2026
Merged

Add revenue pool yield deposit entrypoint#521
greatest0fallt1me merged 1 commit into
CalloraOrg:mainfrom
newmattock:issue-484-yield-deposit

Conversation

@newmattock

@newmattock newmattock commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add a deposit_yield revenue-pool entrypoint that lets the authorized treasury deposit protocol earnings.
  • Track cumulative deposited yield and emit a yield_deposited event for observability.
  • Cover the entrypoint with unit tests and add operator documentation.

Verification

  • PATH="$HOME/.rustup/toolchains/1.90.0-aarch64-apple-darwin/bin:$PATH" cargo check -p callora-revenue-pool --lib
  • cargo test -p callora-revenue-pool deposit_yield -- --nocapture is currently blocked before running the filtered tests by an existing test_proptest.rs HashSet<Address> compile error.
  • cargo fmt --package callora-revenue-pool -- --check is currently blocked by an existing formatting issue in test_proptest.rs.

CI note

  • Current red CI is caused by existing workspace formatting/proptest failures.
  • The release build also hits the repo's existing 64 KiB vault WASM gate; PR Add contract WASM size budget checks #520 raises the budget to the requested 100 KB check.

Closes #484

@drips-wave

drips-wave Bot commented Jun 27, 2026

Copy link
Copy Markdown

@newmattock Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@greatest0fallt1me
greatest0fallt1me merged commit 263af93 into CalloraOrg:main Jun 27, 2026
0 of 3 checks passed
greatest0fallt1me pushed a commit that referenced this pull request Jun 27, 2026
Two events introduced in recent PRs (#516 admin_broadcast, #521
yield_deposited) were emitted in contracts/revenue_pool/src/lib.rs
without corresponding entries in EVENT_SCHEMA.md, leaving indexers
with no documented shape for these topics.

Changes:
- EVENT_SCHEMA.md: add `yield_deposited` entry (topics: Symbol +
  treasury Address; data: (amount i128, source Symbol,
  cumulative_yield_deposited i128)) under callora-revenue-pool
- EVENT_SCHEMA.md: add `admin_broadcast` entry (topics: Symbol +
  caller Address; data: AdminBroadcast { severity, message }) under
  callora-revenue-pool
- EVENT_SCHEMA.md: add both events to the indexer quick-reference table
- scripts/check-event-shape.sh: new bash gate that extracts all
  events::event_*(&env) call sites from lib.rs and verifies each has a
  matching ### heading in the revenue-pool section of EVENT_SCHEMA.md;
  exits 1 on mismatch
- .github/workflows/ci.yml: new `event-shape` job that runs the gate on
  every push and PR

Schema is the source of truth; no Rust code was changed.

Closes #508
ola196 added a commit to ola196/Callora-Contracts that referenced this pull request Jun 28, 2026
* test: cross-contract conservation invariant

* feat(vault): add Kani harness for transfer correctness + fix compile errors

Closes CalloraOrg#490

## Compilation fixes
- Fix StorageKey::MetaKey → StorageKey::Meta (5 occurrences in lib.rs)
- Add missing get_max_deduct() method to CalloraVault
- Add #[allow(dead_code)] to orphaned migrate() helper

## Correctness fixes
- deduct(): add require_not_paused() check (deposit/batch_deduct already had it)
- deposit event: add caller Address as topic[1] to match EVENT_SCHEMA.md (2 topics)

## Test fixes
- deduct_while_paused_succeeds → deduct_while_paused_fails (#[should_panic])
- batch_deduct_while_paused_succeeds → batch_deduct_while_paused_fails (#[should_panic])
- deposit_event_schema_alignment: update to assert 2 topics + caller address
- owner_deposit_increases_balance_and_emits_event: same update
- owner_can_deposit: unwrap on topic[1] now resolves correctly
- fuzz tests: remove duplicate else-branch that caused parse error
- settlement/test.rs: fix _third_party → third_party in setup_contract()
- Fix unused variable warnings (settlement, step_cap)

## Kani formal verification (closes CalloraOrg#490)
Add contracts/vault/src/kani_proofs.rs with 7 adversarial harnesses:
  1. kani_deduct_balance_non_negative  – balance ≥ 0 after any valid deduct
  2. kani_deduct_strictly_reduces_balance – deduct always decreases balance
  3. kani_deposit_no_overflow          – deposit checked_add succeeds in-range
  4. kani_deposit_overflow_detected    – checked_add returns None on overflow
  5. kani_max_deduct_enforced          – amount > max_deduct rejected before mutation
  6. kani_batch_deduct_total_no_overflow – batch total accumulation stays valid
  7. kani_withdraw_balance_non_negative – withdraw mirrors deduct invariant

Harnesses compile only under cfg(kani); normal cargo test/CI unaffected.
Vault Cargo.toml declares cfg(kani) as a known check-cfg to silence rustc warning.

## CI status
- cargo fmt --check: ✅
- cargo clippy -D warnings: ✅
- cargo test --workspace: ✅ (270 tests: 179 vault + 52 settlement + 39 revenue-pool)

* fix: Unicode normalization on metadata

* feat: admin migrate_developer_balance with timelock

* feat: per-token settlement balances

Track balances per (developer, token) tuple instead of single-token.
Add migration helper for legacy DeveloperBalanceV1 entries.
All receive_payment, withdraw, batch, and view functions accept
a token parameter. Vault contract updated to pass token.

Closes CalloraOrg#495

* fix: revenue_pool event shape vs schema

Two events introduced in recent PRs (CalloraOrg#516 admin_broadcast, CalloraOrg#521
yield_deposited) were emitted in contracts/revenue_pool/src/lib.rs
without corresponding entries in EVENT_SCHEMA.md, leaving indexers
with no documented shape for these topics.

Changes:
- EVENT_SCHEMA.md: add `yield_deposited` entry (topics: Symbol +
  treasury Address; data: (amount i128, source Symbol,
  cumulative_yield_deposited i128)) under callora-revenue-pool
- EVENT_SCHEMA.md: add `admin_broadcast` entry (topics: Symbol +
  caller Address; data: AdminBroadcast { severity, message }) under
  callora-revenue-pool
- EVENT_SCHEMA.md: add both events to the indexer quick-reference table
- scripts/check-event-shape.sh: new bash gate that extracts all
  events::event_*(&env) call sites from lib.rs and verifies each has a
  matching ### heading in the revenue-pool section of EVENT_SCHEMA.md;
  exits 1 on mismatch
- .github/workflows/ci.yml: new `event-shape` job that runs the gate on
  every push and PR

Schema is the source of truth; no Rust code was changed.

Closes CalloraOrg#508

* fix: document remaining 3 undocumented revenue_pool events (pause_set, admin_cancelled, upgraded)

* feat: on-chain per-developer rate-limit on vault.deduct

* feat: revenue_pool pause guardian

* test(settlement): add full struct snapshot tests for PaymentReceivedEvent

- Add test_payment_received_event_snapshot_to_pool: asserts the complete
  PaymentReceivedEvent struct (from_vault, amount, to_pool, developer) in
  a single assert_eq! for the to_pool=true branch
- Add test_payment_received_event_snapshot_to_developer: same full-struct
  assertion for the to_pool=false / developer branch
- These complement the existing field-by-field event shape tests by
  catching any future change to the event's structure or values in one
  comparison, rather than requiring each field to be checked individually

Note: contracts/settlement currently has 34 pre-existing compile errors
on main (missing Severity/AdminBroadcast types in lib.rs, argument
mismatches in unrelated withdraw_developer_balance tests, missing Box
imports in test_invariant.rs) that block cargo test from running. These
are unrelated to this change and were verified to exist on main prior to
this branch via git stash comparison. This PR does not attempt to fix
them as they are out of scope for this issue.

Closes CalloraOrg#491

* feat: settlement V1->V2 migration

* feat: storage TTL doctor script

* feat: snapshot diff helper

* feat: paginated developer balance view

* feat: settlement OverDraft variant

Add SettlementError::OverDraft = 23 to distinguish overdraft attempts
(withdrawal amount > developer balance) from other insufficient-balance
conditions. Replace InsufficientDeveloperBalance in
withdraw_developer_balance with OverDraft.

- errors.rs: add OverDraft = 23 variant with doc comment
- lib.rs: return OverDraft instead of InsufficientDeveloperBalance
- test_error_codes.rs: add mapping + doc line assertion for OverDraft
- docs/ERROR_CODES.md: add row 23 to Settlement table

Closes CalloraOrg#531

* feat(settlement): add per-developer minimum balance threshold and admin setter

* feat: per-developer claim window

* feat: per-tx max deduct

- Extract DEFAULT_MAX_DEDUCT constant and check_max_deduct() helper into
  contracts/vault/src/limits.rs for clear separation of cap logic
- Re-export from lib.rs (pub mod limits; pub use limits::{...})
- Replace inline if-checks in deduct() and batch_deduct() with check_max_deduct()
- Add focused unit tests in test_limits.rs (7 tests: default value, at/below/above
  cap, edge cases)
- Update docs/interfaces/vault.json: improve get_max_deduct description, add
  missing set_max_deduct entry with params, errors, and event docs

Closes CalloraOrg#538

---------

Co-authored-by: wavyboy-build <waveboy829@gmail.com>
Co-authored-by: ZuLu0890 <ayodelepraise2000@gmail.com>
Co-authored-by: Jerry-Tekh <Jerry-Tekh@users.noreply.github.com>
Co-authored-by: Songu3020 <petersongu2000@gmail.com>
Co-authored-by: juchechu <maxjerry242@gmail.com>
Co-authored-by: gaiabio12-design <263269140+gaiabio12-design@users.noreply.github.com>
Co-authored-by: Stephan-Thomas <xevermontes8@gmail.com>
Co-authored-by: greatest0fallt1me <1nonlygem@gmail.com>
Co-authored-by: Oba <republicoba1@gmail.com>
Co-authored-by: Samuel Ojetunde <samuelojetunde898@gmail.com>
Co-authored-by: Deyanju23 <opehalimahadeyanju@gmail.com>
Co-authored-by: TechSis <136842950+Deyanju23@users.noreply.github.com>
Co-authored-by: NEA DEV <nwaforebuka12@gmail.com>
Co-authored-by: dominiccreates <dominiccreatess@gmail.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.

Add revenue-pool yield deposit endpoint for protocol earnings

2 participants