feat: add protocol fee mechanism#4
Open
devSoniia wants to merge 19 commits into
Open
Conversation
…289#63) - Add ERR_SAME_PARTY (E010) constant to types.rs for consistent error codes - Use ERR_SAME_PARTY in validate_create_stream() instead of inline string - Update test to match new error code prefix
- Pre-deployment checklist (tests, keys, audit, XLM balance) - Step-by-step deploy commands for token and stream contracts - Post-deploy verification steps - Rollback procedure: pause+upgrade or revert to previous WASM
- Connect wallet via Freighter - Create stream, withdraw, query state with TypeScript examples - Error handling with PayStream error codes
- examples/javascript/stream.js — create stream, query state (Node.js) - examples/python/stream.py — create stream, query state (stellar-sdk) - examples/rust/stream.rs — create stream, query claimable (off-chain client) - examples/README.md — setup instructions and links - README.md — link examples/ and docs/integration/frontend.md
Closes Vera3289#101 — TypeScript SDK (sdk/ package) Closes Vera3289#102 — Freighter wallet integration Closes Vera3289#103 — Demo React app Closes Vera3289#104 — pollClaimable utility - sdk/: PayStreamClient wrapping all 10 contract functions with full TypeScript types; read-only calls via simulateTransaction, mutating calls return unsigned XDR for caller to sign and submit - sdk/src/freighter.ts: connectFreighter, getFreighterPublicKey, freighterSignTransaction, isFreighterConnected helpers; throws FreighterNotInstalledError with install link when extension absent - sdk/src/poll.ts: pollClaimable(client, streamId, intervalMs, cb) polls claimable() at a configurable interval, stops on unsubscribe, handles network errors gracefully - demo/: Vite + React app connecting to testnet; connect wallet, create stream, load stream by ID, live claimable balance (5 s poll), withdraw button for employee
feat: TypeScript SDK, Freighter wallet, pollClaimable, and demo app
…ema-docs Issue Vera3289#87: add event schema reference documentation
…-audit Issue Vera3289#75: Fund-lock audit and recovery regression test
…ce-docs Issue Vera3289#97: add performance benchmark documentation
…nbook docs: add mainnet deployment runbook (Vera3289#86)
feat: add SDK usage examples in JS, Python, and Rust (Vera3289#95)
…ntegration docs: add frontend integration guide for JS/TS (Vera3289#91)
…-employee fix: reject stream creation when employer == employee (Vera3289#63)
- Add FeeBps and FeeRecipient variants to DataKey enum - Add PendingAdmin to DataKey (was missing, used by storage.rs) - Add get/set_fee_bps and get/set_fee_recipient storage helpers - Add set_protocol_fee admin function (0-100 bps, E011 if exceeded) - Deduct fee from withdrawal amount; send to fee_recipient - Fee of 0 disables the mechanism entirely - Fix broken use statement in test.rs and add missing imports - Add 5 tests: no fee default, 1% fee deduction, disable fee, above-max rejected (E011), non-admin rejected, 0.5% rounding Closes Vera3289#125
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements an optional protocol fee collected on withdrawals, as specified in Vera3289#125.
Changes
contracts/stream/src/types.rsFeeBpsandFeeRecipientvariants toDataKeyPendingAdmintoDataKey(was missing; used by storage helpers)ERR_FEE_TOO_HIGHerror constant (E011)contracts/stream/src/storage.rsget_fee_bps/set_fee_bps— fee in basis points, stored in instance storageget_fee_recipient/set_fee_recipient— fee destination addresscontracts/stream/src/lib.rsset_protocol_fee(admin, nonce, fee_bps, fee_recipient)— admin-only, nonce-protectedwithdrawto deduct fee before transferring to employee:fee = claimable * fee_bps / 10_000(integer division, rounds down)fee_bps == 0or no recipient is setcontracts/stream/src/test.rsusestatement and missing importstest_withdraw_no_fee_by_default— 0 fee → employee gets full amounttest_withdraw_with_fee_deducted— 1% fee → employee gets 99%test_fee_disabled_when_zero— fee can be re-set to 0test_set_protocol_fee_above_max_rejected— E011 on fee_bps > 100test_set_protocol_fee_non_admin_rejected— non-admin rejectedtest_fee_rounding— 0.5% fee rounds down correctlyAcceptance Criteria
Closes Vera3289#125