Last updated
Last updated
Hinkal Swaps are allowing users to swap ERC-20 tokens discreetly. To achieve this functionality, Hinkal uses relayers and APIs from , , and (more to be added in the future).
When a user wants to swap assets, they generate zk-proof that they are eligible to swap a given amount of the first asset in return for the incoming amount of the second asset. From the viewpoint of outsiders, the swap transaction will be submitted from the relayer's public Ethereum address to Hinkal Pool smart contract.
In the transaction, Hinkal Pool will call , or ’s Smart Contract in order to swap the assets. If, for any reason, the swap fails, then the whole transaction will be reverted, so no additional commitments and nullifiers will be created.
Since the protocol implements UTXO based model of commitments and nullifiers, the swapped amount should be known at the time of zk-proof generation. At the time of the swap transaction submission, it is unknown how many other swap transactions will be submitted in the current block.
This factor generates unpredictable slippage from the viewpoint of the user and relayer. Slippage is relative to the transaction value, whereas gas fees are not. For example, paying $1 out of $10 in gas fees amounts to 10%, but paying $1 out of $1000 is only 0.1%. Check out Hinkal's current used to fairly compensate for the costs.
To tackle the following risks:
slippage
gas costs
smart-contract parameter change affecting payoffs (e.g. CRV emission rate)
the Unexpected Payoffs are compensated to the user using generated before the transaction is submitted.
Important to mention, relayers do not have custody of the swapped assets.
The swapping process in Hinkal is similar to deposits and withdrawals but with a few notable differences. Instead of using the SwapperM1x2x1.circom
circuit, users initiate the SwapperM
circuit, which handles multiple tokens. Additionally, rather than calling the _internalTransact()
function, the protocol calls _internalRunExternalAction()
. This forwards the swap operation to ExternalActionSwap:runAction()
. This function performs the token swap and returns the output UTXOs, which cannot be calculated off-chain due to the real-time fluctuations in token prices.
Once the UTXOs are generated, the corresponding output commitments are created on-chain and added to Hinkal’s Merkle tree. Unlike deposits and withdrawals, where output commitments are generated off-chain as part of the ZKP process, swap-related commitments are computed directly on-chain after the swap has been completed.