Skip to content

Feature/rollback mechanism#489

Open
dami-005 wants to merge 4 commits into
AtomicIP:mainfrom
dami-005:feature/rollback-mechanism
Open

Feature/rollback mechanism#489
dami-005 wants to merge 4 commits into
AtomicIP:mainfrom
dami-005:feature/rollback-mechanism

Conversation

@dami-005
Copy link
Copy Markdown

closes #411
contracts/atomic_swap/src/types.rs:

  • SwapStatus::RolledBack — new terminal state for rolled-back swaps
  • SwapRolledBackEvent { swap_id, buyer_refund, treasury_penalty } — emitted on rollback

contracts/atomic_swap/src/lib.rs:

  • ContractError::RollbackWindowExpired = 45 — called after 24h window
  • DataKey::CompletionTimestamp(u64) — written by reveal_key on successful completion
  • reveal_key — now records CompletionTimestamp when swap completes
  • validate_and_rollback_swap(env, swap_id, is_key_valid) -> bool:
    • Buyer-only (swap.buyer.require_auth())
    • Requires SwapStatus::Completed
    • Enforces 24-hour window from CompletionTimestamp
    • is_key_valid = true → returns false, no state change
    • is_key_valid = false → transfers 90% to buyer, 10% to treasury, sets RolledBack, clears timestamp, appends history, emits event, returns true

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

  1. Invalid key sets RolledBack status
  2. Valid key returns false and leaves swap Completed
  3. Call after 24h window is rejected
  4. Call within 24h (at 86,399s) succeeds
  5. Exact 90/10 split verified against token balances
  6. Second rollback call fails (swap is RolledBack, not Completed)
  7. Rollback on non-Completed swap (e.g. Accepted) is rejected

dami-005 added 4 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
- Add DataKey::SwapSigners(u64) — required co-signer list
- Add DataKey::SwapSignatures(u64) — collected signatures
- Add ContractError::NotAllSigned = 42
- Add ContractError::AlreadySigned = 43
- Add ContractError::NotARequiredSigner = 44
- Add initiate_swap_with_signers(env, token, ip_id, seller, price,
  buyer, signers) — stores required signers alongside the swap
- Add sign_swap_reveal(env, swap_id, signer) — required signer
  records their approval; rejects outsiders and duplicates
- Gate reveal_key: if SwapSigners exist, all must have signed
  before the key can be revealed (NotAllSigned error otherwise)
- Add multi_signer_tests.rs with 7 tests covering:
  blocked until all sign, full flow success, outsider rejection,
  duplicate signature rejection, 3-of-3 flow, sign on pending
  rejection, and empty signers list rejection
- Add SwapStatus::RolledBack to types.rs
- Add SwapRolledBackEvent { swap_id, buyer_refund, treasury_penalty }
- Add DataKey::CompletionTimestamp(u64) — set in reveal_key on success
- Add ContractError::RollbackWindowExpired = 45
- Add validate_and_rollback_swap(env, swap_id, is_key_valid) -> bool:
  - Buyer-only, within 24 hours of completion
  - is_key_valid=true: no-op, returns false
  - is_key_valid=false: refunds 90% to buyer, 10% to treasury,
    sets status to RolledBack, emits rollback event
- Add rollback_tests.rs with 7 tests covering:
  RolledBack status set, valid-key no-op, post-24h rejection,
  within-24h success, correct 90/10 split amounts,
  idempotency (second call fails), non-Completed rejection
@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 Rollback with Partial Refund

1 participant