# Swap and Approval Flows

Our swap client utilizes a modular mechanism that decouples price discovery from transaction execution, giving developers full control over wallet integration while preserving aggregator-grade routing quality.

***

### **Quote & Build Flow:**&#x20;

Applications call `getQuote` to receive a read-only price estimate. The SDK automatically resolves common token symbols such as `USDC`, `USDT`, `ETH`, `SOL`, and `native` into chain-specific addresses before calling the aggregator. When ready to commit, `buildSwap` is invoked with the wallet address, gas level, swap mode, and optional slippage.&#x20;

{% hint style="info" %}
If slippage is omitted, the SDK requests auto slippage and defaults `slippagePercent` to `0.5`, matching the Rust reference flow. Applications can then pass the returned payload to a signer of their choice.
{% endhint %}

***

### **Approval Flow:**&#x20;

Applications call `checkApprovals` to verify token allowance for a wallet against the aggregator's spender contract. Unlike quote discovery, approval handling is ERC-20 specific and requires special care for tokens like USDT that enforce revoke-then-approve semantics on stale allowances.&#x20;

The SDK surfaces this behavior through the `isAllowanceInsufficient` utility and automatically handles the revoke cycle during one-shot execution. Each application must trigger its own approval transaction; the SDK does not hold custody of user keys.

***

### **One-Shot Execution Flow:**&#x20;

Developers can use `executeSwap` to orchestrate the complete pipeline in a single call: approval lookup, revoke-then-approve for stale approvals when needed, swap transaction build, and final transaction execution. The SDK stays transport-agnostic and does not hardcode wallet logic.&#x20;

> Developers must provide an `executeTransaction` callback that receives the prepared transaction request (including `to`, `value`, `data`, `gasLimit`, and optional `jitoUnsignedTx` for Solana MEV protection) and returns the broadcast result.


---

# 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/neofinance-as-a-service/swap-module/swap-and-approval-flows.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.
