Skip to content

Feat/sdk decode events - #284

Open
Opulencechuks wants to merge 6 commits into
tributary-protocol:mainfrom
Opulencechuks:feat/sdk-decode-events
Open

Feat/sdk decode events#284
Opulencechuks wants to merge 6 commits into
tributary-protocol:mainfrom
Opulencechuks:feat/sdk-decode-events

Conversation

@Opulencechuks

Copy link
Copy Markdown
Contributor

Closes #61

Pull Request Description

What this changes

  • Exposes typed TypeScript interfaces representing each of the contract events (SplitCreatedEvent, SplitPaidEvent, SplitUpdatedEvent, SplitClosedEvent, ControlTransferredEvent, DepositedEvent, DistributedEvent, and a union type ContractEvent).
  • Introduces and exports the decodeEvent utility in the SDK (index.ts) to automatically parse raw events. This utility robustly handles raw xdr.ScVal objects, base64-encoded XDR strings, { xdr: string } wrapped objects, or pre-converted native values.
  • Adds a comprehensive round-trip unit test suite in index.test.ts covering decoding of all seven contract events and edge cases like optional new controller addresses.
  • Adds a "test" script in the SDK package.json to facilitate test execution.

Why

  • Consumers of the indexer or RPC previously had to manually decode raw event XDR by hand. Providing typed decoders and helpers directly in the SDK simplifies downstream event consumption and ensures type-safety.

Checklist

  • cargo fmt --all and cargo clippy --all-targets -- -D warnings pass (Formatting checks passed locally; full compiler runs on CI)
  • cargo test passes (No Rust contract changes were made)
  • New behavior has tests (SDK events are covered by a decode round-trip test suite)
  • Linked issue, if there is one (Resolves the SDK event decoder helper issue)

Draining a nested split tree currently needs one distribute call per node.
This change introduces a `distribute_cascade` function that distributes a
parent split and recursively distributes any freshly-credited direct children
(and their children, etc.) in a single call.

The cascade is bounded by a `max_depth` parameter up to `MAX_CASCADE_DEPTH` (5)
to protect against Soroban gas limit exhaustion.

A private helper `distribute_node` is extracted to reuse the balance-draining
logic. Unit tests cover a two-level tree, depth bounds, and maximum depth limits.
@Spagero763

Copy link
Copy Markdown
Contributor

Heads up: this looks like the same feature as #275 (both titled "implement bounded cascade distribution helper"), and equivalent functionality (distribute_cascade / distribute_all_tokens) already merged to main via #285. Your contract build is also failing on a missing Error::NoPendingTransfer variant, which is a side effect of that merge renumbering the error enum. Given the feature's already on main, you may want to check #285 and either close this or find something additive on top of it rather than fixing the compile error.

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 a typed helper to decode contract events in the SDK

2 participants