CoW Swapper
The CoW Swapper enables ERC20-to-ERC20 token swaps within Arcadia Accounts via CoW Protocol's batch auction mechanism. Combined with Arcadia Flash Actions, it supports a range of automated strategies without assets leaving the Account:
Compounding staked positions: Staking rewards paid in a third token (e.g. OP, ARB, AERO) are swapped back into the pool's underlying tokens and compounded into the liquidity position. The CoW Swapper handles the token swap, the existing Compounder handles the rest.
Take profit: Account Owners can automatically take a portion of earned yield and swap it into any token of choice (e.g. USDC) rather than compounding everything back into the pool.
General swaps: Any ERC20 token held in an Arcadia Account can be swapped to any other ERC20 token, enabling flexible portfolio management.
Debt repayment: For leveraged positions, earned yield can be swapped into the debt token and used to repay the loan, gradually deleveraging the position over time.
Stop losses: Position assets are swapped when certain price conditions are met, protecting against downside risk.
Properties
CoW Swapper is:
Immutable.
Non-Custodial but triggering is Permissioned.
The contract relies on CoW Protocol's batch auction for price discovery, with the Initiator earning an optional fee capped by the Account Owner.
How It Works
1. Setup
Only the Account Owner can configure the CoW Swapper. They have to set which address to whitelist as Initiator (can also be themselves), a maxSwapFee cap on what the Initiator can charge (can be 0), and which OrderHook contract to use for additional per-account restrictions.
2. Signing the Order
When the Initiator (or the Account Owner themselves) decides a swap should be done (e.g. to compound claimed staking rewards), they start by constructing and signing a valid CoW swap order. This order is then submitted to CoW's order book.
3. CoW Auction
The CoW Protocol runs a 'Fair Combinatorial Auction', where solvers compete to fill the order within a set amount of time.
The solver that can quote the best price wins the auction and can fill the order.
4. Settlement
The winning solver executes the order on-chain. The solver triggers the transaction via CoW's Flash Loan Router, which initiates a flash action on the Arcadia Account, pulling tokenIn out to the CowSwapper.
First, the CowSwapper logic is triggered. The CowSwapper reconstructs the order based on the input data, computes its hash, and stores the hash in transient storage.
Next, an Account Owner-defined OrderHook is called. Via this hook the Account Owner can enforce additional, customisable constraints (more on this in the next section).
Lastly, the actual swap is settled via CoW's Settlement contract. The settlement contract executes the swap and does a number of checks:
Check that the order has not expired
Check that the order has not been previously filled
Check that the actual execution price was equal to or better than what was specified in the order
Check the order's signature: for the CowSwapper we use EIP-1271 signatures. The contract checks two things: the hash matches what was just reconstructed from the order parameters, and the signature over that hash came from the Initiator or Account Owner.
The hash construction is the core of the trust model. Every field in the order — tokenOut, amountOut, deadline, fee — feeds into the hash that gets verified on-chain. If a solver modified any parameter between the Initiator's submission and settlement, the on-chain reconstruction produces a different hash, the signature check fails, and the transaction reverts. The Initiator commits to specific terms upfront. Those exact terms are what gets executed.
Order Hooks
Account Owners who want more control can use custom Order Hooks. Examples of what a custom hook can do:
Oracle check. Verify the solver's output is within acceptable range of an on-chain price, as a second layer of protection on top of solver competition.
Token filters. Whitelist or blacklist specific assets. Stops the Initiator from swapping into tokens the owner hasn't approved.
Rate limits. Cap swap frequency or maximum size per time window, useful for strategies that should execute gradually rather than all at once.
Trust Assumptions
Initiators
Initiators can decide when to swap tokens, the tokenIn and tokenOut, the amountIn and the minimum amountOut.
The Account Owner can easily restrict the tokenIn and tokenOut via the Order Hook:
Whitelist/blacklist, or fix tokenIn and/or tokenOut
Set minimum cooldown periods
For the minimum amountOut, the decentralised batch auction provides a safety net. Even with a low minimum amountOut, the batch auction guarantees a competitive actual price. Account Owners can additionally use third-party oracles to set a minimum value via a custom Order Hook.
Solvers
Solvers cannot modify anything in the order. If they change any field of the order, or skip certain steps such as the flash loan or hook calls, the on-chain calculated hash will not match the signature.
If the auction mechanism fails or solvers collude, the worst case is that the minimum amountOut specified by the Initiator is what gets quoted.
Fees
The Initiator can charge a fee: a percentage of the tokenOut received, where the percentage is set per order but always capped by the maxSwapFee configured by the Account Owner.
CoW Protocol charges gas costs indirectly by factoring them into the price quoted for the swap.
For more information on protocol fees, see Fees.
Last updated