# Execution & Validation

### Execution

#### executeSwap

Orchestrates the entire swap flow in a single call: approval lookup, revoke-then-approve for stale USDT-like allowances, swap transaction build, and final execution. The SDK remains transport-agnostic — you supply an `executeTransaction` callback that handles signing and broadcasting.

```
const result = await swapClient.executeSwap({
  chainIndex: "1",
  fromToken: "USDC",
  toToken: "WETH",
  amount: "100000000",
  walletAddress: "0xYourWallet",
  gasLevel: "average",
  executeTransaction: async (request) => {
    return sendSwapTransactionThroughWallet(request);
  },
});
```

**Callback payload.** The `executeTransaction` callback receives a request object with the following fields, mirroring the Rust `wallet_contract_call` flow: `to`, `chainIndex`, `value`, `data`, `unsignedTx`, `gasLimit`, `aaDexTokenAddress`, `aaDexTokenAmount`, `mevProtection`, and `jitoUnsignedTx`.

**Response shape.** `executeSwap` returns:

```
{
  approveTxHash: string | null;
  swapTxHash: string;
  fromToken: unknown;
  toToken: unknown;
  fromAmount: unknown;
  toAmount: unknown;
  priceImpact: unknown;
  gasUsed: unknown;
}
```

All other methods (quote, build, approval, chain, liquidity) return the aggregator `data` payload directly.

***

### Validation Utilities

The SDK ports the Rust pre-flight checks into TypeScript, so invalid inputs are caught before any network call. These validators normalize amounts without floating-point math, resolve chain-specific token aliases, reject same-token swaps, and guard against EVM-vs-Solana address shape mismatches.

Useful named exports include: `resolveSwapTokenAddress`, `readableToMinimalString`, `validateAmount`, `validateApproveAmount`, `validateSlippage`, `validateSwapMode`, `validateGasLevel`, `validateTips`, `validateAddressForChain`, and `isAllowanceInsufficient`.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://city-protocol.gitbook.io/docs/software-development-kit/swap/execution-and-validation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
