---
name: cdp-swaps
description: Executes EVM token swaps (ETH to ERC-20 or ERC-20 to ERC-20) with Permit2 approval flow. Mainnet only (base, ethereum, arbitrum, optimism, polygon).
---

# cdp-swaps

Token swap on EVM mainnet.

## Preconditions

1. CLI configured → `/cdp-setup`
2. Funded account on a mainnet network (base, ethereum, arbitrum, optimism, polygon).
3. Swaps are mainnet only — testnet networks are rejected.

## Steps

### 1. Get quote (read-only)

```
cdp evm swaps quote network==base toToken==0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 \
  fromToken==0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE \
  fromAmount==100000000000000 taker==<address>
```
Note: `==` for query params on GET.

### 2. Create swap

```
cdp evm swaps network=base toToken=<toToken> fromToken=<fromToken> \
  fromAmount=<amount> taker=<address> signerAddress=<address>
```
`cdp evm swaps` IS the POST action (no `create` subcommand). Use `=` for body fields.

### 3. Handle Permit2 (ERC-20 source tokens only)

If response contains `.permit2.eip712`:

a. **One-time approval** — approve ERC-20 to Permit2 contract:
   ```
   PERMIT2=0x000000000022d473030f116ddee9f6b43ac78ba3
   APPROVE_DATA=$(cdp util abi-encode "approve(address,uint256)" $PERMIT2 115792089237316195423570985008687907853269984665640564039457584007913129639935)
   ```
   Send via `/cdp-accounts-send` with `to=<fromToken_contract>`, `data=$APPROVE_DATA`, `value=0`.

b. **Sign Permit2 typed data**:
   ```
   cdp evm accounts sign typed-data <address> \
     primaryType=<permit2.eip712.primaryType> \
     types:=<permit2.eip712.types> \
     message:=<permit2.eip712.message> \
     domain:=<permit2.eip712.domain>
   ```

c. **Append signature to calldata**:
   ```
   SIG_RAW="${signature:2}"
   SIG_LEN="0000000000000000000000000000000000000000000000000000000000000041"
   FULL_DATA="${swap.transaction.data}${SIG_LEN}${SIG_RAW}"
   ```

If no `.permit2` (native ETH source) → use `swap.transaction.data` as-is.

### 4. Confirm with user

Show amount, estimated output, and network before proceeding.

### 5. Encode, sign, send

```
cdp util tx-encode --network <network> --to <swap.transaction.to> \
  --data <FULL_DATA> --value <swap.transaction.value> --from <address> \
  --gas-limit <swap.transaction.gas>
cdp evm accounts sign transaction <address> transaction=<tx>
cdp evm accounts send transaction <address> network=<network> transaction=<signedTransaction>
```

### 6. Verify

```
cdp evm token-balances get <network> <address>
```
Assert: fromToken decreased, toToken increased.

## Compatibility

| Account type | Supported |
|-------------|-----------|
| EVM EOA | yes (mainnet only) |
| Smart account | no — taker must be EOA |
| Solana | no |
