ExternalActionSwap
Overview
ExternalActionSwap defines a common swap action interface used by Hinkal external actions. It receives user intent from HinkalInLogic.handleRunExternalAction, executes a swap on a target router, pays the relay, returns tokens back to Hinkal, and reports resulting UTXOs.
Routing is delegated to an aggregator, so Hinkal does not maintain one adapter per DEX. On EVM chains the router is LI.FI, which internally splits the trade across the underlying DEXs and aggregators.
Concrete adapters:
LifiExternalAction- LI.FI Router arbitrary calldata (EVM swaps and cross-chain swaps)
Solana swaps do not use this contract; they are executed on the Solana program side against either the LI.FI API (ExternalActionId.Lifi, Public/Proxy accounts) or the OKX DEX API (ExternalActionId.Okx, shielded and Public accounts).
Inheritance
Transferer- ERC20/ETH helpers (approve, transfers, balances)ExternalActionBaseV2- recipient allowlist and ownership controls
Key Storage
IHinkalHelper public hinkalHelper- to calculate relay feeIWrapper internal immutable wrapper- WETH/Native wrapper, available to adapters that need to wrap or unwrap ETHaddress public immutable router- target aggregator routeruint256 public constant SWAP_DEADLINE_WINDOW = 10 minutes- max age of the proof's timestamp
Entry Point from Hinkal
function runAction(CircomData circomData, int256[] deltaAmounts)
external onlyAllowedRecipient returns (UTXO[] utxoSet)Delegates to
swap(circomData, deltaAmounts).Protected by
onlyAllowedRecipientso only the registered Hinkal contract can call.
Flow:
Read input token/amount from
circomData.erc20TokenAddresses[0]anddeltaAmounts[0].If
feeToken == inputToken, subtract the flat fee from the input amount.Read output token from
circomData.erc20TokenAddresses[1].Require
slippageValues[1] != 0("swap output slippage floor not set").Require
block.timestamp <= circomData.timeStamp + SWAP_DEADLINE_WINDOW("swap expired").Execute the swap via
callRouter.Pay the relay:
relayFeeis the flat fee,hinkalFee = hinkalHelper.calculateRelayFee(swappedAmount, 0, variableRate). IffeeToken == outputToken, both are sent to the relay in the output token in one transfer; otherwise the flat fee is sent infeeTokenand the variable fee inoutputToken.Transfer the remaining output amount to
msg.sender(Hinkal), and create a singleUTXOwith output token, amount, and stealth info.
Adapter
LifiExternalAction
Measures
outputTokenbalance before the call.If input is ETH (
address(0)), forwardsinputAmountasmsg.valuetorouter.call(externalActionMetadata); else approves the router unlimited allowance and calls without value.Requires success with distinct revert messages for native (
"LI.FI swap failed: native coin") vs ERC20 ("LI.FI swap failed: erc-20 token").Computes
swappedAmountas the post-call balance delta foroutputToken.
Metadata: raw calldata produced off-chain by the LI.FI API for the specific chain, tokens and route. Fetch it with getEvmSwapPrices (TypeScript SDK) or GetSwapQuotesJSON (Go/mobile SDK); the returned lifiDataValue is the metadata, and the matching action id is ExternalActionId.Lifi.
Fees and Accounting
Input-side: If the
feeTokenis the input token, the flat fee is removed from the input before the swap.Output-side: The variable Hinkal fee is computed on the swap result and deducted before returning to Hinkal; the flat relay fee is also deducted from the output when
feeToken == outputToken.Hinkal later enforces slippage and balance equations; this adapter focuses on execution and fee pass-through.
ETH Handling
The LI.FI router takes and returns native ETH directly, so the adapter passes
msg.valueon native input and reads native balances viagetERC20OrETHBalance; no wrapping is performed in the swap path.The
wrapper(WETH) is available in the base contract for adapters and flows that do need wrapping;WrapperTokenExchangecovers the standalone wrap/unwrap case.Transfers via
transferERC20TokenOrETHso ETH and ERC20 paths are unified.
Security Considerations
onlyAllowedRecipientprevents arbitrary callers from abusing approvals/funds.No internal slippage check: circuit/Hinkal-level
slippageValuesenforce minimum outputs, and the action refuses to run when the output slippage floor is unset.SWAP_DEADLINE_WINDOWbounds how stale the proof's timestamp can be at execution time.Unlimited approval is given per-call to the router; this contract is trust-minimized by recipient gating and Hinkal balance checks.
Explicit revert messages for external call failures improve debuggability.
Example Integrations
LI.FI single-hop swap on one EVM chain, metadata produced by the LI.FI quote API.
LI.FI split-route aggregation across several DEXs, returned as one router call.
LI.FI cross-chain swap where the destination chain and recipient are encoded in the route calldata.
Last updated

