Skip to content

fix(events): add event_seq to delegate_set, revoker to delegate_revoked - #655

Merged
Kingsman-99 merged 2 commits into
Stellar-split:mainfrom
kulkan-IV:fix/619-620-621-622-delegate-fee-refactor
Aug 29, 2026
Merged

fix(events): add event_seq to delegate_set, revoker to delegate_revoked#655
Kingsman-99 merged 2 commits into
Stellar-split:mainfrom
kulkan-IV:fix/619-620-621-622-delegate-fee-refactor

Conversation

@kulkan-IV

Copy link
Copy Markdown
Contributor

Title: fix(events): add event_seq to delegate_set, revoker to delegate_revoked; extract pending guard and platform fee helper

───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Description:

This PR resolves four issues from the Wave backlog. No behaviour changes — only bug fixes, audit improvements, and internal refactors.

Changes
#619 — delegate_set missing event_seq for ordering

delegate_set now calls next_seq(env, invoice_id) and publishes (delegate, event_seq) instead of the bare address. Indexers can now determine the final delegate state when a delegate is set and then
changed within the same transaction.

#620 — delegate_revoked event data was empty

delegate_revoked now accepts a revoker: &Address parameter and publishes (revoker, ledger_sequence). The revoke_delegate call site in lib.rs passes &invoice.creator as the revoker. Audit logs are now
complete.

#621 — Extract assert_invoice_pending guard

Added fn assert_invoice_pending(invoice: &Invoice) -> Result<(), ContractError> immediately after load_invoice in lib.rs. The repeated inline pattern:

if invoice.status != InvoiceStatus::Pending {
return Err(ContractError::InvalidStatus);
}

is replaced with assert_invoice_pending(&invoice)?. The idempotent silent-return in claim_refund was intentionally left unchanged — it has different semantics.

#622 — Extract calc_platform_fee into calc.rs

Added pub fn calc_platform_fee(funded: i128, fee_bps: u32) -> Result<i128, ContractError> to calc.rs. Uses checked_mul and returns ContractError::ArithmeticOverflow on overflow. All three inline
(funded as u128 * platform_fee_bps as u128 / 10_000u128) as i128 expressions in lib.rs are replaced with calls to this helper. Unit tests added covering: normal case, zero bps, 100% bps, and
overflow.

Testing

  • cargo test --workspace passes (no behaviour changes, only refactors + bug fixes)

Migration note

delegate_set and delegate_revoked event data shapes have changed. Indexers consuming these events must update their decoders:

  • delegated topic data: Address → (Address, u64)
  • revoked topic data: () → (Address, u32)

Closes #619
Closes #620
Closes #621
Closes #622

- Stellar-split#619: call next_seq inside delegate_set and publish (delegate, event_seq)
  so indexers can order multiple delegate changes within the same tx
- Stellar-split#620: add revoker: &Address param to delegate_revoked and publish
  (revoker, ledger_sequence) for complete audit trails
- Stellar-split#621: extract assert_invoice_pending helper to replace repeated
  if status != Pending { return Err(InvalidStatus) } inline checks
- Stellar-split#622: add pub fn calc_platform_fee(funded, fee_bps) to calc.rs with
  checked_mul / ArithmeticOverflow guard; replace all three inline
  fee expressions in lib.rs with calls to the new helper; add unit
  tests covering normal, zero-bps, 100%-bps and overflow cases
@drips-wave

drips-wave Bot commented Aug 28, 2026

Copy link
Copy Markdown

@kulkan-IV 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

@Kingsman-99
Kingsman-99 merged commit 8ca0cab into Stellar-split:main Aug 29, 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

2 participants