Skip to content

Feature/arbitration timelock#486

Open
dami-005 wants to merge 2 commits into
AtomicIP:mainfrom
dami-005:feature/arbitration-timelock
Open

Feature/arbitration timelock#486
dami-005 wants to merge 2 commits into
AtomicIP:mainfrom
dami-005:feature/arbitration-timelock

Conversation

@dami-005
Copy link
Copy Markdown

closes #409

contracts/atomic_swap/src/lib.rs:

  • ContractError::ArbitrationNotTimedOut = 41 — returned when auto-refund is called too early
  • DataKey::ArbitrationTimestamp(u64) — stores the ledger timestamp when arbitration was first requested
  • ProtocolConfig.arbitration_timeout_seconds — new field, defaults to 1_209_600 (14 days)
  • request_arbitration — extended to write ArbitrationTimestamp on the first call; subsequent calls are no-ops for the timestamp (first-request-wins, prevents a malicious party from resetting
    the clock)
  • auto_refund_on_arbitration_timeout(env, swap_id) — permissionless; checks swap is Disputed, that arbitration was requested, and that arbitration_timeout_seconds have elapsed; then refunds
    buyer, cancels swap, emits arb_tout event

contracts/atomic_swap/src/arbitration_timeout_tests.rs — 7 tests:

  1. request_arbitration records timestamp without changing swap state
  2. Auto-refund before timeout is rejected
  3. Auto-refund after timeout succeeds and cancels swap
  4. Auto-refund without a prior request_arbitration is rejected
  5. Second auto-refund call fails (swap already Cancelled)
  6. A third-party address (not buyer/seller) can trigger the refund
  7. Second request_arbitration call doesn't overwrite the first timestamp

dami-005 added 2 commits May 27, 2026 10:44
- Add DataKey::UserReputation(Address) storing score 0-100
- Add DataKey::ReputationMultiplier(u64) for per-swap min buyer rep
- Implement get_reputation(env, address) -> u32 (default 50)
- Implement set_reputation_multiplier(env, swap_id, min_reputation)
- Update reputation on swap completion: +5 seller & buyer
- Update reputation on cancel_swap: -10 canceller
- Update reputation on cancel_expired_swap: -10 seller (defaulted)
- Enforce min reputation in accept_swap (InsufficientReputation error)
- Add ContractError::InsufficientReputation = 40
- Add reputation_tests.rs with 7 tests covering all behaviours
- Add arbitration_timeout_seconds to ProtocolConfig (default 14 days)
- Add DataKey::ArbitrationTimestamp(u64) to track request time
- Add ContractError::ArbitrationNotTimedOut = 41
- Update request_arbitration to record timestamp on first call
  (subsequent calls are no-ops for the timestamp — first wins)
- Add auto_refund_on_arbitration_timeout(env, swap_id): anyone can
  call after timeout elapses; refunds buyer and cancels swap
- Add arbitration_timeout_tests.rs with 7 tests covering:
  timestamp recording, early rejection, timeout success,
  no-request rejection, idempotency, third-party trigger,
  and timestamp immutability on second request
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 27, 2026

@dami-005 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

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.

Implement Swap Arbitration with Timelock

1 participant