### Get Route API Request Examples
Source: https://docs.kyberswap.com/kyberswap-solutions/kyberswap-zap-as-a-service/kyberswap-zap-as-a-service-zaas-api/zaas-http-api
Provides example requests for the ZaaS API 'Get Route' endpoint using cURL, JavaScript, Python, and Ruby. These examples demonstrate how to query for swap routes with specific parameters and headers.
```Bash
curl -X GET "https://zap-api.kyberswap.com/polygon/api/v1/in/route?dex=DEX_UNISWAPV3&pool.id=0xb46388f104ff88aac68626a316aaf3a924f32055&position.tickLower=-24800&position.tickUpper=32400&tokensIn=0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE&amountsIn=1000000000000000000&slippage=100" \
-H "accept: application/json"\
-H "x-client-id: zap-docs"
```
```JavaScript
fetch('https://zap-api.kyberswap.com/polygon/api/v1/in/route?dex=DEX_UNISWAPV3&pool.id=0xb46388f104ff88aac68626a316aaf3a924f32055&position.tickLower=-24800&position.tickUpper=32400&tokensIn=0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE&amountsIn=1000000000000000000&slippage=100', {
headers: {
'accept': 'application/json',
'x-client-id': 'zap-docs'
}
});
```
```Python
import requests
headers = {
'accept': 'application/json',
'x-client-id': 'zap-docs',
}
params = {
'dex': 'DEX_UNISWAPV3',
'pool.id': '0xb46388f104ff88aac68626a316aaf3a924f32055',
'position.tickLower': '-24800',
'position.tickUpper': '32400',
'tokensIn': '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
'amountsIn': '1000000000000000000',
'slippage': '100',
}
response = requests.get('https://zap-api.kyberswap.com/polygon/api/v1/in/route', params=params, headers=headers)
```
```Ruby
require 'net/http'
uri = URI('https://zap-api.kyberswap.com/polygon/api/v1/in/route?dex=DEX_UNISWAPV3&pool.id=0xb46388f104ff88aac68626a316aaf3a924f32055&position.tickLower=-24800&position.tickUpper=32400&tokensIn=0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE&amountsIn=1000000000000000000&slippage=100')
req = Net::HTTP::Get.new(uri)
req['accept'] = 'application/json'
req['x-client-id'] = 'zap-docs'
req_options = {
use_ssl: uri.scheme == 'https'
}
res = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
http.request(req)
end
```
--------------------------------
### Build Route Example
Source: https://docs.kyberswap.com/kyberswap-solutions/kyberswap-zap-as-a-service/kyberswap-zap-as-a-service-zaas-api/zaas-http-api
Demonstrates how to call the KyberSwap API to build a transaction route using various client languages. It includes examples for making POST requests with necessary headers and JSON payload.
```Bash
curl -X POST "https://zap-api.kyberswap.com/polygon/api/v1/in/route/build" \
-H "accept: application/json"\
-H "content-type: application/json"\
-H "x-client-id: zap-docs" \
-d '{"sender":"0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270","recipient":"0x5cb738DAe833Ec21fe65ae1719fAd8ab8cE7f23D","route":"KLUv/WALBWUVAKavgSFAb9qflX03+n9Wj9hEtiy3sD717uBIcklIUtb9UBVFASZwAG8AewCseGGDZz+f91M98txGAZqZqQsXPJhqdXGMHUIosW9O3X9D9ykvz587bZntFA+ybObckq051tD33d6immunvvu1fJ584ZaJB7tzeUH7jBfGkjJLmzw1GHNfFpS6uHNC7SJxoQMzFkbw7EKHR7EubGBGFDwMD76LRM+krFq9qkyNUC9kEi1HIhRHC7BQ8iwgDMREw9E88FRyoQUe3d1X1WmZdd13nzPVJkbpFzKe9ImUFau7UkkdoU7rrkob/cLF8yr1lzvRdntKumohg+d/c1MyvypzJ3ZnVvmqUP/CCZ4MFRR4b3mPgEmai5fykypW/M+uUGc6UqjV+vaERXQuLpywCFTMSWW+a2rki1JyJv301E6EuKEkvAnDloWPaYxxsAqB13BIFJo3IWEHB3k7n1FCrqvSKw5wk4ZUrp6p7OnTanbzoEAo2KPg8SYgEsWHb+4OUMcV4GmAOiwMlcrDQ6WC3tilpdQOpUrWinl/I8SaO19ljaGwCjy58OK5R0HTdAWK0Cu13SgoCBMNCNMGIhgMvlCiiXg8g4PuNRIRjmcBsBUAktd4MIa1iAeTaFy8CLOY4HlIKM1baBwUDqZ/XfvWqSrba5ma77q5X5V6i/o178ZAIBHMcHBY+BoKRIInQCBAAkOIkfEBRAi1htoyA+Fh2bFWvRh8hvz97PowAKx1qdsQ5xjp2pgs22UIOyQAShdlhjfwZzCdB+z1ohnGvFnSTTKxnORd4epZFuIeA+w2wAw7LgAorNLwQsqNf+xgg82V4vgsD37S9QzcQQb7FtadgPK3lKx7U4HBskxWQGuCP0HydKwMJ+YSsBBVIoM2YptDA0F2jZS8pJQuID3loJeJAg==","deadline":1800000000,"source":"zap-docs"}'
```
```JavaScript
fetch('https://zap-api.kyberswap.com/polygon/api/v1/in/route/build', {
method: 'POST',
headers: {
'accept': 'application/json',
'content-type': 'application/json',
'x-client-id': 'zap-docs'
},
body: JSON.stringify({
'sender': '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270',
'recipient': '0x5cb738DAe833Ec21fe65ae1719fAd8ab8cE7f23D',
'route': 'KLUv/WALBWUVAKavgSFAb9qflX03+n9Wj9hEtiy3sD717uBIcklIUtb9UBVFASZwAG8AewCseGGDZz+f91M98txGAZqZqQsXPJhqdXGMHUIosW9O3X9D9ykvz587bZntFA+ybObckq051tD33d6immunvvu1fJ584ZaJB7tzeUH7jBfGkjJLmzw1GHNfFpS6uHNC7SJxoQMzFkbw7EKHR7EubGBGFDwMD76LRM+krFq9qkyNUC9kEi1HIhRHC7BQ8iwgDMREw9E88FRyoQUe3d1X1WmZdd13nzPVJkbpFzKe9ImUFau7UkkdoU7rrkob/cLF8yr1lzvRdntKumohg+d/c1MyvypzJ3ZnVvmqUP/CCZ4MFRR4b3mPgEmai5fykypW/M+uUGc6UqjV+vaERXQuLpywCFTMSWW+a2rki1JyJv301E6EuKEkvAnDloWPaYxxsAqB13BIFJo3IWEHB3k7n1FCrqvSKw5wk4ZUrp6p7OnTanbzoEAo2KPg8SYgEsWHb+4OUMcV4GmAOiwMlcrDQ6WC3tilpdQOpUrWinl/I8SaO19ljaGwCjy58OK5R0HTdAWK0Cu13SgoCBMNCNMGIhgMvlCiiXg8g4PuNRIRjmcBsBUAktd4MIa1iAeTaFy8CLOY4HlIKM1baBwUDqZ/XfvWqSrba5ma77q5X5V6i/o178ZAIBHMcHBY+BoKRIInQCBAAkOIkfEBRAi1htoyA+Fh2bFWvRh8hvz97PowAKx1qdsQ5xjp2pgs22UIOyQAShdlhjfwZzCdB+z1ohnGvFnSTTKxnORd4epZFuIeA+w2wAw7LgAorNLwQsqNf+xgg82V4vgsD37S9QzcQQb7FtadgPK3lKx7U4HBskxWQGuCP0HydKwMJ+YSsBBVIoM2YptDA0F2jZS8pJQuID3loJeJAg==',
'deadline': 1800000000,
'source': 'zap-docs'
})
});
```
```Python
import requests
headers = {
'accept': 'application/json',
'content-type': 'application/json',
'x-client-id': 'zap-docs',
}
json_data = {
'sender': '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270',
'recipient': '0x5cb738DAe833Ec21fe65ae1719fAd8ab8cE7f23D',
'route': 'KLUv/WALBWUVAKavgSFAb9qflX03+n9Wj9hEtiy3sD717uBIcklIUtb9UBVFASZwAG8AewCseGGDZz+f91M98txGAZqZqQsXPJhqdXGMHUIosW9O3X9D9ykvz587bZntFA+ybObckq051tD33d6immunvvu1fJ584ZaJB7tzeUH7jBfGkjJLmzw1GHNfFpS6uHNC7SJxoQMzFkbw7EKHR7EubGBGFDwMD76LRM+krFq9qkyNUC9kEi1HIhRHC7BQ8iwgDMREw9E88FRyoQUe3d1X1WmZdd13nzPVJkbpFzKe9ImUFau7UkkdoU7rrkob/cLF8yr1lzvRdntKumohg+d/c1MyvypzJ3ZnVvmqUP/CCZ4MFRR4b3mPgEmai5fykypW/M+uUGc6UqjV+vaERXQuLpywCFTMSWW+a2rki1JyJv301E6EuKEkvAnDloWPaYxxsAqB13BIFJo3IWEHB3k7n1FCrqvSKw5wk4ZUrp6p7OnTanbzoEAo2KPg8SYgEsWHb+4OUMcV4GmAOiwMlcrDQ6WC3tilpdQOpUrWinl/I8SaO19ljaGwCjy58OK5R0HTdAWK0Cu13SgoCBMNCNMGIhgMvlCiiXg8g4PuNRIRjmcBsBUAktd4MIa1iAeTaFy8CLOY4HlIKM1baBwUDqZ/XfvWqSrba5ma77q5X5V6i/o178ZAIBHMcHBY+BoKRIInQCBAAkOIkfEBRAi1htoyA+Fh2bFWvRh8hvz97PowAKx1qdsQ5xjp2pgs22UIOyQAShdlhjfwZzCdB+z1ohnGvFnSTTKxnORd4epZFuIeA+w2wAw7LgAorNLwQsqNf+xgg82V4vgsD37S9QzcQQb7FtadgPK3lKx7U4HBskxWQGuCP0HydKwMJ+YSsBBVIoM2YptDA0F2jZS8pJQuID3loJeJAg==',
'deadline': 1800000000,
'source': 'zap-docs',
}
response = requests.post('https://zap-api.kyberswap.com/polygon/api/v1/in/route/build', headers=headers, json=json_data)
```
--------------------------------
### Install KyberSwap Liquidity Widget
Source: https://docs.kyberswap.com/kyberswap-solutions/kyberswap-liquidity-widget/integrating-the-kyberswap-liquidity-widget
Instructions for installing the KyberSwap Liquidity Widget library using npm or Yarn package managers. This is the initial step required to integrate the widget into your project.
```bash
npm i @kyberswap/liquidity-widgets
```
```bash
yarn add @kyberswap/liquidity-widgets
```
--------------------------------
### Install KyberSwap Widget via npm
Source: https://docs.kyberswap.com/kyberswap-solutions/kyberswap-widget/developer-guides/integrating-the-kyberswap-widget
Installs the KyberSwap widgets library using the npm package manager. This is the first step to integrating the swap widget into your project.
```shell
npm i @kyberswap/widgets
```
--------------------------------
### Install KyberSwap Widget via Yarn
Source: https://docs.kyberswap.com/kyberswap-solutions/kyberswap-widget/developer-guides/integrating-the-kyberswap-widget
Installs the KyberSwap widgets library using the Yarn package manager. This is an alternative to npm for installing the necessary dependencies.
```shell
yarn add @kyberswap/widgets
```
--------------------------------
### ZaaS API: Get Route Endpoint
Source: https://docs.kyberswap.com/kyberswap-solutions/kyberswap-zap-as-a-service/kyberswap-zap-as-a-service-zaas-api/zaas-http-api
This entry details the 'Get Route' endpoint for the ZaaS API, which helps find optimal routes for token swaps. It includes the OpenAPI specification URL and example requests for fetching routing information.
```APIDOC
OpenAPI Specification:
https://1368568567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fw1XgQJc40kVeGUIxgI7c%2Fuploads%2FKb7c0Iq7tzY7f82rIq8J%2Fopenapi.yaml?alt=media&token=dc0081be-5e7a-4a26-932b-b6f8d6ebe333
Endpoint:
GET /api/v1/in/route
Description:
Retrieves the optimal route for a token swap (zap in) based on specified parameters like DEX, pool ID, tick ranges, input tokens, amounts, and slippage.
Parameters:
- dex: The decentralized exchange identifier (e.g., DEX_UNISWAPV3).
- pool.id: The ID of the liquidity pool.
- position.tickLower: The lower tick bound for concentrated liquidity positions.
- position.tickUpper: The upper tick bound for concentrated liquidity positions.
- tokensIn: The input token address or identifier.
- amountsIn: The amount of input tokens.
- slippage: The maximum acceptable slippage percentage.
Headers:
- accept: application/json
- x-client-id: A unique identifier for the client, required for rate limiting.
Base URL:
https://zap-api.kyberswap.com/{chain} (where {chain} is a supported blockchain, e.g., 'arbitrum').
```
--------------------------------
### KyberSwap Aggregator API V1 Get Swap Route (APIDOC)
Source: https://docs.kyberswap.com/kyberswap-solutions/kyberswap-aggregator/developer-guides/execute-a-swap-with-the-aggregator-api
The V1 Get Swap Route API allows integrators to query for optimal swap rates by providing tokenIn, tokenOut, and amountIn parameters. The API returns a data object containing routeSummary for human-readable routing data and routerAddress for the contract facilitating the swap. This is the recommended API for efficient route queries.
```apidoc
API: GET /v1/routes
Description: Queries for superior swap rates and routing information.
Parameters:
- tokenIn: (Required) The address of the input token.
- tokenOut: (Required) The address of the output token.
- amountIn: (Required) The amount of the input token to be swapped, represented as a string.
- ... (other optional parameters available on specification page)
Returns:
- routeSummary: An object containing routing data in a human-readable format, representing the best rate found.
- routerAddress: The address of the KyberSwap router contract that facilitates the swap.
Example Usage:
GET /v1/routes?tokenIn=0x...&tokenOut=0x...&amountIn=1000000000000000000
Note: This API is part of the V1 Aggregator API, which is more performant than the non-versioned API.
```
--------------------------------
### KNCL to KNC v2 Migration Process
Source: https://docs.kyberswap.com/governance/kyberdao/faq
Step-by-step guide on how to migrate legacy KNCL tokens to the new KNC v2 token using the KyberSwap migration portal. This process involves connecting a wallet, approving the token, and initiating the migration transaction.
```APIDOC
Migration Portal:
https://kyberswap.com/kyberdao/stake-knc
Steps:
1. Connect wallet to KyberSwap on the Ethereum network.
2. Open the migration portal UI.
3. Approve KNCL balance for use (one-time onchain transaction).
4. Specify KNCL amount to migrate and click 'Migrate' (onchain transaction).
```
--------------------------------
### Embed KyberSwap iFrame
Source: https://docs.kyberswap.com/kyberswap-solutions/kyberswap-widget/iframe-alternative
Example of how to embed the KyberSwap iFrame into a website or dApp using JSX. Demonstrates common parameter configurations for input/output currencies, fee settings, and chain ID.
```jsx
```
--------------------------------
### TypeScript: Configure API Request Parameters
Source: https://docs.kyberswap.com/kyberswap-solutions/limit-order/developer-guides/create-limit-order
Example of configuring parameters for an API request to fetch the maker's active amount. It specifies the chain ID, maker asset address, and maker's address.
```typescript
const targetPathConfig = {
params: {
chainId: ChainId.MATIC, // Example: ChainId.MATIC
makerAsset: makerAsset.address, // Address of the ERC20 token
maker: signerAddress // Address of the maker
}
};
```
--------------------------------
### KyberSwap API Response Parameter Mapping
Source: https://docs.kyberswap.com/kyberswap-solutions/kyberswap-aggregator/developer-guides/upgrading-to-apiv1
This documentation outlines the parameter differences and mappings for KyberSwap API responses. It compares parameters available in the base API GET endpoint with those in the APIv1 GET and APIv1 POST endpoints, noting alterations and new parameters introduced in APIv1.
```APIDOC
API Response Parameter Mapping:
This section details the parameter mappings and differences between various KyberSwap API endpoints.
Parameter Alterations in APIv1 POST:
- `inputAmount` (non-versioned) maps to `amountIn` in `[V1]POST`.
- `encodedSwapData` (non-versioned) maps to `data` in `[V1]POST`.
Parameter Comparison Table:
| API GET | APIv1 GET | APIv1 POST |
| ----------------- | ----------------- | ------------- |
| inputAmount | amountIn | amountIn |
| outputAmount | amountOut | amountOut |
| totalGas | gas | gas |
| gasPriceGwei | gasPrice | |
| gasUsd | gasUsd | gasUsd |
| amountInUsd | amountInUsd | amountInUsd |
| amountOutUsd | amountOutUsd | amountOutUsd |
| receiveUsd | - | - |
| swaps | route | - |
| pool | pool | - |
| tokenIn | tokenIn | - |
| tokenOut | tokenOut | - |
| swapAmount | swapAmount | - |
| amountOut | amountOut | - |
| limitReturnAmount | limitReturnAmount | - |
| maxPrice | - | - |
| exchange | exchange | - |
| poolLength | poolLength | - |
| poolType | poolType | - |
| tokens | - | - |
| address | - | - |
| symbol | - | - |
| name | - | - |
| price | - | - |
| decimals | - | - |
| encodedSwapData | - | data |
| routerAddress | routerAddress | routerAddress |
| - | code | code |
| - | message | message |
| - | data | data |
| - | routeSummary | - |
| - | extraFee | - |
| - | feeAmount | - |
| - | chargeFeeBy | - |
| - | isInBps | - |
| - | feeReceiver | - |
```
--------------------------------
### Get Maker Orders TypeScript Example
Source: https://docs.kyberswap.com/kyberswap-solutions/limit-order/developer-guides/hard-cancel
Demonstrates how to use the KyberSwap API to fetch a Maker's active orders. This is a prerequisite step before selecting specific orders for cancellation.
```TypeScript
const targetPathConfig = {
params: {
chainId: ChainId.MATIC,
maker: signerAddress,
status: "active"
}
};
// Assuming getMakerOrders is a function that makes the API call
// const orders = await getMakerOrders(targetPathConfig);
```
--------------------------------
### Customize Widget Theme
Source: https://docs.kyberswap.com/kyberswap-solutions/kyberswap-widget/developer-guides/customizing-the-kyberswap-widget
Demonstrates how to initialize the KyberSwap Widget with custom theme settings. The `theme` object allows for extensive visual customization of the widget's appearance to match your dApp's branding. It requires the `Widget` component from '@kyberswap/widgets' and an `ethersProvider`.
```javascript
import { Widget } from "@kyberswap/widgets";
const theme = {
// Theme properties defined below
}
```
--------------------------------
### Blink MEV Protection RPC Endpoint
Source: https://docs.kyberswap.com/kyberswap-solutions/kyberswap-interface/user-guides/selecting-preferred-network
Provides MEV protection for Ethereum transactions by routing them through the Blink builder instead of the public mempool. Offers frontrunning protection and prevents failed transactions. Users configure this endpoint in their wallet.
```APIDOC
Endpoint: https://ethereum-mev-protection.kyberengineering.io/
Purpose:
- MEV Protection
- Frontrunning Protection
- No Failed Transactions (transactions only included if they don't revert)
Usage:
Configure this RPC endpoint in your cryptocurrency wallet to submit transactions via Blink.
Benefits:
- Transactions are not visible in the public mempool, preventing sandwich bots.
- Avoids gas costs for failed transactions.
Privacy:
- Blink RPC does not track user information (IP, location, etc.).
- No user information is stored or logged.
```
--------------------------------
### KyberSwap API: Get Trading Pairs
Source: https://docs.kyberswap.com/kyberswap-solutions/limit-order/limit-order-api-specification/general-apis
Retrieves a list of available trading pairs supported by the KyberSwap Limit Order API. This GET request is part of the 'Latest' API version.
```APIDOC
GET /read-partner/api/v1/orders/pairs
Description: Fetches available trading pairs.
Source: LimitOrderAPIs_v1.2.yaml
```
--------------------------------
### KyberSwap Zap-In Route API
Source: https://docs.kyberswap.com/kyberswap-solutions/kyberswap-zap-as-a-service/kyberswap-zap-as-a-service-zaas-api/zaas-grpc-api
Provides endpoints for managing zap-in routes, including getting the best route, decoding route information for debugging, and building encoded data for a specified route. Supports GET and POST requests with various parameters and headers.
```APIDOC
Service:
// Get the best zap-in route.
rpc GetInRoute(GetInRouteRequest) returns (GetInRouteResponse)
option (google.api.http) = {get: "/api/v1/in/route"};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
parameters: [
{
headers: {
name: "X-Client-Id"
description: "Client Id"
type: STRING
}
},
{
headers: {
name: "X-Request-Id"
description: "Request Id"
type: STRING
}
}
]
};
// Decode zap-in route for debugging purposes.
rpc DecodeInRoute(DecodeInRouteRequest) returns (DecodeInRouteResponse)
option (google.api.http) = {
post: "/api/v1/in/route/decode"
body: "*"
};
// Build encoded data for the specified zap-in route.
rpc BuildInRoute(BuildInRouteRequest) returns (BuildInRouteResponse)
option (google.api.http) = {
post: "/api/v1/in/route/build"
body: "*"
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
parameters: [
{
headers: {
name: "X-Client-Id"
description: "Client Id"
type: STRING
}
},
{
headers: {
name: "X-Request-Id"
description: "Request Id"
type: STRING
}
}
]
};
// Get the best zap-in route.
message GetInRouteRequest {
// which dex to use zap with
Dex dex = 1;
// the pool to zap into
Pool pool = 2 [(buf.validate.field).required = true];
// position details
Position position = 3 [(buf.validate.field).required = true];
// which token(s) to use as zap source. also accepts comma separated addresses
repeated string tokens_in = 4 [(buf.validate.field).repeated.items.string.pattern = "^0x[0-9A-Za-z]{40}(,0x[0-9A-Za-z]{40})*$"];
// amount(s) to zap including fee, corresponding to tokenIn. also accepts comma separated amounts.
repeated string amounts_in = 5 [(buf.validate.field).repeated.items.string.pattern = "^\\d+(,\\d+)*$"];
// which token(s) to use as zap source. also accepts comma separated addresses.
// deprecated: use tokens_in. if both fields are specified, they are combined
repeated string token_in = 14 [(buf.validate.field).repeated.items.string.pattern = "^0x[0-9A-Za-z]{40}(,0x[0-9A-Za-z]{40})*$"];
// amount(s) to zap including fee, corresponding to tokenIn. also accepts comma separated amounts.
// deprecated: use amounts_in. if both fields are specified, they are combined
repeated string amount_in = 15 [(buf.validate.field).repeated.items.string.pattern = "^\\d+(,\\d+)*$"];
option (buf.validate.message).cel = {
id: "GetInRouteRequest.tokens_in"
message: "missing tokens_in"
};
}
```
--------------------------------
### KyberSwap Zap-Migrate Route API
Source: https://docs.kyberswap.com/kyberswap-solutions/kyberswap-zap-as-a-service/kyberswap-zap-as-a-service-zaas-api/zaas-grpc-api
Provides endpoints for managing zap-migrate routes, including getting the best route, decoding route information for debugging, and building encoded data for a specified route. Supports GET and POST requests with various parameters and headers.
```APIDOC
// Get the best zap-migrate route.
rpc GetMigrateRoute(GetMigrateRouteRequest) returns (GetMigrateRouteResponse)
option (google.api.http) = {get: "/api/v1/migrate/route"};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
parameters: [
{
headers: {
name: "X-Client-Id"
description: "Client Id"
type: STRING
}
},
{
headers: {
name: "X-Request-Id"
description: "Request Id"
type: STRING
}
}
]
responses: {
key: '200'
value: {
description: "OK"
examples: {
key: 'application/json'
value: '{"code":0,"data":{}}'
}
}
}
};
// Decode zap-migrate route for debugging purposes.
rpc DecodeMigrateRoute(DecodeMigrateRouteRequest) returns (DecodeMigrateRouteResponse)
option (google.api.http) = {
post: "/api/v1/migrate/route/decode"
body: "*"
};
// Build encoded data for the specified zap-migrate route.
rpc BuildMigrateRoute(BuildMigrateRouteRequest) returns (BuildMigrateRouteResponse)
option (google.api.http) = {
post: "/api/v1/migrate/route/build"
body: "*"
};
```
--------------------------------
### KyberSwap ZaaS API - Liquidity Provision
Source: https://docs.kyberswap.com/kyberswap-solutions/kyberswap-zap-as-a-service
The Zap as a Service (ZaaS) API facilitates simplified liquidity provision for concentrated liquidity protocols. It supports adding new liquidity positions and increasing existing ones, integrating with the KyberSwap aggregator to minimize price impact and maximize capital efficiency.
```APIDOC
KyberSwap Zap as a Service (ZaaS) API
Overview:
This API simplifies the process of providing liquidity to concentrated liquidity protocols, making it as easy as a token swap. It leverages the KyberSwap aggregator to ensure optimal pricing and reduce price impact.
Supported Use Cases:
1. **Add Liquidity to a Pool with a new position**
* **Description:** Enables users to create a new liquidity position in a concentrated liquidity pool by specifying the desired token pair, fee tier, and liquidity range. The API handles the underlying token swaps and deposit into the pool.
* **Parameters (Conceptual):
- `tokenA`: The first token for liquidity provision.
- `tokenB`: The second token for liquidity provision.
- `amountA`: The amount of tokenA to provide.
- `amountB`: The amount of tokenB to provide (or derived from amountA and range).
- `feeTier`: The fee tier of the target pool.
- `range`: The price range for the liquidity position.
- `recipient`: The address to receive LP tokens.
* **Returns (Conceptual):
- Transaction hash for the liquidity provision.
- Details of the created position.
2. **Increase Liquidity into an existing Liquidity Position**
* **Description:** Allows users to add more liquidity to an already existing position in a concentrated liquidity pool. This is useful for rebalancing or adding capital to active positions.
* **Parameters (Conceptual):
- `positionId`: The unique identifier of the existing liquidity position.
- `tokenA`: The first token to add.
- `tokenB`: The second token to add.
- `amountA`: The amount of tokenA to add.
- `amountB`: The amount of tokenB to add.
- `recipient`: The address to receive LP tokens.
* **Returns (Conceptual):
- Transaction hash for the liquidity increase.
- Updated position details.
Advantages:
* **Streamlined Process:** Simplifies complex liquidity provision steps.
* **Minimized Price Impact:** Utilizes KyberSwap aggregation for better execution prices.
* **Capital Efficiency:** Employs fallback logic for optimal capital usage.
Future Developments (Potential API Endpoints):
* **Create New Pool:** Functionality to create a pool if it doesn't exist for a given token pair and fee tier.
* **Remove Liquidity:** Functionality to withdraw liquidity from a position, potentially into a single token.
```
--------------------------------
### KyberSwap API: Get Contract Addresses
Source: https://docs.kyberswap.com/kyberswap-solutions/limit-order/limit-order-api-specification/general-apis
Retrieves the contract addresses for KyberSwap services. This GET request is part of the 'Latest' API version. Note: For the full return object, refer to the OpenAPI specification file due to GitBook's limited support for OpenAPI's `additionalProperties` definition.
```APIDOC
GET /read-ks/api/v1/configs/contract-address
Description: Fetches KyberSwap contract addresses.
Source: LimitOrderAPIs_v1.2.yaml
Note: Refer to the .yaml file for the complete return object.
```
--------------------------------
### KyberSwap Chain API - Build Route
Source: https://docs.kyberswap.com/kyberswap-solutions/kyberswap-aggregator/aggregator-api-specification/permit
Details the `build` API endpoint for constructing swap routes on KyberSwap. This endpoint accepts a `permit` calldata parameter for EIP-2612 tokens, allowing swaps without an initial approval transaction.
```APIDOC
POST /v1/route/build
Request Body:
{
"tokenIn": "0x...",
"tokenOut": "0x...",
"amountIn": "1000000000000000000",
"recipient": "0x...",
"permit": "0x..." // Optional: EIP-2612 permit calldata
}
Response Body:
{
"route": [
// ... route details ...
],
"estimatedAmountOut": "..."
}
Description:
This API call is used to build a swap route. The `permit` parameter, when provided, allows for swaps of EIP-2612 tokens without requiring a prior ERC-20 approval transaction. The format and generation of the `permit` calldata should follow the EIP-2612 specification.
```
--------------------------------
### Get and Calculate Taking Amount for Order
Source: https://docs.kyberswap.com/kyberswap-solutions/limit-order/developer-guides/fill-limit-order
Retrieves orders, filters for a target order, and calculates half of the `takingAmount`. This is a prerequisite for checking allowance before filling an order.
```typescript
const orders = await getOrders();
const targetOrder = orders.filter(order => order.id == targetOrderId.toString());
const takingAmount = Number(targetOrder[0].takingAmount)/2;
```
--------------------------------
### Get Active/Open Orders (TypeScript)
Source: https://docs.kyberswap.com/kyberswap-solutions/limit-order/developer-guides/fill-limit-order
Retrieves a list of active or open limit orders for a specified token pair. This step is crucial for identifying orders that can be filled.
```typescript
const targetPathConfig = {
params: {
chainId: ChainId.MATIC,
makerAsset: makerAsset.address, // USDC
takerAsset: takerAsset.address // KNC
}
};
// Assuming getOrders() is a function that makes the API call to /read-partner/api/v1/orders
```
--------------------------------
### Query Swap Route with KyberSwap Aggregator API (TypeScript)
Source: https://docs.kyberswap.com/kyberswap-solutions/kyberswap-aggregator/developer-guides/execute-a-swap-with-the-aggregator-api
This TypeScript code snippet demonstrates how to query for superior swap rates using the KyberSwap Aggregator API's V1 GET endpoint. It requires token input and output addresses and the amount to be swapped. Further details on parameters can be found on the specification page.
```typescript
const targetPathConfig = {
params: {
tokenIn: tokenIn.address,
tokenOut: tokenOut.address,
amountIn: Number(1*10**tokenIn.decimals).toString()
}
};
```