Skip to content

Feat/swap enhancements - #395

Merged
fejilaup-cloud merged 5 commits into
AtomicIP:mainfrom
famvilianity-eng:feat/swap-enhancements
Apr 27, 2026
Merged

Feat/swap enhancements#395
fejilaup-cloud merged 5 commits into
AtomicIP:mainfrom
famvilianity-eng:feat/swap-enhancements

Conversation

@famvilianity-eng

Copy link
Copy Markdown
Contributor

Swap Enhancement Features: Insurance, Renegotiation, Escrow & Conditional Acceptance

Summary

This PR implements four critical swap enhancement features that improve buyer protection,
negotiation flexibility, fraud prevention, and conditional deal acceptance. These features
address real-world use cases in high-value IP transactions.

Changes

#354: Swap Insurance Option

  • Added insurance_premium: i128 field to SwapRecord
  • Implemented accept_swap_with_insurance(swap_id, insurance_premium)
  • Buyer-only operation with insurance premium held in escrow
  • Protects buyers from invalid key risks

#353: Swap Renegotiation Protocol

  • Added RenegotiationOffer struct for tracking proposals
  • Implemented propose_renegotiation(swap_id, new_price) - seller or buyer
  • Implemented accept_renegotiation(swap_id) - counterparty accepts
  • Implemented reject_renegotiation(swap_id) - counterparty rejects
  • Enables mid-swap price adjustments without cancellation

#352: Swap Escrow Agent Support

  • Added escrow_agent: Option<Address> field to SwapRecord
  • Implemented initiate_swap_with_escrow(...) - seller-only
  • Implemented escrow_release_funds(swap_id) - escrow-agent-only
  • Reduces fraud risk in high-value transactions

#351: Swap Conditional Acceptance

  • Implemented accept_swap_conditional(swap_id, conditions) - buyer-only
  • Conditions stored as BytesN<32> hash on-chain
  • Allows buyers to set acceptance criteria

Technical Details

Data Structure Updates

  • Extended SwapRecord with 2 new fields
  • Added 4 new DataKey variants for persistent storage
  • Added 4 new event types
  • Added RenegotiationOffer struct

New Functions (7 total)

  • accept_swap_with_insurance()
  • propose_renegotiation()
  • accept_renegotiation()
  • reject_renegotiation()
  • initiate_swap_with_escrow()
  • escrow_release_funds()
  • accept_swap_conditional()

Backward Compatibility

✅ All changes are backward compatible:

  • New fields have sensible defaults (0 or None)
  • Existing functions unchanged
  • New functions are additive
  • No breaking changes

Security

✅ Authorization checks maintained
✅ Fund safety with contract escrow
✅ All operations maintain existing security patterns

Related Issues

- Add insurance_premium field to SwapRecord
- Add SwapInsurance DataKey for storing insurance premiums
- Implement accept_swap_with_insurance() for buyer protection
- Insurance premium transferred to contract escrow
- Add InsurancePayoutEvent for tracking insurance payouts
- Add SwapRenegotiations DataKey for storing renegotiation offers
- Add RenegotiationOffer struct for tracking proposals
- Implement propose_renegotiation() for seller or buyer
- Implement accept_renegotiation() for counterparty
- Implement reject_renegotiation() for counterparty
- Add RenegotiationProposedEvent for tracking proposals
- Add tests for renegotiation flow
- Add escrow_agent field to SwapRecord for high-value swaps
- Add SwapEscrowAgent DataKey for storing escrow agent addresses
- Implement initiate_swap_with_escrow() for seller-initiated escrow
- Implement escrow_release_funds() for escrow agent fund release
- Add EscrowReleasedEvent for tracking escrow releases
- Add tests for escrow flow
- Add SwapConditions DataKey for storing acceptance conditions
- Implement accept_swap_conditional() for buyer-set conditions
- Conditions stored as BytesN<32> hash on-chain
- Add ConditionalAcceptanceEvent for tracking conditional accepts
- Add tests for conditional acceptance flow
@drips-wave

drips-wave Bot commented Apr 26, 2026

Copy link
Copy Markdown

@famvilianity-eng 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 8d04627 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 Insurance Option Implement Swap Renegotiation Protocol Add Swap Escrow Agent Support Implement Swap Conditional Acceptance

2 participants