Feature/atomic swap - #321
Open
Daverisky-max wants to merge 2 commits into
Open
Conversation
|
@Daverisky-max 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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #309
Implement Atomic Swap Contract (HTLC)
Resolves Issue #309
Description
This pull request introduces the Atomic Swap smart contract (
atomic-swap) for the Soroban ecosystem. The contract implements a Hash-Time-Locked Contract (HTLC) pattern, enabling trustless token exchanges between two parties, including cross-chain swaps.The contract uses an independent HTLC design (one swap record per leg) to maximize flexibility and conform to standard cross-chain patterns.
Key Features Implemented:
create_swap): Initiator escrows tokens, specifying the target claimer, the hashlock (SHA-256 hash of a secret), and the timeout ledger timestamp.accept_swap): A helper function to safely create the second leg of an atomic swap, ensuring timelocks are nested correctly and statuses match.withdraw): Allows the claimer to retrieve escrowed tokens by revealing the preimage of the hashlock before the timelock expires. The secret is saved on-chain, allowing the counterparty to claim the other leg.refund): Allows the original depositor to reclaim their tokens if the timelock expires without a successful withdrawal.get_swap,get_status) for frontend integrations.Implementation Details
contracts/atomic_swap/.Cargo.toml.created,withdrawn,refunded).Testing
contracts/atomic_swap/src/test.rs.cargo clippy --all-targets -- -D warningsandcargo fmt --check.Review Checklist
Please review the code in
feature/atomic-swap. Let me know if any further tweaks are needed before merging!