# Solana swaps

Two routes move a coin with no Bitcoin involved: between an EVM chain and Solana, and between two Solana coins. They are the routes the Maxy app takes for the same pairs, on the same code. The user's own wallet sends one checked transaction to the user's own address, and Maxy never holds the coins.

| Route | Pairs | Carrier | What the wallet sends |
| --- | --- | --- | --- |
| `chain-swap` | Any EVM token to a Solana coin, and back | One LI.FI route | An EVM transaction or a Solana transaction |
| `sol-swap` | Two Solana coins | Jupiter | A Solana transaction |

## Place the order

The same four calls as [Coin to coin](https://maxy.co/docs/coin-to-coin): quote with both wallets, post the quote's `order`, send what comes back, then `POST /orders/submit` with its hash or signature. The quote's `signing.kind` names the wallet that sends: `evm_tx` or `solana_tx`. In the sandbox, `simulatedHash` stands in for it.

```sh
curl -s -G "$BASE/quote" -H "x-maxy-key: $MAXY_API_KEY" --data-urlencode "from=USDC on base" --data-urlencode "to=SOL" \
  -d amount=10 -d fromAddress="$WALLET" -d toAddress="$SOLANA_WALLET" > quote.json
curl -s -X POST "$BASE/orders" -H "x-maxy-key: $MAXY_API_KEY" -H "content-type: application/json" \
  -d "$(jq -c '{order: .order}' quote.json)" > placed.json
TX_HASH=$(jq -r .transaction.simulatedHash placed.json)
curl -s -X POST "$BASE/orders/submit" -H "x-maxy-key: $MAXY_API_KEY" -H "content-type: application/json" \
  -d "$(jq -c --arg tx "$TX_HASH" '.next.body + {txHash: $tx}' placed.json)"
```

With the SDK, `execute` builds the route for each side's own signer (`evm`, `solana`) and pays `destAddress` when one is named:

```ts
import { createMaxyClient, evmSignerFromPrivateKey, type SolanaSigner } from 'maxy-labs';

declare const solana: SolanaSigner; // the wallet's own Solana provider
const maxy = createMaxyClient();
const evm = evmSignerFromPrivateKey(process.env.EVM_KEY!);
await maxy.swap.execute({ from: 'USDC on base', to: 'SOL', amount: '10', evm, solana });
await maxy.swap.execute({ from: 'SOL', to: 'BONK', amount: '0.1', solana }); // a coin written alone takes the other side's chain
```

From the command line, `price` and `swap` take the same words. A swap from Solana signs with `MAXY_SOLANA_KEY`:

```sh
maxy price 10 usdc base to sol
maxy swap 0.1 sol to bonk --yes
```

From an EVM token, an `approve` step may come first: it approves exactly the amount for the LI.FI Diamond. Follow `steps` in order.

## What is checked before the wallet signs

- **From an EVM chain.** The transaction goes to the LI.FI Diamond, pays the user's own address on the other chain, and moves the coin and amount asked for, with no call after it. `POST /orders` simulates it from the wallet: if `simulation.ok` is false, do not send it.
- **From Solana.** The transaction is simulated against the wallet's own accounts: at most the amount sold and a bridge's own SOL fee may leave it. A Jupiter swap may call only Jupiter's programs, and the coin bought must arrive in the same wallet.

Anything else is `verification_failed`, and nothing is sent. A `sol-swap` pays the wallet that sends it, so its `toAddress` is the same as `fromAddress`.

## Track it

`GET /status?orderId=<source transaction>&chainId=<source chain>&toChainId=<destination chain>&route=chain-swap`. The chain ids are LI.FI's, as the order carries them: Solana is `1151111081099710`. The order is `completed` once the coin has arrived, and `receiving.txHash` names the transaction that delivered it. A `sol-swap` is one Solana transaction: `GET /status?orderId=<signature>&route=sol-swap` reads `completed` once it lands.

## Parity with the Maxy app

Every pair the Maxy app swaps also trades through the API, the SDK and the command line on the same code path: Bitcoin to and from every listed chain, any EVM token to any other, and the two routes above. `GET /pairs` lists them in `pairs`, `anyToken` and `coinToCoin`. Limit orders, DCA, Grid and Multi stay in the Maxy app for now: the API, the SDK and the command line place market swaps.

---
Source: https://maxy.co/docs/solana-swaps (Maxy Docs › User flows and examples › Swaps)
