> ## Documentation Index
> Fetch the complete documentation index at: https://docs.train.tech/llms.txt
> Use this file to discover all available pages before exploring further.

# Solver Implementation

> Describes the protocol implementation for the Solver

**1. Monitor the source chain**

Subscribe to `UserLocked` events to detect any locks made to your address with a hashlock.

**2. Lock funds on the destination chain**

* When a lock is detected, call `solverLock()` on the destination chain and pass the same `hashlock` with `timelock` of [$T + 2\Delta$](https://docs.train.tech/protocol-spec/model.md#standard-flow), along with the reward and `rewardTimelock`.
* Solver locks are keyed by **(hashlock, your solver address)** — you get exactly one slot per hashlock, ever. A blind retry reverts with `SolverLockAlreadyExists` instead of double-funding the swap; if your lock was refunded (e.g. a botched fill), re-filling the same hashlock requires a different solver address.

**3. Verify the lock on source chain**

* Monitor the source chain for the `UserLocked` event details (or use the `getUserLock(hashlock)` function) on the detected lock.
* Verify that the `hashlock` matches what the user used.
* Verify that the `timelock` provides sufficient time to act, ensuring it is at least [$T + \Delta$](https://docs.train.tech/protocol-spec/model.md#standard-flow).
* Verify that the `payoutCurve` is one you recognize (only fill locks whose curve you trust — the curve determines the redeem payout).

**4. Receive secret from user**

The user will sign and transmit the derived secret to you via off-chain channels. Verify that when hashed, this secret matches the hashlock on both chains.

**5. Complete the exchange**

* Once you receive the secret, call `redeemSolver()` on the destination chain to unlock the user's funds. **You are incentivized to do this quickly: before the `rewardTimelock` expires, the reward routes to you; after it expires, any actor can redeem and claim the reward instead.**
* Call `redeemUser()` on the source chain to claim your primary fee/reward.
* Pass in the secret value received from the user.

> [!WARNING]
>
> [Edge Case: User Fails to Act on the Solver's Lock](https://docs.train.tech/protocol-spec/edge-cases.md#user-fails-to-act-on-the-solvers-lock)
>
> * If the source lock is never completed, wait for the `timelock` to expire.
> * Call `refundSolver()` on the destination chain to reclaim your funds and reward.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.