Skip to content

feat: Add swap enhancements (#355-#358) - #394

Merged
fejilaup-cloud merged 4 commits into
AtomicIP:mainfrom
chukwudiikeh:feat/swap-enhancements
Apr 27, 2026
Merged

feat: Add swap enhancements (#355-#358)#394
fejilaup-cloud merged 4 commits into
AtomicIP:mainfrom
chukwudiikeh:feat/swap-enhancements

Conversation

@chukwudiikeh

@chukwudiikeh chukwudiikeh commented Apr 26, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR implements four critical swap enhancement features to improve the atomic swap protocol:

#355: Swap Arbitration by Third Party

  • Implement third-party arbitration mechanism for disputed swaps
  • Buyer or seller can request arbitration with evidence
  • Designated arbitrator can decide to refund or complete swap
  • Includes collateral handling in arbitration decisions

#356: Atomic Refund on Key Invalidity

  • Implement atomic verification and completion of swaps
  • If decryption key is invalid, automatically refund buyer and cancel swap
  • If key is valid, complete swap and release payment to seller
  • Ensures no stuck funds due to invalid keys

#357: Swap Batch Processing

  • Implement batch_accept_swaps() for buyer to accept multiple swaps in one transaction
  • Implement batch_reveal_keys() for seller to reveal keys for multiple swaps
  • Reduces gas costs by processing multiple swaps atomically
  • Validates all swaps before processing to ensure consistency

#358: Swap Timeout Escalation

  • Implement escalate_swap_timeout() for buyer to extend swap deadline
  • Buyer can only escalate when timeout is imminent (within 1 hour)
  • Seller is notified of deadline extension
  • Prevents swap cancellation by allowing deadline extension

Changes

  • Added 4 new storage keys: SwapArbitrator, AtomicRefundProcessed, TimeoutExtension
  • Added 8 new event types for all features
  • Implemented 8 new contract functions
  • All functions include proper authorization checks and error handling
  • Maintains backward compatibility with existing swap functionality

Testing

Each feature includes:

  • Authorization validation
  • State transition checks
  • Collateral handling verification
  • Event emission validation

Commits

  1. feat(Implement Swap Arbitration by Third Party #355): Add swap arbitration by third party
  2. feat(Add Swap Atomic Refund on Key Invalidity #356): Add atomic refund on key invalidity
  3. feat(Implement Swap Batch Processing #357): Implement swap batch processing
  4. feat(Add Swap Timeout Escalation #358): Add swap timeout escalation

Closes #355
Closes #356
Closes #357
Closes #358

- Implement request_arbitration() for buyer/seller to request arbitration
- Implement set_arbitrator() to designate arbitrator for a swap
- Implement arbitrate_swap() for arbitrator to decide refund or completion
- Add ArbitratorSetEvent, ArbitrationRequestedEvent, and ArbitratedEvent
- Add SwapArbitrator storage key for tracking arbitrator per swap
- Arbitrator can refund buyer or complete swap with payment release
- Implement verify_and_complete_swap() for seller to verify key atomically
- If decryption key is invalid, automatically refund buyer and cancel swap
- If key is valid, complete swap and release payment to seller
- Refund includes both payment and collateral if present
- Add AtomicRefundEvent to notify of automatic refunds
- Add AtomicRefundProcessed storage key to track refund status
- Implement batch_accept_swaps() for buyer to accept multiple swaps at once
- Implement batch_reveal_keys() for seller to reveal keys for multiple swaps
- Batch operations reduce gas costs by processing multiple swaps in single tx
- Add BatchAcceptedEvent and BatchKeysRevealedEvent for batch operations
- Validates all swaps before processing to ensure atomicity
- Handles collateral deposits and payment transfers for all swaps
- Implement escalate_swap_timeout() for buyer to extend swap deadline
- Buyer can only escalate when timeout is imminent (within 1 hour)
- New expiry must be strictly greater than current expiry
- Seller is notified via TimeoutEscalationRequestedEvent
- Allows deadline extension without cancelling swap
- Add TimeoutExtension storage key to track extended deadlines
@drips-wave

drips-wave Bot commented Apr 26, 2026

Copy link
Copy Markdown

@chukwudiikeh 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

@fejilaup-cloud
fejilaup-cloud merged commit 883e68d into AtomicIP:main Apr 27, 2026
0 of 2 checks passed
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 Swap Timeout Escalation Implement Swap Batch Processing Add Swap Atomic Refund on Key Invalidity Implement Swap Arbitration by Third Party

2 participants