Garden uses Hashed Time Lock Contracts (HTLCs) to implement atomic swap functionality on EVM chains. The contract manages the lifecycle of a swap through four main operations with enhanced signature support and flexible initiation methods:
Uses EIP712 signatures for off-chain authorization, enabling gasless transactions where authorized third parties can initiate swaps on behalf of users.
The redeem function allows the redeemer to claim the locked tokens by providing the secret that hashes to the stored secret hash.
Copy
Ask AI
function redeem( bytes32 orderID, bytes calldata secret) external
The secret must hash to the exact value stored during initiation using SHA256. Once revealed, this secret enables the counterparty to claim funds on the other chain. No signature required - anyone can execute if they know the secret.
The instant refund function provides a way for the redeemer to consent to canceling the swap before the timelock expires using EIP712 signatures.
Copy
Ask AI
function instantRefund( bytes32 orderID, bytes calldata signature) external
This requires the redeemer’s EIP712 signature to prevent unauthorized instant refunds. This ensures mutual consent before the settlement window expires.
The native ETH version simplifies the user experience by eliminating the need for token approvals, while the ERC20 version provides compatibility with all standard tokens.
Chain ID inclusion prevents cross-chain replay attacks, while the parameter combination ensures each order is uniquely identifiable across the network.