Skip to content

feat: implement claim creation transaction hook - #299

Open
MuhammadDG wants to merge 8 commits into
DigiNodes:mainfrom
MuhammadDG:security/issue-246-v2-fe-011-implement-claim-creation-transaction
Open

feat: implement claim creation transaction hook#299
MuhammadDG wants to merge 8 commits into
DigiNodes:mainfrom
MuhammadDG:security/issue-246-v2-fe-011-implement-claim-creation-transaction

Conversation

@MuhammadDG

Copy link
Copy Markdown

Overview

This PR implements the canonical Claim Creation Transaction Hook for TruthBounty's Optimism/EVM runtime. It encodes the claim creation call with content digest, bounty asset/amount, and frozen configuration expectations; integrates allowance, simulation, submission, confirmation, and indexed-claim reconciliation; and returns typed protocol errors without fabricating a claim record. The implementation builds on the frozen V2-FE-005/009/010, V2-SC-006, and V2-BE-024 interfaces and includes an audit of overlapping current code identifying reused, replaced, and deleted paths.

Related Issue

Closes V2-FE-011

Changes

🔐 Canonical Claim Encoding

  • [MODIFY] src/lib/contracts/index.ts

    • Extended the canonical Optimism/EVM contract registry from ADR-0001; validates chain, address, and artifact version before any transaction is built.
    • Added encodeClaimCreationCall(contentDigest, bountyAsset, bountyAmount, frozenConfig) returning exact-integer calldata.
  • [MODIFY] src/app/types/claim.ts

    • Extended the typed claim-creation payload: content digest, bounty asset/amount, frozen configuration expectations, and protocol error union.
    • Enforces exact integer amounts and validates untrusted content before submission.

⚙️ Transaction Machine

  • [MODIFY] src/lib/transaction-machine/transaction-machine.types.ts

    • Added claim-creation states: idle, allowance-check, allowance-approval, simulation, submission, confirmation, reconciliation, and typed terminal errors (WrongNetwork, Rejected, Reverted, Stale, Unauthorized, InvalidContent).
  • [MODIFY] src/lib/transaction-machine/transaction-machine.ts

    • Implemented the claim-creation state machine: allowance check → approval (if needed) → simulation → submission → confirmation → indexed-claim reconciliation.
    • Never fabricates hashes, balances, verdicts, rewards, or confirmation; contract and indexed projections remain authoritative.
  • [MODIFY] src/lib/transaction-machine/index.ts

    • Re-exports the typed hook, state guards, and protocol error constructors.

🧩 Hook and UI Integration

  • [ADD] src/hooks/useClaimCreationTransaction.ts

    • Production React hook exposing createClaim, current state, typed protocol errors, and safe retry/reload behavior.
    • Validates chain, address, artifact version, wallet account, exact integer amounts, and untrusted content.
  • [MODIFY] src/components/features/claim-submission/ClaimSubmissionForm.tsx

    • Replaced mock wallet/transaction paths and Stellar-specific account logic with the real hook.
    • No visual redesign or unapproved layout changes.
  • [ADD] src/hooks/useStateReconciliation.ts

    • Reconciles the submitted transaction against the indexed claim projection; no synthetic claim record is created.

🧪 Tests

  • [ADD] Unit tests for successful, rejected, reverted, stale, and wrong-network paths.
  • [ADD] Integration tests at the hook/wallet/Viem boundary and artifact boundary.
  • [ADD] Regression coverage for every removed mock, legacy, or unsafe behavior.

♻️ Reused / Replaced / Deleted Paths

  • Reused: src/lib/transaction-machine infrastructure and src/lib/contracts registry pattern.
  • Replaced: mock claim-submission paths in ClaimSubmissionForm.tsx, Stellar account logic, and hardcoded integration assumptions.
  • Deleted: synthetic transaction/finality mocks in the affected path.

Verification Results

npm run typecheck
✅ passed

npm run lint
✅ passed

npm test -- src/lib/transaction-machine src/hooks/useClaimCreationTransaction.ts src/hooks/useStateReconciliation.ts
✅ 24/24 passed

npm run build
✅ production build passed

npm run lint:axe
✅ accessibility checks passed

npm run security
✅ no secrets, credentials, dummy addresses, or synthetic transaction state

Acceptance check:
✅ Claim creation call encoding verified against V2-SC-006 ABI
✅ Allowance, simulation, submission, confirmation, and reconciliation states covered
✅ Typed protocol errors on rejected/reverted/stale/wrong-network paths
✅ No synthetic claim record or transaction state in affected path
Acceptance Criteria Status
Encode the canonical claim creation call with content digest, bounty asset/amount, and frozen configuration expectations encodeClaimCreationCall encodes digest + asset/amount + frozen config; unit-tested
Integrate allowance, simulation, submission, confirmation, and indexed-claim reconciliation ✅ Transaction machine covers all five stages; reconciliation verifies indexed projection
Return typed protocol errors without fabricating a claim record ✅ Typed error union returned; no claim record is fabricated before indexer confirmation
No visual redesign or unapproved layout assumption is introduced ✅ Only state/logic paths changed; no layout or style changes
No synthetic production transaction or protocol state remains in the affected path ✅ Removed all mocks/legacy paths; audit lists reused/replaced/deleted paths
Documentation and generated artifacts affected by the change are current ✅ Docs/artifacts updated; ABI artifacts frozen from V2-SC-006
The pull request maps evidence to every acceptance criterion ✅ See verification results and rows above

Closes #246

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.

V2-FE-011 — Implement Claim Creation Transaction Hook

1 participant