Squid Dev Documentation
Ask or search…
K

V1 -> V2 Migration

New SDK or Widget version

npm install @0xsquid/sdk@^2.8.1
~ Widget V2 version to be released soon

Base URLs

  • V1
    • API https://api.squidrouter.com/v1
    • SDK https://api.squidrouter.com
  • V2
    • API https://v2.api.squidrouter.com/v2
    • SDK https://v2.api.squidrouter.com

Ethers version (Squid SDK integrations only)

  • V1: Ethers V5
  • V2: Ethers V5 or V6 up to v6.7.1 ##HIGHER VERSION NOT SUPPORTED YET##

Change /route from GET to POST

  • The /route endpoint is now POST. /status is still a /GET request.
SDK
API
Our SDK handles this behind the scenes. No changes needed
const getRoute = async (params: any) => {
try {
const result = await axios.post(
"https://v2.api.squidrouter.com/v2/route",
params,
{
headers: {
"x-integrator-id": integratorId,
"Content-Type": "application/json",
},
}
);
const requestId = result.headers["x-request-id"];
return { data: result.data, requestId: requestId };
} catch (error) {
// Log the error response if it's available.
if (error.response) {
console.error("API error:", error.response.data);
}
console.error("Error with parameters:", params);
throw error;
}
};

Importing types

  • V1:
    • import { ChainType, RouteResponse, SquidCallType } from "@0xsquid/sdk";
  • V2: Slightly different import path
    • import { ChainType, RouteResponse, SquidCallType } from "@0xsquid/sdk/dist/types";

integrator-id is required on all requests in V2

Description
SDK
API
Click the tabs for example code
V1
const getSquidSDK = async () => {
const squid = new Squid({
baseUrl: "https://api.squidrouter.com",
});
await squid.init();
return squid;
};
V2 (set once in initial config)
const getSquidSDK = async () => {
const squid = new Squid({
baseUrl: "https://v2.api.squidrouter.com",
integratorId: "<your-integrator-id>
});
await squid.init();
return squid;
};
Add integrator-id to headers of every GET and POST request:
const getChains = async () => {
const result = await axios.get('https://v2.api.squidrouter.com/v2/chains', {
headers: {
'x-integrator-id': integratorId,
},
});
return result.data;
};
const getRoute = async (params: any) => {
try {
const result = await axios.post(
"https://v2.api.squidrouter.com/v2/route",
params,
{
headers: {
"x-integrator-id": integratorId,
"Content-Type": "application/json",
},
}
);
const requestId = result.headers["x-request-id"];
return { data: result.data, requestId: requestId };
} catch (error) {
// Log the error response if it's available.
if (error.response) {
console.error("API error:", error.response.data);
}
console.error("Error with parameters:", params);
throw error;
}
};

Chain IDs are always strings in V2

  • Specifically check for fromChain and toChain
  • e.g. if chainId = 1, convert to chainId = "1"

enableExpress has been renamed to enableBoost

  • This is a request param in the getRoute function. Or on the /route API endpoint.

Setting slippage in the route request

  • V2 introduces auto-slippage as default. Setting slippage manually is now optional
  • V1
  • // inside getRoute() params
    slippage: 1, // 1% slippage
  • V2
  • // inside getRoute() params
    // slippageConfig is required
    slippageConfig: {
    autoMode: 1, // 1 is "normal" slippage. Always set to 1
    },
    // optionally set slippage manually, this will override slippageConfig
    slippageConfig: {
    slippage: 1, // 1% slippage
    autoMode: 1, // ignored if manual slippage is set,
    },

Rename customContractCalls to postHook

Add chainType: ChainType.EVM, to every call object in your array of calls.
{
chainType: ChainType.EVM, // only change in call structure for V2
callType: SquidCallType.FULL_TOKEN_BALANCE,
target: config.MANAPolygon,
value: "0",
callData: config.erc20ContractInterface.encodeFunctionData(
"transfer",
[userAddress, "0"]
),
payload: {
tokenAddress: config.MANAPolygon,
inputPos: 1,
},
estimatedGas: "50000",
}
The array of calls is now set under the calls key of the postHook object. There are some other params now.
postHook = {
chainType: ChainType.EVM,
fundAmount: "0", // unused in postHook, only in preHook
fundToken: "0x", // unused in postHook, only in preHook
calls: yourArrayOfCalls
}