Squid 백서

Squid

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 27쪽 중 18쪽

in the agent wallet. {% endhint %} ## Features * **Wallet management** — generate and store a private key in the OS keychain; retrieve the agent wallet address * **Token & chain discovery** — list all EVM chains and tokens supported by Squid Router * **Balance checking** — query native and ERC-20 balances across all EVM chains * **Cross-chain swaps** — get a route quote, review it, then execute with background monitoring * **Swap status** — poll the status of any in-flight swap by transaction hash {% hint style="info" %} The Squid MCP currently supports **EVM chains only**. {% endhint %} *** ## Getting Started ### Requirements * [**Node.js** ≥ 22](https://nodejs.org/en/download) * **yarn** — `npm install -g yarn` * A [**Squid Integrator ID**](https://squidrouter.typeform.com/partnerships) (issued on a limited basis upon review via the partnerships form) ### 1. Clone the repo and build ```bash # Download the repository git clone https://github.com/0xsquid/squid-mcp.git cd squid-mcp # Install dependencies yarn install # Compile the source yarn build ``` ### 2. Connect to your MCP client Add the MCP server to your AI client of choice. #### Claude Desktop 1. Open the Claude Desktop settings ![macOS menu bar with the Claude app menu open, showing Settings... highlighted](https://4247625265-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtXbXyuWIO2PwzNc5Dets%2Fuploads%2Fgit-blob-8b7feec9734bb788d37f0fadad94587db351fe15%2Fclaude-desktop-settings.png?alt=media)<br> 2. Go to **Settings > Desktop app > Developer** and click **"Edit Config"** ![Claude Desktop Settings page with the Developer section selected, showing an Edit Config button](https://4247625265-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtXbXyuWIO2PwzNc5Dets%2Fuploads%2Fgit-blob-a014d88cf06ba3886263ec43c09864cad5f8dc0f%2Fclaude-desktop-developer-settings.png?alt=media)<br> 3. This will open `claude_desktop_config.json` in your file explorer ![macOS Finder window showing the Claude config directory with claude\_desktop\_config.json highlighted](https://4247625265-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtXbXyuWIO2PwzNc5Dets%2Fuploads%2Fgit-blob-42709db14fce010f76ebe6a85af8e457e544fe6a%2Fclaude-desktop-config-file.png?alt=media)<br> 4. Open the file with a text editor and add `squid-mcp` under `mcpServers`: ```json { "mcpServers": { "squid-mcp": { "command": "node", "args": ["/absolute/path/to/squid-mcp/dist/index.js"] } } } ``` <br> 5. Restart Claude Desktop — you should now see the Squid MCP available and running ![Claude Desktop Developer page showing squid-mcp listed with status running](https://4247625265-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtXbXyuWIO2PwzNc5Dets%2Fuploads%2Fgit-blob-5230c4e038abd26c222cd5f34d14b04a1e91b990%2Fclaude-desktop-squid-mcp-enabled.png?alt=media) <details> <summary>Using fnm or nvm?</summary> Claude Desktop does not inherit your shell environment, so the `node` shim on your `PATH` may not resolve correctly. Use the absolute path to the node binary instead: ```json { "mcpServers": { "squid-mcp": { "command": "/Users/your-user/.local/share/fnm/node-versions/v22.0.0/installation/bin/node", "args": ["/absolute/path/to/squid-mcp/dist/index.js"] } } } ``` To find the path for your active version: ```bash ls ~/.local/share/fnm/node-versions/ ``` </details> #### Claude Code (CLI) ```bash claude mcp add squid-mcp node /absolute/path/to/squid-mcp/dist/index.js ``` If successful, you should see: ``` Added stdio MCP server squid-mcp with command: node /Users/your-user/squid-mcp/dist/index.js to local config File modified: /Users/your-user/.claude.json ``` To verify it was added successfully, run `/mcp` in Claude Code. ![Claude Code CLI showing squid-mcp listed under Local MCPs with a green checkmark](https://4247625265-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtXbXyuWIO2PwzNc5Dets%2Fuploads%2Fgit-blob-3015206463af1d35534df37efbd0a93f5604f6a0%2Fclaude-code-mcp-verified.png?alt=media) *** ## Available Tools | Tool | Description | | ------------------- | ------------------------------------------------------------ | | `setup_wallet` | Generate a new wallet and store it in the OS keychain | | `get_agent_address` | Return the agent wallet address | | `get_chains` | List all EVM chains supported by Squid Router | | `get_tokens` | List tokens on a given chain (filterable by symbol/name) | | `get_balances` | Show non-zero balances across all chains (or a specific one) | | `get_route` | Get a swap route quote (stores it as a pending route) | | `execute_swap` | Execute the pending route; monitors completion in background | | `get_status` | Poll the status of a swap by transaction hash | *** ## Typical Swap Workflow ``` 1. setup_wallet → create the agent wallet (first time only) 2. get_agent_address → confirm the wallet address and fund it 3. get_balances → check available funds 4. get_tokens → look up token addresses if needed 5. get_route → review quote (amounts, fees, slippage, ETA) 6. execute_swap → submit (only after you approve the route) 7. get_status → poll until "success" or "error" ``` Once the wallet is set up and funded, you can simply tell the AI assistant what you want to do in natural language — for example: > *"Swap 1 USDC on Ethereum to ETH on Base"* The assistant will use the tools above to get a quote, present it for your approval, and execute the swap. *** ## Export Your Private Key To back up or import the agent wallet key into another wallet: ```bash yarn build && yarn export-key ``` The key is printed only to your local terminal — it is never sent to the AI assistant or any MCP context. # Squid MPP Adapter AI agents and backend services can now accept and make payments across any EVM chain using the **Squid MPP adapter** — a [Machine Payments Protocol (MPP)](https://tempo.xyz) adapter powered by Squid to abstract away the complexity of cross-chain bridging. Instead of managing bridges or writing complex multi-chain payment logic, developers can integrate the Squid MPP adapter to automatically handle bridging and paying for 402 resources in a single, seamless integration. Clients settle automatically by scanning their available balances across all Squid-supported EVM chains and routing through the Squid API to [Tempo mainnet](https://tempo.xyz). *** ### Features * **Auto chain selection** — scans all Squid-supported EVM chains for available balances and picks the best source token automatically * **Cross-chain bridging** — routes tokens from any supported chain to Tempo mainnet via Squid Router * **HTTP 402 payment flow** — standard MPP challenge/credential cycle: server issues a challenge, client pays and retries with a credential > **Info** The Squid MPP adapter currently supports **EVM chains only**. *** ### Getting Started #### Requirements * [**Node.js** ≥ 18](https://nodejs.org/en/download) * A [**Squid Integrator ID**](https://squidrouter.typeform.com/partnerships) (issued on a limited basis upon review via the partnerships form) #### Server integration Protect any HTTP endpoint so that only clients who have paid can access it. Install the [`mppx`](https://mpp.dev/sdk/typescript) library: ```bash npm install mppx ``` Generate a secret key for credential signing: ```bash openssl rand -hex 32 ``` Add the output to your environment variables: ```env MPP_SECRET_KEY=<output from above> ``` Add `mppx.charge()` as middleware on any route you want to gate. The `tempo()` method configures the settlement token and recipient on Tempo mainnet: ```ts import { Mppx, tempo } from "mppx" const mppx = Mppx.create({ secretKey: process.env.MPP_SECRET_KEY!, methods: [ tempo({ currency: "0x20c0000000000000000000000000000000000000", // PathUSD on Tempo recipient: process.env.RECIPIENT_ADDRESS! }) ] }) // Protect any route — amount is in PathUSD units app.get("/resource", mppx.charge({ amount: "0.01" }), c => { return c.json({ data: "secret content" }) }) ``` Unauthenticated requests receive an HTTP 402 with the charge parameters. Requests that include a valid credential pass through to the handler. Learn more about protecting endpoints with MPP at the official [MPP docs](https://mpp.dev/quickstart/server). #### Client integration Access any MPP-protected endpoint and pay from any supported EVM chain — no manual bridging required. Install `@0xsquid/mpp` alongside `mppx` and `viem`: ```bash npm install @0xsquid/mpp mppx viem ``` You will need a funded agent wallet (USDC or any Squid-supported token on any supported chain) and your Squid Integrator ID. ```env # Private key of the agent wallet PRIVATE_KEY=0x... ``` Wrap your fetch calls with `Mppx.create()` using `squid()` as the payment method. When a 402 is received, the library handles the entire bridge flow: ```ts import { privateKeyToAccount } from "viem/accounts" import { Mppx } from "mppx" import { squid } from "@0xsquid/mpp" const account = privateKeyToAccount(process.env.PRIVATE_KEY! as `0x${string}`) const { fetch: mppxFetch } = Mppx.create({ polyfill: false, methods: [ squid({ account, integratorId: "your-integrator-id" }) ] }) const response = await mppxFetch("https://mpp-server.com/resource") console.log(await response.json()) ``` **`squid(config)` options** | Option | Type | Required | Description | | -------------- | ----------------------------------- | -------- | --------------------------------------------------------------------------------------- | | `account` | `Account` | Yes | A [viem Account](https://viem.sh/docs/accounts/local) (e.g. from `privateKeyToAccount`) | | `integratorId` | `string` | Yes | Your Squid integrator ID | | `onPayment` | `(summary: PaymentSummary) => void` | No | Callback fired after a successful payment with amount, token, and source chain info | Learn more about MPP clients at the official [MPP docs](https://mpp.dev/quickstart/client). *** ### Payment Flow ``` Client Server Squid API Tempo Chain | | | | |-- GET /resource --> | | | |<- HTTP 402 -------- | | | | { amount, | | | | currency, | | | | recipient } | | | | | | | | [find optimal source token] | | | | | | |-- get route quote ----------------------> | | |<- bridge route -------------------------- | | | | | | |-- submit bridge tx ---------------------> | | |-- poll bridge status -------------------> | | | | |-- pay on Tempo ----> | | | |<- payment tx hash -- | |<- payment tx hash ----------------------- | | | | | | |-- GET /resource --> | | | | + credential |-- verify tx -----------------------------> | | |<- payment confirmed ---------------------- | |<- 200 OK ---------- | | | ``` # Contracts Squid deploys router contracts on every supported EVM chain. Most chains share the same contract address, but some newer chains use a different deployment. {% hint style="info" %} **Dynamic Lookup:** You can always retrieve the correct contract address for any chain programmatically using the `/v2/sdk-info` or `/v2/chains` endpoints. Each chain object includes a `squidContracts.squidRouter` field with the correct router address. {% endhint %} ## **Mainnet** ### **SquidRouter — Primary** Used on the majority of EVM chains: | Chain | Address | | ------------- | ------------------------------------------------------------------------------------------------------------------------- | | All (default) | `0xce16F69375520ab01377ce7B88f5BA8C48F8D666` | | Blast | [0x492751eC3c57141deb205eC2da8bFcb410738630](https://blastexplorer.io/address/0xDC3D8e1Abe590BCa428a8a2FC4CfDbD1AcF57Bd9) | | Fraxtal | [0xDC3D8e1Abe590BCa428a8a2FC4CfDbD1AcF57Bd9](https://fraxscan.com/address/0xdc3d8e1abe590bca428a8a2fc4cfdbd1acf57bd9) | ### **SquidRouter — Alternate** The following chains use an alternate router address: | Address | `0x2B4d4Cf15dAD79D3426D19674Bd237C1dc9144aa` | | ------- | -------------------------------------------- | | Chain | Chain ID | | --------- | -------- | | Berachain | 80094 | | Citrea | 4114 | | Gnosis | 100 | | Hedera | 295 | | HyperEVM | 999 | | Mantra | 5887 | | Monad | 143 | | Peaq | 3338 | | SagaEVM | 5464 | | Soneium | 1868 | | Sonic | 146 | | Tempo | 4217 | {% hint style="warning" %} **Always use the contract address returned by the API** for the chain you are targeting. Do not hardcode router addresses — use the `/v2/sdk-info` or `/v2/chains` endpoint to fetch the correct `squidContracts.squidRouter` dynamically. {% endhint %} ### How to look up the router address {% tabs %} {% tab title="API" %} ```bash curl -H "x-integrator-id: YOUR_ID" \ "https://v2.api.squidrouter.com/v2/chains?chainId=295" | jq '.chain.squidContracts.squidRouter' ``` {% endtab %} {% tab title="SDK" %} ```typescript const squid = new Squid({ integratorId: "YOUR_ID" }); await squid.init(); const hedera = squid.chains.find(c => c.chainId === "295"); console.log(hedera.squidContracts.squidRouter); // "0x2b4d4cf15dad79d3426d19674bd237c1dc9144aa" ``` {% endtab %} {% endtabs %} ### **SquidMulticall** `0xaD6Cea45f98444a922a2b4fE96b8C90F0862D2F4` # Additional Dev Resources Additional Dev Resources is a repository of topics and information that can help developers and builders who are looking to utilize Squid's widgets, API, or SDK. **To quickly navigate the topics use the Ask feature, in the top right, which will help you navigate to documentation related to your question.** # Choose How To Integrate Squid {% tabs %} {% tab title="Widgets" %} Customisable React or iframe widgets built for specific user flows. Recommended in most cases. * Fastest to implement * Customisable themes * Customisable supported tokens, hooks etc * Multi-chain wallet management * Handle all edge cases regarding cross-chain UX. * Different widgets for Swap & Bridge, Staking, Checkout <figure><img src="https://4247625265-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtXbXyuWIO2PwzNc5Dets%2Fuploads%2FajRORYStWdHH9jOLKrSj%2FScreenshot%202023-10-07%20at%207.17.03%20pm.png?alt=media&amp;token=f2d7a6bb-1489-4b4e-b56a-a454eda9b065" alt=""><figcaption></figcaption></figure> {% endtab %} {% tab title="SDK" %} All the main Squid functions, and some more helpers, in typescript, at your fingertips. Get full control of your UI. ```typescript const route = await squid.getRoute(params) const fromToken = squid.tokens.find( (t) => t.symbol.toLocaleLowerCase() === "USDC" && t.chainId === "1" ); ``` {% endtab %} {% tab title="API" %} Write your own client code for Squid. Best for traders, wallets, mobile apps, or anyone who prefers not to use Javascript and ethers/wagmi etc. ```typescript const getRoute = async (params: any) => { const result = await axios.get('https://api.squidrouter.com/v1/route', { params: params, headers: { 'x-integrator-id': integratorId, }, }); return result.data; }; ``` {% endtab %} {% endtabs %} <figure><img src="https://4247625265-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtXbXyuWIO2PwzNc5Dets%2Fuploads%2FGtxnyxuU8wMVusoqOCZO%2Fimage.png?alt=media&amp;token=6144ad88-c2cb-4109-92cd-be7a874c1d74" alt=""><figcaption></figcaption></figure> # Squid x Tenderly Mainnet fork dev environment Squid has worked with [Tenderly](https://tenderly.co/) to build a powerful cross-chain development environment. This environment is a replicated Mainnet fork of most Squid-supported EVM chains. This lets users and developers test using mainnet liquidity, and is our recommended development environment. You can spend funds from your account in this environment without spending them on mainnet. Mainnet fork environment base URL <https://axelar-relayer.testsquidrouter.com/api> Polygon mainnet fork RPC <https://rpc.tenderly.co/fork/94010ea6-20cb-4a3a-b8b6-c7cb5e4574e8> Arbitrum mainnet fork RPC <https://rpc.tenderly.co/fork/ba53ac43-0a0f-4f0a-9735-5b5de80c028f> You can get other RPCs from this front end <https://squid-widget-git-main-v2-0xsquid.vercel.app/?apiUrl=https://axelar-relayer.testsquidrouter.com/api> * Try connecting your wallet and clicking “switch network” on the source wallet. Metamask should pop up with the new chain config (MAKE SURE YOU DON'T SUBMIT TO REAL MAINNET) {% tabs %} {% tab title="Users" %} Users can test swapping in our dev environment {% embed url="<https://squid-widget-git-main-v2-0xsquid.vercel.app/?apiUrl=https://axelar-relayer.testsquidrouter.com/api>" fullWidth="true" %} {% endtab %} {% tab title="Widget" %} Set your base URL to <https://axelar-relayer.testsquidrouter.com/api> {% endtab %} {% tab title="SDK" %} Set your base URL to <https://axelar-relayer.testsquidrouter.com/api> <pre class="language-typescript"><code class="lang-typescript">import { Squid } from "@0xsquid/sdk"; <strong>(async () => { </strong> // instantiate the SDK const squid = new Squid(); squid.setConfig({ baseUrl: "https://axelar-relayer.testsquidrouter.com/api", // for testnet use "https://testnet.v2.api.squidrouter.com" integratorId: "your-integrator-id" }); // init the SDK await squid.init(); console.log("Squid inited"); })(); </code></pre> {% endtab %} {% tab title="API" %} Set your base URL to <https://axelar-relayer.testsquidrouter.com/api> ```typescript const baseUrl = "https://v2.api.squidrouter.com/v2" ``` {% endtab %} {% tab title="Debug" %} You can use Tenderly's block explorer and debugger on any transaction submitted to these RPCs. {% embed url="<https://dashboard.tenderly.co/explorer>" %} {% endtab %} {% endtabs %} ### # Testnet or Mainnet? ### Mainnet Currently Squid only supports mainnet since maintaining liquidity across testnets is not feasible. --- [Next Page](https://docs.squidrouter.com/llms-full.txt/1) # Understanding Gas Payments Cross-chain transactions are all about gas. The lack of atomicity, as well as varying prices of gas on different chains makes reliable execution very difficult to obtain. It's something we pride ourselves on, as for over a year we've been working closely with Axelar's relay team to hone gas payments to get reliable and cheap execution for our users. Here are the basics: Squid separates gas fee payments into source chain and cross-chain gas fees. ### Source chain gas fees Source chain gas fees are paid by the user as normal for any crypto transaction. 1. The Squid API/SDK/Widget recommends the `gasLimit` for the transaction. * i.e. the maximum amount of gas that the source transaction will consume. 2. The user's wallet recommends a good price per unit of `gas` that will get the transaction executed on chain. * This amount is variable and so the exact cost of the source chain transaction is unknown until the user completes the tx. ### Cross-chain gas fees Squid bundles all cross-chain gas fees into a single payment, whether the transaction includes multiple hops or just one hop. The complexity is abstracted away from any developer using the Squid API/SDK/Widget. From EVM * For transactions from EVM chains, Axelar takes a gas payment using `value` in native tokens on the source chain. If we are sending USDC from Arbitrum, we pay native ETH to the Axelar gas service contract as part of source chain transaction. Hence, the user needs enough native gas on the source chain to pay for the entire transaction, and this is independent from the amount the user is swapping/bridging. * You can find the `value` amount to be paid in the API or SDK route response at `route.estimate.transactionRequest.value` * Axelar's model for cross-chain gas fee payment is currently a pay for what you use model. The user over pays on the source chain, then gets refunded the value that isn't used during the transaction. From Cosmos via Axelar * Gas fees are paid as part of the token to be bridged. For example if swapping from ATOM to ETH, Squid will swap first to axlUSDC, bridge to Ethereum, then swap for ETH. The bridged token is axlUSDC, so the cross-chain g
프로젝트로 돌아가기