Model
Outlines the main protocol model for performing atomic swaps between parties
The protocol model relies on atomic swaps for parties exchanging assets across different chains. The model outlines the core flow of assets and actions that should be taken by each party for a successful asset exchange. Depending on the source and destination, and whether there is a party willing to exchange on those chains, either the Standard flow or Multi-hop flow is used.
Standard flow
When a party directly supports both the source and destination chains and is willing to perform the swap, the standard flow applies. The user initiates the process by calling commit
and setting the timelock to , where is the current timestamp and is the duration for which the user is willing to lock their funds. The party performing the exchange must then call the lock
function on the destination chain, setting the timelock to (), where is a reasonable duration (e.g., 15 minutes) to ensure the user has time to act and leave sufficient time for the party. Finally, the user calls addLock
, specifying the timelock and completing their commitment with a hashlock.
Here are the steps:
User Commit
The user creates a commit object on the source chain with a timelock of .
Party Lock
The party creates a lock object on the destination chain with a hashlock and a timelock of .
User AddLock
The user adds a lock to the commitment on the source chain, adding a hashlock and updating the timelock to .
Party Redeem
The party redeems the locked funds on the destination chain.
User Redeem
The user redeems the locked funds on the source chain.
Multi-hop flow
When transferring funds from a source chain to a destination chain is not possible due to the absence of a party directly linking the two, a multi-hop approach is used, with the chain length denoted as . In this process, the user initially commits funds on the source chain to the first party. Each party in the sequence subsequently calls commit, committing funds for the next party, until the final party on the destination chain calls lock. This locks the funds with a hashlock and the longest timelock, set to , where is the current timestamp and is a reasonable duration (e.g., 15 minutes). The Solver on the destination chain locks funds with a duration of from the current timestamp, ensuring sufficient time for each Solver in the chain to act.
Following this, each party in the hop-chain, starting from the user to the second-to-last party, performs the addLock function with the same hashlock as used on the destination chain but with progressively shorter timelocks. For the user, the timelock is set to , while for the second-to-last party, it is . This pattern continues recursively, with each party adding a lock using the hashlock and a timelock specific to their position in the chain.
When the party on the destination chain calls redeem and reveals the secret, they transfer the user’s funds and redeem the locked funds for themselves. This revelation of the secret allows each preceding party in the chain to sequentially redeem their funds, completing the multi-hop swap.
Here are the steps:
User Commit
The user creates a PreHTLC for Solver(AB).
Solver(AB) Commit
Once detected, Solver(AB) creates a PreHTLC for Solver(BC).
Solver(BC) Lock
Solver(BC) then creates an HTLC for the user.
User, Solver(AB) AddLock
The user detects the last transaction, retrieves the hashlock, and converts their PreHTLC to an HTLC on Chain A. Solver(AB) does the same on Chain B.
Unlocks
Solver(BC) can now release the user’s funds on Chain C and claim their funds on Chain B, while Solver(AB) can claim their funds on Chain A.
Was this page helpful?