Squid 백서

Squid

원문

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

e": "application/json", }, } ); const route = routeResult.data.route; const quoteId = route.quoteId; // Save this — required for status tracking console.log("Quote ID:", quoteId); ``` ### Transaction Request Types <a href="#transaction-request-types" id="transaction-request-types"></a> The route response's `transactionRequest` object will include a `transaction_request_type` field that determines how to execute the transaction. There are three types: TypeDescription `ON_CHAIN_EXECUTION` Standard on-chain transaction (EVM). Execute like any Squid transaction. `DEPOSIT_ADDRESS_CALLDATA` Deposit to the provided address with the specified calldata. Used for certain non-EVM chains. `DEPOSIT_ADDRESS_WITH_SIGNATURE` Submit a signed deposit to the provided address. Used for certain non-EVM chains. ### Executing the Route <a href="#executing-the-route" id="executing-the-route"></a> #### `ON_CHAIN_EXECUTION` (EVM Transactions) <a href="#on_chain_execution-evm-transactions" id="on_chain_execution-evm-transactions"></a> For EVM-to-EVM Squid Intents routes where `transaction_request_type` is `ON_CHAIN_EXECUTION`, execution is the same as any Squid transaction: <a class="button secondary">Copy</a> ``` const tx = await signer.sendTransaction({ to: route.transactionRequest.target, data: route.transactionRequest.data, value: route.transactionRequest.value, gasLimit: route.transactionRequest.gasLimit, gasPrice: route.transactionRequest.gasPrice, }); const receipt = await tx.wait(); console.log("Transaction hash:", receipt.transactionHash); ``` #### `DEPOSIT_ADDRESS_CALLDATA` & `DEPOSIT_ADDRESS_WITH_SIGNATURE` <a href="#deposit_address_calldata-and-deposit_address_with_signature" id="deposit_address_calldata-and-deposit_address_with_signature"></a> For certain chains, Squid Intents uses a **deposit address flow** instead of standard on-chain execution. The `transaction_request_type` field will be one of: * `"DEPOSIT_ADDRESS_CALLDATA"` — submit a deposit to the provided address with the specified calldata * `"DEPOSIT_ADDRESS_WITH_SIGNATURE"` — submit a signed deposit to the provided address <a class="button secondary">Copy</a> ``` const route = routeResult.data.route; const transactionRequest = route.transactionRequest; // Check the type to determine the execution flow console.log("Transaction type:", transactionRequest.transaction_request_type); // "ON_CHAIN_EXECUTION", "DEPOSIT_ADDRESS_CALLDATA", or "DEPOSIT_ADDRESS_WITH_SIGNATURE" // Follow the deposit instructions in the transactionRequest // The specific fields will vary by chain and type ``` ### Status Tracking <a href="#status-tracking" id="status-tracking"></a> **Status polling is required for Squid Intents.** After executing a Squid Intent transaction, you **must** call the status API with the `quoteId` parameter. If `quoteId` is not included in the status call, the Squid Intents transaction will be **refunded** to the source chain. #### Getting the Quote ID <a href="#getting-the-quote-id" id="getting-the-quote-id"></a> The `quoteId` is returned at the top level of the route response: <a class="button secondary">Copy</a> ``` { "route": { "quoteId": "6f388be5205ee044cd7fd5047a4ce72e" } } ``` #### Polling for Status <a href="#polling-for-status" id="polling-for-status"></a> <a class="button secondary">Copy</a> ``` // Function to get the status of a Squid Intents transaction const getStatus = async (params) => { try { const result = await axios.get("https://v2.api.squidrouter.com/v2/status", { params: { transactionId: params.transactionId, fromChainId: params.fromChainId, toChainId: params.toChainId, quoteId: params.quoteId, // Required for Squid Intents }, headers: { "x-integrator-id": integratorId, }, }); return result.data; } catch (error) { if (error.response) { console.error("API error:", error.response.data); } throw error; } }; // Poll for transaction completion const updateTransactionStatus = async (txHash, quoteId) => { const getStatusParams = { transactionId: txHash, fromChainId: fromChainId, toChainId: toChainId, quoteId: quoteId, // Required for Squid Intents }; let status; const completedStatuses = ["success", "partial_success", "needs_gas", "not_found", "refund"]; const maxRetries = 10; let retryCount = 0; do { try { status = await getStatus(getStatusParams); console.log(`Route status: ${status.squidTransactionStatus}`); } catch (error) { if (error.response && error.response.status === 404) { retryCount++; if (retryCount >= maxRetries) { console.error("Max retries reached. Transaction not found."); break; } console.log("Transaction not found. Retrying..."); await new Promise((resolve) => setTimeout(resolve, 5000)); continue; } else { throw error; } } if (!completedStatuses.includes(status.squidTransactionStatus)) { await new Promise((resolve) => setTimeout(resolve, 5000)); } } while (!completedStatuses.includes(status.squidTransactionStatus)); }; ``` ### Refund Behavior <a href="#refund-behavior" id="refund-behavior"></a> When a Squid Intent transaction fails, funds are automatically refunded on the source chain. Refunds typically complete within **\~15 minutes**. * Funds are transferred from the `msg.sender` on the source chain * Refunds are sent to the `order.fromAddress`, which corresponds to the `fromAddress` in the route request * This ensures refunds go to the actual user even if the transaction was initiated through a smart contract ### Squid Intents Limitations <a href="#coral-v2-limitations" id="coral-v2-limitations"></a> * Bitcoin and Solana support is coming soon # Become A Solver Whitelabeling Squid Intents ### Overview <mark style="color:yellow;">**With Squid intents whitelabeling, integrators can deploy their own solver network and multi-chain liquidity within Squid’s cross-chain routing infrastructure.**</mark> This enables a seamless, branded trading experience while leveraging Squid Intents' intent-based order system. ### Why Whitelabel Squid Intents? * **Brand & Liquidity Control**: Enable your users to swap seamlessly between ecosystems under your brand, managing liquidity and user experience end-to-end. * **Revenue Opportunities**: Capture spread, fees, and revenue from every order routed through your network. * **Scalability**: Leverage Squid’s vetted cross-chain connectivity without reimplementing complex bridging and messaging logic. ### Prerequisites * **On-Chain Liquidity**: Provision assets across one or more EVM-compatible chains. * **Solver Infrastructure**: Host an orderbook and execution engine capable of generating quotes in Squid Intents' RFQ format. * **Technical Alignment**: Support REST or WebSocket endpoints and adhere to Squid Intents' order lifecycle conventions (RFQ, fill, settlement). ### Business Case Whitelabeling Squid Intents allows you to: * Integrate seamlessly into existing trading terminals or DeFi frontends. * Extend your market-making services to permissionless cross-chain order filling * Differentiate with proprietary pricing algorithms and liquidity incentives. ### Getting Started 1. **Discuss Partnership**: Reach out to Squid to align on requirements and liquidity commitments. 2. **Production Launch**: Go live under your own brand, supported by Squid Intents' monitoring and support. ### Contact For more information or to express interest, please fill out our [partnerships form](https://squidrouter.typeform.com/partnerships) and a member of the Squid team will follow up. # Chain Integration Guides This section provides detailed integration guides for specific chains supported by Squid. Each guide walks through the available integration methods — Widget, API, and SDK — along with chain-specific parameters, supported tokens, and working code examples. * [Bitcoin and Solana](/api-and-sdk-integration/chain-integration-guides/bitcoin-and-solana) * [XRPL Integration](/api-and-sdk-integration/chain-integration-guides/xrpl-integration) * [Stellar Integration](/api-and-sdk-integration/chain-integration-guides/stellar-integration) * [Hedera Integration](/api-and-sdk-integration/chain-integration-guides/hedera-integration) * [Canton Integration](/api-and-sdk-integration/chain-integration-guides/canton-integration) # Bitcoin and Solana Bitcoin and Solana cross-chain swaps are now on Squid! The cross-chain swap mechanism is powered by [Chainflip](https://chainflip.io/). Currently, Bitcoin and Solana integrations are in a closed beta. Please reach out if you would like to have the functionality enabled for your integrator ID. This brief outlines what you need to know in order to enable swaps to and from Bitcoin and Solana. You can also explore the detailed[ **ready-to-run examples in our Github repo**](https://github.com/0xsquid/examples/tree/main/V2/api). ### Creating a Route Currently swaps are only supported to EVM chains. You can swap from EVM chains to Solana and BTC just as you would in a typical cross-chain swap. When swapping **from** Solana or BTC, the `/v2/route` endpoint will return one of two transaction types depending on the token pair. You should check the `transactionRequest.type` field in the response to determine which flow to follow. #### Transaction Type: `ON_CHAIN_EXECUTION` (Direct Swaps) For certain token pairs, Chainflip provides direct swap access. In this case, the route response returns a `transactionRequest` with `type: "ON_CHAIN_EXECUTION"` containing raw transaction data that can be signed and submitted directly on-chain — similar to a standard EVM swap. **Direct Swap Pairs (Solana)** | From Token | To Token | To Chain | | ---------- | -------- | ---------------- | | SOL | ETH | Ethereum (1) | | SOL | USDC | Arbitrum (42161) | | SOL | ETH | Arbitrum (42161) | | USDC | ETH | Ethereum (1) | | USDC | USDC | Arbitrum (42161) | | USDC | ETH | Arbitrum (42161) | **Example Request (SOL → ETH on Ethereum)** ```json { "fromAddress": "35tWpkpFr7UawcpuXm6ir1nN1v5tfoJgKj84xv1YukZn", "fromAmount": "100000000", "fromChain": "solana-mainnet-beta", "fromToken": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", "toAddress": "0x2d0178a76632443B0A64EFEEBc42AE25E8c4B949", "toChain": "1", "toToken": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", "slippage": 1 } ``` **Example Response** ```json { "transactionRequest": { "type": "ON_CHAIN_EXECUTION", "target": "", "data": "AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAQADBx738cKik3CAiHapY2..." } } ``` For direct swaps, status checking follows the standard pattern using the on-chain transaction hash — no special `bridgeType` parameter is needed. #### Transaction Type: `CHAINFLIP_DEPOSIT_ADDRESS` (Deposit Address Flow) All other Solana and BTC routes (i.e., any pair **not** listed in the direct swap pairs table above) will return a `transactionRequest` with `type: "CHAINFLIP_DEPOSIT_ADDRESS"`. This requires an additional step: you must pass the `transactionRequest` body to the deposit address endpoint to get a deposit address, then transfer the assets to that address. **Example Request (SOL → USDC on Base)** ```json { "fromAddress": "35tWpkpFr7UawcpuXm6ir1nN1v5tfoJgKj84xv1YukZn", "fromAmount": "100000000", "fromChain": "solana-mainnet-beta", "fromToken": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", "toAddress": "0x2d0178a76632443B0A64EFEEBc42AE25E8c4B949", "toChain": "8453", "toToken": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913", "slippage": 1 } ``` **Example Response** ```json { "transactionRequest": { "type": "CHAINFLIP_DEPOSIT_ADDRESS", "request": { "quote": { "intermediateAmount": "17908621", "egressAmount": "4083107065211964" } } } } ``` **Step 2: Get the Deposit Address** Take the `transactionRequest` body from the route response and submit it to the deposit address endpoint ([https://v2.api.squidrouter.com/v2/deposit-address](https://v2.api.squidrouter.com/v2/)) using the same headers as the route request endpoint. **Deposit-address Endpoint Body Example** ```json { "type": "CHAINFLIP_DEPOSIT_ADDRESS", "request": { "amount": "70000", "fromChain": "bitcoin", "fromAsset": "BTC", "toChain": "42161", "toAsset": "USDC", "fromAddress": "bc1qzea6nfdfmztwjcn8htqn4tk9j3v2uawf4rck0g", "toAddress": "0xC601C9100f8420417A94F6D63e5712C21029525e", "maxBoostFeeBps": 5, "fillOrKillParams": { "minPrice": "95922.744760479036194738", "refundAddress": "bc1qzea6nfdfmztwjcn8htqn4tk9j3v2uawf4rck0g", "retryDurationBlocks": 150 } } } ``` The deposit address endpoint ([https://v2.api.squidrouter.com/v2/deposit-address](https://v2.api.squidrouter.com/v2/)) will return the deposit address(**`depositAddress`**) which is where the asset should be transferred, the amount(**`amount`**), which is the amount that should be transferred, and the **`chainflipStatusTrackingId`**, which will be used for the status tracking. ```json { "depositAddress": "bc1pdlqe7rw4ep6w6d6q7j3vu300l577wqdn7sw6q3ya3lvlssv5wahq77765y", "amount": "70000", "chainflipStatusTrackingId": "5994435-Bitcoin-26351" } ``` #### Bitcoin Parameters * ChainID: `bitcoin` * Native Token: `satoshi` * Minimum Swap Amount: `.0007 BTC` * The Bitcoin wallet address should be a Native SegWit (Bech32) address #### Solana Parameters * ChainID: `solana-mainnet-beta` * Native Token: `0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee` * Supported Tokens: SOL, USDC(`EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v`) * Minimum Swap Amount: `$20 USD` ### Key Implementation Differences #### Status Checking Status checking depends on the transaction type returned by the route endpoint: **For Direct Swaps (`ON_CHAIN_EXECUTION`):** Use the standard status checking flow with the on-chain transaction hash — the same as any EVM-to-EVM swap. No special `bridgeType` parameter is needed. **For Deposit Address Swaps (`CHAINFLIP_DEPOSIT_ADDRESS`):** Unlike EVM-to-EVM or EVM-to-Cosmos swaps, deposit address swaps from Bitcoin and Solana require setting a **`bridgeType`** parameter and setting the **`transactionId`** parameter as the `chainflipStatusTrackingId` returned from the deposit-address endpoint. When calling the status API([https://v2.api.squidrouter.com/v2/status](https://v2.api.squidrouter.com/v2/)), the bridgeType should be set as **`chainflip`** if the bridge destination is Arbitrum(42161) or **`chainflipmultihop`** if the bridge destination is another EVM chain that is not Arbitrum ```typescript // Status checking params for deposit address swaps: { transactionId: chainflipStatusTrackingId, // Use chainflipStatusTrackingId from the deposit-address endpoint fromChainId: fromChainId, toChainId: toChainId, bridgeType: "chainflip" // Required for SOL or BTC to Arbitrum and chainflipmultihop to any other EVM, } ``` This chainflipID can be found in the returned object from the [https://v2.api.squidrouter.com/v2/deposit-address](https://v2.api.squidrouter.com/v2/) endpoint. ```json { "depositAddress": "bc1pdlqe7rw4ep6w6d6q7j3vu300l577wqdn7sw6q3ya3lvlssv5wahq77765y", "amount": "70000", "chainflipStatusTrackingId": "5994435-Bitcoin-26351" } ``` ### Route Parameters Examples **Bitcoin Example** ```typescript const params = { fromAddress: sourceAddress, fromChain: "bitcoin", fromToken: "satoshi", fromAmount: "70000", // Amount in satoshis toChain: "42161", toToken: toToken, toAddress: destinationAddress, quoteOnly: false }; ``` **Solana Example** ```typescript const params = { fromAddress: wallet.publicKey.toString(), fromChain: "solana-mainnet-beta", fromToken: "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", fromAmount: "100000000", // Amount in lamports toChain: "42161", toToken: toToken, toAddress: destinationAddress, quoteOnly: false }; ``` #### Important Notes 1. Check the `transactionRequest.type` field in the route response to determine which flow to use 2. For direct swap pairs (`ON_CHAIN_EXECUTION`), sign and submit the transaction data directly on-chain 3. For all other pairs (`CHAINFLIP_DEPOSIT_ADDRESS`), retrieve the deposit address from the `/deposit-address` endpoint and transfer assets there 4. Deposit address swaps require the `bridgeType` parameter for status checks; direct swaps use the standard transaction hash 5. Status monitoring for deposit address swaps should use the `chainflipStatusTrackingId` from the deposit-address response 6. Transaction confirmation times vary significantly between chains # Bitcoin Intents Squid Intents support for Bitcoin enables fast, solver-driven cross-chain swaps from Bitcoin (BTC) to any supported EVM chain. ## Settlement Times Bitcoin settlement times vary based on the transaction amount: | $0-1,000 | $1,000-50,000 | $50,000+ | | -------- | ------------- | -------- | | 1 block | 3 blocks | 5 blocks | ## Prerequisites 1. **Integrator ID**: Squid Intents must be enabled for your integrator ID. Contact the Squid team to get this set up. 2. **Bitcoin Wallet Address**: The source wallet must be a Native SegWit (Bech32) address (starting with `bc1q`). *** ## Step 1: Request Route Request a route using the standard `/v2/route` endpoint (via API or SDK) with Bitcoin parameters: * `fromChain`: `"bitcoin"` * `fromToken`: `"satoshi"` * `fromAddress`: Native SegWit address of the user (e.g. `bc1q...`) ```typescript const params = { fromAddress: "bc1qzea6nfdfmztwjcn8htqn4tk9j3v2uawf4rck0g", fromChain: "bitcoin", fromToken: "satoshi", fromAmount: "70000", // Amount in satoshis toChain: "42161", // Arbitrum toToken: "0xaf88d065e77c8cc2239327c5edb3a432268e5831", // USDC toAddress: "0xC601C9100f8420417A94F6D63e5712C21029525e", quoteOnly: false }; // API: // const routeResult = await axios.post("https://v2.api.squidrouter.com/v2/route", params, { headers: { "x-integrator-id": integratorId } }); // const route = routeResult.data.route; // const quoteId = route.quoteId; // SDK: // const { route, requestId } = await squid.getRoute(params); // const quoteId = route.estimate.quoteId || route.quoteId; ``` > \[!IMPORTANT] Save the `quoteId` returned in the route response. It is mandatory for tracking transaction status. ## Step 2: Sign the PSBT The `transactionRequest` object returned in the route response contains the transaction payload. Check the `transaction_request_type` (or `type`) field. For Squid Intents, this will be: `DEPOSIT_ADDRESS_CALLDATA` The `transactionRequest.data` field contains a hex-encoded Partially Signed Bitcoin Transaction (PSBT). You must prompt the user's wallet to sign this PSBT. #### Browser Wallet Example (UniSat Wallet) ```typescript const transactionRequest = route.transactionRequest; if (transactionRequest.transaction_request_type === "DEPOSIT_ADDRESS_CALLDATA") { const psbtHex = transactionRequest.data; // Sign and finalize the PSBT with UniSat Wallet const signedPsbtHex = await window.unisat.signPsbt(psbtHex, { autoFinalized: true }); // Broadcast the transaction const txHash = await window.unisat.pushPsbt(signedPsbtHex); console.log("Broadcasted Tx Hash:", txHash); } ``` #### Node.js / Backend Example (`bitcoinjs-lib`) ```typescript import * as bitcoin from 'bitcoinjs-lib'; import ECPairFactory from 'ecpair'; import * as ecc from 'tiny-secp256k1'; bitcoin.initEccLib(ecc); const ECPair = ECPairFactory(ecc); const keyPair = ECPair.fromWIF(privateKeyWIF, bitcoin.networks.bitcoin); const psbt = bitcoin.Psbt.fromHex(transactionRequest.data, { network: bitcoin.networks.bitcoin }); psbt.signAllInputs(keyPair); psbt.finalizeAllInputs(); const tx = psbt.extractTransaction(); const txHex = tx.toHex(); const txHash = tx.getId(); ``` ## Step 3: Broadcast Transaction Submit the raw transaction hex to the Bitcoin network. If using a browser extension wallet like UniSat, this is done automatically using `pushPsbt`. For backend scripts, you can broadcast using a public block explorer API (e.g. Blockstream): ```typescript const response = await axios.post('https://blockstream.info/api/tx', txHex); ```
프로젝트로 돌아가기